コード例 #1
0
ファイル: LocaleTranslation.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  *
  * The translation update functions executed here are batch operations which
  * are also used in translation update batches. The batch functions may need
  * to be executed multiple times to complete their task, typically this is the
  * translation import function. When a batch function is not finished, a new
  * queue task is created and added to the end of the queue. The batch context
  * data is needed to continue the batch task is stored in the queue with the
  * queue data.
  */
 public function processItem($data)
 {
     $this->moduleHandler->loadInclude('locale', 'batch.inc');
     list($function, $args) = $data;
     // We execute batch operation functions here to check, download and import
     // the translation files. Batch functions use a context variable as last
     // argument which is passed by reference. When a batch operation is called
     // for the first time a default batch context is created. When called
     // iterative (usually the batch import function) the batch context is passed
     // through via the queue and is part of the $data.
     $last = count($args) - 1;
     if (!is_array($args[$last]) || !isset($args[$last]['finished'])) {
         $batch_context = ['sandbox' => [], 'results' => [], 'finished' => 1, 'message' => ''];
     } else {
         $batch_context = $args[$last];
         unset($args[$last]);
     }
     $args = array_merge($args, [&$batch_context]);
     // Call the batch operation function.
     call_user_func_array($function, $args);
     // If the batch operation is not finished we create a new queue task to
     // continue the task. This is typically the translation import task.
     if ($batch_context['finished'] < 1) {
         unset($batch_context['strings']);
         $this->queue->createItem([$function, $args]);
     }
 }
コード例 #2
0
ファイル: QueueTest.php プロジェクト: sgtsaughter/d8portfolio
 /**
  * Queues and dequeues a set of items to check the basic queue functionality.
  *
  * @param \Drupal\Core\Queue\QueueInterface $queue1
  *   An instantiated queue object.
  * @param \Drupal\Core\Queue\QueueInterface $queue2
  *   An instantiated queue object.
  */
 protected function queueTest($queue1, $queue2)
 {
     // Create four items.
     $data = array();
     for ($i = 0; $i < 4; $i++) {
         $data[] = array($this->randomMachineName() => $this->randomMachineName());
     }
     // Queue items 1 and 2 in the queue1.
     $queue1->createItem($data[0]);
     $queue1->createItem($data[1]);
     // Retrieve two items from queue1.
     $items = array();
     $new_items = array();
     $items[] = $item = $queue1->claimItem();
     $new_items[] = $item->data;
     $items[] = $item = $queue1->claimItem();
     $new_items[] = $item->data;
     // First two dequeued items should match the first two items we queued.
     $this->assertEqual($this->queueScore($data, $new_items), 2, 'Two items matched');
     // Add two more items.
     $queue1->createItem($data[2]);
     $queue1->createItem($data[3]);
     $this->assertTrue($queue1->numberOfItems(), 'Queue 1 is not empty after adding items.');
     $this->assertFalse($queue2->numberOfItems(), 'Queue 2 is empty while Queue 1 has items');
     $items[] = $item = $queue1->claimItem();
     $new_items[] = $item->data;
     $items[] = $item = $queue1->claimItem();
     $new_items[] = $item->data;
     // All dequeued items should match the items we queued exactly once,
     // therefore the score must be exactly 4.
     $this->assertEqual($this->queueScore($data, $new_items), 4, 'Four items matched');
     // There should be no duplicate items.
     $this->assertEqual($this->queueScore($new_items, $new_items), 4, 'Four items matched');
     // Delete all items from queue1.
     foreach ($items as $item) {
         $queue1->deleteItem($item);
     }
     // Check that both queues are empty.
     $this->assertFalse($queue1->numberOfItems(), 'Queue 1 is empty');
     $this->assertFalse($queue2->numberOfItems(), 'Queue 2 is empty');
 }
コード例 #3
0
ファイル: HttpFetcher.php プロジェクト: alnutile/drunatra
 /**
  * {@inheritdoc}
  *
  * @todo Call sourceDelete() when changing plugins.
  */
 public function onFeedDeleteMultiple(array $feeds)
 {
     if ($this->configuration['use_pubsubhubbub']) {
         foreach ($feeds as $feed) {
             $item = array('type' => $this->getPluginId(), 'id' => $feed->id());
             // Unsubscribe from feed.
             $this->unsubscribeQueue->createItem($item);
         }
     }
     // Remove caches and files for this feeds.
     foreach ($feeds as $feed) {
         $this->clear($feed);
     }
 }
コード例 #4
0
ファイル: UpdateProcessor.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function deleteQueueItem($item)
 {
     return $this->fetchQueue->deleteItem($item);
 }