Imbo\Database\MongoDB::updateMetadata PHP Method

updateMetadata() public method

public updateMetadata ( $user, $imageIdentifier, array $metadata )
$metadata array
    public function updateMetadata($user, $imageIdentifier, array $metadata)
    {
        try {
            // Fetch existing metadata and merge with the incoming data
            $existing = $this->getMetadata($user, $imageIdentifier);
            $updatedMetadata = array_merge($existing, $metadata);
            $this->getImageCollection()->update(['user' => $user, 'imageIdentifier' => $imageIdentifier], ['$set' => ['updated' => time(), 'metadata' => $updatedMetadata]], ['multiple' => false]);
        } catch (MongoException $e) {
            throw new DatabaseException('Unable to update meta data', 500, $e);
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * @covers Imbo\Database\MongoDB::updateMetadata
  * @expectedException Imbo\Exception\DatabaseException
  * @expectedExceptionMessage Unable to update meta data
  * @expectedExceptionCode 500
  */
 public function testThrowsExceptionWhenMongoFailsDuringUpdateMetadata()
 {
     $this->imageCollection->expects($this->once())->method('findOne')->will($this->returnValue(['some' => 'data']));
     $this->imageCollection->expects($this->once())->method('update')->will($this->throwException(new MongoException()));
     $this->driver->updateMetadata('key', 'identifier', ['key' => 'value']);
 }