]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Update.php
Merge pull request #7250 from MrPetovan/bug/6410-normalize-message-button
[friendica.git] / src / Core / Update.php
index 0d7b348b42c276f4587fab076c32fa7e34896d8b..a52ef903b2da8867854fc1660317d57817e51cec 100644 (file)
@@ -3,12 +3,8 @@
 namespace Friendica\Core;
 
 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;
 
 class Update
@@ -19,11 +15,13 @@ class Update
        /**
         * @brief Function to check if the Database structure needs an update.
         *
-        * @param string $basePath The base path of this application
-        * @param boolean $via_worker boolean Is the check run via the worker?
+        * @param string   $basePath   The base path of this application
+        * @param boolean  $via_worker Is the check run via the worker?
+        * @param App\Mode $mode       The current app mode
+        *
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function check($basePath, $via_worker)
+       public static function check($basePath, $via_worker, App\Mode $mode)
        {
                if (!DBA::connected()) {
                        return;
@@ -224,93 +222,6 @@ class Update
                }
        }
 
-       /**
-        * Checks the config settings and saves given config values into the config file
-        *
-        * @param string   $basePath The basepath of Friendica
-        * @param App\Mode $mode     The Application mode
-        *
-        * @return bool True, if something has been saved
-        */
-       public static function saveConfigToFile($basePath, App\Mode $mode)
-       {
-               $configFileLoader = new ConfigFileLoader($basePath, $mode);
-               $configCache = new Config\Cache\ConfigCache();
-               $configFileLoader->setupCache($configCache, true);
-               $configFileSaver = new ConfigFileSaver($basePath);
-
-               $updated = false;
-
-               if (self::updateConfigEntry($configCache, $configFileSaver,'config', 'hostname')) {
-                       $updated = true;
-               };
-
-               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;
-               }
-
-               DBA::delete('config', ['cat' => 'config', 'k' => 'hostname']);
-               DBA::delete('config', ['cat' => 'system', 'k' => 'basepath']);
-
-               return true;
-       }
-
-       /**
-        * Adds a value to the ConfigFileSave in case it isn't already updated
-        *
-        * @param IConfigCache    $configCache     The cached config file
-        * @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, $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)) {
-                       $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;
-               }
-       }
-
        /**
         * send the email and do what is needed to do on update fails
         *
@@ -355,6 +266,7 @@ class Update
                                        'uid'      => $admin['uid'],
                                        'type'     => SYSTEM_EMAIL,
                                        'to_email' => $admin['email'],
+                                       'subject'  => l10n::t('[Friendica Notify] Database update'),
                                        'preamble' => $preamble,
                                        'body'     => $body,
                                        'language' => $lang]
@@ -393,6 +305,7 @@ class Update
                                                'uid' => $admin['uid'],
                                                'type' => SYSTEM_EMAIL,
                                                'to_email' => $admin['email'],
+                                               'subject'  => l10n::t('[Friendica Notify] Database update'),
                                                'preamble' => $preamble,
                                                'body' => $preamble,
                                                'language' => $lang]