mirror of
https://github.com/Karaka-Management/oms-Workflow.git
synced 2026-01-11 06:48:41 +00:00
undo serialize deprecation and switch to installExternal api calls
This commit is contained in:
parent
98ce9692a3
commit
242ba08457
|
|
@ -14,7 +14,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Workflow\Admin;
|
||||
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Module\InstallerAbstract;
|
||||
use phpOMS\System\File\PathException;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
|
||||
/**
|
||||
* Installer class.
|
||||
|
|
@ -33,4 +38,99 @@ final class Installer extends InstallerAbstract
|
|||
* @since 1.0.0
|
||||
*/
|
||||
public const PATH = __DIR__;
|
||||
|
||||
/**
|
||||
* Install data from providing modules.
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array $data Additional data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function installExternal(ApplicationAbstract $app, array $data) : array
|
||||
{
|
||||
if (!\is_file($data['path'] ?? '')) {
|
||||
throw new PathException($data['path'] ?? '');
|
||||
}
|
||||
|
||||
$workflowFile = \file_get_contents($data['path'] ?? '');
|
||||
if ($workflowFile === false) {
|
||||
throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$workflowData = \json_decode($workflowFile, true) ?? [];
|
||||
if ($workflowData === false) {
|
||||
throw new \Exception(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (!\is_dir(__DIR__ . '/../../../temp')) {
|
||||
\mkdir(__DIR__ . '/../../../temp');
|
||||
}
|
||||
|
||||
$apiApp = new class() extends ApplicationAbstract
|
||||
{
|
||||
protected string $appName = 'Api';
|
||||
};
|
||||
|
||||
$apiApp->dbPool = $app->dbPool;
|
||||
$apiApp->orgId = $app->orgId;
|
||||
$apiApp->accountManager = $app->accountManager;
|
||||
$apiApp->appSettings = $app->appSettings;
|
||||
$apiApp->moduleManager = $app->moduleManager;
|
||||
$apiApp->eventManager = $app->eventManager;
|
||||
|
||||
foreach ($workflowData as $workflow) {
|
||||
self::installWorkflow($apiApp, $workflow);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Install application page.
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array $data Additional data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function installWorkflow(ApplicationAbstract $app, array $data) : void
|
||||
{
|
||||
/** @var \Modules\Workflow\Controller\ApiController $module */
|
||||
$module = $app->moduleManager->get('Workflow');
|
||||
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('name', $data['name']);
|
||||
|
||||
$tempPath = __DIR__ . '/../../../temp/';
|
||||
|
||||
$workflowFiles = \scandir(__DIR__ . '/../../..' . $data['path']);
|
||||
foreach ($workflowFiles as $filePath) {
|
||||
if (!\is_file(__DIR__ . '/../../..' . $data['path'] . '/' . $filePath) || $filePath === '..' || $filePath === '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
\copy(
|
||||
__DIR__ . '/../../..' . $data['path'] . '/' . $filePath,
|
||||
$tempPath . $filePath
|
||||
);
|
||||
|
||||
$request->addFile([
|
||||
'error' => \UPLOAD_ERR_OK,
|
||||
'type' => \substr($filePath, \strrpos($filePath, '.') + 1),
|
||||
'name' => $filePath,
|
||||
'tmp_name' => $tempPath . $filePath,
|
||||
'size' => \filesize($tempPath . $filePath),
|
||||
]);
|
||||
}
|
||||
|
||||
$module->apiTemplateCreate($request, $response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
$view = $this->createView($instance, $request, $response);
|
||||
$this->setHelperResponseHeader($view, $instance->template->name, $request, $response);
|
||||
$this->setWorkflowResponseHeader($view, $instance->template->name, $request, $response);
|
||||
$view->setData('path', __DIR__ . '/../../../');
|
||||
|
||||
$response->set('export', $view);
|
||||
|
|
@ -137,7 +137,7 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function setHelperResponseHeader(View $view, string $name, RequestAbstract $request, ResponseAbstract $response) : void
|
||||
private function setWorkflowResponseHeader(View $view, string $name, RequestAbstract $request, ResponseAbstract $response) : void
|
||||
{
|
||||
switch ($request->getData('type')) {
|
||||
case 'pdf':
|
||||
|
|
@ -370,6 +370,13 @@ final class ApiController extends Controller
|
|||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Template', 'Template successfully created', $template);
|
||||
}
|
||||
|
||||
private function createTemplateDir(WorkflowTemplate $template) : string
|
||||
{
|
||||
return '/Modules/Workflow/'
|
||||
. $template->getId() . ' '
|
||||
. $template->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate template create request
|
||||
*
|
||||
|
|
@ -470,6 +477,7 @@ final class ApiController extends Controller
|
|||
$count = \count($data);
|
||||
|
||||
// @todo: if no Cli is available do it in the web app (maybe first web request and if this is also not allowed run it in here)
|
||||
/*
|
||||
SystemUtils::runProc(
|
||||
'php',
|
||||
__DIR__ . '/../../../cli.php' . ' '
|
||||
|
|
@ -479,5 +487,6 @@ final class ApiController extends Controller
|
|||
. '-d ' . \escapeshellarg(\json_encode($data)),
|
||||
true
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Workflow\Controller;
|
||||
|
||||
use Modules\Media\Models\CollectionMapper;
|
||||
use Modules\Workflow\Models\WorkflowTemplateMapper;
|
||||
use phpOMS\Contract\RenderableInterface;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
|
|
@ -47,6 +49,23 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/Workflow/Theme/Backend/workflow-template-list');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005501001, $request, $response));
|
||||
|
||||
$path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/'));
|
||||
$templates = WorkflowTemplateMapper::getAll()
|
||||
->with('createdBy')
|
||||
->with('tags')
|
||||
->with('tags/title')
|
||||
->where('virtualPath', $path)
|
||||
->where('tags/title/language', $response->getLanguage())
|
||||
->execute();
|
||||
|
||||
list($collection, $parent) = CollectionMapper::getCollectionsByPath($path);
|
||||
|
||||
$view->addData('parent', $parent);
|
||||
$view->addData('collections', $collection);
|
||||
$view->addData('path', $path);
|
||||
$view->addData('reports', $templates);
|
||||
$view->addData('account', $this->app->accountManager->get($request->header->account));
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,4 +31,6 @@ abstract class PermissionCategory extends Enum
|
|||
public const TEMPLATE = 2;
|
||||
|
||||
public const EXPORT = 3;
|
||||
|
||||
public const WORKFLOW = 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,154 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
* @var \Modules\Tasks\Models\Task[] $tasks
|
||||
* @var \phpOMS\Views\View $this
|
||||
* @var \Modules\Workflow\Models\Template[] $templates
|
||||
*/
|
||||
$tasks = $this->getData('tasks');
|
||||
echo $this->getData('nav')->render();
|
||||
$templates = $this->getData('reports');
|
||||
|
||||
/** @var \Modules\Admin\Models\Account $account */
|
||||
$account = $this->getData('account');
|
||||
|
||||
$accountDir = $account->getId() . ' ' . $account->login;
|
||||
|
||||
/** @var \Modules\Media\Models\Collection[] */
|
||||
$collections = $this->getData('collections');
|
||||
$mediaPath = \urldecode($this->getData('path') ?? '/');
|
||||
|
||||
$previous = empty($templates) ? '{/prefix}workflow/template/list' : '{/prefix}workflow/template/list?{?}&id=' . \reset($templates)->getId() . '&ptype=p';
|
||||
$next = empty($templates) ? '{/prefix}workflow/template/list' : '{/prefix}workflow/template/list?{?}&id=' . \end($templates)->getId() . '&ptype=n';
|
||||
|
||||
echo $this->getData('nav')->render(); ?>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<ul class="crumbs-2">
|
||||
<li data-href="<?= UriFactory::build('{/prefix}workflow/template/list?path=/Accounts/' . $accountDir); ?>"><a href="<?= UriFactory::build('{/prefix}workflow/template/list?path=/Accounts/' . $accountDir); ?>"><i class="fa fa-home"></i></a>
|
||||
<li data-href="<?= UriFactory::build('{/prefix}workflow/template/list?path=/'); ?>"><a href="<?= UriFactory::build('{/prefix}workflow/template/list?path=/'); ?>">/</a></li>
|
||||
<?php
|
||||
$subPath = '';
|
||||
$paths = \explode('/', \ltrim($mediaPath, '/'));
|
||||
$length = \count($paths);
|
||||
$parentPath = '';
|
||||
|
||||
for ($i = 0; $i < $length; ++$i) :
|
||||
if ($paths[$i] === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($i === $length - 1) {
|
||||
$parentPath = $subPath === '' ? '/' : $subPath;
|
||||
}
|
||||
|
||||
$subPath .= '/' . $paths[$i];
|
||||
|
||||
$url = UriFactory::build('{/prefix}workflow/template/list?path=' . $subPath);
|
||||
?>
|
||||
<li data-href="<?= $url; ?>"<?= $i === $length - 1 ? 'class="active"' : ''; ?>><a href="<?= $url; ?>"><?= $this->printHtml($paths[$i]); ?></a></li>
|
||||
<?php endfor; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="portlet">
|
||||
<div class="portlet-head"><?= $this->getHtml('Workflows'); ?><i class="fa fa-download floatRight download btn"></i></div>
|
||||
<div class="slider">
|
||||
<table id="workflowTemplateList" class="default sticky">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><label class="checkbox" for="workflowTemplateList-0">
|
||||
<input type="checkbox" id="workflowTemplateList-0" name="templateselect">
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
<td>
|
||||
<td class="wf-100"><?= $this->getHtml('Name'); ?>
|
||||
<label for="workflowTemplateList-sort-1">
|
||||
<input type="radio" name="workflowTemplateList-sort" id="workflowTemplateList-sort-1">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="workflowTemplateList-sort-2">
|
||||
<input type="radio" name="workflowTemplateList-sort" id="workflowTemplateList-sort-2">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('Creator'); ?>
|
||||
<label for="workflowTemplateList-sort-5">
|
||||
<input type="radio" name="workflowTemplateList-sort" id="workflowTemplateList-sort-5">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="workflowTemplateList-sort-6">
|
||||
<input type="radio" name="workflowTemplateList-sort" id="workflowTemplateList-sort-6">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('Created'); ?>
|
||||
<label for="workflowTemplateList-sort-7">
|
||||
<input type="radio" name="workflowTemplateList-sort" id="workflowTemplateList-sort-7">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="workflowTemplateList-sort-8">
|
||||
<input type="radio" name="workflowTemplateList-sort" id="workflowTemplateList-sort-8">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<tbody>
|
||||
<?php if (!empty($parentPath)) : $url = UriFactory::build('{/prefix}workflow/template/list?path=' . $parentPath); ?>
|
||||
<tr tabindex="0" data-href="<?= $url; ?>">
|
||||
<td>
|
||||
<td data-label="<?= $this->getHtml('Type'); ?>"><a href="<?= $url; ?>"><i class="fa fa-folder-open-o"></i></a>
|
||||
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>">..
|
||||
</a>
|
||||
<td>
|
||||
<td>
|
||||
<td>
|
||||
<?php endif; ?>
|
||||
<?php $count = 0; foreach ($collections as $key => $value) : ++$count;
|
||||
$url = UriFactory::build('{/prefix}workflow/template/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name);
|
||||
?>
|
||||
<tr data-href="<?= $url; ?>">
|
||||
<td><label class="checkbox" for="workflowTemplateList-<?= $key; ?>">
|
||||
<input type="checkbox" id="workflowTemplateList-<?= $key; ?>" name="templateselect">
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
<td><a href="<?= $url; ?>"><i class="fa fa-folder-open-o"></i></a>
|
||||
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->name); ?></a>
|
||||
<td><a class="content" href="<?= UriFactory::build('{/prefix}profile/single?{?}&for=' . $value->createdBy->getId()); ?>"><?= $this->printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->createdBy->name1, $value->createdBy->name2, $value->createdBy->name3, $value->createdBy->login ?? ''])); ?></a>
|
||||
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->createdAt->format('Y-m-d')); ?></a>
|
||||
<?php endforeach; ?>
|
||||
<?php foreach ($templates as $key => $template) : ++$count;
|
||||
$url = UriFactory::build('{/prefix}workflow/template/view?{?}&id=' . $template->getId()); ?>
|
||||
<tr tabindex="0" data-href="<?= $url; ?>">
|
||||
<td><label class="checkbox" for="workflowTemplateList-<?= $key; ?>">
|
||||
<input type="checkbox" id="workflowTemplateList-<?= $key; ?>" name="templateselect">
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
<td>
|
||||
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($template->name); ?></a>
|
||||
<td data-label="<?= $this->getHtml('Creator'); ?>"><a class="content" href="<?= UriFactory::build('{/prefix}profile/single?{?}&for=' . $template->createdBy->getId()); ?>"><?= $this->printHtml($this->renderUserName('%3$s %2$s %1$s', [$template->createdBy->name1, $template->createdBy->name2, $template->createdBy->name3, $template->createdBy->login ?? ''])); ?></a>
|
||||
<td data-label="<?= $this->getHtml('Updated'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($template->createdAt->format('Y-m-d')); ?></a>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($count === 0) : ?>
|
||||
<tr tabindex="0" class="empty">
|
||||
<td colspan="4"><?= $this->getHtml('Empty', '0', '0'); ?>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
</div>
|
||||
<div class="portlet-foot">
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($next); ?>"><?= $this->getHtml('Next', '0', '0'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user