wipe-out.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. exit;
  31. }
  32. if (!is_file(dirname(__FILE__).'/../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 = dirname(__FILE__).'/../';
  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_PATH).'home';
  47. $clean_dirs = array(
  48. api_get_path(SYS_COURSE_PATH), //courses
  49. api_get_path(SYS_CODE_PATH).'inc/conf/',
  50. api_get_path(SYS_CODE_PATH).'upload/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 strcmp($entry,'htaccess')===0 or strcmp($entry,'index.html')===0 or substr($entry,-9,9)=='.dist.php') {
  63. //skip files that are part of the Chamilo installation
  64. } else {
  65. if ($dir == $homepath and
  66. ((is_dir($homepath.$entry) and $entry == 'default_platform_document')
  67. or (!is_dir($homepath.$entry) and substr($entry,-5)=='.html') and strlen($entry)<=17)
  68. ) {
  69. //skip
  70. } else {
  71. if (is_dir($dir.$entry)) {
  72. //echo "Removing ".$dir.$entry."\n";
  73. api_rmdirr($dir.$entry);
  74. } else {
  75. //echo "Removing ".$dir.$entry."\n";
  76. unlink($dir.$entry);
  77. }
  78. }
  79. }
  80. }
  81. }
  82. echo "Dropping database ".$global_db."\n";
  83. $sql = "DROP DATABASE $global_db";
  84. $res = Database::query($sql);
  85. if ($res === false) {
  86. echo "Failed dropping database. Please check manually.\n";
  87. } else {
  88. echo "All clean!\n";
  89. echo "Load $webpath to run install again.\n";
  90. }