]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #5829 from annando/develop
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 6 Oct 2018 04:06:47 +0000 (00:06 -0400)
committerGitHub <noreply@github.com>
Sat, 6 Oct 2018 04:06:47 +0000 (00:06 -0400)
Cache the AP delivery process

18 files changed:
bin/auth_ejabberd.php
bin/daemon.php
boot.php
index.php
src/App.php
src/App/Mode.php [new file with mode: 0644]
src/Core/Addon.php
src/Core/Config.php
src/Core/Console/ArchiveContact.php
src/Core/Console/Cache.php
src/Core/Console/Config.php
src/Core/Console/GlobalCommunityBlock.php
src/Core/Console/GlobalCommunitySilence.php
src/Core/Console/Maintenance.php
src/Core/Console/NewPassword.php
src/Core/Console/PostUpdate.php
src/Core/PConfig.php
src/Protocol/ActivityPub/Receiver.php

index 7ad28c96f5660c3c8da843c91c97b3b308404426..55917bf6d906e8cb7f55b9d7ca0f65a01bc4d825 100755 (executable)
@@ -54,7 +54,7 @@ require_once "include/dba.php";
 
 $a = new App(dirname(__DIR__));
 
-if ($a->mode === App::MODE_NORMAL) {
+if (App\Mode::isNormal()) {
        $oAuth = new ExAuth();
        $oAuth->readStdin();
 }
\ No newline at end of file
index 159b20e159503f3373b9836157c9b74513f0e34f..e2bad90df59775e74ad4cd96164a84d6df41d13c 100755 (executable)
@@ -34,7 +34,7 @@ require_once "include/dba.php";
 
 $a = new App(dirname(__DIR__));
 
-if ($a->isInstallMode()) {
+if (App\Mode::isInstall()) {
        die("Friendica isn't properly installed yet.\n");
 }
 
index b5c9166982226830dbcab7a52bde85e92cd96af9..b1d5b593fd4619c64472786ca39f5e1fecd8f470 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -673,62 +673,6 @@ function run_update_function($x, $prefix)
        }
 }
 
-/**
- * @brief Synchronise addons:
- *
- * system.addon contains a comma-separated list of names
- * of addons which are used on this system.
- * Go through the database list of already installed addons, and if we have
- * an entry, but it isn't in the config list, call the uninstall procedure
- * and mark it uninstalled in the database (for now we'll remove it).
- * Then go through the config list and if we have a addon that isn't installed,
- * call the install procedure and add it to the database.
- *
- * @param object $a App
- */
-function check_addons(App $a)
-{
-       $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
-       if (DBA::isResult($r)) {
-               $installed = $r;
-       } else {
-               $installed = [];
-       }
-
-       $addons = Config::get('system', 'addon');
-       $addons_arr = [];
-
-       if ($addons) {
-               $addons_arr = explode(',', str_replace(' ', '', $addons));
-       }
-
-       $a->addons = $addons_arr;
-
-       $installed_arr = [];
-
-       if (count($installed)) {
-               foreach ($installed as $i) {
-                       if (!in_array($i['name'], $addons_arr)) {
-                               Addon::uninstall($i['name']);
-                       } else {
-                               $installed_arr[] = $i['name'];
-                       }
-               }
-       }
-
-       if (count($addons_arr)) {
-               foreach ($addons_arr as $p) {
-                       if (!in_array($p, $installed_arr)) {
-                               Addon::install($p);
-                       }
-               }
-       }
-
-       Addon::loadHooks();
-
-       return;
-}
-
 /**
  * @brief Used to end the current process, after saving session state.
  * @deprecated
index bccdebe7b05f65ab9f0999343d7355b4382bfc7a..f34b79867cd42d02f7a0a7deaaa13a6a3af231d5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -36,7 +36,7 @@ $a->backend = false;
 require_once "include/dba.php";
 
 // Missing DB connection: ERROR
-if ($a->mode & App::MODE_LOCALCONFIGPRESENT && !($a->mode & App::MODE_DBAVAILABLE)) {
+if (App\Mode::has(App\Mode::LOCALCONFIGPRESENT) && !App\Mode::has(App\Mode::DBAVAILABLE)) {
        System::httpExit(500, ['title' => 'Error 500 - Internal Server Error', 'description' => 'Apologies but the website is unavailable at the moment.']);
 }
 
@@ -48,7 +48,7 @@ if ($a->isMaxProcessesReached() || $a->isMaxLoadReached()) {
        System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'System is currently overloaded. Please try again later.']);
 }
 
-if (!$a->isInstallMode()) {
+if (!App\Mode::isInstall()) {
        if (Config::get('system', 'force_ssl') && ($a->get_scheme() == "http")
                && (intval(Config::get('system', 'ssl_policy')) == SSL_POLICY_FULL)
                && (substr(System::baseUrl(), 0, 8) == "https://")
@@ -107,7 +107,7 @@ if (!empty($_SESSION['language']) && $_SESSION['language'] !== $lang) {
        L10n::loadTranslationTable($lang);
 }
 
-if (!empty($_GET['zrl']) && $a->mode == App::MODE_NORMAL) {
+if (!empty($_GET['zrl']) && App\Mode::isNormal()) {
        $a->query_string = Profile::stripZrls($a->query_string);
        if (!local_user()) {
                // Only continue when the given profile link seems valid
@@ -130,7 +130,7 @@ if (!empty($_GET['zrl']) && $a->mode == App::MODE_NORMAL) {
        }
 }
 
-if (!empty($_GET['owt']) && $a->mode == App::MODE_NORMAL) {
+if (!empty($_GET['owt']) && App\Mode::isNormal()) {
        $token = $_GET['owt'];
        $a->query_string = Profile::stripQueryParam($a->query_string, 'owt');
        Profile::openWebAuthInit($token);
@@ -165,14 +165,14 @@ $_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []);
 
 // in install mode, any url loads install module
 // but we need "view" module for stylesheet
-if ($a->isInstallMode() && $a->module!="view") {
+if (App\Mode::isInstall() && $a->module != 'view') {
        $a->module = 'install';
-} elseif (!($a->mode & App::MODE_MAINTENANCEDISABLED) && $a->module != "view") {
+} elseif (!App\Mode::has(App\Mode::MAINTENANCEDISABLED) && $a->module != 'view') {
        $a->module = 'maintenance';
 } else {
        check_url($a);
        check_db(false);
-       check_addons($a);
+       Addon::check();
 }
 
 Nav::setSelected('nothing');
@@ -320,7 +320,7 @@ if (file_exists($theme_info_file)) {
 
 /* initialise content region */
 
-if ($a->mode == App::MODE_NORMAL) {
+if (App\Mode::isNormal()) {
        Addon::callHooks('page_content_top', $a->page['content']);
 }
 
index 7622a1a0ce3aacb5e2795fbdd6b9c1e7b572e78e..9a09bcfce0ba8d425599c7ff735d75daa3c788b0 100644 (file)
@@ -31,21 +31,6 @@ require_once 'include/text.php';
  */
 class App
 {
-       const MODE_LOCALCONFIGPRESENT = 1;
-       const MODE_DBAVAILABLE = 2;
-       const MODE_DBCONFIGAVAILABLE = 4;
-       const MODE_MAINTENANCEDISABLED = 8;
-
-       /**
-        * @deprecated since version 2008.08 Use App->isInstallMode() instead to check for install mode.
-        */
-       const MODE_INSTALL = 0;
-
-       /**
-        * @deprecated since version 2008.08 Use the precise mode constant to check for a specific capability instead.
-        */
-       const MODE_NORMAL = App::MODE_LOCALCONFIGPRESENT | App::MODE_DBAVAILABLE | App::MODE_DBCONFIGAVAILABLE | App::MODE_MAINTENANCEDISABLED;
-
        public $module_loaded = false;
        public $module_class = null;
        public $query_string = '';
@@ -67,7 +52,6 @@ class App
        public $argv;
        public $argc;
        public $module;
-       public $mode = App::MODE_INSTALL;
        public $strings;
        public $basepath;
        public $urlpath;
@@ -326,13 +310,13 @@ class App
 
                $this->loadDatabase();
 
-               $this->determineMode();
+               App\Mode::determine($this->basepath);
 
                $this->determineUrlPath();
 
                Config::load();
 
-               if ($this->mode & self::MODE_DBAVAILABLE) {
+               if (App\Mode::has(App\Mode::DBAVAILABLE)) {
                        Core\Addon::loadHooks();
 
                        $this->loadAddonConfig();
@@ -518,45 +502,6 @@ class App
                }
        }
 
-       /**
-        * Sets the App mode
-        *
-        * - App::MODE_INSTALL    : Either the database connection can't be established or the config table doesn't exist
-        * - App::MODE_MAINTENANCE: The maintenance mode has been set
-        * - App::MODE_NORMAL     : Normal run with all features enabled
-        *
-        * @return type
-        */
-       private function determineMode()
-       {
-               $this->mode = 0;
-
-               if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')
-                       && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
-                       return;
-               }
-
-               $this->mode |= App::MODE_LOCALCONFIGPRESENT;
-
-               if (!DBA::connected()) {
-                       return;
-               }
-
-               $this->mode |= App::MODE_DBAVAILABLE;
-
-               if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
-                       return;
-               }
-
-               $this->mode |= App::MODE_DBCONFIGAVAILABLE;
-
-               if (Config::get('system', 'maintenance')) {
-                       return;
-               }
-
-               $this->mode |= App::MODE_MAINTENANCEDISABLED;
-       }
-
        public function loadDatabase()
        {
                if (DBA::connected()) {
@@ -596,16 +541,6 @@ class App
                $this->save_timestamp($stamp1, 'network');
        }
 
-       /**
-        * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
-        *
-        * @return bool
-        */
-       public function isInstallMode()
-       {
-               return !($this->mode & App::MODE_LOCALCONFIGPRESENT) || !($this->mode & App::MODE_DBCONFIGAVAILABLE);
-       }
-
        /**
         * @brief Returns the base filesystem path of the App
         *
@@ -1467,7 +1402,7 @@ class App
         */
        public function getCurrentTheme()
        {
-               if ($this->isInstallMode()) {
+               if (App\Mode::isInstall()) {
                        return '';
                }
 
diff --git a/src/App/Mode.php b/src/App/Mode.php
new file mode 100644 (file)
index 0000000..189573e
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+
+namespace Friendica\App;
+
+use Friendica\Core\Config;
+use Friendica\Database\DBA;
+
+/**
+ * Mode of the current Friendica Node
+ *
+ * @package Friendica\App
+ */
+class Mode
+{
+       const LOCALCONFIGPRESENT = 1;
+       const DBAVAILABLE = 2;
+       const DBCONFIGAVAILABLE = 4;
+       const MAINTENANCEDISABLED = 8;
+
+       /***
+        * @var int the mode of this Application
+        *
+        * Default is 0 (= not set)
+        */
+       private static $mode = 0;
+
+       /**
+        * Sets the App mode
+        *
+        * - App::MODE_INSTALL    : Either the database connection can't be established or the config table doesn't exist
+        * - App::MODE_MAINTENANCE: The maintenance mode has been set
+        * - App::MODE_NORMAL     : Normal run with all features enabled
+        *
+        * @param string $basepath the Basepath of the Application
+        *
+        */
+       public static function determine($basepath)
+       {
+               self::$mode = 0;
+
+               if (!file_exists($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')
+                       && !file_exists($basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
+                       return;
+               }
+
+               self::$mode |= Mode::LOCALCONFIGPRESENT;
+
+               if (!DBA::connected()) {
+                       return;
+               }
+
+               self::$mode |= Mode::DBAVAILABLE;
+
+               if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
+                       return;
+               }
+
+               self::$mode |= Mode::DBCONFIGAVAILABLE;
+
+               if (Config::get('system', 'maintenance')) {
+                       return;
+               }
+
+               self::$mode |= Mode::MAINTENANCEDISABLED;
+       }
+
+       /**
+        * Checks, if the Friendica Node has the given mode
+        *
+        * @param int $mode A mode to test
+        *
+        * @return bool returns true, if the mode is set
+        */
+       public static function has($mode)
+       {
+               return self::$mode & $mode;
+       }
+
+
+       /**
+        * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
+        *
+        * @return bool
+        */
+       public static function isInstall()
+       {
+               return !self::has(Mode::LOCALCONFIGPRESENT) ||
+                       !self::has(MODE::DBCONFIGAVAILABLE);
+       }
+
+       /**
+        * Normal mode is when the local config file is set, the DB schema is installed and the maintenance mode is off.
+        *
+        * @return bool
+        */
+       public static function isNormal()
+       {
+               return self::has(Mode::LOCALCONFIGPRESENT) &&
+                       self::has(Mode::DBAVAILABLE) &&
+                       self::has(Mode::DBCONFIGAVAILABLE) &&
+                       self::has(Mode::MAINTENANCEDISABLED);
+       }
+}
index 4c20c96ad4705546ed0ab6c429c0e64351a74f9b..d5a7a6f1b4d853b7d96f810daa63ff1fb23b655c 100644 (file)
@@ -5,6 +5,7 @@
 namespace Friendica\Core;
 
 use Friendica\App;
+use Friendica\BaseObject;
 use Friendica\Database\DBA;
 
 require_once 'include/dba.php';
@@ -12,8 +13,65 @@ require_once 'include/dba.php';
 /**
  * Some functions to handle addons
  */
-class Addon
+class Addon extends BaseObject
 {
+       /**
+        * @brief Synchronise addons:
+        *
+        * system.addon contains a comma-separated list of names
+        * of addons which are used on this system.
+        * Go through the database list of already installed addons, and if we have
+        * an entry, but it isn't in the config list, call the uninstall procedure
+        * and mark it uninstalled in the database (for now we'll remove it).
+        * Then go through the config list and if we have a addon that isn't installed,
+        * call the install procedure and add it to the database.
+        *
+        */
+       public static function check()
+       {
+               $a = self::getApp();
+
+               $r = DBA::select('addon', [], ['installed' => 1]);
+               if (DBA::isResult($r)) {
+                       $installed = DBA::toArray($r);
+               } else {
+                       $installed = [];
+               }
+
+               $addons = Config::get('system', 'addon');
+               $addons_arr = [];
+
+               if ($addons) {
+                       $addons_arr = explode(',', str_replace(' ', '', $addons));
+               }
+
+               $a->addons = $addons_arr;
+
+               $installed_arr = [];
+
+               if (count($installed)) {
+                       foreach ($installed as $i) {
+                               if (!in_array($i['name'], $addons_arr)) {
+                                       self::uninstall($i['name']);
+                               } else {
+                                       $installed_arr[] = $i['name'];
+                               }
+                       }
+               }
+
+               if (count($addons_arr)) {
+                       foreach ($addons_arr as $p) {
+                               if (!in_array($p, $installed_arr)) {
+                                       self::install($p);
+                               }
+                       }
+               }
+
+               self::loadHooks();
+
+               return;
+       }
+
        /**
         * @brief uninstalls an addon.
         *
@@ -139,7 +197,7 @@ class Addon
         */
        public static function registerHook($hook, $file, $function, $priority = 0)
        {
-               $file = str_replace(get_app()->get_basepath() . DIRECTORY_SEPARATOR, '', $file);
+               $file = str_replace(self::getApp()->get_basepath() . DIRECTORY_SEPARATOR, '', $file);
 
                $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
                $exists = DBA::exists('hook', $condition);
@@ -162,7 +220,7 @@ class Addon
         */
        public static function unregisterHook($hook, $file, $function)
        {
-               $relative_file = str_replace(get_app()->get_basepath() . DIRECTORY_SEPARATOR, '', $file);
+               $relative_file = str_replace(self::getApp()->get_basepath() . DIRECTORY_SEPARATOR, '', $file);
 
                // This here is only needed for fixing a problem that existed on the develop branch
                $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
@@ -178,7 +236,7 @@ class Addon
         */
        public static function loadHooks()
        {
-               $a = get_app();
+               $a = self::getApp();
                $a->hooks = [];
                $r = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
 
@@ -201,7 +259,7 @@ class Addon
         */
        public static function forkHooks($priority, $name, $data = null)
        {
-               $a = get_app();
+               $a = self::getApp();
 
                if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
                        foreach ($a->hooks[$name] as $hook) {
@@ -221,7 +279,7 @@ class Addon
         */
        public static function callHooks($name, &$data = null)
        {
-               $a = get_app();
+               $a = self::getApp();
 
                if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
                        foreach ($a->hooks[$name] as $hook) {
@@ -262,7 +320,7 @@ class Addon
         */
        public static function isApp($name)
        {
-               $a = get_app();
+               $a = self::getApp();
 
                if (is_array($a->hooks) && (array_key_exists('app_menu', $a->hooks))) {
                        foreach ($a->hooks['app_menu'] as $hook) {
@@ -293,7 +351,7 @@ class Addon
         */
        public static function getInfo($addon)
        {
-               $a = get_app();
+               $a = self::getApp();
 
                $info = [
                        'name' => $addon,
index f71522d068b9c63e6dbc4a7cd158fcf4d0a7df29..f2b0d12ab02979d28d04ca0a423600ffb365bfc5 100644 (file)
@@ -31,7 +31,7 @@ class Config extends BaseObject
        public static function init()
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return;
                }
 
@@ -55,7 +55,7 @@ class Config extends BaseObject
        public static function load($family = "config")
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return;
                }
 
@@ -88,7 +88,7 @@ class Config extends BaseObject
        public static function get($family, $key, $default_value = null, $refresh = false)
        {
                // Database isn't ready or populated yet, fallback to file config
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return self::getApp()->getConfigValue($family, $key, $default_value);
                }
 
@@ -116,7 +116,7 @@ class Config extends BaseObject
        public static function set($family, $key, $value)
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return false;
                }
 
@@ -141,7 +141,7 @@ class Config extends BaseObject
        public static function delete($family, $key)
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return false;
                }
 
index acdacbed1de9ac57b6bf2024a08855db51ba97bb..8a6bc1f7bf5312733c6659c861546010d9f5af16 100644 (file)
@@ -56,7 +56,7 @@ HELP;
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
                }
 
-               if ($a->mode === App::MODE_INSTALL) {
+               if (App\Mode::isInstall()) {
                        throw new RuntimeException('Friendica isn\'t properly installed yet.');
                }
 
index d0bc427dee7712b9a2c0e4886421e46593f1d384..2d3508894a4007b91a1de13c44d8a5cb434d18b9 100644 (file)
@@ -65,7 +65,7 @@ HELP;
                        $this->out('Options: ' . var_export($this->options, true));
                }
 
-               if (!($a->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        $this->out('Database isn\'t ready or populated yet, database cache won\'t be available');
                }
 
index db436b8394e1ca2a533ab651997dab06a64d8706..d67f6cbb966dc42416fb1b31581b173ce64e9204 100644 (file)
@@ -84,7 +84,7 @@ HELP;
                        throw new CommandArgsException('Too many arguments');
                }
 
-               if (!($a->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        $this->out('Database isn\'t ready or populated yet, showing file config only');
                }
 
@@ -143,7 +143,7 @@ HELP;
                if (count($this->args) == 0) {
                        Core\Config::load();
 
-                       if (Core\Config::get('system', 'config_adapter') == 'jit' && $a->mode & App::MODE_DBCONFIGAVAILABLE) {
+                       if (Core\Config::get('system', 'config_adapter') == 'jit' && App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                                $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
                        }
 
index f51ed95fe2b4f49d93406317dca55d47c6e7eb3e..dbab4ff02c4dca1beeb9b0cab0690ac63d575d4a 100644 (file)
@@ -56,7 +56,7 @@ HELP;
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
                }
 
-               if ($a->isInstallMode()) {
+               if (App\Mode::isInstall()) {
                        throw new \RuntimeException('Database isn\'t ready or populated yet');
                }
 
index 03101cdf0f3ec4da192a2436f0ec1fa74a747046..0dce00a7b176de83684b6316b7964456e6b7f9c9 100644 (file)
@@ -65,7 +65,7 @@ HELP;
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
                }
 
-               if ($a->isInstallMode()) {
+               if (App\Mode::isInstall()) {
                        throw new RuntimeException('Database isn\'t ready or populated yet');
                }
 
index a3e3b80a7eb33f3feae05807a426291f4ca6f59c..d693cb6e89213641abafcbcc37cfcabecd36510e 100644 (file)
@@ -64,7 +64,7 @@ HELP;
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
                }
 
-               if ($a->isInstallMode()) {
+               if (App\Mode::isInstall()) {
                        throw new \RuntimeException('Database isn\'t ready or populated yet');
                }
 
index 2581d81cd06cd3e2da76fdc3afffa8bbe0e05201..56f3ae7c98eb9757032b95ee88d50043e1759d3f 100644 (file)
@@ -57,7 +57,7 @@ HELP;
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
                }
 
-               if ($a->isInstallMode()) {
+               if (App\Mode::isInstall()) {
                        throw new RuntimeException('Database isn\'t ready or populated yet');
                }
 
index 24ed514b5e46ef3c992ecf548c1388efca2123b8..a77aae39de58a7891eab17de70e31ad01d66e8ff 100644 (file)
@@ -50,7 +50,7 @@ HELP;
                        return 0;
                }
 
-               if ($a->isInstallMode()) {
+               if (App\Mode::isInstall()) {
                        throw new \RuntimeException('Database isn\'t ready or populated yet');
                }
 
index 2b6618930097c1c2ddf6c149b2a8d9286372331d..3c48a568cb08de1d3d45d93fcc8ea123a712acc8 100644 (file)
@@ -30,7 +30,7 @@ class PConfig extends BaseObject
        public static function init($uid)
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return;
                }
 
@@ -55,7 +55,7 @@ class PConfig extends BaseObject
        public static function load($uid, $family)
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return;
                }
 
@@ -84,7 +84,7 @@ class PConfig extends BaseObject
        public static function get($uid, $family, $key, $default_value = null, $refresh = false)
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return;
                }
 
@@ -113,7 +113,7 @@ class PConfig extends BaseObject
        public static function set($uid, $family, $key, $value)
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return false;
                }
 
@@ -139,7 +139,7 @@ class PConfig extends BaseObject
        public static function delete($uid, $family, $key)
        {
                // Database isn't ready or populated yet
-               if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
+               if (!App\Mode::has(App\Mode::DBCONFIGAVAILABLE)) {
                        return false;
                }
 
index 30d710702a4182d7019514922fa711aa7a7ec874..5c644176f02db55d42443c4165836456a4879d48 100644 (file)
@@ -357,11 +357,11 @@ class Receiver
        }
 
        /**
-        * @brief 
+        * @brief Switches existing contacts to ActivityPub
         *
-        * @param $cid
+        * @param integer $cid Contact ID
         * @param integer $uid User ID
-        * @param $url
+        * @param string $url Profile URL
         */
        private static function switchContact($cid, $uid, $url)
        {
@@ -370,7 +370,7 @@ class Receiver
                        return;
                }
 
-               logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' from OStatus to ActivityPub');
+               logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
 
                $photo = $profile['photo'];
                unset($profile['photo']);
@@ -381,7 +381,11 @@ class Receiver
 
                Contact::updateAvatar($photo, $uid, $cid);
 
-               /// @todo Send a new follow request to be sure that the connection still exists
+               // Send a new follow request to be sure that the connection still exists
+               if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
+                       ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
+                       logger('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
+               }
        }
 
        /**