From a37ffe28b5dacbaf9b55da588e183c177f421abd Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 6 Nov 2020 01:46:52 +0100 Subject: [PATCH 1/5] Add width/height --- src/FileStorage/DataTransformer.php | 2 +- src/Model/Behavior/FileStorageBehavior.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/FileStorage/DataTransformer.php b/src/FileStorage/DataTransformer.php index 943de9c..d19c018 100644 --- a/src/FileStorage/DataTransformer.php +++ b/src/FileStorage/DataTransformer.php @@ -73,7 +73,7 @@ public function entityToFileObject(EntityInterface $entity): FileInterface public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity): EntityInterface { $data = [ - 'id' => $file->uuid(), + 'id' => $file->uuid(), //FIXME 'model' => $file->model(), 'foreign_key' => $file->modelId(), 'filesize' => $file->filesize(), diff --git a/src/Model/Behavior/FileStorageBehavior.php b/src/Model/Behavior/FileStorageBehavior.php index 4f95446..4a3cc0d 100644 --- a/src/Model/Behavior/FileStorageBehavior.php +++ b/src/Model/Behavior/FileStorageBehavior.php @@ -36,9 +36,9 @@ class FileStorageBehavior extends Behavior protected FileStorage $fileStorage; /** - * @var \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface + * @var \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface|null */ - protected ?ProcessorInterface $imageProcessor; + protected $imageProcessor; /** * @var \Burzum\FileStorage\FileStorage\DataTransformerInterface @@ -219,7 +219,7 @@ protected function checkEntityBeforeSave(EntityInterface $entity) { if ($entity->isNew()) { if (!$entity->has('model')) { - $entity->set('model', $this->getTable()->getTable()); + $entity->set('model', $this->getTable()->getAlias()); } if (!$entity->has('adapter')) { @@ -338,12 +338,15 @@ public function processImages(FileInterface $file, EntityInterface $entity): Fil $model = $file->model(); $identifier = $entity->get('identifier'); + $model = 'Events'; //FIXME + $identifier = 'EventImages'; //FIXME + if (!isset($imageSizes[$model][$identifier])) { return $file; } $file = $file->withVariants($imageSizes[$model][$identifier]); - $file = $this->imageProcessor->process($file); + $file = $this->getImageProcessor()->process($file); return $file; } From 10e1fe0f21647c7c141b2cfe6d6c93dab31a1f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 11 Nov 2020 00:16:49 +0100 Subject: [PATCH 2/5] Adding the FileAssociationBehavior.php --- .../Behavior/FileAssociationBehavior.php | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/Model/Behavior/FileAssociationBehavior.php diff --git a/src/Model/Behavior/FileAssociationBehavior.php b/src/Model/Behavior/FileAssociationBehavior.php new file mode 100644 index 0000000..995aeef --- /dev/null +++ b/src/Model/Behavior/FileAssociationBehavior.php @@ -0,0 +1,114 @@ + [] + ]; + + /** + * @inheritdoc + */ + public function initialize(array $config): void + { + $class = get_class($this->getTable()); + foreach ($config['associations'] as $association => &$assocConfig) { + $defaults = [ + 'overrideable' => false, + 'model' => substr($class, strrpos($class, '\\') + 1), + 'property' => $this->getTable()->getAssociation($association)->getProperty() + ]; + + $assoConfig += $assoConfig; + } + + parent::initialize($config); + } + + /** + * @param \Cake\Event\EventInterface $event + * @param \App\Model\Entity\Event $entity + * @param \ArrayObject $options + * + * @return void + */ + public function afterSave( + EventInterface $event, + EntityInterface $entity, + ArrayObject $options + ): void { + $associations = $this->getConfig('assocations'); + + foreach ($associations as $association => $assocConfig) { + $property = $assocConfig['property']; + if ($entity->{$property} === null) { + continue; + } + + if ($entity->id && $entity->{$property} && $entity->{$property}->file->getError() === UPLOAD_ERR_OK) { + if ($assocConfig['overrideable'] === true) { + $this->findAndRemovePreviousFile($entity, $association, $assocConfig); + } + + $entity->{$property}->set('collection', $assocConfig['collection']); + $entity->{$property}->set('model', $assocConfig['model']); + $entity->{$property}->set('foreign_key', $entity->id); + + $this->{$association}->saveOrFail($entity->{$property}); + } + } + } + + /** + * @param \Cake\Event\EventInterface $event + * @param string $association + * @param array $assocConfig + * @return void + */ + protected function findAndRemovePreviousFile( + EntityInterface $entity, + string $association, + array $assocConfig + ): void { + $result = $this->{$association}->find() + ->where([ + 'collection' => $assocConfig['collection'], + 'model' => $assocConfig['model'], + 'foreign_key' => $entity->get((string)$this->getTable()->getPrimaryKey()) + ]); + + if ($result) { + $this->{$association}->delete($result); + } + } +} From 7f5da42966edb7c55328595877a37afc5a038805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 11 Nov 2020 01:24:13 +0100 Subject: [PATCH 3/5] Refactoring information gathering for uploaded records --- .../20201110234846_AddCollectionColumn.php | 21 +++++++++++++ .../Behavior/FileAssociationBehavior.php | 30 +++++++++++-------- src/Model/Behavior/FileStorageBehavior.php | 9 ++---- tests/Fixture/FileStorageFixture.php | 3 +- 4 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 config/Migrations/20201110234846_AddCollectionColumn.php diff --git a/config/Migrations/20201110234846_AddCollectionColumn.php b/config/Migrations/20201110234846_AddCollectionColumn.php new file mode 100644 index 0000000..2edca26 --- /dev/null +++ b/config/Migrations/20201110234846_AddCollectionColumn.php @@ -0,0 +1,21 @@ +table('file_storage') + ->addColumn('collection', 'string', ['length' => 128, 'null' => true, 'default' => null]) + ->update(); + } +} diff --git a/src/Model/Behavior/FileAssociationBehavior.php b/src/Model/Behavior/FileAssociationBehavior.php index 995aeef..ef8afa0 100644 --- a/src/Model/Behavior/FileAssociationBehavior.php +++ b/src/Model/Behavior/FileAssociationBehavior.php @@ -12,6 +12,7 @@ use Cake\Datasource\EntityInterface; use Cake\Event\EventDispatcherTrait; use Cake\Event\EventInterface; +use Cake\ORM\Association\HasOne; use Cake\ORM\Behavior; use League\Flysystem\AdapterInterface; use Phauthentic\Infrastructure\Storage\FileInterface; @@ -41,18 +42,22 @@ class FileAssociationBehavior extends Behavior */ public function initialize(array $config): void { + parent::initialize($config); + $class = get_class($this->getTable()); - foreach ($config['associations'] as $association => &$assocConfig) { + foreach ($config['associations'] as $association => $assocConfig) { + $associationObject = $this->getTable()->getAssociation($association); + $defaults = [ - 'overrideable' => false, - 'model' => substr($class, strrpos($class, '\\') + 1), + 'replace' => $associationObject instanceof HasOne, + 'model' => substr($class, strrpos($class, '\\') + 1, -5), 'property' => $this->getTable()->getAssociation($association)->getProperty() ]; - $assoConfig += $assoConfig; + $config['associations'][$association] = $assocConfig += $defaults; } - parent::initialize($config); + $this->setConfig('associations', $config['associations']); } /** @@ -62,12 +67,12 @@ public function initialize(array $config): void * * @return void */ - public function afterSave( + public function beforeSave( EventInterface $event, EntityInterface $entity, ArrayObject $options ): void { - $associations = $this->getConfig('assocations'); + $associations = $this->getConfig('associations'); foreach ($associations as $association => $assocConfig) { $property = $assocConfig['property']; @@ -76,15 +81,13 @@ public function afterSave( } if ($entity->id && $entity->{$property} && $entity->{$property}->file->getError() === UPLOAD_ERR_OK) { - if ($assocConfig['overrideable'] === true) { + if ($assocConfig['replace'] === true) { $this->findAndRemovePreviousFile($entity, $association, $assocConfig); } $entity->{$property}->set('collection', $assocConfig['collection']); $entity->{$property}->set('model', $assocConfig['model']); $entity->{$property}->set('foreign_key', $entity->id); - - $this->{$association}->saveOrFail($entity->{$property}); } } } @@ -100,15 +103,16 @@ protected function findAndRemovePreviousFile( string $association, array $assocConfig ): void { - $result = $this->{$association}->find() + $result = $this->getTable()->{$association}->find() ->where([ 'collection' => $assocConfig['collection'], 'model' => $assocConfig['model'], 'foreign_key' => $entity->get((string)$this->getTable()->getPrimaryKey()) - ]); + ]) + ->first(); if ($result) { - $this->{$association}->delete($result); + $this->getTable()->{$association}->delete($result); } } } diff --git a/src/Model/Behavior/FileStorageBehavior.php b/src/Model/Behavior/FileStorageBehavior.php index 4a3cc0d..829d1cf 100644 --- a/src/Model/Behavior/FileStorageBehavior.php +++ b/src/Model/Behavior/FileStorageBehavior.php @@ -336,16 +336,13 @@ public function processImages(FileInterface $file, EntityInterface $entity): Fil { $imageSizes = Configure::read('FileStorage.imageVariants'); $model = $file->model(); - $identifier = $entity->get('identifier'); + $collection = $entity->get('collection'); - $model = 'Events'; //FIXME - $identifier = 'EventImages'; //FIXME - - if (!isset($imageSizes[$model][$identifier])) { + if (!isset($imageSizes[$model][$collection])) { return $file; } - $file = $file->withVariants($imageSizes[$model][$identifier]); + $file = $file->withVariants($imageSizes[$model][$collection]); $file = $this->getImageProcessor()->process($file); return $file; diff --git a/tests/Fixture/FileStorageFixture.php b/tests/Fixture/FileStorageFixture.php index b72d5a6..60b5d6e 100644 --- a/tests/Fixture/FileStorageFixture.php +++ b/tests/Fixture/FileStorageFixture.php @@ -32,13 +32,14 @@ class FileStorageFixture extends TestFixture 'user_id' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 36], 'foreign_key' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 36], 'model' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 64], + 'collection' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 128], 'filename' => ['type' => 'string', 'null' => false, 'default' => null], 'filesize' => ['type' => 'integer', 'null' => true, 'default' => null, 'length' => 16], 'mime_type' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 32], 'extension' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 32], 'hash' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 64], 'path' => ['type' => 'string', 'null' => true, 'default' => null], - 'adapter' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 32, 'comment' => 'Gaufrette Storage Adapter Class'], + 'adapter' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 32], 'variants' => ['type' => 'json', 'null' => true, 'default' => null], 'metadata' => ['type' => 'json', 'null' => true, 'default' => null], 'created' => ['type' => 'datetime', 'null' => true, 'default' => null], From 4f2f186504e0b72c2ab332cd7ac468fcbfa251ec Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 12 Nov 2020 02:38:34 +0100 Subject: [PATCH 4/5] Move image to file processing stack --- .../Behavior/FileAssociationBehavior.php | 5 +- src/Model/Behavior/FileStorageBehavior.php | 47 +++++++++---------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/Model/Behavior/FileAssociationBehavior.php b/src/Model/Behavior/FileAssociationBehavior.php index ef8afa0..30a3dc9 100644 --- a/src/Model/Behavior/FileAssociationBehavior.php +++ b/src/Model/Behavior/FileAssociationBehavior.php @@ -82,7 +82,7 @@ public function beforeSave( if ($entity->id && $entity->{$property} && $entity->{$property}->file->getError() === UPLOAD_ERR_OK) { if ($assocConfig['replace'] === true) { - $this->findAndRemovePreviousFile($entity, $association, $assocConfig); + //$this->findAndRemovePreviousFile($entity, $association, $assocConfig); } $entity->{$property}->set('collection', $assocConfig['collection']); @@ -107,7 +107,8 @@ protected function findAndRemovePreviousFile( ->where([ 'collection' => $assocConfig['collection'], 'model' => $assocConfig['model'], - 'foreign_key' => $entity->get((string)$this->getTable()->getPrimaryKey()) + 'foreign_key' => $entity->get((string)$this->getTable()->getPrimaryKey()), + 'id !=' => $entity->get($assocConfig['property'])->get($this->getTable()->{$association}->getPrimaryKey()) ]) ->first(); diff --git a/src/Model/Behavior/FileStorageBehavior.php b/src/Model/Behavior/FileStorageBehavior.php index 829d1cf..1ba9bf3 100644 --- a/src/Model/Behavior/FileStorageBehavior.php +++ b/src/Model/Behavior/FileStorageBehavior.php @@ -33,17 +33,17 @@ class FileStorageBehavior extends Behavior /** * @var \Phauthentic\Infrastructure\Storage\FileStorage */ - protected FileStorage $fileStorage; + protected $fileStorage; /** - * @var \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface|null + * @var \Burzum\FileStorage\FileStorage\DataTransformerInterface */ - protected $imageProcessor; + protected $transformer; /** - * @var \Burzum\FileStorage\FileStorage\DataTransformerInterface + * @var \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface */ - protected DataTransformerInterface $transformer; + protected $processor; /** * Default config @@ -55,14 +55,9 @@ class FileStorageBehavior extends Behavior 'ignoreEmptyFile' => true, 'fileField' => 'file', 'fileStorage' => null, - 'imageProcessor' => null, + 'fileProcessor' => null, ]; - /** - * @var array - */ - protected array $processors = []; - /** * @inheritDoc * @@ -85,6 +80,8 @@ public function initialize(array $config): void $this->getTable() ); } + + $this->processors = (array)$this->getConfig('processors'); } /** @@ -184,11 +181,12 @@ public function afterSave(EventInterface $event, EntityInterface $entity, ArrayO try { $file = $this->entityToFileObject($entity); $file = $this->fileStorage->store($file); + + // TODO: move into stack processing $file = $this->processImages($file, $entity); - foreach ($this->processors as $processor) { - $file = $processor->process($file); - } + $processor = $this->getFileProcessor(); + $file = $processor->process($file); $entity = $this->fileObjectToEntity($file, $entity); $this->getTable()->save( @@ -285,7 +283,7 @@ protected function getFileInfoFromUpload(&$upload, $field = 'file') * * @return int Number of deleted records / files */ - public function deleteAllFiles($conditions) + public function deleteAllFiles(array $conditions) { $table = $this->getTable(); @@ -334,7 +332,7 @@ public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity */ public function processImages(FileInterface $file, EntityInterface $entity): FileInterface { - $imageSizes = Configure::read('FileStorage.imageVariants'); + $imageSizes = (array)Configure::read('FileStorage.imageVariants'); $model = $file->model(); $collection = $entity->get('collection'); @@ -343,7 +341,6 @@ public function processImages(FileInterface $file, EntityInterface $entity): Fil } $file = $file->withVariants($imageSizes[$model][$collection]); - $file = $this->getImageProcessor()->process($file); return $file; } @@ -353,20 +350,20 @@ public function processImages(FileInterface $file, EntityInterface $entity): Fil * * @return \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface */ - protected function getImageProcessor(): ProcessorInterface + protected function getFileProcessor(): ProcessorInterface { - if ($this->imageProcessor !== null) { - return $this->imageProcessor; + if ($this->processor !== null) { + return $this->processor; } - if ($this->getConfig('imageProcessor') instanceof ProcessorInterface) { - $this->imageProcessor = $this->getConfig('imageProcessor'); + if ($this->getConfig('fileProcessor') instanceof ProcessorInterface) { + $this->processor = $this->getConfig('fileProcessor'); } - if ($this->imageProcessor === null) { - throw new RuntimeException('No image processor found'); + if ($this->processor === null) { + throw new RuntimeException('No processor found'); } - return $this->imageProcessor; + return $this->processor; } } From 5ecb05b7231fe19bca61dbe7a829a265a0465050 Mon Sep 17 00:00:00 2001 From: mscherer Date: Sun, 15 Nov 2020 17:27:15 +0100 Subject: [PATCH 5/5] Fix upload for edit mode. --- phpcs.xml | 4 +- phpstan.neon | 4 +- .../Behavior/FileAssociationBehavior.php | 51 +++++++++++-------- src/Model/Behavior/FileStorageBehavior.php | 4 +- src/Model/Entity/FileStorage.php | 18 +++++++ src/Model/Table/FileStorageTable.php | 16 ++++++ src/Shell/ImageVersionShell.php | 5 +- src/View/Helper/ImageHelper.php | 2 +- 8 files changed, 75 insertions(+), 29 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 260755e..61f0a9a 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -10,12 +10,12 @@ - + - + diff --git a/phpstan.neon b/phpstan.neon index bd7887a..02e6eb7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false bootstrapFiles: @@ -7,3 +7,5 @@ parameters: earlyTerminatingMethodCalls: Cake\Console\Shell: - abort + ignoreErrors: + - '#Cannot cast array\\|string to string#' diff --git a/src/Model/Behavior/FileAssociationBehavior.php b/src/Model/Behavior/FileAssociationBehavior.php index 30a3dc9..aaf7531 100644 --- a/src/Model/Behavior/FileAssociationBehavior.php +++ b/src/Model/Behavior/FileAssociationBehavior.php @@ -4,22 +4,12 @@ namespace Burzum\FileStorage\Model\Behavior; -use App\Storage\Identifiers; use ArrayObject; -use Burzum\FileStorage\FileStorage\DataTransformer; -use Burzum\FileStorage\FileStorage\DataTransformerInterface; -use Cake\Core\Configure; use Cake\Datasource\EntityInterface; -use Cake\Event\EventDispatcherTrait; use Cake\Event\EventInterface; use Cake\ORM\Association\HasOne; use Cake\ORM\Behavior; -use League\Flysystem\AdapterInterface; -use Phauthentic\Infrastructure\Storage\FileInterface; -use Phauthentic\Infrastructure\Storage\FileStorage; -use Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface; -use RuntimeException; -use Throwable; +use Laminas\Diactoros\UploadedFile; /** * File Association Behavior. @@ -31,14 +21,15 @@ class FileAssociationBehavior extends Behavior { /** - * @inheritdoc + * @var array + * @inheritDoc */ protected $_defaultConfig = [ - 'associations' => [] + 'associations' => [], ]; /** - * @inheritdoc + * @inheritDoc */ public function initialize(array $config): void { @@ -51,10 +42,10 @@ public function initialize(array $config): void $defaults = [ 'replace' => $associationObject instanceof HasOne, 'model' => substr($class, strrpos($class, '\\') + 1, -5), - 'property' => $this->getTable()->getAssociation($association)->getProperty() + 'property' => $this->getTable()->getAssociation($association)->getProperty(), ]; - $config['associations'][$association] = $assocConfig += $defaults; + $config['associations'][$association] = $assocConfig + $defaults; } $this->setConfig('associations', $config['associations']); @@ -62,12 +53,12 @@ public function initialize(array $config): void /** * @param \Cake\Event\EventInterface $event - * @param \App\Model\Entity\Event $entity + * @param \Cake\Datasource\EntityInterface $entity * @param \ArrayObject $options * * @return void */ - public function beforeSave( + public function afterSave( EventInterface $event, EntityInterface $entity, ArrayObject $options @@ -80,22 +71,38 @@ public function beforeSave( continue; } - if ($entity->id && $entity->{$property} && $entity->{$property}->file->getError() === UPLOAD_ERR_OK) { + if ($entity->id && $entity->{$property} && $entity->{$property}->file) { + $file = $entity->{$property}->file; + + $ok = false; + if (is_array($file) && $file['error'] === UPLOAD_ERR_OK) { + $ok = true; + } elseif ($file instanceof UploadedFile && $file->getError() === UPLOAD_ERR_OK) { + $ok = true; + } + + if (!$ok) { + continue; + } + if ($assocConfig['replace'] === true) { - //$this->findAndRemovePreviousFile($entity, $association, $assocConfig); + $this->findAndRemovePreviousFile($entity, $association, $assocConfig); } $entity->{$property}->set('collection', $assocConfig['collection']); $entity->{$property}->set('model', $assocConfig['model']); $entity->{$property}->set('foreign_key', $entity->id); + + $this->getTable()->{$association}->saveOrFail($entity->{$property}); } } } /** - * @param \Cake\Event\EventInterface $event + * @param \Cake\Datasource\EntityInterface $entity * @param string $association * @param array $assocConfig + * * @return void */ protected function findAndRemovePreviousFile( @@ -108,7 +115,7 @@ protected function findAndRemovePreviousFile( 'collection' => $assocConfig['collection'], 'model' => $assocConfig['model'], 'foreign_key' => $entity->get((string)$this->getTable()->getPrimaryKey()), - 'id !=' => $entity->get($assocConfig['property'])->get($this->getTable()->{$association}->getPrimaryKey()) + 'id !=' => $entity->get($assocConfig['property'])->get((string)$this->getTable()->{$association}->getPrimaryKey()), ]) ->first(); diff --git a/src/Model/Behavior/FileStorageBehavior.php b/src/Model/Behavior/FileStorageBehavior.php index 1ba9bf3..190fb93 100644 --- a/src/Model/Behavior/FileStorageBehavior.php +++ b/src/Model/Behavior/FileStorageBehavior.php @@ -81,7 +81,7 @@ public function initialize(array $config): void ); } - $this->processors = (array)$this->getConfig('processors'); + //$this->processors = (array)$this->getConfig('processors'); } /** @@ -264,7 +264,7 @@ protected function getFileInfoFromUpload(&$upload, $field = 'file') if (!is_array($uploadedFile)) { $upload['filesize'] = $uploadedFile->getSize(); $upload['mime_type'] = $uploadedFile->getClientMediaType(); - $upload['extension'] = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION); + $upload['extension'] = pathinfo((string)$uploadedFile->getClientFilename(), PATHINFO_EXTENSION); $upload['filename'] = $uploadedFile->getClientFilename(); } else { $upload['filesize'] = $uploadedFile['size']; diff --git a/src/Model/Entity/FileStorage.php b/src/Model/Entity/FileStorage.php index 4913d8a..1b063c0 100644 --- a/src/Model/Entity/FileStorage.php +++ b/src/Model/Entity/FileStorage.php @@ -12,6 +12,24 @@ * @author Florian Krämer * @copyright 2012 - 2020 Florian Krämer * @license MIT + * + * @property array $variants + * @property array $metadata + * @property int $id + * @property int|null $user_id + * @property int|null $foreign_key + * @property string|null $model + * @property string|null $filename + * @property int|null $filesize + * @property string|null $mime_type + * @property string|null $extension + * @property string|null $hash + * @property string|null $path + * @property string|null $adapter + * @property \Cake\I18n\FrozenTime $created + * @property \Cake\I18n\FrozenTime $modified + * @property string|null $collection + * @property array $variant_urls */ class FileStorage extends Entity implements FileStorageEntityInterface { diff --git a/src/Model/Table/FileStorageTable.php b/src/Model/Table/FileStorageTable.php index 9aa7ced..95e357b 100644 --- a/src/Model/Table/FileStorageTable.php +++ b/src/Model/Table/FileStorageTable.php @@ -25,6 +25,22 @@ * @author Florian Krämer * @copyright 2012 - 2020 Florian Krämer * @license MIT + * + * @method \Burzum\FileStorage\Model\Entity\FileStorage newEmptyEntity() + * @method \Burzum\FileStorage\Model\Entity\FileStorage newEntity(array $data, array $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage[] newEntities(array $data, array $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage get($primaryKey, $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage findOrCreate($search, ?callable $callback = null, $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage[] patchEntities(iterable $entities, array $data, array $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage|false save(\Cake\Datasource\EntityInterface $entity, $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, $options = []) + * @method \Burzum\FileStorage\Model\Entity\FileStorage[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, $options = []) + * @mixin \Cake\ORM\Behavior\TimestampBehavior + * @mixin \Burzum\FileStorage\Model\Behavior\FileStorageBehavior */ class FileStorageTable extends Table { diff --git a/src/Shell/ImageVersionShell.php b/src/Shell/ImageVersionShell.php index 53fbd6f..2f6a0eb 100644 --- a/src/Shell/ImageVersionShell.php +++ b/src/Shell/ImageVersionShell.php @@ -25,7 +25,7 @@ class ImageVersionShell extends Shell /** * Storage Table Object * - * @var \Cake\ORM\Table|null + * @var \Cake\ORM\Table */ public $Table; @@ -200,6 +200,9 @@ public function regenerate(): void foreach ($operations as $version => $operation) { try { + if ($this->command === null) { + $this->abort('No command given'); + } $this->_loop($this->command, $this->args[0], [$version => $operation], $options); } catch (Exception $e) { $this->abort($e->getMessage()); diff --git a/src/View/Helper/ImageHelper.php b/src/View/Helper/ImageHelper.php index e1f36f5..0ac05d6 100644 --- a/src/View/Helper/ImageHelper.php +++ b/src/View/Helper/ImageHelper.php @@ -88,7 +88,7 @@ public function imageUrl(FileStorageEntityInterface $image, ?string $variant = n } if (!$path) { - throw VariantDoesNotExistException::withName($variant); + throw VariantDoesNotExistException::withName((string)$variant); } $options = array_merge($this->getConfig(), $options);