mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #22 - Self-refresh maintenance page every 5 minutes or the outage duration, whatever is lower.
This commit is contained in:
@@ -42,7 +42,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class maintenance_static_page {
|
||||
/**
|
||||
* Creates a page based on the given outage.
|
||||
*
|
||||
* @param outage|null $outage
|
||||
*
|
||||
* @return maintenance_static_page
|
||||
* @throws coding_exception
|
||||
*/
|
||||
@@ -63,12 +65,18 @@ class maintenance_static_page {
|
||||
$html = $data['contents'];
|
||||
}
|
||||
|
||||
return self::create_from_html($html);
|
||||
$page = self::create_from_html($html);
|
||||
if (!is_null($outage)) {
|
||||
$page->set_max_refresh_time($outage->get_duration_planned());
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a page based on the given HTML.
|
||||
*
|
||||
* @param string|null $html
|
||||
*
|
||||
* @return maintenance_static_page
|
||||
* @throws coding_exception
|
||||
*/
|
||||
@@ -96,7 +104,9 @@ class maintenance_static_page {
|
||||
|
||||
/**
|
||||
* maintenance_static_page constructor.
|
||||
*
|
||||
* @param DOMDocument|null $dom
|
||||
*
|
||||
* @throws coding_exception
|
||||
*/
|
||||
protected function __construct($dom) {
|
||||
@@ -117,4 +127,15 @@ class maintenance_static_page {
|
||||
public function get_io() {
|
||||
return $this->generator->get_io();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum amount of seconds to auto refresh the static page.
|
||||
* @param int $maxsecs
|
||||
*/
|
||||
public function set_max_refresh_time($maxsecs) {
|
||||
$current = $this->generator->get_refresh_time();
|
||||
if ($maxsecs < $current) {
|
||||
$this->generator->set_refresh_time($maxsecs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ class maintenance_static_page_generator {
|
||||
/** @var maintenance_static_page_io */
|
||||
protected $io;
|
||||
|
||||
/** @var int */
|
||||
protected $refreshtime = 300;
|
||||
|
||||
/**
|
||||
* maintenance_static_page_generator constructor.
|
||||
*
|
||||
@@ -74,6 +77,7 @@ class maintenance_static_page_generator {
|
||||
$this->io->create_resources_path();
|
||||
|
||||
$this->remove_script_tags();
|
||||
$this->add_meta_refresh();
|
||||
$this->update_link_stylesheet();
|
||||
$this->update_link_favicon();
|
||||
$this->update_images();
|
||||
@@ -265,4 +269,29 @@ class maintenance_static_page_generator {
|
||||
}
|
||||
return $matches;
|
||||
}
|
||||
|
||||
private function add_meta_refresh() {
|
||||
$meta = $this->dom->createElement('meta');
|
||||
$meta->setAttribute('http-equiv', 'refresh');
|
||||
$meta->setAttribute('content', $this->refreshtime);
|
||||
|
||||
$head = $this->dom->getElementsByTagName('head')[0];
|
||||
if ($head) {
|
||||
$head->appendChild($meta);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_refresh_time() {
|
||||
return $this->refreshtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $refreshtime
|
||||
*/
|
||||
public function set_refresh_time($refreshtime) {
|
||||
$this->refreshtime = $refreshtime;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user