17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
42 $this->uses_trans = TRUE;
56 return parent::getCodeName().
'-'.$this->_running_vars[
'thesaurus_id'];
69 return translate(
'thesaurus_hipo_name_import_thesaurus_xml');
85 'name' => translate(
'thesaurus_hipo_starting_process'),
86 'function_call' => Array(
87 'process_function' =>
'processStart',
89 'running_mode' =>
'server',
91 'allow_cancel' => FALSE,
94 'message' => translate(
'thesaurus_hipo_setting_up_env'),
97 'name' => translate(
'thesaurus_hipo_acquiring_locks'),
99 'init_details_function' =>
'getLockAssetDetails',
101 'running_mode' =>
'server',
103 'allow_cancel' => TRUE,
109 'name' => translate(
'thesaurus_hipo_erasing_thesaurus'),
110 'function_call' => Array(
111 'paint_function' =>
'paintEraseContents',
112 'process_function' =>
'processEraseContents',
114 'running_mode' =>
'web',
115 'auto_step' => FALSE,
116 'allow_cancel' => TRUE,
122 'name' => translate(
'thesaurus_hipo_parsing_xml'),
123 'function_call' => Array(
124 'process_function' =>
'processParseXML',
126 'running_mode' =>
'server',
127 'skip_step' => FALSE,
129 'allow_cancel' => FALSE,
147 $step_data = Array();
152 $step_data[
'complete'] = FALSE;
153 while (!$step_data[
'complete']) {
172 if (is_null($this->_running_vars[
'thesaurus_id'])) {
173 trigger_localised_error(
'HIPO0061', E_USER_WARNING);
179 if (is_null($asset)) {
180 trigger_localised_error(
'HIPO0062', E_USER_WARNING, $this->_running_vars[
'thesaurus_id']);
184 return parent::prepare();
201 $step_data[
'percent_done'] = 100;
202 $step_data[
'complete'] = TRUE;
220 $o->openSection(translate(
'thesaurus_hipo_erasing_thesaurus'));
222 echo translate(
'thesaurus_hipo_confirm_erase');
223 $o->addHiddenField(
'form_submitted', 1);
243 if (isset($_REQUEST[
'form_submitted'])) {
246 if (!$th_asset->erase()) {
247 trigger_localised_error(
'HIPO0063', E_USER_WARNING);
251 $step_data[
'percent_done'] = 100;
252 $step_data[
'complete'] = TRUE;
273 $stack =& $this->_running_vars[
'stack'];
274 $tagstack =& $this->_running_vars[
'tagstack'];
275 $relations =& $this->_running_vars[
'relations'];
279 if ($tag !=
'thesaurus' && $tag !=
'term' && $tag !=
'relation' && $tag !=
'note') {
280 trigger_localised_error(
'HIPO0064', E_USER_WARNING, $tag);
283 if (empty($stack) && $tag !=
'thesaurus') {
284 trigger_error(
'EMPTY STACK');
288 $current_tag = array_get_index($this->_running_vars,
'current_tag');
291 if (!empty($stack)) {
292 trigger_localised_error(
'HIPO0067', E_USER_WARNING, $tag);
295 array_unshift($stack, Array(
'term' => NULL));
300 if (isset($stack[0][
'relation'])) {
301 trigger_localised_error(
'HIPO0065', E_USER_WARNING, $tag);
305 $rel_name = array_get_index($attrs,
'name');
306 $rel_id = array_get_index($relations, $rel_name);
307 if (is_null($rel_id)) {
309 $rel_id = $thesaurus->addRelation($rel_name);
310 $relations[$rel_name] = $rel_id;
313 $stack[0][
'relation'] = $rel_id;
318 if (empty($attrs[
'name'])) {
319 trigger_localised_error(
'HIPO0066', E_USER_WARNING);
326 if (is_null($stack[0][
'term'])) {
327 $parent_asset =& $thesaurus;
329 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($stack[0][
'term']);
330 $rel_id = array_get_index($stack[0],
'relation');
331 if (is_null($rel_id)) {
332 $NULL_rel_id = array_get_index($relations, NULL);
334 if (is_null($NULL_rel_id)) {
335 $rel_id = $thesaurus->addRelation(NULL);
336 $relations[NULL] = $rel_id;
338 $rel_id = $NULL_rel_id;
343 $create_link[
'asset'] =& $parent_asset;
344 $create_link[
'value'] = $rel_id;
347 $term_asset->setAttrValue(
'name', $attrs[
'name']);
348 $term_asset->create($create_link);
351 array_unshift($stack, Array(
'term' => $term_asset->id));
356 if ($tagstack[0] !=
'term') {
357 trigger_error(
'NOTE tag can only be a child of TERM tag', E_USER_WARNING);
361 if (empty($attrs[
'name'])) {
362 trigger_error(
'Note must have a Name', E_USER_WARNING);
366 $this->_running_vars[
'current_note'][
'name'] = $attrs[
'name'];
371 trigger_localised_error(
'HIPO0067', E_USER_WARNING, $tag);
376 array_unshift($tagstack, $tag);
394 $stack =& $this->_running_vars[
'stack'];
395 $tagstack =& $this->_running_vars[
'tagstack'];
397 if (isset($tagstack[0]) && $tagstack[0] ==
'note') {
400 if (isset($this->_running_vars[
'current_note'][
'text'])) {
401 $this->_running_vars[
'current_note'][
'text'] .= $data;
403 $this->_running_vars[
'current_note'][
'text'] = $data;
422 $stack =& $this->_running_vars[
'stack'];
423 $tagstack =& $this->_running_vars[
'tagstack'];
424 $relations =& $this->_running_vars[
'relations'];
426 if ($tag !=
'thesaurus' && $tag !=
'term' && $tag !=
'relation' && $tag !=
'note') {
427 trigger_localised_error(
'HIPO0064', E_USER_WARNING, $tag);
431 trigger_error(
'EMPTY STACK');
435 if ($tagstack[0] != $tag) {
436 trigger_error(
'Malformed XML. Cannot close tag <'.$tag.
'> while being in <'.$tagstack[0].
'>');
442 if (is_null($stack[0][
'term'])) {
445 trigger_error(
'Malformed XML. Unexpected tag: <'.$tag.
'>.');
451 if (!is_null($stack[0][
'relation'])) {
452 unset($stack[0][
'relation']);
454 trigger_error(
'Malformed XML. Unexpected tag: <'.$tag.
'>.');
460 if (!is_null($stack[0][
'term'])) {
463 trigger_error(
'Malformed XML. Unexpected tag: <'.$tag.
'>.');
469 $note_name = $this->_running_vars[
'current_note'][
'name'];
470 $note_value = $this->_running_vars[
'current_note'][
'text'];
471 $term = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($stack[0][
'term']);
472 $term->addTermNote($note_name, $note_value);
473 unset($this->_running_vars[
'current_note']);
478 trigger_localised_error(
'HIPO0067', E_USER_WARNING, $tag);
482 array_shift($tagstack);
500 $blocks_per_step = 10;
503 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'thesaurus_term');
505 if (!isset($step_data[
'total_read'])) {
507 $step_data[
'total_parsed'] = 0;
508 $step_data[
'total_read'] = 0;
509 $step_data[
'remainder'] =
'';
512 if (!isset($this->_running_vars[
'stack'])) {
513 $this->_running_vars[
'stack'] = Array();
516 if (!isset($this->_running_vars[
'tagstack'])) {
517 $this->_running_vars[
'tagstack'] = Array();
520 if (!isset($this->_running_vars[
'relations'])) {
521 $this->_running_vars[
'relations'] = Array();
525 $xml_parser = xml_parser_create();
527 xml_parser_set_option ($xml_parser, XML_OPTION_CASE_FOLDING, 0);
532 $import_path = $th_asset->getXmlFilePath();
534 if (!($fp = fopen($import_path,
'r'))) {
535 trigger_localised_error(
'CORE0257', E_USER_WARNING, $import_path);
541 $file_size = $fstat[
'size'];
543 if ($step_data[
'total_read'] > 0) {
545 $data = fread($fp, $step_data[
'total_read']);
546 if (!xml_parse($xml_parser, $data, feof($fp))) {
547 trigger_localised_error(
'CORE0258', E_USER_WARNING, xml_error_string(xml_get_error_code($xml_parser)), htmlentities($data, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
552 xml_set_element_handler($xml_parser, Array(&$this,
'startElement'), Array(&$this,
'endElement'));
553 xml_set_character_data_handler($xml_parser, Array(&$this,
'cDataHandler'));
556 while (!feof($fp) && $blocks <= $blocks_per_step) {
559 $data = fread($fp, $block_size);
560 if (!xml_parse($xml_parser, $data, feof($fp))) {
561 trigger_localised_error(
'CORE0258', E_USER_WARNING, xml_error_string(xml_get_error_code($xml_parser)), htmlentities($data, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
565 $parsed = xml_get_current_byte_index($xml_parser);
567 $step_data[
'remainder'] = substr($data, $parsed);
568 $step_data[
'total_read'] = $step_data[
'total_read'] + strlen($data);
569 $step_data[
'total_parsed'] = $step_data[
'total_parsed'] + $parsed;
574 $step_data[
'percent_done'] = ($step_data[
'total_read']/$file_size) * 100;
578 $step_data[
'complete'] = TRUE;
579 xml_parser_free($xml_parser);
581 $step_data[
'complete'] = FALSE;
583 $step_data[
'message'] =
'Parsed '.sprintf(
'%01.2f',$step_data[
'total_read']/1024).
' Kb of '.sprintf(
'%01.2f',$file_size/1024).
' Kb';
602 $job_type =
'hipo_job_acquire_locks';
604 $options[
'auto_complete'] = TRUE;
606 $running_vars = Array(
607 'assetids' => Array($this->_running_vars[
'thesaurus_id'],),
608 'lock_type' =>
'attributes',
609 'dependants_only' => FALSE,
610 'forceably_acquire' => FALSE,
624 $thes = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'thesaurus_id']);