/** * Set up the plugin, configure options, etc. * @param Builder $phpci * @param Build $build * @param array $options */ public function __construct(Builder $phpci, Build $build, array $options = array()) { $path = $phpci->buildPath; $this->phpci = $phpci; $this->build = $build; $this->directory = isset($options['directory']) ? $this->phpci->interpolate($options['directory']) : $path; }
/** * Connects to PgSQL and runs a specified set of queries. * @return boolean */ public function execute() { try { $opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); $pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, $opts); foreach ($this->queries as $query) { $pdo->query($this->phpci->interpolate($query)); } } catch (\Exception $ex) { $this->phpci->logFailure($ex->getMessage()); return false; } return true; }
/** * Runs the shell command. */ public function execute() { if (!defined('ENABLE_SHELL_PLUGIN') || !ENABLE_SHELL_PLUGIN) { throw new \Exception('The shell plugin is not enabled.'); } $success = true; foreach ($this->commands as $command) { $command = $this->phpci->interpolate($command); if (!$this->phpci->executeCommand($command)) { $success = false; } } return $success; }
/** * @param string $query * @return boolean * @throws \Exception */ protected function executeFile($query) { if (!isset($query['file'])) { throw new \Exception(Lang::get('import_file_key')); } $import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']); if (!is_readable($import_file)) { throw new \Exception(Lang::get('cannot_open_import', $import_file)); } $database = isset($query['database']) ? $this->phpci->interpolate($query['database']) : null; $import_command = $this->getImportCommand($import_file, $database); if (!$this->phpci->executeCommand($import_command)) { throw new \Exception(Lang::get('unable_to_execute')); } return true; }
/** * @param string $query * @return boolean * @throws \Exception */ protected function executeFile($query) { if (!isset($query['file'])) { throw new \Exception("Import statement must contain a 'file' key"); } $import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']); if (!is_readable($import_file)) { throw new \Exception("Cannot open SQL import file: {$import_file}"); } $database = isset($query['database']) ? $this->phpci->interpolate($query['database']) : null; $import_command = $this->getImportCommand($import_file, $database); if (!$this->phpci->executeCommand($import_command)) { throw new \Exception("Unable to execute SQL file"); } return true; }