From ee8029a456fd5e1175d7d39683750bd1c33ac29c Mon Sep 17 00:00:00 2001 From: Aina Sitraka <35221835+aynsix@users.noreply.github.com> Date: Fri, 29 Jul 2022 17:04:20 +0300 Subject: [PATCH] PHRAS-3717 Wrong extension on subdef upload w. adapt=0 (#4107) * fix substitute adapt 0 * fix path file dest --- lib/Alchemy/Phrasea/Filesystem/FilesystemService.php | 10 ++++++---- lib/Alchemy/Phrasea/Media/SubdefSubstituer.php | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php index ed6f8c01c9..764d07f4f3 100644 --- a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php +++ b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php @@ -99,18 +99,20 @@ class FilesystemService * @param \record_adapter $record * @param \databox_subdef $subdef * @param string $marker + * @param string $extension if not set,get from subdef spec * @return string */ - public function generateSubdefFilename(\record_adapter $record, \databox_subdef $subdef, $marker = '') + public function generateSubdefFilename(\record_adapter $record, \databox_subdef $subdef, $marker = '', $extension = null) { - return $record->getRecordId() . '_' . $marker . $subdef->get_name() . '.' . $this->getExtensionFromSpec($subdef->getSpecs()); + $extension = empty($extension) ? $this->getExtensionFromSpec($subdef->getSpecs()) : $extension; + return $record->getRecordId() . '_' . $marker . $subdef->get_name() . '.' . $extension; } - public function generateSubdefSubstitutionPathname(\record_adapter $record, \databox_subdef $subdef) + public function generateSubdefSubstitutionPathname(\record_adapter $record, \databox_subdef $subdef, $extension = null) { $pathdest = $this->directorySpread($subdef->get_path()); - return $pathdest . $this->generateSubdefFilename($record, $subdef, '0_'); + return $pathdest . $this->generateSubdefFilename($record, $subdef, '0_', $extension); } /** diff --git a/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php b/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php index 94ef31941d..2fd8f573da 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php +++ b/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php @@ -102,15 +102,13 @@ class SubdefSubstituer $databox_subdef = $record->getDatabox()->get_subdef_structure()->get_subdef($type, $name); if ($this->isOldSubdefPresent($record, $name)) { - $path_file_dest = $record->get_subdef($name)->getRealPath(); $record->get_subdef($name)->remove_file(); $record->clearSubdefCache($name); - } else { - $path_file_dest = $this->fs->generateSubdefSubstitutionPathname($record, $databox_subdef); } if($adapt) { try { + $path_file_dest = $this->fs->generateSubdefSubstitutionPathname($record, $databox_subdef); $this->alchemyst->turnInto( $media->getFile()->getRealPath(), $path_file_dest, @@ -120,6 +118,7 @@ class SubdefSubstituer return; } } else { + $path_file_dest = $this->fs->generateSubdefSubstitutionPathname($record, $databox_subdef, pathinfo($media->getFile()->getRealPath(), PATHINFO_EXTENSION)); $this->fs->copy($media->getFile()->getRealPath(), $path_file_dest); }