1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package midcom.console |
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace midcom\console\command; |
10
|
|
|
|
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
15
|
|
|
use midcom\console\loginhelper; |
16
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Purge deleted objects |
20
|
|
|
* |
21
|
|
|
* @package midcom.console |
22
|
|
|
*/ |
23
|
|
|
#[AsCommand( |
24
|
|
|
name: 'midcom:purgedeleted', |
25
|
|
|
description: 'Purge deleted objects', |
26
|
|
|
aliases: ['purgedeleted'] |
27
|
|
|
)] |
28
|
|
|
class purgedeleted extends Command |
29
|
|
|
{ |
30
|
|
|
use loginhelper; |
|
|
|
|
31
|
|
|
|
32
|
|
|
protected function configure() |
33
|
|
|
{ |
34
|
|
|
$config = new \midcom_config; |
35
|
|
|
$this->addOption('days', 'd', InputOption::VALUE_REQUIRED, 'Grace period in days', $config->get('cron_purge_deleted_after')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) : int |
39
|
|
|
{ |
40
|
|
|
$handler = new \midcom_cron_purgedeleted; |
41
|
|
|
$handler->set_cutoff((int) $input->getOption('days')); |
42
|
|
|
\midcom::get()->auth->request_sudo('midcom.core'); |
43
|
|
|
|
44
|
|
|
$output->writeln('Purging entries deleted before ' . gmdate('Y-m-d H:i:s', $handler->get_cutoff())); |
45
|
|
|
|
46
|
|
|
$total_purged = 0; |
47
|
|
|
$total_errors = 0; |
48
|
|
|
$start = microtime(true); |
49
|
|
|
foreach ($handler->get_classes() as $mgdschema) { |
50
|
|
|
$output->writeln("\n\nProcessing class <info>{$mgdschema}</info>"); |
51
|
|
|
$errors = 0; |
52
|
|
|
$stats = $handler->process_class($mgdschema); |
53
|
|
|
foreach ($stats['errors'] as $error) { |
54
|
|
|
$output->writeln(' <error>' . $error . '</error>'); |
55
|
|
|
$errors++; |
56
|
|
|
} |
57
|
|
|
$output->write(" Purged <info>{$stats['purged']}</info> deleted objects, <comment>" . $errors . " failures</comment>"); |
58
|
|
|
$total_purged += $stats['purged']; |
59
|
|
|
$total_errors += $errors; |
60
|
|
|
} |
61
|
|
|
$elapsed = round(microtime(true) - $start, 2); |
62
|
|
|
$output->writeln("\n\nPurged <info>{$total_purged}</info> deleted objects in {$elapsed}s, <comment>" . $total_errors . " failures</comment>"); |
63
|
|
|
return Command::SUCCESS; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|