wipe-out.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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(__DIR__.'/../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. exit;
  31. }
  32. if (!is_file(__DIR__.'/../main/inc/conf/configuration.php')) {
  33. 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";
  34. exit;
  35. }
  36. /**
  37. * Preparing vars
  38. */
  39. ini_set('track_errors',1);
  40. $_SERVER['SERVER_NAME'] = '';
  41. $_SERVER['HTTP_HOST'] = 'localhost';
  42. $root = __DIR__.'/../';
  43. require $root.'main/inc/global.inc.php';
  44. $global_db = Database::get_main_database();
  45. $webpath = api_get_path(WEB_PATH);
  46. $homepath = api_get_path(SYS_APP_PATH).'home';
  47. $clean_dirs = array(
  48. api_get_path(SYS_COURSE_PATH), //courses
  49. api_get_path(SYS_APP_PATH).'config/',
  50. api_get_path(SYS_UPLOAD_PATH).'users/',
  51. api_get_path(SYS_ARCHIVE_PATH)
  52. );
  53. // With all this, we will still be missing custom languages and CSS dirs
  54. /**
  55. * Running the cleanup
  56. */
  57. echo "Assuming ".api_get_path(SYS_PATH)." as Chamilo directory\n";
  58. foreach ($clean_dirs as $dir) {
  59. $list = scandir($dir);
  60. echo "Cleaning $dir\n";
  61. foreach ($list as $entry) {
  62. if (substr($entry,0,1) == '.' or
  63. strcmp($entry,'htaccess')===0 or
  64. strcmp($entry,'index.html')===0 or
  65. substr($entry,-9,9)=='.dist.php'
  66. ) {
  67. //skip files that are part of the Chamilo installation
  68. } else {
  69. if ($dir == $homepath and
  70. ((is_dir($homepath.$entry) and $entry == 'default_platform_document')
  71. or (!is_dir($homepath.$entry) and substr($entry,-5)=='.html') and strlen($entry)<=17)
  72. ) {
  73. //skip
  74. } else {
  75. if (is_dir($dir.$entry)) {
  76. //echo "Removing ".$dir.$entry."\n";
  77. rmdirr($dir.$entry);
  78. } else {
  79. //echo "Removing ".$dir.$entry."\n";
  80. unlink($dir.$entry);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. echo "Dropping database ".$global_db."\n";
  87. $sql = "DROP DATABASE $global_db";
  88. $res = Database::query($sql);
  89. if ($res === false) {
  90. echo "Failed dropping database. Please check manually.\n";
  91. } else {
  92. echo "All clean!\n";
  93. echo "Load $webpath to run install again.\n";
  94. }