]> git.mxchange.org Git - friendica.git/commitdiff
Merge branch 'develop' of https://github.com/friendica/friendica into develop
authorRalf Thees <ralf@herrthees.de>
Sun, 21 Oct 2018 08:27:46 +0000 (10:27 +0200)
committerRalf Thees <ralf@herrthees.de>
Sun, 21 Oct 2018 08:27:46 +0000 (10:27 +0200)
config/config.ini.php
include/enotify.php
index.php
src/Database/DBStructure.php
src/LegacyModule.php [new file with mode: 0644]
src/Protocol/ActivityPub/Transmitter.php
src/Worker/DBClean.php

index ea3df52cbdbdbc11c36d5ab11ea8f23dbb50b026..a324e709ec93c8016b7fbedf97a95eec0b69073c 100644 (file)
@@ -121,9 +121,14 @@ db_loglimit_index_high = 0
 
 ; dbclean_expire_conversation (Integer)
 ; When DBClean is enabled, any entry in the conversation table will be deleted after this many days.
-; These data are normally needed only for debugging purposes and they are safe to delete.
+: This data is used for ActivityPub, so it shouldn't be lower than the average duration of a discussion.
 dbclean_expire_conversation = 90
 
+; dbclean-expire-limit (Integer)
+; This defines the number of items that are to be deleted in a single call.
+; Reduce this value when you are getting memory issues.
+dbclean-expire-limit = 1000
+
 ; diaspora_test (Boolean)
 ; For development only. Disables the message transfer.
 diaspora_test = false
index 6d8cef87947194eea4f23aeb15e68be772cf0d99..5665f485f457f7754fee59570f82a689abac87d1 100644 (file)
@@ -134,6 +134,7 @@ function notification($params)
                $thread = Item::selectFirstThreadForUser($params['uid'] ,['ignored'], ['iid' => $parent_id]);
                if (DBA::isResult($thread) && $thread["ignored"]) {
                        logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
+                       L10n::popLang();
                        return;
                }
 
@@ -628,6 +629,7 @@ function notification($params)
                        '$content_allowed'      => $content_allowed,
                ]);
 
+               L10n::popLang();
                // use the Emailer class to send the message
                return Emailer::send(
                        [
@@ -643,6 +645,7 @@ function notification($params)
                );
        }
 
+       L10n::popLang();
        return false;
 }
 
index 884b067325d6e88744f2f4b1ad1d97b600f0fb40..c834688ffb3f093f68a0b4e9286df9ad68067fca 100644 (file)
--- a/index.php
+++ b/index.php
@@ -260,6 +260,8 @@ if (strlen($a->module)) {
                } else {
                        include_once "addon/{$a->module}/{$a->module}.php";
                        if (function_exists($a->module . '_module')) {
+                               Friendica\LegacyModule::setModuleFile("addon/{$a->module}/{$a->module}.php");
+                               $a->module_class = 'Friendica\\LegacyModule';
                                $a->module_loaded = true;
                        }
                }
@@ -273,10 +275,11 @@ if (strlen($a->module)) {
 
        /**
         * If not, next look for a 'standard' program module in the 'mod' directory
+        * We emulate a Module class through the LegacyModule class
         */
-
        if (! $a->module_loaded && file_exists("mod/{$a->module}.php")) {
-               include_once "mod/{$a->module}.php";
+               Friendica\LegacyModule::setModuleFile("mod/{$a->module}.php");
+               $a->module_class = 'Friendica\\LegacyModule';
                $a->module_loaded = true;
        }
 
@@ -336,16 +339,11 @@ if ($a->module_loaded) {
 
        Addon::callHooks($a->module . '_mod_init', $placeholder);
 
-       if ($a->module_class) {
-               call_user_func([$a->module_class, 'init']);
-       } else if (function_exists($a->module . '_init')) {
-               $func = $a->module . '_init';
-               $func($a);
-       }
+       call_user_func([$a->module_class, 'init']);
 
        // "rawContent" is especially meant for technical endpoints.
        // This endpoint doesn't need any theme initialization or other comparable stuff.
-       if (!$a->error && $a->module_class) {
+       if (!$a->error) {
                call_user_func([$a->module_class, 'rawContent']);
        }
 
@@ -356,34 +354,19 @@ if ($a->module_loaded) {
 
        if (! $a->error && $_SERVER['REQUEST_METHOD'] === 'POST') {
                Addon::callHooks($a->module . '_mod_post', $_POST);
-               if ($a->module_class) {
-                       call_user_func([$a->module_class, 'post']);
-               } else if (function_exists($a->module . '_post')) {
-                       $func = $a->module . '_post';
-                       $func($a);
-               }
+               call_user_func([$a->module_class, 'post']);
        }
 
        if (! $a->error) {
                Addon::callHooks($a->module . '_mod_afterpost', $placeholder);
-               if ($a->module_class) {
-                       call_user_func([$a->module_class, 'afterpost']);
-               } else if (function_exists($a->module . '_afterpost')) {
-                       $func = $a->module . '_afterpost';
-                       $func($a);
-               }
+               call_user_func([$a->module_class, 'afterpost']);
        }
 
        if (! $a->error) {
                $arr = ['content' => $a->page['content']];
                Addon::callHooks($a->module . '_mod_content', $arr);
                $a->page['content'] = $arr['content'];
-               if ($a->module_class) {
-                       $arr = ['content' => call_user_func([$a->module_class, 'content'])];
-               } else if (function_exists($a->module . '_content')) {
-                       $func = $a->module . '_content';
-                       $arr = ['content' => $func($a)];
-               }
+               $arr = ['content' => call_user_func([$a->module_class, 'content'])];
                Addon::callHooks($a->module . '_mod_aftercontent', $arr);
                $a->page['content'] .= $arr['content'];
        }
index f8fc1651c140ece8dffd8385f65097bdf1561638..50566dc877c00bdd35d8f28859107321f44ba3c1 100644 (file)
@@ -77,10 +77,9 @@ class DBStructure
                                The friendica developers released update %s recently,
                                but when I tried to install it, something went terribly wrong.
                                This needs to be fixed soon and I can't do it alone. Please contact a
-                               friendica developer if you can not help me on your own. My database might be invalid."));
-                       $body = L10n::t("The error message is\n[pre]%s[/pre]");
-                       $preamble = sprintf($preamble, $update_id);
-                       $body = sprintf($body, $error_message);
+                               friendica developer if you can not help me on your own. My database might be invalid.",
+                               $update_id));
+                       $body = L10n::t("The error message is\n[pre]%s[/pre]", $error_message);
 
                        notification([
                                'uid'      => $admin['uid'],
@@ -90,6 +89,7 @@ class DBStructure
                                'body'     => $body,
                                'language' => $lang]
                        );
+                       L10n::popLang();
                }
 
                //try the logger
diff --git a/src/LegacyModule.php b/src/LegacyModule.php
new file mode 100644 (file)
index 0000000..737101b
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+
+namespace Friendica;
+
+/**
+ * This mock module enable class encapsulation of legacy global function modules.
+ * After having provided the module file name, all the methods will behave like a normal Module class.
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class LegacyModule extends BaseModule
+{
+       /**
+        * The module name, which is the name of the file (without the .php suffix)
+        * It's used to check for existence of the module functions.
+        *
+        * @var string
+        */
+       private static $moduleName = '';
+
+       /**
+        * The only method that needs to be called, with the module/addon file name.
+        *
+        * @param string $file_path
+        */
+       public static function setModuleFile($file_path)
+       {
+               if (!is_readable($file_path)) {
+                       throw new Exception(Core\L10n::t('Legacy module file not found: %s', $file_path));
+               }
+
+               self::$moduleName = basename($file_path, '.php');
+
+               require_once $file_path;
+       }
+
+       public static function init()
+       {
+               self::runModuleFunction('init');
+       }
+
+       public static function content()
+       {
+               return self::runModuleFunction('content');
+       }
+
+       public static function post()
+       {
+               self::runModuleFunction('post');
+       }
+
+       public static function afterpost()
+       {
+               self::runModuleFunction('afterpost');
+       }
+
+       /**
+        * Runs the module function designated by the provided suffix if it exists, the BaseModule method otherwise
+        *
+        * @param string $function_suffix
+        * @return string
+        */
+       private static function runModuleFunction($function_suffix)
+       {
+               $function_name = static::$moduleName . '_' . $function_suffix;
+
+               if (\function_exists($function_name)) {
+                       return $function_name(self::getApp());
+               } else {
+                       return parent::{$function_suffix}();
+               }
+       }
+}
index 2291b68e9a2c9acc116ce0130813168938b72478..7295408d83c7242822d3b48590202dd2427fa4eb 100644 (file)
@@ -476,7 +476,7 @@ class Transmitter
 
                        foreach ($permissions[$element] as $receiver) {
                                if ($receiver == $item_profile['followers']) {
-                                       $inboxes = self::fetchTargetInboxesforUser($uid, $personal);
+                                       $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
                                } else {
                                        $profile = APContact::getByURL($receiver, false);
                                        if (!empty($profile)) {
index ca0da954c010ff08c51f3e1876ae13383b2ba620..dba9cfd4c61894a86c0fc35861ff986f94a8c67b 100644 (file)
@@ -63,7 +63,7 @@ class DBClean {
                $count = 0;
 
                // We split the deletion in many small tasks
-               $limit = 1000;
+               $limit = Config::get('system', 'dbclean-expire-limit', 1000);
 
                // Get the expire days for step 8 and 9
                $days = Config::get('system', 'dbclean-expire-days', 0);
@@ -275,7 +275,7 @@ class DBClean {
                                                                        OR (`item`.`file` != '') OR (`item`.`event-id` != '')
                                                                        OR (`item`.`attach` != '') OR `item`.`wall` OR `item`.`origin`)
                                                                        AND `item`.`parent` = `thread`.`iid`)
-                                       ORDER BY `thread`.`iid` LIMIT 1000", $days, $last_id);
+                                       ORDER BY `thread`.`iid` LIMIT ?", $days, $last_id, $limit);
                        $count = DBA::numRows($r);
                        if ($count > 0) {
                                logger("found expired threads: ".$count);