]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorRoland Haeder <roland@mxchange.org>
Sun, 24 Jan 2016 15:13:11 +0000 (16:13 +0100)
committerRoland Haeder <roland@mxchange.org>
Sun, 24 Jan 2016 15:13:11 +0000 (16:13 +0100)
classes/User.php
lib/default.php
lib/emailexception.php [new file with mode: 0644]
lib/httpclient.php
lib/installer.php
lib/mail.php
plugins/OStatus/classes/HubSub.php
plugins/OStatus/classes/Ostatus_profile.php
plugins/OStatus/lib/ostatusqueuehandler.php
plugins/OpportunisticQM/README
plugins/OpportunisticQM/lib/opportunisticqueuemanager.php

index c8b334d489ab76c553f7a27e6601c1cb63c397d3..c232b2b12f307c8c2ee2e0d60cc069a3746612f4 100644 (file)
@@ -207,7 +207,7 @@ class User extends Managed_DataObject
      * @return  User object
      * @throws  Exception on failure
      */
-    static function register(array $fields) {
+    static function register(array $fields, $accept_email_fail=false) {
 
         // MAGICALLY put fields into current scope
 
@@ -371,8 +371,15 @@ class User extends Managed_DataObject
 
             $profile->query('COMMIT');
 
-            if (!empty($email) && !$user->email) {
-                mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
+            if (!empty($email) && !empty($user->email)) {
+                try {
+                    mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
+                } catch (EmailException $e) {
+                    common_log(LOG_ERR, "Could not send user registration email for user id=={$user->id}: {$e->getMessage()}");
+                    if (!$accept_email_fail) {
+                        throw $e;
+                    }
+                }
             }
 
             // Welcome message
index 738f4de1e54a6b21f5e2863ea340ce0b51c5e61b..b19d3e4580d25765f371884caff38e242cb8e476 100644 (file)
@@ -353,6 +353,7 @@ $default =
         array('ssl_cafile' => false, // To enable SSL cert validation, point to a CA bundle (eg '/usr/lib/ssl/certs/ca-certificates.crt') (this activates "ssl_verify_peer")
               'ssl_verify_host' => true,    // HTTPRequest2 makes sure this is set to CURLOPT_SSL_VERIFYHOST==2 if using curl
               'curl' => false, // Use CURL backend for HTTP fetches if available. (If not, PHP's socket streams will be used.)
+              'connect_timeout' => 5,
               'proxy_host' => null,
               'proxy_port' => null,
               'proxy_user' => null,
diff --git a/lib/emailexception.php b/lib/emailexception.php
new file mode 100644 (file)
index 0000000..417bfe1
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Class for an exception when there is something wrong with sending email
+ *
+ * PHP version 5
+ *
+ * LICENCE: 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 <http://www.gnu.org/licenses/>.
+ *
+ * @category  Exception
+ * @package   GNUsocial
+ * @author    Mikael Nordfeldth <mmn@hethane.se>
+ * @copyright 2016 Free Software Foundation, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
+ * @link      http://www.gnu.org/software/social/
+ */
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class EmailException extends Exception
+{
+}
index 3de88e2259ea3507946a7fd37c7445fa8440b34e..c251a03d4551e0ef0a209050b691793a8771ad85 100644 (file)
@@ -121,6 +121,7 @@ class HTTPClient extends HTTP_Request2
 
     function __construct($url=null, $method=self::METHOD_GET, $config=array())
     {
+        $this->config['connect_timeout'] = common_config('http', 'connect_timeout') ?: $this->config['connect_timeout'];
         $this->config['max_redirs'] = 10;
         $this->config['follow_redirects'] = true;
         
index 36f83a3ead5e723342022b2647d5ce8827e80c7e..ff7677dc7d86ba03ef06499d1946c7c5adddd5c0 100644 (file)
@@ -527,7 +527,7 @@ abstract class Installer
             $data['email'] = $this->adminEmail;
         }
         try {
-            $user = User::register($data);
+            $user = User::register($data, true);    // true to skip email sending verification
         } catch (Exception $e) {
             return false;
         }
index 2076476f875c54c6171eb05777a4072024f89a88..da22eb6715a1b2c333ae0cf60f6271f513e373f5 100644 (file)
@@ -52,7 +52,7 @@ function mail_backend()
         $backend = $mail->factory(common_config('mail', 'backend'),
                                  common_config('mail', 'params') ?: array());
         if ($_PEAR->isError($backend)) {
-            throw new ServerException($backend->getMessage());
+            throw new EmailException($backend->getMessage(), $backend->getCode());
         }
     }
     return $backend;
@@ -82,7 +82,7 @@ function mail_send($recipients, $headers, $body)
         assert($backend); // throws an error if it's bad
         $sent = $backend->send($recipients, $headers, $body);
         if ($_PEAR->isError($sent)) {
-            throw new ServerException($sent->getMessage());
+            throw new EmailException($sent->getMessage(), $sent->getCode());
         }
         return true;
     } catch (PEAR_Exception $e) {
index c9d65c56a7a45b09a6beff359f1d2753207eeb23..7ffda88e748c596496177e7f26c684ba03e96e36 100644 (file)
@@ -226,8 +226,12 @@ class HubSub extends Managed_DataObject
      * @param string $atom well-formed Atom feed
      * @param array $pushCallbacks list of callback URLs
      */
-    function bulkDistribute($atom, $pushCallbacks)
+    function bulkDistribute($atom, array $pushCallbacks)
     {
+        if (empty($pushCallbacks)) {
+            common_log(LOG_ERR, 'Callback list empty for bulkDistribute.');
+            return false;
+        }
         $data = array('atom' => $atom,
                       'topic' => $this->topic,
                       'pushCallbacks' => $pushCallbacks);
@@ -235,6 +239,7 @@ class HubSub extends Managed_DataObject
                              count($pushCallbacks) . " sites");
         $qm = QueueManager::get();
         $qm->enqueue($data, 'hubprep');
+        return true;
     }
 
     /**
index 9d41b6727341d41eaa31949f574bd1b2c6cd47c4..07432d78fa1c4d65a3134973bcc948ec7a84e38c 100644 (file)
@@ -377,14 +377,19 @@ class Ostatus_profile extends Managed_DataObject
     public function notifyDeferred($entry, Profile $actor)
     {
         if ($this->salmonuri) {
-            common_debug("OSTATUS: user {$actor->getNickname()} ({$actor->getID()}) wants to ping {$this->localProfile()->getNickname()} on {$this->salmonuri}");
-            $data = array('salmonuri' => $this->salmonuri,
-                          'entry' => $this->notifyPrepXml($entry),
-                          'actor' => $actor->getID(),
-                          'target' => $this->localProfile()->getID());
-
-            $qm = QueueManager::get();
-            return $qm->enqueue($data, 'salmon');
+            try {
+                common_debug("OSTATUS: user {$actor->getNickname()} ({$actor->getID()}) wants to ping {$this->localProfile()->getNickname()} on {$this->salmonuri}");
+                $data = array('salmonuri' => $this->salmonuri,
+                              'entry' => $this->notifyPrepXml($entry),
+                              'actor' => $actor->getID(),
+                              'target' => $this->localProfile()->getID());
+
+                $qm = QueueManager::get();
+                return $qm->enqueue($data, 'salmon');
+            } catch (Exception $e) {
+                common_log(LOG_ERR, 'OSTATUS: Something went wrong when creating a Salmon slap: '._ve($e->getMessage()));
+                return false;
+            }
         }
 
         return false;
index 2914f933552d7196b844635b36aca209a09e0fe6..a4d9e527e2afed5459ba8120277f4e7b0b77298d 100644 (file)
@@ -257,7 +257,7 @@ class OStatusQueueHandler extends QueueHandler
                 }
             }
         }
-        if (count($batch) >= 0) {
+        if (count($batch) > 0) {
             $sub->bulkDistribute($atom, $batch);
         }
     }
index 5d20d68bb874bf6691028c1f85df7c4f4034224e..57baf29937be0ca8d68dc27250587e4707cb31eb 100644 (file)
@@ -3,7 +3,7 @@ time for 1 second since starting the Action processing. If you want to
 change this (such as disabling, 0 seconds, or maybe running bigger 
 chunks, for like 4 seconds) you can do this, where 'n' is time in seconds.
 
-addPlugin('OpportunisticQM', array('secs_per_action', n));
+addPlugin('OpportunisticQM', array('secs_per_action' => n));
 
 Add 'rel_to_pageload'=>false to the array if you want to run the queue 
 for a certain amount of seconds _despite_ maybe already having run that 
index c0339f958b5e4a2bdcf7b751ecd53f66612c2b62..db1404ba6c4168b101d6610fbee479aeffd2604b 100644 (file)
@@ -18,7 +18,7 @@ class OpportunisticQueueManager extends DBQueueManager
 {
     protected $qmkey = false;
     protected $max_execution_time = null;
-    protected $max_execution_margin = null; // margin to execution time, including timeouts etc.
+    protected $max_execution_margin = null; // margin to PHP's max_execution_time
     protected $max_queue_items = null;
 
     protected $started_at = null;
@@ -43,7 +43,7 @@ class OpportunisticQueueManager extends DBQueueManager
         }
 
         if ($this->max_execution_margin === null) {
-            $this->max_execution_margin = 10;    // should be calculated from our default timeouts for http requests etc.
+            $this->max_execution_margin = common_config('http', 'connect_timeout') + 1;   // think PHP's max exec time, minus this value to have time for timeouts etc.
         }
 
         return parent::__construct();
@@ -65,7 +65,7 @@ class OpportunisticQueueManager extends DBQueueManager
             return false;
         }
         // If too much time has passed, stop
-        if ($time_passed >= $this->max_execution_time - $this->max_execution_margin) {
+        if ($time_passed >= $this->max_execution_time || $time_passed > ini_get('max_execution_time') - $this->max_execution_margin) {
             return false;
         }
         // If we have a max-item-limit, check if it has been passed