View Issue Details

IDProjectCategoryView StatusLast Update
11447Development [All Projects] Pluginspublic2018-10-06 19:04
ReporterDenisChenuAssigned ToDenisChenu 
PrioritynormalSeverityminor 
Status resolvedResolutionreopened 
Product Version 
Target VersionFixed in Version3.x 
Summary11447: Unable to use beforeTokenSave afterSurveySave event
Description

See discussion here : https://github.com/LimeSurvey/LimeSurvey/commit/c69d913562cb4bcf87453ba3f6e7ad65b6f2fcaf#commitcomment-18190072

In fact : we already have an event for beforeSave and afterSave, but we can not uise it for Dynbamic moodel (Token or Survey)

Steps To Reproduce

Add Yii::log('after'.get_class($this->owner).'Save', 'info','application.plugins.event');
in PluginEventBehavior->afterSave

And
'filePluginevent' => array(
'class' => 'CFileLogRoute',
'levels' => 'info',
'categories'=>'application.plugins.event',
),
in config.phpo

Look at tmp/runtime/application.log

Additional Information

$this->owner send Model class + model id, maybe we need to fix it or send it with another part, specific for dynamic model.

TagsNo tags attached.

Activities

DenisChenu

DenisChenu

2016-07-12 10:19

developer   ~39869

if(is_subclass_of($this->owner,'Dynamic'))
{
Yii::log('after'.get_parent_class($this->owner).'Save', 'info','application.plugins.event');
}

Does the trick, but must add the dynamicId too (i think)

I'm sure we can have the model

DenisChenu

DenisChenu

2016-07-12 10:39

developer   ~39870

Last edited: 2016-07-12 10:42

View 2 revisions

The question is :

  • Did we need to
    1. update Token model to add beforeTokenSave
    2. fix/update PluginEventBehavior to send beforeTokenSave and send the surveyId and the model

Same for Survey, then

Same for all dynamic => add the dynamicId
Same for all model => Add the model in event

/!\ Danger :
Looping ....
plugin add an event at afterTokenSave and save the token .....

This plugin can fix the looping, but diod we need to fix it before ?

In another plugin, i do:

class extendAdminStatitistics extends PluginBase
{

protected $storage = 'DbStorage';

/**

  • Did it's already own controller
    */
    private $ownController=false;
    static protected $name = 'extendAdminStatitistics';
    static protected $description = 'extend admin statitics with own controller extending the LS core controller';
    public function init()
    {
    $this->subscribe('beforeControllerAction', 'setAdminStatitistics');
    }
    public function setAdminStatitistics()
    {
    if(!$this->ownController && $this->event->get('controller')=='admin' && $this->event->get('action')=='statistics')
    {
    Yii::setPathOfAlias('extendAdminStatitistics', dirname(FILE));
    Yii::import("extendAdminStatitistics.controllers.ReplaceAdminController");
    $this->ownController=true; // Else looping
    $oAdminController= new ReplaceAdminController('admin');
    $oAdminController->run("adminStatisticsController");// to try to deactivate
    $this->event->set('run',false);
    }
    }
    }
c_schmitz

c_schmitz

2016-07-19 14:01

administrator   ~39989

I think we should fix/update PluginEventBehavior to send the beforeTokenSave with the surveyId and the model. Denis, can you do that?

DenisChenu

DenisChenu

2016-07-21 15:51

developer   ~40010

OK,

Make a pull request because : i want to remove other event :) then aestaban must test the plugin.

Choice 2 , maybe with a partial plugin (to be moved in own plugin after) in https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/plugins/Authdb/Authdb.php to send the 2 plugins.

c_schmitz

c_schmitz

2016-07-22 12:00

administrator   ~40016

The other event is generic so I think it will be very hard to remove it - it is supposed to fire for all static tables that way.

So please just introduce the beforeTokenSave - same issue should exist for all dynamic models. Therefore survey_xxx and timings_xxx might need to be fixed, too.

DenisChenu

DenisChenu

2016-07-22 13:11

developer   ~40021

No,

I mean : https://github.com/LimeSurvey/LimeSurvey/commit/c69d913562cb4bcf87453ba3f6e7ad65b6f2fcaf#diff-091a0a33007efec2513a2239ea06c9ebR706

We must have only one event at a time.
Then need :

Send dynamicId
Send object

in : https://github.com/LimeSurvey/LimeSurvey/blob/master/application/models/behaviors/PluginEventBehavior.php#L33

aesteban

aesteban

2016-07-31 01:14

developer   ~40118

@c_schmitz, @DenisChenu: Please, take a look at:

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

This is not the definitive solution you are talking about in this bug but this is better than current code.

DenisChenu

DenisChenu

2016-07-31 12:15

developer   ~40119

@aesteban : i think we can have only one event, really.

Actually 2 events :
beforeToken_12421Save + beforeTokenSave

The first beforeToken_12421Save can not be used : then it must be removed and replace by beforeTokenSave :). I get it.

Your patch really is better than the other : \o/ Do it for bedoreSurveySave too.

Then n: when fixing PluginEventBehavior i just have to remove 2 others event :).

aesteban

aesteban

2016-07-31 19:22

developer   ~40121

Merged. I fixed two issues too. I added survey id in entity field. I thinks this is better than not having this information and is correct from a DB point of view (table name is lime_token_XXXXX).

@DenisChenu: When you write the permanent solution, remember you can remove the whole save() method, not just the event call.

I will take a look at Survey case to try to reproduce this solution.

DenisChenu

DenisChenu

2018-10-06 17:09

developer   ~49276

@aesteban : i review system to add Response, but more : adding iSurveyId to TokenDynamic too https://github.com/LimeSurvey/LimeSurvey/commit/399b4f0e99e8d61ae1d40e3555a7e5c895bf2f72

DenisChenu

DenisChenu

2018-10-06 17:14

developer   ~49277

Add iSurveyID and surveyId for Timing done here https://github.com/LimeSurvey/LimeSurvey/commit/fbeb2db6fe6df46e45073e0d06f460c24508fb30

Timing is not a child of Dynamic. Still other model where need surveyId ?

Related Changesets

LimeSurvey: master 81aeb59f

2016-07-30 22:58:35

aesteban

Details Diff
Dev: Improving previous ugly solution for token changes not logged

Dev: See commit c69d913 (ugly solution) and bug 11447
mod - application/controllers/admin/tokens.php Diff File
mod - application/models/Token.php Diff File

LimeSurvey: master 399b4f0e

2018-10-06 17:07:38

DenisChenu

Details Diff
Dev: add iSurveyID and surveyId for event
Dev: Token + TokenDynamic + Response + SurveyDynamic
mod - application/models/Response.php Diff File
mod - application/models/SurveyDynamic.php Diff File
mod - application/models/Token.php Diff File
mod - application/models/TokenDynamic.php Diff File
mod - application/models/behaviors/PluginEventBehavior.php Diff File

LimeSurvey: master fbeb2db6

2018-10-06 17:12:12

DenisChenu

Details Diff
Dev: add survey id in beforeTimingSave + afterTimingSave
mod - application/models/Timing.php Diff File

LimeSurvey: master e5427b5d

2018-10-06 17:15:47

DenisChenu

Details Diff
Dev: oups … Timing didn't use sid but surveyId …
mod - application/models/Timing.php Diff File

LimeSurvey: master fd7911f8

2018-10-06 17:22:29

DenisChenu

Details Diff
Dev: fix whole … getDynamicId and method_exists
mod - application/models/Dynamic.php Diff File
mod - application/models/behaviors/PluginEventBehavior.php Diff File

LimeSurvey: master 6bb4566a

2018-10-06 19:01:53

DenisChenu

Details Diff
Dev: sid in SurveyDynamic and TokenDynamic are static …
mod - application/models/Response.php Diff File
mod - application/models/SurveyDynamic.php Diff File
mod - application/models/Token.php Diff File
mod - application/models/TokenDynamic.php Diff File
mod - application/models/behaviors/PluginEventBehavior.php Diff File

Issue History

Date Modified Username Field Change
2016-07-12 09:54 DenisChenu New Issue
2016-07-12 10:19 DenisChenu Note Added: 39869
2016-07-12 10:39 DenisChenu Note Added: 39870
2016-07-12 10:42 DenisChenu Note Edited: 39870 View Revisions
2016-07-19 14:01 c_schmitz Note Added: 39989
2016-07-19 14:01 c_schmitz Assigned To => DenisChenu
2016-07-19 14:01 c_schmitz Status new => assigned
2016-07-21 15:51 DenisChenu Note Added: 40010
2016-07-22 12:00 c_schmitz Note Added: 40016
2016-07-22 12:00 c_schmitz Priority none => normal
2016-07-22 13:11 DenisChenu Note Added: 40021
2016-07-31 01:14 aesteban Note Added: 40118
2016-07-31 12:15 DenisChenu Note Added: 40119
2016-07-31 18:25 aesteban Changeset attached => LimeSurvey master 81aeb59f
2016-07-31 19:22 aesteban Note Added: 40121
2016-09-14 16:31 DenisChenu Project Bug reports => Development
2018-10-06 17:09 DenisChenu Note Added: 49276
2018-10-06 17:09 DenisChenu Status assigned => resolved
2018-10-06 17:09 DenisChenu Resolution open => fixed
2018-10-06 17:09 DenisChenu Fixed in Version => 3.x
2018-10-06 17:14 DenisChenu Status resolved => feedback
2018-10-06 17:14 DenisChenu Resolution fixed => reopened
2018-10-06 17:14 DenisChenu Note Added: 49277
2018-10-06 17:14 DenisChenu Status feedback => resolved
2018-10-06 17:23 DenisChenu Changeset attached => LimeSurvey master fd7911f8
2018-10-06 17:23 DenisChenu Changeset attached => LimeSurvey master e5427b5d
2018-10-06 17:23 DenisChenu Changeset attached => LimeSurvey master fbeb2db6
2018-10-06 17:23 DenisChenu Changeset attached => LimeSurvey master 399b4f0e
2018-10-06 19:04 DenisChenu Changeset attached => LimeSurvey master 6bb4566a