/usr/share/php/arc/store/ARC2_StoreHelper.php is in libarc-php 2~20101006-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | <?php
/*
homepage: http://arc.semsol.org/
license: http://arc.semsol.org/license
class: ARC2 RDF Store Helper
author: Benjamin Nowack
version: 2010-11-16
*/
ARC2::inc('Class');
class ARC2_StoreHelper extends ARC2_Class {
function __construct($a, &$caller) {
parent::__construct($a, $caller);
}
function __init() {/* db_con */
parent::__init();
$this->store = $this->caller;
}
/* */
function changeNamespaceURI($old_uri, $new_uri) {
$id_changes = 0;
$t_changes = 0;
/* table lock */
if ($this->store->getLock()) {
$con = $this->store->getDBCon();
foreach (array('id', 's', 'o') as $id_col) {
$tbl = $this->store->getTablePrefix() . $id_col . '2val';
$sql = 'SELECT id, val FROM ' . $tbl . ' WHERE val LIKE "' . mysql_real_escape_string($old_uri, $con). '%"';
$rs = mysql_query($sql, $con);
if (!$rs) continue;
while ($row = mysql_fetch_array($rs)) {
$new_val = str_replace($old_uri, $new_uri, $row['val']);
$new_id = $this->store->getTermID($new_val, $id_col);
if (!$new_id) {/* unknown ns uri, overwrite current id value */
$sub_sql = "UPDATE " . $tbl . " SET val = '" . mysql_real_escape_string($new_val, $con) . "' WHERE id = " . $row['id'];
$sub_r = mysql_query($sub_sql, $con);
$id_changes++;
}
else {/* replace ids */
$t_tbls = $this->store->getTables();
foreach ($t_tbls as $t_tbl) {
if (preg_match('/^triple/', $t_tbl)) {
foreach (array('s', 'p', 'o', 'o_lang_dt') as $t_col) {
$sub_sql = "UPDATE " . $this->store->getTablePrefix() . $t_tbl . " SET " . $t_col . " = " . $new_id . " WHERE " . $t_col . " = " . $row['id'];
$sub_r = mysql_query($sub_sql, $con);
$t_changes += mysql_affected_rows($con);
}
}
}
}
}
}
$this->store->releaseLock();
}
return array('id_replacements' => $id_changes, 'triple_updates' => $t_changes);
}
/* */
}
|