Commit 90097c594d47da903a81fe4b2239f4db917658f5

Authored by Benjamin Renard
1 parent 14f84041

Create a backup before WS migration

src/InputOutput/IHMImpl/Config/IHMConfigClass.php
... ... @@ -49,6 +49,8 @@ class IHMConfigClass
49 49  
50 50 private static $processMgrFile = "processManager.xml";
51 51  
  52 + private static $migrationBackupDir = "MIGRATION_BACKUP";
  53 +
52 54 private static $jobsMgrFile = "jobs.xml";
53 55  
54 56 private static $userParamMgrFile = "WsParams.xml";
... ... @@ -112,6 +114,20 @@ class IHMConfigClass
112 114 {
113 115 return self::getDataDir().self::$processMgrFile;
114 116 }
  117 +
  118 + public static function getMigrationBackupPath($version)
  119 + {
  120 + $backupPath = self::getDataDir().self::$migrationBackupDir;
  121 + if (!is_dir($backupPath))
  122 + mkdir($backupPath);
  123 + $backupPath .= ("".$version."/");
  124 + if (!is_dir($backupPath))
  125 + mkdir($backupPath);
  126 + $backupPath .= (self::$userName.'/');
  127 + if (!is_dir($backupPath))
  128 + mkdir($backupPath);
  129 + return mkdir($backupPath);
  130 + }
115 131  
116 132 public static function getGenericDataPath()
117 133 {
... ...
src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php
... ... @@ -56,7 +56,6 @@ class IHMUserWSManagerClass
56 56 if (empty($this->wsInfo)) {
57 57 return FALSE;
58 58 }
59   - $this->wsInfo["version"] = 0;// DEBUG - To Remove!!!
60 59  
61 60 return TRUE;
62 61 }
... ... @@ -161,20 +160,32 @@ class IHMUserWSManagerClass
161 160 }
162 161 }
163 162 }
  163 +
  164 + if (!empty($split_plot)) {
  165 + //Backup
  166 + $backupPath = IHMConfigClass::getMigrationBackupPath($this->wsInfo['version']);
  167 + copy($req_mgr_file_path, $backupPath.basename($req_mgr_file_path));
  168 + foreach ($split_plot as $old_key => $split) {
  169 + $req_data_path = IHMConfigClass::getStoredRequestPath() . $old_key;
  170 + copy($req_data_path, $backupPath.basename($req_data_path));
  171 + }
164 172  
165   - //Apply split in user requests file
166   - foreach ($split_plot as $old_key => $split) {
167   - $parentNode = $plot_requests[$old_key]->parentNode;
168   - $parentNode->removeChild($plot_requests[$old_key]);
169   - foreach ($split as $new_key => $new_name) {
170   - $new_node = $dom->createElement("request");
171   - $new_node->setAttribute("xml:id", $new_key);
172   - $new_node->setAttribute("name", $new_name);
173   - $parentNode->appendChild($new_node);
  173 + //Apply split in user requests file + cleanup
  174 + foreach ($split_plot as $old_key => $split) {
  175 + $parentNode = $plot_requests[$old_key]->parentNode;
  176 + $parentNode->removeChild($plot_requests[$old_key]);
  177 + unlink(IHMConfigClass::getStoredRequestPath() . $old_key);
  178 + foreach ($split as $new_key => $new_name) {
  179 + $new_node = $dom->createElement("request");
  180 + $new_node->setAttribute("xml:id", $new_key);
  181 + $new_node->setAttribute("name", $new_name);
  182 + $parentNode->appendChild($new_node);
  183 + }
174 184 }
  185 +
  186 + $dom->save($req_mgr_file_path);
175 187 }
176 188  
177   - $dom->save($req_mgr_file_path);
178 189 return TRUE;
179 190 }
180 191 }
... ...