mirror of
https://github.com/moodle/moodle.git
synced 2025-04-08 01:43:32 +02:00
MDL-46269 tool_httpsreplace: Add progress bar support
This commit is contained in:
parent
2533959982
commit
e3b853a79f
@ -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;
|
||||
}
|
||||
|
@ -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 '<p>'.get_string('domainexplain', 'tool_httpsreplace').'</p>';
|
||||
echo '<p>'.page_doc_link(get_string('doclink', 'tool_httpsreplace')).'</p>';
|
||||
|
||||
$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 '<p>'.get_string('oktoprocede', 'tool_httpsreplace').'</p>';
|
||||
} else {
|
||||
@ -89,10 +96,16 @@ if (!$data = $form->get_data()) {
|
||||
|
||||
echo '<p>'.get_string('replacing', 'tool_httpsreplace').'</p>';
|
||||
|
||||
$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'));
|
||||
|
||||
}
|
||||
|
@ -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.';
|
||||
|
Loading…
x
Reference in New Issue
Block a user