Update only fields with changes
This commit is contained in:
@@ -44,16 +44,11 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
return parent::insert($entity);
|
return parent::insert($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Entity $entity
|
|
||||||
* @return Entity
|
|
||||||
*/
|
|
||||||
public function update(Entity $entity) {
|
public function update(Entity $entity) {
|
||||||
$entity->setLastModified(time());
|
$entity->setLastModified(time());
|
||||||
return parent::update($entity);
|
return parent::update($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return Entity if not found
|
* @return Entity if not found
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ namespace OCA\Deck\Db;
|
|||||||
class Entity extends \OCP\AppFramework\Db\Entity {
|
class Entity extends \OCP\AppFramework\Db\Entity {
|
||||||
|
|
||||||
private $_relations = array();
|
private $_relations = array();
|
||||||
private $_updatedFields = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a property as relation so it will not get updated using Mapper::update
|
* Mark a property as relation so it will not get updated using Mapper::update
|
||||||
@@ -53,16 +52,8 @@ class Entity extends \OCP\AppFramework\Db\Entity {
|
|||||||
*/
|
*/
|
||||||
protected function markFieldUpdated($attribute){
|
protected function markFieldUpdated($attribute){
|
||||||
if(!in_array($attribute, $this->_relations)) {
|
if(!in_array($attribute, $this->_relations)) {
|
||||||
$this->_updatedFields[$attribute] = true;
|
parent::markFieldUpdated($attribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* overwritten from \OCP\AppFramework\Db\Entity to avoid writing relational attributes
|
|
||||||
* @return array Array of field's update status
|
|
||||||
*/
|
|
||||||
public function getUpdatedFields(){
|
|
||||||
return $this->_updatedFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user