diff --git a/admin/tool/httpsreplace/classes/url_finder.php b/admin/tool/httpsreplace/classes/url_finder.php index b5cb82018b6..619e46898bf 100644 --- a/admin/tool/httpsreplace/classes/url_finder.php +++ b/admin/tool/httpsreplace/classes/url_finder.php @@ -39,19 +39,21 @@ class url_finder { /** * Returns a hash of what hosts are referred to over http and would need to be changed. * + * @param progress_bar $progress Progress bar keeping track of this process. * @return array Hash of domains with number of references as the value. */ - public function http_link_stats() { - return $this->process(false); + public function http_link_stats($progress = null) { + return $this->process(false, $progress); } /** * Changes all resources referred to over http to https. * + * @param progress_bar $progress Progress bar keeping track of this process. * @return bool True upon success */ - public function upgrade_http_links() { - return $this->process(true); + public function upgrade_http_links($progress = null) { + return $this->process(true, $progress); } /** @@ -82,9 +84,10 @@ class url_finder { /** * Originally forked from core function db_search(). * @param bool $replacing Whether or not to replace the found urls. + * @param progress_bar $progress Progress bar keeping track of this process. * @return bool|array If $replacing, return true on success. If not, return hash of http urls to number of times used. */ - private function process($replacing = false) { + private function process($replacing = false, $progress = null) { global $DB, $CFG; require_once($CFG->libdir.'/filelib.php'); @@ -126,7 +129,13 @@ class url_finder { 'varchar', ); + $numberoftables = count($tables); + $tablenumber = 0; foreach ($tables as $table) { + if ($progress) { + $progress->update($tablenumber, $numberoftables, get_string('searching', 'tool_httpsreplace', $table)); + $tablenumber++; + } if (in_array($table, $skiptables)) { continue; } diff --git a/admin/tool/httpsreplace/index.php b/admin/tool/httpsreplace/index.php index 953de4661c7..4fedae1e36a 100644 --- a/admin/tool/httpsreplace/index.php +++ b/admin/tool/httpsreplace/index.php @@ -60,10 +60,17 @@ $form = new \tool_httpsreplace\form(); $finder = new \tool_httpsreplace\url_finder(); if (!$data = $form->get_data()) { - $results = $finder->http_link_stats(); - echo '

'.get_string('domainexplain', 'tool_httpsreplace').'

'; echo '

'.page_doc_link(get_string('doclink', 'tool_httpsreplace')).'

'; + + $PAGE->set_cacheable(false); + $progressbar = new progress_bar(); + echo $progressbar->create(); + + $results = $finder->http_link_stats($progressbar); + + $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace')); + if (empty($results)) { echo '

'.get_string('oktoprocede', 'tool_httpsreplace').'

'; } else { @@ -89,10 +96,16 @@ if (!$data = $form->get_data()) { echo '

'.get_string('replacing', 'tool_httpsreplace').'

'; + $PAGE->set_cacheable(false); + $progressbar = new progress_bar(); + echo $progressbar->create(); + echo $OUTPUT->box_start(); - $finder->upgrade_http_links(); + $finder->upgrade_http_links($progressbar); echo $OUTPUT->box_end(); + $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace')); + echo $OUTPUT->continue_button(new moodle_url('/admin/index.php')); } diff --git a/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php b/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php index 07f917a1a79..b24d59a5df7 100644 --- a/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php +++ b/admin/tool/httpsreplace/lang/en/tool_httpsreplace.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['complete'] = 'Completed.'; $string['count'] = 'Number of embeded content items'; $string['disclaimer'] = 'I understand the risks of this operation'; $string['doclink'] = 'Read more documentation on the wiki'; @@ -34,4 +35,5 @@ $string['oktoprocede'] = 'The scan finds no issues with your content. You can pr $string['pageheader'] = 'Upgrade externally hosted content urls to https'; $string['pluginname'] = 'HTTPS conversion tool'; $string['replacing'] = 'Replacing http content with https...'; +$string['searching'] = 'Searching {$a}'; $string['takeabackupwarning'] = 'Once this tool run, changes made can\'t be reverted. A complete backup should be made before running this script! There is a low risk that the wrong content will be replaced, introducing problems.';