wipe-out.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script wipes out your Chamilo installation completely: databases,
  5. * courses directories, configuration files and all other temp directories.
  6. * It only works when launched from the command line and requires Chamilo to
  7. * be installed (otherwise it will not find the references as to the paths and
  8. * databases to delete). It only wipes out stuff and directories it knows are
  9. * created by Chamilo though, so don't worry about your own files if you didn't
  10. * store them in variable Chamilo directories.
  11. * Requires Chamilo LMS 1.9 or greater
  12. * @chamilo.tests.scripts
  13. */
  14. /**
  15. * Security checks
  16. */
  17. if (PHP_SAPI != 'cli') {
  18. echo "For security reasons, this script can only be launched from the command line, sorry.";
  19. exit;
  20. }
  21. if (!isset($argv[1]) || $argv[1] != '--i-am-sure') {
  22. echo " This script will completely erase all Chamilo installations based on this\n",
  23. " directory. There will be no way to recover it. If you really are sure you\n",
  24. " want to do this, please launch this script again using the\n --i-am-sure\n",
  25. " parameter. You've been warned. Don't come complaining!\n";
  26. exit;
  27. }
  28. if (!file_exists(dirname(__FILE__).'/../main/inc/global.inc.php')) {
  29. echo " This script needs to be run from the tests/ directory inside a Chamilo\n", " installation. Please make sure main/inc/global.inc.php exists, then run this\n", " script again.\n";
  30. }
  31. if (!is_file(dirname(__FILE__).'/../main/inc/conf/configuration.php')) {
  32. echo " This script will only work on an already installed version of Chamilo. The \n", "main/inc/conf/configuration.php file could not be found, which is understood\n", "as Chamilo not being installed.\n";
  33. }
  34. /**
  35. * Preparing vars
  36. */
  37. ini_set('track_errors',1);
  38. $_SERVER['SERVER_NAME'] = '';
  39. $_SERVER['HTTP_HOST'] = 'localhost';
  40. $root = dirname(__FILE__).'/../';
  41. require $root.'main/inc/global.inc.php';
  42. $courses = api_get_path(SYS_COURSE_PATH);
  43. $main = api_get_path(SYS_CODE_PATH).'inc/conf/';
  44. $global_db = Database::get_main_database();
  45. $users = api_get_path(SYS_CODE_PATH).'upload/users/';
  46. $arch = api_get_path(SYS_ARCHIVE_PATH);
  47. $webpath = api_get_path(WEB_PATH);
  48. $homepath = api_get_path(SYS_PATH).'home';
  49. // With all this, we will still be missing custom languages and CSS dirs
  50. /**
  51. * Running the cleanup
  52. */
  53. echo "Assuming ".api_get_path(SYS_PATH)." as Chamilo directory\n";
  54. foreach (array($courses, $users, $arch, $homepath, $main) as $dir) {
  55. $list = scandir($dir);
  56. echo "Cleaning $dir\n";
  57. foreach ($list as $entry) {
  58. if (substr($entry,0,1) == '.' or strcmp($entry,'htaccess')===0 or strcmp($entry,'index.html')===0 or substr($entry,-9,9)=='.dist.php') {
  59. //skip files that are part of the Chamilo installation
  60. } else {
  61. if ($dir == $homepath and
  62. ((is_dir($homepath.$entry) and $entry == 'default_platform_document')
  63. or (!is_dir($homepath.$entry) and substr($entry,-5)=='.html') and strlen($entry)<=17)
  64. ) {
  65. //skip
  66. } else {
  67. if (is_dir($dir.$entry)) {
  68. //echo "Removing ".$dir.$entry."\n";
  69. rmdirr($dir.$entry);
  70. } else {
  71. //echo "Removing ".$dir.$entry."\n";
  72. unlink($dir.$entry);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. echo "Dropping database ".$global_db."\n";
  79. $sql = "DROP DATABASE $global_db";
  80. $res = Database::query($sql);
  81. if ($res === false) {
  82. echo "Failed dropping database. Please check manually.\n";
  83. } else {
  84. echo "All clean! Load $webpath to run install again.\n";
  85. }