Merge pull request #6935 from nupplaphil/issue/missing_basepath

Fixing basepath issue
This commit is contained in:
Hypolite Petovan 2019-03-26 08:23:50 -04:00 committed by GitHub
commit 753b1e0f25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 18 deletions

View file

@ -6,6 +6,7 @@ use Friendica\App;
use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\Util\BasePath;
use Friendica\Util\Config\ConfigFileLoader;
use Friendica\Util\Config\ConfigFileSaver;
use Friendica\Util\Strings;
@ -235,7 +236,7 @@ class Update
{
$configFileLoader = new ConfigFileLoader($basePath, $mode);
$configCache = new Config\Cache\ConfigCache();
$configFileLoader->setupCache($configCache);
$configFileLoader->setupCache($configCache, true);
$configFileSaver = new ConfigFileSaver($basePath);
$updated = false;
@ -243,10 +244,16 @@ class Update
if (self::updateConfigEntry($configCache, $configFileSaver,'config', 'hostname')) {
$updated = true;
};
if (self::updateConfigEntry($configCache, $configFileSaver,'system', 'basepath')) {
if (self::updateConfigEntry($configCache, $configFileSaver,'system', 'basepath', BasePath::create(dirname(__DIR__) . '/../'))) {
$updated = true;
}
// In case there is nothing to do, skip the update
if (!$updated) {
return true;
}
if (!$configFileSaver->saveToConfigFile()) {
Logger::alert('Config entry update failed - maybe wrong permission?');
return false;
@ -255,7 +262,7 @@ class Update
DBA::delete('config', ['cat' => 'config', 'k' => 'hostname']);
DBA::delete('config', ['cat' => 'system', 'k' => 'basepath']);
return $updated;
return true;
}
/**
@ -265,30 +272,43 @@ class Update
* @param ConfigFileSaver $configFileSaver The config file saver
* @param string $cat The config category
* @param string $key The config key
* @param string $default A default value, if none of the settings are valid
*
* @return boolean True, if a value was updated
*
* @throws \Exception if DBA or Logger doesn't work
*/
private static function updateConfigEntry(IConfigCache $configCache, ConfigFileSaver $configFileSaver, $cat, $key)
private static function updateConfigEntry(IConfigCache $configCache, ConfigFileSaver $configFileSaver, $cat, $key, $default = '')
{
// check if the config file differs from the whole configuration (= The db contains other values)
$fileConfig = $configCache->get($cat, $key);
$savedConfig = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
if (!DBA::isResult($savedConfig)) {
if (DBA::isResult($savedConfig)) {
$savedValue = $savedConfig['v'];
} else {
$savedValue = null;
}
// If the db contains a config value, check it
if (isset($savedValue) && $fileConfig !== $savedValue) {
Logger::info('Difference in config found', ['cat' => $cat, 'key' => $key, 'file' => $fileConfig, 'saved' => $savedValue]);
$configFileSaver->addConfigValue($cat, $key, $savedValue);
return true;
// If both config values are not set, use the default value
} elseif (!isset($fileConfig) && !isset($savedValue)) {
Logger::info('Using default for config', ['cat' => $cat, 'key' => $key, 'value' => $default]);
$configFileSaver->addConfigValue($cat, $key, $default);
return true;
// If either the file config value isn't empty or the db value is the same as the
// file config value, skip it
} else {
Logger::info('No Difference in config found', ['cat' => $cat, 'key' => $key, 'value' => $fileConfig, 'saved' => $savedValue]);
return false;
}
if ($fileConfig !== $savedConfig['v']) {
Logger::info('Difference in config found', ['cat' => $cat, 'key' => $key, 'file' => $fileConfig, 'saved' => $savedConfig['v']]);
$configFileSaver->addConfigValue($cat, $key, $savedConfig['v']);
} else {
Logger::info('No Difference in config found', ['cat' => $cat, 'key' => $key, 'value' => $fileConfig, 'saved' => $savedConfig['v']]);
}
return true;
}
/**