17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
57 public static function paintConfig(&$o, $class, $write_access)
60 $o->openField(translate(
'lookups_updating_threshold'));
63 text_box($class.
'[SQ_HIPO_LOOKUPS_THRESHOLD]', SQ_HIPO_LOOKUPS_THRESHOLD, 5);
65 echo SQ_HIPO_LOOKUPS_THRESHOLD;
67 echo
' '.translate(
'assets');
83 'SQ_HIPO_LOOKUPS_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
102 return parent::getCodeName().
'-'.md5(implode(
'-', $this->_running_vars[
'assetids']));
115 return translate(
'hipo_name_update_lookups');
131 'name' => translate(
'hipo_updating_lookups'),
132 'function_call' => Array(
133 'process_function' =>
'processLookups',
135 'running_mode' =>
'server',
137 'allow_cancel' => TRUE,
157 if (SQ_HIPO_LOOKUPS_THRESHOLD == 0)
return 0;
158 if (!isset($this->_running_vars[
'todo_assetids'])) {
161 return ((count($this->_running_vars[
'todo_assetids']) / SQ_HIPO_LOOKUPS_THRESHOLD) * 100);
174 while (!empty($this->_running_vars[
'todo_assetids'])) {
193 if (empty($this->_running_vars[
'assetids'])) {
194 trigger_localised_error(
'HIPO0001', E_USER_WARNING);
199 $todo_normal = Array();
200 $todo_shadows = Array();
202 foreach ($this->_running_vars[
'assetids'] as $assetid) {
204 $id_parts = explode(
':', $assetid);
205 if (isset($id_parts[1])) {
206 $todo_shadows = array_merge($todo_shadows, array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid)));
208 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
209 if ($asset instanceof
Bridge) {
210 if (!method_exists($asset,
'getChildren')) {
211 trigger_localised_error(
'SYS0204', E_USER_WARNING, $asset->name);
213 $todo_shadows = array_merge($todo_shadows, array_keys($asset->getChildren($assetid)));
217 $where =
'l.minorid = :assetid';
218 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
't');
219 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'l');
220 $sql =
'SELECT t.treeid
221 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk_tree t INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk l ON t.linkid = l.linkid
229 }
catch (Exception $e) {
230 throw new Exception(
'Unable to get treeid for minorid: '.$assetid.
' due to database error: '.$e->getMessage());
233 $sql =
'SELECT l.minorid, MAX(LENGTH(t.treeid)) as length
234 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk_tree t
235 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk l ON t.linkid = l.linkid
236 AND (('.db_extras_bitand(
MatrixDAL::getDbType(),
'l.link_type', SQ_SC_LINK_BACKEND_NAV).
' > 0) OR
237 (('.db_extras_bitand(
MatrixDAL::getDbType(),
'l.link_type', SQ_SC_LINK_SIGNIFICANT).
' > 0) AND ';
238 $sql .= (
MatrixDAL::getDbType() ===
'oci') ?
'(l.value IS NOT NULL)))' :
'(l.value <> \'\'))) ';
239 $where =
't.treeid LIKE :treeid
240 GROUP BY l.minorid ORDER BY length';
242 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
't');
243 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'l');
249 }
catch (Exception $e) {
250 throw new Exception(
'Unable to get minorids for treeid: '.$treeid[0][
'treeid'].
' due to database error: '.$e->getMessage());
253 $todo_normal = array_merge($todo_normal, $new_assets);
259 $todo_assetids = Array();
260 if (!empty($todo_normal)) {
261 usort($todo_normal, create_function(
'$a, $b',
'return $a[\'length\'] > $b[\'length\'];'));
262 foreach($todo_normal as $asset_info) {
263 $todo_assetids[] = $asset_info[
'minorid'];
270 $rm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'remap_manager');
271 $auto_add_remaps = $rm->attr(
'remap_upon_webpath_change');
273 $this->_running_vars[
'todo_assetids'] = array_unique(array_merge($todo_assetids, $todo_shadows));
274 if (!isset($this->_running_vars[
'auto_add_remaps'])) $this->_running_vars[
'auto_add_remaps'] = $auto_add_remaps;
275 $this->_running_vars[
'done_assetids'] = Array();
276 return parent::prepare();
292 if (!empty($this->_running_vars[
'todo_assetids'])) {
293 $assetid = array_shift($this->_running_vars[
'todo_assetids']);
294 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
296 if (!is_null($asset)) {
297 if (!$asset->updateLookups($this->_running_vars[
'auto_add_remaps']))
return FALSE;
298 $step_data[
'message'] = translate(
'hipo_updating_lookups_for', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
299 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
302 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
303 $this->
_addError(translate(
'hipo_cannot_update_lookups', $assetid));
307 $this->_running_vars[
'done_assetids'][] = $assetid;
310 if (empty($this->_running_vars[
'todo_assetids'])) {
311 $step_data[
'percent_done'] = 100;
312 $step_data[
'complete'] = TRUE;
314 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
315 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
316 $step_data[
'complete'] = FALSE;