]> git.mxchange.org Git - friendica.git/commitdiff
Remove BaseURL Auto-Check
authorPhilipp <admin@philipp.info>
Sat, 21 Jan 2023 19:20:29 +0000 (20:20 +0100)
committerPhilipp <admin@philipp.info>
Sat, 21 Jan 2023 20:07:20 +0000 (21:07 +0100)
bin/worker.php
src/App/BaseURL.php
tests/src/Util/BaseURLTest.php

index de207ae98fd5fe26be65c944d0bcdc144ea1b17c..a742132480b923adc203faded953d028660a768d 100755 (executable)
@@ -69,8 +69,6 @@ if (!DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
        return;
 }
 
-DI::baseUrl()->saveByURL(DI::config()->get('system', 'url'));
-
 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
 
 if ($spawn) {
index ab3d03a5bee8fc2cab4af8116d06a5db915b0283..d394dfce9553eae767f41de3700d19eaac67cc5a 100644 (file)
@@ -257,109 +257,14 @@ class BaseURL
         */
        public function __construct(IManageConfigValues $config, array $server)
        {
-               $this->config = $config;
-               $this->server = $server;
-
-               $this->determineSchema();
-               $this->checkConfig();
-       }
-
-       /**
-        * Check the current config during loading
-        */
-       public function checkConfig()
-       {
+               $this->config    = $config;
+               $this->server    = $server;
                $this->hostname  = $this->config->get('config', 'hostname');
-               $this->urlPath   = $this->config->get('system', 'urlpath');
-               $this->sslPolicy = $this->config->get('system', 'ssl_policy');
+               $this->urlPath   = $this->config->get('system', 'urlpath') ?? '';
+               $this->sslPolicy = $this->config->get('system', 'ssl_policy') ?? static::DEFAULT_SSL_SCHEME;
                $this->url       = $this->config->get('system', 'url');
 
-               if (empty($this->hostname)) {
-                       $this->determineHostname();
-
-                       if (!empty($this->hostname)) {
-                               $this->config->set('config', 'hostname', $this->hostname);
-                       }
-               }
-
-               if (!isset($this->urlPath)) {
-                       $this->determineURLPath();
-                       $this->config->set('system', 'urlpath', $this->urlPath);
-               }
-
-               if (!isset($this->sslPolicy)) {
-                       if ($this->scheme == 'https') {
-                               $this->sslPolicy = self::SSL_POLICY_FULL;
-                       } else {
-                               $this->sslPolicy = self::DEFAULT_SSL_SCHEME;
-                       }
-                       $this->config->set('system', 'ssl_policy', $this->sslPolicy);
-               }
-
-               if (empty($this->url)) {
-                       $this->determineBaseUrl();
-
-                       if (!empty($this->url)) {
-                               $this->config->set('system', 'url', $this->url);
-                       }
-               }
-       }
-
-       /**
-        * Determines the hostname of this node if not set already
-        */
-       private function determineHostname()
-       {
-               $this->hostname = '';
-
-               if (!empty($this->server['SERVER_NAME'])) {
-                       $this->hostname = $this->server['SERVER_NAME'];
-
-                       if (!empty($this->server['SERVER_PORT']) && $this->server['SERVER_PORT'] != 80 && $this->server['SERVER_PORT'] != 443) {
-                               $this->hostname .= ':' . $this->server['SERVER_PORT'];
-                       }
-               }
-       }
-
-       /**
-        * Figure out if we are running at the top of a domain or in a sub-directory
-        */
-       private function determineURLPath()
-       {
-               $this->urlPath = '';
-
-               /*
-                * The automatic path detection in this function is currently deactivated,
-                * see issue https://github.com/friendica/friendica/issues/6679
-                *
-                * The problem is that the function seems to be confused with some url.
-                * These then confuses the detection which changes the url path.
-                */
-
-               /* Relative script path to the web server root
-                * Not all of those $_SERVER properties can be present, so we do by inverse priority order
-                */
-               $relative_script_path =
-                       ($this->server['REDIRECT_URL']        ?? '') ?:
-                       ($this->server['REDIRECT_URI']        ?? '') ?:
-                       ($this->server['REDIRECT_SCRIPT_URL'] ?? '') ?:
-                       ($this->server['SCRIPT_URL']          ?? '') ?:
-                        $this->server['REQUEST_URI']         ?? '';
-
-               /* $relative_script_path gives /relative/path/to/friendica/module/parameter
-                * QUERY_STRING gives pagename=module/parameter
-                *
-                * To get /relative/path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING
-                */
-               if (!empty($relative_script_path)) {
-                       // Module
-                       if (!empty($this->server['QUERY_STRING'])) {
-                               $this->urlPath = trim(dirname($relative_script_path, substr_count(trim($this->server['QUERY_STRING'], '/'), '/') + 1), '/');
-                       } else {
-                               // Root page
-                               $this->urlPath = trim($relative_script_path, '/');
-                       }
-               }
+               $this->determineSchema();
        }
 
        /**
index feda9a7c561e186ca71593b4cb3e4c53b6a4b959..4095c344daf159f0cd17842079a47db155e3c3b0 100644 (file)
@@ -200,47 +200,6 @@ class BaseURLTest extends MockedTest
                ];
        }
 
-       /**
-        * Test the default config determination
-        * @dataProvider dataDefault
-        */
-       public function testCheck($server, $input, $assert)
-       {
-               $configMock = \Mockery::mock(IManageConfigValues::class);
-               $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn($input['hostname']);
-               $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn($input['urlPath']);
-               $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']);
-               $configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']);
-
-               // If we don't have an urlPath as an input, we assert it, we will save it to the DB for the next time
-               if (!isset($input['urlPath']) && isset($assert['urlPath'])) {
-                       $configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'])->once();
-               }
-
-               // If we don't have the ssl_policy as an input, we assert it, we will save it to the DB for the next time
-               if (!isset($input['sslPolicy']) && isset($assert['sslPolicy'])) {
-                       $configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'])->once();
-               }
-
-               // If we don't have the hostname as an input, we assert it, we will save it to the DB for the next time
-               if (empty($input['hostname']) && !empty($assert['hostname'])) {
-                       $configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'])->once();
-               }
-
-               // If we don't have an URL at first, but we assert it, we will save it to the DB for the next time
-               if (empty($input['url']) && !empty($assert['url'])) {
-                       $configMock->shouldReceive('set')->with('system', 'url', $assert['url'])->once();
-               }
-
-               $baseUrl = new BaseURL($configMock, $server);
-
-               self::assertEquals($assert['hostname'], $baseUrl->getHostname());
-               self::assertEquals($assert['urlPath'], $baseUrl->getUrlPath());
-               self::assertEquals($assert['sslPolicy'], $baseUrl->getSSLPolicy());
-               self::assertEquals($assert['scheme'], $baseUrl->getScheme());
-               self::assertEquals($assert['url'], $baseUrl->get());
-       }
-
        public function dataSave()
        {
                return [