/** Backup runtime folder * @param bool $includeDatabase * Backup database, too? * * @return array */ public function backupRuntime($includeDatabase = false) { global $Config, $Database; // create paths $path = $Config->get('dir_runtime'); $path_new = $Config->get('dir_data') . '/backup/runtime/' . date('Y_m_d__H_i_s'); // move folder to backup-directory if (!ts_FileHandler::copyFolder($path, $path_new)) { return false; } // backup database //TODO - skip database-backup (creates too big sql-file!) if ($includeDatabase) { // get path for sql-backup $path_sql = $path_new . '/backup_database.sql'; // backup database // if (!self::backupDatabase($path_sql)) return false; } // get number of backups $path = $Config->get('dir_data') . '/backup/runtime'; $backups = ts_FileHandler::getSubFolders($path); rsort($backups); $counter = 0; foreach ($backups as $index => $value) { $counter++; if ($counter >= 10) { // delete backup ts_FileHandler::deleteFolder($path . '/' . $value); } } return true; }
/** Preparse * @param string $path * Source path * @param string $path_new * Destination path * @param string|bool $path_to_cut * Common path of module/style (internal use) * @param bool $rm_flags * Remove flag comments? * * @return string */ public function parse($path, $path_new, $path_to_cut = "", $rm_flags = false) { global $Config, $Log; // is packet set? if (empty($this->Packet)) { return false; } // get all files $files = ts_FileHandler::getSubfiles($path); // preparse all files foreach ($files as $index => $value) { if (substr($value, -4) == ".swp") { continue; } if (!$this->parseFile("{$path}/{$value}", "{$path_new}/{$value}", $path_to_cut, $rm_flags)) { return false; } } // get all subfolders $subfolders = ts_FileHandler::getSubfolders($path); // parse all subfolders foreach ($subfolders as $index => $value) { // only move directories named static if ($value == 'static') { ts_FileHandler::copyFolder("{$path}/{$value}", "{$path_new}/{$value}"); continue; } if (!$this->parse("{$path}/{$value}", "{$path_new}/{$value}", $path_to_cut, $rm_flags)) { $Log->doLog(3, "PreParser: Failed to preparse subfolder ({$path}/{$value})"); return false; } } return true; }
/** Parse static * * @return bool */ protected function parseStatic() { global $Parser, $Config; // copy all dirs and files if (!ts_FileHandler::copyFolder($this->path . '/static', $Config->get('dir_runtime') . '/static')) { return false; } // overwrite all files directly in /static and do module replacement // get paths $path_source = $this->path . '/static'; $path_destination = $Config->get('dir_runtime') . '/static'; // get all files $files = ts_FileHandler::getSubfiles($path_source); // parse all files foreach ($files as $index => $value) { // read $content = ts_FileHandler::readFile($path_source . '/' . $value); // parse $content = $Parser->replaceModule($content, $this->id); // write if (!$content or !ts_FileHandler::writeFile($path_destination . '/' . $value, $content, 1)) { return false; } } return true; }
/** Preparse and move all files and subfolders within path * * @return bool */ protected function _preparse() { global $Config; // get new path $path_new = $this->_getPath(false, false); // free path if ($this->path == $path_new) { // move $path_old = $this->path . '__moved_by_preparser_' . rand(1, 1000); ts_FileHandler::copyFolder($this->path, $path_old); $this->path = $path_old; } elseif (is_dir($path_new)) { ts_BackupHandler::backupModule($path_new, 'invalid_name'); } ts_FileHandler::deleteFolder($path_new); // load PreParser-object $PreParser = new ts_PreParser($this); // parse if ($PreParser->parse($this->path, $path_new, $Config->get('dir_data'))) { // success // delete old source ts_FileHandler::deleteFolder($this->path); $this->path = $path_new; return true; } // failure ts_FileHandler::deleteFolder($path_new); return false; }
/** Parse images and other files of this style * * @return bool */ protected function parseImages() { global $Config, $Parser; // source-path $path_source = $this->path . '/modules'; // loop modules $modules = ts_FileHandler::getSubfolders($path_source); foreach ($modules as $index => $value) { // get id__module $id__module = $Parser->replaceModule('$' . $value . '$'); if (!$id__module) { continue; } // get path_new $path_new = $Config->get('dir_runtime') . '/files'; $prefix = 'style' . $this->id . '__mod' . $id__module . '__'; // move all files in folder if (!ts_FileHandler::copyFolder($path_source . '/' . $value . '/images', $path_new, true, $prefix)) { return false; } } return true; }