Esempio n. 1
0
 /**
  * Install the {@link http://onpub.com/pdfs/onpub_schema.pdf Onpub schema}.
  *
  * Calling this method will install the Onpub tables in the PDO-connected
  * database.
  *
  * @param int $version Optional argument to specify what version of the Onpub
  * schema to install. If NULL (the default), the latest version of the schema
  * will be added to the database.
  * @return mixed TRUE if the schema was successfully installed. An array
  * of PDOException objects will be returned if any errors occured.
  */
 public function install($version = NULL)
 {
     $sqlfile = array();
     $line = 0;
     $exceptions = array();
     $sqlfile = file(Path::canonicalize(__DIR__ . '/../sql/createonpubtables-rev0.sql'));
     // advance past all comments
     while (strpos($sqlfile[$line], '--') !== FALSE) {
         $line++;
         while ($sqlfile[$line] == "\n") {
             $line++;
         }
     }
     for ($i = $line; $i < sizeof($sqlfile); $i++) {
         $query = '';
         while (strpos($sqlfile[$i], ';') === FALSE) {
             $query .= $sqlfile[$i];
             $i++;
         }
         $query .= $sqlfile[$i];
         if ($i + 1 < sizeof($sqlfile)) {
             while ($sqlfile[$i + 1] == "\n") {
                 $i++;
             }
         }
         $result = NULL;
         $result = $this->pdo->exec($query);
         try {
             OnpubDatabase::verifyExec($this->pdo, $result, FALSE);
         } catch (PDOException $e) {
             $exceptions[] = $e;
         }
     }
     if (sizeof($exceptions)) {
         return $exceptions;
     }
     return TRUE;
 }