From: Alexander Ebert Date: Sat, 17 Dec 2016 11:52:06 +0000 (+0100) Subject: Improved file logger during setup X-Git-Tag: 3.0.0_RC_2~42 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4618869809d6d03acfb220f7f8c96ecc65835f71;p=GitHub%2FWoltLab%2FWCF.git Improved file logger during setup --- diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index aeba6ab1c5..9d68a5da98 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -19,6 +19,7 @@ use wcf\system\package\PackageArchive; use wcf\system\session\ACPSessionFactory; use wcf\system\session\SessionHandler; use wcf\system\setup\Installer; +use wcf\system\setup\SetupFileHandler; use wcf\system\template\SetupTemplateEngine; use wcf\util\DirectoryUtil; use wcf\util\FileUtil; @@ -843,13 +844,13 @@ class WCFSetup extends WCF { $acpTemplateInserts = $fileInserts = []; foreach (self::$installedFiles as $file) { $match = []; - if (preg_match('!/acp/templates/([^/]+)\.tpl$!', $file, $match)) { + if (preg_match('~^acp/templates/([^/]+)\.tpl$~', $file, $match)) { // acp template $acpTemplateInserts[] = $match[1]; } else { // regular file - $fileInserts[] = preg_replace('/^'.preg_quote(WCF_DIR, '/').'/', '', $file); + $fileInserts[] = $file; } } @@ -888,18 +889,17 @@ class WCFSetup extends WCF { * Scans the given dir for installed files. * * @param string $dir + * @throws SystemException */ protected function getInstalledFiles($dir) { - if ($files = glob($dir.'*')) { - foreach ($files as $file) { - if (is_dir($file)) { - $this->getInstalledFiles(FileUtil::addTrailingSlash($file)); - } - else { - self::$installedFiles[] = FileUtil::unifyDirSeparator($file); - } - } + $logFile = $dir . 'files.log'; + if (!file_exists($logFile)) { + throw new SystemException("Expected a valid file log at '".$logFile."'."); } + + self::$installedFiles = explode("\n", file_get_contents($logFile)); + + @unlink($logFile); } /** @@ -1234,7 +1234,9 @@ class WCFSetup extends WCF { * Installs the files of the tar archive. */ protected static function installFiles() { - new Installer(self::$directories['wcf'], SETUP_FILE, null, 'install/files/'); + $fileHandler = new SetupFileHandler(); + new Installer(self::$directories['wcf'], SETUP_FILE, $fileHandler, 'install/files/'); + $fileHandler->dumpToFile(self::$directories['wcf'] . 'files.log'); } /** diff --git a/wcfsetup/install/files/lib/system/setup/SetupFileHandler.class.php b/wcfsetup/install/files/lib/system/setup/SetupFileHandler.class.php new file mode 100644 index 0000000000..16000f8bce --- /dev/null +++ b/wcfsetup/install/files/lib/system/setup/SetupFileHandler.class.php @@ -0,0 +1,41 @@ + + * @package WoltLabSuite\Core\System\Setup + */ +class SetupFileHandler implements IFileHandler { + /** + * list of installed files + * @var string[] + */ + protected $files; + + /** + * @inheritDoc + */ + public function checkFiles(array $files) { + /* does nothing */ + } + + /** + * @inheritDoc + */ + public function logFiles(array $files) { + $this->files = $files; + } + + /** + * Writes the list of files to a log file. + * + * @param string $filename + */ + public function dumpToFile($filename) { + file_put_contents($filename, implode("\n", $this->files)); + } +}