]> git.mxchange.org Git - friendica.git/commitdiff
Move system messages from boot to own class
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 27 Jul 2022 15:54:50 +0000 (11:54 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 27 Jul 2022 15:54:50 +0000 (11:54 -0400)
boot.php
src/App.php
src/DI.php
src/Module/Notifications/Ping.php
src/Navigation/SystemMessages.php [new file with mode: 0644]

index 2756a594782ea0f6e5ca8714443ed32f05ce0454..ea4f28b74174e9611891af4376a04ef0799ebdb4 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -171,18 +171,11 @@ function remote_user()
  * @param string $s - Text of notice
  *
  * @return void
+ * @deprecated since version 2022.09, use \Friendica\Navigation\SystemMessages instead
  */
 function notice(string $s)
 {
-       if (empty($_SESSION)) {
-               return;
-       }
-
-       if (empty($_SESSION['sysmsg'])) {
-               $_SESSION['sysmsg'] = [];
-       }
-
-       $_SESSION['sysmsg'][] = $s;
+       \Friendica\DI::sysmsg()->addNotice($s);
 }
 
 /**
@@ -193,16 +186,9 @@ function notice(string $s)
  * @param string $s - Text of notice
  *
  * @return void
+ * @deprecated since version 2022.09, use \Friendica\Navigation\SystemMessages instead
  */
 function info(string $s)
 {
-       if (empty($_SESSION)) {
-               return;
-       }
-
-       if (empty($_SESSION['sysmsg_info'])) {
-               $_SESSION['sysmsg_info'] = [];
-       }
-
-       $_SESSION['sysmsg_info'][] = $s;
+       \Friendica\DI::sysmsg()->addInfo($s);
 }
index f59b15d1dbcaac331781d5daa33ce65c9750a74b..ceace228f5f8ca993ab19685f28b7225ede4782b 100644 (file)
@@ -648,10 +648,6 @@ class App
                                header('X-Account-Management-Status: none');
                        }
 
-                       $_SESSION['sysmsg']       = Core\Session::get('sysmsg', []);
-                       $_SESSION['sysmsg_info']  = Core\Session::get('sysmsg_info', []);
-                       $_SESSION['last_updated'] = Core\Session::get('last_updated', []);
-
                        /*
                         * check_config() is responsible for running update scripts. These automatically
                         * update the DB schema whenever we push a new one out. It also checks to see if
index e8fa90eb9bb7114718c21094b3a2ea4276b5b2bc..a28eb707a4c33a8de497acc3664cb9f35fa53f4f 100644 (file)
@@ -22,6 +22,7 @@
 namespace Friendica;
 
 use Dice\Dice;
+use Friendica\Navigation\SystemMessages;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -234,6 +235,14 @@ abstract class DI
                return self::$dice->create(Core\System::class);
        }
 
+       /**
+        * @return \Friendica\Navigation\SystemMessages
+        */
+       public static function sysmsg()
+       {
+               return self::$dice->create(SystemMessages::class);
+       }
+
        //
        // "LoggerInterface" instances
        //
index c09d6d0cbed962d3caa158e5093e32c0b73c1643..57da97b4f7a5e0da28123abf493c4f24b5f33de8 100644 (file)
@@ -42,6 +42,7 @@ use Friendica\Navigation\Notifications\Exception\NoMessageException;
 use Friendica\Navigation\Notifications\Factory;
 use Friendica\Navigation\Notifications\Repository;
 use Friendica\Navigation\Notifications\ValueObject;
+use Friendica\Navigation\SystemMessages;
 use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Profiler;
@@ -50,6 +51,8 @@ use Psr\Log\LoggerInterface;
 
 class Ping extends BaseModule
 {
+       /** @var SystemMessages */
+       private $systemMessages;
        /** @var Repository\Notification */
        private $notificationRepo;
        /** @var Introduction */
@@ -57,10 +60,11 @@ class Ping extends BaseModule
        /** @var Factory\FormattedNavNotification */
        private $formattedNavNotification;
 
-       public function __construct(Repository\Notification $notificationRepo, Introduction $introductionRepo, Factory\FormattedNavNotification $formattedNavNotification, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+       public function __construct(SystemMessages $systemMessages, Repository\Notification $notificationRepo, Introduction $introductionRepo, Factory\FormattedNavNotification $formattedNavNotification, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
+               $this->systemMessages           = $systemMessages;
                $this->notificationRepo         = $notificationRepo;
                $this->introductionRepo         = $introductionRepo;
                $this->formattedNavNotification = $formattedNavNotification;
@@ -256,19 +260,6 @@ class Ping extends BaseModule
                        usort($navNotifications, $sort_function);
                }
 
-               $sysmsgs      = [];
-               $sysmsgs_info = [];
-
-               if (!empty($_SESSION['sysmsg'])) {
-                       $sysmsgs = $_SESSION['sysmsg'];
-                       unset($_SESSION['sysmsg']);
-               }
-
-               if (!empty($_SESSION['sysmsg_info'])) {
-                       $sysmsgs_info = $_SESSION['sysmsg_info'];
-                       unset($_SESSION['sysmsg_info']);
-               }
-
                $notification_count = $sysnotify_count + $intro_count + $register_count;
 
                $data             = [];
@@ -289,8 +280,8 @@ class Ping extends BaseModule
                $data['notifications'] = $navNotifications;
 
                $data['sysmsgs'] = [
-                       'notice' => $sysmsgs,
-                       'info'   => $sysmsgs_info
+                       'notice' => $this->systemMessages->flushNotices(),
+                       'info'   => $this->systemMessages->flushInfos(),
                ];
 
                if (isset($_GET['callback'])) {
diff --git a/src/Navigation/SystemMessages.php b/src/Navigation/SystemMessages.php
new file mode 100644 (file)
index 0000000..0b00a5a
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * Friendica is a communications platform for integrated social communications
+ * utilising decentralised communications and linkage to several indie social
+ * projects - as well as popular mainstream providers.
+ *
+ * Our mission is to free our friends and families from the clutches of
+ * data-harvesting corporations, and pave the way to a future where social
+ * communications are free and open and flow between alternate providers as
+ * easily as email does today.
+ */
+
+namespace Friendica\Navigation;
+
+use Friendica\Core\Session\Capability\IHandleSessions;
+
+class SystemMessages
+{
+       /**
+        * @var IHandleSessions
+        */
+       private $session;
+
+       public function __construct(IHandleSessions $session)
+       {
+               $this->session = $session;
+       }
+
+       public function addNotice(string $message)
+       {
+               $sysmsg = $this->getNotices();
+
+               $sysmsg[] = $message;
+
+               $this->session->set('sysmsg', $sysmsg);
+       }
+
+       public function getNotices(): array
+       {
+               return $this->session->get('sysmsg', []);
+       }
+
+       public function flushNotices(): array
+       {
+               $notices = $this->getNotices();
+               $this->session->remove('sysmsg');
+               return $notices;
+       }
+
+       public function addInfo(string $message)
+       {
+               $sysmsg = $this->getNotices();
+
+               $sysmsg[] = $message;
+
+               $this->session->set('sysmsg_info', $sysmsg);
+       }
+
+       public function getInfos(): array
+       {
+               return $this->session->get('sysmsg_info', []);
+       }
+
+       public function flushInfos(): array
+       {
+               $notices = $this->getInfos();
+               $this->session->remove('sysmsg_info');
+               return $notices;
+       }
+}