/** * Internal method shared between _save() and _update() methods. * * @param object &$node */ private function __restoreData($node) { // Be sure to update current revision unset($node->revision); // Restore owner if ($user_uuid = $this->getData('user')) { $node->uid = (int) Yamm_EntityFactory::getIdentifierByUuid($user_uuid); } // Restore terms $node->taxonomy = array(); foreach ($this->getData('terms') as $term_uuid) { $tid = (int) Yamm_EntityFactory::getIdentifierByUuid($term_uuid); $node->taxonomy[$tid] = $tid; } // Restore node referenced nodes foreach ($this->getData('nodes') as $field_name => $value) { foreach ($value as $index => $node_uuid) { $referenced = (int) Yamm_EntityFactory::getIdentifierByUuid($node_uuid); $node->{$field_name}[$index] = array('nid' => $referenced); } } }
/** * 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(); } }
/** * Internal method shared between _save() and _update() methods. * * @param object &$node * @return void */ private function __restoreData(&$edit) { // Restore vocabulary. $edit['vid'] = (int) Yamm_EntityFactory::getIdentifierByUuid($this->getData('vocabulary')); $edit['parent'] = array(); // Restore parents. foreach ($this->getData('parents') as $uuid) { $tid = (int) Yamm_EntityFactory::getIdentifierByUuid($uuid); $edit['parent'][$tid] = $tid; } // Restore relations. foreach ($this->getData('relations') as $uuid) { $tid = (int) Yamm_EntityFactory::getIdentifierByUuid($uuid); $edit['relations'][$tid] = $tid; } // Restore synonyms. $edit['synonyms'] = $this->getData('synonyms'); }