/** * Remove the files and directories created for this test. */ public function tearDown() { if ($this->fs->exists($this->root)) { $this->fs->remove($this->root); } parent::tearDown(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $destroy_prs = array(); $pull_request = $this->getConfigParameter('pull_request'); $pr_directories = $this->getConfigParameter('pr_directories'); // Get deployed PR's based on directories in $pr_directories and compare // that to the PR's open on GitHub. if ($input->getOption('closed')) { $deployed_prs = array(); $finder = new Finder(); // @TODO need to ensure that prefix is alphanumeric ONLY. $pattern = '/^' . $pull_request['prefix'] . '\\-([0-9]+)/'; $iterator = $finder->directories()->name($pattern)->depth(0)->in($pr_directories); foreach ($iterator as $directory) { preg_match($pattern, $directory->getFilename(), $matches); $deployed_prs[] = $matches[1]; } if (!empty($deployed_prs)) { $github = $this->getGithub(); $open_prs = array(); $paginator = new Github\ResultPager($github); $prs = $paginator->fetchAll($github->api('pr'), 'all', array($this->getConfigParameter('organization'), $this->getConfigParameter('repository'), array('state' => 'open'))); foreach ($prs as $pr) { $open_prs[] = $pr['number']; } // PR's to destroy are deployed PR's that are not open. $destroy_prs = array_diff($deployed_prs, $open_prs); } } else { $pr_number = $input->getArgument('pull-request'); if (!is_numeric($pr_number)) { throw new \Exception("PR must be a number."); } $destroy_prs[] = $pr_number; } if (!empty($destroy_prs)) { $fs = new Filesystem(); $site_dir = $input->getOption('site-dir'); foreach ($destroy_prs as $destroy_pr) { // @TODO get this path from a central place. $pr_path = rtrim($pr_directories, '/') . "/{$pull_request['prefix']}-{$destroy_pr}.{$pull_request['domain']}"; if ($fs->exists($pr_path)) { // Drop the database. // @TODO set/get database name in central place, and use in DrupalSettings. $database = $pull_request['prefix'] . '_' . $destroy_pr; $process = new Process("drush sqlq 'DROP database {$database}'", $pr_path . "/docroot/sites/" . $site_dir); $process->run(); // Remove the PR's web root. $fs->remove($pr_path); // @TODO destroy memcache bins. $output->writeln("<info>Successfully destroyed PR #{$destroy_pr}</info>"); } } } else { $output->writeln("<info>No PR's to destroy.</info>"); } }
/** * Remove the files and directories created for this test. */ public function tearDown() { $fs = new Filesystem(); if ($fs->exists($this->root)) { $fs->remove($this->root); } }
/** * Remove the files and directories created for this test. */ public function tearDown() { if ($this->fs->exists($this->file)) { $this->fs->remove($this->file); } }