17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
44 $this->uses_trans = TRUE;
58 return parent::getCodeName().
'-'.$this->_running_vars[
'thesaurus_id'];
71 return translate(
'thesaurus_hipo_name_export_thesaurus_xml');
87 'name' => translate(
'thesaurus_hipo_starting_process'),
88 'function_call' => Array(
89 'process_function' =>
'processStart',
91 'running_mode' =>
'server',
93 'allow_cancel' => FALSE,
96 'message' => translate(
'thesaurus_hipo_setting_up_env'),
99 'name' => translate(
'thesaurus_hipo_acquiring_locks'),
101 'init_details_function' =>
'getLockAssetDetails',
103 'running_mode' =>
'server',
105 'allow_cancel' => TRUE,
111 'name' => translate(
'thesaurus_hipo_creating_xml'),
112 'function_call' => Array(
113 'process_function' =>
'processCreateXML',
115 'running_mode' =>
'server',
116 'skip_step' => FALSE,
118 'allow_cancel' => FALSE,
124 'name' => translate(
'thesaurus_hipo_finalising'),
125 'function_call' => Array(
126 'process_function' =>
'processFinish',
128 'running_mode' =>
'server',
129 'skip_step' => FALSE,
131 'allow_cancel' => FALSE,
150 if (is_null($this->_running_vars[
'thesaurus_id'])) {
151 trigger_localised_error(
'HIPO0072', E_USER_WARNING);
157 if (is_null($asset)) {
158 trigger_localised_error(
'HIPO0073', E_USER_WARNING, $this->_running_vars[
'thesaurus_id']);
162 return parent::prepare();
179 $step_data[
'percent_done'] = 100;
180 $step_data[
'complete'] = TRUE;
199 $thesaurus->setAttrValue(
'contents_changed', FALSE);
200 $thesaurus->saveAttributes();
201 $step_data[
'percent_done'] = 100;
202 $step_data[
'complete'] = TRUE;
216 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
217 $step_data = Array();
221 $running_vars = Array();
224 $errors = $hh->freestyleHipo($job_type, $running_vars);
225 if (!empty($errors)) {
226 $this->
_addError(
'acquiring locks failed');
232 $this->
_addError(
'generating the xml failed');
254 $filepath = $thesaurus->getXmlFilePath();
255 if (file_exists($filepath)) {
256 $filepath = realpath($filepath);
259 $iterations_per_step = 100;
260 $iterations_this_step = 0;
262 $all_relations = $thesaurus->getActiveRelations();
264 if (!isset($step_data[
'unprocessed'])) {
265 if (file_exists($filepath)) unlink($filepath);
266 create_directory(dirname($filepath));
269 $step_data[
'total_terms'] = $thesaurus->countTerms();
270 $step_data[
'links_closed'] = 0;
271 $filehandle = fopen($filepath,
'wb');
273 $step_data[
'unprocessed'] = $thesaurus->getAllTerms();
274 $step_data[
'seen_terms'] = Array();
276 fwrite($filehandle,
'<!-- MySource Matrix Thesaurus -->'.
"\n");
277 fwrite($filehandle,
'<!-- Generated on '.date(
'r').
' -->'.
"\n");
278 fwrite($filehandle,
'<!-- Do not import into system version less than 3.12 -->'.
"\n");
279 fwrite($filehandle,
'<thesaurus>'.
"\n");
282 $filehandle = fopen($filepath,
'ab');
285 if (!is_writable($filepath)) {
286 trigger_localised_error(
'HIPO0074', E_USER_WARNING, $filepath);
289 $unprocessed =& $step_data[
'unprocessed'];
290 $seen_terms =& $step_data[
'seen_terms'];
292 while (!$finished && $iterations_this_step <= $iterations_per_step) {
293 $iterations_this_step++;
295 if (empty($unprocessed)) {
300 array_unshift($seen_terms, array_shift($unprocessed));
302 $current_term =& $seen_terms[0];
304 $termid = $current_term[
'termid'];
305 $term = $current_term[
'term'];
306 $term_notes = $thesaurus->getTermNotes($termid);
307 $child_relations = $thesaurus->getChildRelationsForTerm($termid);
309 if (empty($term_notes) && empty($child_relations)) {
310 fwrite($filehandle,
"\t".
'<term name="'.htmlentities($term, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'" />'.
"\n");
314 fwrite($filehandle,
"\t".
'<term name="'.htmlentities($term, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'">'.
"\n");
316 foreach ($term_notes as $note_array) {
317 fwrite($filehandle,
"\t\t".
'<note name="'.htmlentities($note_array[
'name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'">'.$note_array[
'value'].
'</note>'.
"\n");
320 foreach ($child_relations as $relid => $relname) {
322 if (!is_null($relname)) {
323 fwrite($filehandle,
"\t\t".
'<relation name="'.htmlentities($relname, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'">'.
"\n");
326 $rel_terms = $thesaurus->getChildTerms($termid, $relid);
327 foreach ($rel_terms as $term) {
328 fwrite($filehandle, $extra_tab.
"\t\t".
'<term name="'.htmlentities($term[
'term'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'" />'.
"\n");
330 if (!is_null($relname)) {
331 fwrite($filehandle,
"\t\t".
'</relation>'.
"\n");
335 fwrite($filehandle,
"\t".
'</term>'.
"\n");
339 $step_data[
'percent_done'] = (count($seen_terms)/$step_data[
'total_terms']) * 100;
340 $step_data[
'message'] =
'Processed '.count($seen_terms).
' of '.$step_data[
'total_terms'].
' terms';
343 fwrite($filehandle,
'</thesaurus>'.
"\n");
344 $step_data[
'complete'] = TRUE;
346 $step_data[
'complete'] = FALSE;
366 $job_type =
'hipo_job_acquire_locks';
368 $options[
'auto_complete'] = TRUE;
370 $running_vars = Array(
371 'assetids' => Array($this->_running_vars[
'thesaurus_id'],),
372 'lock_type' =>
'attributes',
373 'dependants_only' => FALSE,
374 'forceably_acquire' => FALSE,
388 return $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'thesaurus_id']);