Beispiel #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);
     }
 }
Beispiel #2
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);
 }
Beispiel #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $instance = $this->getContainer()->get('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')));
     }
     $datasource = $instance->getDatasource();
     $process = proc_open("mysqldump " . $datasource->toMySQLArguments($this->getContainer()->getParameter('my_cnf_dir')) . " " . $input->getOption('passthru'), array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes, $input->getOption('root'));
     return proc_close($process);
 }
 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();
 }
Beispiel #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Amp\InstanceRepository $instances */
     $instances = $this->getContainer()->get('instances');
     $instances->lock();
     $defaultUrl = $input->getOption('url');
     // 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' => $defaultUrl));
     $output->writeln("");
     $instances->load();
     // force reload
     $instance = $instances->find(Instance::makeId($root, ''));
     $this->createConfigFile($instance->getRoot() . '/config.php', $instance->getDatasource(), $dataDir);
     // Connect to test instance
     $output->writeln("<info>Connect to test application</info>");
     $output->writeln("<comment>Expect response: \"{$this->expectedResponse}\"</comment>");
     $response = $this->doPost($instance->getUrl() . '/index.php', array('exampleData' => 'foozball'));
     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>Tips for common issues:</comment>");
         $output->writeln("<comment> - (Re)run \"amp config\"</comment>");
         $httpdType = $this->getContainer()->getParameter('httpd_type');
         $output->writeln("<comment> - Double-check the httpd_type ({$httpdType}) along with any displayed instructions.</comment>");
         if (!$httpdType || $httpdType === 'none') {
             $output->writeln("<comment> - In absence of a known httpd_type, you will be responsible for configuring vhosts. Ensure that the vhost ({$defaultUrl}) is configured.</comment>");
         }
         $restartCommand = $this->getContainer()->getParameter('httpd_restart_command');
         $output->writeln("<comment> - Double-check the httpd_restart_command.</comment>");
         if (!$restartCommand || $restartCommand === 'NONE') {
             $output->writeln("<comment> - In absence of the httpd_restart_command, you will be responsible for any restarts. Cycle through and alternately run \"amp test\" and restart httpd manually.</comment>");
         }
         $output->writeln("<comment> - (Re)run \"amp test\"</comment>");
     }
     if (!rmdir($dataDir)) {
         $output->writeln("<error>Failed to clean up data directory: {$dataDir}</error>");
     }
 }
Beispiel #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)));
 }
Beispiel #7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('admin')) {
         $db = $this->getContainer()->get('db');
         if (is_callable(array($db, 'getAdminDatasource'))) {
             $datasource = $db->getAdminDatasource();
         } else {
             throw new \Exception("This database does not provide access to an administrative datasource.");
         }
     } else {
         $instance = $this->getContainer()->get('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')));
         }
         $datasource = $instance->getDatasource();
     }
     $process = proc_open("mysql " . $datasource->toMySQLArguments($this->getContainer()->getParameter('my_cnf_dir')), array(0 => $input->getOption('eval') ? array('pipe', 'r') : STDIN, 1 => STDOUT, 2 => STDERR), $pipes, $input->getOption('root'));
     if (is_resource($process) && $input->getOption('eval')) {
         fwrite($pipes[0], $this->filterSql(file_get_contents('php://stdin'), $datasource->createPDO()));
         fclose($pipes[0]);
     }
     return proc_close($process);
 }
Beispiel #8
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>");
     }
 }