PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/arc2/store/ARC2_StoreHelper.php

https://bitbucket.org/rhiaro/public-notices-as-georss
PHP | 66 lines | 47 code | 8 blank | 11 comment | 6 complexity | 210100c6b54b7edb8baae45de7aa2829 MD5 | raw file
  1. <?php
  2. /*
  3. homepage: http://arc.semsol.org/
  4. license: http://arc.semsol.org/license
  5. class: ARC2 RDF Store Helper
  6. author: Benjamin Nowack
  7. version: 2010-11-16
  8. */
  9. ARC2::inc('Class');
  10. class ARC2_StoreHelper extends ARC2_Class {
  11. function __construct($a, &$caller) {
  12. parent::__construct($a, $caller);
  13. }
  14. function __init() {/* db_con */
  15. parent::__init();
  16. $this->store = $this->caller;
  17. }
  18. /* */
  19. function changeNamespaceURI($old_uri, $new_uri) {
  20. $id_changes = 0;
  21. $t_changes = 0;
  22. /* table lock */
  23. if ($this->store->getLock()) {
  24. $con = $this->store->getDBCon();
  25. foreach (array('id', 's', 'o') as $id_col) {
  26. $tbl = $this->store->getTablePrefix() . $id_col . '2val';
  27. $sql = 'SELECT id, val FROM ' . $tbl . ' WHERE val LIKE "' . mysql_real_escape_string($old_uri, $con). '%"';
  28. $rs = mysql_query($sql, $con);
  29. if (!$rs) continue;
  30. while ($row = mysql_fetch_array($rs)) {
  31. $new_val = str_replace($old_uri, $new_uri, $row['val']);
  32. $new_id = $this->store->getTermID($new_val, $id_col);
  33. if (!$new_id) {/* unknown ns uri, overwrite current id value */
  34. $sub_sql = "UPDATE " . $tbl . " SET val = '" . mysql_real_escape_string($new_val, $con) . "' WHERE id = " . $row['id'];
  35. $sub_r = mysql_query($sub_sql, $con);
  36. $id_changes++;
  37. }
  38. else {/* replace ids */
  39. $t_tbls = $this->store->getTables();
  40. foreach ($t_tbls as $t_tbl) {
  41. if (preg_match('/^triple/', $t_tbl)) {
  42. foreach (array('s', 'p', 'o', 'o_lang_dt') as $t_col) {
  43. $sub_sql = "UPDATE " . $this->store->getTablePrefix() . $t_tbl . " SET " . $t_col . " = " . $new_id . " WHERE " . $t_col . " = " . $row['id'];
  44. $sub_r = mysql_query($sub_sql, $con);
  45. $t_changes += mysql_affected_rows($con);
  46. }
  47. }
  48. }
  49. }
  50. }
  51. }
  52. $this->store->releaseLock();
  53. }
  54. return array('id_replacements' => $id_changes, 'triple_updates' => $t_changes);
  55. }
  56. /* */
  57. }