示例#1
0
 /**
  * Get UUID for object.
  *
  * @param string $type
  * @param int|string $identifier
  * 
  * @return string
  */
 public static function getUuidForType($type, $identifier, $generate = FALSE)
 {
     if (!($uuid = yamm_api_uuid_get($type, $identifier))) {
         if ($generate) {
             $uuid = yamm_api_uuid_create();
             yamm_api_uuid_save($uuid, $type, $identifier);
         } else {
             throw new Yamm_Entity_UnknownUuidException("Unable to fetch UUID for type " . $type . ", identifier " . $identifier . ".");
         }
     }
     return $uuid;
 }
示例#2
0
文件: Entity.php 项目: pounard/yamm
 /**
  * Save object on local Drupal. This should be only call within the
  * Yamm_EntityParser implementation.
  */
 public function save()
 {
     $this->__hookPresave();
     // Update object
     try {
         $this->__identifier = Yamm_EntityFactory::getIdentifierByUuid($this->__uuid);
         // Check object has not been deleted on client
         if (!$this->_objectExists()) {
             throw new Yamm_Entity_DeletedOnClientException("Object has been deleted");
         }
         $this->_update($this->__object, $this->__identifier);
         yamm_api_debug('Update @entity', array('@entity' => $this));
         $this->__hookUpdate();
     } catch (Yamm_Entity_DeletedOnClientException $e) {
         yamm_api_uuid_delete($this->__uuid);
         $this->__identifier = $this->_save($this->__object);
         if (!$this->__identifier) {
             yamm_api_debug('Insert after deletion failed for @entity', array('@entity' => $this));
             throw new Yamm_Entity_UnableToSaveObjectException("Object could not be saved (after deletion)");
         }
         yamm_api_uuid_save($this->__uuid, $this->_type, $this->__identifier);
         yamm_api_debug('Insert after deletion for @entity', array('@entity' => $this));
         $this->__hookSave();
     } catch (Yamm_Entity_UnknownUuidException $e) {
         $this->__identifier = $this->_save($this->__object);
         if (!$this->__identifier) {
             yamm_api_debug('Insert failed for @entity', array('@entity' => $this));
             throw new Yamm_Entity_UnableToSaveObjectException("Object could not be saved");
         }
         yamm_api_uuid_save($this->__uuid, $this->_type, $this->__identifier);
         yamm_api_debug('Insert @entity', array('@entity' => $this));
         $this->__hookSave();
     }
 }