From afb6d86d3c0a2c8797f921712f4f06b14ee694d7 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 22 Mar 2020 20:30:37 +0100 Subject: [PATCH] Fixed installation --- Core/Frameworks/Baikal/Model/Config.php | 26 +++++++++---------- .../Baikal/Model/Config/Database.php | 4 --- .../Baikal/Model/Config/Standard.php | 18 ++----------- .../Frameworks/Baikal/Model/Config/System.php | 15 +---------- .../Controller/Install/Initialize.php | 2 +- 5 files changed, 17 insertions(+), 48 deletions(-) diff --git a/Core/Frameworks/Baikal/Model/Config.php b/Core/Frameworks/Baikal/Model/Config.php index 27dc0be..978ee9a 100644 --- a/Core/Frameworks/Baikal/Model/Config.php +++ b/Core/Frameworks/Baikal/Model/Config.php @@ -41,16 +41,14 @@ abstract class Config extends \Flake\Core\Model\NoDb { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); $aConfig = $config[$sConfigFileSection]; + foreach (array_keys($this->aData) as $sProp) { + if (array_key_exists($sProp, $aConfig)) { + $this->aData[$sProp] = $aConfig[$sProp]; + } + } } catch (\Exception $e) { error_log('Error reading baikal.yaml file : ' . $e->getMessage()); - $aConfig = static::getDefaultConfig(); - } - - - foreach (array_keys($this->aData) as $sProp) { - if (array_key_exists($sProp, $aConfig)) { - $this->aData[$sProp] = $aConfig[$sProp]; - } + // Keep default values in $aData } } @@ -58,7 +56,7 @@ abstract class Config extends \Flake\Core\Model\NoDb { if (file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) { return Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml")[$this->sConfigFileSection]; } else { - return static::getDefaultConfig(); + return $this->aData; } } @@ -87,7 +85,12 @@ abstract class Config extends \Flake\Core\Model\NoDb { } function persist() { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + if (file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + } else { + $config = []; + + } $config[$this->sConfigFileSection] = $this->aData; $yaml = Yaml::dump($config); file_put_contents(PROJECT_PATH_CONFIG . "baikal.yaml", $yaml); @@ -96,7 +99,4 @@ abstract class Config extends \Flake\Core\Model\NoDb { function destroy() { } - - protected static function getDefaultConfig() { - } } diff --git a/Core/Frameworks/Baikal/Model/Config/Database.php b/Core/Frameworks/Baikal/Model/Config/Database.php index 6a01743..0eb0404 100644 --- a/Core/Frameworks/Baikal/Model/Config/Database.php +++ b/Core/Frameworks/Baikal/Model/Config/Database.php @@ -115,8 +115,4 @@ class Database extends \Baikal\Model\Config { function label() { return "Baïkal Database Settings"; } - - protected static function getDefaultConfig() { - throw new \Exception("Should never reach getDefaultConfig() on \Baikal\Model\Config\Database"); - } } diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index a654630..5507870 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -64,13 +64,13 @@ class Standard extends \Baikal\Model\Config { "timezone" => "Europe/Paris", "card_enabled" => true, "cal_enabled" => true, - "invite_from" => "", "dav_auth_type" => "Digest", "admin_passwordhash" => "", "auth_realm" => "BaikalDAV" - ]; +]; function __construct() { + $this->aData["invite_from"] = "noreply@" . $_SERVER['SERVER_NAME']; // Default value parent::__construct("system"); } @@ -165,18 +165,4 @@ class Standard extends \Baikal\Model\Config { return parent::get($sProp); } - - protected static function getDefaultConfig() { - - return [ - "timezone" => "Europe/Paris", - "card_enabled" => true, - "cal_enabled" => true, - "invite_from" => "noreply@" . $_SERVER['SERVER_NAME'], - "dav_auth_type" => "Digest", - "admin_passwordhash" => "", - "auth_realm" => "BaikalDAV", - "configured_version" => BAIKAL_VERSION - ]; - } } diff --git a/Core/Frameworks/Baikal/Model/Config/System.php b/Core/Frameworks/Baikal/Model/Config/System.php index c03a439..980c19f 100644 --- a/Core/Frameworks/Baikal/Model/Config/System.php +++ b/Core/Frameworks/Baikal/Model/Config/System.php @@ -66,7 +66,7 @@ class System extends \Baikal\Model\Config { # Default values protected $aData = [ - "sqlite_file" => "db/db.sqlite", + "sqlite_file" => PROJECT_PATH_SPECIFIC . "db/db.sqlite", "mysql" => false, "mysql_host" => "", "mysql_dbname" => "", @@ -125,17 +125,4 @@ class System extends \Baikal\Model\Config { function label() { return "Baïkal Settings"; } - - protected static function getDefaultConfig() { - - return [ - "sqlite_file" => "db/db.sqlite", - "mysql" => false, - "mysql_host" => "", - "mysql_dbname" => "", - "mysql_username" => "", - "mysql_password" => "", - "encryption_key" => "" - ]; - } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index edb4f85..66d35f9 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -37,7 +37,7 @@ class Initialize extends \Flake\Core\Controller { # Assert that /Specific is writable if (!file_exists(PROJECT_PATH_SPECIFIC) || !is_dir(PROJECT_PATH_SPECIFIC) || !is_writable(PROJECT_PATH_SPECIFIC) || !file_exists(PROJECT_PATH_CONFIG) || !is_dir(PROJECT_PATH_CONFIG) || !is_writable(PROJECT_PATH_CONFIG)) { - $message = "

Error - Insufficient permissions on the Specific/ folder

"; + $message = "

Error - Insufficient permissions on the configuration folders

"; $message .= "

In order to work properly, Baïkal needs to have write permissions in the Specific/ and config/ folder.

"; die($message);