Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
update_system_design_parse_file.php
1 <?php
29 ini_set('memory_limit', -1);
30 error_reporting(E_ALL);
31 $SYSTEM_ROOT = '';
32 
33 if ((php_sapi_name() == 'cli')) {
34  if (isset($_SERVER['argv'][1])) {
35  $SYSTEM_ROOT = $_SERVER['argv'][1];
36  }
37 
38  $err_msg = "ERROR: You need to supply the path to the System Root as the first argument\n";
39 
40 } else {
41  if (isset($_GET['SYSTEM_ROOT'])) {
42  $SYSTEM_ROOT = $_GET['SYSTEM_ROOT'];
43  }
44 
45  $err_msg = '
46  <div style="background-color: red; color: white; font-weight: bold;">
47  You need to supply the path to the System Root as a query string variable called SYSTEM_ROOT
48  </div>
49  ';
50 }
51 
52 if (empty($SYSTEM_ROOT)) {
53  $err_msg .= "Usage: php install/step_01.php <PATH_TO_MATRIX>\n";
54  echo $err_msg;
55  exit();
56 }
57 
58 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
59  $err_msg = "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
60  $err_msg .= "Usage: php install/step_01.php <PATH_TO_MATRIX>\n";
61  echo $err_msg;
62  exit();
63 }
64 
65 $SYSTEM_ROOT = realpath($SYSTEM_ROOT);
66 
67 if (!defined('SQ_SYSTEM_ROOT')) {
68  define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
69 }
70 require_once $SYSTEM_ROOT.'/core/include/init.inc';
71 require_once $SYSTEM_ROOT.'/install/install.inc';
72 require_once $SYSTEM_ROOT.'/core/include/general_occasional.inc';
73 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
74 
75 echo 'Updating parse files of login designs for #5038'."\n";
76 echo "\n";
77 
78 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
79 
80 $design_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('designs_folder');
81 $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($design_folder->id, 'design', FALSE);
82 $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
83 
84 foreach ($children as $id => $content) {
85  if(!isset($content[0]['type_code'])) {
86  trigger_error('can not find type code of designs');
87  continue;
88  }
89 
90  echo "Updating design #".$id."\n";
91  //parse file
92  switch ($content[0]['type_code']) {
93  case 'login_design':
94  $new_parse_file = $SYSTEM_ROOT.'/core/assets/system/login_design/design_files/index.html';
95  $source_parse_file_md5 = '38c31c49d16ae6dee3e2a47e693ba003';
96  break;
97  case 'password_change_design':
98  $new_parse_file = $SYSTEM_ROOT.'/core/assets/system/password_change_design/design_files/index.html';
99  $source_parse_file_md5 = '228a10aa65433b652f32f1c3b4037b3e';
100  break;
101  case 'ees_login_design':
102  $new_parse_file = $SYSTEM_ROOT.'/core/assets/system/ees_login_design/design_files/index.html';
103  $source_parse_file_md5 = 'f0acced582b5b9d355ce2a4b22595cc1';
104  break;
105  default:
106  continue;
107  }//end switch
108 
109  $new_file = file_get_contents($new_parse_file);
110  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
111  $design_edit_fns = $design->getEditFns();
112  $type_code = ucwords(str_replace('_', ' ', $design->type()));
113 
114 
115  // Update design parse file for ees_login_design, there is some css changes
116  $parse_file = $design->data_path.'/parse.txt';
117  $ext_file = file_get_contents($parse_file);
118  $parse_file_md5 = md5(file_get_contents($parse_file));
119  if ($parse_file_md5 != $source_parse_file_md5) {
120  echo 'Parse file in '.$type_code.' was modified. Skipping.'."\n";
121  }
122  else if (!is_file($parse_file) || !is_file($new_parse_file)) {
123  trigger_error ('parse file is not available');
124  }
125  else {
126 
127  // update the parse file
128  if(!_updateFile($new_parse_file, 'parse.txt', $design->data_path, $design->data_path_suffix)) {
129  trigger_error('failed to update parse file '.$new_parse_file);
130  exit();
131  }
132 
133  $design_edit_fns->parseAndProcessFile($design);
134  $design->generateDesignFile();
135 
136  echo 'Parse file in '.$type_code.' Successfully updated...'."\n";
137  }
138 }
139 
140 echo "\n".'All desings updated successfully'."\n";
141 
142 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
143 $GLOBALS['SQ_SYSTEM']->am->forgetAsset($design_folder->id, TRUE);
144 
145 
146 
153 function _updateFile ($new_file, $file_name, $data_path, $data_path_suffix) {
154  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
155  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
156 
157  $file_path = $data_path.'/'.$file_name;
158 
159  if (!unlink($file_path)) {
160  trigger_error('failed to remove old file '.$file_name);
161  return FALSE;
162  }
163 
164  if (string_to_file(file_get_contents($new_file), $file_path)) {
165  // add a new version to the repository
166  $file_status = $fv->upToDate($file_path);
167  if (FUDGE_FV_MODIFIED & $file_status) {
168  if (!$fv->commit($file_path, '')) {
169  trigger_localised_error('CORE0160', E_USER_WARNING);
170  }
171  }
172  } else {
173  trigger_error('Can not overwrite old file '.$file_name);
174  }
175 
176  // make sure we have the latest version of our file
177  if (!$fv->checkOut($data_path_suffix.'/'.$file_name, $data_path)) {
178  trigger_localised_error('CORE0032', E_USER_WARNING);
179  return FALSE;
180  }//end if
181 
182 
183  return TRUE;
184 }//end _updateFile
185 
186 ?>