From 89220f53f52a3a2062dc1dae7c216e203e573680 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Tue, 12 Mar 2024 17:16:15 +0100 Subject: [PATCH 1/7] Adjust for Queue v8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c45732f..9587a1b 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "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": { "cakephp/migrations": "^4.1.0", From ce81f04eaf5f8f6bdcf92500ca3fa8489faf9c5f Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 12 Mar 2024 17:28:38 +0100 Subject: [PATCH 2/7] Flexible backend for Queue v8. --- composer.json | 1 + src/Controller/Admin/LoadHelperTrait.php | 34 +++++++++++++++++++ .../Admin/QueueSchedulerController.php | 10 +++--- .../Admin/SchedulerRowsController.php | 9 +++-- templates/Admin/SchedulerRows/index.php | 4 +-- templates/Admin/SchedulerRows/view.php | 2 +- templates/element/yes_no.php | 17 ++++++++++ tests/TestCase/Utility/CommandFinderTest.php | 2 +- tests/bootstrap.php | 4 +-- 9 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 src/Controller/Admin/LoadHelperTrait.php create mode 100644 templates/element/yes_no.php diff --git a/composer.json b/composer.json index 9587a1b..9176000 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "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" diff --git a/src/Controller/Admin/LoadHelperTrait.php b/src/Controller/Admin/LoadHelperTrait.php new file mode 100644 index 0000000..8d1fd57 --- /dev/null +++ b/src/Controller/Admin/LoadHelperTrait.php @@ -0,0 +1,34 @@ +viewBuilder()->addHelpers($helpers); + } + +} diff --git a/src/Controller/Admin/QueueSchedulerController.php b/src/Controller/Admin/QueueSchedulerController.php index 232a038..794af7d 100644 --- a/src/Controller/Admin/QueueSchedulerController.php +++ b/src/Controller/Admin/QueueSchedulerController.php @@ -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(); } /** diff --git a/src/Controller/Admin/SchedulerRowsController.php b/src/Controller/Admin/SchedulerRowsController.php index d479fb6..7e2d8c2 100644 --- a/src/Controller/Admin/SchedulerRowsController.php +++ b/src/Controller/Admin/SchedulerRowsController.php @@ -2,8 +2,8 @@ namespace QueueScheduler\Controller\Admin; +use Queue\Controller\Admin\LoadHelperTrait; use QueueScheduler\Controller\AppController; -use Templating\View\Helper\IconHelper; /** * Rows Controller @@ -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(); } /** diff --git a/templates/Admin/SchedulerRows/index.php b/templates/Admin/SchedulerRows/index.php index 9a76560..eb86c22 100644 --- a/templates/Admin/SchedulerRows/index.php +++ b/templates/Admin/SchedulerRows/index.php @@ -39,9 +39,9 @@ name) ?> type) ?> frequency) ?> - Format->yesNo($row->allow_concurrent) ?> + element('Queue.yes_no', ['value' => $row->allow_concurrent]) ?> - Format->yesNo($row->enabled) ?> + element('Queue.yes_no', ['value' => $row->enabled]) ?> enabled && $row->type === $row::TYPE_SHELL_COMMAND && !\Cake\Core\Configure::read('QueueScheduler.allowRaw')) { ?> Icon->render('stop-circle', [], ['title' => 'Raw commands are currently configured to be not runnable on non-debug system for security reasons.']); ?> diff --git a/templates/Admin/SchedulerRows/view.php b/templates/Admin/SchedulerRows/view.php index e6837e3..86077ef 100644 --- a/templates/Admin/SchedulerRows/view.php +++ b/templates/Admin/SchedulerRows/view.php @@ -40,7 +40,7 @@ - Format->yesNo($row->allow_concurrent) ?> allow_concurrent ? __('Yes') : __('No'); ?> + element('Queue.yes_no', ['value' => $row->allow_concurrent]) ?> allow_concurrent ? __('Yes') : __('No'); ?>
diff --git a/templates/element/yes_no.php b/templates/element/yes_no.php new file mode 100644 index 0000000..358886e --- /dev/null +++ b/templates/element/yes_no.php @@ -0,0 +1,17 @@ + +helpers()->has('IconSnippet')) { + echo $this->IconSnippet->yesNo($value); + } elseif ($this->helpers()->has('Format')) { + echo $this->Format->yesNo($value); + } else { + echo $value ? 'Yes' : 'No'; + } +?> diff --git a/tests/TestCase/Utility/CommandFinderTest.php b/tests/TestCase/Utility/CommandFinderTest.php index 6b688c8..a30db25 100644 --- a/tests/TestCase/Utility/CommandFinderTest.php +++ b/tests/TestCase/Utility/CommandFinderTest.php @@ -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', diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 12c2b29..e620126 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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); @@ -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()); From 0074ce54111abd30e3d04ea829621e99b576eea8 Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 12 Mar 2024 17:31:31 +0100 Subject: [PATCH 3/7] Adjust test. --- tests/TestCase/Utility/CommandFinderTest.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/TestCase/Utility/CommandFinderTest.php b/tests/TestCase/Utility/CommandFinderTest.php index a30db25..6dc78f2 100644 --- a/tests/TestCase/Utility/CommandFinderTest.php +++ b/tests/TestCase/Utility/CommandFinderTest.php @@ -17,17 +17,19 @@ public function testAll() { $result = (new CommandFinder())->all(); unset($result['Queue.MigrateTasks']); + + $keys = array_keys($result); $expected = [ - 'Queue.BakeQueueTask' => 'Queue.BakeQueueTask', - 'Queue.Worker' => 'Queue.Worker', - 'Queue.Job' => 'Queue.Job', - 'Queue.Run' => 'Queue.Run', - 'Queue.Add' => 'Queue.Add', - 'Queue.Info' => 'Queue.Info', - 'QueueScheduler.Run' => 'QueueScheduler.Run', - 'Tools.Inflect' => 'Tools.Inflect', + 'Queue.BakeQueueTask', + 'Queue.Worker', + 'Queue.Job', + 'Queue.Run', + 'Queue.Add', + 'Queue.Info', + 'QueueScheduler.Run', + 'Tools.Inflect', ]; - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $keys); } } From 1b2112d488c79dbb999e3ec6857d6e7f2f234ece Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 12 Mar 2024 17:33:42 +0100 Subject: [PATCH 4/7] Adjust test. --- tests/TestCase/Utility/CommandFinderTest.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/TestCase/Utility/CommandFinderTest.php b/tests/TestCase/Utility/CommandFinderTest.php index 6dc78f2..a30db25 100644 --- a/tests/TestCase/Utility/CommandFinderTest.php +++ b/tests/TestCase/Utility/CommandFinderTest.php @@ -17,19 +17,17 @@ public function testAll() { $result = (new CommandFinder())->all(); unset($result['Queue.MigrateTasks']); - - $keys = array_keys($result); $expected = [ - 'Queue.BakeQueueTask', - 'Queue.Worker', - 'Queue.Job', - 'Queue.Run', - 'Queue.Add', - 'Queue.Info', - 'QueueScheduler.Run', - 'Tools.Inflect', + 'Queue.BakeQueueTask' => 'Queue.BakeQueueTask', + 'Queue.Worker' => 'Queue.Worker', + 'Queue.Job' => 'Queue.Job', + 'Queue.Run' => 'Queue.Run', + 'Queue.Add' => 'Queue.Add', + 'Queue.Info' => 'Queue.Info', + 'QueueScheduler.Run' => 'QueueScheduler.Run', + 'Tools.Inflect' => 'Tools.Inflect', ]; - $this->assertEquals($expected, $keys); + $this->assertEquals($expected, $result); } } From e68747023698ef38e50e6655cff4892a55eb25e2 Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 12 Mar 2024 17:33:58 +0100 Subject: [PATCH 5/7] Adjust test. --- tests/TestCase/Utility/CommandFinderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Utility/CommandFinderTest.php b/tests/TestCase/Utility/CommandFinderTest.php index a30db25..3da6257 100644 --- a/tests/TestCase/Utility/CommandFinderTest.php +++ b/tests/TestCase/Utility/CommandFinderTest.php @@ -16,7 +16,7 @@ public function testAll() { Plugin::getCollection()->add(new QueuePlugin()); $result = (new CommandFinder())->all(); - unset($result['Queue.MigrateTasks']); + unset($result['Queue.MigrateTask']); $expected = [ 'Queue.BakeQueueTask' => 'Queue.BakeQueueTask', 'Queue.Worker' => 'Queue.Worker', From 154a5c33a3757055910cc3a13a8a86cbd147dc26 Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 12 Mar 2024 17:36:14 +0100 Subject: [PATCH 6/7] Adjust test. --- templates/Admin/SchedulerRows/index.php | 4 ++-- templates/Admin/SchedulerRows/view.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/Admin/SchedulerRows/index.php b/templates/Admin/SchedulerRows/index.php index eb86c22..ea04e7d 100644 --- a/templates/Admin/SchedulerRows/index.php +++ b/templates/Admin/SchedulerRows/index.php @@ -39,9 +39,9 @@ name) ?> type) ?> frequency) ?> - element('Queue.yes_no', ['value' => $row->allow_concurrent]) ?> + element('QueueScheduler.yes_no', ['value' => $row->allow_concurrent]) ?> - element('Queue.yes_no', ['value' => $row->enabled]) ?> + element('QueueScheduler.yes_no', ['value' => $row->enabled]) ?> enabled && $row->type === $row::TYPE_SHELL_COMMAND && !\Cake\Core\Configure::read('QueueScheduler.allowRaw')) { ?> Icon->render('stop-circle', [], ['title' => 'Raw commands are currently configured to be not runnable on non-debug system for security reasons.']); ?> diff --git a/templates/Admin/SchedulerRows/view.php b/templates/Admin/SchedulerRows/view.php index 86077ef..13cd015 100644 --- a/templates/Admin/SchedulerRows/view.php +++ b/templates/Admin/SchedulerRows/view.php @@ -40,7 +40,7 @@ - element('Queue.yes_no', ['value' => $row->allow_concurrent]) ?> allow_concurrent ? __('Yes') : __('No'); ?> + element('QueueScheduler.yes_no', ['value' => $row->allow_concurrent]) ?> allow_concurrent ? __('Yes') : __('No'); ?>
From 5686de4a7282cd1ff4da2ede72dc7d00ae2093ef Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 12 Mar 2024 17:37:24 +0100 Subject: [PATCH 7/7] Adjust test. --- tests/TestCase/Utility/CommandFinderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Utility/CommandFinderTest.php b/tests/TestCase/Utility/CommandFinderTest.php index 3da6257..a30db25 100644 --- a/tests/TestCase/Utility/CommandFinderTest.php +++ b/tests/TestCase/Utility/CommandFinderTest.php @@ -16,7 +16,7 @@ public function testAll() { Plugin::getCollection()->add(new QueuePlugin()); $result = (new CommandFinder())->all(); - unset($result['Queue.MigrateTask']); + unset($result['Queue.MigrateTasks']); $expected = [ 'Queue.BakeQueueTask' => 'Queue.BakeQueueTask', 'Queue.Worker' => 'Queue.Worker',