Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_remove_web_path.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
19 
32 {
33 
34 
54  public static function execute($settings, &$state)
55  {
56 
57  // check required settings
58  if (empty($settings['path']) && empty($settings['remove_all'])) return FALSE;
59 
60  if (empty($state['asset'])) {
61  // grab the asset if assetid is given, but not the asset.
62  if (empty($state['assetid'])) {
63  return FALSE;
64  } else {
65  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
66  }
67  }
68 
69  if (is_null($state['asset'])) return FALSE;
70 
71  // replace keywords
72  $web_path = self::replaceKeywordsInWebPath($settings['path'], $state['asset']);
73  $valid_paths = make_valid_web_paths(Array($web_path));
74  $web_path = array_shift($valid_paths);
75 
76 
77 
78  // remove web path
79  $web_paths_old = $web_paths_new = $state['asset']->getWebPaths();
80 
81  foreach ($web_paths_new as $key => $path){
82  if($path === $web_path){
83  unset ($web_paths_new[$key]);
84  }
85  }
86 
87  // remove all paths, if needed
88  if (!empty($settings['remove_all'])) {
89  $web_paths_new = Array();
90  }
91 
92  // only save the new paths if they have changed
93  // (note that lookups are updated by the saveWebPaths fn)
94  if ($web_paths_new !== $web_paths_old) {
95  if (!$state['asset']->saveWebPaths($web_paths_new)) {
96  return FALSE;
97  }
98  }
99 
100  //update lookups for children
101  if(!empty($settings['update_children'])){
102  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
103  $vars = Array('assetids' => Array($state['asset']->id));
104  $lookup_errors = $hh->freestyleHipo('hipo_job_update_lookups', $vars);
105  if (!empty($lookup_errors)) {
106  return FALSE;
107  }
108  }
109 
110  return Array(
111  'assetid' => $state['asset']->id
112  );
113 
114  }//end execute()
115 
116 
129  public static function replaceKeywordsInWebPath($web_path, Asset $event_asset)
130  {
131  // replace global keywords
132  replace_global_keywords($web_path);
133 
134  // replace event asset keywords
135  $keywords = retrieve_keywords_replacements($web_path);
136  $replacements = Array();
137  foreach ($keywords as $keyword) {
138  $replacements[$keyword] = $event_asset->getKeywordReplacement($keyword);
139  }
140  replace_keywords($web_path, $replacements);
141 
142  return $web_path;
143 
144  }//end replaceKeywordsInWebPath()
145 
146 
157  public static function getInterface($settings, $prefix, $write_access=FALSE)
158  {
159  ob_start();
160 
161  $web_path = array_get_index($settings, 'path', '');
162  echo translate('remove_web_path').' ';
163  if ($write_access) {
164  text_box($prefix.'[path]', $web_path, 40);
165  } else {
166  echo '<b>'.$web_path.'</b>';
167  }
168  echo '<br />';
169  echo '<div class="sq-backend-section-note">'.translate('trigger_remove_web_path_note').'</div>';
170  check_box($prefix.'[remove_all]', '1', array_get_index($settings, 'remove_all', '0'), '', ($write_access ? '' : 'disabled="disabled"'));
171  echo '<label for='.$prefix.'[remove_all]'.'>'.translate('trigger_remove_web_path_remove_all').'.</label>';
172  echo '<br />';
173  check_box($prefix.'[update_children]', '1', array_get_index($settings, 'update_children', '0'), '', ($write_access ? '' : 'disabled="disabled"'));
174  echo '<label for='.$prefix.'[update_children]'.'>'.translate('trigger_remove_web_path_update_children').'.</label>';
175  return ob_get_clean();
176 
177  }//end getInterface()
178 
179 
191  public static function processInterface(&$settings, $request_data)
192  {
193  $web_path = array_get_index($request_data, 'path', '');
194  $web_path = trim($web_path);
195  $remove_all = array_get_index($request_data, 'remove_all', '');
196  $update_children = array_get_index($request_data, 'update_children', '');
197 
198  if ($web_path == '' && $remove_all == '') {
199  return translate('web_path_not_specified');
200  }
201  $settings['path'] = $web_path;
202  $settings['remove_all'] = $remove_all;
203  $settings['update_children'] = $update_children;
204 
205  return FALSE;
206 
207  }//end processInterface()
208 
209 
219  public static function getLocks($settings, &$state)
220  {
221  return Array($state['assetid'] => Array('lookups'));
222 
223  }//end getLocks()
224 
225 
226 }//end class
227 
228 ?>