create() публичный Метод

Create a new object in the backend.
public create ( Horde_Kolab_Storage_Folder $folder, Horde_Kolab_Storage_Object_Writer $data, string $type ) : boolean | string
$folder Horde_Kolab_Storage_Folder The folder to retrieve the data object from.
$data Horde_Kolab_Storage_Object_Writer The data writer.
$type string The type of object to be stored.
Результат boolean | string The return value of the append operation.
Пример #1
0
    public function testStore()
    {
        if (version_compare(PHP_VERSION, '5.5.0', '>=') && version_compare(PHP_VERSION, '5.5.3', '<=')) {
            $this->markTestSkipped('PHP version with broken quoted-printable-encode');
        }
        setlocale(LC_MESSAGES, 'C');
        $factory = new Horde_Kolab_Format_Factory();
        $writer = new Horde_Kolab_Storage_Object_Writer_Format($factory);
        $folder = $this->getMock('Horde_Kolab_Storage_Folder');
        $folder->expects($this->once())->method('getPath')->will($this->returnValue('INBOX'));
        $driver = new Horde_Kolab_Storage_Stub_Driver('user');
        $object = new Horde_Kolab_Storage_Object();
        $object->setDriver($driver);
        $object->setData(array('summary' => 'TEST', 'description' => 'test', 'uid' => 'ABC1234'));
        $object->create($folder, $writer, 'note');
        $result = $driver->messages['INBOX'][0];
        $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 @version@
MIME-Version: 1.0
X-Kolab-Type: application/x-vnd.kolab.note
Content-Type: multipart/mixed; name="Kolab Groupware Data";
 boundary=""
Content-Disposition: attachment; filename="Kolab Groupware Data"

This message is in MIME format.

--=_
Content-Type: text/plain; name="Kolab Groupware Information"; charset=utf-8
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
Content-Transfer-Encoding: quoted-printable

<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<note version=3D"1.0">
  <uid>ABC1234</uid>
  <body></body>
  <categories></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>TEST</summary>
  <background-color>#000000</background-color>
  <foreground-color>#ffff00</foreground-color>
</note>

--=_
', $result);
    }
Пример #2
0
 public function testKolabPart()
 {
     $driver = new Horde_Kolab_Storage_Stub_Driver('user');
     $folder = $this->getMock('Horde_Kolab_Storage_Folder');
     $folder->expects($this->once())->method('getPath')->will($this->returnValue('INBOX'));
     $writer = $this->getMock('Horde_Kolab_Storage_Object_Writer');
     $writer->expects($this->once())->method('save')->will($this->returnValue('<content/>'));
     $object = new Horde_Kolab_Storage_Object();
     $object->setData(array('uid' => 'UID'));
     $object->setDriver($driver);
     $object->create($folder, $writer, 'event');
     $message = $driver->fetchComplete('INBOX', 0);
     $this->assertEquals('inline', $message[1]->getPart('2')->getDisposition());
     $this->assertEquals('xml', $message[1]->getPart('2')->getDispositionParameter('x-kolab-type'));
     $this->assertEquals('kolab.xml', $message[1]->getPart('2')->getName());
     $this->assertEquals('application/x-vnd.kolab.event', $message[1]->getPart('2')->getType());
     $this->assertEquals('<content/>', trim($message[1]->getPart('2')->getContents()));
 }
Пример #3
0
 /**
  * Create a new object.
  *
  * @param array   &$object The array that holds the object data.
  * @param boolean $raw     True if the data to be stored has been provided in
  *                         raw format.
  *
  * @return string The ID of the new object or true in case the backend does
  *                not support this return value.
  *
  * @throws Horde_Kolab_Storage_Exception In case an error occured while
  *                                       saving the data.
  */
 public function create(&$object, $raw = false)
 {
     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();
     }
     $storage_object = new Horde_Kolab_Storage_Object();
     $storage_object->setDriver($this->_driver);
     $storage_object->setData($object);
     if (empty($object['uid'])) {
         $object['uid'] = $storage_object->getUid();
     }
     $result = $storage_object->create($this->_folder, $writer, $this->getType());
     if ($result === true) {
         $params = array();
     } else {
         $params = array('changes' => array(Horde_Kolab_Storage_Folder_Stamp::ADDED => array($result => $storage_object), Horde_Kolab_Storage_Folder_Stamp::DELETED => array()));
     }
     $this->synchronize($params);
     return $result;
 }