PHRAS-3717 Wrong extension on subdef upload w. adapt=0 (#4107)

* fix substitute adapt 0

* fix path file dest
This commit is contained in:
Aina Sitraka
2022-07-29 17:04:20 +03:00
committed by GitHub
parent 8efdc36efa
commit ee8029a456
2 changed files with 8 additions and 7 deletions

View File

@@ -99,18 +99,20 @@ class FilesystemService
* @param \record_adapter $record * @param \record_adapter $record
* @param \databox_subdef $subdef * @param \databox_subdef $subdef
* @param string $marker * @param string $marker
* @param string $extension if not set,get from subdef spec
* @return string * @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()); $pathdest = $this->directorySpread($subdef->get_path());
return $pathdest . $this->generateSubdefFilename($record, $subdef, '0_'); return $pathdest . $this->generateSubdefFilename($record, $subdef, '0_', $extension);
} }
/** /**

View File

@@ -102,15 +102,13 @@ class SubdefSubstituer
$databox_subdef = $record->getDatabox()->get_subdef_structure()->get_subdef($type, $name); $databox_subdef = $record->getDatabox()->get_subdef_structure()->get_subdef($type, $name);
if ($this->isOldSubdefPresent($record, $name)) { if ($this->isOldSubdefPresent($record, $name)) {
$path_file_dest = $record->get_subdef($name)->getRealPath();
$record->get_subdef($name)->remove_file(); $record->get_subdef($name)->remove_file();
$record->clearSubdefCache($name); $record->clearSubdefCache($name);
} else {
$path_file_dest = $this->fs->generateSubdefSubstitutionPathname($record, $databox_subdef);
} }
if($adapt) { if($adapt) {
try { try {
$path_file_dest = $this->fs->generateSubdefSubstitutionPathname($record, $databox_subdef);
$this->alchemyst->turnInto( $this->alchemyst->turnInto(
$media->getFile()->getRealPath(), $media->getFile()->getRealPath(),
$path_file_dest, $path_file_dest,
@@ -120,6 +118,7 @@ class SubdefSubstituer
return; return;
} }
} else { } 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); $this->fs->copy($media->getFile()->getRealPath(), $path_file_dest);
} }