示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->instances->lock();
     $container = $this->getContainer();
     $mysql_type = $container->getParameter('mysql_type');
     if ($mysql_type == "") {
         $this->doCommand($output, OutputInterface::VERBOSITY_NORMAL, 'config', array());
         $this->getApplication()->loadContainer();
         $this->instances = $this->getContainer()->get('instances');
     }
     $instance = $this->instances->find(Instance::makeId($input->getOption('root'), $input->getOption('name')));
     if ($instance === NULL) {
         $instance = new Instance();
         $instance->setRoot($input->getOption('root'));
         $instance->setName($input->getOption('name'));
     } elseif (!$input->getOption('force')) {
         throw new \Exception("Cannot create instance. Use -f to overwrite existing instance.");
     }
     if ($input->getOption('url')) {
         $instance->setUrl($input->getOption('url'));
     }
     $this->instances->create($instance, !$input->getOption('skip-url'), !$input->getOption('skip-db'), $input->getOption('perm'));
     $this->instances->save();
     if ($output->getVerbosity() > OutputInterface::VERBOSITY_QUIET) {
         $this->export($instance->getRoot(), $instance->getName(), $input->getOption('prefix'), $input->getOption('output-file'), $output);
     }
 }
示例#2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
         $rows = array();
         foreach ($this->instances->findAll() as $instance) {
             $rows[] = array('root', $instance->getRoot());
             $rows[] = array('name', $instance->getName());
             $rows[] = array('dsn', $instance->getDsn());
             $rows[] = array('url', $instance->getUrl());
             $rows[] = array('', '');
         }
         /** @var $table \Symfony\Component\Console\Helper\TableHelper */
         $table = $this->getApplication()->getHelperSet()->get('table');
         $table->setHeaders(array('Property', 'Value'));
         $table->setRows($rows);
         $table->render($output);
     } else {
         $rows = array();
         foreach ($this->instances->findAll() as $instance) {
             $rows[] = array($instance->getRoot(), $instance->getName(), $instance->getDsn() ? 'y' : '', $instance->getUrl() ? 'y' : '');
         }
         /** @var $table \Symfony\Component\Console\Helper\TableHelper */
         $table = $this->getApplication()->getHelperSet()->get('table');
         $table->setHeaders(array('Root', 'Name', 'DB', 'Web'));
         $table->setRows($rows);
         $table->render($output);
         $output->writeln('For more detailed info, use "amp show -v" or "amp export [--root=X] [---name=X]');
     }
 }
示例#3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $instance = $this->instances->find(Instance::makeId($input->getOption('root'), $input->getOption('name')));
     if (!$instance) {
         throw new \Exception("Failed to locate instance: " . Instance::makeId($input->getOption('root'), $input->getOption('name')));
     }
     $process = proc_open("mysql " . $instance->getDatasource()->toMySQLArguments(), array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes, $input->getOption('root'));
     return proc_close($process);
 }
示例#4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->instances->lock();
     $instance = $this->instances->find(Instance::makeId($input->getOption('root'), $input->getOption('name')));
     if (!$instance) {
         return;
     }
     $this->instances->remove($instance->getId());
     $this->instances->save();
 }
示例#5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->instances->lock();
     $count = 0;
     foreach ($this->instances->findAll() as $instance) {
         if ($input->getOption('force') || !file_exists($instance->getRoot())) {
             $output->writeln("Destroy (root={$instance->getRoot()}, name={$instance->getName()}, dsn={$instance->getDsn()})");
             $this->instances->remove($instance->getId());
             $count++;
         } else {
             $output->writeln("Skip (root={$instance->getRoot()}, name={$instance->getName()}, dsn={$instance->getDsn()})");
         }
     }
     $output->writeln("Destroyed {$count} instance(s)");
     $this->instances->save();
 }
示例#6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $instance = $this->instances->find(Instance::makeId($input->getOption('root'), $input->getOption('name')));
     if (!$instance) {
         throw new \Exception("Failed to locate instance: " . Instance::makeId($input->getOption('root'), $input->getOption('name')));
     }
     $prefix = $input->getOption('prefix');
     $dsnParts = \DB\DSN::parseDSN($instance->getDsn());
     $output_file_path = $input->getOption('output-file');
     if ($output_file_path != '') {
         $output_file = fopen($output_file_path, "w");
         $output = new StreamOutput($output_file);
     }
     $envVars = array("{$prefix}URL" => $instance->getUrl(), "{$prefix}ROOT" => $instance->getRoot(), "{$prefix}DB_DSN" => $instance->getDsn(), "{$prefix}DB_USER" => $dsnParts['username'], "{$prefix}DB_PASS" => $dsnParts['password'], "{$prefix}DB_HOST" => $dsnParts['hostspec'], "{$prefix}DB_PORT" => $dsnParts['port'], "{$prefix}DB_NAME" => $dsnParts['database'], "{$prefix}DB_ARGS" => $instance->getDatasource() ? $instance->getDatasource()->toMySQLArguments() : '');
     foreach ($envVars as $var => $value) {
         $output->writeln($var . '=' . escapeshellarg($value));
     }
     // $output->writeln('export ' . implode(' ', array_keys($envVars)));
 }
示例#7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->instances->lock();
     // Display help text
     //$output->write($this->templateEngine->render('testing.php', array(
     //  'apache_dir' => $this->getContainer()->getParameter('apache_dir'),
     //  'nginx_dir' => $this->getContainer()->getParameter('nginx_dir'),
     //)));
     // Setup test instance
     $output->writeln("<info>Create test application</info>");
     list($root, $dataDir) = $this->createCanaryFiles($output);
     $this->doCommand($output, OutputInterface::VERBOSITY_NORMAL, 'create', array('--root' => $root, '--force' => 1, '--url' => 'http://localhost:7979'));
     $output->writeln("");
     // Connect to test instance
     $output->writeln("<info>Connect to test application</info>");
     $output->writeln("<comment>Expect response: \"{$this->expectedResponse}\"</comment>");
     $this->instances->load();
     // force reload
     $instance = $this->instances->find(Instance::makeId($root, ''));
     $response = $this->doPost($instance->getUrl() . '/index.php', array('dsn' => $instance->getDsn()));
     if ($response == $this->expectedResponse) {
         $output->writeln("<info>Received expected response</info>");
         // Tear down test instance
         // Skip teardown; this allows us to preserve the port-number
         // across multiple executions.
         //$output->writeln("<info>Cleanup test application</info>");
         //$this->doCommand($output, OutputInterface::VERBOSITY_NORMAL, 'destroy', array(
         //  '--root' => $root,
         //));
     } else {
         $output->writeln("<error>Received incorrect response: \"{$response}\"</error>");
         $output->writeln("<comment>Tip: Try running \"amp config\" and/or restarting the webserver.</comment>");
     }
     if (!rmdir($dataDir)) {
         $output->writeln("<error>Failed to clean up data directory: {$dataDir}</error>");
     }
 }