From be9a6b3ed31e05ea24f879a6fbf4b3685a00aba9 Mon Sep 17 00:00:00 2001 From: Aina Sitraka <35221835+aynsix@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:43:30 +0300 Subject: [PATCH] PHRAS-3894 : bin/maintenance clean: - Removing BETA prefix and Memory leak (#4391) * remove beta * prefix beta in description --- .../Command/Maintenance/CleanLogDocsCommand.php | 14 +++++++++++--- .../Command/Maintenance/CleanLogSearchCommand.php | 14 +++++++++++--- .../Command/Maintenance/CleanLogViewCommand.php | 13 ++++++++++--- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogDocsCommand.php b/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogDocsCommand.php index 05b503ca51..3677eb50f7 100644 --- a/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogDocsCommand.php +++ b/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogDocsCommand.php @@ -14,10 +14,10 @@ class CleanLogDocsCommand extends Command public function __construct() { - parent::__construct('BETA - Clean:log_docs'); + parent::__construct('clean:log_docs'); $this - ->setDescription('clean the log_docs for all databox (if not specified) or a specific databox_id ') + ->setDescription('Beta - clean the log_docs for all databox (if not specified) or a specific databox_id ') ->addOption('databox_id', null, InputOption::VALUE_REQUIRED, 'the databox to clean') ->addOption('older_than', null, InputOption::VALUE_REQUIRED, 'delete older than ') ->addOption('action', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'download, mail, ftp, delete (if delete , delete also log entry for all events like push, add , validate, edit, collection, status, print, substit, publish for this record_id)') @@ -112,11 +112,19 @@ public function doExecute(InputInterface $input, OutputInterface $output) } $output->writeln(sprintf("\n \n dry-run , %d log docs entry to delete for databox %s", count($rowsActionDelete), $databox->get_dbname())); + // displayed only the 1000 first row to avoid memory leak + + $displayedRows = array_slice($rowsActionDelete, 0, 1000); + if (count($rows) > 1000) { + array_push($displayedRows, array_fill_keys(['id', 'log_id', 'date', 'record_id', 'final', 'action'], ' ... ')); + array_push($displayedRows, array_fill_keys(['id', 'log_id', 'date', 'record_id', 'final', 'action'], ' ... ')); + } + $logEntryTable = $this->getHelperSet()->get('table'); $headers = ['id', 'log_id', 'date', 'record_id', 'final', 'action']; $logEntryTable ->setHeaders($headers) - ->setRows($rowsActionDelete) + ->setRows($displayedRows) ->render($output); } else { diff --git a/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogSearchCommand.php b/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogSearchCommand.php index 71ccb5470c..89d01cc28e 100644 --- a/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogSearchCommand.php +++ b/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogSearchCommand.php @@ -11,10 +11,10 @@ class CleanLogSearchCommand extends Command { public function __construct() { - parent::__construct('BETA - Clean:log_search'); + parent::__construct('clean:log_search'); $this - ->setDescription('clean the log_search for all databox (if not specified) or a specific databox_id ') + ->setDescription('Beta - clean the log_search for all databox (if not specified) or a specific databox_id ') ->addOption('databox_id', null, InputOption::VALUE_REQUIRED, 'the databox to clean') ->addOption('older_than', null, InputOption::VALUE_REQUIRED, 'delete older than ') ->addOption('dry-run', null, InputOption::VALUE_NONE, 'dry run, list and count') @@ -77,11 +77,19 @@ public function doExecute(InputInterface $input, OutputInterface $output) $stmt->closeCursor(); $output->writeln(sprintf("\n \n dry-run , %d log search entry to delete for databox %s", count($rows), $databox->get_dbname())); + // displayed only the 1000 first row to avoid memory leak + + $displayedRows = array_slice($rows, 0, 1000); + if (count($rows) > 1000) { + array_push($displayedRows, array_fill_keys(['id', 'date', 'search', 'results', 'coll_id'], ' ... ')); + array_push($displayedRows, array_fill_keys(['id', 'date', 'search', 'results', 'coll_id'], ' ... ')); + } + $logEntryTable = $this->getHelperSet()->get('table'); $headers = ['id', 'date', 'search', 'results', 'coll_id']; $logEntryTable ->setHeaders($headers) - ->setRows($rows) + ->setRows($displayedRows) ->render($output); } else { $stmt = $databox->get_connection()->executeQuery($sqlDelete); diff --git a/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogViewCommand.php b/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogViewCommand.php index 89f811c8d4..b1ecef44dd 100644 --- a/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogViewCommand.php +++ b/lib/Alchemy/Phrasea/Command/Maintenance/CleanLogViewCommand.php @@ -11,10 +11,10 @@ class CleanLogViewCommand extends Command { public function __construct() { - parent::__construct('BETA - Clean:log_view'); + parent::__construct('clean:log_view'); $this - ->setDescription('clean the log_view for all databox (if not specified) or a specific databox_id ') + ->setDescription('Beta - clean the log_view for all databox (if not specified) or a specific databox_id ') ->addOption('databox_id', null, InputOption::VALUE_REQUIRED, 'the databox to clean') ->addOption('older_than', null, InputOption::VALUE_REQUIRED, 'delete older than ') ->addOption('dry-run', null, InputOption::VALUE_NONE, 'dry run, list and count') @@ -77,12 +77,19 @@ public function doExecute(InputInterface $input, OutputInterface $output) $stmt->closeCursor(); $output->writeln(sprintf("\n \n dry-run , %d log view entry to delete for databox %s", count($rows), $databox->get_dbname())); + // displayed only the 1000 first row to avoid memory leak + $displayedRows = array_slice($rows, 0, 1000); + if (count($rows) > 1000) { + array_push($displayedRows, array_fill_keys(['id', 'date', 'record_id', 'coll_id'], ' ... ')); + array_push($displayedRows, array_fill_keys(['id', 'date', 'record_id', 'coll_id'], ' ... ')); + } $logEntryTable = $this->getHelperSet()->get('table'); $headers = ['id', 'date', 'record_id', 'coll_id']; $logEntryTable ->setHeaders($headers) - ->setRows($rows) + ->setRows($displayedRows) ->render($output); + } else { $stmt = $databox->get_connection()->executeQuery($sqlDelete);