|
9 | 9 | use Calculate;
|
10 | 10 | use ExternalModules\AbstractExternalModule;
|
11 | 11 | use ExternalModules\ExternalModules;
|
12 |
| -use FormRenderSkipLogic\Migration\Migration; |
13 | 12 | use Form;
|
14 | 13 | use LogicTester;
|
15 | 14 | use Piping;
|
|
19 | 18 | use RCView;
|
20 | 19 | use REDCap;
|
21 | 20 |
|
22 |
| -require_once dirname(__FILE__) . '/Migration.php'; |
23 |
| - |
24 | 21 | /**
|
25 | 22 | * ExternalModule class for REDCap Form Render Skip Logic.
|
26 | 23 | */
|
@@ -102,14 +99,59 @@ function redcap_save_record($project_id, $record = null, $instrument, $event_id,
|
102 | 99 | * @inheritdoc
|
103 | 100 | */
|
104 | 101 | 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 | + } |
107 | 105 |
|
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 | + } |
113 | 155 | }
|
114 | 156 |
|
115 | 157 | /**
|
@@ -563,19 +605,4 @@ function _calculateCondition($a, $b, $op = '=') {
|
563 | 605 |
|
564 | 606 | return $a === $b;
|
565 | 607 | }
|
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 |
| - } |
581 | 608 | }
|
0 commit comments