load() public method

Loads the object from the backend.
public load ( string $backend_id, Horde_Kolab_Storage_Folder $folder, Horde_Kolab_Storage_Object_Writer $data, Horde_Mime_Part $structure = null )
$backend_id string The object ID within the backend.
$folder Horde_Kolab_Storage_Folder The folder to retrieve the data object from.
$data Horde_Kolab_Storage_Object_Writer The data parser.
$structure Horde_Mime_Part The MIME message structure of the object.
Example #1
0
    public function testStore()
    {
        $driver = new Horde_Kolab_Storage_Stub_Driver('user');
        $driver->setMessage('INBOX', 1, file_get_contents(__DIR__ . '/../../../../fixtures/note.eml'));
        $factory = new Horde_Kolab_Format_Factory();
        $writer = new Horde_Kolab_Storage_Object_Writer_Format($factory);
        $object = new Horde_Kolab_Storage_Object();
        $object->setDriver($driver);
        $folder = $this->getMock('Horde_Kolab_Storage_Folder');
        $folder->expects($this->once())->method('getPath')->will($this->returnValue('INBOX'));
        $folder->expects($this->once())->method('getType')->will($this->returnValue('note'));
        $structure = $driver->fetchComplete('INBOX', 1);
        $object->load(1, $folder, $writer, $structure[1]);
        $object->setData(array('summary' => 'NEW', 'description' => 'test', 'uid' => 'ABC1234'));
        $object->save($writer);
        $result = $driver->messages['INBOX'][2];
        $result = preg_replace(array('/=20/', '/Date: .*/', '/boundary=".*"/', '/--=_.*/', '/<creation-date>[^<]*/', '/<last-modification-date>[^<]*/', '/\\r\\n/', '/=\\n/'), array(' ', 'Date: ', 'boundary=""', '--=_', '<creation-date>', '<last-modification-date>', "\n", ''), $result);
        $this->assertEquals('From: user
To: user
Date: 
Subject: ABC1234
User-Agent: Horde::Kolab::Storage v@version@
MIME-Version: 1.0
X-Kolab-Type: application/x-vnd.kolab.note
Content-Type: multipart/mixed; boundary="";
 name="Kolab Groupware Data"
Content-Disposition: attachment; filename="Kolab Groupware Data"

This message is in MIME format.

--=_
Content-Type: text/plain; charset=utf-8; name="Kolab Groupware Information"
Content-Disposition: inline; filename="Kolab Groupware Information"

This is a Kolab Groupware object. To view this object you will need an email
client that understands the Kolab Groupware format. For a list of such email
clients please visit http://www.kolab.org/content/kolab-clients
--=_
Content-Type: application/x-vnd.kolab.note; name=kolab.xml
Content-Disposition: inline; x-kolab-type=xml; filename=kolab.xml

<?xml version="1.0" encoding="UTF-8"?>
<note version="1.0">
  <uid>ABC1234</uid>
  <body/>
  <categories/>
  <creation-date></creation-date>
  <last-modification-date></last-modification-date>
  <sensitivity>public</sensitivity>
  <product-id>Horde_Kolab_Format_Xml-@version@ (api version: 2)</product-id>
  <summary>NEW</summary>
  <x-test>other client</x-test>
  <background-color>#000000</background-color>
  <foreground-color>#ffff00</foreground-color>
</note>

--=_
', $result);
    }
Example #2
0
 /**
  * @expectedException Horde_Kolab_Storage_Object_Exception
  */
 public function testSaveException()
 {
     $data = $this->getMock('Horde_Kolab_Storage_Object_Writer');
     $this->driver->expects($this->once())->method('fetchComplete')->will($this->returnValue(array(new Horde_Mime_Headers(), $this->getMultipartMimeMessage('application/x-vnd.kolab.event'))));
     $this->driver->expects($this->once())->method('appendMessage')->will($this->returnValue(false));
     $object = new Horde_Kolab_Storage_Object();
     $this->folder->expects($this->once())->method('getType')->will($this->returnValue('event'));
     $this->folder->expects($this->once())->method('getPath')->will($this->returnValue('INBOX/Calendar'));
     $object->setDriver($this->driver);
     $object->load('1', $this->folder, $data, $this->getMultipartMimeMessage('application/x-vnd.kolab.event'));
     $object->save($data);
 }
Example #3
0
 /**
  * Retrieves the objects for the given UIDs.
  *
  * @param array   $uids The message UIDs.
  * @param boolean $raw  True if the raw format should be returned rather than
  *                      the parsed data.
  *
  * @return array An array of objects.
  * @throws new Horde_Kolab_Storage_Exception
  */
 public function fetch($uids, $raw = false)
 {
     if (empty($uids)) {
         return array();
     }
     if ($raw === false) {
         $writer = new Horde_Kolab_Storage_Object_Writer_Format(new Horde_Kolab_Format_Factory(), array('version' => $this->_version));
     } else {
         $writer = new Horde_Kolab_Storage_Object_Writer_Raw();
     }
     $objects = array();
     $structures = $this->_driver->fetchStructure($this->_folder->getPath(), $uids);
     foreach ($structures as $uid => $structure) {
         if (!isset($structure['structure'])) {
             throw new Horde_Kolab_Storage_Exception('Backend returned a structure without the expected "structure" element.');
         }
         $object = new Horde_Kolab_Storage_Object();
         $object->setDriver($this->_driver);
         $object->load($uid, $this->_folder, $writer, $structure['structure']);
         $objects[$uid] = $object;
     }
     return $objects;
 }