Revert BaseURL

This commit is contained in:
Philipp Holzer 2023-01-03 13:16:19 +01:00
parent 376e0a9397
commit 4d4b4a8858
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
2 changed files with 36 additions and 68 deletions

View file

@ -177,7 +177,7 @@ class BaseURL
$currURLPath = $this->urlPath; $currURLPath = $this->urlPath;
if (!empty($hostname) && $hostname !== $this->hostname) { if (!empty($hostname) && $hostname !== $this->hostname) {
if ($this->config->set('config', 'hostname', $hostname, false)) { if ($this->config->set('config', 'hostname', $hostname)) {
$this->hostname = $hostname; $this->hostname = $hostname;
} else { } else {
return false; return false;
@ -185,45 +185,40 @@ class BaseURL
} }
if (isset($sslPolicy) && $sslPolicy !== $this->sslPolicy) { 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; $this->sslPolicy = $sslPolicy;
} else { } else {
$this->hostname = $currHostname; $this->hostname = $currHostname;
$this->config->set('config', 'hostname', $this->hostname, false); $this->config->set('config', 'hostname', $this->hostname);
$this->config->save();
return false; return false;
} }
} }
if (isset($urlPath) && $urlPath !== $this->urlPath) { if (isset($urlPath) && $urlPath !== $this->urlPath) {
if ($this->config->set('system', 'urlpath', $urlPath, false)) { if ($this->config->set('system', 'urlpath', $urlPath)) {
$this->urlPath = $urlPath; $this->urlPath = $urlPath;
} else { } else {
$this->hostname = $currHostname; $this->hostname = $currHostname;
$this->sslPolicy = $currSSLPolicy; $this->sslPolicy = $currSSLPolicy;
$this->config->set('config', 'hostname', $this->hostname, false); $this->config->set('config', 'hostname', $this->hostname);
$this->config->set('system', 'ssl_policy', $this->sslPolicy, false); $this->config->set('system', 'ssl_policy', $this->sslPolicy);
$this->config->save();
return false; return false;
} }
} }
$this->determineBaseUrl(); $this->determineBaseUrl();
if (!$this->config->set('system', 'url', $this->url, false)) { if (!$this->config->set('system', 'url', $this->url)) {
$this->hostname = $currHostname; $this->hostname = $currHostname;
$this->sslPolicy = $currSSLPolicy; $this->sslPolicy = $currSSLPolicy;
$this->urlPath = $currURLPath; $this->urlPath = $currURLPath;
$this->determineBaseUrl(); $this->determineBaseUrl();
$this->config->set('config', 'hostname', $this->hostname, false); $this->config->set('config', 'hostname', $this->hostname);
$this->config->set('system', 'ssl_policy', $this->sslPolicy, false); $this->config->set('system', 'ssl_policy', $this->sslPolicy);
$this->config->set('system', 'urlpath', $this->urlPath, false); $this->config->set('system', 'urlpath', $this->urlPath);
$this->config->save();
return false; return false;
} }
$this->config->save();
return true; return true;
} }
@ -300,21 +295,17 @@ class BaseURL
$this->sslPolicy = $this->config->get('system', 'ssl_policy'); $this->sslPolicy = $this->config->get('system', 'ssl_policy');
$this->url = $this->config->get('system', 'url'); $this->url = $this->config->get('system', 'url');
$savable = false;
if (empty($this->hostname)) { if (empty($this->hostname)) {
$this->determineHostname(); $this->determineHostname();
if (!empty($this->hostname)) { if (!empty($this->hostname)) {
$this->config->set('config', 'hostname', $this->hostname, false); $this->config->set('config', 'hostname', $this->hostname);
$savable = true;
} }
} }
if (!isset($this->urlPath)) { if (!isset($this->urlPath)) {
$this->determineURLPath(); $this->determineURLPath();
$this->config->set('system', 'urlpath', $this->urlPath, false); $this->config->set('system', 'urlpath', $this->urlPath);
$savable = true;
} }
if (!isset($this->sslPolicy)) { if (!isset($this->sslPolicy)) {
@ -323,22 +314,16 @@ class BaseURL
} else { } else {
$this->sslPolicy = self::DEFAULT_SSL_SCHEME; $this->sslPolicy = self::DEFAULT_SSL_SCHEME;
} }
$this->config->set('system', 'ssl_policy', $this->sslPolicy, false); $this->config->set('system', 'ssl_policy', $this->sslPolicy);
$savable = true;
} }
if (empty($this->url)) { if (empty($this->url)) {
$this->determineBaseUrl(); $this->determineBaseUrl();
if (!empty($this->url)) { if (!empty($this->url)) {
$this->config->set('system', 'url', $this->url, false); $this->config->set('system', 'url', $this->url);
$savable = true;
} }
} }
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', 'ssl_policy')->andReturn($input['sslPolicy']);
$configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']); $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 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'])) { if (!isset($input['urlPath']) && isset($assert['urlPath'])) {
$configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'], false)->once(); $configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'])->once();
$savable = true;
} }
// 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 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'])) { if (!isset($input['sslPolicy']) && isset($assert['sslPolicy'])) {
$configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'], false)->once(); $configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'])->once();
$savable = true;
} }
// 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 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'])) { if (empty($input['hostname']) && !empty($assert['hostname'])) {
$configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'], false)->once(); $configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'])->once();
$savable = true;
} }
// 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 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'])) { if (empty($input['url']) && !empty($assert['url'])) {
$configMock->shouldReceive('set')->with('system', 'url', $assert['url'], false)->once(); $configMock->shouldReceive('set')->with('system', 'url', $assert['url'])->once();
$savable = true;
}
if ($savable) {
$configMock->shouldReceive('save')->once();
} }
$baseUrl = new BaseURL($configMock, $server); $baseUrl = new BaseURL($configMock, $server);
@ -335,20 +325,18 @@ class BaseURLTest extends MockedTest
$baseUrl = new BaseURL($configMock, []); $baseUrl = new BaseURL($configMock, []);
if (isset($save['hostname'])) { 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'])) { 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'])) { 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('set')->with('system', 'url', $url)->andReturn(true)->once();
$configMock->shouldReceive('save')->once();
$baseUrl->save($save['hostname'], $save['sslPolicy'], $save['urlPath']); $baseUrl->save($save['hostname'], $save['sslPolicy'], $save['urlPath']);
@ -375,20 +363,18 @@ class BaseURLTest extends MockedTest
$baseUrl = new BaseURL($configMock, []); $baseUrl = new BaseURL($configMock, []);
if (isset($save['hostname'])) { 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'])) { 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'])) { 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('set')->with('system', 'url', $url)->andReturn(true)->once();
$configMock->shouldReceive('save')->once();
$baseUrl->saveByURL($url); $baseUrl->saveByURL($url);
@ -545,25 +531,22 @@ class BaseURLTest extends MockedTest
switch ($fail) { switch ($fail) {
case 'hostname': 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; break;
case 'sslPolicy': case 'sslPolicy':
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice(); $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(false)->once(); $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(false)->once();
$configMock->shouldReceive('save')->once();
break; break;
case 'urlPath': case 'urlPath':
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice(); $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(true)->twice(); $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any(), false)->andReturn(false)->once(); $configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any())->andReturn(false)->once();
$configMock->shouldReceive('save')->once();
break; break;
case 'url': case 'url':
$configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any(), false)->andReturn(true)->twice(); $configMock->shouldReceive('set')->with('config', 'hostname', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any(), false)->andReturn(true)->twice(); $configMock->shouldReceive('set')->with('system', 'ssl_policy', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any(), false)->andReturn(true)->twice(); $configMock->shouldReceive('set')->with('system', 'urlpath', \Mockery::any())->andReturn(true)->twice();
$configMock->shouldReceive('set')->with('system', 'url', \Mockery::any(), false)->andReturn(false)->once(); $configMock->shouldReceive('set')->with('system', 'url', \Mockery::any())->andReturn(false)->once();
$configMock->shouldReceive('save')->once();
break; break;
} }