dolibarr/htdocs/admin/tools/purge.php

157 lines
5.1 KiB
PHP
Raw Permalink Normal View History

<?php
2025-01-01 09:43:18 +01:00
/* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/tools/purge.php
* \brief Page to purge files (temporary or not)
*/
2021-08-04 12:26:38 +02:00
if (! defined('CSRFCHECK_WITH_TOKEN')) {
define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
}
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
require '../../main.inc.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 23:53:20 +01:00
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
2025-01-01 09:43:18 +01:00
*
* @var string $dolibarr_main_data_root
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 23:53:20 +01:00
*/
$langs->load("admin");
2020-09-16 19:39:50 +02:00
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$choice = GETPOST('choice', 'aZ09');
$nbsecondsold = GETPOSTINT('nbsecondsold');
// Define filelog to discard it from purge
$filelog = '';
2023-02-21 12:57:36 +01:00
if (isModEnabled('syslog')) {
$filelog = getDolGlobalString('SYSLOG_FILE');
$filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
}
// Security
2021-08-04 12:26:38 +02:00
if (!$user->admin) {
accessforbidden();
}
/*
* Actions
*/
2021-08-04 12:26:38 +02:00
2021-02-26 22:04:03 +01:00
if ($action == 'purge' && !preg_match('/^confirm/i', $choice) && ($choice != 'allfiles' || $confirm == 'yes')) {
// Increase limit of time. Works only if we are not in safe mode
2025-01-01 09:43:18 +01:00
$ExecTimeLimit = getDolGlobalInt('MAIN_ADMIN_TOOLS_PURGE_EXEC_TIME_LIMIT', 600);
2021-02-26 22:04:03 +01:00
if (!empty($ExecTimeLimit)) {
$err = error_reporting();
error_reporting(0); // Disable all errors
//error_reporting(E_ALL);
@set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
error_reporting($err);
}
2019-06-04 20:03:27 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
$utils = new Utils($db);
$result = $utils->purgeFiles($choice, $nbsecondsold);
$mesg = $utils->output;
2015-11-18 16:05:41 +01:00
setEventMessages($mesg, null, 'mesgs');
}
/*
* View
*/
llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-tools_purge');
$form = new Form($db);
print load_fiche_titre($langs->trans("Purge"), '', 'title_setup');
2020-05-06 05:10:42 +02:00
print '<span class="opacitymedium">'.$langs->trans("PurgeAreaDesc", $dolibarr_main_data_root).'</span><br>';
print '<br>';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'" />';
2012-08-02 10:07:55 +02:00
print '<input type="hidden" name="action" value="purge" />';
2024-06-15 19:04:28 +02:00
print '<div class="divsection wordbreak">';
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">';
print '<tr class="border"><td style="padding: 4px">';
2023-02-21 12:57:36 +01:00
if (isModEnabled('syslog')) {
2020-12-18 13:24:02 +01:00
print '<input type="radio" name="choice" id="choicelogfile" value="logfile"';
print ($choice && $choice == 'logfile') ? ' checked' : '';
$filelogparam = $filelog;
2020-12-04 21:08:51 +01:00
if ($user->admin && preg_match('/^dolibarr.*\.log$/', basename($filelog))) {
$filelogparam = '<a class="wordbreak" href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file=';
$filelogparam .= basename($filelog);
$filelogparam .= '">'.$filelog.'</a>';
}
2020-12-04 21:08:51 +01:00
$desc = $langs->trans("PurgeDeleteLogFile", '{filelogparam}');
$desc = str_replace('{filelogparam}', $filelogparam, $desc);
2020-12-18 13:24:02 +01:00
print '> <label for="choicelogfile">'.$desc.'</label>';
print '<br><br>';
}
2020-12-18 13:24:02 +01:00
print '<input type="radio" name="choice" id="choicetempfiles" value="tempfiles"';
print (!$choice || $choice == 'tempfiles' || $choice == 'allfiles') ? ' checked' : '';
2021-09-29 17:28:06 +02:00
print '> <label for="choicetempfiles">'.$langs->trans("PurgeDeleteTemporaryFilesShort").'</label><br><br>';
2020-12-18 13:24:02 +01:00
print '<input type="radio" name="choice" id="choiceallfiles" value="confirm_allfiles"';
print ($choice && $choice == 'confirm_allfiles') ? ' checked' : '';
print '> <label for="choiceallfiles">'.$langs->trans("PurgeDeleteAllFilesInDocumentsDir", $dolibarr_main_data_root).'</label>';
print '<br>';
if (getDolGlobalInt('MAIN_PURGE_ACCEPT_NBSECONDSOLD')) {
print 'NbSecondsOld = <input class="width50 right" type="text" name="nbsecondsold" value="'.$nbsecondsold.'">';
}
print '</td></tr></table>';
2024-06-15 19:04:28 +02:00
print '</div>';
2015-06-21 03:47:16 +02:00
//if ($choice != 'confirm_allfiles')
//{
print '<br>';
print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("PurgeRunNow").'"></div>';
2015-06-21 03:47:16 +02:00
//}
print '</form>';
2020-12-04 21:08:51 +01:00
if (preg_match('/^confirm/i', $choice)) {
print '<br>';
$formquestion = array();
print $form->formconfirm($_SERVER["PHP_SELF"].'?choice=allfiles&nbsecondsold='.$nbsecondsold, $langs->trans('Purge'), $langs->trans('ConfirmPurge').img_warning().' ', 'purge', $formquestion, 'no', 2);
}
2018-07-28 14:29:28 +02:00
// End of page
llxFooter();
2012-04-11 13:29:45 +02:00
$db->close();