From d6b4b95fb5ffd79deb8c4450eb0e05eaa47967d9 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 28 Jan 2003 09:41:24 +0000 Subject: [PATCH] added method to sync with the database (write the array contents to the db) --- lib/session/SiteMap.inc | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/session/SiteMap.inc b/lib/session/SiteMap.inc index e4ce3e2..8c13e7a 100644 --- a/lib/session/SiteMap.inc +++ b/lib/session/SiteMap.inc @@ -460,7 +460,7 @@ class SiteMap { * @return string the action for this page */ function getActionFromPageUsingDB($sPage) { - global $default, $lang_err_database; + global $default, $lang_err_database; $sql = new Owl_DB(); // lookup the action for the specified page @@ -513,5 +513,50 @@ class SiteMap { return arrayToString($this->aSiteMap); } } + + /** + * Writes the current sitemap from the array to the DB + */ + function syncWithDB() { + global $default; + $sql = new Owl_DB(); + + // only if we're using the array + if (!$this->bUseDB) { + // clear section table + if ($sql->query("DELETE from $default->owl_site_sections_table")) { + $default->log->debug("Sitemap::syncWithDB removed sections"); + } else { + $default->log->error("Sitemap::syncWithDB remove sections failed"); + } + // for each section + foreach ($this->aSiteMap as $section => $valArr) { + // insert into the section + $sSectionSql = "INSERT INTO $default->owl_site_sections_table (name) VALUES ('$section')"; + $default->log->debug("Sitemap::syncWithDB insert=$sSectionSql"); + + if ($sql->query($sSectionSql)) { + $sectionID = $sql->insert_id(); + $default->log->debug("Sitemap::syncWithDB added section $section; $sectionID"); + } else { + $default->log->error("Sitemap::syncWithDB add section $section failed"); + } + + // for each group, page array combination + foreach ($valArr as $requiredAccess => $pageArr) { + // now loop through all the pages + foreach ($pageArr as $action => $page) { + $sSiteMapSql = "INSERT INTO $default->owl_sitemap_table (action, page, section_id, access_id, link_text, is_default) " . + "VALUES ('$action', '" . $page["page"] . "', $sectionID, $requiredAccess, '" . $page["description"] . "', " . settype($page["default"], bool) . ")"; + if ($sql->query($sSiteMapSql)) { + $default->log->debug("Sitemap::syncWithDb sitemap insert worked for ($action, " . $page["page"] . ")"); + } else { + $default->log->debug("Sitemap::syncWithDB sitemap insert failed ($sSiteMapSql)"); + } + } + } + } + } + } } ?> -- libgit2 0.21.4