Skip to content

Commit 0ea5ec7

Browse files
committed
feat: add queue install command
1 parent 7ac2bb7 commit 0ea5ec7

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Leaf\Queue\Commands;
4+
5+
use Aloe\Command;
6+
use Aloe\Core;
7+
use Leaf\Queue;
8+
9+
class QueueInstallCommand extends Command
10+
{
11+
protected static $defaultName = 'queue:install';
12+
public $description = 'Install leaf queue';
13+
public $help = 'Generate and run migrations';
14+
15+
protected function handle()
16+
{
17+
$this->comment('Generating queue migrations...');
18+
19+
$migrationDir = getcwd() . '/app/database/migrations';
20+
$migrationFile = $migrationDir . '/2023_09_13_133625_create_jobs.php';
21+
22+
if (!Core::isMVCProject()) {
23+
$migrationDir = getcwd() . '/database/migrations';
24+
25+
if (!is_dir($migrationDir)) {
26+
mkdir($migrationDir, 0777, true);
27+
}
28+
29+
$migrationFile = $migrationDir . '/queue.config.php';
30+
}
31+
32+
if (file_exists($migrationFile)) {
33+
$this->error('Queue migration already exists');
34+
return 1;
35+
}
36+
37+
if (!copy(__DIR__ . '/stubs/migration.stub', $migrationFile)) {
38+
$this->error('Failed to generate queue migration');
39+
return 1;
40+
}
41+
42+
$this->info('Queue migration generated successfully');
43+
$this->comment('Running queue migration...');
44+
45+
$filename = basename($migrationFile, '.php');
46+
47+
if (!\Aloe\Core::run("php leaf db:migrate -f $filename", $this->output)) {
48+
$this->error('Failed to run queue migration');
49+
return 1;
50+
}
51+
52+
$this->info('Queue migration ran successfully');
53+
return 0;
54+
}
55+
}

0 commit comments

Comments
 (0)