archive_cleanup.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // resetting the course id
  7. $cidReset = true;
  8. // including some necessary files
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. ini_set('memory_limit', -1);
  11. ini_set('max_execution_time', 0);
  12. // setting the section (for the tabs)
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. // Access restrictions
  15. api_protect_admin_script(true);
  16. // setting breadcrumbs
  17. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  18. $form = new FormValidator(
  19. 'archive_cleanup_form',
  20. 'post',
  21. '',
  22. '',
  23. [],
  24. FormValidator::LAYOUT_BOX
  25. );
  26. $form->addButtonSend(get_lang('ArchiveDirCleanupProceedButton'));
  27. if ($form->validate()) {
  28. if (function_exists('opcache_reset')) {
  29. opcache_reset();
  30. }
  31. $file = api_get_path(SYS_PUBLIC_PATH).'build/main.js';
  32. if (file_exists($file)) {
  33. unlink($file);
  34. }
  35. $dir = api_get_path(SYS_PUBLIC_PATH).'build';
  36. $files = scandir($dir);
  37. foreach ($files as $file) {
  38. if (preg_match('/main\..*\.js/', $file)) {
  39. unlink($dir.'/'.$file);
  40. }
  41. }
  42. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  43. $htaccess = @file_get_contents($archive_path.'.htaccess');
  44. $result = rmdirr($archive_path, true, true);
  45. if (false === $result) {
  46. Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupFailed'), 'error'));
  47. } else {
  48. Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupSucceeded')));
  49. }
  50. try {
  51. \Chamilo\CoreBundle\Composer\ScriptHandler::dumpCssFiles();
  52. Display::addFlash(Display::return_message(get_lang('WebFolderRefreshSucceeded')));
  53. } catch (Exception $e) {
  54. Display::addFlash(Display::return_message(get_lang('WebFolderRefreshFailed'), 'error'));
  55. error_log($e->getMessage());
  56. }
  57. if (!empty($htaccess)) {
  58. @file_put_contents($archive_path.'/.htaccess', $htaccess);
  59. }
  60. header('Location: '.api_get_self());
  61. exit;
  62. }
  63. Display::display_header(get_lang('ArchiveDirCleanup'));
  64. echo Display::return_message(get_lang('ArchiveDirCleanupDescr'), 'warning');
  65. $form->display();
  66. Display::display_footer();