mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-01-11 17:08:40 +00:00
phpstan, phpcs, phpunit fixes
This commit is contained in:
parent
15d381a423
commit
d4e46af1c7
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ final class CollectionMapper extends MediaMapper
|
|||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class MediaMapper extends DataMapperFactory
|
|||
/**
|
||||
* Belongs to.
|
||||
*
|
||||
* @var array<string, array{mapper:string, external:string, column?:string, by?:string}>
|
||||
* @var array<string, array{mapper:class-string, external:string, column?:string, by?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const BELONGS_TO = [
|
||||
|
|
@ -75,7 +75,7 @@ class MediaMapper extends DataMapperFactory
|
|||
/**
|
||||
* Belongs to.
|
||||
*
|
||||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const OWNS_ONE = [
|
||||
|
|
@ -96,7 +96,7 @@ class MediaMapper extends DataMapperFactory
|
|||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ final class MediaTypeMapper extends DataMapperFactory
|
|||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
16
Theme/Backend/Lang/api.de.lang.php
Executable file
16
Theme/Backend/Lang/api.de.lang.php
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Media
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return ['Media' => [
|
||||
]];
|
||||
|
|
@ -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',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user