17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
42 $this->uses_trans = FALSE;
44 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'search');
45 $this->_hipo_vars[
'job_dir'] = SQ_PACKAGES_PATH.
'/search/hipo_jobs';
59 public static function paintConfig(&$o, $class, $write_access)
61 $o->openField(translate(
'sch_hipo_reindex_threshold'));
64 text_box($class.
'[SQ_HIPO_REINDEX_THRESHOLD]', SQ_HIPO_REINDEX_THRESHOLD, 5);
66 echo SQ_HIPO_REINDEX_THRESHOLD;
68 echo
' '.translate(
'assets');
84 'SQ_HIPO_REINDEX_THRESHOLD' => Array(
'editable' => 1,
'default' => 5),
101 if (SQ_HIPO_REINDEX_THRESHOLD == 0)
return 0;
102 if (!isset($this->_running_vars[
'todo_assetids'])) {
106 return ((count($this->_running_vars[
'todo_assetids']) / SQ_HIPO_REINDEX_THRESHOLD) * 100);
122 return parent::getCodeName().
'-'. htmlspecialchars(implode(
',', $this->_running_vars[
'root_assetid']));
135 return translate(
'sch_hipo_name_reindex_assets');
151 'name' => translate(
'sch_hipo_reindexing_assets'),
152 'function_call' => Array(
153 'process_function' =>
'processReIndex',
155 'running_mode' =>
'server',
160 'allow_cancel' => TRUE,
176 if (array_get_index(
'contextid', $this->_running_vars)) {
177 $this->_running_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
180 while (!empty($this->_running_vars[
'todo_assetids'])) {
181 if (!$this->
processReIndex($this->_steps[0], get_class_lower($this))) {
199 if (is_null($this->_running_vars[
'root_assetid']) || empty($this->_running_vars[
'root_assetid'])) {
200 $this->_running_vars[
'root_assetid'] = 1;
203 if (!is_array($this->_running_vars[
'root_assetid'])) {
204 $this->_running_vars[
'root_assetid'] = Array($this->_running_vars[
'root_assetid']);
210 if (array_get_index(
'contextid', $this->_running_vars)) {
211 $this->_running_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
214 $todo_assetids = Array();
215 foreach ($this->_running_vars[
'root_assetid'] as $assetid) {
217 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
218 if (is_null($asset)) {
219 trigger_localised_error(
'SCH0022', E_USER_WARNING, $assetid);
223 if (!empty($this->_running_vars[
'root_only']) && $this->_running_vars[
'root_only']) {
224 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($asset->id);
226 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id);
228 $todo_assetids += $child_assets;
229 $todo_assetids[$asset->id][0][
'type_code'] = $asset->type();
233 $this->_running_vars[
'todo_assetids'] = $todo_assetids;
234 $this->_running_vars[
'done_assetids'] = Array();
236 return parent::prepare();
252 if (!empty($this->_running_vars[
'todo_assetids'])) {
253 $GLOBALS[
'SQ_SYSTEM']->changeContext($this->_running_vars[
'contextid']);
255 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
256 $sm = $am->getSystemAsset(
'search_manager');
257 if (is_null($sm))
return FALSE;
260 reset($this->_running_vars[
'todo_assetids']);
261 $assetid = key($this->_running_vars[
'todo_assetids']);
262 $asset_type = $this->_running_vars[
'todo_assetids'][$assetid][0][
'type_code'];
263 unset($this->_running_vars[
'todo_assetids'][$assetid]);
264 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
267 $step_data[
'message'] = translate(
'sch_reindexing_asset', $asset->name);
268 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
269 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
270 $sm->reindexAsset($asset, Array(
'all'));
271 $sm->reindexAttributes($asset, Array(
'all'), TRUE);
272 $sm->reindexContents($asset, Array(
'all'), TRUE);
273 $sm->reindexMetadata($asset->id, Array(
'all'));
274 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
275 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
279 $this->_running_vars[
'done_assetids'][] = $assetid;
281 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
284 if (empty($this->_running_vars[
'todo_assetids'])) {
285 $step_data[
'percent_done'] = 100;
286 $step_data[
'complete'] = TRUE;
288 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
289 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
290 $step_data[
'complete'] = FALSE;