Skip to content

Commit 07d4bc1

Browse files
committed
✨ job/call now support void/bool/string returns
allow jobs from config files and model methods to yield void/bool/string instead of janitor data-array Signed-off-by: bnomei <[email protected]>
1 parent a90e42a commit 07d4bc1

File tree

7 files changed

+54
-6
lines changed

7 files changed

+54
-6
lines changed

commands/call.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@
4343
} else {
4444
$result = $model->$method($cli->arg('data'));
4545
}
46+
if (is_null($result)) {
47+
$result = [];
48+
$result['status'] = 200;
49+
} elseif (is_bool($result)) {
50+
$result = [];
51+
$result['status'] = $result ? 200 : 204;
52+
} elseif (is_string($result)) {
53+
$result = [];
54+
$result = [
55+
'status' => 200,
56+
'message' => $result,
57+
];
58+
}
4659
} else {
4760
$result['message'] = t('janitor.method-not-found', 'Method "' . $method . '" could not be called on model of class <' . $model::class . '>.');
4861
}

commands/job.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@
4343
} else {
4444
$result = $job($model, $cli->arg('data'));
4545
}
46+
if (is_null($result)) {
47+
$result = [];
48+
$result['status'] = 200;
49+
} elseif (is_bool($result)) {
50+
$result = [];
51+
$result['status'] = $result ? 200 : 204;
52+
} elseif (is_string($result)) {
53+
$result = [];
54+
$result = [
55+
'status' => 200,
56+
'message' => $result,
57+
];
58+
}
4659
} else {
4760
$result['message'] = t('janitor.job-not-found', 'Job "' . $key . '" could not be found.');
4861
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby3-janitor",
33
"type": "kirby-plugin",
4-
"version": "3.7.0",
4+
"version": "3.8.0",
55
"license": "MIT",
66
"homepage": "https://github.com/bnomei/kirby3-janitor",
77
"description": "Kirby 3 Plugin for running commands like cleaning the cache from within the Panel, PHP code or a cronjob",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/JanitorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,15 @@ public function testMethod()
6767
'Repeat after me: hello',
6868
$janitor->command('janitor:call --method repeatAfterMe --data hello --page page://vf0xqIlpU0ZlSorI')['message']
6969
);
70+
71+
$this->assertEquals(
72+
200,
73+
$janitor->command('janitor:call --method nullberry --page page://vf0xqIlpU0ZlSorI')['status']
74+
);
75+
76+
$this->assertEquals(
77+
204,
78+
$janitor->command('janitor:call --method boolberry --page page://vf0xqIlpU0ZlSorI')['status']
79+
);
7080
}
7181
}

tests/site/models/default.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
class DefaultPage extends \Kirby\Cms\Page
44
{
5+
public function nullberry(): void
6+
{
7+
// will yield 200 automatically
8+
}
9+
10+
public function boolberry(): bool
11+
{
12+
// will yield 200/204 automatically
13+
return false;
14+
}
15+
16+
517
public function whoAmI(): array
618
{
719
return [

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'bnomei/kirby3-janitor',
4-
'pretty_version' => '3.7.0',
5-
'version' => '3.7.0.0',
4+
'pretty_version' => '3.8.0',
5+
'version' => '3.8.0.0',
66
'reference' => NULL,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -11,8 +11,8 @@
1111
),
1212
'versions' => array(
1313
'bnomei/kirby3-janitor' => array(
14-
'pretty_version' => '3.7.0',
15-
'version' => '3.7.0.0',
14+
'pretty_version' => '3.8.0',
15+
'version' => '3.8.0.0',
1616
'reference' => NULL,
1717
'type' => 'kirby-plugin',
1818
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)