class SolrCommandHelper in Search API Solr 8.3
Same name and namespace in other branches
- 4.x src/Utility/SolrCommandHelper.php \Drupal\search_api_solr\Utility\SolrCommandHelper
Provides functionality to be used by CLI tools.
Hierarchy
- class \Drupal\search_api\Utility\CommandHelper implements \Psr\Log\LoggerAwareInterface uses \Psr\Log\LoggerAwareTrait
- class \Drupal\search_api_solr\Utility\SolrCommandHelper
Expanded class hierarchy of SolrCommandHelper
2 files declare their use of SolrCommandHelper
- SearchApiSolrCommands.php in src/
Commands/ SearchApiSolrCommands.php - SearchApiSolrDevelCommands.php in modules/
search_api_solr_devel/ src/ Commands/ SearchApiSolrDevelCommands.php
File
- src/
Utility/ SolrCommandHelper.php, line 13
Namespace
Drupal\search_api_solr\UtilityView source
class SolrCommandHelper extends CommandHelper {
/**
* Re-install all Solr Field Types from their yml files.
*/
public function reinstallFieldtypesCommand() {
search_api_solr_install_missing_field_types();
}
/**
* Gets the config for a Solr search server.
*
* @param string $server_id
* The ID of the server.
* @param string $file_name
* The file name of the config zip that should be created.
* @param string $solr_version
* The targeted Solr version.
*
* @throws \Drupal\search_api\SearchApiException
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/
public function getServerConfigCommand($server_id, $file_name = NULL, $solr_version = NULL) {
$servers = $this
->loadServers([
$server_id,
]);
$server = reset($servers);
if (!$server) {
throw new SearchApiSolrException('Unknown server');
}
if ($solr_version) {
$config = $server
->getBackendConfig();
// Temporarily switch the Solr version but don't save!
$config['connector_config']['solr_version'] = $solr_version;
$server
->setBackendConfig($config);
}
$solr_configset_controller = new SolrConfigSetController();
$solr_configset_controller
->setServer($server);
$archive_options = new Archive();
$stream = FALSE;
if ($file_name !== NULL) {
// If no filename is provided, output stream is standard output.
$stream = fopen($file_name, 'w+b');
$archive_options
->setOutputStream($stream);
}
$zip = $solr_configset_controller
->getConfigZip($archive_options);
$zip
->finish();
if ($stream) {
fclose($stream);
}
}
/**
* Finalizes one ore more indexes.
*
* @param string[]|null $indexIds
* (optional) An array of index IDs, or NULL if we should finalize all
* enabled indexes.
* @param bool $force
* (optional) Force the finalization, even if the index isn't "dirty".
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \Drupal\search_api\SearchApiException
* @throws \Drupal\search_api_solr\SearchApiSolrException
*/
public function finalizeIndexCommand(array $indexIds = NULL, $force = FALSE) {
$servers = search_api_solr_get_servers();
if ($force) {
// It's important to mark all indexes as "dirty" before the first
// finalization runs because there might be dependencies between the
// indexes. Therefor we do the loop two times.
foreach ($servers as $server) {
foreach ($server
->getIndexes() as $index) {
if ($index
->status() && !$index
->isReadOnly() && (!$indexIds || in_array($index
->id(), $indexIds))) {
\Drupal::state()
->set('search_api_solr.' . $index
->id() . '.last_update', \Drupal::time()
->getRequestTime());
}
}
}
}
foreach ($servers as $server) {
/** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
$backend = $server
->getBackend();
foreach ($server
->getIndexes() as $index) {
if ($index
->status() && !$index
->isReadOnly() && (!$indexIds || in_array($index
->id(), $indexIds))) {
$backend
->finalizeIndex($index);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommandHelper:: |
protected | property | The entity type manager. | |
CommandHelper:: |
protected | property | The event dispatcher. | |
CommandHelper:: |
protected | property | The storage for search index entities. | |
CommandHelper:: |
protected | property | The module handler. | |
CommandHelper:: |
protected | property | The storage for search server entities. | |
CommandHelper:: |
protected | property | A callable for translating strings. | |
CommandHelper:: |
public | function | Deletes all items from one or more indexes. | |
CommandHelper:: |
public | function | Clears all indexes on a server. | |
CommandHelper:: |
public | function | Disables one or more enabled search indexes. | |
CommandHelper:: |
public | function | Disables a server. | |
CommandHelper:: |
public | function | Enables one or more disabled search indexes. | |
CommandHelper:: |
public | function | Enables a server. | |
CommandHelper:: |
public | function | Returns the total number of search indexes. | |
CommandHelper:: |
public | function | Indexes items on one or more indexes. | |
CommandHelper:: |
public | function | Lists all search indexes. | |
CommandHelper:: |
public | function | Lists all search indexes with their status. | |
CommandHelper:: |
public | function | Returns the indexes with the given IDs. | |
CommandHelper:: |
public | function | Returns the servers with the given IDs. | |
CommandHelper:: |
public | function | Rebuilds the tracker for an index. | |
CommandHelper:: |
public | function | Loads an override-free copy of a config entity, for saving. | |
CommandHelper:: |
public | function | Resets the tracker for an index, optionally filtering on entity types. | |
CommandHelper:: |
public | function | Returns an array of results. | |
CommandHelper:: |
public | function | Returns a list of servers created on the page. | |
CommandHelper:: |
public | function | Switches an index to another server. | |
CommandHelper:: |
public | function | Changes the state of a single index. | |
CommandHelper:: |
public | function | Translates a string using the set translation method. | |
CommandHelper:: |
public | function | Constructs a CommandHelper object. | |
SolrCommandHelper:: |
public | function | Finalizes one ore more indexes. | |
SolrCommandHelper:: |
public | function | Gets the config for a Solr search server. | |
SolrCommandHelper:: |
public | function | Re-install all Solr Field Types from their yml files. |