Revert BaseURL

This commit is contained in:
Philipp 2023-01-03 13:16:19 +01:00
parent 376e0a9397
commit 4d4b4a8858
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
2 changed files with 36 additions and 68 deletions

View file

@ -177,7 +177,7 @@ class BaseURL
$currURLPath = $this->urlPath;
if (!empty($hostname) && $hostname !== $this->hostname) {
if ($this->config->set('config', 'hostname', $hostname, false)) {
if ($this->config->set('config', 'hostname', $hostname)) {
$this->hostname = $hostname;
} else {
return false;
@ -185,45 +185,40 @@ class BaseURL
}
if (isset($sslPolicy) && $sslPolicy !== $this->sslPolicy) {
if ($this->config->set('system', 'ssl_policy', $sslPolicy, false)) {
if ($this->config->set('system', 'ssl_policy', $sslPolicy)) {
$this->sslPolicy = $sslPolicy;
} else {
$this->hostname = $currHostname;
$this->config->set('config', 'hostname', $this->hostname, false);
$this->config->save();
$this->config->set('config', 'hostname', $this->hostname);
return false;
}
}
if (isset($urlPath) && $urlPath !== $this->urlPath) {
if ($this->config->set('system', 'urlpath', $urlPath, false)) {
if ($this->config->set('system', 'urlpath', $urlPath)) {
$this->urlPath = $urlPath;
} else {
$this->hostname = $currHostname;
$this->sslPolicy = $currSSLPolicy;
$this->config->set('config', 'hostname', $this->hostname, false);
$this->config->set('system', 'ssl_policy', $this->sslPolicy, false);
$this->config->save();
$this->config->set('config', 'hostname', $this->hostname);
$this->config->set('system', 'ssl_policy', $this->sslPolicy);
return false;
}
}
$this->determineBaseUrl();
if (!$this->config->set('system', 'url', $this->url, false)) {
if (!$this->config->set('system', 'url', $this->url)) {
$this->hostname = $currHostname;
$this->sslPolicy = $currSSLPolicy;
$this->urlPath = $currURLPath;
$this->determineBaseUrl();
$this->config->set('config', 'hostname', $this->hostname, false);
$this->config->set('system', 'ssl_policy', $this->sslPolicy, false);
$this->config->set('system', 'urlpath', $this->urlPath, false);
$this->config->save();
$this->config->set('config', 'hostname', $this->hostname);
$this->config->set('system', 'ssl_policy', $this->sslPolicy);
$this->config->set('system', 'urlpath', $this->urlPath);
return false;
}
$this->config->save();
return true;
}
@ -300,21 +295,17 @@ class BaseURL
$this->sslPolicy = $this->config->get('system', 'ssl_policy');
$this->url = $this->config->get('system', 'url');
$savable = false;
if (empty($this->hostname)) {
$this->determineHostname();
if (!empty($this->hostname)) {
$this->config->set('config', 'hostname', $this->hostname, false);
$savable = true;
$this->config->set('config', 'hostname', $this->hostname);
}
}
if (!isset($this->urlPath)) {
$this->determineURLPath();
$this->config->set('system', 'urlpath', $this->urlPath, false);
$savable = true;
$this->config->set('system', 'urlpath', $this->urlPath);
}
if (!isset($this->sslPolicy)) {
@ -323,22 +314,16 @@ class BaseURL
} else {
$this->sslPolicy = self::DEFAULT_SSL_SCHEME;
}
$this->config->set('system', 'ssl_policy', $this->sslPolicy, false);
$savable = true;
$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, false);
$savable = true;
$this->config->set('system', 'url', $this->url);
}
}
if ($savable) {
$this->config->save();
}
}
/**

View file

@ -199,34 +199,24 @@ class BaseURLTest extends MockedTest
$configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']);
$configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']);
$savable = false;
// 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'], false)->once();
$savable = true;
$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'], false)->once();
$savable = true;
$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'], false)->once();
$savable = true;
$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'], false)->once();
$savable = true;
}
if ($savable) {
$configMock->shouldReceive('save')->once();
$configMock->shouldReceive('set')->with('system', 'url', $assert['url'])->once();
}
$baseUrl = new BaseURL($configMock, $server);
@ -335,20 +325,18 @@ class BaseURLTest extends MockedTest
$baseUrl = new BaseURL($configMock, []);
if (isset($save['hostname'])) {
$configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'], false)->andReturn(true)->once();
$configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'])->andReturn(true)->once();
}
if (isset($save['urlPath'])) {
$configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'], false)->andReturn(true)->once();
$configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'])->andReturn(true)->once();
}
if (isset($save['sslPolicy'])) {
$configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'], false)->andReturn(true)->once();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'])->andReturn(true)->once();
}
$configMock->shouldReceive('set')->with('system', 'url', $url, false)->andReturn(true)->once();
$configMock->shouldReceive('save')->once();
$configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once();
$baseUrl->save($save['hostname'], $save['sslPolicy'], $save['urlPath']);
@ -375,20 +363,18 @@ class BaseURLTest extends MockedTest
$baseUrl = new BaseURL($configMock, []);
if (isset($save['hostname'])) {
$configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'], false)->andReturn(true)->once();
$configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'])->andReturn(true)->once();
}
if (isset($save['urlPath'])) {
$configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'], false)->andReturn(true)->once();
$configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'])->andReturn(true)->once();
}
if (isset($save['sslPolicy'])) {
$configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'], false)->andReturn(true)->once();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'])->andReturn(true)->once();
}
$configMock->shouldReceive('set')->with('system', 'url', $url, false)->andReturn(true)->once();
$configMock->shouldReceive('save')->once();
$configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once();
$baseUrl->saveByURL($url);
@ -545,25 +531,22 @@ class BaseURLTest extends MockedTest
switch ($fail) {
case 'hostname':
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(false)->once();
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(false)->once();
break;
case 'sslPolicy':
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(false)->once();
$configMock->shouldReceive('save')->once();
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(false)->once();
break;
case 'urlPath':
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any(), false)->andReturn(false)->once();
$configMock->shouldReceive('save')->once();
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any())->andReturn(false)->once();
break;
case 'url':
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any(), false)->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'url', \Mockery::any(), false)->andReturn(false)->once();
$configMock->shouldReceive('save')->once();
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'url', \Mockery::any())->andReturn(false)->once();
break;
}