mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-26 14:04:17 +01:00
Use low level env init on migrate:run + migrate:to
This commit is contained in:
4
aac
4
aac
@@ -25,7 +25,9 @@ foreach ($commandsGlob as $item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$commandPre = '\\MyAAC\Commands\\';
|
$commandPre = '\\MyAAC\Commands\\';
|
||||||
$application->add(new ($commandPre . $name));
|
if (!trait_exists($class = $commandPre . $name)) {
|
||||||
|
$application->add(new $class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$pluginCommands = Plugins::getCommands();
|
$pluginCommands = Plugins::getCommands();
|
||||||
|
|||||||
33
system/src/Commands/Env.php
Normal file
33
system/src/Commands/Env.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MyAAC\Commands;
|
||||||
|
|
||||||
|
use POT;
|
||||||
|
|
||||||
|
trait Env
|
||||||
|
{
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
if (!isset($config['installed']) || !$config['installed']) {
|
||||||
|
throw new \RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($config['server_path'])) {
|
||||||
|
throw new \RuntimeException('Server Path has been not set. Go to config.php and set it.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// take care of trailing slash at the end
|
||||||
|
if($config['server_path'][strlen($config['server_path']) - 1] !== '/')
|
||||||
|
$config['server_path'] .= '/';
|
||||||
|
|
||||||
|
$config['lua'] = load_config_lua($config['server_path'] . 'config.lua');
|
||||||
|
|
||||||
|
// POT
|
||||||
|
require_once SYSTEM . 'libs/pot/OTS.php';
|
||||||
|
$ots = POT::getInstance();
|
||||||
|
$eloquentConnection = null;
|
||||||
|
|
||||||
|
require_once SYSTEM . 'database.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|||||||
|
|
||||||
class MigrateRunCommand extends Command
|
class MigrateRunCommand extends Command
|
||||||
{
|
{
|
||||||
|
use Env;
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->setName('migrate:run')
|
$this->setName('migrate:run')
|
||||||
@@ -23,12 +25,12 @@ class MigrateRunCommand extends Command
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
require SYSTEM . 'init.php';
|
|
||||||
|
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$ids = $input->getArgument('id');
|
$ids = $input->getArgument('id');
|
||||||
|
|
||||||
|
$this->init();
|
||||||
|
|
||||||
// pre-check
|
// pre-check
|
||||||
// in case one of the migrations doesn't exist - we won't execute any of them
|
// in case one of the migrations doesn't exist - we won't execute any of them
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|||||||
|
|
||||||
class MigrateToCommand extends Command
|
class MigrateToCommand extends Command
|
||||||
{
|
{
|
||||||
|
use Env;
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->setName('migrate:to')
|
$this->setName('migrate:to')
|
||||||
@@ -32,7 +34,7 @@ class MigrateToCommand extends Command
|
|||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->initEnv();
|
$this->init();
|
||||||
|
|
||||||
$currentVersion = Config::where('name', 'database_version')->first()->value;
|
$currentVersion = Config::where('name', 'database_version')->first()->value;
|
||||||
if ($currentVersion > $versionDest) {
|
if ($currentVersion > $versionDest) {
|
||||||
@@ -80,29 +82,4 @@ class MigrateToCommand extends Command
|
|||||||
|
|
||||||
updateDatabaseConfig('database_version', ($_up ? $id : $id - 1));
|
updateDatabaseConfig('database_version', ($_up ? $id : $id - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initEnv()
|
|
||||||
{
|
|
||||||
global $config;
|
|
||||||
if (!isset($config['installed']) || !$config['installed']) {
|
|
||||||
throw new \RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(empty($config['server_path'])) {
|
|
||||||
throw new \RuntimeException('Server Path has been not set. Go to config.php and set it.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// take care of trailing slash at the end
|
|
||||||
if($config['server_path'][strlen($config['server_path']) - 1] !== '/')
|
|
||||||
$config['server_path'] .= '/';
|
|
||||||
|
|
||||||
$config['lua'] = load_config_lua($config['server_path'] . 'config.lua');
|
|
||||||
|
|
||||||
// POT
|
|
||||||
require_once SYSTEM . 'libs/pot/OTS.php';
|
|
||||||
$ots = POT::getInstance();
|
|
||||||
$eloquentConnection = null;
|
|
||||||
|
|
||||||
require_once SYSTEM . 'database.php';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user