public function handleEntity(array &$metadata = array()) { $sitemap = xmlsitemap_link_load($this->original_entity->type(), $this->original_entity->id()); if ($sitemap) { $resolver = new Resolver($this->original_entity, false); $resolver->resolveDependencies(false, $sitemap, false, 'xmlsitemap'); $metadata['sitemap_definition'] = $resolver->resolvedDefinition(); } }
public function handleEntity(array &$metadata = array()) { $metadata['webform_validation']['processed'] = true; $metadata['webform_validation']['rules'] = array(); $validation = webform_validation_get_node_rules($this->original_entity->id()); if ($validation) { $resolver = new Resolver($this->original_entity, false); $resolver->resolveDependencies(false, $validation, false, 'webform_validation'); $metadata['webform_validation']['rules'] = $resolver->resolvedDefinition(); } }
public function diff() { // Get the preparer registry. $preparer_registry = new PreparerRegistry(); if (!$this->revisions_table) { // Prepare the entity. $preparer_registry->beforeSend($this->entity); $resolver = new Resolver($this->entity); return array($this->entity->vuuid() => array('additions' => $resolver->resolvedDefinition(), 'deletions' => array())); } // Get the revisions in between the two mentioned. If the old is blank, get the entire history. $revision_ids = $this->getRevisionHistory($this->old_revision_id, $this->new_revision_id); if ($revision_ids === false) { return false; } $payload = array(); $before_id = $this->old_revision_id ? $this->old_revision_id : -1; foreach ($revision_ids as $current_id) { // Load the entities. if ($before_id === -1) { $old_entity = null; } else { $old_entity = clone $this->entity; $old_entity->setRevision($before_id); } $new_entity = clone $this->entity; $new_entity->setRevision($current_id); // Pass the entity through the preparers to add any additional field metadata. if ($old_entity !== null) { $preparer_registry->beforeSend($old_entity); } $preparer_registry->beforeSend($new_entity); $payload[$current_id . '|' . $new_entity->vuuid()] = $this->singleDiff($old_entity, $new_entity); // Update the before ID. $before_id = $current_id; } return $payload; }
public function execute(Entity $entity, Remote $remote, array $options, &$context) { // Get the transaction from the session. $transaction_session = TransactionSession::getFromSession(); if (!$transaction_session) { return; } // Prepare the list of entities. $entities = array(); // Get the dependencies from the entity. try { if ($entity->supportsRevisions()) { $revision = $entity->revision(); $resolver = new RevisionResolver($entity); } else { $resolver = new Resolver($entity); } $dependencies = $resolver->dependencies(); if (!empty($revision)) { $entity->setRevision($revision); } } catch (ResolverException $ex) { $message = t('There was an error processing the dependencies for the <strong>:type</strong> <code>:id</code> to the remote. Skipping.', array(':type' => $entity->type(), ':id' => $entity->id())); drupal_set_message($message, 'error'); watchdog('publisher', $message, array(), WATCHDOG_WARNING); $this->updateContextMessages($entity, $context); return; } // Optionally mark the item as forced based on the entity type. $force = array_key_exists('force', $options) ? $options['force'] : false; drupal_alter('publisher_force_entity', $force, $entity); // Loop through each of the dependencies and mark them as forced if the options specify. if ($force) { foreach ($dependencies as $key => $dependency) { $dependencies[$key]['force'] = true; $dependencies[$key]['required'] = true; } } // Mark the root dependency as required if it has a status update. if (array_key_exists($entity->uuid(), $dependencies)) { $dependencies[$entity->uuid()]['source_required'] = false; $status = publisher_entity_tracking_get_status($entity->uuid(), $entity->type(), $remote->name); if (!$status->date_synced) { $dependencies[$entity->uuid()]['source_required'] = true; } } // Add the relationships to the transaction session. if ($resolver->relationships()) { $relationships = $transaction_session->getRelationships(); foreach ($resolver->relationships() as $relationship) { $relationships[] = $relationship; } $transaction_session->setRelationships($relationships); } // Add the metadata to the transaction session. if ($metadata = $resolver->metadata()) { $transaction_session->setMetadata($metadata); } // Prepare the post data. $post_data = array('dependencies' => $dependencies); // Start the transaction. $transaction = new Transaction($remote); $response = $transaction->send('begin', $post_data); if (!$response['success']) { $message = t('There was an error sending the <strong>:type</strong> <code>:id</code> to the remote. See recent log messages for more details.', array(':type' => $entity->type(), ':id' => $entity->id())); drupal_set_message($message, 'error'); watchdog('publisher', $message, array(), WATCHDOG_WARNING); Debug::wd($response); } $needs = array(); if (array_key_exists('dependencies', $response)) { $needs = $response['dependencies']; } // Check to see if the receiving server didn't need anything. if (count($needs) <= 0) { $message = t('The remote <strong>:remote</strong> already has the latest version of the <strong>:type</strong> <code>:id</code>', array(':remote' => $remote->label, ':type' => $entity->type(), ':id' => $entity->id())); drupal_set_message($message); watchdog('publisher', $message); $this->updateContextMessages($entity, $context); return; } // Make sure each of the needs is valid before adding them to the transaction // session. foreach ($needs as $need) { if (!array_key_exists('uuid', $need) || !array_key_exists('entity_type', $need) || !array_key_exists('need revision', $need) || !array_key_exists('have revision', $need)) { continue; } // Check to see if the entity exists and prepare its payload. $entity_need = Entity::loadByUUID($need['uuid'], $need['entity_type']); if (!$entity_need) { $message = t('One of the entities the destination server needs could not be found. Please check the development log for more details.'); drupal_set_message($message, 'error'); watchdog('publisher', $message, array(), WATCHDOG_WARNING); Debug::wd($need); continue; } // Generate the payload for the entity. $entity_need_payload = publisher_compare_revision_uuid($entity_need, $need['have your revision'], $need['need revision']); if ($entity_need_payload === false) { $message = t('One or more revisions did not exist for the <strong>:type</strong> <code>:id</code>', array(':type' => $entity_need->type(), ':id' => $entity_need->id())); drupal_set_message($message, 'error'); watchdog('publisher', $message, array(), WATCHDOG_WARNING); continue; } // Add the entity to the entities list in the transaction session. $entities[$entity_need->uuid()] = array('entity_type' => $entity_need->type(), 'entity_uuid' => $entity_need->uuid(), 'entity_id' => $entity_need->id(), 'entity_vuuid' => $entity_need->vuuid(), 'have_revision' => $need['have revision'], 'have_your_revision' => $need['have your revision'], 'need_revision' => $need['need revision'], 'required_from_remote' => $need['required_from_remote'], 'original_dependency' => $dependencies[$entity_need->uuid()], 'revisions_payload' => $entity_need_payload); } // Add the entities to the transaction session. $transaction_session->addEntities($entity->uuid(), $entities); $transaction_session->storeToSession(); // Finally, record the context messages. $this->updateContextMessages($entity, $context); }