Imbo\Database\MongoDB::deleteImage PHP Method

deleteImage() public method

public deleteImage ( $user, $imageIdentifier )
    public function deleteImage($user, $imageIdentifier)
    {
        try {
            $data = $this->getImageCollection()->findOne(['user' => $user, 'imageIdentifier' => $imageIdentifier]);
            if ($data === null) {
                throw new DatabaseException('Image not found', 404);
            }
            $this->getImageCollection()->remove(['user' => $user, 'imageIdentifier' => $imageIdentifier], ['justOne' => true]);
        } catch (MongoException $e) {
            throw new DatabaseException('Unable to delete image data', 500, $e);
        }
        return true;
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Imbo\Database\MongoDB::deleteImage
  * @expectedException Imbo\Exception\DatabaseException
  * @expectedExceptionMessage Unable to delete image data
  * @expectedExceptionCode 500
  */
 public function testThrowsExceptionWhenMongoFailsDuringDeleteImage()
 {
     $this->imageCollection->expects($this->once())->method('findOne')->will($this->throwException(new MongoException()));
     $this->driver->deleteImage('key', 'identifier');
 }