From c3da6b068bc22ab31a883e436c2b785427cba2be Mon Sep 17 00:00:00 2001 From: rurban Date: Mon, 28 May 2007 20:13:46 +0000 Subject: [PATCH] Overwrite all attributes at once at page->save to delete dangling meta git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@5704 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/CachedMarkup.php | 17 +++++++++++------ lib/WikiDB.php | 22 ++++++++++++++++++++-- lib/WikiDB/backend/ADODB.php | 8 +++++++- lib/WikiDB/backend/PearDB.php | 16 ++++++++++++++-- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/lib/CachedMarkup.php b/lib/CachedMarkup.php index 74f841aad..2ec113aa2 100644 --- a/lib/CachedMarkup.php +++ b/lib/CachedMarkup.php @@ -1,5 +1,5 @@ * Copyright (C) 2004,2005,2006,2007 $ThePhpWikiProgrammingTeam * @@ -451,17 +451,18 @@ class Cached_SemanticLink extends Cached_WikiLink { else return false; } - /* add relation to the link table. - * attributes have the _relation, but not the _page set. + /* Add relation to the link table. + * attributes have the _relation, but not the _page set. */ function getWikiPageLinks($basepage) { if ($basepage == '') return false; if (!isset($this->_page) and isset($this->_attribute)) { - // an attribute, we store it in the basepage now. - $page = $GLOBALS['request']->getPage($basepage); + // An attribute: we store it in the basepage now, to fill the cache for page->save + // TODO: side-effect free query + $page = $GLOBALS['request']->getPage($basepage); $page->setAttribute($this->_relation, $this->_attribute); + $this->_page = $basepage; return array(array('linkto' => '', 'relation' => $this->_relation)); - //return false; } if ($link = $this->getPagename($basepage)) return array(array('linkto' => $link, 'relation' => $this->_relation)); @@ -754,6 +755,10 @@ class Cached_PluginInvocation extends Cached_DynamicContent { } // $Log: not supported by cvs2svn $ +// Revision 1.56 2007/04/08 16:39:40 rurban +// fix when DISABLE_UNITS = true (thanks to Walter Rafelsberger) +// simplify title calculation +// // Revision 1.55 2007/03/18 17:35:14 rurban // Fix :DontStoreLink // diff --git a/lib/WikiDB.php b/lib/WikiDB.php index 6eae6e74c..fe69c63cc 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -1,5 +1,5 @@ getType(); $meta['pagetype'] = $type->getName(); $links = $formatted->getWikiPageLinks(); // linkto => relation + $attributes = array(); + foreach ($links as $link) { + if ($link['linkto'] === "" and $link['relation']) { + $attributes[$link['relation']] = $this->getAttribute($link['relation']); + } + } + $meta['attribute'] = $attributes; $backend = &$this->_wikidb->_backend; $newrevision = $this->createRevision($version, $wikitext, $meta, $links); @@ -1393,7 +1400,7 @@ class WikiDB_Page else return ''; } - /* Semantic Web value, not stored in the links + /* Semantic Web value, not stored in the links. * todo: unify with some unit knowledge */ function setAttribute($relation, $value) { @@ -1405,6 +1412,14 @@ class WikiDB_Page $this->set('attributes', $attr); } + function getAttribute($relation) { + $meta = $this->get('attributes'); + if (empty($meta)) + return ''; + else + return $meta[$relation]; + } + }; /** @@ -2197,6 +2212,9 @@ function _sql_debuglog_shutdown_function() { } // $Log: not supported by cvs2svn $ +// Revision 1.151 2007/05/01 16:20:12 rurban +// MailNotify->onChangePage only on DEBUG (still broken) +// // Revision 1.150 2007/03/18 17:35:27 rurban // Improve comments // diff --git a/lib/WikiDB/backend/ADODB.php b/lib/WikiDB/backend/ADODB.php index 6dfaa172a..42db3a9b0 100644 --- a/lib/WikiDB/backend/ADODB.php +++ b/lib/WikiDB/backend/ADODB.php @@ -1,5 +1,5 @@ _get_pageid($link['relation'], true); else $relation = 0; + if ($linkto === "") { // ignore attributes + continue; + } // avoid duplicates if (isset($linkseen[$linkto]) and !$relation) { continue; @@ -1545,6 +1548,9 @@ class WikiDB_backend_ADODB_search extends WikiDB_backend_search_sql } // $Log: not supported by cvs2svn $ +// Revision 1.97 2007/01/28 22:53:23 rurban +// protect against $oldlinks warning +// // Revision 1.96 2007/01/21 23:28:32 rurban // Disable hasGenID. requires CREATE perms // diff --git a/lib/WikiDB/backend/PearDB.php b/lib/WikiDB/backend/PearDB.php index da8d2b0e4..faff4cedc 100644 --- a/lib/WikiDB/backend/PearDB.php +++ b/lib/WikiDB/backend/PearDB.php @@ -1,5 +1,5 @@ _get_pageid($pagename, true); $dbh->query("DELETE FROM $link_tbl WHERE linkfrom=$pageid"); - if ($links) { + $linkseen = array(); foreach ($links as $link) { $linkto = $link['linkto']; + if ($linkto === "") { // ignore attributes + continue; + } if ($link['relation']) $relation = $this->_get_pageid($link['relation'], true); else @@ -527,10 +530,16 @@ extends WikiDB_backend if (!$relation) $linkseen[$linkto] = true; $linkid = $this->_get_pageid($linkto, true); + if (!$linkid) { + echo("No link for $linkto on page $pagename"); + //printSimpleTrace(debug_backtrace()); + trigger_error("No link for $linkto on page $pagename"); + } assert($linkid); $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto, relation)" . " VALUES ($pageid, $linkid, $relation)"); } + unset($linkseen); } $this->unlock(); } @@ -1243,6 +1252,9 @@ class WikiDB_backend_PearDB_search extends WikiDB_backend_search_sql } // $Log: not supported by cvs2svn $ +// Revision 1.106 2007/01/04 16:57:32 rurban +// Clarify API: sortby,limit and exclude are strings. fix upgrade test connection +// // Revision 1.105 2006/12/23 13:03:32 rurban // reorder deletion // -- 2.45.0