/** * @param OutputInterface $output */ public function loadCommands(OutputInterface $output) { // $application is required to be defined in the register_command scripts $application = $this->application; require_once \OC::$SERVERROOT . '/core/register_command.php'; if ($this->config->getSystemValue('installed', false)) { if (!\OCP\Util::needUpgrade()) { OC_App::loadApps(); foreach (OC_App::getAllApps() as $app) { $file = OC_App::getAppPath($app) . '/appinfo/register_command.php'; if (file_exists($file)) { require $file; } } } else { $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available"); } } else { $output->writeln("ownCloud is not installed - only a limited number of commands are available"); } $input = new ArgvInput(); if ($input->getFirstArgument() !== 'check') { $errors = \OC_Util::checkServer(\OC::$server->getConfig()); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln($error['error']); $output->writeln($error['hint']); $output->writeln(''); } throw new \Exception("Environment not properly prepared."); } } }
public function isSafe(ArgvInput $input, $env) { if ('prod' == $env) { if (in_array($input->getFirstArgument(), $this->productionBlackList)) { return false; } } return true; }
/** * Determine whether a CLI command is for compilation, and if so, clear the directory * * @throws \Magento\Framework\Exception\FileSystemException * @return void */ public function handleCompilerEnvironment() { $compilationCommands = [DiCompileCommand::NAME, DiCompileMultiTenantCommand::NAME]; $cmdName = $this->input->getFirstArgument(); $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h'); if (!in_array($cmdName, $compilationCommands) || $isHelpOption) { return; } $generationDir = $cmdName === DiCompileMultiTenantCommand::NAME ? $this->input->getParameterOption(DiCompileMultiTenantCommand::INPUT_KEY_GENERATION) : null; if (!$generationDir) { $mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $generationDir = (new DirectoryList(BP, $mageDirs))->getPath(DirectoryList::GENERATION); } if ($this->filesystemDriver->isExists($generationDir)) { $this->filesystemDriver->deleteDirectory($generationDir); } }
/** * Determine whether a CLI command is for compilation, and if so, clear the directory * * @throws \Magento\Framework\Exception\FileSystemException * @return void */ public function handleCompilerEnvironment() { $compilationCommands = [DiCompileCommand::NAME]; $cmdName = $this->input->getFirstArgument(); $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h'); if (!in_array($cmdName, $compilationCommands) || $isHelpOption) { return; } $compileDirList = []; $mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $directoryList = new DirectoryList(BP, $mageDirs); $compileDirList[] = $directoryList->getPath(DirectoryList::GENERATION); $compileDirList[] = $directoryList->getPath(DirectoryList::DI); foreach ($compileDirList as $compileDir) { if ($this->filesystemDriver->isExists($compileDir)) { $this->filesystemDriver->deleteDirectory($compileDir); } } }
/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); /** @var Application $application */ $application = $command->getApplication(); $inputDefinition = $command->getDefinition(); if ($command instanceof HelpCommand) { $input = new ArgvInput(); $input->bind($inputDefinition); $command = $application->find($input->getFirstArgument()); } if ($command instanceof BaseCommand) { $this->setInputDefinition($inputDefinition); } }
/** * @param OutputInterface $output * @throws \Exception */ public function loadCommands(OutputInterface $output) { // $application is required to be defined in the register_command scripts $application = $this->application; require_once __DIR__ . '/../../../core/register_command.php'; if ($this->config->getSystemValue('installed', false)) { if (\OCP\Util::needUpgrade()) { $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available"); $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); } elseif ($this->config->getSystemValue('maintenance', false)) { $output->writeln("ownCloud is in maintenance mode - no app have been loaded"); } else { OC_App::loadApps(); foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { $appPath = \OC_App::getAppPath($app); if ($appPath === false) { continue; } \OC::$loader->addValidRoot($appPath); $file = $appPath . '/appinfo/register_command.php'; if (file_exists($file)) { require $file; } } } } else { $output->writeln("ownCloud is not installed - only a limited number of commands are available"); } $input = new ArgvInput(); if ($input->getFirstArgument() !== 'check') { $errors = \OC_Util::checkServer(\OC::$server->getConfig()); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln((string) $error['error']); $output->writeln((string) $error['hint']); $output->writeln(''); } throw new \Exception("Environment not properly prepared."); } } }
public function testGetFirstArgument() { $input = new ArgvInput(array('cli.php', '-fbbar')); $this->assertEquals('', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input'); $input = new ArgvInput(array('cli.php', '-fbbar', 'foo')); $this->assertEquals('foo', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input'); }
/** * @param InputInterface $input * @param OutputInterface $output * @throws \Exception */ public function loadCommands(InputInterface $input, OutputInterface $output) { // $application is required to be defined in the register_command scripts $application = $this->application; $inputDefinition = $application->getDefinition(); $inputDefinition->addOption(new InputOption('no-warnings', null, InputOption::VALUE_NONE, 'Skip global warnings, show command output only', null)); try { $input->bind($inputDefinition); } catch (\RuntimeException $e) { //expected if there are extra options } if ($input->getOption('no-warnings')) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } require_once __DIR__ . '/../../../core/register_command.php'; if ($this->config->getSystemValue('installed', false)) { if (\OCP\Util::needUpgrade()) { $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available"); $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); } elseif ($this->config->getSystemValue('maintenance', false)) { $output->writeln("ownCloud is in maintenance mode - no app have been loaded"); } else { OC_App::loadApps(); foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { $appPath = \OC_App::getAppPath($app); if ($appPath === false) { continue; } \OC::$loader->addValidRoot($appPath); $file = $appPath . '/appinfo/register_command.php'; if (file_exists($file)) { require $file; } } } } else { $output->writeln("ownCloud is not installed - only a limited number of commands are available"); } $input = new ArgvInput(); if ($input->getFirstArgument() !== 'check') { $errors = \OC_Util::checkServer(\OC::$server->getConfig()); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln((string) $error['error']); $output->writeln((string) $error['hint']); $output->writeln(''); } throw new \Exception("Environment not properly prepared."); } } }
/** * Bootstrap the application events. * * @return void */ public function boot() { $this->publishes([__DIR__ . '/../config/propel.php' => config_path('propel.php')]); if (!$this->app->config['propel.propel.runtime.connections']) { throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.'); } // load pregenerated config if (file_exists(app_path() . '/propel/config.php')) { Propel::init(app_path() . '/propel/config.php'); return; } // runtime configuration /** @var \Propel\Runtime\ServiceContainer\StandardServiceContainer */ $serviceContainer = \Propel\Runtime\Propel::getServiceContainer(); $serviceContainer->closeConnections(); $serviceContainer->checkVersion('2.0.0-dev'); $propel_conf = $this->app->config['propel.propel']; $runtime_conf = $propel_conf['runtime']; // set connections foreach ($runtime_conf['connections'] as $connection_name) { $config = $propel_conf['database']['connections'][$connection_name]; if (!isset($config['classname'])) { if ($this->app->config['app.debug']) { $config['classname'] = '\\Propel\\Runtime\\Connection\\DebugPDO'; } else { $config['classname'] = '\\Propel\\Runtime\\Connection\\ConnectionWrapper'; } } $serviceContainer->setAdapterClass($connection_name, $config['adapter']); $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle(); $manager->setConfiguration($config + [$propel_conf['paths']]); $manager->setName($connection_name); $serviceContainer->setConnectionManager($connection_name, $manager); } $serviceContainer->setDefaultDatasource($runtime_conf['defaultConnection']); // set loggers $has_default_logger = false; if (isset($runtime_conf['log'])) { foreach ($runtime_conf['log'] as $logger_name => $logger_conf) { $serviceContainer->setLoggerConfiguration($logger_name, $logger_conf); $has_default_logger |= $logger_name === 'defaultLogger'; } } if (!$has_default_logger) { $serviceContainer->setLogger('defaultLogger', \Log::getMonolog()); } Propel::setServiceContainer($serviceContainer); $command = false; if (\App::runningInConsole()) { $input = new ArgvInput(); $command = $input->getFirstArgument(); } // skip auth driver adding if running as CLI to avoid auth model not found if ('propel:model:build' !== $command && 'propel' === \Config::get('auth.driver')) { $query_name = \Config::get('auth.user_query', false); if ($query_name) { $query = new $query_name(); if (!$query instanceof Criteria) { throw new InvalidConfigurationException("Configuration directive «auth.user_query» must contain valid classpath of user Query. Excpected type: instanceof Propel\\Runtime\\ActiveQuery\\Criteria"); } } else { $user_class = \Config::get('auth.model'); $query = new $user_class(); if (!method_exists($query, 'buildCriteria')) { throw new InvalidConfigurationException("Configuration directive «auth.model» must contain valid classpath of model, which has method «buildCriteria()»"); } $query = $query->buildPkeyCriteria(); $query->clear(); } \Auth::extend('propel', function (\Illuminate\Foundation\Application $app) use($query) { return new PropelUserProvider($query, $app->make('hash')); }); } }
/** * Register propel auth provider. * * @return void */ protected function registerPropelAuth() { $command = false; if (\App::runningInConsole()) { $input = new ArgvInput(); $command = $input->getFirstArgument(); } // skip auth driver adding if running as CLI to avoid auth model not found if ('propel:model:build' === $command) { return; } $query_name = \Config::get('auth.user_query', false); if ($query_name) { $query = new $query_name(); if (!$query instanceof Criteria) { throw new InvalidConfigurationException("Configuration directive «auth.user_query» must contain valid classpath of user Query. Excpected type: instanceof Propel\\Runtime\\ActiveQuery\\Criteria"); } } else { $user_class = \Config::get('auth.model'); $query = new $user_class(); if (!method_exists($query, 'buildCriteria')) { throw new InvalidConfigurationException("Configuration directive «auth.model» must contain valid classpath of model, which has method «buildCriteria()»"); } $query = $query->buildPkeyCriteria(); $query->clear(); } \Auth::extend('propel', function (Application $app) use($query) { return new Auth\PropelUserProvider($query, $app->make('hash')); }); }