Exemplo n.º 1
0
 /**
  * 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);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Create a content type revision, before saving new one
  *
  * This is kind goret (french word), what will be done here:
  *  * Copy old content type to a new name.
  *  * As the old content type has a new name, create a UUID for it
  *  * Change all node with content type name to old content type name (they
  *    should keep their old fields etc).
  *  * Alter the old content type with new one coming from network, and TADA
  *    we have multiple content types, each node keeping it content type.
  */
 private function __revisionContent($new_export, $type_name)
 {
     // Compare both content types.
     $data = cache_get('content_entity_' . $type_name, $table = 'yamm_data_store');
     $old_hash = $data->data;
     $new_hash = md5($new_export);
     if ($old_hash != $new_hash) {
         // Duplicate content, change its name.
         $revision = time();
         $new_name = $type_name . '-' . $revision;
         db_query("UPDATE {node_type} SET type = '%s', name = CONCAT(name, ' Revision %s') WHERE type = '%s'", array($new_name, $revision, $type_name));
         // Generate and save new UUID for old type.
         Yamm_EntityFactory::getUuidForType('content', $new_name, TRUE);
         // Update all nodes.
         db_query("UPDATE {node} SET type = '%s' WHERE type = '%s'", array($new_name, $type_name));
         // Save won't rely on cache.
         content_clear_type_cache();
         $this->_save($new_export);
     }
 }
Exemplo n.º 3
0
 /**
  * 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();
     }
 }
Exemplo n.º 4
0
 /**
  * (non-PHPdoc)
  * @see IFormable::formSubmit()
  */
 public function formSubmit(&$values)
 {
     $this->_options['backend'] = $values['backend']['backend_type'];
     try {
         $backend = $this->getBackend();
         $backend->formSubmit($values['backend']['backend_form']);
     } catch (Yamm_Sync_ProfileException $e) {
         /* Silent error. */
     }
     foreach ($values['types'] as $type) {
         $settings = Yamm_EntityFactory::getEntitySettingsInstance($type);
         $settings->formSubmit($values['entity_' . $type]);
         // Do not save empty options.
         if ($settings->getOptionsCount() > 0) {
             $this->_options['entity_' . $type] = $settings->getOptions();
         }
     }
 }
Exemplo n.º 5
0
 /**
  * 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');
 }
Exemplo n.º 6
0
 /**
  * (non-PHPdoc)
  * @see Yamm_Sync_Backend_Interface::getEntities()
  */
 public function getEntities($limit = YAMM_SYNC_DEFAULT_LIMIT, $offset = 0, $phase = 'default')
 {
     $ret = array();
     if (!($view = self::loadView($phase))) {
         throw new Yamm_Sync_ProfileException("View '" . $phase . "' does not exist.");
     }
     try {
         // Prepare view.
         $view->set_display(NULL);
         $view->pre_execute();
         // Emulate incremental behavior using page feature.
         $view->set_use_pager(TRUE);
         $view->set_items_per_page($limit);
         $view->set_offset($offset);
         // Get results.
         $view->execute();
         $count = count($view->result);
         watchdog('yamm', 'View @view exports @count objects', array('@view' => $view->name, '@count' => $count), WATCHDOG_DEBUG);
         $entity_type = Yamm_Sync_Backend_Views::getViewEntityType($view);
         foreach ($view->result as $result) {
             // We hope our user is not stupid, and set only one field which is the
             // internal object id.
             // FIXME: We could use the base field here.
             $result = (array) $result;
             $identifier = array_shift($result);
             try {
                 $uuid = Yamm_EntityFactory::getUuidForType($entity_type, $identifier, TRUE);
                 $entity = Yamm_Entity::loadByUuid($uuid);
                 $ret[] = $entity;
             } catch (Yamm_EntityException $e) {
                 // Just alert the site admin this entity build failed, but continue
                 // with others.
                 watchdog('yamm', '@e', array('@e' => $e->getMessage()), WATCHDOG_ERROR);
             }
         }
     } catch (Yamm_Sync_ProfileException $e) {
         watchdog('yamm_pull', '@e', array('@e' => $e->getMessage()), WATCHDOG_ERROR);
     }
     // Keep some memory to survive.
     $view->destroy();
     unset($view);
     return $ret;
 }