Skip to content

Commit

Permalink
D3Files component - copyFilesBetweenModels bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
anothersoftware-lv committed Apr 29, 2021
1 parent f538772 commit b1fd461
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions components/D3Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ public static function uploadModelFile(ActiveRecord $model, string $className,
*/
public static function copyFilesBetweenModels(ActiveRecord $modelFrom, ActiveRecord $modelTo, ?string $modelFromClass = null)
{
$modelName = $modelFromClass ?? get_class($modelFrom);
$modelFromName = $modelFromClass ?? get_class($modelFrom);
$modelToName = get_class($modelTo);

$modelFiles = ModelD3Files::getRecordFilesList($modelName, $modelFrom->id);
$modelFiles = ModelD3Files::getRecordFilesList($modelFromName, $modelFrom->id);

foreach ($modelFiles as $file) {

Expand All @@ -212,14 +213,14 @@ public static function copyFilesBetweenModels(ActiveRecord $modelFrom, ActiveRec

$ext = pathinfo($file['file_name'], PATHINFO_EXTENSION);

$fileTypes = self::getAllowedFileTypes($modelName);
$fileTypes = self::getAllowedFileTypes($modelToName);
if (!preg_match($fileTypes, $ext)) {
continue;
}

ModelD3Files::saveContent(
$file['file_name'],
$modelName,
$modelToName,
$modelTo->id,
$fileContent,
$fileTypes
Expand Down

0 comments on commit b1fd461

Please sign in to comment.