Add script to replace strings in all HTML files of courses - refs BT#15200

pull/2782/head
Yannick Warnier 7 years ago
parent cada956e67
commit aedb4cee13
  1. 33
      tests/scripts/edit_course_html_files.php

@ -0,0 +1,33 @@
<?php
/**
* Goes through all HTML files of the courses directory and replaces
* the first string by the second string.
* This is useful when a portal was installed under one URL and then
* changed URL (or port), to ensure documents are not pointing to the
* previous URL.
* This script is designed to be run from the browser, so maybe you
* need to move it to an executable folder and change the first require.
* @author Yannick Warnier <yannick.warnier@beeznest.com>
*/
require __DIR__.'/../../main/inc/global.inc.php';
// Search string
$search = 'be:8181';
$replace = 'be';
$dir = api_get_path(SYS_COURSE_PATH);
$courses = scandir($dir);
$i = 0;
foreach ($courses as $courseDir) {
if (substr($courseDir, 0, 1) === '.') {
continue;
}
exec('find '.$dir.$courseDir.'/document/ -type f -name "*.html" -exec sed -i '."'s/hn:8181/hn/g' {} +");
//print('find '.$dir.$courseDir.'/document/ -type f -name "*.html" -exec sed -i '."'s/hn:8181/hn/g' {} +<br />");
$i++;
//if ($i == 2) {
// exit;
//}
echo "Replaced all $search in ".$dir.$courseDir."<br />";
}
echo "Done";
Loading…
Cancel
Save