38
38
class PluginFormcreatorInstall {
39
39
protected $ migration ;
40
40
41
+ /**
42
+ * array of upgrade steps key => value
43
+ * key is the version to upgrade from
44
+ * value is the version to upgrade to
45
+ *
46
+ * Exemple: an entry '2.0' => '2.1' tells that versions 2.0
47
+ * are upgradable to 2.1
48
+ *
49
+ * @var array
50
+ */
51
+ private $ upgradeSteps = [
52
+ '0.0 ' => '2.5 ' ,
53
+ '2.5 ' => '2.6 ' ,
54
+ '2.6 ' => '2.6.1 ' ,
55
+ '2.6.1 ' => '2.6.3 ' ,
56
+ '2.6.3 ' => '2.7 ' ,
57
+ ];
58
+
41
59
/**
42
60
* Install the plugin
43
61
* @param Migration $migration
@@ -66,43 +84,21 @@ public function install(Migration $migration) {
66
84
*/
67
85
public function upgrade (Migration $ migration ) {
68
86
$ this ->migration = $ migration ;
69
- $ fromSchemaVersion = $ this ->getSchemaVersion ();
70
-
71
- $ this ->installSchema ();
87
+ if (isset ($ _SESSION ['plugin_formcreator ' ]['cli ' ]) && $ _SESSION ['plugin_formcreator ' ]['cli ' ] == 'force-upgrade ' ) {
88
+ // Might return false
89
+ $ fromSchemaVersion = array_search (PLUGIN_FORMCREATOR_SCHEMA_VERSION , $ this ->upgradeSteps );
90
+ } else {
91
+ $ fromSchemaVersion = $ this ->getSchemaVersion ();
92
+ }
72
93
73
- // All cases are run starting from the one matching the current schema version
74
- switch ($ fromSchemaVersion ) {
75
- case '0.0 ' :
76
- require_once (__DIR__ . '/update_0.0_2.5.php ' );
77
- plugin_formcreator_update_2_5 ($ this ->migration );
78
-
79
- case '2.5 ' :
80
- require_once (__DIR__ . '/update_2.5_2.6.php ' );
81
- plugin_formcreator_update_2_6 ($ this ->migration );
82
-
83
- case '2.6 ' :
84
- require_once (__DIR__ . '/update_2.6_2.6.1.php ' );
85
- plugin_formcreator_update_2_6_1 ($ this ->migration );
86
-
87
- require_once (__DIR__ . '/update_2.6.2_2.6.3.php ' );
88
- plugin_formcreator_update_2_6_3 ($ this ->migration );
89
-
90
- require_once (__DIR__ . '/update_2.6_2.7.php ' );
91
- plugin_formcreator_update_2_7 ($ this ->migration );
92
-
93
- default :
94
- // Must be the last case
95
- if ($ this ->endsWith (PLUGIN_FORMCREATOR_VERSION , "-dev " )) {
96
- if (is_readable (__DIR__ . "/update_dev.php " ) && is_file (__DIR__ . "/update_dev.php " )) {
97
- include_once __DIR__ . "/update_dev.php " ;
98
- $ updateDevFunction = 'plugin_formcreator_update_dev ' ;
99
- if (function_exists ($ updateDevFunction )) {
100
- $ updateDevFunction ($ this ->migration );
101
- }
102
- }
103
- }
94
+ while ($ fromSchemaVersion && isset ($ this ->upgradeSteps [$ fromSchemaVersion ])) {
95
+ $ this ->upgradeOneStep ($ this ->upgradeSteps [$ fromSchemaVersion ]);
96
+ $ fromSchemaVersion = $ this ->upgradeSteps [$ fromSchemaVersion ];
104
97
}
98
+
105
99
$ this ->migration ->executeMigration ();
100
+ // if the schema contains new tables
101
+ $ this ->installSchema ();
106
102
$ this ->configureExistingEntities ();
107
103
$ this ->createRequestType ();
108
104
$ this ->createDefaultDisplayPreferences ();
@@ -112,6 +108,28 @@ public function upgrade(Migration $migration) {
112
108
return true ;
113
109
}
114
110
111
+ /**
112
+ * Proceed to upgrade of the plugin to the given version
113
+ *
114
+ * @param string $toVersion
115
+ */
116
+ protected function upgradeOneStep ($ toVersion ) {
117
+ ini_set ("max_execution_time " , "0 " );
118
+ ini_set ("memory_limit " , "-1 " );
119
+
120
+ $ suffix = str_replace ('. ' , '_ ' , $ toVersion );
121
+ $ includeFile = __DIR__ . "/upgrade_to_ $ toVersion.php " ;
122
+ if (is_readable ($ includeFile ) && is_file ($ includeFile )) {
123
+ include_once $ includeFile ;
124
+ $ updateClass = "PluginFormcreatorUpgradeTo $ suffix " ;
125
+ $ this ->migration ->addNewMessageArea ("Upgrade to $ toVersion " );
126
+ $ upgradeStep = new $ updateClass ();
127
+ $ upgradeStep ->upgrade ($ this ->migration );
128
+ $ this ->migration ->executeMigration ();
129
+ $ this ->migration ->displayMessage ('Done ' );
130
+ }
131
+ }
132
+
115
133
/**
116
134
* Find the version of the plugin
117
135
*
0 commit comments