feat (media-library): emscli media library update file links#1572
feat (media-library): emscli media library update file links#1572YanisGroffier wants to merge 27 commits intoems-project:7.xfrom
Conversation
…g fields) into ems object links (if the file exists in a media library)
…-library-update-file-links
…tion. Removed lines.
| use RectorPrefix202601\Symfony\Component\Console\Input\InputArgument; | ||
| use RectorPrefix202601\Symfony\Component\Console\Input\InputOption; |
| $this->options = new MediaLibrarySyncOptions( | ||
| //TODO If I have to put all args in this method, do I have to declare them before (in the object attributes) or can I simply put a bunch of nulls and false? | ||
| folder: $this->getArgumentString(self::ARGUMENT_FOLDER), | ||
| contentType: $this->getOptionString(self::OPTION_CONTENT_TYPE), | ||
| folderField: $this->getOptionString(self::OPTION_FOLDER_FIELD), | ||
| pathField: null, | ||
| fileField: null, | ||
| metaDataFile: null, | ||
| locateRowExpression: null, | ||
| targetFolder: null, | ||
| dryRun: false, | ||
| onlyMissingFile: false, | ||
| onlyMetadataFile: false, | ||
| hashFolder: false, | ||
| hashMetaDataFile: false, | ||
| ); | ||
|
|
||
| } |
There was a problem hiding this comment.
Why do you want to have a MediaLibrarySyncOptions? With all those options? I would recommand to first starts with simple class's members
| foreach ($coreApi->search()->scroll($search) as $hit) | ||
| { | ||
|
|
||
| foreach($this->fields as $field) { |
There was a problem hiding this comment.
Do not hesitate to create functions in order to avoid too much nested loops
| $this->io->section('Found Media Library files'); | ||
| dump($this->logReports); |
There was a problem hiding this comment.
See in the colibri script how an excel is generated and uploaded in the admin
| if($match['content_type'] === 'media_file') { | ||
| $emsLink = EMSLink::fromMatch($match); | ||
| $this->logMediaLibraryLink($key, $emsLink, $value); |
There was a problem hiding this comment.
No need to log already "good" links
| ], $tempFile->path); | ||
| $filename = \sprintf('UpdateFileLinks - Rapport %s.xlsx', \date('YmdHis')); | ||
| $hash = $this->coreApi->file()->uploadFile($tempFile->path, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $filename); | ||
| $this->io->success($this->buildUrl($hash, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $filename)); |
There was a problem hiding this comment.
Does the mime type not already define somewhere ?
There was a problem hiding this comment.
No but it can be put in a const to avoid repetition
| $this->mediaLibraryContentType = $this->getOptionString(self::OPTION_MEDIA_LIBRARY_CONTENT_TYPE); | ||
| $this->fileField = $this->getOptionString(self::OPTION_FILE_FIELD); | ||
| $this->coreApi = $this->adminHelper->getCoreApi(); | ||
| $this->mimeType = $this->getOptionString(self::OPTION_MIME_TYPE); |
There was a problem hiding this comment.
Not really useful to me. The mimetype 'Type of spreadsheet document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' should be defined in the class EMS\Helpers\Html\MimeTypes
| $defaultAlias = $this->coreApi->meta()->getDefaultContentTypeEnvironmentAlias($this->contentTypeName); | ||
| $search = new Search([$defaultAlias]); | ||
| $search->setContentTypes([$this->contentTypeName]); | ||
| $search->setSources(['*']); |
There was a problem hiding this comment.
Use $this->fields instead of retriving everything
There was a problem hiding this comment.
Think about converting property accessor field to a elasticsearch field
| $hash = $link->getOuuid(); | ||
| $found = $this->findMediaFileByHash($link, $hash, $value); | ||
| if ($found && $this->force) { | ||
| $value = \str_replace($match[0], $found->jsonSerialize(), $value); |
| if ($found && $this->force) { | ||
| $value = \str_replace($match[0], $found->jsonSerialize(), $value); | ||
| } else { | ||
| $this->logAssetLink($key, EMSLink::fromMatch($match), $value); |
There was a problem hiding this comment.
What do you log? not found or not $this->force
|
|
||
| private function findMediaFileByHash(EMSLink $link, string $hash, mixed $value): ?EMSLink | ||
| { | ||
| $alias = $this->coreApi->meta()->getDefaultContentTypeEnvironmentAlias($this->mediaLibraryContentType); |
Command to convert ems file links (in wysiwyg fields) into ems object links (if the file already exists in a media library)