diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 7c1089a..a1a24ab 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -285,8 +285,8 @@ "name": "media_type_rel_dst", "type": "INT", "null": false, - "foreignTable": "type", - "foreignKey": "type_id" + "foreignTable": "media_type", + "foreignKey": "media_type_id" } } } diff --git a/Admin/Installer.php b/Admin/Installer.php index 80661e7..32ff088 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -116,7 +116,7 @@ final class Installer extends InstallerAbstract }; $apiApp->dbPool = $app->dbPool; - $apiApp->unitId = $app->unitId; + $apiApp->unitId = $app->unitId; $apiApp->accountManager = $app->accountManager; $apiApp->appSettings = $app->appSettings; $apiApp->moduleManager = $app->moduleManager; diff --git a/Controller/ApiController.php b/Controller/ApiController.php index c8c615e..c533afe 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -378,21 +378,36 @@ final class ApiController extends Controller return \phpOMS\Utils\Parser\Pdf\PdfParser::pdf2text($path/*, __DIR__ . '/../../../Tools/OCRImageOptimizer/bin/OCRImageOptimizerApp'*/); case 'doc': case 'docx': - if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) { + $include = \realpath(__DIR__ . '/../../../Resources/'); + if ($include === false) { + return ''; + } + + if (!Autoloader::inPaths($include)) { Autoloader::addPath($include); } return \phpOMS\Utils\Parser\Document\DocumentParser::parseDocument($path, $output); case 'ppt': case 'pptx': - if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) { + $include = \realpath(__DIR__ . '/../../../Resources/'); + if ($include === false) { + return ''; + } + + if (!Autoloader::inPaths($include)) { Autoloader::addPath($include); } return \phpOMS\Utils\Parser\Presentation\PresentationParser::parsePresentation($path, $output); case 'xls': case 'xlsx': - if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) { + $include = \realpath(__DIR__ . '/../../../Resources/'); + if ($include === false) { + return ''; + } + + if (!Autoloader::inPaths($include)) { Autoloader::addPath($include); } @@ -502,6 +517,19 @@ final class ApiController extends Controller return $media; } + /** + * Api method to create a reference. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ public function apiReferenceCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateReferenceCreate($request))) { @@ -518,6 +546,7 @@ final class ApiController extends Controller // create relation $parentCollectionId = (int) $request->getData('parent'); if ($parentCollectionId === 0) { + /** @var Collection $parentCollection */ $parentCollection = CollectionMapper::get() ->where('virtualPath', (string) ($request->getData('virtualpath') ?? '')) ->where('name', (string) ($request->getData('name') ?? '')) @@ -532,7 +561,7 @@ final class ApiController extends Controller } /** - * Method to create collection from request. + * Method to create a reference from request. * * @param RequestAbstract $request Request * @@ -542,7 +571,7 @@ final class ApiController extends Controller */ private function createReferenceFromRequest(RequestAbstract $request) : Reference { - $mediaReference = new Reference(); + $mediaReference = new Reference(); $mediaReference->name = (string) $request->getData('name'); $mediaReference->source = new NullMedia((int) $request->getData('source')); $mediaReference->createdBy = new NullAccount($request->header->account); @@ -552,7 +581,7 @@ final class ApiController extends Controller } /** - * Validate collection create request + * Validate reference create request * * @param RequestAbstract $request Request * diff --git a/Models/CollectionMapper.php b/Models/CollectionMapper.php index 503f75c..abb151b 100755 --- a/Models/CollectionMapper.php +++ b/Models/CollectionMapper.php @@ -30,7 +30,7 @@ final class CollectionMapper extends MediaMapper /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ @@ -45,7 +45,7 @@ final class CollectionMapper extends MediaMapper /** * Model to use by the mapper. * - * @var string + * @var class-string * @since 1.0.0 */ public const MODEL = Collection::class; diff --git a/Models/Media.php b/Models/Media.php index b09596b..255582a 100755 --- a/Models/Media.php +++ b/Models/Media.php @@ -290,9 +290,16 @@ class Media implements \JsonSerializable return $this->nonce !== null; } + /** + * Has password defined + * + * @return bool + * + * @since 1.0.0 + */ public function hasPassword() : bool { - return !empty($password); + return !empty($this->password); } /** @@ -463,6 +470,60 @@ class Media implements \JsonSerializable return $this->types[$id] ?? new NullMediaType(); } + /** + * Get media type by name + * + * @param string $name Type name + * + * @return MediaType + * + * @since 1.0.0 + */ + public function getMediaTypeName(string $name) : MediaType + { + foreach ($this->types as $type) { + if ($type->name === $name) { + return $type; + } + } + + return new NullMediaType(); + } + + /** + * Has media type by id + * + * @param int $id Media type id + * + * @return bool + * + * @since 1.0.0 + */ + public function hasMediaTypeId(int $id) : bool + { + return isset($this->types[$id]); + } + + /** + * Has media type by name + * + * @param string $name Media type name + * + * @return bool + * + * @since 1.0.0 + */ + public function hasMediaTypeName(string $name) : bool + { + foreach ($this->types as $type) { + if ($type->name === $name) { + return true; + } + } + + return false; + } + /** * Adding new tag. * diff --git a/Models/MediaContentMapper.php b/Models/MediaContentMapper.php index c8d73f0..b871ba0 100755 --- a/Models/MediaContentMapper.php +++ b/Models/MediaContentMapper.php @@ -40,7 +40,7 @@ class MediaContentMapper extends DataMapperFactory /** * Model to use by the mapper. * - * @var string + * @var class-string * @since 1.0.0 */ public const MODEL = MediaContent::class; diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index f7d584e..7e4e3a6 100755 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -62,7 +62,7 @@ class MediaMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ @@ -75,7 +75,7 @@ class MediaMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const OWNS_ONE = [ @@ -96,7 +96,7 @@ class MediaMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ @@ -117,7 +117,7 @@ class MediaMapper extends DataMapperFactory /** * Model to use by the mapper. * - * @var string + * @var class-string * @since 1.0.0 */ public const MODEL = Media::class; diff --git a/Models/MediaTypeL11nMapper.php b/Models/MediaTypeL11nMapper.php index 5b68c01..f9bd731 100755 --- a/Models/MediaTypeL11nMapper.php +++ b/Models/MediaTypeL11nMapper.php @@ -59,7 +59,7 @@ final class MediaTypeL11nMapper extends DataMapperFactory /** * Model to use by the mapper. * - * @var string + * @var class-string * @since 1.0.0 */ public const MODEL = BaseStringL11n::class; diff --git a/Models/MediaTypeMapper.php b/Models/MediaTypeMapper.php index 0c62db7..a2acca0 100755 --- a/Models/MediaTypeMapper.php +++ b/Models/MediaTypeMapper.php @@ -41,7 +41,7 @@ final class MediaTypeMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ @@ -57,7 +57,7 @@ final class MediaTypeMapper extends DataMapperFactory /** * Model to use by the mapper. * - * @var string + * @var class-string * @since 1.0.0 */ public const MODEL = MediaType::class; diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 15b7090..090235b 100755 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -115,6 +115,10 @@ class UploadFile $fCounter = -1; foreach ($files as $key => $f) { + if (!isset($f['name'], $f['tmp_name'], $f['size'])) { + return []; + } + ++$fCounter; $path = $this->outputDir; diff --git a/Theme/Backend/Lang/api.de.lang.php b/Theme/Backend/Lang/api.de.lang.php new file mode 100755 index 0000000..038fdb9 --- /dev/null +++ b/Theme/Backend/Lang/api.de.lang.php @@ -0,0 +1,16 @@ + [ +]]; diff --git a/tests/Controller/Api/ApiControllerMediaTrait.php b/tests/Controller/Api/ApiControllerMediaTrait.php index 7a6f24a..e2b3e1e 100755 --- a/tests/Controller/Api/ApiControllerMediaTrait.php +++ b/tests/Controller/Api/ApiControllerMediaTrait.php @@ -186,7 +186,13 @@ trait ApiControllerMediaTrait { self::assertEquals( [], - $this->module->uploadFiles(['test'], ['test'], ['test'], 1, '/test', '', null, '', '', 99) + $this->module->uploadFiles( + names: ['test'], + fileNames: ['test'], + files: ['test'], + account: 1, + basePath: '/test', + ) ); }