/** * Uninstall b2evolution: Delete DB & Cache files */ function uninstall_b2evolution() { global $DB; /* REMOVE PAGE CACHE */ load_class('_core/model/_pagecache.class.php', 'PageCache'); // Remove general page cache $PageCache = new PageCache(NULL); $PageCache->cache_delete(); // Skip if T_blogs table is already deleted. Note that db_delete() will not throw any errors on missing tables. if ($DB->query('SHOW TABLES LIKE "T_blogs"')) { // Get all blogs $blogs_SQL = new SQL(); $blogs_SQL->SELECT('blog_ID'); $blogs_SQL->FROM('T_blogs'); $blogs = $DB->get_col($blogs_SQL->get()); $BlogCache =& get_BlogCache('blog_ID'); foreach ($blogs as $blog_ID) { $Blog = $BlogCache->get_by_ID($blog_ID); // Remove page cache of current blog $PageCache = new PageCache($Blog); $PageCache->cache_delete(); } } /* REMOVE DATABASE */ db_delete(); echo '<p>' . T_('Reset done!') . '</p>'; }
/** * Check if the given blog cache directory is ready for operation * * @param mixed blog ID, or NULL to check the general cache * @param boolean true if function should try to repair the corresponding cache folder, false otherwise * @return mixed false if the corresponding setting is disabled, or array( status, message ). */ function system_check_blog_cache($blog_ID = NULL, $repair = false) { global $Settings; load_class('_core/model/_pagecache.class.php', 'PageCache'); $Blog = NULL; $result = NULL; if ($blog_ID == NULL) { if ($Settings->get('general_cache_enabled')) { $result = system_check_dir('cache', 'general/'); $before_msg = T_('General cache') . ': '; } } else { $BlogCache =& get_BlogCache(); $Blog = $BlogCache->get_by_ID($blog_ID); if ($Blog->get_setting('cache_enabled')) { $result = system_check_dir('cache', 'c' . $blog_ID . '/'); $before_msg = sprintf(T_('%s cache') . ': ', $Blog->get('shortname')); } } if (!isset($result)) { return false; } if (!$repair || $result == 0) { return system_get_result($result); } // try to repair the corresponding cache folder $PageCache = new PageCache($Blog); $PageCache->cache_delete(); $PageCache->cache_create(); return system_check_blog_cache($blog_ID, false); }
/** * Delete a blog and dependencies from database * * Includes WAY TOO MANY requests because we try to be compatible with MySQL 3.23, bleh! * * @param boolean true if you want to echo progress */ function dbdelete($echo = false) { global $DB, $Messages, $Plugins; // Try to obtain some serious time to do some serious processing (5 minutes) set_max_execution_time(300); // Note: No need to localize the status messages... if ($echo) { echo '<p>MySQL 3.23 compatibility mode!'; } $DB->begin(); // Get list of cats that are going to be deleted (3.23) if ($echo) { echo '<br />Getting category list to delete... '; } $cat_list = implode(',', $DB->get_col("\n\t\t\t\tSELECT cat_ID\n\t\t\t\t FROM T_categories\n\t\t\t\t WHERE cat_blog_ID = {$this->ID}")); if (empty($cat_list)) { // There are no cats to delete if ($echo) { echo 'None!'; } } else { // Delete the cats & dependencies // Get list of posts that are going to be deleted (3.23) if ($echo) { echo '<br />Getting post list to delete... '; } $post_list = implode(',', $DB->get_col("\n\t\t\t\t\tSELECT postcat_post_ID\n\t\t\t\t\t FROM T_postcats\n\t\t\t\t\t WHERE postcat_cat_ID IN ({$cat_list})")); if (empty($post_list)) { // There are no posts to delete if ($echo) { echo 'None!'; } } else { // Delete the posts & dependencies // TODO: There's also a constraint FK_post_parent_ID.. // Delete postcats if ($echo) { echo '<br />Deleting post-categories... '; } $ret = $DB->query("DELETE FROM T_postcats\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE postcat_cat_ID IN ({$cat_list})"); if ($echo) { printf('(%d rows)', $ret); } $Messages->add(T_('Deleted post-categories'), 'success'); // Delete comments if ($echo) { echo '<br />Deleting comments on blog\'s posts... '; } $comments_list = implode(',', $DB->get_col("\n\t\t\t\t\t\tSELECT comment_ID\n\t\t\t\t\t\t FROM T_comments\n\t\t\t\t\t\t WHERE comment_post_ID IN ({$post_list})")); if (!empty($comments_list)) { // Delete the comments & dependencies $DB->query("DELETE FROM T_comments__votes\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE cmvt_cmt_ID IN ({$comments_list})"); $ret = $DB->query("DELETE FROM T_comments\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE comment_post_ID IN ({$post_list})"); } else { // No comments in this blog $ret = 0; } if ($echo) { printf('(%d rows)', $ret); } $Messages->add(T_('Deleted comments on blog\'s posts'), 'success'); // Delete posts if ($echo) { echo '<br />Deleting blog\'s posts... '; } $DB->query("DELETE FROM T_items__itemtag\n\t\t\t\t\t\t\t\t\t\t\tWHERE itag_itm_ID IN ({$post_list})"); $DB->query("DELETE FROM T_items__item_settings\n\t\t\t\t\t\t\t\t\t\t\tWHERE iset_item_ID IN ({$post_list})"); $DB->query("DELETE FROM T_items__prerendering\n\t\t\t\t\t\t\t\t\t\t\tWHERE itpr_itm_ID IN ({$post_list})"); $DB->query("DELETE FROM T_items__status\n\t\t\t\t\t\t\t\t\t\t\tWHERE pst_ID IN ({$post_list})"); $DB->query("DELETE FROM T_items__subscriptions\n\t\t\t\t\t\t\t\t\t\t\tWHERE isub_item_ID IN ({$post_list})"); $DB->query("DELETE FROM T_items__version\n\t\t\t\t\t\t\t\t\t\t\tWHERE iver_itm_ID IN ({$post_list})"); $DB->query("DELETE FROM T_links\n\t\t\t\t\t\t\t\t\t\t\tWHERE link_itm_ID IN ({$post_list})"); $DB->query("DELETE FROM T_slug\n\t\t\t\t\t\t\t\t\t\t\tWHERE slug_itm_ID IN ({$post_list})"); $ret = $DB->query("DELETE FROM T_items__item\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE post_ID IN ({$post_list})"); if ($echo) { printf('(%d rows)', $ret); } $Messages->add(T_('Deleted blog\'s posts'), 'success'); } // / are there posts? // Delete categories if ($echo) { echo '<br />Deleting blog\'s categories... '; } $ret = $DB->query("DELETE FROM T_categories\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE cat_blog_ID = {$this->ID}"); if ($echo) { printf('(%d rows)', $ret); } $Messages->add(T_('Deleted blog\'s categories'), 'success'); } // / are there cats? // Delete the blog cache folder - try to delete even if cache is disabled load_class('_core/model/_pagecache.class.php', 'PageCache'); $PageCache = new PageCache($this); $PageCache->cache_delete(); // remember ID, because parent method resets it to 0 $old_ID = $this->ID; // Delete main (blog) object: parent::dbdelete(); $DB->commit(); // re-set the ID for the Plugin event $this->ID = $old_ID; $Plugins->trigger_event('AfterCollectionDelete', $params = array('Blog' => &$this)); $this->ID = 0; if ($echo) { echo '<br />Done.</p>'; } }
/** * Enable/Disable the given cache * * @param string cache key name, 'general_cache_enabled', blogs 'cache_enabled' * @param boolean status to set * @param integer the id of the blog, if we want to set a blog's cache. Let it NULL to set general caching. * @param boolean true to save db changes, false if db update will be called outside from this function */ function set_cache_enabled($cache_key, $new_status, $coll_ID = NULL, $save_setting = true) { load_class('_core/model/_pagecache.class.php', 'PageCache'); global $Settings; if (empty($coll_ID)) { // general cache $Blog = NULL; $old_cache_status = $Settings->get($cache_key); } else { // blog page cache $BlogCache =& get_BlogCache(); $Blog = $BlogCache->get_by_ID($coll_ID); $old_cache_status = $Blog->get_setting($cache_key); } $PageCache = new PageCache($Blog); if ($old_cache_status == false && $new_status == true) { // Caching has been turned ON: if ($PageCache->cache_create(false)) { // corresponding cache folder was created if (empty($coll_ID)) { // general cache $result = array('success', T_('General caching has been enabled.')); } else { // blog page cache $result = array('success', T_('Page caching has been enabled.')); } } else { // error creating cache folder if (empty($coll_ID)) { // general cache $result = array('error', T_('General caching could not be enabled. Check /cache/ folder file permissions.')); } else { // blog page cache $result = array('error', T_('Page caching could not be enabled. Check /cache/ folder file permissions.')); } $new_status = false; } } elseif ($old_cache_status == true && $new_status == false) { // Caching has been turned OFF: $PageCache->cache_delete(); if (empty($coll_ID)) { // general cache $result = array('note', T_('General caching has been disabled. Cache contents have been purged.')); } else { // blog page cache $result = array('note', T_('Page caching has been disabled. Cache contents have been purged.')); } } else { // nothing was changed // check if ajax_form_enabled has correct state after b2evo upgrade if ($Blog != NULL && $new_status && !$Blog->get_setting('ajax_form_enabled')) { // if page cache is enabled, ajax form must be enabled to $Blog->set_setting('ajax_form_enabled', true); $Blog->dbupdate(); } return NULL; } // set db changes if ($Blog == NULL) { $Settings->set('general_cache_enabled', $new_status); if ($save_setting) { // save $Settings->dbupdate(); } } else { $Blog->set_setting($cache_key, $new_status); if ($cache_key == 'cache_enabled' && $new_status) { // if page cache is enabled, ajax form must be enabled to $Blog->set_setting('ajax_form_enabled', true); } if ($save_setting) { // save $Blog->dbupdate(); } } return $result; }
/** * Delete a blog and dependencies from database * * @param boolean true if you want to echo progress */ function dbdelete($echo = false) { global $DB, $Messages, $Plugins, $Settings; // Try to obtain some serious time to do some serious processing (5 minutes) set_max_execution_time(300); if ($echo) { echo 'Delete collection with all of it\'s content... '; } // remember ID, because parent method resets it to 0 $old_ID = $this->ID; // Delete main (blog) object: if (!parent::dbdelete()) { $Messages->add('Blog has not been deleted.', 'error'); return false; } // Delete the blog cache folder - try to delete even if cache is disabled load_class('_core/model/_pagecache.class.php', 'PageCache'); $PageCache = new PageCache($this); $PageCache->cache_delete(); // Delete blog's media folder recursively: $FileRootCache =& get_FileRootCache(); if ($root_directory = $FileRootCache->get_root_dir('collection', $old_ID)) { // Delete the folder only when it is detected rmdir_r($root_directory); $Messages->add(T_('Deleted blog\'s files'), 'success'); } // re-set the ID for the Plugin event $this->ID = $old_ID; $Plugins->trigger_event('AfterCollectionDelete', $params = array('Blog' => &$this)); $this->ID = 0; if (isset($Settings)) { // Reset settings related to the deleted blog if ($Settings->get('default_blog_ID') == $old_ID) { // Reset default blog ID $Settings->set('default_blog_ID', 0); } if ($Settings->get('info_blog_ID') == $old_ID) { // Reset info blog ID $Settings->set('info_blog_ID', 0); } if ($Settings->get('login_blog_ID') == $old_ID) { // Reset login blog ID $Settings->set('login_blog_ID', 0); } if ($Settings->get('msg_blog_ID') == $old_ID) { // Reset messaging blog ID $Settings->set('msg_blog_ID', 0); } $Settings->dbupdate(); } if ($echo) { echo '<br />Done.</p>'; } return true; }