protected function execute(InputInterface $input, OutputInterface $output)
 {
     $url = $input->getOption('url');
     $email = $input->getOption('email');
     $disable = $input->getOption('disable');
     $events = $input->getOption('event');
     if (!$url && !$email) {
         $output->writeln('<error>Must specify either a url or an email address</error>');
         return;
     }
     if ($url && $email) {
         $output->writeln('<error>Must specify only a url or an email address</error>');
         return;
     }
     if (!($resource = $this->getResource('webhook', $output))) {
         return;
     }
     if ($url) {
         $resource->setUrl($url);
     } else {
         $resource->setEmail($email);
     }
     $resource->setEventTypes($events ? $events : Webhook::$events);
     $this->getApi()->create($resource);
     $resource = $this->getApi()->getLastResponse();
     $resource = $resource['body']['data'];
     $table = $this->getHelperSet()->get('table');
     $this->formatTableRow($resource, $table, false);
     $output->writeln('<info>Webhook created</info>');
     $table->render($output);
 }
Exemplo n.º 2
2
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws InvalidArgumentException
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output, true);
     if (!$this->initMagento()) {
         return;
     }
     $type = $input->getArgument('type');
     $areas = array('global', 'adminhtml', 'frontend', 'crontab');
     if ($type === null) {
         $type = $this->askForArrayEntry($areas, $output, 'Please select an area:');
     }
     if (!in_array($type, $areas)) {
         throw new InvalidArgumentException('Invalid type! Use one of: ' . implode(', ', $areas));
     }
     if ($input->getOption('format') === null) {
         $this->writeSection($output, 'Observers: ' . $type);
     }
     $frontendEvents = \Mage::getConfig()->getNode($type . '/events')->asArray();
     if (true === $input->getOption('sort')) {
         // sorting for Observers is a bad idea because the order in which observers will be called is important.
         ksort($frontendEvents);
     }
     $table = array();
     foreach ($frontendEvents as $eventName => $eventData) {
         $observerList = array();
         foreach ($eventData['observers'] as $observer) {
             $observerList[] = $this->getObserver($observer, $type);
         }
         $table[] = array($eventName, implode("\n", $observerList));
     }
     $this->getHelper('table')->setHeaders(array('Event', 'Observers'))->setRows($table)->renderByFormat($output, $table, $input->getOption('format'));
 }
Exemplo n.º 3
1
 /**
  * {@inheritdoc}
  */
 protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
 {
     // only list constants when no Reflector is present.
     //
     // TODO: make a NamespaceReflector and pass that in for commands like:
     //
     //     ls --constants Foo
     //
     // ... for listing constants in the Foo namespace
     if ($reflector !== null || $target !== null) {
         return;
     }
     // only list constants if we are specifically asked
     if (!$input->getOption('constants')) {
         return;
     }
     $category = $input->getOption('user') ? 'user' : $input->getOption('category');
     $label = $category ? ucfirst($category) . ' Constants' : 'Constants';
     $constants = $this->prepareConstants($this->getConstants($category));
     if (empty($constants)) {
         return;
     }
     $ret = array();
     $ret[$label] = $constants;
     return $ret;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
     $oldCacheDir = $realCacheDir . '_old';
     $filesystem = $this->getContainer()->get('filesystem');
     if (!is_writable($realCacheDir)) {
         throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
     }
     if ($filesystem->exists($oldCacheDir)) {
         $filesystem->remove($oldCacheDir);
     }
     $kernel = $this->getContainer()->get('kernel');
     $output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
     $this->getContainer()->get('cache_clearer')->clear($realCacheDir);
     if ($input->getOption('no-warmup')) {
         $filesystem->rename($realCacheDir, $oldCacheDir);
     } else {
         // the warmup cache dir name must have the same length than the real one
         // to avoid the many problems in serialized resources files
         $warmupDir = substr($realCacheDir, 0, -1) . '_';
         if ($filesystem->exists($warmupDir)) {
             $filesystem->remove($warmupDir);
         }
         $this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
         $filesystem->rename($realCacheDir, $oldCacheDir);
         if (defined('PHP_WINDOWS_VERSION_BUILD')) {
             sleep(1);
             // workaround for windows php rename bug
         }
         $filesystem->rename($warmupDir, $realCacheDir);
     }
     $filesystem->remove($oldCacheDir);
 }
Exemplo n.º 5
0
 /**
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $key = $input->getArgument('key');
     if ($input->getOption('file')) {
         $file = $input->getOption('file');
     } else {
         $file = 'config.yml';
     }
     try {
         $yaml = new YamlUpdater($this->app, $file);
         $match = $yaml->get($key);
         if (!empty($match)) {
             $result = sprintf("%s: %s", $key, $match);
         } else {
             $result = sprintf("<error>The key '%s' was not found in %s.</error>", $key, $file);
         }
     } catch (FileNotFoundException $e) {
         $result = sprintf("<error>Can't read file: %s.</error>", $file);
     } catch (ParseException $e) {
         $result = sprintf("<error>Invalid YAML in file: %s.</error>", $file);
     } catch (FilesystemException $e) {
         $result = sprintf('<error>' . $e->getMessage() . '</error>');
     }
     $output->writeln($result);
 }
Exemplo n.º 6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('list')) {
         $this->listImport($output);
         return;
     }
     $importRef = $input->getArgument('ref');
     $path = $input->getArgument('filePath');
     if ($importRef === null || $path === null) {
         throw new \RuntimeException('Not enough arguments.' . PHP_EOL . 'If no options are provided, ref and filePath arguments are required.');
     }
     /** @var \Thelia\Handler\ImportHandler $importHandler */
     $importHandler = $this->getContainer()->get('thelia.import.handler');
     $import = $importHandler->getImportByRef($importRef);
     if ($import === null) {
         throw new \RuntimeException($importRef . ' import doesn\'t exist.');
     }
     $importEvent = $importHandler->import($import, new File($input->getArgument('filePath')), (new LangQuery())->findOneByLocale($input->getOption('locale')));
     $formattedLine = $this->getHelper('formatter')->formatBlock('Successfully import ' . $importEvent->getImport()->getImportedRows() . ' row(s)', 'fg=black;bg=green', true);
     $output->writeln($formattedLine);
     if (count($importEvent->getErrors()) > 0) {
         $formattedLine = $this->getHelper('formatter')->formatBlock('With error', 'fg=black;bg=yellow', true);
         $output->writeln($formattedLine);
         foreach ($importEvent->getErrors() as $error) {
             $output->writeln('<comment>' . $error . '</comment>');
         }
     }
 }
Exemplo n.º 7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     foreach ($this->dropOrder as $option) {
         if ($input->getOption($option)) {
             $drop[] = $option;
         }
     }
     // Default to the full drop order if no options were specified
     $drop = empty($drop) ? $this->dropOrder : $drop;
     $class = $input->getOption('class');
     $sm = $this->getSchemaManager();
     $isErrored = false;
     foreach ($drop as $option) {
         try {
             if (isset($class)) {
                 $this->{'processDocument' . ucfirst($option)}($sm, $class);
             } else {
                 $this->{'process' . ucfirst($option)}($sm);
             }
             $output->writeln(sprintf('Dropped <comment>%s%s</comment> for <info>%s</info>', $option, isset($class) ? self::INDEX === $option ? '(es)' : '' : (self::INDEX === $option ? 'es' : 's'), isset($class) ? $class : 'all classes'));
         } catch (\Exception $e) {
             $output->writeln('<error>' . $e->getMessage() . '</error>');
             $isErrored = true;
         }
     }
     return $isErrored ? 255 : 0;
 }
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getDialogHelper();
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output, $dialog);
     }
     $input->setOption('module', $module);
     // --bundle-name option
     $bundle_name = $input->getOption('bundle-name');
     if (!$bundle_name) {
         $bundle_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.contenttype.questions.bundle-name'), 'default'), function ($bundle_name) {
             return $this->validateClassName($bundle_name);
         }, false, 'default', null);
     }
     $input->setOption('bundle-name', $bundle_name);
     // --bundle-title option
     $bundle_title = $input->getOption('bundle-title');
     if (!$bundle_title) {
         $bundle_title = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.contenttype.questions.bundle-title'), 'default'), function ($bundle_title) {
             return $this->validateClassName($bundle_title);
         }, false, 'default', null);
     }
     $input->setOption('bundle-title', $bundle_title);
 }
Exemplo n.º 9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     ini_set('memory_limit', -1);
     set_time_limit(0);
     $this->output = $output;
     $this->em = $this->getContainer()->get('doctrine')->getManager();
     $siteId = (int) $input->getOption('site_id');
     $this->site = $this->em->getRepository('SudouxCmsSiteBundle:Site')->find($siteId);
     if (!isset($this->site)) {
         throw new \Exception("Site was not found");
     }
     $availableFunctions = array('import_branches_from_csv');
     $function = $input->getArgument('function');
     if (!in_array($function, $availableFunctions)) {
         throw new \Exception("Function does not exist");
     }
     switch ($function) {
         case 'import_branches_from_csv':
             $csvPath = $input->getOption('csv_path');
             if (empty($csvPath)) {
                 throw new \Exception("Option --csv_path cannot be empty");
             }
             $this->importBranchesFromCsv($csvPath);
             break;
     }
 }
Exemplo n.º 10
0
 /**
  * Execute the command.
  *
  * @param Input $input
  * @param Output $output
  * @return void
  */
 protected function execute(Input $input, Output $output)
 {
     $name = $input->getArgument("name");
     // Validate the name straight away.
     if (count($chunks = explode("/", $name)) != 2) {
         throw new \InvalidArgumentException("Invalid repository name '{$name}'.");
     }
     $output->writeln(sprintf("Cloning <comment>%s</comment> into <info>%s/%s</info>...", $name, getcwd(), end($chunks)));
     // If we're in a test environment, stop executing.
     if (defined("ADVISER_UNDER_TEST")) {
         return null;
     }
     // @codeCoverageIgnoreStart
     if (!$this->git->cloneGithubRepository($name)) {
         throw new \UnexpectedValueException("Repository https://github.com/{$name} doesn't exist.");
     }
     // Change the working directory.
     chdir($path = getcwd() . "/" . end($chunks));
     $output->writeln(sprintf("Changed the current working directory to <comment>%s</comment>.", $path));
     $output->writeln("");
     // Running "AnalyseCommand"...
     $arrayInput = [""];
     if (!is_null($input->getOption("formatter"))) {
         $arrayInput["--formatter"] = $input->getOption("formatter");
     }
     $this->getApplication()->find("analyse")->run(new ArrayInput($arrayInput), $output);
     // Change back, remove the directory.
     chdir(getcwd() . "/..");
     $this->removeDirectory($path);
     $output->writeln("");
     $output->writeln(sprintf("Switching back to <info>%s</info>, removing <comment>%s</comment>...", getcwd(), $path));
     // @codeCoverageIgnoreStop
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $noDevMode = (bool) $input->getOption('no-dev');
     $optimize = (bool) $input->getOption('optimize-autoloader');
     $build = new Build(new ConsoleIO($input, $output, $this->getHelperSet()));
     $build->build(getcwd(), $optimize, $noDevMode);
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $step = $input->getArgument('step');
     $config = $this->getSuiteConfig($suite, $input->getOption('config'));
     $class = $this->getClassName($step);
     $path = $this->buildPath(Configuration::supportDir() . 'Step' . DIRECTORY_SEPARATOR . ucfirst($suite), $step);
     $dialog = $this->getHelperSet()->get('question');
     $filename = $path . $class . '.php';
     $helper = $this->getHelper('question');
     $question = new Question("Add action to StepObject class (ENTER to exit): ");
     $gen = new StepObjectGenerator($config, ucfirst($suite) . '\\' . $step);
     if (!$input->getOption('silent')) {
         do {
             $question = new Question('Add action to StepObject class (ENTER to exit): ', null);
             $action = $dialog->ask($input, $output, $question);
             if ($action) {
                 $gen->createAction($action);
             }
         } while ($action);
     }
     $res = $this->save($filename, $gen->produce());
     if (!$res) {
         $output->writeln("<error>StepObject {$filename} already exists</error>");
         exit;
     }
     $output->writeln("<info>StepObject was created in {$filename}</info>");
 }
Exemplo n.º 13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Start checking the database!');
     $connFile = $input->getOption('config');
     $this->conn = file_exists($connFile) ? require_once $connFile : $this->conn;
     if (!$this->conn instanceof Connection) {
         throw new \Exception('It\'s not available db connection object.');
     }
     $checker = new SchemaChecker($this->conn);
     $structureFile = $input->getOption('structure');
     if (!file_exists($structureFile)) {
         throw new \Exception('Structure file not exists!');
     }
     $sql = $checker->getDiffSql($structureFile);
     if (empty($sql)) {
         $output->writeln('Nothing has changed.');
     } else {
         $output->writeln('Began to update the database.');
         $output->writeln('//sql--------------------');
         foreach ($sql as $s) {
             $output->writeln($s . ';');
             $this->conn->query($s);
         }
         $output->writeln('\\\\end sql----------------');
         $output->writeln('Database has been updated!');
     }
 }
Exemplo n.º 14
0
 /**
  * finds a list of packages which depend on another package
  *
  * @param  InputInterface            $input
  * @param  OutputInterface           $output
  * @param  Composer                  $composer
  * @return array
  * @throws \InvalidArgumentException
  */
 private function getReferences(InputInterface $input, OutputInterface $output, Composer $composer)
 {
     $needle = $input->getArgument('package');
     $references = array();
     $verbose = (bool) $input->getOption('verbose');
     $repos = $composer->getRepositoryManager()->getRepositories();
     $types = $input->getOption('link-type');
     foreach ($repos as $repository) {
         foreach ($repository->getPackages() as $package) {
             foreach ($types as $type) {
                 $type = rtrim($type, 's');
                 if (!isset($this->linkTypes[$type])) {
                     throw new \InvalidArgumentException('Unexpected link type: ' . $type . ', valid types: ' . implode(', ', array_keys($this->linkTypes)));
                 }
                 foreach ($package->{'get' . $this->linkTypes[$type]}() as $link) {
                     if ($link->getTarget() === $needle) {
                         if ($verbose) {
                             $references[] = array($type, $package, $link);
                         } else {
                             $references[$package->getName()] = $package->getPrettyName();
                         }
                     }
                 }
             }
         }
     }
     return $references;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $i = 0;
     $kernel = $this->getContainer()->get('kernel');
     $doctrine = $this->getContainer()->get('doctrine');
     $entityManager = $doctrine->getEntityManager();
     $cron = new Cron();
     $cron->setTimestamp(time());
     $cron->setAction('Observe Alarms Start');
     $entityManager->persist($cron);
     $entityManager->flush();
     $isSandbox = $input->getOption('sandbox');
     $isEmulation = $input->getOption('emulate');
     $output->writeln('Sandbox: ' . $isSandbox);
     $output->writeln('Emulation: ' . $isEmulation);
     // operating under the assumption that this thing is executed by a cronjob, this thing needs to be run for just a minute
     $intervalSpent = 0;
     while ($intervalSpent <= self::CRON_INTERVAL) {
         $detector = new AlarmDetector($doctrine);
         $detector->detectAlarms($isEmulation);
         $output->writeln(PHP_EOL . ++$i . PHP_EOL);
         usleep(self::CHECK_INTERVAL);
         // 250ms
         $intervalSpent += self::CHECK_INTERVAL;
     }
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $newWidth = $input->getOption('size');
     $inverted = filter_var($input->getOption('inverted'), FILTER_VALIDATE_BOOLEAN);
     $chars = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('AsciiArtAnalyzerBundle:Char')->getAllChars($inverted);
     $manager = new ImageManager(['driver' => 'imagick']);
     $image = $manager->make("files/image.jpg");
     /**
      * @var \Imagick $imagick
      */
     $imagick = $image->resize($newWidth, $newWidth / $image->getWidth() * $image->getHeight())->getCore();
     list($width, $height) = array_values($imagick->getImageGeometry());
     $ascii = [];
     foreach (range(1, $height) as $y) {
         $string = "";
         foreach (range(1, $width) as $x) {
             $rgb = $imagick->getImagePixelColor($x, $y)->getColor();
             $pixelLuminosity = intval(($rgb['r'] + $rgb['g'] + $rgb['b']) / 3);
             $string .= $chars[$pixelLuminosity];
         }
         array_push($ascii, $string);
     }
     if ($input->getOption('output') == 'image') {
         $this->asciiToImage($ascii, $inverted);
     } else {
         echo implode("\n", $ascii);
     }
 }
Exemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<comment>Scan begining.</comment>');
     $result = $this->getContainer()->get('dokapi.swagger.scanner')->scan();
     $output->writeln('<comment>Scan done.</comment>');
     $apis = $result->getAll('api');
     $output->writeln(sprintf('<info>%s api(s) detected(s)</info>', count($apis)));
     if ($input->getOption('verbose')) {
         foreach ($result->getAll('api') as $api) {
             $output->writeln(sprintf('-----------------------------------------------------------------'));
             $output->writeln(sprintf('--- Api version: <info>%s</info>, path: <info>%s</info>', $api->getVersion(), $api->getPath()));
             $output->writeln(sprintf('-----------------------------------------------------------------'));
             foreach ($api->getResources() as $resource) {
                 $output->writeln(sprintf('------ Resource: <comment>%s</comment>', $resource->getId()));
                 foreach ($resource->getOperations() as $operation) {
                     $output->writeln(sprintf('--------- <comment>%s</comment>, path: <comment>%s</comment>, parameters: <comment>%s</comment>, responses: <comment>%s</comment>', $operation->getId(), $operation->getPath(), count($operation->getParameters()), count($operation->getResponses())));
                 }
             }
         }
     }
     if ($outputDir = $input->getOption('output-dir')) {
         $output->writeln(sprintf('Output results in directory <info>%s</info>', $outputDir));
         $renderer = new FilesystemRenderer($outputDir);
         $renderer->render($result);
         $output->writeln('<info>Done.</info>');
     }
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc }
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $privateKeyPath = $input->getOption('privateKey');
     $keyBundlePath = $input->getOption('certificate');
     $path = $input->getOption('path');
     if (is_null($privateKeyPath) || is_null($keyBundlePath) || is_null($path)) {
         $output->writeln('--privateKey, --certificate and --path are required.');
         return null;
     }
     $privateKey = $this->fileAccessHelper->file_get_contents($privateKeyPath);
     $keyBundle = $this->fileAccessHelper->file_get_contents($keyBundlePath);
     if ($privateKey === false) {
         $output->writeln(sprintf('Private key "%s" does not exists.', $privateKeyPath));
         return null;
     }
     if ($keyBundle === false) {
         $output->writeln(sprintf('Certificate "%s" does not exists.', $keyBundlePath));
         return null;
     }
     $rsa = new RSA();
     $rsa->loadKey($privateKey);
     $x509 = new X509();
     $x509->loadX509($keyBundle);
     $x509->setPrivateKey($rsa);
     $this->checker->writeCoreSignature($x509, $rsa, $path);
     $output->writeln('Successfully signed "core"');
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getDialogHelper();
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output, $dialog);
     }
     $input->setOption('module', $module);
     // --class-name option
     $class_name = $input->getOption('class-name');
     if (!$class_name) {
         $class_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.class-name'), 'ExamplePlugin'), 'ExamplePlugin');
     }
     $input->setOption('class-name', $class_name);
     $default_machine_name = $this->getStringUtils()->camelCaseToUnderscore($class_name);
     // --machine-name option
     $machine_name = $input->getOption('machine-name');
     if (!$machine_name) {
         $machine_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.machine-name'), $default_machine_name), $default_machine_name);
     }
     $input->setOption('machine-name', $machine_name);
     $default_label = $this->getStringUtils()->camelCaseToHuman($class_name);
     // --label option
     $label = $input->getOption('label');
     if (!$label) {
         $label = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.label'), $default_label), $default_label);
     }
     $input->setOption('label', $label);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logins = $input->getOption('login');
     $skipExisting = $input->getOption('skip-existing');
     if (empty($logins)) {
         $logins = $this->ldapUsers->getAllUserLogins();
     }
     $count = 0;
     $failed = array();
     foreach ($logins as $login) {
         if ($skipExisting && $this->userExistsInPiwik($login)) {
             $output->write("Skipping '{$login}', already exists in Piwik...");
             continue;
         }
         $output->write("Synchronizing '{$login}'...  ");
         try {
             $this->loginLdapAPI->synchronizeUser($login);
             ++$count;
             $output->writeln("<info>success!</info>");
         } catch (Exception $ex) {
             $failed[] = array('login' => $login, 'reason' => $ex->getMessage());
             $output->writeln("<error>failed!</error>");
         }
     }
     $this->writeSuccessMessage($output, array("Synchronized {$count} users!"));
     if (!empty($failed)) {
         $output->writeln("<info>Could not synchronize the following users in LDAP:</info>");
         foreach ($failed as $missingLogin) {
             $output->writeln($missingLogin['login'] . "\t\t<comment>{$missingLogin['reason']}</comment>");
         }
     }
     return count($failed);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $emName = $input->getOption('em');
     $emName = $emName ? $emName : 'default';
     $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
     $em = $this->container->get($emServiceName);
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         foreach ($this->application->getKernel()->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
         }
     }
     $loader = new DataFixturesLoader($this->container);
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     $purger = new ORMPurger($em);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
Exemplo n.º 22
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $header_style = new OutputFormatterStyle('white', 'green', array('bold'));
     $output->getFormatter()->setStyle('header', $header_style);
     $start = intval($input->getOption('start'));
     $stop = intval($input->getOption('stop'));
     if ($start >= $stop || $start < 0) {
         throw new \InvalidArgumentException('Stop number should be greater than start number');
     }
     $output->writeln('<header>Fibonacci numbers between ' . $start . ' - ' . $stop . '</header>');
     $xnM2 = 0;
     // set x(n-2)
     $xnM1 = 1;
     // set x(n-1)
     $xn = 0;
     // set x(n)
     $totalFiboNr = 0;
     while ($xnM2 <= $stop) {
         if ($xnM2 >= $start) {
             $output->writeln('<header>' . $xnM2 . '</header>');
             $totalFiboNr++;
         }
         $xn = $xnM1 + $xnM2;
         $xnM2 = $xnM1;
         $xnM1 = $xn;
     }
     $output->writeln('<header>Total of Fibonacci numbers found = ' . $totalFiboNr . ' </header>');
 }
Exemplo n.º 23
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     $this->client = $client = SnsClient::factory(array('key' => $this->getContainer()->getParameter('amazon_s3.key'), 'secret' => $this->getContainer()->getParameter('amazon_s3.secret'), 'region' => $this->getContainer()->getParameter('amazon_s3.region')));
     if ($input->getOption('list-android')) {
         $this->showEndpoints($this->getContainer()->getParameter('amazon_sns.android_arn'), 'List of GCM endpoints:');
     }
     if ($input->getOption('list-ios')) {
         $this->showEndpoints($this->getContainer()->getParameter('amazon_sns.ios_arn'), 'List of APNS endpoints:');
     }
     $endpoint = $input->getArgument('endpoint');
     if ($endpoint) {
         if ($input->getOption('delete')) {
             $output->writeln('<comment>Delete endpoint</comment>');
             $client->deleteEndpoint(array('EndpointArn' => $endpoint));
         } else {
             $testMessage = 'Test notification';
             try {
                 $client->publish(array('TargetArn' => $endpoint, 'MessageStructure' => 'json', 'Message' => json_encode(array('APNS' => json_encode(array('aps' => array('alert' => $testMessage))), 'GCM' => json_encode(array('data' => array('message' => $testMessage)))))));
             } catch (\Aws\Sns\Exception\SnsException $e) {
                 $output->writeln("<error>{$e->getMessage()}</error>");
             }
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $command = $this->getApplication()->find("prototype:generate:twig");
     $arguments = array("--entity" => $input->getOption("entity"), "--rootFolder" => $input->getOption("rootFolder"), "--viewType" => "Element", "--templatePath" => "CorePrototypeBundle:Command:element.create.template.twig", "--fileName" => "create.html.twig", "--withAssociated" => $input->getOption("withAssociated"));
     $inputCommand = new ArrayInput($arguments);
     $returnCode = $command->run($inputCommand, $output);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manifest = $input->getOption('manifest') ?: 'https://platform.sh/cli/manifest.json';
     $currentVersion = $input->getOption('current-version') ?: $this->getApplication()->getVersion();
     if (extension_loaded('Phar') && !($localPhar = \Phar::running(false))) {
         $this->stdErr->writeln('This instance of the CLI was not installed as a Phar archive.');
         if (file_exists(CLI_ROOT . '/../../autoload.php')) {
             $this->stdErr->writeln('Update using: <info>composer global update</info>');
         }
         return 1;
     }
     $manager = new Manager(Manifest::loadFile($manifest));
     if (isset($localPhar)) {
         $manager->setRunningFile($localPhar);
     }
     $onlyMinor = !$input->getOption('major');
     $updated = $manager->update($currentVersion, $onlyMinor);
     if ($updated) {
         $this->stdErr->writeln("Successfully updated");
         $localPhar = $manager->getRunningFile();
         passthru('php ' . escapeshellarg($localPhar) . ' --version');
     } else {
         $this->stdErr->writeln("No updates found. The Platform.sh CLI is up-to-date.");
     }
     return 0;
 }
Exemplo n.º 26
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $inputSource = $input->getOption('input');
     $size = (int) $input->getOption('size');
     if ($size < 1 || $size > 2000) {
         $output->writeln('<error>Sample size must be a positive integer between 1 and 2000.</error>');
         return;
     }
     // Input size should be 10 times the size of the sample
     $streamSize = $size * 10;
     switch ($inputSource) {
         case 'stdin':
             $stream = new StreamIterator();
             break;
         case 'random.org':
             $stream = new RandomOrgIterator($this->httpClient);
             $stream->setLength($streamSize);
             break;
         case 'internal':
             $stream = new RandomByteIterator();
             $stream->setLength($streamSize);
             break;
         default:
             $output->writeln('<error>Unknown input source: "' . $inputSource . '". Use either stdin, random.org or internal.</error>');
             return;
     }
     $this->sampler->setStream($stream);
     $result = $this->sampler->getSampleAsString($size);
     $output->writeln($result);
 }
Exemplo n.º 27
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $magento = new Magento($input->getOption('magento-root'));
     $config_adapter = new ConfigurationAdapter($magento);
     $yaml = new Parser();
     if ($input->getArgument('config-yaml-file')) {
         $config_yaml_file = $input->getArgument('config-yaml-file');
         if (!file_exists($config_yaml_file)) {
             throw new \Exception("File ({$config_yaml_file}) does not exist");
         }
         if (!is_readable($config_yaml_file)) {
             throw new \Exception("File ({$config_yaml_file}) is not readable");
         }
         $config_db_yaml = ConfigYaml::build($config_adapter);
         $config_file_contents = $yaml->parse(file_get_contents($config_yaml_file));
         $config_file_yaml = new ConfigYaml($config_file_contents, $input->getOption('env'));
         $diff = ConfigYaml::compare($config_file_yaml, $config_db_yaml);
         if (count($diff) > 0) {
             $db_data = $config_db_yaml->getData();
             $file_data = $config_file_yaml->getData();
             $diff_count = 0;
             foreach ($diff as $scope => $scope_data) {
                 foreach ($scope_data as $key => $value) {
                     $diff_count++;
                     $diff_message = sprintf("%s/%s is different (File: %s, DB: %s)", $scope, $key, $this->decorateValue($file_data[$scope][$key]), $this->decorateValue($db_data[$scope][$key]));
                     $output->writeln($diff_message);
                 }
             }
             return $diff_count;
         } else {
             return 0;
         }
     }
 }
Exemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $database = $input->getArgument('database');
     $file = $input->getOption('file');
     $learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
     $databaseConnection = $this->resolveConnection($io, $database);
     if (!$file) {
         $date = new \DateTime();
         $file = sprintf('%s/%s-%s.sql', $this->getSite()->getSiteRoot(), $databaseConnection['database'], $date->format('Y-m-d-h-i-s'));
     }
     $command = sprintf('mysqldump --user=%s --password=%s --host=%s --port=%s %s > %s', $databaseConnection['username'], $databaseConnection['password'], $databaseConnection['host'], $databaseConnection['port'], $databaseConnection['database'], $file);
     if ($learning) {
         $io->commentBlock($command);
     }
     $processBuilder = new ProcessBuilder(['–lock-all-tables']);
     $process = $processBuilder->getProcess();
     $process->setTty('true');
     $process->setCommandLine($command);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     $io->success(sprintf('%s %s', $this->trans('commands.database.dump.messages.success'), $file));
 }
Exemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var ModelManager $em */
     $em = $this->container->get('models');
     $repository = $em->getRepository('Shopware\\Models\\Plugin\\Plugin');
     $builder = $repository->createQueryBuilder('plugin');
     $builder->andWhere('plugin.capabilityEnable = true');
     $builder->addOrderBy('plugin.active', 'desc');
     $builder->addOrderBy('plugin.name');
     $filter = strtolower($input->getOption('filter'));
     if ($filter === 'active') {
         $builder->andWhere('plugin.active = true');
     }
     if ($filter === 'inactive') {
         $builder->andWhere('plugin.active = false');
     }
     $namespace = $input->getOption('namespace');
     if (count($namespace)) {
         $builder->andWhere('p.namespace IN (:namespace)');
         $builder->setParameter('namespace', $namespace);
     }
     $plugins = $builder->getQuery()->execute();
     $rows = array();
     /** @var Plugin $plugin */
     foreach ($plugins as $plugin) {
         $rows[] = array($plugin->getName(), $plugin->getLabel(), $plugin->getVersion(), $plugin->getAuthor(), $plugin->getActive() ? 'Yes' : 'No', $plugin->getInstalled() ? 'Yes' : 'No');
     }
     $table = $this->getHelperSet()->get('table');
     $table->setHeaders(array('Plugin', 'Label', 'Version', 'Author', 'Active', 'Installed'))->setRows($rows);
     $table->render($output);
 }
 /**
  * {inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->setApi(new \AdministrationApi());
     $args = array();
     if ($modules = $input->getOption('modules')) {
         $args['module_list'] = $modules;
     }
     if ($searchOnly = $input->getOption('searchOnly')) {
         $args['search_only'] = true;
     }
     if ($byBoost = $input->getOption('byBoost')) {
         $args['order_by_boost'] = true;
     }
     $result = $this->callApi('searchFields', $args);
     // handle output which is different when ordered by boost
     $table = new Table($output);
     if ($byBoost) {
         $table->setHeaders(array('Module', 'Field', 'Boost'));
         foreach ($result as $raw => $boost) {
             $raw = explode('.', $raw);
             $table->addRow([$raw[0], $raw[1], $boost]);
         }
     } else {
         $table->setHeaders(array('Module', 'Field', 'Type', 'Searchable', 'Boost'));
         foreach ($result as $module => $fields) {
             foreach ($fields as $field => $props) {
                 $searchAble = !empty($props['searchable']) ? 'yes' : 'no';
                 $boost = isset($props['boost']) ? $props['boost'] : 'n/a';
                 $table->addRow([$module, $field, $props['type'], $searchAble, $boost]);
             }
         }
     }
     $table->render();
 }