mirror of
https://github.com/Karaka-Management/oms-Editor.git
synced 2026-01-11 17:18:42 +00:00
always use and many other todo implementations
This commit is contained in:
parent
f42e5fbd23
commit
ccdf62ae04
|
|
@ -29,14 +29,14 @@ class Navigation
|
|||
/**
|
||||
* Install navigation providing
|
||||
*
|
||||
* @param string $path Module path
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param string $path Module path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function install(string $path, ApplicationAbstract $app) : void
|
||||
public static function install(ApplicationAbstract $app, string $path) : void
|
||||
{
|
||||
\Modules\Navigation\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Navigation.install.json']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,16 @@
|
|||
"type": "TEXT",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_versioned": {
|
||||
"name": "editor_doc_versioned",
|
||||
"type": "TINYINT",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_version": {
|
||||
"name": "editor_doc_version",
|
||||
"type": "VARCHAR(50)",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_virtual": {
|
||||
"name": "editor_doc_virtual",
|
||||
"type": "VARCHAR(255)",
|
||||
|
|
@ -155,5 +165,56 @@
|
|||
"foreignKey": "media_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"editor_doc_versioned": {
|
||||
"name": "editor_doc_versioned",
|
||||
"fields": {
|
||||
"editor_doc_versioned_id": {
|
||||
"name": "editor_doc_versioned_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"editor_doc_versioned_title": {
|
||||
"name": "editor_doc_versioned_title",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_versioned_version": {
|
||||
"name": "editor_doc_versioned_version",
|
||||
"type": "VARCHAR(50)",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_versioned_content": {
|
||||
"name": "editor_doc_versioned_content",
|
||||
"type": "TEXT",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_versioned_plain": {
|
||||
"name": "editor_doc_versioned_plain",
|
||||
"type": "TEXT",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_versioned_doc": {
|
||||
"name": "editor_doc_versioned_doc",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "editor_doc",
|
||||
"foreignKey": "editor_doc_id"
|
||||
},
|
||||
"editor_doc_versioned_at": {
|
||||
"name": "editor_doc_versioned_at",
|
||||
"type": "DATETIME",
|
||||
"null": false
|
||||
},
|
||||
"editor_doc_versioned_by": {
|
||||
"name": "editor_doc_versioned_by",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "account",
|
||||
"foreignKey": "account_id"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,13 +46,13 @@ final class Installer extends InstallerAbstract
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function install(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void
|
||||
public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void
|
||||
{
|
||||
parent::install($dbPool, $info, $cfgHandler);
|
||||
parent::install($app, $info, $cfgHandler);
|
||||
|
||||
$types = include __DIR__ . '/Install/Types/types.php';
|
||||
foreach ($types as $type) {
|
||||
self::createType($dbPool, $type);
|
||||
self::createType($app->dbPool, $type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ namespace Modules\Editor\Controller;
|
|||
use Modules\Admin\Models\AccountMapper;
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Editor\Models\EditorDoc;
|
||||
use Modules\Editor\Models\EditorDocHistory;
|
||||
use Modules\Editor\Models\EditorDocHistoryMapper;
|
||||
use Modules\Editor\Models\EditorDocMapper;
|
||||
use Modules\Media\Models\CollectionMapper;
|
||||
use Modules\Media\Models\MediaMapper;
|
||||
|
|
@ -90,11 +92,16 @@ final class ApiController extends Controller
|
|||
$this->createModel($request->header->account, $doc, EditorDocMapper::class, 'doc', $request->getOrigin());
|
||||
|
||||
if (!empty($request->getFiles() ?? [])
|
||||
|| !empty($request->getDataJson('media') ?? [])
|
||||
|| !empty($request->getDataJson('media') ?? [])
|
||||
) {
|
||||
$this->createDocMedia($doc, $request);
|
||||
}
|
||||
|
||||
if ($doc->isVersioned) {
|
||||
$history = $this->createHistory($doc);
|
||||
$this->createModel($request->header->account, $history, EditorDocHistoryMapper::class, 'doc_history', $request->getOrigin());
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Document', 'Document successfully created', $doc);
|
||||
}
|
||||
|
||||
|
|
@ -190,8 +197,10 @@ final class ApiController extends Controller
|
|||
$doc->title = (string) ($request->getData('title') ?? '');
|
||||
$doc->plain = (string) ($request->getData('plain') ?? '');
|
||||
$doc->content = Markdown::parse((string) ($request->getData('plain') ?? ''));
|
||||
$doc->isVersioned = (bool) ($request->getData('versioned') ?? false);
|
||||
$doc->setVirtualPath((string) ($request->getData('virtualpath') ?? '/'));
|
||||
$doc->createdBy = new NullAccount($request->header->account);
|
||||
$doc->version = (string) ($request->getData('version') ?? '');
|
||||
|
||||
if (!empty($tags = $request->getDataJson('tags'))) {
|
||||
foreach ($tags as $tag) {
|
||||
|
|
@ -213,6 +222,13 @@ final class ApiController extends Controller
|
|||
return $doc;
|
||||
}
|
||||
|
||||
private function createHistory(EditorDoc $doc) : EditorDocHistory
|
||||
{
|
||||
$history = EditorDocHistory::createFromDoc($doc);
|
||||
|
||||
return $history;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create document
|
||||
*
|
||||
|
|
@ -232,6 +248,16 @@ final class ApiController extends Controller
|
|||
$old = clone EditorDocMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$new = $this->updateEditorFromRequest($request);
|
||||
$this->updateModel($request->header->account, $old, $new, EditorDocMapper::class, 'doc', $request->getOrigin());
|
||||
|
||||
if ($new->isVersioned
|
||||
&& ($old->plain !== $new->plain
|
||||
|| $old->title !== $new->title
|
||||
)
|
||||
) {
|
||||
$history = $this->createHistory($new);
|
||||
$this->createModel($request->header->account, $history, EditorDocHistoryMapper::class, 'doc_history', $request->getOrigin());
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Document', 'Document successfully updated', $new);
|
||||
}
|
||||
|
||||
|
|
@ -248,9 +274,11 @@ final class ApiController extends Controller
|
|||
{
|
||||
/** @var \Modules\Editor\Models\EditorDoc $doc */
|
||||
$doc = EditorDocMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$doc->isVersioned = (bool) ($request->getData('versioned') ?? $doc->isVersioned);
|
||||
$doc->title = (string) ($request->getData('title') ?? $doc->title);
|
||||
$doc->plain = (string) ($request->getData('plain') ?? $doc->plain);
|
||||
$doc->content = Markdown::parse((string) ($request->getData('plain') ?? $doc->plain));
|
||||
$doc->version = (string) ($request->getData('version') ?? $doc->version);
|
||||
|
||||
return $doc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,14 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface
|
|||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Version.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $version = '';
|
||||
|
||||
/**
|
||||
* Title.
|
||||
*
|
||||
|
|
@ -118,6 +126,14 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface
|
|||
*/
|
||||
protected array $media = [];
|
||||
|
||||
/**
|
||||
* Is versioned
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public bool $isVersioned = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
|
|||
163
Models/EditorDocHistory.php
Normal file
163
Models/EditorDocHistory.php
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Editor\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://karaka.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Editor\Models;
|
||||
|
||||
use Modules\Admin\Models\Account;
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Tag\Models\Tag;
|
||||
use phpOMS\Contract\ArrayableInterface;
|
||||
|
||||
/**
|
||||
* News article class.
|
||||
*
|
||||
* @package Modules\Editor\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class EditorDocHistory implements \JsonSerializable, ArrayableInterface
|
||||
{
|
||||
/**
|
||||
* Article ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Doc ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $doc = 0;
|
||||
|
||||
/**
|
||||
* Version.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $version = '';
|
||||
|
||||
/**
|
||||
* Title.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $title = '';
|
||||
|
||||
/**
|
||||
* Content.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $content = '';
|
||||
|
||||
/**
|
||||
* Unparsed.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $plain = '';
|
||||
|
||||
/**
|
||||
* Created.
|
||||
*
|
||||
* @var \DateTimeImmutable
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public \DateTimeImmutable $createdAt;
|
||||
|
||||
/**
|
||||
* Creator.
|
||||
*
|
||||
* @var Account
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public Account $createdBy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdBy = new NullAccount();
|
||||
$this->createdAt = new \DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
public static function createFromDoc(EditorDoc $doc) : self
|
||||
{
|
||||
$hist = new self();
|
||||
$hist->doc = $doc->getId();
|
||||
$hist->createdBy = $doc->createdBy;
|
||||
$hist->title = $doc->title;
|
||||
$hist->plain = $doc->plain;
|
||||
$hist->content = $doc->content;
|
||||
$hist->version = $doc->version;
|
||||
|
||||
return $hist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'plain' => $this->plain,
|
||||
'content' => $this->content,
|
||||
'createdAt' => $this->createdAt,
|
||||
'createdBy' => $this->createdBy,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) \json_encode($this->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
82
Models/EditorDocHistoryMapper.php
Normal file
82
Models/EditorDocHistoryMapper.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Editor\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://karaka.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Editor\Models;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Editor doc mapper class.
|
||||
*
|
||||
* @package Modules\Editor\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class EditorDocHistoryMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'editor_doc_versioned_id' => ['name' => 'editor_doc_versioned_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'editor_doc_versioned_version' => ['name' => 'editor_doc_versioned_version', 'type' => 'string', 'internal' => 'version'],
|
||||
'editor_doc_versioned_title' => ['name' => 'editor_doc_versioned_title', 'type' => 'string', 'internal' => 'title'],
|
||||
'editor_doc_versioned_plain' => ['name' => 'editor_doc_versioned_plain', 'type' => 'string', 'internal' => 'plain'],
|
||||
'editor_doc_versioned_content' => ['name' => 'editor_doc_versioned_content', 'type' => 'string', 'internal' => 'content'],
|
||||
'editor_doc_versioned_at' => ['name' => 'editor_doc_versioned_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||
'editor_doc_versioned_by' => ['name' => 'editor_doc_versioned_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||
];
|
||||
|
||||
/**
|
||||
* Belongs to.
|
||||
*
|
||||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'editor_doc_versioned_by',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'editor_doc_versioned';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD ='editor_doc_versioned_id';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const AT = 'editor_doc_versioned_at';
|
||||
}
|
||||
|
|
@ -38,13 +38,15 @@ final class EditorDocMapper extends DataMapperFactory
|
|||
*/
|
||||
public const COLUMNS = [
|
||||
'editor_doc_id' => ['name' => 'editor_doc_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'editor_doc_created_by' => ['name' => 'editor_doc_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||
'editor_doc_version' => ['name' => 'editor_doc_version', 'type' => 'string', 'internal' => 'version'],
|
||||
'editor_doc_title' => ['name' => 'editor_doc_title', 'type' => 'string', 'internal' => 'title'],
|
||||
'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'],
|
||||
'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'],
|
||||
'editor_doc_type' => ['name' => 'editor_doc_type', 'type' => 'int', 'internal' => 'type'],
|
||||
'editor_doc_virtual' => ['name' => 'editor_doc_virtual', 'type' => 'string', 'internal' => 'virtualPath'],
|
||||
'editor_doc_created_at' => ['name' => 'editor_doc_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||
'editor_doc_versioned' => ['name' => 'editor_doc_versioned', 'type' => 'bool', 'internal' => 'isVersioned'],
|
||||
'editor_doc_created_at' => ['name' => 'editor_doc_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'],
|
||||
'editor_doc_created_by' => ['name' => 'editor_doc_created_by', 'type' => 'int', 'internal' => 'createdBy'],
|
||||
'editor_doc_visible' => ['name' => 'editor_doc_visible', 'type' => 'bool', 'internal' => 'isVisible'],
|
||||
];
|
||||
|
||||
|
|
|
|||
39
Models/NullEditorDocHistory.php
Normal file
39
Models/NullEditorDocHistory.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Editor\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://karaka.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Editor\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Editor\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullEditorDocHistory extends EditorDocHistory
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user