/** * Migrate given view to PostgreSql server. * * @param string $strViewName * @return void */ private function createView($strViewName) { $sql = ''; try { $this->log(PHP_EOL . "\t" . '-- Attempting to create view: "' . $this->strSchema . '"."' . $strViewName . '"...' . PHP_EOL); $this->connect(); $sql = 'SHOW CREATE VIEW `' . $strViewName . '`;'; $stmt = $this->mysql->query($sql); $arrColumns = $stmt->fetchAll(\PDO::FETCH_ASSOC); unset($sql, $stmt); $sql = ViewGenerator::generateView($this->strSchema, $strViewName, $arrColumns[0]['Create View']); $stmt = $this->pgsql->query($sql); unset($sql, $stmt, $arrColumns); $this->log(PHP_EOL . "\t" . '-- View: "' . $this->strSchema . '"."' . $strViewName . '" is created...' . PHP_EOL); } catch (\PDOException $e) { $boolViewsErrorsDirectoryExists = true; if (!file_exists($this->strViewsErrorsDirectoryPath)) { mkdir($this->strViewsErrorsDirectoryPath); if (!file_exists($this->strViewsErrorsDirectoryPath)) { $boolViewsErrorsDirectoryExists = false; } } if (file_exists($this->strViewsErrorsDirectoryPath)) { $resource = fopen($this->strViewsErrorsDirectoryPath . '/' . $strViewName . '.sql', 'w'); fwrite($resource, $sql); fclose($resource); unset($resource); } $strMsg = $boolViewsErrorsDirectoryExists && file_exists($this->strViewsErrorsDirectoryPath . '/' . $strViewName . '.sql') ? __METHOD__ . PHP_EOL . "\t" . '-- Cannot create view "' . $this->strSchema . '"."' . $strViewName . '" ' . PHP_EOL . "\t" . '-- You can find view definition at "logs_directory/not_created_views/' . $strViewName . '.sql"' . PHP_EOL . "\t" . '-- You can try to fix view definition script and run it manually.' : __METHOD__ . PHP_EOL . "\t" . '-- Cannot create view "' . $this->strSchema . '"."' . $strViewName . '" '; $this->log(PHP_EOL . "\t" . '-- Cannot create view "' . $this->strSchema . '"."' . $strViewName . '" ' . PHP_EOL); $this->generateError($e, $strMsg, $sql); unset($strMsg, $boolViewsErrorsDirectoryExists, $sql); } }
/** * Generate View object metafile * @return string file name of View object metafile */ public function genViewMeta() { if (!$this->formGen) { $this->doGen = new DOGenerator($this->module, $this->dbname, $this->table, $this->dbConfig, $this->opts); $this->doGen->prepareData(); $this->formGen = new FormGenerator($this->module, $this->doGen, $this->opts); } $viewGen = new ViewGenerator($this->module, $this->formGen, $this->opts); $viewFile = $viewGen->generateView(); return $viewFile; }