Exemple #1
0
 public function receive($endpoint, $payload = array())
 {
     if (!array_key_exists('entities', $payload) || !is_array($payload['entities']) || count($payload['entities']) <= 0) {
         throw new MalformedRequestException('No entities were passed with the request.');
     }
     if (!array_key_exists('metadata', $payload)) {
         throw new MalformedRequestException('No metadata was passed with the request.');
     }
     $this->metadata = $payload['metadata'];
     // Mark the remote as active so we don't create an infinite loop.
     BounceManager::getInstance()->addRemote($this->remote);
     // Note we'll never unset this flag because it's safe to say that all
     // entity updates done in this request are because of a publisher operation,
     // so we shouldn't do any entity tracking on any saves for this request.
     // Drupal's static cache (which powers publisher_set_flag) will be reset
     // after the request has been completed.
     publisher_set_flag('importing_entities');
     foreach ($payload['entities'] as $entity) {
         if (!$this->importEntity($entity)) {
             drupal_set_message('There was an error importing one of the entities. Because the entity that failed ' . 'might have been a dependency of another entity, the operation has been cancelled.', 'error');
             break;
         }
     }
     // Mark the remote as finished so we can send to it later.
     BounceManager::getInstance()->completeRemote($this->remote);
     return array();
 }
Exemple #2
0
 public function receive($endpoint, $payload = array())
 {
     if (!array_key_exists('entities', $payload)) {
         throw new MalformedRequestException('The payload must contain entities to delete, but it does not.');
     }
     $deleted[] = array();
     foreach ($payload['entities'] as $to_delete) {
         if (Entity::exists($to_delete['entity_uuid'], $to_delete['entity_type'])) {
             publisher_set_flag('publisher_deleting');
             $entity_ids = entity_get_id_by_uuid($to_delete['entity_type'], array($to_delete['entity_uuid']));
             $entity_id = count($entity_ids) > 0 ? reset($entity_ids) : false;
             if ($entity_id === false) {
                 continue;
             }
             entity_delete($to_delete['entity_type'], $entity_id);
             drupal_set_message(t('<strong>:type</strong> @title deleted successfully.', array(':type' => $to_delete['entity_type'], '@title' => $to_delete['entity_title'])));
             $deleted[] = $to_delete;
         } else {
             drupal_set_message(t('<strong>:type</strong> @title did not exist.', array(':type' => $to_delete['entity_type'], '@title' => $to_delete['entity_title'])));
             $deleted[] = $to_delete;
         }
     }
     return array('deleted' => $deleted);
 }