Unify package directory calculation of database and script PIP with file pip
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 14 Apr 2023 08:03:14 +0000 (10:03 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 14 Apr 2023 08:03:14 +0000 (10:03 +0200)
Fixes #5392

wcfsetup/install/files/lib/system/package/plugin/DatabasePackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/ScriptPackageInstallationPlugin.class.php

index b73f94d6b2cfa8e62c9e9d360a747194a30cb170..dd30f980161db3b6ba59affb5bdb1a7a66ecd597 100644 (file)
@@ -2,10 +2,11 @@
 
 namespace wcf\system\package\plugin;
 
+use wcf\data\application\Application;
+use wcf\data\package\Package;
 use wcf\system\database\table\DatabaseTableChangeProcessor;
 use wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin;
 use wcf\system\WCF;
-use wcf\util\FileUtil;
 
 /**
  * Executes individual database scripts during installation.
@@ -26,25 +27,15 @@ class DatabasePackageInstallationPlugin extends AbstractPackageInstallationPlugi
         parent::install();
 
         $abbreviation = 'wcf';
-        $path = '';
         if (isset($this->instruction['attributes']['application'])) {
             $abbreviation = $this->instruction['attributes']['application'];
         } elseif ($this->installation->getPackage()->isApplication) {
-            $path = FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir);
+            $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package);
         }
 
-        if (empty($path)) {
-            $dirConstant = \strtoupper($abbreviation) . '_DIR';
-            if (!\defined($dirConstant)) {
-                throw new \InvalidArgumentException("Cannot execute database PIP, abbreviation '{$abbreviation}' is unknown.");
-            }
+        $packageDir = Application::getDirectory($abbreviation);
 
-            $path = \constant($dirConstant);
-        }
-
-        $scriptPath = $path . $this->instruction['value'];
-
-        $this->updateDatabase($scriptPath);
+        $this->updateDatabase($packageDir . $this->instruction['value']);
     }
 
     /**
index 187ab9738e7c713e3d63946adcdde46495f9c6ea..3a8b47fd8a56a906359da1791f79551340dfb6fb 100644 (file)
@@ -2,9 +2,9 @@
 
 namespace wcf\system\package\plugin;
 
+use wcf\data\application\Application;
+use wcf\data\package\Package;
 use wcf\system\cache\CacheHandler;
-use wcf\system\exception\SystemException;
-use wcf\util\FileUtil;
 
 /**
  * Executes individual PHP scripts during installation.
@@ -23,21 +23,13 @@ class ScriptPackageInstallationPlugin extends AbstractPackageInstallationPlugin
         parent::install();
 
         $abbreviation = 'wcf';
-        $path = '';
         if (isset($this->instruction['attributes']['application'])) {
             $abbreviation = $this->instruction['attributes']['application'];
         } elseif ($this->installation->getPackage()->isApplication) {
-            $path = FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir);
+            $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package);
         }
 
-        if (empty($path)) {
-            $dirConstant = \strtoupper($abbreviation) . '_DIR';
-            if (!\defined($dirConstant)) {
-                throw new SystemException("Cannot execute script-PIP, abbreviation '" . $abbreviation . "' is unknown");
-            }
-
-            $path = \constant($dirConstant);
-        }
+        $packageDir = Application::getDirectory($abbreviation);
 
         $flushCache = true;
         if (
@@ -52,7 +44,7 @@ class ScriptPackageInstallationPlugin extends AbstractPackageInstallationPlugin
             CacheHandler::getInstance()->flushAll();
         }
 
-        return $this->run($path . $this->instruction['value']);
+        return $this->run($packageDir . $this->instruction['value']);
     }
 
     /**