Skip to content

Commit

Permalink
chore: Removed deprecated UniqueEntity constraint fron roadiz
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Jun 26, 2023
1 parent 2b2f7fa commit c08593d
Show file tree
Hide file tree
Showing 32 changed files with 196 additions and 314 deletions.
2 changes: 0 additions & 2 deletions lib/RoadizCompatBundle/src/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ public static function getAliases(): array
\RZ\Roadiz\CoreBundle\Form\Constraint\RecaptchaValidator::class => \RZ\Roadiz\CMS\Forms\Constraints\RecaptchaValidator::class,
\RZ\Roadiz\CoreBundle\Form\Constraint\SimpleLatinString::class => \RZ\Roadiz\CMS\Forms\Constraints\SimpleLatinString::class,
\RZ\Roadiz\CoreBundle\Form\Constraint\SimpleLatinStringValidator::class => \RZ\Roadiz\CMS\Forms\Constraints\SimpleLatinStringValidator::class,
\RZ\Roadiz\CoreBundle\Form\Constraint\UniqueEntity::class => \RZ\Roadiz\CMS\Forms\Constraints\UniqueEntity::class,
\RZ\Roadiz\CoreBundle\Form\Constraint\UniqueEntityValidator::class => \RZ\Roadiz\CMS\Forms\Constraints\UniqueEntityValidator::class,
\RZ\Roadiz\CoreBundle\Form\Constraint\UniqueFilename::class => \RZ\Roadiz\CMS\Forms\Constraints\UniqueFilename::class,
\RZ\Roadiz\CoreBundle\Form\Constraint\UniqueFilenameValidator::class => \RZ\Roadiz\CMS\Forms\Constraints\UniqueFilenameValidator::class,
\RZ\Roadiz\CoreBundle\Form\Constraint\UniqueNodeName::class => \RZ\Roadiz\CMS\Forms\Constraints\UniqueNodeName::class,
Expand Down
5 changes: 3 additions & 2 deletions lib/RoadizCompatBundle/src/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ protected function getPreviewResolver(): PreviewResolverInterface
}

/**
* @param object $event
* @return object The passed $event MUST be returned
* @template T of object
* @param T $event
* @return T The passed $event MUST be returned
*/
protected function dispatchEvent($event)
{
Expand Down
30 changes: 26 additions & 4 deletions lib/RoadizCoreBundle/src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,48 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->askQuestion($question)
) {
$fixturesRoot = dirname(__DIR__) . '/../config';
$data = Yaml::parse(file_get_contents($fixturesRoot . "/fixtures.yaml"));
$fixtureFile = file_get_contents($fixturesRoot . "/fixtures.yaml");

if (false === $fixtureFile) {
$io->error('No fixtures.yaml file found in ' . $fixturesRoot);
return 1;
}

$data = Yaml::parse($fixtureFile);

if (isset($data["importFiles"]['roles'])) {
foreach ($data["importFiles"]['roles'] as $filename) {
$filePath = $fixturesRoot . "/" . $filename;
$this->rolesImporter->import(file_get_contents($filePath));
$fileContents = file_get_contents($filePath);
if (false === $fileContents) {
$io->error('No file found in ' . $filePath);
return 1;
}
$this->rolesImporter->import($fileContents);
$io->success('Theme file “' . $filePath . '” has been imported.');
}
}
if (isset($data["importFiles"]['groups'])) {
foreach ($data["importFiles"]['groups'] as $filename) {
$filePath = $fixturesRoot . "/" . $filename;
$this->groupsImporter->import(file_get_contents($filePath));
$fileContents = file_get_contents($filePath);
if (false === $fileContents) {
$io->error('No file found in ' . $filePath);
return 1;
}
$this->groupsImporter->import($fileContents);
$io->success('Theme file “' . $filePath . '” has been imported.');
}
}
if (isset($data["importFiles"]['settings'])) {
foreach ($data["importFiles"]['settings'] as $filename) {
$filePath = $fixturesRoot . "/" . $filename;
$this->settingsImporter->import(file_get_contents($filePath));
$fileContents = file_get_contents($filePath);
if (false === $fileContents) {
$io->error('No file found in ' . $filePath);
return 1;
}
$this->settingsImporter->import($fileContents);
$io->success('Theme files “' . $filePath . '” has been imported.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class NodesSourcesEntitiesPathCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container): void
{
$projectDir = $container->getParameter('kernel.project_dir');
if (!\is_string($projectDir)) {
throw new \RuntimeException('kernel.project_dir parameter must be a string.');
}
$container->setParameter('roadiz_core.generated_entities_dir', $projectDir . '/src/GeneratedEntity');
$container->setParameter('roadiz_core.serialized_node_types_dir', $projectDir . '/src/Resources/node-types');
$container->setParameter('roadiz_core.import_files_config_path', $projectDir . '/src/Resources/config.yml');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ public function onFilterDocumentEvent(FilterDocumentEvent $event): void
$document = $event->getDocument();
if (
$document instanceof Document &&
null !== $document->getId() &&
\is_numeric($document->getId()) &&
$document->isLocal() &&
null !== $document->getRelativePath()
) {
$this->bus->dispatch(new Envelope(new DocumentRawMessage($document->getId())));
$this->bus->dispatch(new Envelope(new DocumentFilesizeMessage($document->getId())));
$this->bus->dispatch(new Envelope(new DocumentSizeMessage($document->getId())));
$this->bus->dispatch(new Envelope(new DocumentAverageColorMessage($document->getId())));
$this->bus->dispatch(new Envelope(new DocumentExifMessage($document->getId())));
$this->bus->dispatch(new Envelope(new DocumentSvgMessage($document->getId())));
$this->bus->dispatch(new Envelope(new DocumentAudioVideoMessage($document->getId())));
$this->bus->dispatch(new Envelope(new DocumentPdfMessage($document->getId())));
$id = (int) $document->getId();
$this->bus->dispatch(new Envelope(new DocumentRawMessage($id)));
$this->bus->dispatch(new Envelope(new DocumentFilesizeMessage($id)));
$this->bus->dispatch(new Envelope(new DocumentSizeMessage($id)));
$this->bus->dispatch(new Envelope(new DocumentAverageColorMessage($id)));
$this->bus->dispatch(new Envelope(new DocumentExifMessage($id)));
$this->bus->dispatch(new Envelope(new DocumentSvgMessage($id)));
$this->bus->dispatch(new Envelope(new DocumentAudioVideoMessage($id)));
$this->bus->dispatch(new Envelope(new DocumentPdfMessage($id)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ protected function processMessage(AbstractDocumentMessage $message, DocumentInte
* This process requires document files to be locally stored!
*/
$pdfPath = \tempnam(\sys_get_temp_dir(), 'pdf_');
if (false === $pdfPath) {
throw new UnrecoverableMessageHandlingException('Cannot create temporary file for PDF thumbnail.');
}
\rename($pdfPath, $pdfPath .= $document->getFilename());

/*
* Copy AV locally
*/
$pdfPathResource = \fopen($pdfPath, 'w');
if (false === $pdfPathResource) {
throw new UnrecoverableMessageHandlingException('Cannot open temporary file for PDF thumbnail.');
}
\stream_copy_to_stream($this->documentsStorage->readStream($document->getMountPath()), $pdfPathResource);
\fclose($pdfPathResource);

Expand All @@ -75,6 +81,9 @@ protected function extractPdfThumbnail(DocumentInterface $document, string $loca
}

$thumbnailPath = \tempnam(\sys_get_temp_dir(), 'thumbnail_');
if (false === $thumbnailPath) {
throw new UnrecoverableMessageHandlingException('Cannot create temporary file for PDF thumbnail.');
}
\rename($thumbnailPath, $thumbnailPath .= $document->getFilename() . '.jpg');

try {
Expand Down
12 changes: 10 additions & 2 deletions lib/RoadizCoreBundle/src/Entity/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,19 @@ public function setVisible(bool $visible): Node
#[SymfonySerializer\Ignore]
public function getOneLineSourceSummary(): string
{
$text = "Source " . $this->getNodeSources()->first()->getId() . PHP_EOL;
$text = "Source " .
(
$this->getNodeSources()->first() ?
$this->getNodeSources()->first()->getId() :
''
) .
PHP_EOL;

foreach ($this->getNodeType()->getFields() as $field) {
$getterName = $field->getGetterName();
$text .= '[' . $field->getLabel() . ']: ' . $this->getNodeSources()->first()->$getterName() . PHP_EOL;
$text .= '[' . $field->getLabel() . ']: ' .
($this->getNodeSources()->first() ? $this->getNodeSources()->first()->$getterName() : '') .
PHP_EOL;
}

return $text;
Expand Down
15 changes: 10 additions & 5 deletions lib/RoadizCoreBundle/src/Entity/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace RZ\Roadiz\CoreBundle\Entity;

use RZ\Roadiz\CompatBundle\Controller\AppController;
use RZ\Roadiz\Core\AbstractEntities\AbstractEntity;

/**
Expand Down Expand Up @@ -88,12 +89,16 @@ public function getInformations(): array

if (class_exists($class)) {
$reflector = new \ReflectionClass($class);
if ($reflector->isSubclassOf('\\RZ\\Roadiz\\CMS\\Controllers\\AppController')) {
if ($reflector->isSubclassOf(AppController::class)) {
$nameCallable = [$class, 'getThemeName'];
$authorCallable = [$class, 'getThemeAuthor'];
$copyrightCallable = [$class, 'getThemeCopyright'];
$dirCallable = [$class, 'getThemeDir'];
return [
'name' => call_user_func([$class, 'getThemeName']),
'author' => call_user_func([$class, 'getThemeAuthor']),
'copyright' => call_user_func([$class, 'getThemeCopyright']),
'dir' => call_user_func([$class, 'getThemeDir'])
'name' => \is_callable($nameCallable) ? call_user_func($nameCallable) : null,
'author' => \is_callable($authorCallable) ? call_user_func($authorCallable) : null,
'copyright' => \is_callable($copyrightCallable) ? call_user_func($copyrightCallable) : null,
'dir' => \is_callable($dirCallable) ? call_user_func($dirCallable) : null,
];
}
}
Expand Down
42 changes: 0 additions & 42 deletions lib/RoadizCoreBundle/src/Form/Constraint/UniqueEntity.php

This file was deleted.

Loading

0 comments on commit c08593d

Please sign in to comment.