View Issue Details

This bug affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
11302Bug reportsPluginspublic2016-06-03 14:46
ReporterDenisChenu Assigned ToLouisGac 
PrioritynoneSeverityminor 
Status closedResolutionfixed 
Product Version2.50.x 
Summary11302: Unable to use TokenDynamic or SurveyDynamic in cron event (or command)
Description

When try to use SurveyDynamic or TokenDynamic model in cron event : receive
exception 'CException' with message 'Object configuration must be an array containing a "class" element.' in ./framework/YiiBase.php:193

Steps To Reproduce

Test included plugin

Additional Information

COmplete error
$ php application/commands/console.php plugin cron --interval=18
exception 'CException' with message 'Object configuration must be an array containing a "class" element.' in ./framework/YiiBase.php:193
Stack trace:
#0 ./framework/base/CModule.php(393): YiiBase::createComponent(Array)
#1 ./framework/base/CModule.php(103): CModule->getComponent('session')
#2 ./application/core/LSWebUser.php(14): CModule->get('session')
#3 ./framework/YiiBase.php(217): LSWebUser->
construct()
#4 ./framework/base/CModule.php(393): YiiBase::createComponent(Array)
#5 ./framework/base/CModule.php(103): CModule->getComponent('user')
#6 ./application/models/SurveyDynamic.php(64): CModule->get('user')
#7 ./framework/db/ar/CActiveRecord.php(2385): SurveyDynamic->tableName()
#8 ./framework/db/ar/CActiveRecord.php(411): CActiveRecordMetaData->
construct(Object(SurveyDynamic))
#9 ./framework/db/ar/CActiveRecord.php(680): CActiveRecord->getMetaData()
#10 ./application/models/LSActiveRecord.php(29): CActiveRecord->hasAttribute('created')
#11 ./framework/db/ar/CActiveRecord.php(396): LSActiveRecord->behaviors()
#12 ./application/models/SurveyDynamic.php(35): CActiveRecord::model('SurveyDynamic')
#13 ./plugins/testToken/testToken.php(41): SurveyDynamic::model('232512')
#14 [internal function]: testToken->countToken()
#15 ./application/libraries/PluginManager/PluginManager.php(193): call_user_func(Array)
#16 ./application/commands/PluginCommand.php(24): ls\pluginmanager\PluginManager->dispatchEvent(Object(PluginEvent))
#17 [internal function]: PluginCommand->actionCron('18')
#18 ./framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(PluginCommand), Array)
#19 ./framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
#20 ./framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#21 ./framework/base/CApplication.php(185): CConsoleApplication->processRequest()
#22 ./application/commands/console.php(55): CApplication->run()

Due to usage of App()->user in model (then $_SESSION)

I send a pull request for this

TagsNo tags attached.
Attached Files
testToken.php (1,219 bytes)   
<?php
/**
 * testToken
 *
 * @author Denis Chenu <denis@sondages.pro>
 * @copyright 2016 Denis Chenu <http://www.sondages.pro>
 * @license LPRAB (WTFPL)
 * @version 0.0.1
 *
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Do What The Fuck You Want to Public License for more details.
 */

class testToken extends \ls\pluginmanager\PluginBase
{
    static protected $description = 'Bug report plugin';
    static protected $name = 'testToken';

    /**
    * Add function to be used in cron event
    */
    public function init()
    {
        $this->subscribe('cron','countToken');
    }

    public function countToken()
    {
        $oSurveys=Survey::model()->findAll(
            "active = 'Y'"
            );
        Yii::import('application.helpers.common_helper', true);

        if($oSurveys)
        {
            foreach ($oSurveys as $oSurvey)
            {
                    $nbResponse=SurveyDynamic::model($oSurvey->sid)->count();
                    echo "Survey {$oSurvey->sid} have {$nbResponse} responses\n";
            }
        }
    }

}
testToken.php (1,219 bytes)   
Bug heat4
Complete LimeSurvey version number (& build)20160530
I will donate to the project if issue is resolvedNo
Browsernot relevant
Database type & versionnot relevant
Server OS (if known)not relevant
Webserver software & version (if known)not relevant
PHP Versionnot relevant

Users monitoring this issue

There are no users monitoring this issue.

Activities

DenisChenu

DenisChenu

2016-05-31 00:10

developer   ~39033

Plugin name is testToken, but use only Survey

DenisChenu

DenisChenu

2016-05-31 00:17

developer   ~39034

https://github.com/LimeSurvey/LimeSurvey/pull/499

https://github.com/LimeSurvey/LimeSurvey/pull/499/commits/293ee251eaa87bcd1d1887e4ce7f4d66a5bca9e6

replace $_SESSION usage by global

c_schmitz

c_schmitz

2016-06-03 14:46

administrator   ~39185

Version 2.50 Build 160603 released

Issue History

Date Modified Username Field Change
2016-05-31 00:09 DenisChenu New Issue
2016-05-31 00:09 DenisChenu File Added: testToken.php
2016-05-31 00:10 DenisChenu Note Added: 39033
2016-05-31 00:17 DenisChenu Note Added: 39034
2016-06-03 11:20 LouisGac Status new => resolved
2016-06-03 11:20 LouisGac Resolution open => fixed
2016-06-03 11:20 LouisGac Assigned To => LouisGac
2016-06-03 14:46 c_schmitz Note Added: 39185
2016-06-03 14:46 c_schmitz Status resolved => closed