Commit cd698c8b authored by Davo Smith's avatar Davo Smith
Browse files

MDL-57638 block_rss_client: warn users about failed RSS feeds

parent 83e52345
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
/** The maximum time in seconds that cron will wait between attempts to retry failing RSS feeds. */ /** The maximum time in seconds that cron will wait between attempts to retry failing RSS feeds. */
const CLIENT_MAX_SKIPTIME = 43200; // 60 * 60 * 12 seconds. const CLIENT_MAX_SKIPTIME = 43200; // 60 * 60 * 12 seconds.
/** @var bool track whether any of the output feeds have recorded failures */
private $hasfailedfeeds = false;
function init() { function init() {
$this->title = get_string('pluginname', 'block_rss_client'); $this->title = get_string('pluginname', 'block_rss_client');
} }
...@@ -59,6 +62,7 @@ ...@@ -59,6 +62,7 @@
* @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed. * @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed.
*/ */
protected function get_footer($feedrecords) { protected function get_footer($feedrecords) {
global $PAGE;
$footer = null; $footer = null;
if ($this->config->block_rss_client_show_channel_link) { if ($this->config->block_rss_client_show_channel_link) {
...@@ -74,6 +78,16 @@ ...@@ -74,6 +78,16 @@
} }
} }
if ($this->hasfailedfeeds) {
if (has_any_capability(['block/rss_client:manageownfeeds', 'block/rss_client:manageanyfeeds'], $this->context)) {
if ($footer === null) {
$footer = new block_rss_client\output\footer();
}
$manageurl = new moodle_url('/blocks/rss_client/managefeeds.php', ['courseid' => $PAGE->course->id]);
$footer->set_failed($manageurl);
}
}
return $footer; return $footer;
} }
...@@ -175,6 +189,7 @@ ...@@ -175,6 +189,7 @@
if ($feedrecord->skipuntil) { if ($feedrecord->skipuntil) {
// Last attempt to gather this feed via cron failed - do not try to fetch it now. // Last attempt to gather this feed via cron failed - do not try to fetch it now.
$this->hasfailedfeeds = true;
return null; return null;
} }
......
...@@ -40,16 +40,23 @@ class footer implements \renderable, \templatable { ...@@ -40,16 +40,23 @@ class footer implements \renderable, \templatable {
/** /**
* The link provided in the RSS channel * The link provided in the RSS channel
* *
* @var \moodle_url * @var \moodle_url|null
*/ */
protected $channelurl; protected $channelurl;
/**
* Link to manage feeds, only provided if a feed has failed.
*
* @var \moodle_url|null
*/
protected $manageurl = null;
/** /**
* Constructor * Constructor
* *
* @param \moodle_url $channelurl The link provided in the RSS channel * @param \moodle_url $channelurl (optional) The link provided in the RSS channel
*/ */
public function __construct(\moodle_url $channelurl) { public function __construct($channelurl = null) {
$this->channelurl = $channelurl; $this->channelurl = $channelurl;
} }
...@@ -65,6 +72,16 @@ class footer implements \renderable, \templatable { ...@@ -65,6 +72,16 @@ class footer implements \renderable, \templatable {
return $this; return $this;
} }
/**
* Record the fact that there is at least one failed feed (and the URL for viewing
* these failed feeds).
*
* @param \moodle_url $manageurl the URL to link to for more information
*/
public function set_failed(\moodle_url $manageurl) {
$this->manageurl = $manageurl;
}
/** /**
* Get the channel url * Get the channel url
* *
...@@ -84,6 +101,10 @@ class footer implements \renderable, \templatable { ...@@ -84,6 +101,10 @@ class footer implements \renderable, \templatable {
public function export_for_template(\renderer_base $output) { public function export_for_template(\renderer_base $output) {
$data = new \stdClass(); $data = new \stdClass();
$data->channellink = clean_param($this->channelurl, PARAM_URL); $data->channellink = clean_param($this->channelurl, PARAM_URL);
if ($this->manageurl) {
$data->hasfailedfeeds = true;
$data->manageurl = clean_param($this->manageurl, PARAM_URL);
}
return $data; return $data;
} }
......
...@@ -44,6 +44,8 @@ $string['editnewsfeeds'] = 'Edit news feeds'; ...@@ -44,6 +44,8 @@ $string['editnewsfeeds'] = 'Edit news feeds';
$string['editrssblock'] = 'Edit RSS headline block'; $string['editrssblock'] = 'Edit RSS headline block';
$string['enableautodiscovery'] = 'Enable auto-discovery of feeds?'; $string['enableautodiscovery'] = 'Enable auto-discovery of feeds?';
$string['enableautodiscovery_help'] = 'If enabled, feeds on web pages are found automatically. For example, if http://docs.moodle.org is entered, then http://docs.moodle.org/en/index.php?title=Special:RecentChanges&feed=rss would be found.'; $string['enableautodiscovery_help'] = 'If enabled, feeds on web pages are found automatically. For example, if http://docs.moodle.org is entered, then http://docs.moodle.org/en/index.php?title=Special:RecentChanges&feed=rss would be found.';
$string['failedfeed'] = 'Feed failed to download - will retry after {$a}';
$string['failedfeeds'] = 'One or more RSS feeds have failed';
$string['feed'] = 'Feed'; $string['feed'] = 'Feed';
$string['feedadded'] = 'News feed added'; $string['feedadded'] = 'News feed added';
$string['feeddeleted'] = 'News feed deleted'; $string['feeddeleted'] = 'News feed deleted';
......
...@@ -114,6 +114,13 @@ foreach($feeds as $feed) { ...@@ -114,6 +114,13 @@ foreach($feeds as $feed) {
$feedinfo = '<div class="title">' . $viewlink . '</div>' . $feedinfo = '<div class="title">' . $viewlink . '</div>' .
'<div class="url">' . html_writer::link($feed->url, $feed->url) .'</div>' . '<div class="url">' . html_writer::link($feed->url, $feed->url) .'</div>' .
'<div class="description">' . $feed->description . '</div>'; '<div class="description">' . $feed->description . '</div>';
if ($feed->skipuntil) {
$skipuntil = userdate($feed->skipuntil, get_string('strftimedatetime', 'langconfig'));
$skipmsg = get_string('failedfeed', 'block_rss_client', $skipuntil);
$notification = new \core\output\notification($skipmsg, 'error');
$notification->set_show_closebutton(false);
$feedinfo .= $OUTPUT->render($notification);
}
$editurl = new moodle_url('/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams); $editurl = new moodle_url('/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams);
$editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit'))); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
......
...@@ -33,4 +33,10 @@ ...@@ -33,4 +33,10 @@
"channellink": "https://www.example.com/feeds/rss" "channellink": "https://www.example.com/feeds/rss"
} }
}} }}
<a href="{{{channellink}}}">{{#str}} clientchannellink, block_rss_client {{/str}}</a> {{#channellink}}
<a href="{{{channellink}}}">{{#str}} clientchannellink, block_rss_client {{/str}}</a>
{{#hasfailedfeeds}}<br>{{/hasfailedfeeds}}
{{/channellink}}
{{#hasfailedfeeds}}
<a href="{{{manageurl}}}">{{#str}} failedfeeds, block_rss_client {{/str}}</a>
{{/hasfailedfeeds}}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment