Relationship Graph

Relationship Graph
related to related to child of child of duplicate of duplicate of

View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
16378Feature requestsPluginspublic2020-11-03 15:59
Reportergabrieljenik Assigned Toollehar  
PrioritynoneSeverityfeature 
Status newResolutionfixed 
Summary16378: New Plugin Event: beforeTokenImport
Description

Adding a new plugin event "beforeTokenImport" for the csv import, under the tokens controller.

Additional Information

BeforeTokenImport

Usage

Allows to update the token details or apply custom validations before importing a token.
The event will be fired after the standard validations are done and before saving the token.

Input

The event receives the following information:

  • importType : The type of import (ex: CSV)
  • importParams : An array cotaining the import process parameters. (ex: bFilterDuplicates => Yes)
  • recordCount : The record number for the token being processed and validated within the ongoing import process
  • token : Array with token data to be imported

Possible output

The following information can be set in the event:

  • importValid : If set to true, this token will be imported.
  • errorMessage : The error message to include in the import result summary.
  • tokenSpecificErrorMessage : The error message specific to the processed line. If this message is not set, a standard one will be used with this format: "{firstname} {lastname} ({email})"
  • token : Array with token data to be imported

Changes to Code

The event will fired from the import() method of the tokens controller (application/controllers/admin/tokens.php), after the standard validations are made and the data in $aWriteArray is complete, but before the token is saved.

Approximately before line 2171:

if (!$oToken->save())

The parameters passed to the event will be the following:

  • importType = 'CSV'
  • params = POST params (csvcharset, filterduplicatetoken, filterblankemail, allowinvalidemail, filterduplicatefields, separator, showwarningtoken)
  • recordCount = $iRecordCount
  • token = $aWriteArray

After returning from the event, the method will retrieve the output parameters.

  • If validImport is set to true, the content of the token parameter will be assigned to $aWriteArray, and the token will be created.

  • If validImportis not set to true, the token will not be imported.
    Line-level error messages (tokenSpecificErrorMessage) will be colected under a pluginErrorMessages array, indexed by the errorMessage parameter.

    $pluginErrorMessages[$errorMessage] = $tokenSpecificErrorMessage

    If tokenSpecificErrorMessage is not set, a standard message containing "First Name", "Last Name" and "Email" will be used instead.

The import results view (application/views/admin/token/csvimportresult.php) will be modified to include the lists of error messages in a similar way as the current InvalidTokenList, DuplicateList, etc.

For each errorMessage in the pluginErrorMessages, a new section will be displayed, showing the related line level messages.

TagsNo tags attached.
Bug heat8
Story point estimate
Users affected %

Relationships

related to 16785 closedgabrieljenik New Plugin Event: beforeTokenImport 

Activities

Mazi

Mazi

2020-06-11 14:54

updater   ~58246

@cdorin, @ollehar: This is a detailed documentation of the plugin event needed for our project. Please review and let us know if we can implement this as outlined.

ollehar

ollehar

2020-06-11 14:59

administrator   ~58247

@DenisChenu Comments?

DenisChenu

DenisChenu

2020-06-11 15:02

developer   ~58248

Can not be done in beforeTokenSave ?
https://manual.limesurvey.org/BeforeModelSave

In my opinion : if we add event and event and event again without global solution …

Or allow update of rules ?

And here : when adding a csv : it already take a lot time … adding an event for each lines ?

DenisChenu

DenisChenu

2020-06-11 15:04

developer   ~58249

In onBeforeSave
Since we have model ,

Find good way to set isValid to false and check if we can addError https://www.yiiframework.com/doc/api/1.1/CModel#addError-detail

gabrieljenik

gabrieljenik

2020-06-11 16:31

manager   ~58250

Hi Denis,

I thought about onBeforeSave.
I really like this event to be more powerfull. I agree with you.

The downside of that event is that on its current status:

  • The isValid is not being considered on the plugin post processing.
  • It could be hard to make the validations to only apply for the import process.
    We could use the "scenario", but still, that is somehow already used and we would need some reorganization.

On the other side, the new event could receive other parameters related to the import process specifically, as type of import, record count, import process params, ..

At last, this event shall be included on LSv3 LTS. As that we don't persuit a major feature or a code reorganization, but more an intervention oriented towards adding a validation point within a controlled scope as to minimize errors and regressions. onBeforeSave is very wide for that situation.

What do you think?

gabrieljenik

gabrieljenik

2020-06-15 16:18

manager   ~58290

@ollehar @cdorin, What do you think about it?

ollehar

ollehar

2020-06-15 16:22

administrator   ~58292

Unless Denis has any principle counter arguments, I'd say go for it. :)

DenisChenu

DenisChenu

2020-06-15 16:34

developer   ~58293

The isValid is not being considered on the plugin post processing.

We must add this :)

gabrieljenik

gabrieljenik

2020-06-16 20:01

manager   ~58316

We must add this :)

Sure we do. I have already some code I did as PoC.
Let's create a new tcketI will open a new ticket for that, if it is ok.

gabrieljenik

gabrieljenik

2020-06-16 20:02

manager   ~58317

We must add this :)
Sure we do. I have already some code I did as PoC.
Let's create a new tcketI will open a new ticket for that, if it is ok.

gabrieljenik

gabrieljenik

2020-06-16 20:02

manager   ~58318

Sorry, not good with mantis formatting

gabrieljenik

gabrieljenik

2020-06-16 21:47

manager   ~58319

I have created a new ticket for the before**Save plugin event.
https://bugs.limesurvey.org/view.php?id=16391

Please, let me know if it is OK then to work on a new beforeTokenImport plugin event.

Thanks!

DenisChenu

DenisChenu

2020-06-17 08:27

developer   ~58322

About beforeTokenImport : yes, right, hard to see how to create a plugin with current system.

But remind : if you can generalise and not create one plugin for each system …

ollehar

ollehar

2020-06-17 12:40

administrator   ~58323

Before starting any work, please make sure that the same feature can be added to LS4. So the same place of the event exists.

gabrieljenik

gabrieljenik

2020-07-16 02:22

manager   ~58964

PR for LTS: https://github.com/LimeSurvey/LimeSurvey/pull/1485

If ok, will create a different ticket for master

Mazi

Mazi

2020-07-16 08:59

updater   ~58965

Looks good!
Please make sure to also update the manual once this gets merged.

gabrieljenik

gabrieljenik

2020-07-23 21:30

manager   ~59066

Added the ImportDone parameter as @DenisChenu suggested.
Now the plugin allows to do custom importing as well.

DenisChenu

DenisChenu

2020-07-24 09:21

developer   ~59069

:+1: thank you

I don't see the update on pull request ?

DenisChenu

DenisChenu

2020-07-24 09:25

developer   ~59070

Oups … don't see it ate 1st option …

ollehar

ollehar

2020-10-23 10:21

administrator   ~60386

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

gabrieljenik

gabrieljenik

2020-11-03 15:59

manager   ~60511

Found a bug.
Corrected here: https://github.com/LimeSurvey/LimeSurvey/pull/1643

Related Changesets

LimeSurvey: 3.x-LTS 509e2f14

2020-10-23 10:21:26

ollehar


Committer: GitHub Details Diff
New feature 16378: New Plugin Event: beforeTokenImport Affected Issues
16378
mod - application/controllers/admin/tokens.php Diff File
mod - application/views/admin/token/csvimportresult.php Diff File
add - plugins/Demo/BeforeTokenImportDemo/BeforeTokenImportDemo.php Diff File

Issue History

Date Modified Username Field Change
2020-06-10 23:04 gabrieljenik New Issue
2020-06-10 23:05 gabrieljenik Additional Information Updated
2020-06-11 11:31 ollehar Project Bug reports => Feature requests
2020-06-11 14:54 Mazi Note Added: 58246
2020-06-11 14:59 ollehar Note Added: 58247
2020-06-11 15:02 DenisChenu Note Added: 58248
2020-06-11 15:04 DenisChenu Note Added: 58249
2020-06-11 16:31 gabrieljenik Note Added: 58250
2020-06-15 16:18 gabrieljenik Note Added: 58290
2020-06-15 16:22 ollehar Note Added: 58292
2020-06-15 16:34 DenisChenu Note Added: 58293
2020-06-16 20:01 gabrieljenik Note Added: 58316
2020-06-16 20:02 gabrieljenik Note Added: 58317
2020-06-16 20:02 gabrieljenik Note Added: 58318
2020-06-16 21:47 gabrieljenik Note Added: 58319
2020-06-17 08:27 DenisChenu Note Added: 58322
2020-06-17 12:40 ollehar Note Added: 58323
2020-07-16 02:22 gabrieljenik Note Added: 58964
2020-07-16 08:59 Mazi Note Added: 58965
2020-07-23 21:30 gabrieljenik Note Added: 59066
2020-07-24 09:21 DenisChenu Note Added: 59069
2020-07-24 09:25 DenisChenu Note Added: 59070
2020-10-23 10:21 ollehar Changeset attached => LimeSurvey 3.x-LTS 509e2f14
2020-10-23 10:21 ollehar Note Added: 60386
2020-10-23 10:21 ollehar Assigned To => ollehar
2020-10-23 10:21 ollehar Resolution open => fixed
2020-10-23 14:07 gabrieljenik Issue cloned: 16785
2020-10-23 14:07 gabrieljenik Relationship added related to 16785
2020-11-03 15:59 gabrieljenik Note Added: 60511