class SearchApiSolrDevelCommands in Search API Solr 4.x
Same name and namespace in other branches
- 8.3 modules/search_api_solr_devel/src/Commands/SearchApiSolrDevelCommands.php \Drupal\search_api_solr_devel\Commands\SearchApiSolrDevelCommands
Defines Drush commands for the Search API Solr Devel.
Hierarchy
- class \Drupal\search_api_solr_devel\Commands\SearchApiSolrDevelCommands extends \Drush\Commands\DrushCommands
Expanded class hierarchy of SearchApiSolrDevelCommands
1 string reference to 'SearchApiSolrDevelCommands'
- drush.services.yml in modules/search_api_solr_devel/ drush.services.yml 
- modules/search_api_solr_devel/drush.services.yml
1 service uses SearchApiSolrDevelCommands
- search_api_solr_devel.commands in modules/search_api_solr_devel/ drush.services.yml 
- Drupal\search_api_solr_devel\Commands\SearchApiSolrDevelCommands
File
- modules/search_api_solr_devel/ src/ Commands/ SearchApiSolrDevelCommands.php, line 18 
Namespace
Drupal\search_api_solr_devel\CommandsView source
class SearchApiSolrDevelCommands extends DrushCommands {
  /**
   * The command helper.
   *
   * @var \Drupal\search_api_solr\Utility\SolrCommandHelper
   */
  protected $commandHelper;
  /**
   * Constructs a SearchApiSolrCommands object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The module handler.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function __construct(EntityTypeManagerInterface $entityTypeManager, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher) {
    parent::__construct();
    $this->commandHelper = new SolrCommandHelper($entityTypeManager, $moduleHandler, $eventDispatcher, 'dt');
  }
  /**
   * {@inheritdoc}
   */
  public function setLogger(LoggerInterface $logger) {
    parent::setLogger($logger);
    $this->commandHelper
      ->setLogger($logger);
  }
  /**
   * Deletes *all* documents on a Solr search server (including all indexes).
   *
   * @param string $server_id
   *   The ID of the server.
   *
   * @command search-api-solr:devel-delete-all
   *
   * @usage search-api-solr-devel:delete-all server_id
   *   Deletes *all* documents on server_id.
   *
   * @throws \Drupal\Component\Plugin\Exception\PluginException
   * @throws \Drupal\search_api_solr\SearchApiSolrException
   * @throws \Drupal\search_api\SearchApiException
   */
  public function deleteAll($server_id) {
    $servers = $this->commandHelper
      ->loadServers([
      $server_id,
    ]);
    if ($server = reset($servers)) {
      $backend = $server
        ->getBackend();
      if ($backend instanceof SolrBackendInterface) {
        $connector = $backend
          ->getSolrConnector();
        $update_query = $connector
          ->getUpdateQuery();
        $update_query
          ->addDeleteQuery('*:*');
        $connector
          ->update($update_query);
        foreach ($server
          ->getIndexes() as $index) {
          if ($index
            ->status() && !$index
            ->isReadOnly()) {
            if ($connector
              ->isCloud()) {
              $connector
                ->update($update_query, $backend
                ->getCollectionEndpoint($index));
            }
            $index
              ->reindex();
          }
        }
      }
      else {
        throw new SearchApiSolrException("The given server ID doesn't use the Solr backend.");
      }
    }
    else {
      throw new SearchApiException("The given server ID doesn't exist.");
    }
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| SearchApiSolrDevelCommands:: | protected | property | The command helper. | |
| SearchApiSolrDevelCommands:: | public | function | Deletes *all* documents on a Solr search server (including all indexes). | |
| SearchApiSolrDevelCommands:: | public | function | ||
| SearchApiSolrDevelCommands:: | public | function | Constructs a SearchApiSolrCommands object. | 
