Ejemplo n.º 1
0
 public function __construct(\SPLFileInfo $asset, Pg $db)
 {
     $this->location = realpath($asset->getPathname());
     $dbSql = $this->dbSql = $db->query(new Query("SELECT * FROM build.assets WHERE location = %location:%", array('location' => $this->location)))->fetch(Result::FETCH_SINGLE);
     if ($dbSql) {
         $diff = new Diff();
         $this->diffText = $diff->diff($dbSql['sql'], file_get_contents($this->location));
     } else {
         $this->diffText = 'Asset not in database';
     }
     $this->message = sprintf("Database asset `%s` at %s changed at %s.\n%s", substr($asset->getBasename(), 0, -4), $this->location, date('Y-m-d H:i:s', $asset->getMTime()), $this->diffText);
 }
Ejemplo n.º 2
0
 public function execute(Pg $pg, $simulate = false)
 {
     if (!$this->object->isChanged()) {
         return true;
     }
     // IMPORTANT: pg_lo_import/export DO NOT WORK without a transaction!
     $pg->query(new Query('BEGIN'));
     if (!($oid = pg_lo_import($pg->resource->get(), $this->object->getFilePath()))) {
         throw new QueryException('Unable to import PgLargeObject');
     }
     // IMPORTANT: pg_lo_import/export DO NOT WORK without a transaction!
     $pg->query(new Query('COMMIT'));
     $this->object->markPersisted($oid);
     return true;
 }
Ejemplo n.º 3
0
 public function execute(Pg $pg, $simulate = false)
 {
     if ($this->object->isNew()) {
         return true;
     }
     // IMPORTANT: pg_lo fn's don't work outside a transaction
     $pg->query(new Query('BEGIN'));
     if (!($response = pg_lo_unlink($pg->resource->get(), $this->object->getOid()))) {
         throw new QueryException("Unable to delete PgLargeObject {$this->object->getOid()}");
     }
     // IMPORTANT: pg_lo_import/export DO NOT WORK without a transaction!
     $pg->query(new Query('COMMIT'));
     $this->object->markDeleted();
     return true;
 }
Ejemplo n.º 4
0
 public function testParameterValidator()
 {
     $this->assertTrue(Pg::isParameterAllowed('bond.spanner'));
     $this->assertTrue(Pg::isParameterAllowed('bond.monkey'));
     $this->assertTrue(Pg::isParameterAllowed('search_path'));
     $this->setExpectedException("InvalidArgumentException");
     Pg::isParameterAllowed('bond.;');
 }
Ejemplo n.º 5
0
 public function build(Pg $db)
 {
     // iterate over the relations and build the
     foreach ($this->working as $relation) {
         $table = new Table($relation, $this->inherits, $this->inheritedValues);
         $db->query($table);
     }
     $this->catalogRefresh();
     // get our new log table relations
     $logRelations = Relation::r()->findAllBySchema($this->inherits->get('schema'))->findByName($this->working->pluck('name'));
     // build entity history
     foreach ($logRelations as $relation) {
         $original = $this->working->findOneByName($relation->get('name'));
         $fnEntityHistory = new FnEntityHistory($relation, $original);
         $db->query($fnEntityHistory);
         $fnTableAtState = new FnTableAtState($relation, $original);
         $db->query($fnTableAtState);
         $viewTableHistory = new ViewTableHistory($relation, $original);
         $db->query($viewTableHistory);
     }
     return $logRelations;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritDoc}
  */
 public function execute(Pg $pg, $simulate = false)
 {
     $pg->query($this->object);
     return true;
 }
Ejemplo n.º 7
0
 /**
  * Get the current (ie, value most recently obtained) from a list of named Sequences
  *
  * @param array $sequences array of sequence names
  * @param Pg $db Database connection to use
  * @return array Array of sequence values
  */
 protected static function getSequenceCurval(array $sequences, Pg $db)
 {
     // anything to do
     if (!$sequences) {
         return array();
     }
     // sequence components
     foreach ($sequences as $key => &$sequence) {
         $sequence = sprintf("currval('%s'::regclass) as %s", $sequence, Query::quoteIdentifier($key));
     }
     $sequences = implode(', ', $sequences);
     return $db->query(new Query("SELECT {$sequences};"))->fetchSingle(Result::FLATTEN_PREVENT);
 }
Ejemplo n.º 8
0
 /**
  * Get loaded assets
  * @param Bond\Pg
  * @param array
  */
 private function getLoadedAssets(Pg $db)
 {
     $result = $db->query(new Query("SELECT * FROM build.assets"));
     $output = [];
     foreach ($result as $row) {
         $output[$row['name']] = md5($row['sql']);
     }
     return $output;
 }