Implicit fix for erroneous `packageDir` values
authorAlexander Ebert <ebert@woltlab.com>
Fri, 18 Aug 2017 11:53:42 +0000 (13:53 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 18 Aug 2017 11:53:42 +0000 (13:53 +0200)
Closes #2355

wcfsetup/install/files/lib/system/WCF.class.php

index 5099a1f57e4a9f7cb9d6f8cfccbff3a6f7aa19b6..a8879043f2e9da56c037557306198971369e2971 100644 (file)
@@ -554,6 +554,26 @@ class WCF {
                self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/';
                
                $className = $abbreviation.'\system\\'.strtoupper($abbreviation).'Core';
+               
+               // class was not found, possibly the app was moved, but `packageDir` has not been adjusted
+               if (!class_exists($className)) {
+                       // check if both the Core and the app are on the same domain
+                       $coreApp = ApplicationHandler::getInstance()->getApplicationByID(1);
+                       if ($coreApp->domainName === $application->domainName) {
+                               // resolve the relative path and use it to construct the autoload directory
+                               $relativePath = FileUtil::getRelativePath($coreApp->domainPath, $application->domainPath);
+                               if ($relativePath !== './') {
+                                       $packageDir = FileUtil::getRealPath(WCF_DIR.$relativePath);
+                                       self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/';
+                                       
+                                       if (class_exists($className)) {
+                                               // the class can now be found, update the `packageDir` value
+                                               (new PackageEditor($package))->update(['packageDir' => $relativePath]);
+                                       }
+                               }
+                       }
+               }
+               
                if (class_exists($className) && is_subclass_of($className, IApplication::class)) {
                        // include config file
                        $configPath = $packageDir . PackageInstallationDispatcher::CONFIG_FILE;