View Issue Details

This bug affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
15500Bug reportsPluginspublic2021-03-08 19:35
Reporteradamzammit Assigned Toollehar  
PrioritynoneSeverityblock 
Status closedResolutionfixed 
Product Version3.19.3 
Fixed in Version3.25.17 
Summary15500: getSurveyInfo() fails with fatal error for a plugin from console when tokens table with attributes set
Description

When using the function getSurveyInfo() inside a plugin that is executed from the console AND the survey I am getting the info for has a tokens table AND has attributes set in the tokens table, I received the error:

PHP Fatal error: Class 'Token_XXXXXX' not found in /var/www/html/framework/db/ar/CActiveRecord.php on line 403

If the same function was called in the plugin NOT from the console, there was no error. Also if there was no tokens table set or a tokens table set with no attributes - there was no error.

I was able to track this down to the console init not importing and registering the ClassFactory.

Here is my solution:

In application/commands/console.php add the 3 lines indicated with "//add"

if (isset($config)) {
    require_once($core.'ConsoleApplication.php');
    $app = Yii::createApplication('ConsoleApplication', $config);
    define('APPPATH', Yii::app()->getBasePath().DIRECTORY_SEPARATOR);
    $app->commandRunner->addCommands(YII_PATH.'/cli/commands');
    $env = (string) @getenv('YII_CONSOLE_COMMANDS');
    if (!empty($env)) {
        $app->commandRunner->addCommands($env);
    }   

    Yii::import('application.helpers.ClassFactory');     //add
    ClassFactory::registerClass('Token_', 'Token');   //add
   ClassFactory::registerClass('Response_', 'Response'); //add
 }
$app->run();

Not sure if anyone else has encountered this or is happy to test?

TagsNo tags attached.
Bug heat10
Complete LimeSurvey version number (& build)3.19.3
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMariaDb
Server OS (if known)
Webserver software & version (if known)
PHP Version7.2

Users monitoring this issue

adamzammit, DenisChenu

Activities

adamzammit

adamzammit

2019-11-01 05:02

developer   ~54299

Hi @DenisChenu - I noticed this when working with the backupSurveyLocally plugin that I have forked from your repository on GitLab.

Do you notice this bug when using your plugin?

Thanks,
Adam

DenisChenu

DenisChenu

2019-11-01 11:21

developer   ~54315

No, because I didn't load Survey model :)

When i need Survey::model : https://gitlab.com/SondagesPro/mailing/sendMailCron/blob/master/sendMailCron.php#L1422

adamzammit

adamzammit

2019-11-04 06:15

developer   ~54378

Does the bug appear when getSurveyInfo() is called here:

https://gitlab.com/SondagesPro/coreAndTools/backupSurveyLocally/blob/master/backupSurveyLocally.php#L298

?

DenisChenu

DenisChenu

2019-11-04 09:42

developer   ~54380

? right … i must look … but i use it on a 2.73 version … :/

DenisChenu

DenisChenu

2019-11-05 07:15

developer   ~54395

@adamzammit : checked : same issue …
Surely sendMailCron loaded before this plugin …

adamzammit

adamzammit

2019-11-08 04:53

developer   ~54477

Thanks @DenisChenu.

Do you think we should add the ClassFactory code to console.php or leave it up to the plugin to load?

Adam

DenisChenu

DenisChenu

2019-11-08 07:40

developer   ~54478

My opinion : must be loaded by core if needed … (When load Token or Response model ?) is the best.

Load by plugins is a workaround … then : load directly when using console (same for all other bug/issue when using console)

ollehar

ollehar

2021-03-03 15:09

administrator   ~62662

Please check if this bug still exists in the latest patch release. Thank you.

adamzammit

adamzammit

2021-03-05 02:36

developer   ~62742

I can confirm the issue still appears for me on the latest 3.x-LTS.

I still require the modification suggested in the original post (Adding the lines to the console.php file) to avoid an error

ollehar

ollehar

2021-03-05 14:55

administrator   ~62765

Fix committed to 3.x-LTS branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=31271

ollehar

ollehar

2021-03-05 14:56

administrator   ~62766

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=31272

ollehar

ollehar

2021-03-05 14:56

administrator   ~62767

Thanks for the fix!

Related Changesets

LimeSurvey: 3.x-LTS e437acb9

2021-03-05 14:55:21

ollehar

Details Diff
Fixed issue 15500: getSurveyInfo() fails with fatal error for a plugin from console Affected Issues
15500
mod - application/commands/console.php Diff File

LimeSurvey: master 31709469

2021-03-05 14:55:58

ollehar

Details Diff
Fixed issue 15500: getSurveyInfo() fails with fatal error for a plugin from console Affected Issues
15500
mod - application/commands/console.php Diff File

Issue History

Date Modified Username Field Change
2019-10-31 05:00 adamzammit New Issue
2019-10-31 05:01 adamzammit Description Updated
2019-10-31 05:01 adamzammit Description Updated
2019-11-01 05:01 adamzammit Issue Monitored: DenisChenu
2019-11-01 05:02 adamzammit Note Added: 54299
2019-11-01 05:03 adamzammit Issue Monitored: adamzammit
2019-11-01 11:21 DenisChenu Note Added: 54315
2019-11-04 06:15 adamzammit Note Added: 54378
2019-11-04 09:42 DenisChenu Note Added: 54380
2019-11-05 07:15 DenisChenu Note Added: 54395
2019-11-08 04:53 adamzammit Note Added: 54477
2019-11-08 07:40 DenisChenu Note Added: 54478
2021-03-03 15:09 ollehar Assigned To => ollehar
2021-03-03 15:09 ollehar Status new => feedback
2021-03-03 15:09 ollehar Note Added: 62662
2021-03-05 02:36 adamzammit Note Added: 62742
2021-03-05 02:36 adamzammit Status feedback => assigned
2021-03-05 14:55 ollehar Changeset attached => LimeSurvey 3.x-LTS e437acb9
2021-03-05 14:55 ollehar Note Added: 62765
2021-03-05 14:55 ollehar Resolution open => fixed
2021-03-05 14:56 ollehar Changeset attached => LimeSurvey master 31709469
2021-03-05 14:56 ollehar Note Added: 62766
2021-03-05 14:56 ollehar Status assigned => resolved
2021-03-05 14:56 ollehar Note Added: 62767
2021-03-08 19:35 c_schmitz Fixed in Version => 3.25.17
2021-03-08 19:35 c_schmitz Status resolved => closed
2021-08-02 17:18 guest Bug heat 6 => 10