Skip to content

Commit

Permalink
Merge tag v2.3.26 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Aug 27, 2024
1 parent f9dd806 commit 426cfed
Show file tree
Hide file tree
Showing 23 changed files with 550 additions and 535 deletions.
93 changes: 50 additions & 43 deletions src/Console/AppInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,39 +82,40 @@ protected function importAppData(string $themeConfigPath): void
{
$data = $this->getAppConfig($themeConfigPath);

if (isset($data["importFiles"])) {
if (isset($data["importFiles"]['groups'])) {
foreach ($data["importFiles"]['groups'] as $filename) {
$this->importFile($filename, $this->groupsImporter);
}
if (!isset($data["importFiles"]) || !is_array($data["importFiles"])) {
$this->io->warning('Config file "' . $themeConfigPath . '" has no data to import.');
return;
}

if (isset($data["importFiles"]['groups'])) {
foreach ($data["importFiles"]['groups'] as $filename) {
$this->importFile($filename, $this->groupsImporter);
}
if (isset($data["importFiles"]['roles'])) {
foreach ($data["importFiles"]['roles'] as $filename) {
$this->importFile($filename, $this->rolesImporter);
}
}
if (isset($data["importFiles"]['roles'])) {
foreach ($data["importFiles"]['roles'] as $filename) {
$this->importFile($filename, $this->rolesImporter);
}
if (isset($data["importFiles"]['settings'])) {
foreach ($data["importFiles"]['settings'] as $filename) {
$this->importFile($filename, $this->settingsImporter);
}
}
if (isset($data["importFiles"]['settings'])) {
foreach ($data["importFiles"]['settings'] as $filename) {
$this->importFile($filename, $this->settingsImporter);
}
if (isset($data["importFiles"]['nodetypes'])) {
foreach ($data["importFiles"]['nodetypes'] as $filename) {
$this->importFile($filename, $this->nodeTypesImporter);
}
}
if (isset($data["importFiles"]['nodetypes'])) {
foreach ($data["importFiles"]['nodetypes'] as $filename) {
$this->importFile($filename, $this->nodeTypesImporter);
}
if (isset($data["importFiles"]['tags'])) {
foreach ($data["importFiles"]['tags'] as $filename) {
$this->importFile($filename, $this->tagsImporter);
}
}
if (isset($data["importFiles"]['tags'])) {
foreach ($data["importFiles"]['tags'] as $filename) {
$this->importFile($filename, $this->tagsImporter);
}
if (isset($data["importFiles"]['attributes'])) {
foreach ($data["importFiles"]['attributes'] as $filename) {
$this->importFile($filename, $this->attributeImporter);
}
}
if (isset($data["importFiles"]['attributes'])) {
foreach ($data["importFiles"]['attributes'] as $filename) {
$this->importFile($filename, $this->attributeImporter);
}
} else {
$this->io->warning('Config file "' . $themeConfigPath . '" has no data to import.');
}
}

Expand All @@ -129,24 +130,30 @@ protected function importFile(string $filename, EntityImporterInterface $importe
} else {
throw new \RuntimeException($filename . ' is not a valid file');
}
if (!$this->dryRun) {
try {
if (false === $fileContent = file_get_contents($file->getPathname())) {
throw new \RuntimeException($file->getPathname() . ' file is not readable');
}
$importer->import($fileContent);
$this->managerRegistry->getManager()->flush();
$this->io->writeln(
'* <info>' . $file->getPathname() . '</info> file has been imported.'
);
return;
} catch (EntityAlreadyExistsException $e) {
$this->io->writeln(
'* <info>' . $file->getPathname() . '</info>' .
' <error>has NOT been imported (' . $e->getMessage() . ')</error>.'
);
if ($this->dryRun) {
$this->io->writeln(
'* <info>' . $file->getPathname() . '</info> file would be imported.'
);
return;
}

try {
if (false === $fileContent = file_get_contents($file->getPathname())) {
throw new \RuntimeException($file->getPathname() . ' file is not readable');
}
$importer->import($fileContent);
$this->managerRegistry->getManager()->flush();
$this->io->writeln(
'* <info>' . $file->getPathname() . '</info> file has been imported.'
);
return;
} catch (EntityAlreadyExistsException $e) {
$this->io->writeln(
'* <info>' . $file->getPathname() . '</info>' .
' <error>has NOT been imported (' . $e->getMessage() . ')</error>.'
);
}

$this->io->writeln(
'* <info>' . $file->getPathname() . '</info> file has been imported.'
);
Expand Down
135 changes: 73 additions & 62 deletions src/Console/CustomFormAnswerPurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,74 +44,85 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->findAllWithRetentionTime();

foreach ($customForms as $customForm) {
if (null !== $interval = $customForm->getRetentionTimeInterval()) {
$purgeBefore = (new \DateTime())->sub($interval);
$customFormAnswers = $this->managerRegistry
->getRepository(CustomFormAnswer::class)
->findByCustomFormSubmittedBefore($customForm, $purgeBefore);
$count = count($customFormAnswers);

$documents = $this->managerRegistry
->getRepository(Document::class)
->findByCustomFormSubmittedBefore($customForm, $purgeBefore);
$documentsCount = count($documents);
$this->purgeCustomFormAnswers($customForm, $input, $output);
}

if ($output->isVeryVerbose()) {
$io->info(\sprintf(
'Checking if “%s” custom-form has answers before %s',
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
));
}
return 0;
}

protected function purgeCustomFormAnswers(CustomForm $customForm, InputInterface $input, OutputInterface $output): void
{
$io = new SymfonyStyle($input, $output);

if (null === $interval = $customForm->getRetentionTimeInterval()) {
return;
}

if ($count > 0) {
$purgeBefore = (new \DateTime())->sub($interval);
$customFormAnswers = $this->managerRegistry
->getRepository(CustomFormAnswer::class)
->findByCustomFormSubmittedBefore($customForm, $purgeBefore);
$count = count($customFormAnswers);

$documents = $this->managerRegistry
->getRepository(Document::class)
->findByCustomFormSubmittedBefore($customForm, $purgeBefore);
$documentsCount = count($documents);

if ($output->isVeryVerbose()) {
$io->info(\sprintf(
'Checking if “%s” custom-form has answers before %s',
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
));
}

if ($count <= 0) {
return;
}

$io->info(\sprintf(
'Purge %d custom-form answer(s) with %d documents(s) from “%s” before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
));

if (
!$input->getOption('dry-run') &&
(!$input->isInteractive() || $io->confirm(\sprintf(
'Are you sure you want to delete %d custom-form answer(s) and %d document(s) from “%s” before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
), false))
) {
$this->managerRegistry
->getRepository(CustomFormAnswer::class)
->deleteByCustomFormSubmittedBefore($customForm, $purgeBefore);

foreach ($documents as $document) {
$this->eventDispatcher->dispatch(
new DocumentDeletedEvent($document)
);
if ($output->isVeryVerbose()) {
$io->info(\sprintf(
'Purge %d custom-form answer(s) with %d documents(s) from “%s” before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
'“%s” document has been deleted',
$document->getRelativePath()
));

if (
!$input->getOption('dry-run') &&
(!$input->isInteractive() || $io->confirm(\sprintf(
'Are you sure you want to delete %d custom-form answer(s) and %d document(s) from “%s” before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
), false))
) {
$this->managerRegistry
->getRepository(CustomFormAnswer::class)
->deleteByCustomFormSubmittedBefore($customForm, $purgeBefore);

foreach ($documents as $document) {
$this->eventDispatcher->dispatch(
new DocumentDeletedEvent($document)
);
if ($output->isVeryVerbose()) {
$io->info(\sprintf(
'“%s” document has been deleted',
$document->getRelativePath()
));
}
$this->managerRegistry->getManager()->remove($document);
}
$this->managerRegistry->getManager()->flush();
$this->logger->info(\sprintf(
'%d answer(s) and %d document(s) were deleted from “%s” custom-form before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
));
}
}
$this->managerRegistry->getManager()->remove($document);
}
$this->managerRegistry->getManager()->flush();
$this->logger->info(\sprintf(
'%d answer(s) and %d document(s) were deleted from “%s” custom-form before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
));
}

return 0;
}
}
15 changes: 8 additions & 7 deletions src/Console/FilesExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ protected function zipFolder(ZipArchive $zip, string $folder, string $prefix = "
*/
foreach ($files as $file) {
// Skip directories (they would be added automatically)
if (!$file->isDir()) {
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = \mb_substr($filePath, \mb_strlen($folder) + 1);

// Add current file to archive
$zip->addFile($filePath, $prefix . '/' . $relativePath);
if ($file->isDir()) {
continue;
}
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = \mb_substr($filePath, \mb_strlen($folder) + 1);

// Add current file to archive
$zip->addFile($filePath, $prefix . '/' . $relativePath);
}
}
}
50 changes: 24 additions & 26 deletions src/Console/FilesImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$zipArchivePath = $input->getArgument('input');
$zip = new ZipArchive();
if (true === $zip->open($zipArchivePath)) {
if (
$io->askQuestion(
$confirmation
)
) {
$zip->extractTo($tempDir);

$fs = new Filesystem();
if ($fs->exists($tempDir . $this->getPublicFolderName())) {
$fs->mirror($tempDir . $this->getPublicFolderName(), $this->fileAware->getPublicFilesPath());
$io->success('Public files have been imported.');
}
if ($fs->exists($tempDir . $this->getPrivateFolderName())) {
$fs->mirror($tempDir . $this->getPrivateFolderName(), $this->fileAware->getPrivateFilesPath());
$io->success('Private files have been imported.');
}
if ($fs->exists($tempDir . $this->getFontsFolderName())) {
$fs->mirror($tempDir . $this->getFontsFolderName(), $this->fileAware->getFontsFilesPath());
$io->success('Font files have been imported.');
}

$fs->remove($tempDir);
}
return 0;
} else {
if (true !== $zip->open($zipArchivePath)) {
$io->error('Zip archive does not exist or is invalid.');
return 1;
}

if (!$io->askQuestion($confirmation)) {
return 0;
}

$zip->extractTo($tempDir);

$fs = new Filesystem();
if ($fs->exists($tempDir . $this->getPublicFolderName())) {
$fs->mirror($tempDir . $this->getPublicFolderName(), $this->fileAware->getPublicFilesPath());
$io->success('Public files have been imported.');
}
if ($fs->exists($tempDir . $this->getPrivateFolderName())) {
$fs->mirror($tempDir . $this->getPrivateFolderName(), $this->fileAware->getPrivateFilesPath());
$io->success('Private files have been imported.');
}
if ($fs->exists($tempDir . $this->getFontsFolderName())) {
$fs->mirror($tempDir . $this->getFontsFolderName(), $this->fileAware->getFontsFilesPath());
$io->success('Font files have been imported.');
}

$fs->remove($tempDir);
return 0;
}
}
18 changes: 9 additions & 9 deletions src/Console/GenerateApiResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->getRepository(NodeType::class)
->findAll();

if (count($nodeTypes) > 0) {
foreach ($nodeTypes as $nt) {
$resourcePath = $this->apiResourceGenerator->generate($nt);
if (null !== $resourcePath) {
$io->writeln("* API resource <info>" . $resourcePath . "</info> has been generated.");
}
}
return 0;
} else {
if (count($nodeTypes) === 0) {
$io->error('No available node-types…');
return 1;
}

foreach ($nodeTypes as $nt) {
$resourcePath = $this->apiResourceGenerator->generate($nt);
if (null !== $resourcePath) {
$io->writeln("* API resource <info>" . $resourcePath . "</info> has been generated.");
}
}
return 0;
}
}
Loading

0 comments on commit 426cfed

Please sign in to comment.