public function before() { parent::before(); $this->site_id_master = $this->request->site_id_master; $this->sitemap_directory_base = str_replace('/', DIRECTORY_SEPARATOR, $this->sitemap_directory_base); if ($this->request->action() == 'generate') { try { $_dir = DOCROOT . $this->sitemap_directory_base . DIRECTORY_SEPARATOR; Ku_Dir::make_writable($_dir); Ku_Dir::remove($_dir); unset($_dir); } catch (Exception $e) { } } }
/** * This function will recursively delete all files in the given path, without * following symlinks. * * @param string path * @return void * @throw Kohana_Exception */ public static function remove($path) { try { // Constructs a new directory iterator from a path $dir = new DirectoryIterator($path); foreach ($dir as $fileinfo) { // Determine if current DirectoryIterator item is a regular file or symbolic link if ($fileinfo->isFile() or $fileinfo->isLink()) { // Deletes a file unlink($fileinfo->getPathName()); } elseif (!$fileinfo->isDot() and $fileinfo->isDir()) { // Recursion Ku_Dir::remove($fileinfo->getPathName()); } } // Removes directory rmdir($path); } catch (Exception $e) { throw new Kohana_Exception('Could not remove :path directory', array(':path' => Debug::path($path))); } }