dolibarr 21.0.3
purge.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25if (! defined('CSRFCHECK_WITH_TOKEN')) {
26 define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
27}
28
29// Load Dolibarr environment
30require '../../main.inc.php';
31include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32
43$langs->load("admin");
44
45$action = GETPOST('action', 'aZ09');
46$confirm = GETPOST('confirm', 'alpha');
47$choice = GETPOST('choice', 'aZ09');
48$nbsecondsold = GETPOSTINT('nbsecondsold');
49
50// Define filelog to discard it from purge
51$filelog = '';
52if (isModEnabled('syslog')) {
53 $filelog = getDolGlobalString('SYSLOG_FILE');
54 $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
55}
56
57// Security
58if (!$user->admin) {
60}
61
62
63/*
64 * Actions
65 */
66
67if ($action == 'purge' && !preg_match('/^confirm/i', $choice) && ($choice != 'allfiles' || $confirm == 'yes')) {
68 // Increase limit of time. Works only if we are not in safe mode
69 $ExecTimeLimit = getDolGlobalInt('MAIN_ADMIN_TOOLS_PURGE_EXEC_TIME_LIMIT', 600);
70 if (!empty($ExecTimeLimit)) {
71 $err = error_reporting();
72 error_reporting(0); // Disable all errors
73 //error_reporting(E_ALL);
74 @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
75 error_reporting($err);
76 }
77
78 require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
79 $utils = new Utils($db);
80
81 $result = $utils->purgeFiles($choice, $nbsecondsold);
82
83 $mesg = $utils->output;
84 setEventMessages($mesg, null, 'mesgs');
85}
86
87
88/*
89 * View
90 */
91
92llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-tools_purge');
93
94$form = new Form($db);
95
96print load_fiche_titre($langs->trans("Purge"), '', 'title_setup');
97
98print '<span class="opacitymedium">'.$langs->trans("PurgeAreaDesc", $dolibarr_main_data_root).'</span><br>';
99print '<br>';
100
101
102print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
103print '<input type="hidden" name="token" value="'.newToken().'" />';
104print '<input type="hidden" name="action" value="purge" />';
105
106print '<div class="divsection wordbreak">';
107print '<table class="border centpercent">';
108
109print '<tr class="border"><td style="padding: 4px">';
110
111if (isModEnabled('syslog')) {
112 print '<input type="radio" name="choice" id="choicelogfile" value="logfile"';
113 print ($choice && $choice == 'logfile') ? ' checked' : '';
114 $filelogparam = $filelog;
115 if ($user->admin && preg_match('/^dolibarr.*\.log$/', basename($filelog))) {
116 $filelogparam = '<a class="wordbreak" href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file=';
117 $filelogparam .= basename($filelog);
118 $filelogparam .= '">'.$filelog.'</a>';
119 }
120 $desc = $langs->trans("PurgeDeleteLogFile", '{filelogparam}');
121 $desc = str_replace('{filelogparam}', $filelogparam, $desc);
122 print '> <label for="choicelogfile">'.$desc.'</label>';
123 print '<br><br>';
124}
125
126print '<input type="radio" name="choice" id="choicetempfiles" value="tempfiles"';
127print (!$choice || $choice == 'tempfiles' || $choice == 'allfiles') ? ' checked' : '';
128print '> <label for="choicetempfiles">'.$langs->trans("PurgeDeleteTemporaryFilesShort").'</label><br><br>';
129
130print '<input type="radio" name="choice" id="choiceallfiles" value="confirm_allfiles"';
131print ($choice && $choice == 'confirm_allfiles') ? ' checked' : '';
132print '> <label for="choiceallfiles">'.$langs->trans("PurgeDeleteAllFilesInDocumentsDir", $dolibarr_main_data_root).'</label>';
133print '<br>';
134if (getDolGlobalInt('MAIN_PURGE_ACCEPT_NBSECONDSOLD')) {
135 print 'NbSecondsOld = <input class="width50 right" type="text" name="nbsecondsold" value="'.$nbsecondsold.'">';
136}
137print '</td></tr></table>';
138print '</div>';
139
140//if ($choice != 'confirm_allfiles')
141//{
142 print '<br>';
143 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("PurgeRunNow").'"></div>';
144//}
145
146print '</form>';
147
148if (preg_match('/^confirm/i', $choice)) {
149 print '<br>';
150 $formquestion = array();
151 print $form->formconfirm($_SERVER["PHP_SELF"].'?choice=allfiles&nbsecondsold='.$nbsecondsold, $langs->trans('Purge'), $langs->trans('ConfirmPurge').img_warning().' ', 'purge', $formquestion, 'no', 2);
152}
153
154// End of page
155llxFooter();
156$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
Class to manage utility methods.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.