Просмотр файла libarea-0.9/app/Commands/Migration/Run.php

Размер файла: 3.11Kb
<?php
/*
 ┌───────────────────────────────────────────────────────────┐
 │                          ATTENTION                        │
 ├───────────────────────────────────────────────────────────┤
 │                                                           │
 │ This file is automatically generated.                     │
 │ All changes made will be lost when updating the library.  │
 │                                                           │
 │                                                           │
 ├───────────────────────────────────────────────────────────┤
 │                          ВНИМАНИЕ                         │
 ├───────────────────────────────────────────────────────────┤
 │                                                           │
 │ Этот файл сгенерирован автоматически.                     │
 │ Все внесённые изменения будут потеряны при обновлении.    │
 │                                                           │
 │                                                           │
 └───────────────────────────────────────────────────────────┘
 */

declare(strict_types=1);

namespace App\Commands\Migration;

use Hleb\Base\Task;
use Hleb\Static\DB;
use Hleb\Static\Settings;
use Phphleb\Migration\Src\MigrateException;
use Phphleb\Migration\Src\Migration;
use Throwable;

class Run extends Task
{
    /**
     * Running migrations.
     *
     * Выполняет миграции.
     *
     * @param string|null $notify - the --no-notify value disables notifications.
     *                            - значение --no-notify отключает оповещения.
     * @throws Throwable
     */
    protected function run(?string $notify = null): int
    {
        if ($notify !== null && $notify !== '--no-notify') {
            throw new MigrateException('The value may be absent or match --no-notify');
        }
        try {
            $migrations = (new Migration(
                DB::getNewInstance(),
                'migrations',
                Settings::getPath('@global/migrations'),
                $notify === null,
            ))->run();

            if ($migrations) {
                echo PHP_EOL . ' ✔ ' . implode(PHP_EOL . ' ✔ ', $migrations) . PHP_EOL;
            }
        } catch (MigrateException $e) {
            echo PHP_EOL . 'ERROR: ' . $e->getMessage() . PHP_EOL;

            return self::ERROR_CODE;
        }
        return self::SUCCESS_CODE;
    }
}