]> git.mxchange.org Git - friendica.git/commitdiff
Replace Addon::DIRECTORY with AddonHelper::getAddonPath()
authorArt4 <art4@wlabs.de>
Tue, 4 Feb 2025 15:18:23 +0000 (15:18 +0000)
committerArt4 <art4@wlabs.de>
Tue, 4 Feb 2025 15:18:23 +0000 (15:18 +0000)
src/App.php
src/Core/Config/Factory/Config.php
src/Core/Config/Util/ConfigFileManager.php
src/Module/Admin/Summary.php
static/dependencies.config.php
tests/Util/CreateDatabaseTrait.php
tests/src/Core/Config/Cache/ConfigFileManagerTest.php
tests/src/Core/Config/ConfigTest.php
tests/src/Core/Config/ConfigTransactionTest.php
tests/src/Core/Storage/Repository/StorageManagerTest.php
tests/src/Database/DatabaseTest.php

index 9c65c8e379ab5b05a62fc6a256d35def6300e379..366d20fbdbe836da8c1e695617826c993980266f 100644 (file)
@@ -166,6 +166,8 @@ class App
                $this->session   = $this->container->create(IHandleUserSessions::class);
                $this->appHelper = $this->container->create(AppHelper::class);
 
+               $addonHelper = $this->container->create(AddonHelper::class);
+
                $this->load(
                        $request->getServerParams(),
                        $this->container->create(DbaDefinition::class),
@@ -174,6 +176,7 @@ class App
                        $this->config,
                        $this->profiler,
                        $this->appHelper,
+                       $addonHelper,
                );
 
                $this->registerTemplateEngine();
@@ -182,7 +185,7 @@ class App
                        $this->container->create(IManagePersonalConfigValues::class),
                        $this->container->create(Page::class),
                        $this->container->create(Nav::class),
-                       $this->container->create(AddonHelper::class),
+                       $addonHelper,
                        $this->container->create(ModuleHTTPException::class),
                        $start_time,
                        $request
@@ -212,6 +215,7 @@ class App
                        $this->container->create(IManageConfigValues::class),
                        $this->container->create(Profiler::class),
                        $this->container->create(AppHelper::class),
+                       $this->container->create(AddonHelper::class),
                );
 
                $this->registerTemplateEngine();
@@ -240,6 +244,7 @@ class App
                        $this->container->create(IManageConfigValues::class),
                        $this->container->create(Profiler::class),
                        $this->container->create(AppHelper::class),
+                       $this->container->create(AddonHelper::class),
                );
 
                /** @var BasePath */
@@ -318,7 +323,8 @@ class App
                Mode $mode,
                IManageConfigValues $config,
                Profiler $profiler,
-               AppHelper $appHelper
+               AppHelper $appHelper,
+               AddonHelper $addonHelper
        ): void {
                if ($config->get('system', 'ini_max_execution_time') !== false) {
                        set_time_limit((int) $config->get('system', 'ini_max_execution_time'));
@@ -340,7 +346,7 @@ class App
 
                if ($mode->has(Mode::DBAVAILABLE)) {
                        Core\Hook::loadHooks();
-                       $loader = (new Config())->createConfigFileManager($appHelper->getBasePath(), $serverParams);
+                       $loader = (new Config())->createConfigFileManager($appHelper->getBasePath(), $addonHelper->getAddonPath(), $serverParams);
                        Core\Hook::callAll('load_config', $loader);
 
                        // Hooks are now working, reload the whole definitions with hook enabled
index da9daa572dad54c4e2a4c8854ff9a2afd6342b06..30d3e597c6ca90946b8a8e59a31aa62013018125 100644 (file)
@@ -42,7 +42,7 @@ class Config
         *
         * @return Util\ConfigFileManager
         */
-       public function createConfigFileManager(string $basePath, array $server = []): Util\ConfigFileManager
+       public function createConfigFileManager(string $basePath, string $addonPath, array $server = []): Util\ConfigFileManager
        {
                if (!empty($server[self::CONFIG_DIR_ENV]) && is_dir($server[self::CONFIG_DIR_ENV])) {
                        $configDir = $server[self::CONFIG_DIR_ENV];
@@ -51,7 +51,7 @@ class Config
                }
                $staticDir = $basePath . DIRECTORY_SEPARATOR . self::STATIC_DIR;
 
-               return new Util\ConfigFileManager($basePath, $configDir, $staticDir, $server);
+               return new Util\ConfigFileManager($basePath, $addonPath, $configDir, $staticDir, $server);
        }
 
        /**
index ecb06a7cc80da56080c37ea62cb3e295f34d489f..def31c4b8c68ac279472af0c738c97ee05fab7b0 100644 (file)
@@ -7,7 +7,6 @@
 
 namespace Friendica\Core\Config\Util;
 
-use Friendica\Core\Addon;
 use Friendica\Core\Config\Exception\ConfigFileException;
 use Friendica\Core\Config\ValueObject\Cache;
 
@@ -46,6 +45,7 @@ class ConfigFileManager
         * @var string
         */
        private $baseDir;
+       private string $addonDir;
        /**
         * @var string
         */
@@ -65,9 +65,10 @@ class ConfigFileManager
         * @param string $configDir
         * @param string $staticDir
         */
-       public function __construct(string $baseDir, string $configDir, string $staticDir, array $server = [])
+       public function __construct(string $baseDir, string $addonDir, string $configDir, string $staticDir, array $server = [])
        {
                $this->baseDir   = $baseDir;
+               $this->addonDir  = $addonDir;
                $this->configDir = $configDir;
                $this->staticDir = $staticDir;
                $this->server    = $server;
@@ -160,17 +161,16 @@ class ConfigFileManager
         */
        public function loadAddonConfig(string $name): array
        {
-               $filepath = $this->baseDir . DIRECTORY_SEPARATOR .   // /var/www/html/
-                                       Addon::DIRECTORY . DIRECTORY_SEPARATOR . // addon/
-                                       $name . DIRECTORY_SEPARATOR .            // openstreetmap/
-                                       'config' . DIRECTORY_SEPARATOR .         // config/
-                                       $name . ".config.php";                   // openstreetmap.config.php
+               $filepath = $this->addonDir . DIRECTORY_SEPARATOR . // /var/www/html/addon/
+                                       $name . DIRECTORY_SEPARATOR .           // openstreetmap/
+                                       'config' . DIRECTORY_SEPARATOR .        // config/
+                                       $name . ".config.php";                  // openstreetmap.config.php
 
-               if (file_exists($filepath)) {
-                       return $this->loadConfigFile($filepath);
-               } else {
+               if (!file_exists($filepath)) {
                        return [];
                }
+
+               return $this->loadConfigFile($filepath);
        }
 
        /**
index 72ce10e41817e3d1ec0888331eba3e37c2c531ea..282c15e4bcfae0dfe6923376096805923a45d434 100644 (file)
@@ -26,7 +26,8 @@ class Summary extends BaseAdmin
        {
                parent::content();
 
-               $basePath = DI::appHelper()->getBasePath();
+               $basePath  = DI::appHelper()->getBasePath();
+               $addonPath = DI::addonHelper()->getAddonPath();
 
                // are there MyISAM tables in the DB? If so, trigger a warning message
                $warningtext = [];
@@ -117,7 +118,7 @@ class Summary extends BaseAdmin
                }
 
                // check legacy basepath settings
-               $configLoader = (new Config())->createConfigFileManager($basePath, $_SERVER);
+               $configLoader = (new Config())->createConfigFileManager($basePath, $addonPath, $_SERVER);
                $configCache  = new Cache();
                $configLoader->setupCache($configCache);
                $confBasepath = $configCache->get('system', 'basepath');
index d2de70d2082c80166a26dd98efb476d16b6c378e..6e6f7ecf52374b95b40c5184d5267f26bc49e7f7 100644 (file)
@@ -87,6 +87,7 @@ return (function(string $basepath, array $getVars, array $serverVars, array $coo
                        'call' => [
                                ['createConfigFileManager', [
                                        $basepath,
+                                       $basepath . '/addon',
                                        $serverVars,
                                ], Dice::CHAIN_CALL],
                        ],
index c188ee8f947685ef45643ba8d83bf7ed0ce67b94..bae22a9e79007c28ae0bb5ddcf8f9d035cd1349e 100644 (file)
@@ -32,7 +32,12 @@ trait CreateDatabaseTrait
                        return $this->dba;
                }
 
-               $configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
+               $configFileManager = new ConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+                       $this->root->url() . '/config',
+                       $this->root->url() . '/static'
+               );
                $config            = new ReadOnlyFileConfig(new Cache([
                        'database' => [
                                'disable_pdo' => true
index e5b1fc623dd6fce05d46f98f44673cd11b49ef8a..098f8c3e74788cab23a1a9b338585d0dbc9f8f5f 100644 (file)
@@ -34,6 +34,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -61,6 +62,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -90,6 +92,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -127,6 +130,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -163,6 +167,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -217,6 +222,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -254,6 +260,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -288,6 +295,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -322,6 +330,7 @@ class ConfigFileManagerTest extends MockedTestCase
 
                $configFileLoader = new ConfigFileManager(
                        $this->root->url(),
+                       $this->root->url() . DIRECTORY_SEPARATOR . 'addon',
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
                        $this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
                );
@@ -341,7 +350,11 @@ class ConfigFileManagerTest extends MockedTestCase
        {
                $this->delConfigFile('local.config.php');
 
-               $configFileManager = (new Config())->createConfigFileManager($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
+               $configFileManager = (new Config())->createConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+                       ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/'],
+               );
                $configCache       = new Cache();
 
                $configFileManager->setupCache($configCache);
@@ -367,10 +380,11 @@ class ConfigFileManagerTest extends MockedTestCase
                                 ->at($this->root->getChild('config2'))
                                 ->setContent(file_get_contents($fileDir . 'B.config.php'));
 
-               $configFileManager = (new Config())->createConfigFileManager($this->root->url(),
-                       [
-                               'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
-                       ]);
+               $configFileManager = (new Config())->createConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+                       ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()],
+               );
                $configCache       = new Cache();
 
                $configFileManager->setupCache($configCache);
@@ -389,11 +403,12 @@ class ConfigFileManagerTest extends MockedTestCase
                                 ->at($this->root->getChild('config'))
                                 ->setContent('');
 
-               $configFileManager = (new Config())->createConfigFileManager($this->root->url());
+               $configFileManager = (new Config())->createConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+               );
                $configCache       = new Cache();
 
                $configFileManager->setupCache($configCache);
-
-               self::assertEquals(1,1);
        }
 }
index 83dbaa0af051d6320884d2ac3e6ad919f9d79cf7..079c39eb6600f43df32a1e826dcca145f4e0e94d 100644 (file)
@@ -56,7 +56,12 @@ class ConfigTest extends DatabaseTestCase
                parent::setUp();
 
                $this->configCache = new Cache();
-               $this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
+               $this->configFileManager = new ConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+                       $this->root->url() . '/config',
+                       $this->root->url() . '/static'
+               );
        }
 
        /**
@@ -608,7 +613,13 @@ class ConfigTest extends DatabaseTestCase
                $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'env.config.php', true);
                $this->loadDirectFixture($this->configToDbArray($data), $this->getDbInstance());
 
-               $configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/', $server);
+               $configFileManager = new ConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+                       $this->root->url() . '/config',
+                       $this->root->url() . '/static',
+                       $server
+               );
                $configFileManager->setupCache($this->configCache);
                $config = new DatabaseConfig($this->getDbInstance(), $this->configCache);
 
index 5c704b76004b4a79b7414176aa037f50ff3ceece..5e1435cf36328b53cf64cf2b1dadd12cefe6281b 100644 (file)
@@ -30,7 +30,12 @@ class ConfigTransactionTest extends FixtureTestCase
        {
                parent::setUp();
 
-               $this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
+               $this->configFileManager = new ConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+                       $this->root->url() . '/config',
+                       $this->root->url() . '/static'
+               );
        }
 
        public function dataTests(): array
index ac74274c03405f5cba07bca18fc12f78af8f90fc..4e56c094c13613c48ec27bb240d46c92a757e4ce 100644 (file)
@@ -64,7 +64,10 @@ class StorageManagerTest extends DatabaseTestCase
                $this->database = $this->getDbInstance();
 
                $configFactory     = new Config();
-               $configFileManager = $configFactory->createConfigFileManager($this->root->url());
+               $configFileManager = $configFactory->createConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+               );
                $configCache       = $configFactory->createCache($configFileManager);
 
                $this->config = new \Friendica\Core\Config\Model\DatabaseConfig($this->database, $configCache);
index c889d6d7d157166395159f15a9eeebc1485d9cb8..5e01ed79da75f1185103d59b96417678ad06182d 100644 (file)
@@ -32,7 +32,12 @@ class DatabaseTest extends FixtureTestCase
                parent::setUp();
 
                $this->configCache       = new Cache();
-               $this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
+               $this->configFileManager = new ConfigFileManager(
+                       $this->root->url(),
+                       $this->root->url() . '/addon',
+                       $this->root->url() . '/config',
+                       $this->root->url() . '/static'
+               );
        }
 
        /**