From 678a5e6e8a2f6910fc4ff4cd4a5c4c574d11f7af Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Sat, 11 Dec 2021 16:43:49 +0000 Subject: [PATCH] Update ClientSettings.php and WebsiteSettings.php ~ Add extra checks to Alphaland\Client\ClientSettingsApplications::FetchCombinedApplicationDependencies() to: 1. Determine if the application dependency actually exists 2. Determine if the application dependency has a dependency to it's super dependant ~ Make the Alphaland\Client\ClientSettingsKind an abstract class ~ Add Alphaland\Web\WebsiteSettings::GetOrCreateSetting() to website settings in case we want to write a setting if it truly doesn't exist Co-Authored-by: Jacob Valara --- .../Dependencies/Client/ClientSettings.php | 12 ++++++++++- globals/Dependencies/Web/WebsiteSettings.php | 20 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/globals/Dependencies/Client/ClientSettings.php b/globals/Dependencies/Client/ClientSettings.php index 6ce51d1..6dda81f 100644 --- a/globals/Dependencies/Client/ClientSettings.php +++ b/globals/Dependencies/Client/ClientSettings.php @@ -409,6 +409,16 @@ namespace Alphaland\Client { $combinedDependencies = self::GetApplicationSettings($applicationName); foreach ($currentDependencies as $dependency) { + // skip it if it doesn't exist just to be safe + if (!self::ApplicationExists($dependency)) { + continue; + } + + // Check if the dependency has a dep on us already + if (self::ApplicationHasDependency($dependency, $applicationName)) { + continue; + } + if ($recursive && self::ApplicationHasAnyDependencies($dependency)) { $combinedDependencies = array_merge($combinedDependencies, self::FetchCombinedApplicationDependencies($dependency, $recursive)); } else { @@ -464,7 +474,7 @@ namespace Alphaland\Client { /** * The client settings kind. */ - class ClientSettingsKind + abstract class ClientSettingsKind { public const Unscoped = "Unscoped"; public const FastLog = "FastLog"; diff --git a/globals/Dependencies/Web/WebsiteSettings.php b/globals/Dependencies/Web/WebsiteSettings.php index 4d4b359..293c723 100644 --- a/globals/Dependencies/Web/WebsiteSettings.php +++ b/globals/Dependencies/Web/WebsiteSettings.php @@ -15,7 +15,7 @@ namespace Alphaland\Web { use PDO; - class WebsiteSettings + /* public static */ class WebsiteSettings { // default return if no settings are found // because there may be a NULL value in the database @@ -99,6 +99,24 @@ namespace Alphaland\Web { return self::ConvertStringToValue($result['value'], $result['type']); } + /** + * Gets or sets the value of a website setting. + * + * @param string $name The name of the setting. + * @param mixed $value The value of the setting. + * @param string $type The type of the setting. + * + * @return mixed The value of the setting. + */ + public static function GetOrCreateSetting(string $name, $value = null, string $type = null) + { + if (!self::SettingExists($name)) { + self::UpdateSetting($name, $value, $type); + } + + return self::GetSetting($name); + } + /** * Sets a website setting. *