18 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
42 $this->uses_trans = FALSE;
44 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'funnelback');
45 $this->_hipo_vars[
'job_dir'] = SQ_PACKAGES_PATH.
'/funnelback/hipo_jobs';
59 public static function paintConfig(&$o, $class, $write_access)
61 $o->openField(translate(
'fnb_hipo_rebuild_cache'));
64 text_box($class.
'[SQ_HIPO_REBUILD_FUNNELBACK_CACHE]', SQ_HIPO_REBUILD_FUNNELBACK_CACHE, 5);
66 echo SQ_HIPO_REBUILD_FUNNELBACK_CACHE;
83 'SQ_HIPO_REBUILD_FUNNELBACK_CACHE' => Array(
'editable' => 1,
'default' => 5),
116 return parent::getCodeName().
'-'.implode(
',', $this->_running_vars[
'root_assetid']);
129 return translate(
'fnb_hipo_rebuild_cache');
145 'name' => translate(
'fnb_hipo_rebuild_cache_step_name0'),
146 'function_call' => Array(
147 'process_function' =>
'processFlushTable',
149 'running_mode' =>
'server',
154 'allow_cancel' => TRUE,
157 'name' => translate(
'fnb_hipo_rebuild_cache_step_name1'),
158 'function_call' => Array(
159 'process_function' =>
'processRebuild',
161 'running_mode' =>
'server',
166 'allow_cancel' => TRUE,
182 if (array_get_index(
'contextid', $this->_running_vars)) {
183 $this->_running_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
189 while (!empty($this->_running_vars[
'todo_assetids'])) {
190 if (!$this->
processRebuild($this->_steps[0], get_class_lower($this))) {
209 if (is_null($this->_running_vars[
'root_assetid']) || empty($this->_running_vars[
'root_assetid'])) {
210 $this->_running_vars[
'root_assetid'] = 1;
213 if (!is_array($this->_running_vars[
'root_assetid'])) {
214 $this->_running_vars[
'root_assetid'] = Array($this->_running_vars[
'root_assetid']);
220 if (array_get_index(
'contextid', $this->_running_vars)) {
221 $this->_running_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
224 $this->_running_vars[
'todo_assetids'] = Array();
225 $this->_running_vars[
'done_assetids'] = Array();
226 foreach ($this->_running_vars[
'root_assetid'] as $assetid) {
228 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
229 if (is_null($asset)) {
230 trigger_localised_error(
'FNB0022', E_USER_WARNING, $assetid);
234 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id);
235 $child_assets[$asset->id][0][
'type_code'] = $asset->type();
236 $this->_running_vars[
'todo_assetids'] += $child_assets;
239 return parent::prepare();
256 if (in_array(
'1', $this->_running_vars[
'root_assetid'])) {
257 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
258 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
260 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
261 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
263 if ($step_data[
'percent_done'] == 0) {
264 $step_data[
'percent_done'] = 50;
266 $step_data[
'percent_done'] = 100;
267 $step_data[
'complete'] = TRUE;
285 if (!empty($this->_running_vars[
'todo_assetids'])) {
286 $GLOBALS[
'SQ_SYSTEM']->changeContext(array_get_index($this->_running_vars,
'contextid', 0));
288 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
289 $fm = $am->getSystemAsset(
'funnelback_manager');
290 if (is_null($fm))
return FALSE;
293 reset($this->_running_vars[
'todo_assetids']);
294 $assetid = key($this->_running_vars[
'todo_assetids']);
295 $asset_type = $this->_running_vars[
'todo_assetids'][$assetid][0][
'type_code'];
296 unset($this->_running_vars[
'todo_assetids'][$assetid]);
297 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
300 $step_data[
'message'] = translate(
'fnb_hipo_refreshing_asset', $asset->name);
301 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
302 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
303 $fm->updateAsset($asset, Array(
'update'));
304 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
305 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
306 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
310 $this->_running_vars[
'done_assetids'][] = $assetid;
312 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($fm, TRUE);
313 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
316 if (empty($this->_running_vars[
'todo_assetids'])) {
317 $step_data[
'percent_done'] = 100;
318 $step_data[
'complete'] = TRUE;
320 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
321 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
322 $step_data[
'complete'] = FALSE;