Merge branch 'develop-unstable' into chg-bootstrap-elements

develop-unstable
Sami Mokaddem 2022-11-28 08:44:55 +01:00
commit ae5a8eef32
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 11 additions and 5 deletions

View File

@ -11,7 +11,7 @@ use Cake\Console\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use Cake\Utility\Hash;
use Cake\Utility\Text;
use Cake\Validation\Validator;
@ -22,7 +22,7 @@ class SummaryCommand extends Command
{
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser->setDescription('Create a summary for data associated to the passed nationality that has been modified.');
$parser->setDescription('Create a summary for data associated to the passed nationality that has been modified. Summaries will be printed out in STDIN and written in individual `txt` files.');
$parser->addArgument('nationality', [
'short' => 'n',
'help' => 'The organisation nationality.',
@ -33,6 +33,11 @@ class SummaryCommand extends Command
'help' => 'The amount of days to look back in the logs',
'default' => 7
]);
$parser->addOption('output', [
'short' => 'o',
'help' => 'The destination folder where to write the files',
'default' => '/tmp'
]);
return $parser;
}
@ -49,15 +54,16 @@ class SummaryCommand extends Command
}
foreach ($nationalities as $nationality) {
$this->io->out(sprintf('Nationality: %s', $nationality));
$this->_collectChangedForNationality($nationality, $days);
$this->_collectChangedForNationality($nationality, $days, $args->getOption('output'));
$this->io->out($io->nl(2));
$this->io->hr();
}
}
protected function _collectChangedForNationality($nationality, $days)
protected function _collectChangedForNationality($nationality, $days, $folderPath)
{
$filename = sprintf('/tmp/%s.txt', $nationality);
$folderPath = rtrim($folderPath, '/');
$filename = sprintf('%s/%s.txt', $folderPath, $nationality);
$file_input = fopen($filename, 'w');
$organisationIDsForNationality = $this->_fetchOrganisationsForNationality($nationality);
if (empty($organisationIDsForNationality)) {