Exemple #1
0
 /**
  * Add a dependency into cache.
  *
  * If object does not have an UUID it will be created, then stored into the
  * local database.
  *
  * This method returns the object UUID, you can use this variable to store
  * it for further usage, in save() for example.
  *
  * @param string $type
  *   Object type to add as dependency.
  * @param int $identifier
  *   Internal id of object.
  * 
  * @return string
  *   Object UUID you can then store as data.
  */
 public function addDependency($type, $identifier)
 {
     $uuid = Yamm_EntityFactory::getUuidForType($type, $identifier, TRUE);
     $this->__dependencies[$uuid] = $uuid;
     return $uuid;
 }
Exemple #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);
     }
 }
Exemple #3
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;
 }