* @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
$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
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,
--- /dev/null
+<?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
+{
+}
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;
$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;
}
$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;
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) {
* @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);
count($pushCallbacks) . " sites");
$qm = QueueManager::get();
$qm->enqueue($data, 'hubprep');
+ return true;
}
/**
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;
}
}
}
- if (count($batch) >= 0) {
+ if (count($batch) > 0) {
$sub->bulkDistribute($atom, $batch);
}
}
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
{
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;
}
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();
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