[CORE][QUEUE] Error checking and type declaration on handling notice queue events

Patch submitted by XRevan86
This commit is contained in:
Miguel Dantas 2019-08-07 22:47:17 +01:00 committed by Diogo Cordeiro
parent de91d28f6f
commit aaabf82eff
10 changed files with 66 additions and 27 deletions

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Common superclass for all IM sending queue handlers. * Common superclass for all IM sending queue handlers.
@ -35,8 +35,13 @@ class ImQueueHandler extends QueueHandler
* @param Notice $notice * @param Notice $notice
* @return boolean success * @return boolean success
*/ */
function handle($notice) function handle($notice): bool
{ {
if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not broadcasting");
return true;
}
$this->plugin->broadcastNotice($notice); $this->plugin->broadcastNotice($notice);
if ($notice->isLocal()) { if ($notice->isLocal()) {
$this->plugin->publicNotice($notice); $this->plugin->publicNotice($notice);

View File

@ -17,20 +17,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Queue handler for pushing new notices to ping servers. * Queue handler for pushing new notices to ping servers.
*/ */
class PingQueueHandler extends QueueHandler { class PingQueueHandler extends QueueHandler {
function transport() { function transport()
{
return 'ping'; return 'ping';
} }
function handle($notice) { function handle($notice): bool
{
if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not broadcasting");
return true;
}
require_once INSTALLDIR . '/lib/ping.php'; require_once INSTALLDIR . '/lib/ping.php';
return ping_broadcast_notice($notice); return ping_broadcast_notice($notice);
} }

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Queue handler for letting plugins handle stuff. * Queue handler for letting plugins handle stuff.
@ -40,8 +40,13 @@ class PluginQueueHandler extends QueueHandler
return 'plugin'; return 'plugin';
} }
function handle($notice) function handle($notice): bool
{ {
if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not broadcasting");
return true;
}
try { try {
Event::handle('HandleQueuedNotice', array(&$notice)); Event::handle('HandleQueuedNotice', array(&$notice));
} catch (NoProfileException $unp) { } catch (NoProfileException $unp) {

View File

@ -46,7 +46,7 @@ class QueueHandler
* @param mixed $object * @param mixed $object
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
function handle($object) function handle($object): bool
{ {
return true; return true;
} }

View File

@ -17,9 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Queue handler for pushing new notices to local subscribers using SMS. * Queue handler for pushing new notices to local subscribers using SMS.
@ -31,8 +29,13 @@ class SmsQueueHandler extends QueueHandler
return 'sms'; return 'sms';
} }
function handle($notice) function handle($notice): bool
{ {
if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not broadcasting");
return true;
}
require_once(INSTALLDIR.'/lib/mail.php'); require_once(INSTALLDIR.'/lib/mail.php');
return mail_broadcast_notice_sms($notice); return mail_broadcast_notice_sms($notice);
} }

View File

@ -17,9 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Prepare WebSub and Salmon distributions for an outgoing message. * Prepare WebSub and Salmon distributions for an outgoing message.
@ -46,9 +44,12 @@ class OStatusQueueHandler extends QueueHandler
return 'ostatus'; return 'ostatus';
} }
function handle($notice) function handle($notice): bool
{ {
assert($notice instanceof Notice); if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not distributing");
return true;
}
$this->notice = $notice; $this->notice = $notice;
$this->user = User::getKV('id', $notice->profile_id); $this->user = User::getKV('id', $notice->profile_id);

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Process a feed distribution POST from a WebSub (previously PuSH) hub. * Process a feed distribution POST from a WebSub (previously PuSH) hub.
@ -31,9 +31,12 @@ class PushInQueueHandler extends QueueHandler
return 'pushin'; return 'pushin';
} }
function handle($data) function handle($data): bool
{ {
assert(is_array($data)); if (!is_array($data)) {
common_log(LOG_ERR, "Got bogus data, not processing");
return true;
}
$feedsub_id = $data['feedsub_id']; $feedsub_id = $data['feedsub_id'];
$post = $data['post']; $post = $data['post'];

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } defined('GNUSOCIAL') || die();
class RSSCloudQueueHandler extends QueueHandler class RSSCloudQueueHandler extends QueueHandler
{ {
@ -26,8 +26,13 @@ class RSSCloudQueueHandler extends QueueHandler
return 'rsscloud'; return 'rsscloud';
} }
function handle($notice) function handle($notice): bool
{ {
if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not using");
return true;
}
try { try {
$profile = $notice->getProfile(); $profile = $notice->getProfile();
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
defined('GNUSOCIAL') || die();
/** /**
* Check for subscription mirroring options on each newly seen post! * Check for subscription mirroring options on each newly seen post!
* *
@ -30,8 +32,13 @@ class MirrorQueueHandler extends QueueHandler
return 'mirror'; return 'mirror';
} }
function handle($notice) function handle($notice): bool
{ {
if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not mirroring");
return true;
}
$mirror = new SubMirror(); $mirror = new SubMirror();
$mirror->subscribed = $notice->profile_id; $mirror->subscribed = $notice->profile_id;
if ($mirror->find()) { if ($mirror->find()) {

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } defined('GNUSOCIAL') || die();
require_once dirname(__DIR__) . '/twitter.php'; require_once dirname(__DIR__) . '/twitter.php';
@ -28,8 +28,13 @@ class TwitterQueueHandler extends QueueHandler
return 'twitter'; return 'twitter';
} }
function handle($notice) function handle($notice): bool
{ {
if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not broadcasting");
return true;
}
$ok = broadcast_twitter($notice); $ok = broadcast_twitter($notice);
return $ok || common_config('twitter', 'ignore_errors'); return $ok || common_config('twitter', 'ignore_errors');
} }