Ejemplo n.º 1
0
 public function execute($selected_entity_uuid, $selected_entity_type, &$context)
 {
     // Load the entity.
     $entity = Entity::loadByUUID($selected_entity_uuid, $selected_entity_type);
     if (!$entity) {
         drupal_set_message(t('An invalid entity was found.'), 'error');
         $this->updateContextMessages(null, $context);
         return;
     }
     // Get the transaction session, and fail if we don't have it.
     $transaction_session = TransactionSession::getFromSession();
     if (!$transaction_session) {
         $current_set =& _batch_current_set();
         $current_set['success'] = false;
         drupal_set_message(t('We lost the transaction session.'), 'error');
         $this->updateContextMessages($entity, $context);
         return;
     }
     // Prepare to send the entity over to the receiving server.
     $entities = array();
     $transaction_entities = $transaction_session->getAllEntities();
     // Make sure the transaction entity exists.
     if (array_key_exists($entity->uuid(), $transaction_entities)) {
         $transaction_entity = $transaction_entities[$entity->uuid()];
     } else {
         drupal_set_message(t('An invalid entity was found.'), 'error');
         $this->updateContextMessages($entity, $context);
         return;
     }
     // Get the relationships for the entity.
     $relationships = array();
     foreach ($transaction_session->getRelationships() as $relationship) {
         if ($relationship['source_uuid'] == $entity->uuid() && (!$entity->supportsRevisions() || $relationship['source_vuuid'] == $entity->vuuid())) {
             $relationships[] = $relationship;
         }
     }
     // Send the entity revisions.
     $entities[] = array('entity_type' => $entity->type(), 'uuid' => $entity->uuid(), 'vuuid' => $entity->vuuid(), 'revisions' => $transaction_entity['revisions_payload'], 'relationships' => $relationships);
     $payload = array('entities' => $entities, 'metadata' => $transaction_session->getMetadata($entity->uuid()));
     // Send the request.
     $transaction = new Transaction($transaction_session->getRemote());
     $response = $transaction->send('import', $payload);
     if (!$response['success']) {
         $message = "There was an error sending the <strong>{$entity->type()}</strong> <code>{$entity->id()}</code> to the remote. Look at the recent log messages for more details.";
         drupal_set_message($message, 'error');
         watchdog('publisher', $message, array(), WATCHDOG_WARNING);
         Debug::wd($response);
     } elseif (empty($response['messages'])) {
         drupal_set_message('The operation was successful, but nothing was done on the remote. This probably means there weren\'t any updates to move.');
     }
     // Mark the entity as synced if the response was successful.
     if ($response['success']) {
         publisher_entity_tracking_mark_as_synced($entity, $transaction_session->getRemote());
     }
     $this->updateContextMessages($entity, $context);
 }
 public function execute(array $relationships, Remote $remote, &$context)
 {
     $transaction = new Transaction($remote);
     $response = $transaction->send('relationships', array('relationships' => $relationships));
     if (!$response['success']) {
         $message = "There was an error sending the relationships over to the target server. Look at the error log for more details.";
         drupal_set_message($message, 'error');
         watchdog('publisher', $message, array(), WATCHDOG_WARNING);
         Debug::wd($response);
     }
     $this->updateContextMessages(null, $context);
 }
Ejemplo n.º 3
0
 public function execute(Remote $remote, $entity_uuid, $entity_type, $entity_title, &$context)
 {
     $post_data = array('entities' => array(array('entity_uuid' => $entity_uuid, 'entity_type' => $entity_type, 'entity_title' => $entity_title)));
     $transaction = new Transaction($remote);
     $response = $transaction->send('delete', $post_data);
     if (!$response['success']) {
         $message = t('There was an error deleting the <strong>:type</strong> @title from the remote. See recent log messages for more details.', array(':type' => $entity_type, '@title' => $entity_title));
         drupal_set_message($message, 'error');
         watchdog('publisher', $message, array(), WATCHDOG_WARNING);
         Debug::wd($response);
     }
     if (!empty($response['deleted']) && is_array($response['deleted'])) {
         foreach ($response['deleted'] as $deleted_entity) {
             publisher_deleted_entities_delete($deleted_entity['entity_uuid'], $deleted_entity['entity_type'], $remote);
         }
     }
     $this->updateContextMessages(null, $context);
 }
Ejemplo n.º 4
0
 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);
 }