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 <valara2@mfdlabs.com>
This commit is contained in:
Nikita Petko 2021-12-11 16:43:49 +00:00 committed by Github Enterprise
parent c040db0c1f
commit 678a5e6e8a
2 changed files with 30 additions and 2 deletions

View File

@ -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";

View File

@ -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.
*