3 homepage: http://arc.semsol.org/
4 license: http://arc.semsol.org/license
6 class: ARC2 RDF Store Helper
7 author: Benjamin Nowack
8 version: 2008-04-03 (Tweak: Changed locking approach from "LOCK TABLE" to "GET LOCK")
13 class ARC2_StoreHelper extends ARC2_Class {
15 function __construct($a = '', &$caller) {
16 parent::__construct($a, $caller);
19 function ARC2_StoreHelper($a = '', &$caller) {
20 $this->__construct($a, $caller);
23 function __init() {/* db_con */
25 $this->store =& $this->caller;
30 function changeNamespaceURI($old_uri, $new_uri) {
34 if ($this->store->getLock()) {
35 $con = $this->store->getDBCon();
36 foreach (array('id', 's', 'o') as $id_col) {
37 $tbl = $this->store->getTablePrefix() . $id_col . '2val';
38 $sql = 'SELECT id, val FROM ' . $tbl . ' WHERE val LIKE "' . mysql_real_escape_string($old_uri, $con). '%"';
39 if ($rs = mysql_query($sql, $con)) {
40 while ($row = mysql_fetch_array($rs)) {
41 $new_val = str_replace($old_uri, $new_uri, $row['val']);
42 $new_id = $this->store->getTermID($new_val, $id_col , 'id');
43 if (!$new_id) {/* new ns uri */
44 $sub_sql = "UPDATE " . $tbl . " SET val = '" . mysql_real_escape_string($new_val, $con) . "' WHERE id = " . $row['id'];
45 $sub_r = mysql_query($sub_sql, $con);
49 $t_tbls = $this->store->getTables();
50 foreach ($t_tbls as $t_tbl) {
51 if (preg_match('/^triple_/', $t_tbl)) {
52 foreach (array('s', 'p', 'o', 'o_lang_dt') as $t_col) {
53 $sub_sql = "UPDATE " . $this->store->getTablePrefix() . $t_tbl . " SET " . $t_col . " = " . $new_id . " WHERE " . $t_col . " = " . $row['id'];
54 $sub_r = mysql_query($sub_sql, $con);
55 $t_changes += mysql_affected_rows($con);
63 $this->store->releaseLock();
65 return array('id_replacements' => $id_changes, 'triple_updates' => $t_changes);