-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PS-598 fix indexer rendition definition duplicates
- Loading branch information
Showing
21 changed files
with
358 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20231221125408 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE rendition_definition ADD key VARCHAR(150) DEFAULT NULL'); | ||
$this->addSql('CREATE UNIQUE INDEX uniq_rend_def_ws_key ON rendition_definition (workspace_id, key)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE SCHEMA public'); | ||
$this->addSql('DROP INDEX uniq_rend_def_ws_key'); | ||
$this->addSql('ALTER TABLE rendition_definition DROP key'); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
databox/api/src/Api/InputTransformer/RenditionDefinitionInputTransformer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Api\InputTransformer; | ||
|
||
use App\Api\Model\Input\RenditionDefinitionInput; | ||
use App\Entity\Core\RenditionDefinition; | ||
use App\Entity\Core\Workspace; | ||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | ||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; | ||
|
||
class RenditionDefinitionInputTransformer extends AbstractInputTransformer | ||
{ | ||
public function supports(string $resourceClass, object $data): bool | ||
{ | ||
return RenditionDefinition::class === $resourceClass && $data instanceof RenditionDefinitionInput; | ||
} | ||
|
||
/** | ||
* @param RenditionDefinitionInput $data | ||
*/ | ||
public function transform(object $data, string $resourceClass, array $context = []): object|iterable | ||
{ | ||
$isNew = !isset($context[AbstractNormalizer::OBJECT_TO_POPULATE]); | ||
/** @var RenditionDefinition $object */ | ||
$object = $context[AbstractNormalizer::OBJECT_TO_POPULATE] ?? new RenditionDefinition(); | ||
|
||
$workspace = null; | ||
if ($data->workspace) { | ||
$workspace = $data->workspace; | ||
} | ||
|
||
if ($isNew) { | ||
if (!$workspace instanceof Workspace) { | ||
throw new BadRequestHttpException('Missing workspace'); | ||
} | ||
|
||
if ($data->key) { | ||
$rendDef = $this->em->getRepository(RenditionDefinition::class) | ||
->findOneBy([ | ||
'key' => $data->key, | ||
'workspace' => $workspace->getId() | ||
]); | ||
|
||
if ($rendDef) { | ||
$isNew = false; | ||
$object = $rendDef; | ||
} | ||
} | ||
} | ||
|
||
if ($isNew) { | ||
$object->setWorkspace($workspace); | ||
$object->setKey($data->key); | ||
} | ||
|
||
if (null !== $data->name) { | ||
$object->setName($data->name); | ||
} | ||
if (null !== $data->class) { | ||
$object->setClass($data->class); | ||
} | ||
|
||
if (null !== $data->download) { | ||
$object->setDownload($data->download); | ||
} | ||
if (null !== $data->pickSourceFile) { | ||
$object->setPickSourceFile($data->pickSourceFile); | ||
} | ||
if (null !== $data->useAsOriginal) { | ||
$object->setUseAsOriginal($data->useAsOriginal); | ||
} | ||
if (null !== $data->useAsPreview) { | ||
$object->setUseAsPreview($data->useAsPreview); | ||
} | ||
if (null !== $data->useAsThumbnail) { | ||
$object->setUseAsThumbnail($data->useAsThumbnail); | ||
} | ||
if (null !== $data->useAsThumbnailActive) { | ||
$object->setUseAsThumbnailActive($data->useAsThumbnailActive); | ||
} | ||
if (null !== $data->definition) { | ||
$object->setDefinition($data->definition); | ||
} | ||
if (null !== $data->priority) { | ||
$object->setPriority($data->priority); | ||
} | ||
|
||
return $object; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
databox/api/src/Api/Model/Input/RenditionDefinitionInput.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Api\Model\Input; | ||
|
||
use App\Entity\Core\RenditionClass; | ||
use App\Entity\Core\RenditionDefinition; | ||
use App\Entity\Core\Workspace; | ||
use Symfony\Component\Serializer\Attribute\Groups; | ||
|
||
class RenditionDefinitionInput | ||
{ | ||
/** | ||
* @var Workspace | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $workspace; | ||
|
||
/** | ||
* @var RenditionClass | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $class; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $name; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $download = true; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $pickSourceFile = false; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $useAsOriginal = false; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $useAsPreview = false; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $useAsThumbnail = false; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $useAsThumbnailActive = false; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $definition = ''; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $priority = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
#[Groups([RenditionDefinition::GROUP_WRITE])] | ||
public $key = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {setLogLevel} from "../lib/logger"; | ||
import {CommandCommonOptions} from "../types"; | ||
|
||
export function applyCommonOptions<O extends CommandCommonOptions>(opts: O): void { | ||
if (opts.debug) { | ||
setLogLevel('debug'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.