1
0
Fork 0

Fixing basepath issue

This commit is contained in:
Philipp Holzer 2019-03-25 09:39:33 +01:00
parent e4875f2faf
commit d78598b64e
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
4 changed files with 20 additions and 8 deletions

2
config/dbstructure.config.php Normal file → Executable file
View file

@ -34,7 +34,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1306); define('DB_UPDATE_VERSION', 1307);
} }
return [ return [

View file

@ -6,6 +6,7 @@ use Friendica\App;
use Friendica\Core\Config\Cache\IConfigCache; use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\Util\BasePath;
use Friendica\Util\Config\ConfigFileLoader; use Friendica\Util\Config\ConfigFileLoader;
use Friendica\Util\Config\ConfigFileSaver; use Friendica\Util\Config\ConfigFileSaver;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -235,7 +236,7 @@ class Update
{ {
$configFileLoader = new ConfigFileLoader($basePath, $mode); $configFileLoader = new ConfigFileLoader($basePath, $mode);
$configCache = new Config\Cache\ConfigCache(); $configCache = new Config\Cache\ConfigCache();
$configFileLoader->setupCache($configCache); $configFileLoader->setupCache($configCache, true);
$configFileSaver = new ConfigFileSaver($basePath); $configFileSaver = new ConfigFileSaver($basePath);
$updated = false; $updated = false;
@ -243,10 +244,16 @@ class Update
if (self::updateConfigEntry($configCache, $configFileSaver,'config', 'hostname')) { if (self::updateConfigEntry($configCache, $configFileSaver,'config', 'hostname')) {
$updated = true; $updated = true;
}; };
if (self::updateConfigEntry($configCache, $configFileSaver,'system', 'basepath')) {
if (self::updateConfigEntry($configCache, $configFileSaver,'system', 'basepath', BasePath::create(dirname(__DIR__)))) {
$updated = true; $updated = true;
} }
// In case there is nothing to do, skip the update
if (!$updated) {
return true;
}
if (!$configFileSaver->saveToConfigFile()) { if (!$configFileSaver->saveToConfigFile()) {
Logger::alert('Config entry update failed - maybe wrong permission?'); Logger::alert('Config entry update failed - maybe wrong permission?');
return false; return false;
@ -255,7 +262,7 @@ class Update
DBA::delete('config', ['cat' => 'config', 'k' => 'hostname']); DBA::delete('config', ['cat' => 'config', 'k' => 'hostname']);
DBA::delete('config', ['cat' => 'system', 'k' => 'basepath']); DBA::delete('config', ['cat' => 'system', 'k' => 'basepath']);
return $updated; return true;
} }
/** /**
@ -265,12 +272,13 @@ class Update
* @param ConfigFileSaver $configFileSaver The config file saver * @param ConfigFileSaver $configFileSaver The config file saver
* @param string $cat The config category * @param string $cat The config category
* @param string $key The config key * @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 * @return boolean True, if a value was updated
* *
* @throws \Exception if DBA or Logger doesn't work * @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) // check if the config file differs from the whole configuration (= The db contains other values)
$fileConfig = $configCache->get($cat, $key); $fileConfig = $configCache->get($cat, $key);
@ -284,6 +292,9 @@ class Update
if ($fileConfig !== $savedConfig['v']) { if ($fileConfig !== $savedConfig['v']) {
Logger::info('Difference in config found', ['cat' => $cat, 'key' => $key, 'file' => $fileConfig, 'saved' => $savedConfig['v']]); Logger::info('Difference in config found', ['cat' => $cat, 'key' => $key, 'file' => $fileConfig, 'saved' => $savedConfig['v']]);
$configFileSaver->addConfigValue($cat, $key, $savedConfig['v']); $configFileSaver->addConfigValue($cat, $key, $savedConfig['v']);
} elseif (empty($fileConfig) && empty($savedConfig)) {
Logger::info('Using default for config', ['cat' => $cat, 'key' => $key, 'value' => $default]);
$configFileSaver->addConfigValue($cat, $key, $default);
} else { } else {
Logger::info('No Difference in config found', ['cat' => $cat, 'key' => $key, 'value' => $fileConfig, 'saved' => $savedConfig['v']]); Logger::info('No Difference in config found', ['cat' => $cat, 'key' => $key, 'value' => $fileConfig, 'saved' => $savedConfig['v']]);
} }

View file

@ -34,10 +34,11 @@ class ConfigFileLoader extends ConfigFileManager
* expected local.config.php * expected local.config.php
* *
* @param IConfigCache $config The config cache to load to * @param IConfigCache $config The config cache to load to
* @param bool $raw Setup the raw config format
* *
* @throws \Exception * @throws \Exception
*/ */
public function setupCache(IConfigCache $config) public function setupCache(IConfigCache $config, $raw = false)
{ {
$config->load($this->loadCoreConfig('defaults')); $config->load($this->loadCoreConfig('defaults'));
$config->load($this->loadCoreConfig('settings')); $config->load($this->loadCoreConfig('settings'));
@ -48,7 +49,7 @@ class ConfigFileLoader extends ConfigFileManager
$config->load($this->loadCoreConfig('local'), true); $config->load($this->loadCoreConfig('local'), true);
// In case of install mode, add the found basepath (because there isn't a basepath set yet // In case of install mode, add the found basepath (because there isn't a basepath set yet
if ($this->appMode->isInstall()) { if (!$raw && ($this->appMode->isInstall() || empty($config->get('system', 'basepath')))) {
// Setting at least the basepath we know // Setting at least the basepath we know
$config->set('system', 'basepath', $this->baseDir); $config->set('system', 'basepath', $this->baseDir);
} }

View file

@ -352,7 +352,7 @@ function update_1298()
* @see https://github.com/friendica/friendica/pull/6920 * @see https://github.com/friendica/friendica/pull/6920
* @return int Success * @return int Success
*/ */
function update_1305() function update_1307()
{ {
$app = BaseObject::getApp(); $app = BaseObject::getApp();
if (Update::saveConfigToFile($app->getBasePath(), $app->getMode())) { if (Update::saveConfigToFile($app->getBasePath(), $app->getMode())) {