Ejemplo n.º 1
0
 public function deletePage($page, $site = null)
 {
     // I hope everything here is within a TRANSACTION!!!
     if (!$page) {
         return;
     }
     if (!$site) {
         $site = DB_SitePeer::instance()->selectByPrimaryKey($page->getSiteId());
     }
     // delete the sources and metadatas
     $db = Database::connection();
     // get descandants first
     $rec = 0;
     $c = new Criteria();
     $c->add("parent_page_id", $page->getPageId());
     $pages = DB_PagePeer::instance()->select($c);
     // ok, these are direct children. need to clear the perent_page_id field
     $descs = array();
     while ($pages !== null && count($pages) > 0 && $rec < 10) {
         $p2 = array();
         foreach ($pages as $p) {
             $c = new Criteria();
             $c->add("parent_page_id", $p->getPageId());
             $ptmp = DB_PagePeer::instance()->select($c);
             $p2 = array_merge($p2, $ptmp);
             if ($rec === 0) {
                 $p->setParentPageId(null);
                 $p->save();
                 // clear metadata
                 $m = $p->getMetadata();
                 $m->setParentPageId(null);
                 $m->save();
             }
         }
         $descs = array_merge($descs, $pages, $p2);
         $pages = $p2;
         $rec++;
     }
     $category = $page->getCategory();
     // sources
     $q = "DELETE FROM page_source WHERE source_id IN (SELECT page_revision.source_id FROM page_revision WHERE page_id='" . $page->getPageId() . "')";
     $db->query($q);
     //metadatas
     $q = "DELETE FROM page_metadata WHERE metadata_id IN (SELECT page_revision.metadata_id FROM page_revision WHERE page_id='" . $page->getPageId() . "')";
     $db->query($q);
     // delete the page too
     $q = "DELETE FROM page WHERE page_id='" . $page->getPageId() . "'";
     $db->query($q);
     // remove from cache too.
     $outdater = new Outdater();
     $outdater->pageEvent('delete', $page->getUnixName());
     // outdate descs too
     foreach ($descs as $desc) {
         $outdater->outdatePageCache($desc);
     }
     // delete the category if empty
     if ($category->getName() != "_default") {
         $c = new Criteria();
         $c->add("category_id", $category->getCategoryId());
         $count = DB_PagePeer::instance()->selectCount($c);
         if ($count == 0) {
             // delete the category
             DB_CategoryPeer::instance()->delete($c);
             $outdater->categoryEvent('delete', $category, $site);
         }
     }
     // remove FILES (if any)
     $path = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/files/" . $page->getUnixName();
     exec('rm -r ' . escapeshellarg($path) . ' &> /dev/null');
     //
 }
Ejemplo n.º 2
0
 public function saveOpenIDEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $settings = $site->getSettings();
     $openIdEnabled = $pl->getParameterValue("enableOpenID") == "true";
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $vals = $json->decode($pl->getParameterValue("vals"));
     $affectedPages = array();
     $outdater = new Outdater();
     $db = Database::connection();
     $db->begin();
     $settings->setOpenidEnabled($openIdEnabled);
     $settings->save();
     // get the already assigned openids
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $oldOpenIDs = DB_OpenidEntryPeer::instance()->select($c);
     $rootProcessed = false;
     $oldOpenIDs2 = $oldOpenIDs;
     foreach ($vals as $val) {
         $pageId = null;
         $page = null;
         if ($val['page']) {
             // not a root page
             $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $val['page']);
             if (!$page) {
                 throw new ProcessException(sprintf(_("The page %s can not be found"), $vals['page']));
             }
             $pageId = $page->getPageId();
         } elseif (!$rootProcessed) {
             $rootProcessed = true;
         } elseif ($rootProcessed) {
             continue;
         }
         // validate the data
         $url = $val['identityUrl'];
         $serverUrl = $val['serverUrl'];
         if (!$url) {
             continue;
         }
         if (!preg_match(';^[a-z0-9\\-\\./#]+$;i', $url)) {
             throw new ProcessException(sprintf("Identity URL %s is not valid.", $url));
         }
         if (!preg_match(';^https?://[a-z0-9\\-\\./#]+$;i', $serverUrl)) {
             throw new ProcessException(sprintf("Server URL %s is not valid.", $serverUrl));
         }
         // check if the entry already exists
         $entry = null;
         foreach ($oldOpenIDs as $oo) {
             if ($oo->getPageId() === $pageId) {
                 $entry = $oo;
                 foreach ($oldOpenIDs2 as $oo2key => &$oo2) {
                     if ($oo2->getPageId() === $pageId) {
                         $ookey = $oo2key;
                         break;
                     }
                 }
                 unset($oldOpenIDs2[$ookey]);
                 break;
             }
         }
         if (!$entry) {
             $entry = new DB_OpenidEntry();
             $entry->setSiteId($site->getSiteId());
             $entry->setPageId($pageId);
         }
         $entry->setUrl('http://' . $url);
         $entry->setServerUrl($serverUrl);
         // save the entry
         $entry->save();
         // outdate caches
         if ($page) {
             $outdater->outdatePageCache($page);
         } else {
             $outdater->outdatePageCache($site->getDefaultPage());
         }
     }
     // remove unused entries
     foreach ($oldOpenIDs2 as $oo) {
         DB_OpenidEntryPeer::instance()->deleteByPrimaryKey($oo->getOpenidId());
         // outdate caches
         $pageId = $oo->getPageId();
         if ($pageId) {
             $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId);
         } else {
             $page = $site->getDefaultPage();
         }
         $outdater->outdatePageCache($page);
     }
     $db->commit();
 }