Improved file logger during setup
authorAlexander Ebert <ebert@woltlab.com>
Sat, 17 Dec 2016 11:52:06 +0000 (12:52 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 17 Dec 2016 11:52:06 +0000 (12:52 +0100)
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/setup/SetupFileHandler.class.php [new file with mode: 0644]

index aeba6ab1c583ae3248c5adf6c529750a26067c63..9d68a5da983f056dde64fb8b73afb54d67a72c68 100644 (file)
@@ -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 (file)
index 0000000..16000f8
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+namespace wcf\system\setup;
+
+/**
+ * Special file handler used during setup to log the deployed files.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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));
+       }
+}