Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_design_parse_file.inc
1 <?php
18 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
19 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
20 
21 
34 {
35 
36 
54  public static function execute($settings, &$state)
55  {
56  // check settings, state
57  if (empty($settings['file_path']) || !file_exists($settings['file_path'])) {
58  // if no settings, fail
59  return FALSE;
60  }
61 
62  // state, design asset
63  if (empty($state['asset'])) {
64  // grab the asset if assetid is given, but not the asset.
65  if (empty($state['assetid'])) {
66  return FALSE;
67  } else {
68  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
69  }
70  }
71 
72  if (is_null($state['asset'])) return FALSE;
73 
74  $asset =& $state['asset'];
75  $edit_fns = $asset->getEditFns();
76 
77  $parse_file = $asset->data_path.'/parse.txt';
78  $changes = FALSE;
79  $new_version = FALSE;
80 
81  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
82 
83  // delete existing parse file if it exists
84  if (is_file($parse_file)) {
85  $new_version = TRUE;
86  if (!unlink($parse_file)) {
87  trigger_localised_error('CORE0164', E_USER_WARNING);
88  return FALSE;
89  }
90  }
91 
92  // copy over the uploaded file
93  if (copy_file($settings['file_path'], $parse_file)) {
94  // tell the asset to update the customisation at the end of the interface processing
95  $asset->_tmp['update_customisations'] = TRUE;
96  $asset->_tmp['generate_design'] = TRUE;
97  $changes = $edit_fns->parseAndProcessFile($asset);
98 
99  // parseAndProcessFile()
100  $parse_file = $asset->data_path.'/parse.txt';
101  $str = file_to_string($parse_file);
102  $contents = $edit_fns->_parseString($asset, $str);
103 
104  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
105  $changes = (!is_null($contents) && $edit_fns->_processContents($asset, $contents) && $asset->saveAttributes());
106  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
107 
108  // if we are overwriting our current parse file, we need to add a new version to the repository
109  if ($new_version) {
110  $file_status = $fv->upToDate($parse_file);
111  if (FUDGE_FV_MODIFIED & $file_status) {
112  if (!$fv->commit($parse_file, '')) {
113  trigger_localised_error('CORE0160', E_USER_WARNING);
114  }
115  }
116  } else {
117  // attempt to add the parse file to the repository
118  if (!$fv->add($asset->data_path_suffix, $parse_file, '')) {
119  trigger_localised_error('CORE1057', E_USER_WARNING);
120  }
121  }
122  }//end if file uploaded
123 
124  // make sure we have the latest version of our file
125  if (!$fv->checkOut($asset->data_path_suffix.'/parse.txt', $asset->data_path)) {
126  trigger_localised_error('CORE0158', E_USER_WARNING);
127  return FALSE;
128  }
129 
130  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
131  $asset->generateDesignFile(TRUE);
132  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
133 
134  return Array(
135  'assetid' => $state['asset']->id,
136  );
137 
138  }//end execute()
139 
140 
151  public static function getInterface($settings, $prefix, $write_access=FALSE)
152  {
153  $file_path = array_get_index($settings, 'file_path', '');
154  ob_start();
155  ?>
156  <table border="0">
157  <tr>
158  <td valign="top"><b><?php echo 'Path to the associated file for the design'; ?></b></td>
159  <td valign="top" style="padding-bottom: 10px;"><?php
160  // level
161  if ($write_access) {
162  echo text_box($prefix.'[file_path]', $file_path, '50');
163  } else {
164  echo $file_path.'&nbsp;';
165  }
166  ?>
167  </td>
168  </tr>
169  </table>
170  <?php
171 
172  return ob_get_clean();
173 
174  }//end getInterface()
175 
176 
188  public static function processInterface(&$settings, $request_data)
189  {
190  $file_path = array_get_index($request_data, 'file_path', '');
191  $file_path = trim($file_path);
192  if ($file_path == '') {
193  return 'file path is not specified.';
194  }
195  $settings['file_path'] = $file_path;
196 
197  return FALSE;
198 
199  }//end processInterface()
200 
201 
211  public static function getLocks($settings, &$state)
212  {
213  return Array(
214  $state['assetid'] => Array(
215  'attributes',
216  ),
217  );
218 
219  }//end getLocks()
220 
221 
222 }//end class
223 
224 ?>