Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Queue\Console;
4
 
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Composer;
8
use Symfony\Component\Console\Attribute\AsCommand;
9
 
10
#[AsCommand(name: 'queue:batches-table')]
11
class BatchesTableCommand extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'queue:batches-table';
19
 
20
    /**
21
     * The name of the console command.
22
     *
23
     * This name is used to identify the command during lazy loading.
24
     *
25
     * @var string|null
26
     *
27
     * @deprecated
28
     */
29
    protected static $defaultName = 'queue:batches-table';
30
 
31
    /**
32
     * The console command description.
33
     *
34
     * @var string
35
     */
36
    protected $description = 'Create a migration for the batches database table';
37
 
38
    /**
39
     * The filesystem instance.
40
     *
41
     * @var \Illuminate\Filesystem\Filesystem
42
     */
43
    protected $files;
44
 
45
    /**
46
     * @var \Illuminate\Support\Composer
47
     */
48
    protected $composer;
49
 
50
    /**
51
     * Create a new batched queue jobs table command instance.
52
     *
53
     * @param  \Illuminate\Filesystem\Filesystem  $files
54
     * @param  \Illuminate\Support\Composer  $composer
55
     * @return void
56
     */
57
    public function __construct(Filesystem $files, Composer $composer)
58
    {
59
        parent::__construct();
60
 
61
        $this->files = $files;
62
        $this->composer = $composer;
63
    }
64
 
65
    /**
66
     * Execute the console command.
67
     *
68
     * @return void
69
     */
70
    public function handle()
71
    {
72
        $table = $this->laravel['config']['queue.batching.table'] ?? 'job_batches';
73
 
74
        $this->replaceMigration(
75
            $this->createBaseMigration($table), $table
76
        );
77
 
78
        $this->components->info('Migration created successfully.');
79
 
80
        $this->composer->dumpAutoloads();
81
    }
82
 
83
    /**
84
     * Create a base migration file for the table.
85
     *
86
     * @param  string  $table
87
     * @return string
88
     */
89
    protected function createBaseMigration($table = 'job_batches')
90
    {
91
        return $this->laravel['migration.creator']->create(
92
            'create_'.$table.'_table', $this->laravel->databasePath().'/migrations'
93
        );
94
    }
95
 
96
    /**
97
     * Replace the generated migration with the batches job table stub.
98
     *
99
     * @param  string  $path
100
     * @param  string  $table
101
     * @return void
102
     */
103
    protected function replaceMigration($path, $table)
104
    {
105
        $stub = str_replace(
106
            '{{table}}', $table, $this->files->get(__DIR__.'/stubs/batches.stub')
107
        );
108
 
109
        $this->files->put($path, $stub);
110
    }
111
}