Skip to content

Commit

Permalink
MDL-46269 tool_httpsreplace: Add progress bar support
Browse files Browse the repository at this point in the history
  • Loading branch information
xow authored and marinaglancy committed Oct 16, 2017
1 parent 2533959 commit e3b853a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
19 changes: 14 additions & 5 deletions admin/tool/httpsreplace/classes/url_finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -82,9 +84,10 @@ private function domain_swap($table, $column, $domain) {
/**
* 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');
Expand Down Expand Up @@ -126,7 +129,13 @@ private function process($replacing = false) {
'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;
}
Expand Down
19 changes: 16 additions & 3 deletions admin/tool/httpsreplace/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,17 @@
$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 {
Expand All @@ -89,10 +96,16 @@

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'));

}
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/httpsreplace/lang/en/tool_httpsreplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,4 +35,5 @@
$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.';

0 comments on commit e3b853a

Please sign in to comment.