master

laravel/framework

Last updated at: 29/12/2023 09:24

FailedTableCommand.php

TLDR

This file is a part of the Illuminate Queue package and contains the FailedTableCommand class, which is a command used to generate a migration for the failed queue jobs database table.

Classes

FailedTableCommand

The FailedTableCommand class extends the MigrationGeneratorCommand class and is responsible for generating a migration file for the failed queue jobs database table. It has the following properties:

  • $name: The console command name
  • $aliases: The console command name aliases
  • $description: The console command description

The class also contains the following methods:

  • migrationTableName(): Returns the name of the migration table as configured in the Laravel application
  • migrationStubFile(): Returns the path to the migration stub file
  • migrationExists($table): Determines whether a migration for the given table already exists
<?php

namespace Illuminate\Queue\Console;

use Illuminate\Console\MigrationGeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;

use function Illuminate\Filesystem\join_paths;

#[AsCommand(name: 'make:queue-failed-table')]
class FailedTableCommand extends MigrationGeneratorCommand
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'make:queue-failed-table';

    /**
     * The console command name aliases.
     *
     * @var array
     */
    protected $aliases = ['queue:failed-table'];

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a migration for the failed queue jobs database table';

    /**
     * Get the migration table name.
     *
     * @return string
     */
    protected function migrationTableName()
    {
        return $this->laravel['config']['queue.failed.table'];
    }

    /**
     * Get the path to the migration stub file.
     *
     * @return string
     */
    protected function migrationStubFile()
    {
        return __DIR__.'/stubs/failed_jobs.stub';
    }

    /**
     * Determine whether a migration for the table already exists.
     *
     * @param  string  $table
     * @return bool
     */
    protected function migrationExists($table)
    {
        if ($table !== 'failed_jobs') {
            return parent::migrationExists($table);
        }

        return count($this->files->glob(sprintf(
            '{%s,%s}',
            join_paths($this->laravel->databasePath('migrations'), '*_*_*_*_create_'.$table.'_table.php'),
            join_paths($this->laravel->databasePath('migrations'), '0001_01_01_000002_create_jobs_table.php'),
        ))) !== 0;
    }
}