Exemplo n.º 1
0
 /**
  * @param  array $attributes
  * @param  array $whiteList
  *
  * @return boolean
  * @throws Exception
  */
 private function makeRoot($attributes, $whiteList)
 {
     $owner = $this->getOwner();
     $owner->{$this->rootAttribute} = 0;
     $owner->{$this->leftAttribute} = 1;
     $owner->{$this->rightAttribute} = 2;
     $owner->{$this->levelAttribute} = 1;
     if ($this->hasManyRoots) {
         $this->db->begin();
         $this->ignoreEvent = true;
         if ($owner->create($attributes, $whiteList) == false) {
             $this->db->rollback();
             $this->ignoreEvent = false;
             return false;
         }
         $pk = $owner->{$this->rootAttribute} = $owner->{$this->primaryKey};
         $owner::findFirst($pk)->update([$this->rootAttribute => $pk]);
         $this->ignoreEvent = false;
         $this->db->commit();
     } else {
         if (count($owner->roots())) {
             throw new Exception('Cannot create more than one root in single root mode.');
         }
         if ($owner->create($attributes, $whiteList) == false) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Delete the migration datasets from the table
  *
  * @param string $tableName
  */
 public function batchDelete($tableName)
 {
     $migrationData = self::$_migrationPath . $this->_version . '/' . $tableName . '.dat';
     if (!file_exists($migrationData)) {
         return;
         // nothing to do
     }
     self::$_connection->begin();
     self::$_connection->delete($tableName);
     $batchHandler = fopen($migrationData, 'r');
     while (($line = fgets($batchHandler)) !== false) {
         $data = explode('|', rtrim($line), 2);
         self::$_connection->delete($tableName, 'id=?', [$data[0]]);
         unset($line);
     }
     fclose($batchHandler);
     self::$_connection->commit();
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  *
  * @return $this
  */
 public function begin()
 {
     $this->db->begin();
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Starts the transaction
  *
  * @return boolean
  */
 public function begin()
 {
     return $this->_connection->begin();
 }