CodeIgniter v4.7 API

Migrate extends BaseCommand
in package
uses SignalTrait

Runs all new migrations.

Table of Contents

Properties

$arguments  : array<string, string>
$commands  : Commands
$logger  : LoggerInterface
$description  : string
the Command's short description
$group  : string
The group the command is lumped under when listing commands.
$name  : string
The Command's name
$options  : array<string, string>
the Command's Options
$usage  : string
the Command's usage
$isPcntlAvailable  : bool|null
Cached result of PCNTL extension availability.
$isPosixAvailable  : bool|null
Cached result of POSIX extension availability.
$registeredSignals  : array<int, int>
Array of registered signals.
$running  : bool
Whether the process should continue running (false = termination requested).
$signalMethodMap  : array<int, string>
Signal-to-method mapping.
$signalsBlocked  : bool
Whether signals are currently blocked.

Methods

__construct()  : mixed
__get()  : array<string, string>|Commands|LoggerInterface|string|null
Makes it simple to access our protected properties.
__isset()  : bool
Makes it simple to check our protected properties.
getPad()  : int
Get pad for $key => $value array output
run()  : int|void
Ensures that all migrations have been run.
setPad()  : string
Pads our string out so that all titles are the same length to nicely line up descriptions.
showHelp()  : void
Show Help includes (Usage, Arguments, Description, Options).
blockSignals()  : void
Block ALL interruptible signals during critical sections.
call()  : int|void
Can be used by a command to run other commands.
getProcessState()  : array{pid: int, running: bool, pcntl_available: bool, registered_signals: int, registered_signals_names: array, signals_blocked: bool, explicit_mappings: int, memory_usage_mb: float, memory_peak_mb: float, session_id?: false|int, process_group?: false|int, has_controlling_terminal?: bool}
Get comprehensive process state information.
getSignalName()  : string
Get human-readable signal name.
getSignals()  : array<int, int>
Get list of registered signals.
handleSignal()  : void
Handle incoming signals.
hasSignals()  : bool
Check if signals are registered.
isPcntlAvailable()  : bool
Check if PCNTL extension is available (cached).
isPosixAvailable()  : bool
Check if POSIX extension is available (cached).
isRunning()  : bool
Check if the process is currently running (not terminated).
mapSignal()  : void
Add or update signal-to-method mapping at runtime.
registerSignals()  : void
Register signal handlers.
requestTermination()  : void
Request immediate termination.
resetState()  : void
Reset all states (for testing or restart scenarios).
shouldTerminate()  : bool
Check if command should terminate.
showError()  : void
A simple method to display an error with line/file, in child commands.
signalsBlocked()  : bool
Check if signals are currently blocked.
unblockSignals()  : void
Unblock previously blocked signals.
unregisterSignals()  : void
Unregister all signals (cleanup).
withSignalsBlocked()  : TReturn
Execute a callable with ALL signals blocked to prevent ANY interruption during critical operations.
callCustomHandler()  : void
Call custom signal handler if one is mapped for this signal.

Properties

$description

the Command's short description

protected string $description = 'Locates and runs all new migrations against the database.'

$group

The group the command is lumped under when listing commands.

protected string $group = 'Database'

$name

The Command's name

protected string $name = 'migrate'

$options

the Command's Options

protected array<string, string> $options = ['-n' => 'Set migration namespace', '-g' => 'Set database group', '--all' => 'Set for all namespaces, will ignore (-n) option']

$usage

the Command's usage

protected string $usage = 'migrate [options]'

$isPcntlAvailable

Cached result of PCNTL extension availability.

private static bool|null $isPcntlAvailable = null

$isPosixAvailable

Cached result of POSIX extension availability.

private static bool|null $isPosixAvailable = null

$registeredSignals

Array of registered signals.

private array<int, int> $registeredSignals = []

$running

Whether the process should continue running (false = termination requested).

private bool $running = true

$signalMethodMap

Signal-to-method mapping.

private array<int, string> $signalMethodMap = []

$signalsBlocked

Whether signals are currently blocked.

private bool $signalsBlocked = false

Methods

__construct()

public __construct(LoggerInterface $logger, Commands $commands) : mixed
Parameters
$logger : LoggerInterface
$commands : Commands

__get()

Makes it simple to access our protected properties.

public __get(string $key) : array<string, string>|Commands|LoggerInterface|string|null
Parameters
$key : string
Return values
array<string, string>|Commands|LoggerInterface|string|null

__isset()

Makes it simple to check our protected properties.

public __isset(string $key) : bool
Parameters
$key : string
Return values
bool

getPad()

Get pad for $key => $value array output

public getPad(array<string, string> $array, int $pad) : int

Use setPad() instead.

Parameters
$array : array<string, string>
$pad : int
Tags
codeCoverageIgnore
Return values
int

run()

Ensures that all migrations have been run.

public run(array<string|int, mixed> $params) : int|void
Parameters
$params : array<string|int, mixed>
Return values
int|void

setPad()

Pads our string out so that all titles are the same length to nicely line up descriptions.

public setPad(string $item, int $max[, int $extra = 2 ][, int $indent = 0 ]) : string
Parameters
$item : string
$max : int
$extra : int = 2

How many extra spaces to add at the end

$indent : int = 0
Return values
string

showHelp()

Show Help includes (Usage, Arguments, Description, Options).

public showHelp() : void

blockSignals()

Block ALL interruptible signals during critical sections.

protected blockSignals() : void

Only SIGKILL (unblockable) can terminate the process.

call()

Can be used by a command to run other commands.

protected call(string $command[, array<int|string, string|null> $params = [] ]) : int|void
Parameters
$command : string
$params : array<int|string, string|null> = []
Tags
throws
ReflectionException
Return values
int|void

getProcessState()

Get comprehensive process state information.

protected getProcessState() : array{pid: int, running: bool, pcntl_available: bool, registered_signals: int, registered_signals_names: array, signals_blocked: bool, explicit_mappings: int, memory_usage_mb: float, memory_peak_mb: float, session_id?: false|int, process_group?: false|int, has_controlling_terminal?: bool}
Return values
array{pid: int, running: bool, pcntl_available: bool, registered_signals: int, registered_signals_names: array, signals_blocked: bool, explicit_mappings: int, memory_usage_mb: float, memory_peak_mb: float, session_id?: false|int, process_group?: false|int, has_controlling_terminal?: bool}

getSignalName()

Get human-readable signal name.

protected getSignalName(int $signal) : string
Parameters
$signal : int
Return values
string

getSignals()

Get list of registered signals.

protected getSignals() : array<int, int>
Return values
array<int, int>

handleSignal()

Handle incoming signals.

protected handleSignal(int $signal) : void
Parameters
$signal : int

hasSignals()

Check if signals are registered.

protected hasSignals() : bool
Return values
bool

isPcntlAvailable()

Check if PCNTL extension is available (cached).

protected isPcntlAvailable() : bool
Return values
bool

isPosixAvailable()

Check if POSIX extension is available (cached).

protected isPosixAvailable() : bool
Return values
bool

isRunning()

Check if the process is currently running (not terminated).

protected isRunning() : bool
Return values
bool

mapSignal()

Add or update signal-to-method mapping at runtime.

protected mapSignal(int $signal, string $method) : void
Parameters
$signal : int
$method : string

registerSignals()

Register signal handlers.

protected registerSignals([array<int, int> $signals = [] ][, array<int, string> $methodMap = [] ]) : void
Parameters
$signals : array<int, int> = []

List of signals to handle

$methodMap : array<int, string> = []

Optional signal-to-method mapping

requestTermination()

Request immediate termination.

protected requestTermination() : void

resetState()

Reset all states (for testing or restart scenarios).

protected resetState() : void

shouldTerminate()

Check if command should terminate.

protected shouldTerminate() : bool
Return values
bool

showError()

A simple method to display an error with line/file, in child commands.

protected showError(Throwable $e) : void
Parameters
$e : Throwable

signalsBlocked()

Check if signals are currently blocked.

protected signalsBlocked() : bool
Return values
bool

unblockSignals()

Unblock previously blocked signals.

protected unblockSignals() : void

unregisterSignals()

Unregister all signals (cleanup).

protected unregisterSignals() : void

withSignalsBlocked()

Execute a callable with ALL signals blocked to prevent ANY interruption during critical operations.

protected withSignalsBlocked(callable(): TReturn $operation) : TReturn

This blocks ALL interruptible signals including:

  • Termination signals (SIGTERM, SIGINT, etc.)
  • Pause/resume signals (SIGTSTP, SIGCONT)
  • Custom signals (SIGUSR1, SIGUSR2)

Only SIGKILL (unblockable) can still terminate the process. Use this for database transactions, file operations, or any critical atomic operations.

Parameters
$operation : callable(): TReturn
Tags
template
Return values
TReturn

callCustomHandler()

Call custom signal handler if one is mapped for this signal.

private callCustomHandler(int $signal) : void

Falls back to generic onInterruption() method if no explicit mapping exists.

Parameters
$signal : int

        
On this page

Search results