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 | </IfModule> |
||
53 | <IfModule !mod_authz_core.c> |
||
54 | Order deny,allow |
||
55 | Deny from all |
||
56 | </IfModule> |
||
57 | # pChart generated files should be allowed |
||
58 | <FilesMatch "^[0-9a-f]+$"> |
||
59 | order allow,deny |
||
60 | allow from all |
||
61 | </FilesMatch> |
||
62 | php_flag engine off |
||
63 | TEXT; |
||
64 | |||
65 | $result = rmdirr($archive_path, true, true); |
||
66 | if (false === $result) { |
||
67 | Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupFailed'), 'error')); |
||
68 | } else { |
||
69 | Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupSucceeded'))); |
||
70 | } |
||
71 | try { |
||
72 | \Chamilo\CoreBundle\Composer\ScriptHandler::dumpCssFiles(); |
||
73 | Display::addFlash(Display::return_message(get_lang('WebFolderRefreshSucceeded'))); |
||
74 | } catch (Exception $e) { |
||
75 | Display::addFlash(Display::return_message(get_lang('WebFolderRefreshFailed'), 'error')); |
||
76 | error_log($e->getMessage()); |
||
77 | } |
||
78 | |||
79 | if (!empty($htaccess)) { |
||
80 | @file_put_contents($archive_path.'/.htaccess', $htaccess); |
||
0 ignored issues
–
show
|
|||
81 | } |
||
82 | |||
83 | header('Location: '.api_get_self()); |
||
84 | exit; |
||
85 | } |
||
86 | |||
87 | Display::display_header(get_lang('ArchiveDirCleanup')); |
||
88 | echo Display::return_message(get_lang('ArchiveDirCleanupDescr'), 'warning'); |
||
89 | $form->display(); |
||
90 | Display::display_footer(); |
||
91 |
If you suppress an error, we recommend checking for the error condition explicitly: