Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
hipo_job_quick_hipo.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/hipo/hipo_job.inc';
18 
36 {
37 
38 
44  function HIPO_Job_Quick_HIPO($code_name='')
45  {
46  $this->HIPO_Job($code_name);
47 
48  }//end constructor
49 
50 
62  function getCodeName()
63  {
64  $items = Array();
65  foreach ($this->_running_vars['items'] as $key => $val) {
66  $items[] = $key.'='.$val;
67  }
68 
69  return parent::getCodeName().'-'.$this->_running_vars['callback_assetid'].'-'.md5(implode(',', $items));
70 
71  }//end getCodeName()
72 
73 
80  function getHipoName()
81  {
82  return translate('hipo_name_quick_hipo');
83 
84  }//end getHipoName()
85 
86 
94  function getInitialStepData()
95  {
96  return Array(
97  Array(
98  'name' => translate('hipo_processing_assets'),
99  'function_call' => Array(
100  'process_function' => 'processQuickHipo',
101  ),
102  'running_mode' => 'server',
103  'auto_step' => TRUE,
104  'allow_cancel' => TRUE,
105  'percent_done' => 0,
106  'complete' => FALSE,
107  'message' => '',
108  ),
109  );
110 
111  }//end getInitialStepData()
112 
113 
120  function freestyle()
121  {
122  while (!empty($this->_running_vars['todo_items'])) {
123  if (!$this->processQuickHipo($this->_steps[0], get_class($this))) {
124  return FALSE;
125  }
126  }
127  return TRUE;
128 
129  }//end freestyle()
130 
131 
138  function &_getCallbackAsset()
139  {
140  $null = NULL;
141  $callback_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_running_vars['callback_assetid']);
142 
143  if (is_null($callback_asset)) {
144  trigger_localised_error('HIPO0080', E_USER_ERROR, $this->_running_vars['callback_assetid']);
145  return $NULL;
146  }
147 
148  if (!method_exists($callback_asset, $this->_running_vars['callback_function'])) {
149  trigger_localised_error('HIPO0081', E_USER_ERROR, $this->_running_vars['callback_function']);
150  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($callback_asset);
151  return $NULL;
152  }
153 
154  return $callback_asset;
155 
156  }//end _getCallbackAsset()
157 
158 
165  function prepare()
166  {
167  // to start acquiring locks, we need to have an asset id to acquire a lock on
168  if (empty($this->_running_vars['items'])) {
169  trigger_localised_error('HIPO0079', E_USER_WARNING, translate('hipo_name_quick_hipo'));
170  return FALSE;
171  }
172 
173  // check that the callback asset is valid, and the callback function exists
174  $callback_asset = $this->_getCallbackAsset();
175  if (is_null($callback_asset)) return FALSE;
176 
177  $this->_running_vars['total_count'] = count($this->_running_vars['items']);
178  $this->_running_vars['todo_items'] = array_keys($this->_running_vars['items']);
179  $this->_running_vars['done_items'] = Array();
180 
181  return parent::prepare();
182 
183  }//end prepare()
184 
185 
195  function processQuickHipo(&$step_data, $prefix)
196  {
197  if (!empty($this->_running_vars['todo_items'])) {
198 
199  // check that the callback asset is valid, and the callback function exists
200  $callback_asset = $this->_getCallbackAsset();
201  if (is_null($callback_asset)) return FALSE;
202 
203  $current_item_index = reset($this->_running_vars['todo_items']);
204  $callback_function = $this->_running_vars['callback_function'];
205 
206  if (!$callback_asset->$callback_function($current_item_index, $this->_running_vars['items'][$current_item_index], $this->_running_vars['settings'])) {
207  if ($this->_running_vars['fail_on_error']) {
208  return FALSE;
209  }
210  }
211 
212  // add this item to the done array so we dont do it again, then remove the item from the todo list
213  $this->_running_vars['done_items'][] = $current_item_index;
214  array_shift($this->_running_vars['todo_items']);
215  }
216 
217  if (empty($this->_running_vars['todo_items'])) {
218  $step_data['percent_done'] = 100;
219  $step_data['complete'] = TRUE;
220  } else {
221  $step_data['percent_done'] = (count($this->_running_vars['done_items']) / $this->_running_vars['total_count']) * 100;
222  $step_data['complete'] = FALSE;
223  }
224 
225  return TRUE;
226 
227  }//end processQuickHipo()
228 
229 
230 }//end class
231 
232 ?>