chamilo / chash

Chamilo Shell
GNU General Public License v3.0
15 stars 10 forks source link

Add command to transform courses/*/index.php in 1.9.* #33

Open ywarnier opened 10 years ago

ywarnier commented 10 years ago

When copying a portal (to do a test site, for example), the paths in courses/*/index.php are wrong (they stay the same as before, although the path has changed).

Add a command files:update_course_index with 1 single param: the new path (up to the "main/" directory. For example, if you want to change the path from /var/www/virtual2.biz.be/www/main/course_home.php to /var/www/virtual4.biz.be/www/main/course_home.php, we should just enter the parameter: /var/www/virtual4.biz.be/www because the rest is obvious.

A command line to do it: find /var/www/virtual2.biz.be/www/courses/*/index.php -type f -exec sed -i 's/virtual2.biz.be/virtual4.biz.be/g' {} \;

A PHP script to do the same: <?php $dir = dirname(FILE); $list = scandir($dir); foreach ($list as $entry) { if (substr($entry,0,1)=='.') { continue; } if (!is_dir($dir.'/'.$entry)) { continue; } if (!is_file($dir.'/'.$entry.'/index.php')) { continue; } $file = file_get_contents($dir.'/'.$entry.'/index.php'); $file = preg_replace('/virtual2.biz.be/','virtual4.biz.be',$file); file_put_contents($dir.'/'.$entry.'/index.php',$file); //die($entry); }

The rest if just chash-ing it in a command.