/**
  * @param Query $query
  * @param callable $transform
  * @param null $readEndpoint
  * @param null $writeEndpoint
  * @param bool $commit
  */
 public function updateBufferedPlugin(Query $query, callable $transform = null, $readEndpoint = null, $writeEndpoint = null, $commit = true)
 {
     /**
      * @var PrefetchIterator $prefetch
      * @var BufferedAdd $update
      * @var SelectDocument $document
      */
     $prefetch = $this->getSolarium()->getPlugin('prefetchiterator');
     $prefetch->setPrefetch($this->getBuffer());
     $prefetch->setQuery($query);
     $prefetch->setEndpoint($readEndpoint);
     $update = $this->solarium->getPlugin('bufferedadd');
     $update->setBufferSize($this->getBuffer());
     $update->setEndpoint($writeEndpoint);
     foreach ($prefetch as $document) {
         if (is_callable($transform)) {
             $document = $transform($document);
         } else {
             $document = new UpdateDocument($document->getFields());
         }
         $update->addDocument($document);
     }
     $update->flush();
     if ($commit === true) {
         $update->commit();
     }
 }
Esempio n. 2
0
 public function testRemovePluginAndGetPluginsWithObjectInput()
 {
     $options = array('option1' => 1);
     $this->client->registerPlugin('testplugin', __NAMESPACE__ . '\\MyClientPlugin', $options);
     $plugin = $this->client->getPlugin('testplugin');
     $plugins = $this->client->getPlugins();
     $this->assertEquals(array('testplugin' => $plugin), $plugins);
     $this->client->removePlugin($plugin);
     $plugins = $this->client->getPlugins();
     $this->assertEquals(array(), $plugins);
 }