/** * resets the cache of a blog * * @param blogId The id of the blog whose cache we'd like to reset * @param resetSummary whether the summary cache should also be cleaned up, * enabled by default * @static */ function resetBlogCache($blogId, $resetSummary = true) { $config =& Config::getConfig(); // nothing to do if caching is not enabled... if (!$config->getValue("template_cache_enabled")) { return false; } //$t = new CachedTemplate( null ); $tmpFolder = $config->getValue("temp_folder"); $blogTmpFolder = $tmpFolder . "/" . $blogId; //$t->cache_dir = $blogTmpFolder; //$t->compile_dir = $blogTmpFolder; // recursively delete the contents of the folder, but not its structure or subfolders File::deleteDir($blogTmpFolder, true, true); //$t->clear_cache( null ); // we need to clear the contents of the summary caches because we have added or removed // posts or done something that might affect the summary! if ($resetSummary) { CacheControl::clearSummaryCache(); } return true; }
function perform() { // get a list with all the global template sets $ts = new TemplateSets(); $globalTemplates = $ts->getGlobalTemplateSets(); foreach ($globalTemplates as $template) { if ($template->getName() == $this->_newTemplateId) { $this->_view = new PluginSiteTemplateSetsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_duplicate_templateset_name")); $this->setCommonData(); return false; } } $ts = new TemplateSetStorage(); $blogId = $this->_blogInfo->getId(); $sourceTemplateFolder = $ts->getTemplateFolder($this->_templateId); $newTemplateFolder = $ts->getBaseTemplateFolder() . "/" . $this->_newTemplateId; if (MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder)) { $ts->addTemplate($this->_newTemplateId); } else { File::deleteDir($newTemplateFolder); $this->_view = new PluginSiteTemplateSetsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_copying_templateset")); $this->setCommonData(); return false; } // if everything went ok... $this->_session->setValue("blogInfo", $this->_blogInfo); $this->saveSession(); $this->_view = new PluginSiteTemplateSetsListView($this->_blogInfo); $this->_view->setSuccessMessage($this->_locale->tr("templateeditor_templateset_copyed_ok")); $this->setCommonData(); // clear the cache CacheControl::resetBlogCache($this->_blogInfo->getId()); return true; }
/** * removes a directory, optinally in a recursive fashion * * @param dirName * @param recursive Whether to recurse through all subdirectories that * are within the given one and remove them. * @param onlyFiles If the recursive mode is enabled, setting this to 'true' will * force the method to only remove files but not folders. The directory will not be * removed but all the files included it in (and all subdirectories) will be. * @return True if successful or false otherwise * @static */ function deleteDir($dirName, $recursive = false, $onlyFiles = false) { // if the directory can't be read, then quit with an error if (!File::isReadable($dirName) || !File::exists($dirName)) { return false; } // if it's not a file, let's get out of here and transfer flow // to the right place... if (!File::isDir($dirName)) { return File::delete($dirName); } // Glob::myGlob is easier to use than Glob::glob, specially when // we're relying on the native version... This improved version // will automatically ignore things like "." and ".." for us, // making it much easier! $files = Glob::myGlob($dirName, "*"); foreach ($files as $file) { if (File::isDir($file)) { // perform a recursive call if we were allowed to do so if ($recursive) { File::deleteDir($file, $recursive, $onlyFiles); } } // File::delete can remove empty folders as well as files if (File::isReadable($file)) { File::delete($file); } } // finally, remove the top-level folder but only in case we // are supposed to! if (!$onlyFiles) { File::delete($dirName); } return true; }
/** * Cleans all the temporary folders used by this class during * its execution. * * @param $folder The name of the temporary folder used * @return Returns true */ function cleanUp($folder) { if (!File::isDir($folder)) { return true; } // recursively delete the folder File::deleteDir($folder, true); return true; }
/** * Recursively removes a folder from disk. * * @return True if successful or false otherwise. */ function _removeFolder($folderName) { // if the folder does not even exist, let's not even bother trying... It // could be that it was manually removed by the user or something! if (File::exists($folderName)) { $result = File::deleteDir($folderName, true); } else { $result = true; } return $result; }