Imbo\EventListener\ExifMetadata::save PHP Method

save() public method

Save metadata to database
public save ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The triggered event
    public function save(EventInterface $event)
    {
        $request = $event->getRequest();
        $database = $event->getDatabase();
        $user = $request->getUser();
        $imageIdentifier = $request->getImage()->getImageIdentifier();
        try {
            $database->updateMetadata($user, $imageIdentifier, $this->properties);
        } catch (DatabaseException $e) {
            $database->deleteImage($user, $imageIdentifier);
            throw new RuntimeException('Could not store EXIF-metadata', 500);
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @covers Imbo\EventListener\ExifMetadata::save
  * @expectedException Imbo\Exception\RuntimeException
  * @expectedExceptionMessage Could not store EXIF-metadata
  * @expectedExceptionCode 500
  */
 public function testWillDeleteImageWhenUpdatingMetadataFails()
 {
     $databaseException = $this->getMock('Imbo\\Exception\\DatabaseException');
     $database = $this->getMock('Imbo\\Database\\DatabaseInterface');
     $database->expects($this->once())->method('updateMetadata')->with('user', 'imageidentifier', [])->will($this->throwException($databaseException));
     $database->expects($this->once())->method('deleteImage')->with('user', 'imageidentifier');
     $image = $this->getMock('Imbo\\Model\\Image');
     $image->expects($this->once())->method('getImageIdentifier')->will($this->returnValue('imageidentifier'));
     $request = $this->getMock('Imbo\\Http\\Request\\Request');
     $request->expects($this->once())->method('getUser')->will($this->returnValue('user'));
     $request->expects($this->once())->method('getImage')->will($this->returnValue($image));
     $event = $this->getMock('Imbo\\EventManager\\Event');
     $event->expects($this->once())->method('getRequest')->will($this->returnValue($request));
     $event->expects($this->once())->method('getDatabase')->will($this->returnValue($database));
     $this->listener->save($event);
 }
All Usage Examples Of Imbo\EventListener\ExifMetadata::save