archive_cleanup.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // resetting the course id
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. ini_set('memory_limit', -1);
  10. ini_set('max_execution_time', 0);
  11. // setting the section (for the tabs)
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. // Access restrictions
  14. api_protect_admin_script(true);
  15. // setting breadcrumbs
  16. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  17. $form = new FormValidator(
  18. 'archive_cleanup_form',
  19. 'post',
  20. '',
  21. '',
  22. [],
  23. FormValidator::LAYOUT_BOX
  24. );
  25. $form->addButtonSend(get_lang('Proceed with cleanup'));
  26. if ($form->validate()) {
  27. if (function_exists('opcache_reset')) {
  28. opcache_reset();
  29. }
  30. $file = api_get_path(SYS_PUBLIC_PATH).'build/main.js';
  31. if (file_exists($file)) {
  32. unlink($file);
  33. }
  34. $dir = api_get_path(SYS_PUBLIC_PATH).'build';
  35. $files = scandir($dir);
  36. foreach ($files as $file) {
  37. if (preg_match('/main\..*\.js/', $file)) {
  38. unlink($dir.'/'.$file);
  39. }
  40. }
  41. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  42. $htaccess = @file_get_contents($archive_path.'.htaccess');
  43. $result = rmdirr($archive_path, true, true);
  44. if (false === $result) {
  45. Display::addFlash(Display::return_message(get_lang('Cleanup of cache and temporary filesFailed'), 'error'));
  46. } else {
  47. Display::addFlash(Display::return_message(get_lang('The app/cache/ directory cleanup has been executed successfully.')));
  48. }
  49. try {
  50. \Chamilo\CoreBundle\Composer\ScriptHandler::dumpCssFiles();
  51. Display::addFlash(Display::return_message(get_lang('The styles and assets in the web/ folder have been refreshed.')));
  52. } catch (Exception $e) {
  53. Display::addFlash(Display::return_message(get_lang('The styles and assets in the web/ folder could not be refreshed, probably due to a permissions problem. Make sure the web/ folder is writeable by your web server.'), 'error'));
  54. error_log($e->getMessage());
  55. }
  56. if (!empty($htaccess)) {
  57. @file_put_contents($archive_path.'/.htaccess', $htaccess);
  58. }
  59. header('Location: '.api_get_self());
  60. exit;
  61. }
  62. Display::display_header(get_lang('Cleanup of cache and temporary files'));
  63. echo Display::return_message(get_lang('Cleanup of cache and temporary filesDescr'), 'warning');
  64. $form->display();
  65. Display::display_footer();