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