mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-01-29 17:18:39 +00:00
autofixes
This commit is contained in:
parent
249e2f65ad
commit
e8008ab855
|
|
@ -83,7 +83,7 @@ final class Installer extends InstallerAbstract
|
|||
*/
|
||||
private static function installMedia($dbPool, $data) : void
|
||||
{
|
||||
$collection = new Collection();
|
||||
$collection = new Collection();
|
||||
$collection->name = (string) $data['name'] ?? '';
|
||||
$collection->setVirtualPath((string) $data['virtualPath'] ?? '/');
|
||||
$collection->setPath((string) ($data['path'] ?? '/Modules/Media/Files/' . ((string) $data['name'] ?? '')));
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ use phpOMS\Message\NotificationLevel;
|
|||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
use phpOMS\System\File\FileUtils;
|
||||
use phpOMS\System\File\Local\Directory;
|
||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||
use phpOMS\System\File\FileUtils;
|
||||
|
||||
/**
|
||||
* Media class.
|
||||
|
|
@ -113,7 +113,7 @@ final class ApiController extends Controller
|
|||
* @param array $files Files
|
||||
* @param int $account Uploader
|
||||
* @param string $basePath Base path. The path which is used for the upload.
|
||||
* @param string $virtualPath Virtual path The path which is used to visually structure the files, like directories.
|
||||
* @param string $virtualPath virtual path The path which is used to visually structure the files, like directories
|
||||
* @param string $type Media type (internal/custom media categorization)
|
||||
* The file storage on the system can be different
|
||||
* @param string $password File password. The password to protect the file (only database)
|
||||
|
|
@ -241,8 +241,8 @@ final class ApiController extends Controller
|
|||
$media = new Media();
|
||||
|
||||
$media->setPath(self::normalizeDbPath($status['path']) . '/' . $status['filename']);
|
||||
$media->name = $status['name'];
|
||||
$media->size = $status['size'];
|
||||
$media->name = $status['name'];
|
||||
$media->size = $status['size'];
|
||||
$media->createdBy = new NullAccount($account);
|
||||
$media->extension = $status['extension'];
|
||||
$media->setVirtualPath($virtualPath);
|
||||
|
|
@ -315,8 +315,8 @@ final class ApiController extends Controller
|
|||
$id = (int) $request->getData('id');
|
||||
|
||||
/** @var Media $media */
|
||||
$media = MediaMapper::get($id);
|
||||
$media->name = (string) ($request->getData('name') ?? $media->name);
|
||||
$media = MediaMapper::get($id);
|
||||
$media->name = (string) ($request->getData('name') ?? $media->name);
|
||||
$media->description = (string) ($request->getData('description') ?? $media->description);
|
||||
$media->setPath((string) ($request->getData('path') ?? $media->getPath()));
|
||||
$media->setVirtualPath(\urldecode((string) ($request->getData('virtualpath') ?? $media->getVirtualPath())));
|
||||
|
|
@ -328,7 +328,7 @@ final class ApiController extends Controller
|
|||
) {
|
||||
$name = \explode('.', \basename($path));
|
||||
|
||||
$media->name = $name[0];
|
||||
$media->name = $name[0];
|
||||
$media->extension = $name[1] ?? '';
|
||||
$media->setVirtualPath(\dirname($path));
|
||||
$media->setPath('/Modules/Media/Files/' . \ltrim($path, '\\/'));
|
||||
|
|
@ -404,11 +404,11 @@ final class ApiController extends Controller
|
|||
*/
|
||||
private function createCollectionFromRequest(RequestAbstract $request) : Collection
|
||||
{
|
||||
$mediaCollection = new Collection();
|
||||
$mediaCollection->name = $request->getData('name') ?? '';
|
||||
$mediaCollection->description = ($description = Markdown::parse($request->getData('description') ?? ''));
|
||||
$mediaCollection = new Collection();
|
||||
$mediaCollection->name = $request->getData('name') ?? '';
|
||||
$mediaCollection->description = ($description = Markdown::parse($request->getData('description') ?? ''));
|
||||
$mediaCollection->descriptionRaw = $description;
|
||||
$mediaCollection->createdBy = new NullAccount($request->header->account);
|
||||
$mediaCollection->createdBy = new NullAccount($request->header->account);
|
||||
|
||||
$media = $request->getDataJson('media-list');
|
||||
foreach ($media as $file) {
|
||||
|
|
@ -459,11 +459,11 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
/* Create collection */
|
||||
$mediaCollection = new Collection();
|
||||
$mediaCollection->name = $name;
|
||||
$mediaCollection->description = Markdown::parse($description);
|
||||
$mediaCollection = new Collection();
|
||||
$mediaCollection->name = $name;
|
||||
$mediaCollection->description = Markdown::parse($description);
|
||||
$mediaCollection->descriptionRaw = $description;
|
||||
$mediaCollection->createdBy = new NullAccount($account);
|
||||
$mediaCollection->createdBy = new NullAccount($account);
|
||||
$mediaCollection->setSources($media);
|
||||
$mediaCollection->setVirtualPath('/');
|
||||
$mediaCollection->setPath('/Modules/Media/Files');
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ final class BackendController extends Controller
|
|||
$collection = CollectionMapper::getParentCollection($path);
|
||||
|
||||
if (\is_array($collection) && \is_dir(__DIR__ . '/../Files' . $path)) {
|
||||
$collection = new Collection();
|
||||
$collection = new Collection();
|
||||
$collection->name = \basename($path);
|
||||
$collection->setVirtualPath(\dirname($path));
|
||||
$collection->setPath(\dirname($path));
|
||||
|
|
@ -144,8 +144,8 @@ final class BackendController extends Controller
|
|||
|
||||
$pathinfo = \pathinfo($file);
|
||||
|
||||
$localMedia = new Media();
|
||||
$localMedia->name = $pathinfo['filename'];
|
||||
$localMedia = new Media();
|
||||
$localMedia->name = $pathinfo['filename'];
|
||||
$localMedia->extension = \is_dir($file) ? 'collection' : $pathinfo['extension'] ?? '';
|
||||
$localMedia->setVirtualPath($path);
|
||||
$localMedia->createdBy = new Account();
|
||||
|
|
@ -200,7 +200,7 @@ final class BackendController extends Controller
|
|||
) {
|
||||
$name = \explode('.', \basename($path));
|
||||
|
||||
$media->name = $name[0];
|
||||
$media->name = $name[0];
|
||||
$media->extension = $name[1] ?? '';
|
||||
$media->setVirtualPath(\dirname($path));
|
||||
$media->setPath('/Modules/Media/Files/' . \ltrim($path, '\\/'));
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Media\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use Modules\Admin\Models\Account;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -122,13 +122,13 @@ final class CollectionMapper extends MediaMapper
|
|||
*/
|
||||
public static function getCollectionsByPath(string $path, bool $showDirectories = false) : array
|
||||
{
|
||||
$collection = CollectionMapper::getByVirtualPath($path);
|
||||
$collection = self::getByVirtualPath($path);
|
||||
$parent = [];
|
||||
|
||||
if ($showDirectories) {
|
||||
$parent = CollectionMapper::getParentCollection($path);
|
||||
$parent = self::getParentCollection($path);
|
||||
if (\is_array($parent) && \is_dir(__DIR__ . '/../../Media/Files' . $path)) {
|
||||
$parent = new Collection();
|
||||
$parent = new Collection();
|
||||
$parent->name = \basename($path);
|
||||
$parent->setVirtualPath(\dirname($path));
|
||||
$parent->setPath(\dirname($path));
|
||||
|
|
@ -162,8 +162,8 @@ final class CollectionMapper extends MediaMapper
|
|||
|
||||
$pathinfo = \pathinfo($file);
|
||||
|
||||
$localMedia = new Collection();
|
||||
$localMedia->name = $pathinfo['filename'];
|
||||
$localMedia = new Collection();
|
||||
$localMedia->name = $pathinfo['filename'];
|
||||
$localMedia->extension = \is_dir($file) ? 'collection' : $pathinfo['extension'] ?? '';
|
||||
$localMedia->setVirtualPath($path);
|
||||
$localMedia->createdBy = new Account();
|
||||
|
|
|
|||
|
|
@ -35,23 +35,23 @@ class MediaMapper extends DataMapperAbstract
|
|||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
'media_id' => ['name' => 'media_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'media_name' => ['name' => 'media_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
||||
'media_type' => ['name' => 'media_type', 'type' => 'string', 'internal' => 'type'],
|
||||
'media_description' => ['name' => 'media_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true],
|
||||
'media_description_raw' => ['name' => 'media_description_raw', 'type' => 'string', 'internal' => 'descriptionRaw'],
|
||||
'media_versioned' => ['name' => 'media_versioned', 'type' => 'bool', 'internal' => 'isVersioned'],
|
||||
'media_hidden' => ['name' => 'media_hidden', 'type' => 'bool', 'internal' => 'isHidden'],
|
||||
'media_file' => ['name' => 'media_file', 'type' => 'string', 'internal' => 'path', 'autocomplete' => true],
|
||||
'media_virtual' => ['name' => 'media_virtual', 'type' => 'string', 'internal' => 'virtualPath', 'autocomplete' => true],
|
||||
'media_absolute' => ['name' => 'media_absolute', 'type' => 'bool', 'internal' => 'isAbsolute'],
|
||||
'media_nonce' => ['name' => 'media_nonce', 'type' => 'string', 'internal' => 'nonce'],
|
||||
'media_password' => ['name' => 'media_password', 'type' => 'string', 'internal' => 'password'],
|
||||
'media_extension' => ['name' => 'media_extension', 'type' => 'string', 'internal' => 'extension'],
|
||||
'media_size' => ['name' => 'media_size', 'type' => 'int', 'internal' => 'size'],
|
||||
'media_id' => ['name' => 'media_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'media_name' => ['name' => 'media_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
||||
'media_type' => ['name' => 'media_type', 'type' => 'string', 'internal' => 'type'],
|
||||
'media_description' => ['name' => 'media_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true],
|
||||
'media_description_raw' => ['name' => 'media_description_raw', 'type' => 'string', 'internal' => 'descriptionRaw'],
|
||||
'media_versioned' => ['name' => 'media_versioned', 'type' => 'bool', 'internal' => 'isVersioned'],
|
||||
'media_hidden' => ['name' => 'media_hidden', 'type' => 'bool', 'internal' => 'isHidden'],
|
||||
'media_file' => ['name' => 'media_file', 'type' => 'string', 'internal' => 'path', 'autocomplete' => true],
|
||||
'media_virtual' => ['name' => 'media_virtual', 'type' => 'string', 'internal' => 'virtualPath', 'autocomplete' => true],
|
||||
'media_absolute' => ['name' => 'media_absolute', 'type' => 'bool', 'internal' => 'isAbsolute'],
|
||||
'media_nonce' => ['name' => 'media_nonce', 'type' => 'string', 'internal' => 'nonce'],
|
||||
'media_password' => ['name' => 'media_password', 'type' => 'string', 'internal' => 'password'],
|
||||
'media_extension' => ['name' => 'media_extension', 'type' => 'string', 'internal' => 'extension'],
|
||||
'media_size' => ['name' => 'media_size', 'type' => 'int', 'internal' => 'size'],
|
||||
'media_collection' => ['name' => 'media_collection', 'type' => 'int', 'internal' => 'collection'],
|
||||
'media_created_by' => ['name' => 'media_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||
'media_created_at' => ['name' => 'media_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||
'media_created_by' => ['name' => 'media_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||
'media_created_at' => ['name' => 'media_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -134,15 +134,15 @@ trait ApiControllerCollectionTrait
|
|||
*/
|
||||
public function testApiCollectionFromMedia() : void
|
||||
{
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media->descriptionRaw = 'descRaw';
|
||||
$media->setPath('some/path');
|
||||
$media->size = 11;
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Media for collection';
|
||||
$id = MediaMapper::create($media);
|
||||
$media->name = 'Media for collection';
|
||||
$id = MediaMapper::create($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ class CollectionMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testCR() : void
|
||||
{
|
||||
$media = new Collection();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media = new Collection();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media->descriptionRaw = 'descRaw';
|
||||
$media->setPath('some/path');
|
||||
$media->size = 11;
|
||||
$media->name = 'Collection';
|
||||
$id = CollectionMapper::create($media);
|
||||
$id = CollectionMapper::create($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@ class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testCR() : void
|
||||
{
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media->descriptionRaw = 'descRaw';
|
||||
$media->setPath('some/path');
|
||||
$media->size = 11;
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Image';
|
||||
$id = MediaMapper::create($media);
|
||||
$media->name = 'Image';
|
||||
$id = MediaMapper::create($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
|
@ -62,15 +62,15 @@ class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testAbsolute() : void
|
||||
{
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media->setPath('https://avatars0.githubusercontent.com/u/16034994');
|
||||
$media->isAbsolute = true;
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Absolute path';
|
||||
$id = MediaMapper::create($media);
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Absolute path';
|
||||
$id = MediaMapper::create($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
|
@ -92,15 +92,15 @@ class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDirectoryMapping() : void
|
||||
{
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media->setPath(\realpath(__DIR__ . '/../../../../../'));
|
||||
$media->isAbsolute = true;
|
||||
$media->size = 11;
|
||||
$media->extension = 'collection';
|
||||
$media->name = 'Directory';
|
||||
$id = MediaMapper::create($media);
|
||||
$media->size = 11;
|
||||
$media->extension = 'collection';
|
||||
$media->name = 'Directory';
|
||||
$id = MediaMapper::create($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
|
@ -122,16 +122,16 @@ class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testGetVirtualPath() : void
|
||||
{
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media->setPath('https://avatars0.githubusercontent.com/u/16034994');
|
||||
$media->setVirtualPath('/mediamappertest/path');
|
||||
$media->isAbsolute = true;
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'With virtual path';
|
||||
$id = MediaMapper::create($media);
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'With virtual path';
|
||||
$id = MediaMapper::create($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
|
@ -154,29 +154,29 @@ class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testParentcollection() : void
|
||||
{
|
||||
$collection = new Collection();
|
||||
$collection->createdBy = new NullAccount(1);
|
||||
$collection->description = 'desc';
|
||||
$collection = new Collection();
|
||||
$collection->createdBy = new NullAccount(1);
|
||||
$collection->description = 'desc';
|
||||
$collection->descriptionRaw = 'descRaw';
|
||||
$collection->setPath('some/path');
|
||||
$collection->setVirtualPath('/virtual/path');
|
||||
$collection->size = 11;
|
||||
$collection->name = 'Collection';
|
||||
$idCollection = CollectionMapper::create($collection);
|
||||
$idCollection = CollectionMapper::create($collection);
|
||||
|
||||
self::assertGreaterThan(0, $collection->getId());
|
||||
self::assertEquals($idCollection, $collection->getId());
|
||||
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media = new Media();
|
||||
$media->createdBy = new NullAccount(1);
|
||||
$media->description = 'desc';
|
||||
$media->setPath('https://avatars0.githubusercontent.com/u/16034994');
|
||||
$media->setVirtualPath('/virtual/path/Collection');
|
||||
$media->isAbsolute = true;
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Absolute path';
|
||||
$idMedia = MediaMapper::create($media);
|
||||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Absolute path';
|
||||
$idMedia = MediaMapper::create($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($idMedia, $media->getId());
|
||||
|
|
|
|||
|
|
@ -196,12 +196,12 @@ class MediaTest extends \PHPUnit\Framework\TestCase
|
|||
$this->media->createdBy = $acc = new NullAccount(1);
|
||||
$this->media->extension = 'pdf';
|
||||
$this->media->setPath('/home/root');
|
||||
$this->media->isAbsolute = true;
|
||||
$this->media->name = 'Report';
|
||||
$this->media->description = 'This is a description';
|
||||
$this->media->isAbsolute = true;
|
||||
$this->media->name = 'Report';
|
||||
$this->media->description = 'This is a description';
|
||||
$this->media->descriptionRaw = 'This is a description raw';
|
||||
$this->media->size = 11;
|
||||
$this->media->isVersioned = true;
|
||||
$this->media->size = 11;
|
||||
$this->media->isVersioned = true;
|
||||
$this->media->setVirtualPath('/test/path');
|
||||
$this->media->isHidden = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class MediaViewTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$media->setPath(__DIR__);
|
||||
$media->isAbsolute = true;
|
||||
$media->extension = 'collection';
|
||||
$media->extension = 'collection';
|
||||
self::assertFalse(
|
||||
$method->invoke($this->view, $media, '/MediaViewTest.php')
|
||||
);
|
||||
|
|
@ -108,7 +108,7 @@ class MediaViewTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$media->setPath(__DIR__);
|
||||
$media->isAbsolute = true;
|
||||
$media->extension = 'collection';
|
||||
$media->extension = 'collection';
|
||||
self::assertTrue(
|
||||
$method->invoke($this->view, $media, '/something')
|
||||
);
|
||||
|
|
@ -194,7 +194,7 @@ class MediaViewTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
|
||||
$media->setPath(__DIR__ . '/test.jpg');
|
||||
$media->extension = 'jpg';
|
||||
$media->extension = 'jpg';
|
||||
$media->isAbsolute = true;
|
||||
self::assertTrue(
|
||||
$method->invoke($this->view, $media)
|
||||
|
|
@ -218,14 +218,14 @@ class MediaViewTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
|
||||
$media->setPath(__DIR__ . '/test.md');
|
||||
$media->extension = 'md';
|
||||
$media->extension = 'md';
|
||||
$media->isAbsolute = true;
|
||||
self::assertTrue(
|
||||
$method->invoke($this->view, $media)
|
||||
);
|
||||
|
||||
$media->setPath(__DIR__ . '/test.jpg');
|
||||
$media->extension = 'jpg';
|
||||
$media->extension = 'jpg';
|
||||
$media->isAbsolute = true;
|
||||
self::assertTrue(
|
||||
$method->invoke($this->view, $media, __DIR__ . '/test.md')
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user