lib/public/AppFramework/Db/Mapper.php
/**
	 * Updates an entry in the db from an entity
	 * @throws \InvalidArgumentException if entity has no id
	 * @param Entity $entity the entity that should be created
	 * @return Entity the saved entity with the set id
	 * @since 7.0.0 - return value was added in 8.0.0
	 */
Updates an entry in the db from an entity
@throws \InvalidArgumentException if entity has no id
@param Entity $entity the entity that should be created
@return Entity the saved entity with the set id
@since 7.0.0 - return value was added in 8.0.0
Updates an entry in the db from an entity @throws \ InvalidArgumentException if entity has no id @param Entity $entity the entity that should be created @return Entity the saved entity with the set id @since 7 . 0 . 0 - return value was added in 8 . 0 . 0
public function update(Entity $entity){
		$properties = $entity->getUpdatedFields();
		if(count($properties) === 0) {
			return $entity;
		}
		$id = $entity->getId();
		if($id === null){
			throw new \InvalidArgumentException(
				'Entity which should be updated has no id');
		}
		unset($properties['id']);
		$columns = '';
		$params = [];
		$i = 0;
		foreach($properties as $property => $updated) {
			$column = $entity->propertyToColumn($property);
			$getter = 'get' . ucfirst($property);
			$columns .= '`' . $column . '` = ?';
			if($i < count($properties)-1){
				$columns .= ',';
			}
			$params[] = $entity->$getter();
			$i++;
		}
		$sql = 'UPDATE `' . $this->tableName . '` SET ' .
				$columns . ' WHERE `id` = ?';
		$params[] = $id;
		$stmt = $this->execute($sql, $params);
		$stmt->closeCursor();
		return $entity;
	}
public function update ( Entity $ entity ) { $ properties = $ entity -> getUpdatedFields ( ) ; if ( count ( $ properties ) === 0 ) { return $ entity ; } $ id = $ entity -> getId ( ) ; if ( $ id === null ) { throw new \ InvalidArgumentException ( 'Entity which should be updated has no id' ) ; } unset ( $ properties [ 'id' ] ) ; $ columns = '' ; $ params = [ ] ; $ i = 0 ; foreach ( $ properties as $ property => $ updated ) { $ column = $ entity -> propertyToColumn ( $ property ) ; $ getter = 'get' . ucfirst ( $ property ) ; $ columns .= '`' . $ column . '` = ?' ; if ( $ i < count ( $ properties ) - 1 ) { $ columns .= ',' ; } $ params [ ] = $ entity -> $ getter ( ) ; $ i ++ ; } $ sql = 'UPDATE `' . $ this -> tableName . '` SET ' . $ columns . ' WHERE `id` = ?' ; $ params [ ] = $ id ; $ stmt = $ this -> execute ( $ sql , $ params ) ; $ stmt -> closeCursor ( ) ; return $ entity ; }
Updates an entry in the db from an entity
 @throws \InvalidArgumentException if entity has no id
 @param Entity $entity the entity that should be created
 @return Entity the saved entity with the set id
 @since 7.0.0 - return value was added in 8.0.0
Updates an entry in the db from an entity @throws \ InvalidArgumentException if entity has no id @param Entity $entity the entity that should be created @return Entity the saved entity with the set id @since 7 . 0 . 0 - return value was added in 8 . 0 . 0
// if entity wasn't changed it makes no sense to run a db query // entity needs an id // get updated fields to save, fields have to be set using a setter to // be saved // do not update the id field // build the fields // only append colon if there are more entries