Skip to content

Commit b8a8d50

Browse files
committed
send notifications for cron-created imports if plugin setting allows
1 parent 5fd13db commit b8a8d50

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
x.x:
44

5+
2.1.1 (12/16/2015):
6+
- send notifications for cron-created imports if plugin setting allows
7+
58
2.1.0 (12/10/2015):
69
- remove group options if not enabled globally
710
- added plugin setting for optional river entries on import

lib/functions.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,41 @@ function cron_import($period) {
9393
if (!RSSImport::groupGatekeeper($rssimport->getContainerEntity(), $rssimport->import_into, false)) {
9494
continue;
9595
}
96+
97+
// need to log in as the rssimport owner in case notifications are enabled
98+
$logged_in_user = elgg_get_logged_in_user_entity();
99+
100+
// also need to prevent any login/logout forwards that can interrupt us
101+
elgg_register_plugin_hook_handler('forward', 'all', __NAMESPACE__ . '\\prevent_forward');
102+
103+
$owner = $rssimport->getOwnerEntity();
104+
if ($owner) {
105+
login($owner);
106+
}
96107

97108
//get the feed
98109
$feed = $rssimport->getFeed();
99110
$history = array();
100111
$items = $feed->get_items(0, 0);
101112
if (is_array($items)) {
102-
foreach ($items as $item) {
103-
if (!$rssimport->isAlreadyImported($item) && !$rssimport->isBlacklisted($item)) {
104-
$history[] = $rssimport->importItem($item);
105-
}
106-
}
113+
foreach ($items as $item) {
114+
if (!$rssimport->isAlreadyImported($item) && !$rssimport->isBlacklisted($item)) {
115+
$history[] = $rssimport->importItem($item);
116+
}
117+
}
107118
}
108119

109120
$rssimport->addToHistory($history);
121+
122+
if ($owner) {
123+
logout();
124+
}
125+
126+
if ($logged_in_user) {
127+
login($logged_in_user);
128+
}
129+
130+
elgg_unregister_plugin_hook_handler('forward', 'all', __NAMESPACE__ . '\\prevent_forward');
110131
}
111132

112133
elgg_set_ignore_access(false);

lib/hooks.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,17 @@ function prevent_notifications($hook, $type, $return, $params) {
101101
}
102102

103103
return $return;
104+
}
105+
106+
/**
107+
* called on the forward plugin hook, prevents the forward
108+
*
109+
* @param type $hook
110+
* @param type $type
111+
* @param type $return
112+
* @param type $params
113+
* @return boolean
114+
*/
115+
function prevent_forward($hook, $type, $return, $params) {
116+
return false; // no forwarding
104117
}

manifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version="1.0" encoding="UTF-8"?><plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> <name>RSS Import</name> <id>rssimport</id> <author>Matt Beckett (matt@mattbeckett.me)</author> <version>2.1.0</version> <description>Import rss feed items into blogs, bookmarks, and pages</description> <website>http://mattbecket.me</website> <copyright>(C) Athabasca University</copyright> <license>GNU Public License version 2</license> <!-- All plugins must require either elgg_version or elgg_release. --> <requires> <type>elgg_release</type> <version>1.9</version> </requires> <suggests> <type>plugin</type> <name>blog</name> </suggests> <suggests> <type>plugin</type> <name>bookmarks</name> </suggests> <suggests> <type>plugin</type> <name>pages</name> </suggests> <screenshot> <description>Import option available on content creation and personal listings</description> <path>screenshots/rssimport1.jpg</path> </screenshot> <screenshot> <description>Feed creation form</description> <path>screenshots/rssimport2.jpg</path> </screenshot> <screenshot> <description>Content in a feed, ready to be imported</description> <path>screenshots/rssimport3.jpg</path> </screenshot> <screenshot> <description>Content imported into a blog</description> <path>screenshots/rssimport4.jpg</path> </screenshot> <category>rss</category></plugin_manifest>
1+
<?xml version="1.0" encoding="UTF-8"?><plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> <name>RSS Import</name> <id>rssimport</id> <author>Matt Beckett (matt@mattbeckett.me)</author> <version>2.1.1</version> <description>Import rss feed items into blogs, bookmarks, and pages</description> <website>http://mattbecket.me</website> <copyright>(C) Athabasca University</copyright> <license>GNU Public License version 2</license> <!-- All plugins must require either elgg_version or elgg_release. --> <requires> <type>elgg_release</type> <version>1.9</version> </requires> <suggests> <type>plugin</type> <name>blog</name> </suggests> <suggests> <type>plugin</type> <name>bookmarks</name> </suggests> <suggests> <type>plugin</type> <name>pages</name> </suggests> <screenshot> <description>Import option available on content creation and personal listings</description> <path>screenshots/rssimport1.jpg</path> </screenshot> <screenshot> <description>Feed creation form</description> <path>screenshots/rssimport2.jpg</path> </screenshot> <screenshot> <description>Content in a feed, ready to be imported</description> <path>screenshots/rssimport3.jpg</path> </screenshot> <screenshot> <description>Content imported into a blog</description> <path>screenshots/rssimport4.jpg</path> </screenshot> <category>rss</category></plugin_manifest>

0 commit comments

Comments
 (0)