Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust for Queue v8 #5

Merged
merged 7 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"cakephp/cakephp": "^5.0.1",
"dragonmantank/cron-expression": "^3.3",
"dereuromark/cakephp-tools": "^3.0.0",
"dereuromark/cakephp-queue": "^7.0.0"
"dereuromark/cakephp-queue": "^7.0.0 || ^8.0.0"
},
"require-dev": {
"dereuromark/cakephp-templating": "^0.2.2",
"cakephp/migrations": "^4.1.0",
"phpunit/phpunit": "^10.3",
"fig-r/psr2r-sniffer": "dev-next"
Expand Down
34 changes: 34 additions & 0 deletions src/Controller/Admin/LoadHelperTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace Queue\Controller\Admin;

use Templating\View\Helper\IconHelper;
use Templating\View\Helper\IconSnippetHelper;
use Templating\View\Helper\TemplatingHelper;

trait LoadHelperTrait {

/**
* @return void
*/
protected function loadHelpers(): void {
$helpers = [
'Shim.Configure',
'Queue.Queue',
'Queue.QueueProgress',
'Tools.Format',
'Tools.Text',
'Tools.Time',
class_exists(IconHelper::class) ? 'Templating.Icon' : 'Tools.Icon',
];
if (class_exists(IconSnippetHelper::class)) {
$helpers[] = 'Templating.IconSnippet';
}
if (class_exists(TemplatingHelper::class)) {
$helpers[] = 'Templating.Templating';
}

$this->viewBuilder()->addHelpers($helpers);
}

}
10 changes: 4 additions & 6 deletions src/Controller/Admin/QueueSchedulerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
namespace QueueScheduler\Controller\Admin;

use Cake\Utility\Hash;
use Queue\Controller\Admin\LoadHelperTrait;
use QueueScheduler\Controller\AppController;
use Templating\View\Helper\IconHelper;

class QueueSchedulerController extends AppController {

use LoadHelperTrait;

/**
* @return void
*/
public function initialize(): void {
parent::initialize();

$this->viewBuilder()->addHelpers([
class_exists(IconHelper::class) ? 'Templating.Icon' : 'Tools.Icon',
'Queue.Queue',
'Queue.QueueProgress',
]);
$this->loadHelpers();
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/Controller/Admin/SchedulerRowsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace QueueScheduler\Controller\Admin;

use Queue\Controller\Admin\LoadHelperTrait;
use QueueScheduler\Controller\AppController;
use Templating\View\Helper\IconHelper;

/**
* Rows Controller
Expand All @@ -13,16 +13,15 @@
*/
class SchedulerRowsController extends AppController {

use LoadHelperTrait;

/**
* @return void
*/
public function initialize(): void {
parent::initialize();

$this->viewBuilder()->addHelpers([
'Tools.Format',
class_exists(IconHelper::class) ? 'Templating.Icon' : 'Tools.Icon',
]);
$this->loadHelpers();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/Admin/SchedulerRows/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<td><?= h($row->name) ?></td>
<td><?= $row::types($row->type) ?></td>
<td><?= h($row->frequency) ?></td>
<td><?= $this->Format->yesNo($row->allow_concurrent) ?></td>
<td><?= $this->element('QueueScheduler.yes_no', ['value' => $row->allow_concurrent]) ?></td>
<td>
<?= $this->Format->yesNo($row->enabled) ?>
<?= $this->element('QueueScheduler.yes_no', ['value' => $row->enabled]) ?>
<?php if ($row->enabled && $row->type === $row::TYPE_SHELL_COMMAND && !\Cake\Core\Configure::read('QueueScheduler.allowRaw')) { ?>
<span><?php echo $this->Icon->render('stop-circle', [], ['title' => 'Raw commands are currently configured to be not runnable on non-debug system for security reasons.']); ?></span>
<?php } ?>
Expand Down
2 changes: 1 addition & 1 deletion templates/Admin/SchedulerRows/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</tr>
<tr>
<th><?= __('Allow Concurrent') ?></th>
<td><?= $this->Format->yesNo($row->allow_concurrent) ?> <?= $row->allow_concurrent ? __('Yes') : __('No'); ?></td>
<td><?= $this->element('QueueScheduler.yes_no', ['value' => $row->allow_concurrent]) ?> <?= $row->allow_concurrent ? __('Yes') : __('No'); ?></td>
</tr>
</table>
<div class="text">
Expand Down
17 changes: 17 additions & 0 deletions templates/element/yes_no.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Overwrite this element snippet locally to customize if needed.
*
* @var \App\View\AppView $this
* @var bool $value
*/
?>
<?php
if ($this->helpers()->has('IconSnippet')) {
echo $this->IconSnippet->yesNo($value);
} elseif ($this->helpers()->has('Format')) {
echo $this->Format->yesNo($value);
} else {
echo $value ? '<span class="yes-no yes-no-yes">Yes</span>' : '<span class="yes-no yes-no-no">No</span>';
}
?>
2 changes: 1 addition & 1 deletion tests/TestCase/Utility/CommandFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public function testAll() {
Plugin::getCollection()->add(new QueuePlugin());

$result = (new CommandFinder())->all();
unset($result['Queue.MigrateTasks']);
$expected = [
'Queue.BakeQueueTask' => 'Queue.BakeQueueTask',
'Queue.Worker' => 'Queue.Worker',
'Queue.Job' => 'Queue.Job',
'Queue.Run' => 'Queue.Run',
'Queue.Add' => 'Queue.Add',
'Queue.MigrateTasks' => 'Queue.MigrateTasks',
'Queue.Info' => 'Queue.Info',
'QueueScheduler.Run' => 'QueueScheduler.Run',
'Tools.Inflect' => 'Tools.Inflect',
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Cake\Database\Connection;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\Fixture\SchemaLoader;
use Templating\View\Icon\BootstrapIcon;
use TestApp\Controller\AppController;
use Tools\View\Icon\BootstrapIcon;

if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
Expand Down Expand Up @@ -96,7 +96,7 @@ class_alias(AppController::class, 'App\Controller\AppController');
]);

Configure::write('Icon', [
'sets' => ['bs' => \Tools\View\Icon\BootstrapIcon::class],
'sets' => ['bs' => BootstrapIcon::class],
]);

Plugin::getCollection()->add(new QueueScheduler\QueueSchedulerPlugin());
Expand Down