Skip to content

Commit 2c8a1da

Browse files
Merge pull request #9 from code16/auto-deploy
Implement Auto-Deploy Configuration & Improve display of errors returned by OZU
2 parents e272998 + a7276cb commit 2c8a1da

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/Console/ConfigureCmsCommand.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Code16\OzuClient\OzuCms\OzuCollectionConfig;
1111
use Code16\OzuClient\OzuCms\List\OzuColumn;
1212
use Illuminate\Console\Command;
13+
use Illuminate\Http\Client\RequestException;
1314
use Illuminate\Support\Facades\Schema;
1415

1516
class ConfigureCmsCommand extends Command
@@ -41,6 +42,7 @@ public function handle(Client $ozuClient): int
4142
'label' => $collection->label(),
4243
'icon' => $collection->icon(),
4344
'hasPublicationState' => $collection->hasPublicationState(),
45+
'autoDeployDateField' => $collection->autoDeployDateField(),
4446
'isCreatable' => $collection->isCreatable(),
4547
'isDeletable' => $collection->isDeletable(),
4648
'order' => $k+1,
@@ -83,10 +85,21 @@ public function handle(Client $ozuClient): int
8385
})
8486
->each(function (array $collection) use ($ozuClient) {
8587
$this->info('Update CMS configuration for [' . $collection['key'] . '].');
86-
$ozuClient->updateCollectionSharpConfiguration(
87-
$collection['key'],
88-
$collection
89-
);
88+
try{
89+
$ozuClient->updateCollectionSharpConfiguration(
90+
$collection['key'],
91+
$collection
92+
);
93+
} catch(RequestException $e) {
94+
if ($message = $e->response->json()) {
95+
if(!isset($message['message'])) {
96+
throw $e;
97+
}
98+
$this->error('[' . $collection['key'] . '] '.$message['message']);
99+
} else {
100+
throw $e;
101+
}
102+
}
90103
});
91104

92105
$this->info('CMS configuration sent to Ozu.');

src/OzuCms/OzuCollectionConfig.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class OzuCollectionConfig
77
protected string $label;
88
protected string $icon;
99
protected bool $hasPublicationState = false;
10+
11+
protected ?string $autoDeployDateField = null;
1012
private bool $isCreatable = true;
1113
private bool $isDeletable = true;
1214

@@ -31,6 +33,18 @@ public function setHasPublicationState(bool $hasState = true): self
3133
return $this;
3234
}
3335

36+
/**
37+
* Declare which date field will trigger auto-deploy when reached
38+
* @param string|null $field
39+
* @return $this
40+
*/
41+
public function setAutoDeployDateField(string $fieldKey): self
42+
{
43+
$this->autoDeployDateField = $fieldKey;
44+
45+
return $this;
46+
}
47+
3448
public function setIsCreatable(bool $isCreatable = true): self
3549
{
3650
$this->isCreatable = $isCreatable;
@@ -60,6 +74,16 @@ public function hasPublicationState(): bool
6074
return $this->hasPublicationState;
6175
}
6276

77+
public function hasAutoDeployDateField(): bool
78+
{
79+
return !is_null($this->autoDeployDateField);
80+
}
81+
82+
public function autoDeployDateField(): ?string
83+
{
84+
return $this->autoDeployDateField;
85+
}
86+
6387
public function isCreatable(): bool
6488
{
6589
return $this->isCreatable;

0 commit comments

Comments
 (0)