View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
19248Bug reportsPluginspublic2024-02-05 11:38
Reportergabrieljenik Assigned Totibor.pacalat  
PrioritynoneSeveritycrash 
Status closedResolutionfixed 
Product Version5.6.x 
Summary19248: When deleting a token through the model, the AuditLog beforeDeleteToken event fails
Description

The beforeDeleteToken event fails.
It expects the sTokenIds parameter.
The dynamic plugin events don't send it.

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

Relationships

related to 19325 closedtibor.pacalat When deleting a token the participant_id is being logged while it should be the token_id 

Users monitoring this issue

There are no users monitoring this issue.

Activities

gabrieljenik

gabrieljenik

2023-11-17 21:26

manager   ~78518

CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near
'LIMIT 1' at line 1. The SQL statement executed was: SELECT * FROM lime_tokens_928514 t WHERE tid= LIMIT 1
/var/www/limesurvey/vendor/yiisoft/yii/framework/db/CDbCommand.php(543)
531 {
532 if($this->_connection->enableProfiling)
533 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().$par.')','system.db.CDbCommand.query');
534
535 $errorInfo=$e instanceof PDOException ? $e->errorInfo : null;
536 $message=$e->getMessage();
537 Yii::log(Yii::t('yii','CDbCommand::{method}() failed: {error}. The SQL statement executed was: {sql}.',
538 array('{method}'=>$method, '{error}'=>$message, '{sql}'=>$this->getText().$par)),CLogger::LEVEL_ERROR,'sys
539
540 if(YII_DEBUG)
541 $message.='. The SQL statement executed was: '.$this->getText().$par;
542
543 throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
544 array('{error}'=>$message)),(int)$e->getCode(),$errorInfo);
545 }
546 }
547
548 /*
549
Builds a SQL SELECT statement from the given query specification.
550 @param array $query the query specification in name-value pairs. The following
551
query options are supported: {@link select}, {@link distinct}, {@link from},
552 {@link where}, {@link join}, {@link group}, {@link having}, {@link order},
553
{@link limit}, {@link offset} and {@link union}.
554 @throws CDbException if "from" key is not present in given query parameter
555
@return string the SQL statement
Stack Trace
#0 + /var/www/limesurvey/vendor/yiisoft/yii/framework/db/CDbCommand.php(415): CDbCommand->queryInternal()
#1 + /var/www/limesurvey/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(1359): CDbCommand->queryRow()
#2
– /var/www/limesurvey/application/models/LSActiveRecord.php(77): CActiveRecord->query()
72 @since 1.1.7
73
/
74 protected function query($criteria, $all = false, $asAR = true)
75 {
76 if ($asAR === true) {
77 return parent::query($criteria, $all);
78 } else {
79 $this->beforeFind();
80 $this->applyScopes($criteria);
81 if (!$all) {
82 $criteria->limit = 1;
#3 + /var/www/limesurvey/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(1464): LSActiveRecord->query()11/9/23, 9:14 AM CDbException
https://lime-dev.haifa.ac.il/index.php/344959 2/2
#4
– /var/www/limesurvey/application/core/plugins/AuditLog/AuditLog.php(390): CActiveRecord->find()
385 $sTokenIds = $this->getEvent()->get('sTokenIds');
386 $aTokenIds = explode(',', $sTokenIds);
387 $oCurrentUser = $this->api->getCurrentUser();
388
389 foreach ($aTokenIds as $tokenId) {
390 $token = Token::model($iSurveyID)->find('tid=' . $tokenId);
391
392 if (!is_null($token)) {
393 $aValues = $token->getAttributes();
394 $oAutoLog = $this->api->newModel($this, 'log');
395 $oAutoLog->uid = $oCurrentUser->uid;
#5 unknown(0): AuditLog->beforeTokenDelete()
#6
– /var/www/limesurvey/application/libraries/PluginManager/PluginManager.php(269): call_user_func()
264 if (
265 !$event->isStopped()
266 && (empty($target) || in_array(get_class($subscription[0]), $target))
267 ) {
268 $subscription[0]->setEvent($event);
269 call_user_func($subscription);
270 }
271 }
272 }
273
274 return $event;
#7 + /var/www/limesurvey/application/models/behaviors/PluginEventBehavior.php(99): LimeSurvey\PluginManager\PluginManager-

dispatchEvent()
#8

  • /var/www/limesurvey/application/models/behaviors/PluginEventBehavior.php(73): PluginEventBehavior->dispatchPluginModelEvent()
    #9 + /var/www/limesurvey/application/models/behaviors/PluginEventBehavior.php(43): PluginEventBehavior->dispatchDynamic()
    #10 + /var/www/limesurvey/vendor/yiisoft/yii/framework/base/CComponent.php(561): PluginEventBehavior->beforeDelete()
    #11 + /var/www/limesurvey/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(865): CComponent->raiseEvent()
    #12 + /var/www/limesurvey/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(979): CActiveRecord->onBeforeDelete()
    #13
  • /var/www/limesurvey/application/models/Token.php(118): CActiveRecord->beforeDelete()
    #14 + /var/www/limesurvey/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(1228): Token->beforeDelete()
    #15 + /var/www/limesurvey/upload/plugins/Feedback360Nomination/Feedback360Nomination.php(611): CActiveRecord->delete()
    #16 + /var/www/limesurvey/upload/plugins/Feedback360Nomination/Feedback360Nomination.php(337): Feedback360Nomination-
    deleteOtherTokens()
    #17 unknown(0): Feedback360Nomination->Invite()
    #18 + /var/www/limesurvey/application/libraries/PluginManager/PluginManager.php(269): call_user_func()
    #19 + /var/www/limesurvey/application/helpers/SurveyRuntimeHelper.php(1309): LimeSurvey\PluginManager\PluginManager->dispatchEvent()
    #20 + /var/www/limesurvey/application/helpers/SurveyRuntimeHelper.php(217): SurveyRuntimeHelper->moveSubmitIfNeeded()
    #21 + /var/www/limesurvey/application/controllers/survey/index.php(636): SurveyRuntimeHelper->run()
    #22
  • /var/www/limesurvey/application/controllers/survey/index.php(22): Index->action()
    #23 + /var/www/limesurvey/vendor/yiisoft/yii/framework/web/actions/CAction.php(76): Index->run()
    #24 + /var/www/limesurvey/vendor/yiisoft/yii/framework/web/CController.php(308): CAction->runWithParams()
    #25 + /var/www/limesurvey/vendor/yiisoft/yii/framework/web/CController.php(286): CController->runAction()
    #26 + /var/www/limesurvey/vendor/yiisoft/yii/framework/web/CController.php(265): CController->runActionWithFilters()
    #27 + /var/www/limesurvey/vendor/yiisoft/yii/framework/web/CWebApplication.php(282): CController->run()
    #28 + /var/www/limesurvey/vendor/yiisoft/yii/framework/web/CWebApplication.php(141): CWebApplication->runController()
    #29 + /var/www/limesurvey/vendor/yiisoft/yii/framework/base/CApplication.php(185): CWebApplication->processRequest()
    #30 + /var/www/limesurvey/index.php(161): CApplication->run()
    2023-11-09 09:14:27 Apache Yii Framework/1.1.2
DenisChenu

DenisChenu

2023-11-18 10:24

developer   ~78519

Last edited: 2023-11-18 10:24

Issue in the plugin : https://manual.limesurvey.org/Dynamic_model_events

PS : save as HTML the error is really more easy to read

gabrieljenik

gabrieljenik

2023-11-21 12:19

manager   ~78581

PS : save as HTML the error is really more easy to read

Yes, I know, I hadn't had this like that :)
Save as PDF is even better.

gabrieljenik

gabrieljenik

2023-11-21 12:21

manager   ~78582

Issue in the plugin : https://manual.limesurvey.org/Dynamic_model_events

I believe the best is to just rename the event on dev.
beforeTokenDelete --> beforeTokenDeleteManually

DenisChenu

DenisChenu

2023-11-21 15:18

developer   ~78593

Save as PDF is even better.

O no !
Clearly as HTML : you have whole page

I believe the best is to just rename the event on dev.

No ! it's an issue in the plugin, all ModelVeent receive model and not model->primaryKey

The issue is here : https://github.com/LimeSurvey/LimeSurvey/blob/b647c39b3c1ccf9dfc7375c83f58f4293b570fbf/application/core/plugins/AuditLog/AuditLog.php#L385

And for BeforeDeleteMany filterCriteria

See BeforeTokenSave
https://github.com/LimeSurvey/LimeSurvey/blob/7841783033bdf80f1b4a2ecc84f1f1153924028b/plugins/AuditLog/AuditLog.php#L342
or beforeParticipantDelete
https://github.com/LimeSurvey/LimeSurvey/blob/7841783033bdf80f1b4a2ecc84f1f1153924028b/plugins/AuditLog/AuditLog.php#L451

gabrieljenik

gabrieljenik

2023-11-21 17:08

manager   ~78604

Clearly as HTML : you have whole page

As PDF as well.

Look at this:
https://github.com/LimeSurvey/LimeSurvey/blob/b647c39b3c1ccf9dfc7375c83f58f4293b570fbf/application/controllers/admin/Tokens.php#L895

DenisChenu

DenisChenu

2023-11-21 17:12

developer   ~78605

Look at this:

Arg … it's a specific one then …

Unsure if both happen ?

DenisChenu

DenisChenu

2023-11-21 17:21

developer   ~78606

You know where this delete action is done ?

DenisChenu

DenisChenu

2023-11-21 17:29

developer   ~78607

Last edited: 2023-11-21 17:38

OK,

I think both can happen

Maybe just fix

$sTokenIds = $this->getEvent()->get('sTokenIds');
if (!$sTokenIds) {
return;
}
$aTokenIds = array_filter(explode(',', (string) $sTokenIds));
etc …

PS : you can fix it, don't really want to fix it …

PS : with pdf : you can not click on + to show hide content

gabrieljenik

gabrieljenik

2023-11-21 17:54

manager   ~78610

That could work, but wouldn't be logging in case someone deletes the model from a plugin, for example.
Also, to note, I believe deleteByPk is not triggering the events.

DenisChenu

DenisChenu

2023-11-21 18:20

developer   ~78612

Also, to note, I believe deleteByPk is not triggering the events.

Unsure here

gabrieljenik

gabrieljenik

2023-11-21 21:22

manager   ~78614

Last edited: 2023-11-21 21:23

Also, to note, I believe deleteByPk is not triggering the events.

https://forum.yiiframework.com/t/before-after-delete-strange-behavior/16050/4

Maybe on LSActiveRecord or on some classes we should overload deleteByPk() and deleteAll() as to make sure the events get triggered?
@ollehar ?

DenisChenu

DenisChenu

2023-11-22 08:49

developer   ~78615

Last edited: 2023-11-22 08:50

Maybe on LSActiveRecord or on some classes we should overload deleteByPk() and deleteAll() as to make sure the events get triggered?

New feature :) and add deleteAllByAttributes
maybe with a different name ? Or an extra param ?

Else : we have same issue with updateAll or updateByPk or updateByAttributes

gabrieljenik

gabrieljenik

2023-12-11 21:32

manager   ~78950

Ok, this is what I believe happened.

  • The event is old. This one was created as a regular event. Then, with time, it got incorporated in the dynamic events mechanism.

  • When that happened, the parameters changed. But the plugin was still using the old ones.

  • The old event is not called from anywhere in the code, so the plugin did not fail.

  • What it is actually being called is beforeTokenDeleteMany, which is triggered from actions on the controller.

So, my call would be to:

  • Adapt auditolog for using both BeforeTokenDelete and BeforeTokenDeleteMany
  • BeforeTokenDeleteMany doesn't have the ids as parameters but it has the criteria. So you need to query the db to get the ids.
  • BeforeTokenDelete relies on sTokenIds parameter. We would need to adapt that to use the id from the model parameter.

As this is used by security areas, I would add automated tests to the plugin.

Thoughts?

gabrieljenik

gabrieljenik

2023-12-23 14:47

manager   ~79065

PR Master: https://github.com/LimeSurvey/LimeSurvey/pull/3676

When ready will also update v5.

gabrieljenik

gabrieljenik

2023-12-29 20:43

manager   ~79076

v5 https://github.com/LimeSurvey/LimeSurvey/pull/3681

guest

guest

2024-01-08 18:57

viewer   ~79107

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

guest

guest

2024-01-31 15:01

viewer   ~79367

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

guest

guest

2024-01-31 15:01

viewer   ~79368

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

LimeBot

LimeBot

2024-02-05 11:38

administrator   ~79417

Fixed in Release 5.6.54+240206

Related Changesets

LimeSurvey: master d59ca854

2024-01-08 18:57:38

Gabriel Jenik


Committer: GitHub Details Diff
Fixed issue 19248: When deleting a token through the model, the AuditLog beforeDeleteToken event fails (#3676)

Co-authored-by: lapiudevgit <devgit@lapiu.biz>
Affected Issues
19248
mod - application/core/plugins/AuditLog/AuditLog.php Diff File

LimeSurvey: 5.x 11b12409

2024-01-31 15:01:27

Gabriel Jenik


Committer: GitHub Details Diff
Fixed issue 19248: When deleting a token through the model, the Audi… …tLog beforeDeleteToken event fails (#3681)

Co-authored-by: lapiudevgit <devgit@lapiu.biz>
Affected Issues
19248
mod - application/core/plugins/AuditLog/AuditLog.php Diff File

LimeSurvey: 5.x 11b12409

2024-01-31 15:01:27

Gabriel Jenik


Committer: GitHub Details Diff
Fixed issue 19248: When deleting a token through the model, the Audi… …tLog beforeDeleteToken event fails (#3681)

Co-authored-by: lapiudevgit <devgit@lapiu.biz>
Affected Issues
19248
mod - application/core/plugins/AuditLog/AuditLog.php Diff File

Issue History

Date Modified Username Field Change
2023-11-17 21:20 gabrieljenik New Issue
2023-11-17 21:21 gabrieljenik Assigned To => gabrieljenik
2023-11-17 21:21 gabrieljenik Status new => confirmed
2023-11-17 21:21 gabrieljenik Category Survey participants (Tokens) => Plugins
2023-11-17 21:21 gabrieljenik Summary When deleting a token through the model, the beforeDeleteToken event fails => When deleting a token through the model, the AuditLog beforeDeleteToken event fails
2023-11-17 21:26 gabrieljenik Note Added: 78518
2023-11-17 21:26 gabrieljenik Bug heat 0 => 2
2023-11-18 10:24 DenisChenu Note Added: 78519
2023-11-18 10:24 DenisChenu Bug heat 2 => 4
2023-11-18 10:24 DenisChenu Note Edited: 78519
2023-11-21 12:19 gabrieljenik Note Added: 78581
2023-11-21 12:21 gabrieljenik Note Added: 78582
2023-11-21 15:18 DenisChenu Note Added: 78593
2023-11-21 15:18 DenisChenu Assigned To gabrieljenik => DenisChenu
2023-11-21 15:18 DenisChenu Status confirmed => assigned
2023-11-21 17:08 gabrieljenik Note Added: 78604
2023-11-21 17:12 DenisChenu Note Added: 78605
2023-11-21 17:21 DenisChenu Note Added: 78606
2023-11-21 17:29 DenisChenu Status assigned => confirmed
2023-11-21 17:29 DenisChenu Note Added: 78607
2023-11-21 17:29 DenisChenu Assigned To DenisChenu =>
2023-11-21 17:30 DenisChenu Note Edited: 78607
2023-11-21 17:38 DenisChenu Note Edited: 78607
2023-11-21 17:54 gabrieljenik Note Added: 78610
2023-11-21 18:20 DenisChenu Note Added: 78612
2023-11-21 21:22 gabrieljenik Note Added: 78614
2023-11-21 21:23 gabrieljenik Note Edited: 78614
2023-11-22 08:49 DenisChenu Note Added: 78615
2023-11-22 08:50 DenisChenu Note Edited: 78615
2023-12-06 17:47 gabrieljenik Assigned To => gabrieljenik
2023-12-06 17:47 gabrieljenik Status confirmed => assigned
2023-12-11 21:32 gabrieljenik Note Added: 78950
2023-12-23 14:47 gabrieljenik Note Added: 79065
2023-12-23 14:47 gabrieljenik Assigned To gabrieljenik => DenisChenu
2023-12-23 14:47 gabrieljenik Status assigned => ready for code review
2023-12-23 18:59 DenisChenu Assigned To DenisChenu => gabrieljenik
2023-12-23 18:59 DenisChenu Status ready for code review => ready for testing
2023-12-26 18:19 gabrieljenik Issue cloned: 19325
2023-12-26 18:19 gabrieljenik Relationship added related to 19325
2023-12-26 18:20 gabrieljenik Assigned To gabrieljenik => tibor.pacalat
2023-12-29 20:43 gabrieljenik Note Added: 79076
2024-01-08 18:57 Changeset attached => LimeSurvey master d59ca854
2024-01-08 18:57 guest Note Added: 79107
2024-01-08 18:57 guest Bug heat 4 => 6
2024-01-31 15:01 Changeset attached => LimeSurvey 5.x 11b12409
2024-01-31 15:01 Changeset attached => LimeSurvey 5.x 11b12409
2024-01-31 15:01 guest Note Added: 79367
2024-01-31 15:01 guest Note Added: 79368
2024-01-31 15:01 tibor.pacalat Status ready for testing => resolved
2024-01-31 15:01 tibor.pacalat Resolution open => fixed
2024-02-05 11:38 LimeBot Note Added: 79417
2024-02-05 11:38 LimeBot Status resolved => closed
2024-02-05 11:38 LimeBot Bug heat 6 => 8