Beispiel #1
0
 /**
  *	Saves permission
  *
  *	@param		pd	RM_Permission_Data	data
  *	@return		void
  */
 public function savePermission($accessId)
 {
     $str = M('Extensions')->listToBinary($this->_permData[$accessId], $this->_listFmt);
     $this->_dbh->exec("REPLACE INTO {$this->_pdTable} (pd_access_id, pd_data) VALUES (?,?)", $accessId, $str);
     if ($this->_cacheNs) {
         M('Cache')->put($this->_cacheNs, $accessId, $str);
     }
 }
Beispiel #2
0
 /**
  *	Updates used space on device.
  *
  *	@return		void
  */
 public function devChSpace($devId, $size)
 {
     if ($size == 0) {
         return;
     }
     $cnt = $this->_dbh->exec("UPDATE {$this->_devTable} SET used_size = used_size + ? WHERE id = ? AND used_size + ? < total_size", $size, $devId, $size);
     if ($cnt != 1) {
         throw new RM_ObjectFs_Exception_Unavailable("Not enough space on device#{$devId} for {$size} byte(s)");
     }
 }
Beispiel #3
0
 protected function _saveObjectHelper($insert, RM_Store_Object $object, RM_Validator_iValidator $validator = NULL)
 {
     if (isNull($validator)) {
         $validator = $object->validator();
     }
     if (!isNull($validator) && !$validator->check($object->props())) {
         return FALSE;
     }
     $meta = $this->_mediator->meta;
     $fields = array();
     $allFields = array();
     $props = $object->props();
     foreach ($meta->propList() as $prop) {
         $allFields[$meta->dbField($prop)] = $props[$prop];
         if ($insert or $props[$prop] !== $object->_propInitial($prop)) {
             $field = $meta->dbQuoted($prop);
             $fields[$insert ? $field : "{$field} = ?"] = $props[$prop];
         }
     }
     if (!$fields) {
         return FALSE;
     }
     if ($insert) {
         $binds = $fields;
         $query = "INSERT INTO {$this->_table}(" . join(',', array_keys($fields)) . ") VALUES(" . sqlBinds($fields) . ")";
     } else {
         list($where, $wbinds) = $this->_getDbWhere($object);
         $binds = array_merge($fields, $wbinds);
         $query = "UPDATE {$this->_table} SET " . join(',', array_keys($fields)) . " WHERE {$where}";
     }
     $this->_dbh->exec($query, array_values($binds));
     if (!isNull($this->_tableHistory)) {
         $obHistory = M('Store')->history();
         if ($obHistory->_closeStamp() || $object->isChildren()) {
             list($where, $wbinds) = $this->_getDbWhere($object);
             $query = "UPDATE {$this->_tableHistory} SET stamp_close = " . $obHistory->getStamp() . ", last_state = 0 WHERE " . $where . " AND last_state = 1";
             $this->_dbh->exec($query, $wbinds);
         }
         $binds = array_merge(array('stamp_open' => $obHistory->getStamp(), 'stamp_close' => $obHistory->getFarFuture(), 'last_state' => 1), $allFields);
         $query = "REPLACE INTO {$this->_tableHistory}( " . join(',', array_keys($binds)) . ") VALUES(" . sqlBinds($binds) . ")";
         $this->_dbh->exec($query, array_values($binds));
         $obHistory->register($object, $insert ? RM_Store_History::OBJECT_CREATE : RM_Store_History::OBJECT_EDIT);
     }
     if ($this->_autoId and !$object->{$this->_autoId}) {
         $object->{$this->_autoId} = $this->_dbh->lastInsertID();
         $allFields[$meta->dbField($this->_autoId)] = $object->{$this->_autoId};
     }
     if ($this->_cacheNs) {
         $this->cacheUpdate($object, $allFields);
     }
     return TRUE;
 }