diff --git a/src/command/PSFSConsole.php b/src/command/PSFSConsole.php index 5871b94..69fd7ad 100644 --- a/src/command/PSFSConsole.php +++ b/src/command/PSFSConsole.php @@ -2,7 +2,6 @@ namespace PSFS\command; -use PSFS\base\Router; use Symfony\Component\Console\Application; use Symfony\Component\Finder\Finder; @@ -15,7 +14,6 @@ require_once $dir . 'autoload.php'; - $project_path = $pwd . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR; if (file_exists($project_path . "bootstrap.php")) { include_once($project_path . "bootstrap.php"); @@ -33,12 +31,16 @@ foreach ($commands as $com) if ($com->isFile()) include_once($com->getRealPath()); //Hidratamos con los comandos de los módulos -$domains = Router::getInstance()->getDomains(); +$domains = \PSFS\base\Router::getInstance()->getDomains(); foreach ($domains as $domain => $paths) { - if (!preg_match('/ROOT/i', $domain)) { + if ((false === stripos($domain, "ROOT")) && file_exists($paths['base'])) { $commands = new Finder(); $commands->in($paths['base'])->path("Command")->name("*.php"); - foreach ($commands as $com) include_once($com->getRealPath()); + foreach ($commands as $com) { + if ($com->isFile()) { + include_once($com->getRealPath()); + } + } } } diff --git a/src/command/UpgradeProject.php b/src/command/UpgradeProject.php index c18302f..8cf2ab0 100644 --- a/src/command/UpgradeProject.php +++ b/src/command/UpgradeProject.php @@ -2,9 +2,8 @@ namespace PSFS\Command; -use PSFS\base\Router; -use PSFS\services\GeneratorService; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -14,21 +13,40 @@ $console ->register('psfs:update:project') ->setDescription(t('Actualización de configuraciones de proyectos en PSFS')) - ->setCode(function (InputInterface $input, OutputInterface $output) { - - $modules = Router::getInstance()->getDomains(); + ->setCode(function (InputInterface $input, OutputInterface $output) use ($console) { + // Clean up config files... + if(file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json')) { + rename(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json.bak'); + } + if(file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json')) { + rename(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json.bak'); + } + $modules = \PSFS\base\Router::getInstance()->getDomains(); $output->writeln("Hay un total de " . (count($modules) - 1) . " ha actualizar"); foreach ($modules as $module => $config) { $clean_module = str_replace(['@', '\\', '/'], '', $module); if ($clean_module !== 'ROOT') { $output->write("\t- Actualizando módulo {$clean_module}"); - GeneratorService::getInstance()->generateConfigurationTemplates($clean_module, $config['base']); + $configPath = $config['base'] . DIRECTORY_SEPARATOR . 'Config'; + // Cleaning up config files and autoloader + if(file_exists($configPath . DIRECTORY_SEPARATOR . 'domains.json')) { + rename($configPath . DIRECTORY_SEPARATOR . 'config.php', $configPath . DIRECTORY_SEPARATOR . 'config.php.bak'); + } + if(file_exists($configPath . DIRECTORY_SEPARATOR . 'propel.yml')) { + unlink($configPath . DIRECTORY_SEPARATOR . 'propel.yml'); + } + \PSFS\services\GeneratorService::getInstance()->generateConfigurationTemplates($clean_module, $config['base']); $output->writeln("\tDONE!"); } } - $router = Router::getInstance(); + $router = \PSFS\base\Router::getInstance(); $router->hydrateRouting(); $router->simpatize(); $output->writeln(t("Rutas del proyecto actualizadas con éxito")); + // Run the deployment command + $commandInput = new ArrayInput([ + 'command' => 'psfs:deploy:project', + ]); + $console->run($commandInput, $output); }); diff --git a/src/functions.php b/src/functions.php index 1c4d937..8f3c2f4 100644 --- a/src/functions.php +++ b/src/functions.php @@ -43,7 +43,7 @@ function getallheaders(): array /* @var $file SplFileInfo */ foreach ($finder as $file) { $path = $file->getRealPath(); - if (!in_array($path, $loaded_files)) { + if (!in_array($path, $loaded_files, true) && file_exists($path)) { $loaded_files[] = $path; require_once($path); }