Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Sep 29, 2023
1 parent 407cdd7 commit 8808fba
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
17 changes: 13 additions & 4 deletions databox/api/src/Api/InputTransformer/AssetInputTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,19 @@ public function transform(object $data, string $resourceClass, array $context =

if (!empty($data->renditions)) {
foreach ($data->renditions as $renditionInput) {
$definition = $this->renditionManager->getRenditionDefinitionByName(
$workspace,
$renditionInput->definition
);
if ($renditionInput->definitionId) {
$definition = $this->renditionManager->getRenditionDefinitionById(
$workspace,
$renditionInput->definitionId
);
} elseif ($renditionInput->name) {
$definition = $this->renditionManager->getRenditionDefinitionByName(
$workspace,
$renditionInput->name
);
} else {
throw new BadRequestHttpException('Rendition input error: You must provide either "name" or "definitionId"');
}
$rendition = $this->renditionManager->getOrCreateRendition($object, $definition);
$file = $this->handleSource($renditionInput->source, $workspace);
$rendition->setFile($file);
Expand Down
4 changes: 2 additions & 2 deletions databox/api/src/Api/InputTransformer/AttributeInputTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function assignAttributes(
$attr = clone $attribute;
$attr->value = $value;
/** @var Attribute|TemplateAttribute $returnedAttribute */
$returnedAttribute = $attributeInputProcessor->transform($attr, $returnedAttribute::class, $subContext);
$returnedAttribute = $attributeInputProcessor->transform($attr, Attribute::class, $subContext);
$object->addAttribute($returnedAttribute);
}

Expand All @@ -85,7 +85,7 @@ protected function assignAttributes(
}

/** @var Attribute|TemplateAttribute $returnedAttribute */
$returnedAttribute = $attributeInputProcessor->transform($attribute, $attribute::class, $subContext);
$returnedAttribute = $attributeInputProcessor->transform($attribute, Attribute::class, $subContext);
$object->addAttribute($returnedAttribute);
}
}
Expand Down
2 changes: 1 addition & 1 deletion databox/api/src/Attribute/AttributeAssigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function assignAttributeFromInput(AbstractBaseAttribute $attribute, Abstr
$type = $this->attributeTypeRegistry->getStrictType($attribute->getDefinition()->getFieldType());
$value = $type->normalizeValue($data->value);

$attribute->setValue($value);
$attribute->setValue($value ?? '');
$attribute->setPosition($data->position ?? 0);

return $attribute;
Expand Down
17 changes: 17 additions & 0 deletions databox/api/src/Storage/RenditionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ public function getRenditionDefinitionByName(Workspace $workspace, string $name)
return $definition;
}

public function getRenditionDefinitionById(Workspace $workspace, string $id): RenditionDefinition
{
$definition = $this
->em
->getRepository(RenditionDefinition::class)
->findOneBy([
'id' => $id,
'workspace' => $workspace->getId(),
]);

if (!$definition instanceof RenditionDefinition) {
throw new \InvalidArgumentException(sprintf('Rendition definition "%s" not found', $id));
}

return $definition;
}

public function resetAssetRenditions(Asset $asset): void
{
$renditions = $asset->getRenditions();
Expand Down
1 change: 1 addition & 0 deletions databox/indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"scripts": {
"start": "node --enable-source-maps dist/index.js",
"console": "node --enable-source-maps dist/console.js",
"console:dev": "ts-node --files ./src/console.ts",
"build": "rimraf ./dist && tsc",
"start:dev": "nodemon",
"test": "jest",
Expand Down
3 changes: 2 additions & 1 deletion databox/indexer/src/databox/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export type AttributeInput = ({value: any} | {values: any[]}) & {
}

export type RenditionInput = {
definition: string;
definitionId?: string;
name?: string;
source?: Source;
}

Expand Down
4 changes: 2 additions & 2 deletions databox/indexer/src/handlers/phraseanet/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function createAsset(
const ad = attrDefinitionIndex[c.meta_structure_id.toString()];

const d = {
definition: `/attribute-definitions/${ad.id}`,
definitionId: ad.id,
origin: 'machine',
originVendor: 'indexer-import',
} as Partial<AttributeInput>;
Expand All @@ -59,7 +59,7 @@ export function createAsset(
}

return {
definition: defName,
name: defName,
sourceFile: {
url: s.permalink.url,
isPrivate: false,
Expand Down

0 comments on commit 8808fba

Please sign in to comment.