Skip to content

Commit afb9f3b

Browse files
committed
Merge branch 'release/3.3.1'
2 parents 9e1046b + 806924a commit afb9f3b

6 files changed

+63
-200
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to the Form Render Skip Logic module will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [3.3.1] - 2018-08-13
6+
### Changed
7+
- Refactor 2.x - 3.x migration in order to use External Modules API functions. (Tiago Bember Simeao)
8+
59

610
## [3.3.0] - 2018-08-09
711
### Added

ExternalModule.php

+52-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Calculate;
1010
use ExternalModules\AbstractExternalModule;
1111
use ExternalModules\ExternalModules;
12-
use FormRenderSkipLogic\Migration\Migration;
1312
use Form;
1413
use LogicTester;
1514
use Piping;
@@ -19,8 +18,6 @@
1918
use RCView;
2019
use REDCap;
2120

22-
require_once dirname(__FILE__) . '/Migration.php';
23-
2421
/**
2522
* ExternalModule class for REDCap Form Render Skip Logic.
2623
*/
@@ -102,14 +99,59 @@ function redcap_save_record($project_id, $record = null, $instrument, $event_id,
10299
* @inheritdoc
103100
*/
104101
function redcap_module_system_change_version($version, $old_version) {
105-
$this->migrateSettings();
106-
}
102+
if (strpos($old_version, 'v2.') !== 0 || $version[0] != 'v' || !is_numeric($version[1]) || $version[1] < 3) {
103+
return;
104+
}
107105

108-
/**
109-
* @inheritdoc
110-
*/
111-
function redcap_module_system_enable($version) {
112-
$this->migrateSettings();
106+
// Migrating settings from version 2.x to 3.x.
107+
foreach (ExternalModules::getEnabledProjects($this->PREFIX) as $project) {
108+
$pid = $project['project_id'];
109+
110+
if ($this->getProjectSetting('control_field', $pid) === null || $this->getProjectSetting('control_fields', $pid) !== null) {
111+
// Skip if there is no config from v2 available or if there is
112+
// already config from v3.
113+
continue;
114+
}
115+
116+
$conds = array_combine(
117+
$this->getProjectSetting('instrument_name', $pid),
118+
$this->getProjectSetting('control_field_value', $pid)
119+
);
120+
121+
$bl = array();
122+
foreach ($conds as $form => $value) {
123+
if (!isset($bl[$value])) {
124+
$bl[$value] = array();
125+
}
126+
127+
$bl[$value][] = $form;
128+
}
129+
130+
$target_forms = array();
131+
foreach ($bl as $forms) {
132+
$target_forms[] = array_values($forms);
133+
}
134+
135+
$count = count($bl);
136+
$settings = array(
137+
'control_fields' => array('true'),
138+
'control_mode' => array('default'),
139+
'control_piping' => array(null),
140+
'control_default_value' => array(null),
141+
'control_event_id' => $this->getProjectSetting('event_name', $pid),
142+
'control_field_key' => $this->getProjectSetting('field_name', $pid),
143+
'branching_logic' => array(array_fill(0, $count, 'true')),
144+
'condition_value' => array(array_map('strval', array_keys($bl))),
145+
'condition_operator' => array(array_fill(0, $count, null)),
146+
'target_events_select' => array(array_fill(0, $count, false)),
147+
'target_events' => array(array_fill(0, $count, array(null))),
148+
'target_forms' => array($target_forms),
149+
);
150+
151+
foreach ($settings as $key => $value) {
152+
$this->setProjectSetting($key, $value, $pid);
153+
}
154+
}
113155
}
114156

115157
/**
@@ -563,19 +605,4 @@ function _calculateCondition($a, $b, $op = '=') {
563605

564606
return $a === $b;
565607
}
566-
567-
/**
568-
* migrates stored module settings from v2.x.x to v3.x.x if needed.
569-
*/
570-
function migrateSettings() {
571-
$migrate = new Migration($this->PREFIX);
572-
573-
//migrate settings only if version 2 settings exist and version 3 settings
574-
//do not exist.
575-
if ($migrate->checkIfVersionSettingsExist("v2.0.0") && !$migrate->checkIfVersionSettingsExist("v3.0.0")) {
576-
$old_setting = $migrate->getV2Settings();
577-
$new_setting = $migrate->convertV2SettingsToV3Settings($old_setting);
578-
$migrate->storeV3Settings($new_setting);
579-
}
580-
}
581608
}

Migration.php

-172
This file was deleted.

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ If you want to make sure no filled forms will be affected by FRSL rules, check "
5757

5858
## Upgrading From Version 2.x - 3.x
5959

60-
Note that version 3.0.0 introduced a breaking change in the configuration. When you upgrade to version 3.x all of your old configurations in 2.x will be converted into the 3.x configuration scheme. This migration only occurs the first time you upgrade from 2.x to 3.x . Thereafter, if you decided to switch back and forth between the two versions, your configurations will not transfer. This is to ensure that all of your old 2.x configurations will still be available to you if you decide to go back to version 2.x .
60+
Note that version 3.0.0 introduced a breaking change in the configuration. When you upgrade to version 3.x all of your old configurations in 2.x will be converted into the 3.x configuration scheme. Thereafter, if you decided to switch back and forth between the two versions, your configurations will not transfer. This is to ensure that all of your old 2.x configurations will still be available to you if you decide to go back to version 2.x.
61+
62+
#### Important
63+
This migration only occurs the first time you upgrade from 2.x to 3.x - and only for the projects that already have FRSL enabled.
64+
65+
![Settings migration](img/migration.png)

config.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"redcap_data_entry_form_top",
99
"redcap_survey_page_top",
1010
"redcap_save_record",
11-
"redcap_module_system_change_version",
12-
"redcap_module_system_enable"
11+
"redcap_module_system_change_version"
1312
],
1413
"authors": [
1514
{

img/migration.png

18.7 KB
Loading

0 commit comments

Comments
 (0)