diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index e41e68c6c5f..47e9e7831c5 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -33,6 +33,9 @@ /** 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. + /** @var bool track whether any of the output feeds have recorded failures */ + private $hasfailedfeeds = false; + function init() { $this->title = get_string('pluginname', 'block_rss_client'); } @@ -59,6 +62,7 @@ * @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed. */ protected function get_footer($feedrecords) { + global $PAGE; $footer = null; if ($this->config->block_rss_client_show_channel_link) { @@ -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; } @@ -173,6 +187,12 @@ global $CFG; require_once($CFG->libdir.'/simplepie/moodle_simplepie.php'); + if ($feedrecord->skipuntil) { + // Last attempt to gather this feed via cron failed - do not try to fetch it now. + $this->hasfailedfeeds = true; + return null; + } + $simplepiefeed = new moodle_simplepie($feedrecord->url); if(isset($CFG->block_rss_client_timeout)){ diff --git a/blocks/rss_client/classes/output/footer.php b/blocks/rss_client/classes/output/footer.php index 3da20398b59..c864df3d686 100644 --- a/blocks/rss_client/classes/output/footer.php +++ b/blocks/rss_client/classes/output/footer.php @@ -40,16 +40,23 @@ class footer implements \renderable, \templatable { /** * The link provided in the RSS channel * - * @var \moodle_url + * @var \moodle_url|null */ protected $channelurl; + /** + * Link to manage feeds, only provided if a feed has failed. + * + * @var \moodle_url|null + */ + protected $manageurl = null; + /** * 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; } @@ -65,6 +72,16 @@ class footer implements \renderable, \templatable { 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 * @@ -84,6 +101,10 @@ class footer implements \renderable, \templatable { public function export_for_template(\renderer_base $output) { $data = new \stdClass(); $data->channellink = clean_param($this->channelurl, PARAM_URL); + if ($this->manageurl) { + $data->hasfailedfeeds = true; + $data->manageurl = clean_param($this->manageurl, PARAM_URL); + } return $data; } diff --git a/blocks/rss_client/lang/en/block_rss_client.php b/blocks/rss_client/lang/en/block_rss_client.php index 3fbbdc794c6..e606979018a 100644 --- a/blocks/rss_client/lang/en/block_rss_client.php +++ b/blocks/rss_client/lang/en/block_rss_client.php @@ -44,6 +44,8 @@ $string['editnewsfeeds'] = 'Edit news feeds'; $string['editrssblock'] = 'Edit RSS headline block'; $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['failedfeed'] = 'Feed failed to download - will retry after {$a}'; +$string['failedfeeds'] = 'One or more RSS feeds have failed'; $string['feed'] = 'Feed'; $string['feedadded'] = 'News feed added'; $string['feeddeleted'] = 'News feed deleted'; diff --git a/blocks/rss_client/managefeeds.php b/blocks/rss_client/managefeeds.php index 475337ca349..85cf983a8e4 100644 --- a/blocks/rss_client/managefeeds.php +++ b/blocks/rss_client/managefeeds.php @@ -114,6 +114,13 @@ foreach($feeds as $feed) { $feedinfo = '
' . $viewlink . '
' . '
' . html_writer::link($feed->url, $feed->url) .'
' . '
' . $feed->description . '
'; + 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); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit'))); diff --git a/blocks/rss_client/templates/footer.mustache b/blocks/rss_client/templates/footer.mustache index b1aa3733edf..dd5d0fe2b39 100644 --- a/blocks/rss_client/templates/footer.mustache +++ b/blocks/rss_client/templates/footer.mustache @@ -33,4 +33,10 @@ "channellink": "https://www.example.com/feeds/rss" } }} -{{#str}} clientchannellink, block_rss_client {{/str}} +{{#channellink}} + {{#str}} clientchannellink, block_rss_client {{/str}} + {{#hasfailedfeeds}}
{{/hasfailedfeeds}} +{{/channellink}} +{{#hasfailedfeeds}} + {{#str}} failedfeeds, block_rss_client {{/str}} +{{/hasfailedfeeds}} \ No newline at end of file