Uncomment foreign keys.
[platal.git] / upgrade / 1.0.1 / positions_as_terms.php
CommitLineData
468c1813
PC
1#!/usr/bin/php5
2<?php
3require_once 'connect.db.inc.php';
4
5$globals->debug = 0; //do not store backtraces
6
7$data = implode('', file('arbo-UTF8.xml'));
8$parser = xml_parser_create();
9xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
10xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
11xml_parse_into_struct($parser, $data, $values, $tags);
12xml_parser_free($parser);
13
14XDB::execute('INSERT INTO `profile_job_term_enum` (`name`, `full_name`) VALUES ("Emplois", "Emplois")');
15
16$opened_nodes = array();
17$broader_ids = array(XDB::insertId());
18
19XDB::execute('INSERT INTO profile_job_term_relation VALUES (0, {?}, "narrower", "original"), ({?}, {?}, "narrower", "computed")',
20 $broader_ids[0], $broader_ids[0], $broader_ids[0]);
21
22// loop through the structures
23foreach ($values as $val) {
24 if (($val['type'] == 'open' || $val['type'] == 'complete') && !empty($val['attributes']['intitule'])) {
25 $intitule = $val['attributes']['intitule'];
26 if (mb_strtoupper($intitule) == $intitule) {
27 $intitule = ucfirst(mb_strtolower($intitule));
28 }
29 $res = XDB::execute('INSERT INTO profile_job_term_enum (name, full_name)
30 VALUES ({?}, {?})',
31 $intitule, $intitule.' (emploi'.(($val['type'] == 'open')?'s':'').')');
32 $newid = XDB::insertId();
33 array_unshift($broader_ids, $newid);
34 array_unshift($opened_nodes, $val['tag']);
35 foreach ($broader_ids as $i => $bid) {
36 XDB::execute('INSERT INTO profile_job_term_relation VALUES ({?}, {?}, "narrower", {?})',
37 $bid, $newid, ($i == 1)?'original':'computed');
38 }
39 }
40 if (count($opened_nodes) > 0 && $val['tag'] == $opened_nodes[0] && ($val['type'] == 'close' || $val['type'] == 'complete')) {
41 array_shift($broader_ids);
42 array_shift($opened_nodes);
43 }
44}
45
46/* vim:set et sw=4 sts=4 ts=4: */
47?>