From b8a8d50a002a1668d568a156485f008bbd3c9d95 Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Wed, 16 Dec 2015 02:26:10 -0800 Subject: [PATCH] send notifications for cron-created imports if plugin setting allows --- CHANGES.txt | 3 +++ lib/functions.php | 31 ++++++++++++++++++++++++++----- lib/hooks.php | 13 +++++++++++++ manifest.xml | 2 +- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index bcb0d63..ab35070 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,9 @@ x.x: +2.1.1 (12/16/2015): + - send notifications for cron-created imports if plugin setting allows + 2.1.0 (12/10/2015): - remove group options if not enabled globally - added plugin setting for optional river entries on import diff --git a/lib/functions.php b/lib/functions.php index 916c549..4dc5969 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -93,20 +93,41 @@ function cron_import($period) { if (!RSSImport::groupGatekeeper($rssimport->getContainerEntity(), $rssimport->import_into, false)) { continue; } + + // need to log in as the rssimport owner in case notifications are enabled + $logged_in_user = elgg_get_logged_in_user_entity(); + + // also need to prevent any login/logout forwards that can interrupt us + elgg_register_plugin_hook_handler('forward', 'all', __NAMESPACE__ . '\\prevent_forward'); + + $owner = $rssimport->getOwnerEntity(); + if ($owner) { + login($owner); + } //get the feed $feed = $rssimport->getFeed(); $history = array(); $items = $feed->get_items(0, 0); if (is_array($items)) { - foreach ($items as $item) { - if (!$rssimport->isAlreadyImported($item) && !$rssimport->isBlacklisted($item)) { - $history[] = $rssimport->importItem($item); - } - } + foreach ($items as $item) { + if (!$rssimport->isAlreadyImported($item) && !$rssimport->isBlacklisted($item)) { + $history[] = $rssimport->importItem($item); + } + } } $rssimport->addToHistory($history); + + if ($owner) { + logout(); + } + + if ($logged_in_user) { + login($logged_in_user); + } + + elgg_unregister_plugin_hook_handler('forward', 'all', __NAMESPACE__ . '\\prevent_forward'); } elgg_set_ignore_access(false); diff --git a/lib/hooks.php b/lib/hooks.php index 14a3186..5229f1b 100644 --- a/lib/hooks.php +++ b/lib/hooks.php @@ -101,4 +101,17 @@ function prevent_notifications($hook, $type, $return, $params) { } return $return; +} + +/** + * called on the forward plugin hook, prevents the forward + * + * @param type $hook + * @param type $type + * @param type $return + * @param type $params + * @return boolean + */ +function prevent_forward($hook, $type, $return, $params) { + return false; // no forwarding } \ No newline at end of file diff --git a/manifest.xml b/manifest.xml index 049a20f..18ddf97 100644 --- a/manifest.xml +++ b/manifest.xml @@ -1 +1 @@ - RSS Import rssimport Matt Beckett (matt@mattbeckett.me) 2.1.0 Import rss feed items into blogs, bookmarks, and pages http://mattbecket.me (C) Athabasca University GNU Public License version 2 elgg_release 1.9 plugin blog plugin bookmarks plugin pages Import option available on content creation and personal listings screenshots/rssimport1.jpg Feed creation form screenshots/rssimport2.jpg Content in a feed, ready to be imported screenshots/rssimport3.jpg Content imported into a blog screenshots/rssimport4.jpg rss \ No newline at end of file + RSS Import rssimport Matt Beckett (matt@mattbeckett.me) 2.1.1 Import rss feed items into blogs, bookmarks, and pages http://mattbecket.me (C) Athabasca University GNU Public License version 2 elgg_release 1.9 plugin blog plugin bookmarks plugin pages Import option available on content creation and personal listings screenshots/rssimport1.jpg Feed creation form screenshots/rssimport2.jpg Content in a feed, ready to be imported screenshots/rssimport3.jpg Content imported into a blog screenshots/rssimport4.jpg rss \ No newline at end of file