Skip to content

Commit a499a6c

Browse files
Allow to pull db & assets without setting the website key
1 parent 3f5a76e commit a499a6c

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"guzzlehttp/guzzle": "^7.5",
3030
"illuminate/contracts": "^11.0|^12.0",
3131
"intervention/image-laravel": "^1.0",
32+
"laravel/prompts": "^0.3.8",
3233
"spatie/laravel-package-tools": "^1.14.0",
3334
"spatie/laravel-sluggable": "^3.6"
3435
},

src/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public function apiKey(): ?string
110110
return $this->apiKey;
111111
}
112112

113+
public function getWebsiteKey(): ?string
114+
{
115+
return $this->http()->get('/website')->json()['key'] ?? null;
116+
}
117+
113118
protected function http(): PendingRequest
114119
{
115120
return Http::withToken($this->apiKey)

src/Console/FetchDataFromOzu.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
use Symfony\Component\Process\Process;
99
use ZipArchive;
1010

11+
use function Laravel\Prompts\confirm;
12+
1113
class FetchDataFromOzu extends Command
1214
{
1315
protected $signature = 'ozu:fetch-ozu-data';
1416

17+
protected $aliases = ['ozu:fetch-data', 'ozu:pull'];
18+
1519
protected $description = 'Gets Ozu’s CMS data and replaces your local database and assets with it.';
1620

1721
private string $databaseDumpPath;
@@ -23,13 +27,16 @@ class FetchDataFromOzu extends Command
2327
public function handle(Client $ozuClient): int
2428
{
2529

26-
$this->warn('/!\\ This action will erase your local database and assets.');
30+
$this->warn('⚠️ This action will erase your local database and assets.');
2731

28-
if (!$this->confirm('Are you sure you want to continue? This cannot be undone.')) {
32+
if (!confirm(
33+
'Are you sure you want to continue? This cannot be undone.',
34+
default: false,
35+
)) {
2936
return self::SUCCESS;
3037
}
3138

32-
$this->initializePaths();
39+
$this->initializePaths($ozuClient);
3340

3441
if (!$this->downloadDatabase($ozuClient)) {
3542
return self::FAILURE;
@@ -53,11 +60,12 @@ public function handle(Client $ozuClient): int
5360
return self::SUCCESS;
5461
}
5562

56-
private function initializePaths(): void
63+
private function initializePaths(Client $ozuClient): void
5764
{
65+
$websiteKey = config('ozu-client.website_key') ?? $ozuClient->getWebsiteKey();
5866
$this->databaseDumpPath = storage_path('app/tmp/ozu.sql');
5967
$this->assetsZipPath = storage_path('app/tmp/ozu-assets.zip');
60-
$this->assetsExtractPath = storage_path('app/public/data/'.config('ozu-client.website_key').'/');
68+
$this->assetsExtractPath = storage_path('app/public/data/'.$websiteKey.'/');
6169
}
6270

6371
private function downloadDatabase(Client $ozuClient): bool

0 commit comments

Comments
 (0)