public function deleteSite($site) { if (!$site) { return; } // get all pages and delete each one $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $pages = DB_PagePeer::instance()->select($c); foreach ($pages as $page) { $this->deletePage($page); } // delete forum? no. will be autodeleted based on the database constrains. // need to delete post revisions $db = Database::connection(); $q = "DELETE FROM forum_post_revision WHERE forum_post_id IN (SELECT post_id FROM forum_post WHERE site_id= {$site->getSiteId()}"; $db->query($q); //delete the site itself $outdater = new Outdater(); $outdater->siteEvent('delete', $site); DB_SitePeer::instance()->deleteByPrimaryKey($site->getSiteId()); }
/** * Changes the "unix name" of the site and effectively its URL address. * * @param unknown_type $runData */ public function renameSiteEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $user = $runData->getUser(); $unixName = trim($pl->getParameterValue('unixName')); $c = new Criteria(); $c->add("user_id", $user->getUserId()); $c->add("site_id", $site->getSiteId()); $c->add("founder", true); $rel = DB_AdminPeer::instance()->selectOne($c); if (!$rel) { throw new ProcessException(_("Sorry, you have no permissions to change URL of this site.")); } $db = Database::connection(); $db->begin(); $oldUnixName = $site->getUnixName(); // validate unix name $errors = array(); if ($unixName == $site->getUnixName()) { $errors['unixname'] = _('The new and current addresses are the same.'); } elseif ($unixName === null || strlen($unixName) < 3 || strlen(WDStringUtils::toUnixName($unixName)) < 3) { $errors['unixname'] = _("Web address must be present and should be at least 3 characters long."); } elseif (strlen($unixName) > 30) { $errors['unixname'] = _("Web address name should not be longer than 30 characters."); } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) { $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.'); } elseif (preg_match("/\\-\\-/", $unixName) !== 0) { $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.'); } else { $unixName = WDStringUtils::toUnixName($unixName); if (!$runData->getUser()->getSuperAdmin()) { // handle forbidden names $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf')); foreach ($forbiddenUnixNames as $f) { if (preg_match($f, $unixName) > 0) { $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.'); } } } // check if the domain is not taken. $c = new Criteria(); $c->add("unix_name", $unixName); $ss = DB_SitePeer::instance()->selectOne($c); if ($ss) { $errors['unixname'] = _('Sorry, this web address is already used by another site.'); } } if (isset($errors['unixname'])) { throw new ProcessException($errors['unixname']); } // remove some data. $c = new Criteria(); $c->add('site_id', $site->getSiteId()); // now clear cache! $keys = array(); $keys[] = 'site..' . $site->getUnixName(); $keys[] = 'site_cd..' . $site->getCustomDomain(); $mc = OZONE::$memcache; foreach ($keys as $k) { $mc->delete($k); } $outdater = new Outdater(); $outdater->siteEvent('delete', $site); $outdater->siteEvent('sitewide_change', $site); // change site name!!! $site->setUnixName($unixName); $site->save(); // remove custom domain link // rename the files @rename(WIKIDOT_ROOT . '/web/files--sites/' . $oldUnixName, WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName()); // delete custom domain link if ($site->getCustomDomain()) { @unlink(WIKIDOT_ROOT . '/web/custom--domains/' . $site->getCustomDomain()); symlink(WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName(), WIKIDOT_ROOT . '/web/custom--domains/' . $site->getCustomDomain()); } $db->commit(); $runData->ajaxResponseAdd("unixName", $site->getUnixName()); }