示例#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;
 }
示例#2
0
 /**
  * Commits the transaction
  *
  * @return boolean
  */
 public function commit()
 {
     if (is_object($this->_manager) === true) {
         call_user_func(array($this->_manager, 'notifyCommit'), $this);
     }
     return $this->_connection->commit();
 }
示例#3
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();
 }
示例#4
0
 /**
  * Commit transaction
  *
  * @return $this
  */
 public function commit()
 {
     $this->db->commit();
     return $this;
 }