Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
update_squiz_logo_login_design.php
1 <?php
28 ini_set('memory_limit', -1);
29 error_reporting(E_ALL);
30 $SYSTEM_ROOT = '';
31 
32 if ((php_sapi_name() == 'cli')) {
33  if (isset($_SERVER['argv'][1])) {
34  $SYSTEM_ROOT = $_SERVER['argv'][1];
35  }
36 
37  $err_msg = "ERROR: You need to supply the path to the System Root as the first argument\n";
38 
39 } else {
40  if (isset($_GET['SYSTEM_ROOT'])) {
41  $SYSTEM_ROOT = $_GET['SYSTEM_ROOT'];
42  }
43 
44  $err_msg = '
45  <div style="background-color: red; color: white; font-weight: bold;">
46  You need to supply the path to the System Root as a query string variable called SYSTEM_ROOT
47  </div>
48  ';
49 }
50 
51 if (empty($SYSTEM_ROOT)) {
52  $err_msg .= "Usage: php install/step_01.php <PATH_TO_MATRIX>\n";
53  echo $err_msg;
54  exit();
55 }
56 
57 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
58  $err_msg = "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
59  $err_msg .= "Usage: php install/step_01.php <PATH_TO_MATRIX>\n";
60  echo $err_msg;
61  exit();
62 }
63 
64 $SYSTEM_ROOT = realpath($SYSTEM_ROOT);
65 
66 if (!defined('SQ_SYSTEM_ROOT')) {
67  define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
68 }
69 require_once $SYSTEM_ROOT.'/core/include/init.inc';
70 require_once $SYSTEM_ROOT.'/install/install.inc';
71 require_once $SYSTEM_ROOT.'/core/include/general_occasional.inc';
72 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
73 
74 echo 'Updating new Squiz Logo for login design, password change design, EES login design ...'."\n";
75 
76 echo "\n";
77 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
78 
79 $design_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('designs_folder');
80 $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($design_folder->id, 'design', FALSE);
81 $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
82 
83 foreach ($children as $id => $content) {
84  if(!isset($content[0]['type_code'])) {
85  trigger_error('can not find type code of designs');
86  continue;
87  }
88  switch ($content[0]['type_code']) {
89  case 'login_design':
90  $file_name = 'login_image.gif';
91  $path = $SYSTEM_ROOT.'/core/assets/system/login_design/design_files/files/'.$file_name;
92  $md5 = '99029df0982274ce2f1c3404b6902f0f';
93  break;
94  case 'password_change_design':
95  $file_name = 'login_image.gif';
96  $path = $SYSTEM_ROOT.'/core/assets/system/password_change_design/design_files/files/'.$file_name;
97  $md5 = '99029df0982274ce2f1c3404b6902f0f';
98  break;
99  case 'ees_login_design':
100  $file_name = 'matrix-logo.png';
101  $path = $SYSTEM_ROOT.'/core/assets/system/ees_login_design/design_files/files/'.$file_name;
102  $md5 = '9ade1af14bab1611aef70b91f1401d3e';
103  //parse file
104  $new_parse_file = $SYSTEM_ROOT.'/core/assets/system/ees_login_design/design_files/index.html';
105  $parse_file_md5_3_28 = 'cd9c6761bae67fdc78474a540a096e58';
106  $parse_file_md5_3_29 = '15c8ab31d536fac3c6035da4d601e690';
107  break;
108  default:
109  continue;
110  }
111 
112  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
113  $design_edit_fns = $design->getEditFns();
114  $type_code = $design->type();
115 
116 
117  // Update design parse file for ees_login_design, there is some css changes
118  if($type_code === 'ees_login_design') {
119  $parse_file = $design->data_path.'/parse.txt';
120  $parse_file_md5 = md5(file_get_contents($parse_file));
121  if($parse_file_md5 !== $parse_file_md5_3_28 && $parse_file_md5 !== $parse_file_md5_3_29) {
122  echo 'Parse file in '.$type_code.' was modified. Skip...'."\n";
123  }
124  else if (!is_file($parse_file) || !is_file($new_parse_file)) {
125  trigger_error ('parse file is not available');
126  }
127  else {
128 
129  // update the parse file
130  if(!_updateFile($new_parse_file, 'parse.txt', $design->data_path, $design->data_path_suffix)) {
131  trigger_error('failed to update ees parse file '.$file_name);
132  exit();
133  }
134 
135  $design_edit_fns->parseAndProcessFile($design);
136  $design->generateDesignFile();
137 
138  echo 'Parse file in ees_login_design. Successfully updated...'."\n";
139  }
140  }
141 
142 
143  // Update logo
144  $existing_ids = Array();
145  $existing = $GLOBALS['SQ_SYSTEM']->am->getLinks($design->id, SQ_LINK_TYPE_2, 'file', FALSE);
146 
147  foreach ($existing as $link) {
148  $existing_ids[$link['minorid']] = $link['linkid'];
149  }
150 
151  $existing_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($existing_ids));
152 
153  // must web-path-ify the new file name to compare, as this is eventually
154  // it's what the file will be named
155  $file_name = make_valid_web_paths(Array($file_name));
156  $file_name = array_shift($file_name);
157 
158  $existing_fileid = 0;
159  // only pick up the file we want to update
160  foreach ($existing_info as $asset_id => $asset_info) {
161  if ($asset_info['name'] == $file_name) {
162  $existing_fileid = $asset_id;
163  break;
164  }
165  }
166 
167  if(empty($existing_fileid)) {
168  trigger_error('Can not find original logo image');
169  exit();
170  }
171 
172  // we already have a design file with the same name, so just upload over the top of it
173  $file = $GLOBALS['SQ_SYSTEM']->am->getAsset($existing_fileid);
174 
175  // check MD5 hash, make sure it is the file we want to update
176  $file_info = $file->getExistingFile();
177  if(md5_file($file_info['path']) !== $md5) {
178  echo $file_name.' in '.$type_code.' was modified. Skip...'."\n";
179  continue;
180  }
181 
182  // update the actual logo file
183  if(!_updateFile($path, $file_name, $file->data_path, $file->data_path_suffix)) {
184  trigger_error('failed to update logo '.$file_name);
185  exit();
186  }
187 
188 
189  echo $file_name.' in '.$type_code.'. Successfully updated...'."\n";
190 
191 }
192 
193 echo 'Done'."\n";
194 
195 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
196 
197 
198 
199 
206 function _updateFile ($new_file, $file_name, $data_path, $data_path_suffix) {
207  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
208  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
209 
210  $file_path = $data_path.'/'.$file_name;
211 
212  if (!unlink($file_path)) {
213  trigger_error('failed to remove old file '.$file_name);
214  return FALSE;
215  }
216 
217  // copy over the new logo
218  if (string_to_file(file_get_contents($new_file), $file_path)) {
219  // add a new version to the repository
220  $file_status = $fv->upToDate($file_path);
221  if (FUDGE_FV_MODIFIED & $file_status) {
222  if (!$fv->commit($file_path, '')) {
223  trigger_localised_error('CORE0160', E_USER_WARNING);
224  }
225  }
226  } else {
227  trigger_error('Can not overwrite old file '.$file_name);
228  }
229 
230  // make sure we have the latest version of our file
231  if (!$fv->checkOut($data_path_suffix.'/'.$file_name, $data_path)) {
232  trigger_localised_error('CORE0032', E_USER_WARNING);
233  return FALSE;
234  }//end if
235 
236 
237  return TRUE;
238 }//end _updateFile
239 
240 ?>