Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
ees_login_design_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
32 {
33 
34 
42  {
43  Asset_Management::__construct($pm);
44 
45  $this->vars = Array(
46  'id_name' => Array(
47  'default' => 'EES Login Design',
48  ),
49  );
50 
51  }//end constructor
52 
53 
62  function _upgrade($current_version)
63  {
64  if (!parent::_upgrade($current_version)) return FALSE;
65  if (version_compare($current_version, '0.2', '<')) {
66  // version 0.1 -> 0.2
67  // There is some css changes to default ees login design
68  // if no custom changes has ever been made, we should automatically restore it to default
69  pre_echo('STARTING EES LOGIN DESIGN UPGRADE - FROM VERSION 0.1');
70 
71  $new_parse_file = SQ_SYSTEM_ROOT.'/core/assets/system/ees_login_design/design_files/index.html';
72  // for all possible previous versions of parse file (different commit person, date)
73  // compare md5 sum to make sure no custom changes has been made
74  $source_parse_file_md5 = Array();
75  $source_parse_file_md5[] = 'a0596932a27bffbd9347d3944e9711de';
76  $source_parse_file_md5[] = '5ad7fd75432a2df88880779a4b2804bd';
77  $source_parse_file_md5[] = 'ffdfb655681c6c05abff6163240a46af';
78  $source_parse_file_md5[] = '46c990414c686b66bc8f949d124010bf';
79  $source_parse_file_md5[] = 'c00cf668108207f1a41a50ab767cb42d';
80  $source_parse_file_md5[] = 'c9f3ec8e7860951262e40de8e034c57c';
81 
82  $new_file = file_get_contents($new_parse_file);
83  $design = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('ees_login_design');
84  $design_edit_fns = $design->getEditFns();
85 
86 
87  // Update design parse file for ees_login_design, there is some css changes
88  $parse_file = $design->data_path.'/parse.txt';
89  $ext_file = file_get_contents($parse_file);
90  $parse_file_md5 = md5(file_get_contents($parse_file));
91 
92  $can_restore = FALSE;
93  foreach ($source_parse_file_md5 as $md5key) {
94  if ($parse_file_md5 == $md5key) {
95  $can_restore = TRUE;
96  }
97  }
98  if (!$can_restore) {
99  echo 'Parse file of EES login design has been modified. Skipping.'."\n";
100  pre_echo('EES LOGIN DESIGN UPGRADE COMPLETE - FROM VERSION 0.1');
101  return TRUE;
102  }
103  if (!is_file($parse_file) || !is_file($new_parse_file)) {
104  trigger_error ('parse file is not available');
105  return FALSE;
106  }
107  else {
108 
109  // update the parse file
110  if(!$this->_updateFile($new_parse_file, 'parse.txt', $design->data_path, $design->data_path_suffix)) {
111  trigger_error('failed to update parse file '.$new_parse_file);
112  return FALSE;
113  }
114 
115  $design_edit_fns->parseAndProcessFile($design);
116  $design->generateDesignFile();
117 
118  echo 'Parse file of EES login design is successfully updated...'."\n";
119  }
120 
121 
122  pre_echo('EES LOGIN DESIGN UPGRADE COMPLETE - FROM VERSION 0.1');
123 
124  }//end if - upgrade to version 0.2
125 
126  return TRUE;
127 
128  }//end _upgrade()
129 
130 
137  function _updateFile ($new_file, $file_name, $data_path, $data_path_suffix) {
138  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
139  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
140 
141  $file_path = $data_path.'/'.$file_name;
142 
143  if (!unlink($file_path)) {
144  trigger_error('failed to remove old file '.$file_name);
145  return FALSE;
146  }
147 
148  if (string_to_file(file_get_contents($new_file), $file_path)) {
149  // add a new version to the repository
150  $file_status = $fv->upToDate($file_path);
151  if (FUDGE_FV_MODIFIED & $file_status) {
152  if (!$fv->commit($file_path, '')) {
153  trigger_localised_error('CORE0160', E_USER_WARNING);
154  }
155  }
156  } else {
157  trigger_error('Can not overwrite old file '.$file_name);
158  }
159 
160  // make sure we have the latest version of our file
161  if (!$fv->checkOut($data_path_suffix.'/'.$file_name, $data_path)) {
162  trigger_localised_error('CORE0032', E_USER_WARNING);
163  return FALSE;
164  }//end if
165 
166 
167  return TRUE;
168  }//end _updateFile
169 
170 
171 }//end class
172 ?>