17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
42 $this->uses_trans = FALSE;
57 public static function paintConfig(&$o, $class, $write_access)
60 $o->openField(translate(
'metadata_regeneration_threshold'));
63 text_box($class.
'[SQ_HIPO_REGENERATE_METADATA_THRESHOLD]', SQ_HIPO_REGENERATE_METADATA_THRESHOLD, 5);
65 echo SQ_HIPO_REGENERATE_METADATA_THRESHOLD;
67 echo
' '.translate(
'assets');
82 return Array(
'SQ_HIPO_REGENERATE_METADATA_THRESHOLD' => Array(
'editable' => 1,
'default' => 1));
98 return parent::getCodeName().
'-'.md5(implode(
'-',$this->_running_vars[
'schemaids']));
111 return translate(
'hipo_name_regenerate_metadata');
127 'name' => translate(
'hipo_generating_metadata_files'),
128 'function_call' => Array(
129 'process_function' =>
'processMetadata',
131 'running_mode' =>
'server',
133 'allow_cancel' => TRUE,
153 if (SQ_HIPO_REGENERATE_METADATA_THRESHOLD == 0) {
156 if (!isset($this->_running_vars[
'todo_assetids'])) {
159 return ((count($this->_running_vars[
'todo_assetids']) / SQ_HIPO_REGENERATE_METADATA_THRESHOLD) * 100);
172 while (!empty($this->_running_vars[
'todo_assetids'])) {
191 if (empty($this->_running_vars[
'schemaids'])) {
192 trigger_localised_error(
'HIPO0003', E_USER_WARNING);
197 if (empty($this->_running_vars[
'contextids']) === TRUE) {
198 $this->_running_vars[
'contextids'] = array_keys($GLOBALS[
'SQ_SYSTEM']->getAllContexts());
203 if (is_array($this->_running_vars[
'contextids']) === FALSE) {
204 $this->_running_vars[
'contextids'] = Array($this->_running_vars[
'contextids']);
207 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
209 $this->_running_vars[
'todo_assetids'] = Array();
210 $this->_running_vars[
'done_assetids'] = Array();
212 foreach ($this->_running_vars[
'schemaids'] as $schemaid) {
213 $this->_running_vars[
'todo_assetids'] = array_merge($this->_running_vars[
'todo_assetids'], $mm->getSchemaAssets($schemaid, TRUE));
217 $this->_running_vars[
'todo_assetids'] = array_values(array_unique($this->_running_vars[
'todo_assetids']));
220 if (empty($this->_running_vars[
'todo_assetids'])) {
224 return parent::prepare();
240 if (!isset($this->_running_vars[
'process_metadata'])) {
241 $this->_running_vars[
'process_metadata'] = $this->_running_vars[
'todo_assetids'];
244 if (!empty($this->_running_vars[
'process_metadata'])) {
245 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
246 $assetid = array_shift($this->_running_vars[
'process_metadata']);
247 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
249 if (!is_null($asset)) {
251 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id,
'metadata')) {
252 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
253 trigger_localised_error(
'HIPO0077', E_USER_WARNING, $asset->name, $assetid);
256 if (!$asset->writeAccess(
'metadata')) {
259 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
260 trigger_localised_error(
'HIPO0078', E_USER_WARNING, $asset->name, $assetid);
262 foreach ($this->_running_vars[
'contextids'] as $contextid) {
263 if (!$mm->regenerateMetadata($asset->id, $contextid))
return FALSE;
265 $step_data[
'message'] = translate(
'hipo_generate_metadata', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
266 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
271 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'metadata');
274 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
275 $this->
_addError(translate(
'hipo_cannot_regenerate_metadata', $assetid));
279 $this->_running_vars[
'done_assetids'][] = $assetid;
282 if (empty($this->_running_vars[
'process_metadata'])) {
283 $step_data[
'percent_done'] = 100;
284 $step_data[
'complete'] = TRUE;
285 unset($this->_running_vars[
'done_assetids']);
286 $this->_running_vars[
'todo_assetids'] = Array();
288 $total = count($this->_running_vars[
'process_metadata']) + count($this->_running_vars[
'done_assetids']);
289 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
290 $step_data[
'complete'] = FALSE;