chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | $cidReset = true; |
||
| 6 | |||
| 7 | require_once __DIR__.'/../inc/global.inc.php'; |
||
| 8 | |||
| 9 | ini_set('memory_limit', -1); |
||
| 10 | ini_set('max_execution_time', 0); |
||
| 11 | |||
| 12 | // setting the section (for the tabs) |
||
| 13 | $this_section = SECTION_PLATFORM_ADMIN; |
||
| 14 | |||
| 15 | // Access restrictions |
||
| 16 | api_protect_admin_script(true); |
||
| 17 | |||
| 18 | // setting breadcrumbs |
||
| 19 | $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')]; |
||
| 20 | |||
| 21 | $form = new FormValidator( |
||
| 22 | 'archive_cleanup_form', |
||
| 23 | 'post', |
||
| 24 | '', |
||
| 25 | '', |
||
| 26 | [], |
||
| 27 | FormValidator::LAYOUT_BOX |
||
| 28 | ); |
||
| 29 | $form->addButtonSend(get_lang('ArchiveDirCleanupProceedButton')); |
||
| 30 | |||
| 31 | if ($form->validate()) { |
||
| 32 | if (function_exists('opcache_reset')) { |
||
| 33 | opcache_reset(); |
||
| 34 | } |
||
| 35 | |||
| 36 | $file = api_get_path(SYS_PUBLIC_PATH).'build/main.js'; |
||
| 37 | if (file_exists($file)) { |
||
| 38 | unlink($file); |
||
| 39 | } |
||
| 40 | $dir = api_get_path(SYS_PUBLIC_PATH).'build'; |
||
| 41 | $files = scandir($dir); |
||
| 42 | foreach ($files as $file) { |
||
| 43 | if (preg_match('/main\..*\.js/', $file)) { |
||
| 44 | unlink($dir.'/'.$file); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | $archive_path = api_get_path(SYS_ARCHIVE_PATH); |
||
| 49 | $htaccess = <<<TEXT |
||
| 50 | <IfModule mod_authz_core.c> |
||
| 51 | Require all denied |
||
| 52 | # pChart generated files should be allowed |
||
| 53 | <FilesMatch "^[0-9a-f]+$"> |
||
| 54 | require all granted |
||
| 55 | </FilesMatch> |
||
| 56 | </IfModule> |
||
| 57 | <IfModule !mod_authz_core.c> |
||
| 58 | Order deny,allow |
||
| 59 | Deny from all |
||
| 60 | # pChart generated files should be allowed |
||
| 61 | <FilesMatch "^[0-9a-f]+$"> |
||
| 62 | order allow,deny |
||
| 63 | allow from all |
||
| 64 | </FilesMatch> |
||
| 65 | </IfModule> |
||
| 66 | php_flag engine off |
||
| 67 | TEXT; |
||
| 68 | |||
| 69 | $result = rmdirr($archive_path, true, true); |
||
| 70 | if (false === $result) { |
||
| 71 | Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupFailed'), 'error')); |
||
| 72 | } else { |
||
| 73 | Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupSucceeded'))); |
||
| 74 | } |
||
| 75 | try { |
||
| 76 | \Chamilo\CoreBundle\Composer\ScriptHandler::dumpCssFiles(); |
||
| 77 | Display::addFlash(Display::return_message(get_lang('WebFolderRefreshSucceeded'))); |
||
| 78 | } catch (Exception $e) { |
||
| 79 | Display::addFlash(Display::return_message(get_lang('WebFolderRefreshFailed'), 'error')); |
||
| 80 | error_log($e->getMessage()); |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!empty($htaccess)) { |
||
| 84 | @file_put_contents($archive_path.'/.htaccess', $htaccess); |
||
|
0 ignored issues
–
show
|
|||
| 85 | } |
||
| 86 | |||
| 87 | header('Location: '.api_get_self()); |
||
| 88 | exit; |
||
| 89 | } |
||
| 90 | |||
| 91 | Display::display_header(get_lang('ArchiveDirCleanup')); |
||
| 92 | echo Display::return_message(get_lang('ArchiveDirCleanupDescr'), 'warning'); |
||
| 93 | $form->display(); |
||
| 94 | Display::display_footer(); |
||
| 95 |
If you suppress an error, we recommend checking for the error condition explicitly: