diff --git a/search_api_db/src/DatabaseCompatibility/MySql.php b/search_api_db/src/DatabaseCompatibility/MySql.php index 134e4f3..da5f1e9 100644 --- a/search_api_db/src/DatabaseCompatibility/MySql.php +++ b/search_api_db/src/DatabaseCompatibility/MySql.php @@ -2,7 +2,6 @@ namespace Drupal\search_api_db\DatabaseCompatibility; -use Drupal\Component\Render\FormattableMarkup; use Drupal\search_api\SearchApiException; /** @@ -24,7 +23,7 @@ class MySql extends GenericDatabase { $this->database->query("ALTER TABLE {{$table}} CONVERT TO CHARACTER SET 'utf8' COLLATE '$collation'"); } catch (\PDOException $e) { - throw new SearchApiException(get_class($e) . " while trying to change collation of {$type} search data table {$table} ':' {$e->getMessage()}", 0, $e); + throw new SearchApiException(get_class($e) . " while trying to change collation of $type search data table $table: " . $e->getMessage(), 0, $e); } } diff --git a/search_api_db/src/Plugin/search_api/backend/Database.php b/search_api_db/src/Plugin/search_api/backend/Database.php index 0e55d1e..6fbc0b1 100644 --- a/search_api_db/src/Plugin/search_api/backend/Database.php +++ b/search_api_db/src/Plugin/search_api/backend/Database.php @@ -2,7 +2,6 @@ namespace Drupal\search_api_db\Plugin\search_api\backend; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\ConfigFactoryInterface; @@ -806,7 +805,7 @@ class Database extends BackendPluginBase { return array('type' => 'int', 'size' => 'tiny'); default: - throw new SearchApiException("Unknown field type {$type}. Database search module might be out of sync with Search API."); + throw new SearchApiException("Unknown field type $type. Database search module might be out of sync with Search API."); } } @@ -1062,7 +1061,8 @@ class Database extends BackendPluginBase { */ public function indexItems(IndexInterface $index, array $items) { if (!$this->getIndexDbInfo($index)) { - throw new SearchApiException("No field settings for index with id {$index->id()}."); + $index_id = $index->id(); + throw new SearchApiException("No field settings for index with id $index_id."); } $indexed = array(); foreach ($items as $id => $item) { @@ -1405,7 +1405,7 @@ class Database extends BackendPluginBase { return strtotime($value); default: - throw new SearchApiException("Unknown field type {$type}. Database search module might be out of sync with Search API."); + throw new SearchApiException("Unknown field type $type. Database search module might be out of sync with Search API."); } } @@ -1467,7 +1467,8 @@ class Database extends BackendPluginBase { $db_info = $this->getIndexDbInfo($index); if (!isset($db_info['field_tables'])) { - throw new SearchApiException("Unknown index {$index->id()}."); + $index_id = $index->id(); + throw new SearchApiException("Unknown index $index_id."); } $fields = $this->getFieldInfo($index); @@ -1511,7 +1512,7 @@ class Database extends BackendPluginBase { } if (!isset($fields[$field_name])) { - throw new SearchApiException("Trying to sort on unknown field {$field_name}."); + throw new SearchApiException("Trying to sort on unknown field $field_name."); } $alias = $this->getTableAlias(array('table' => $db_info['index_table']), $db_query); $db_query->orderBy($alias . '.' . $fields[$field_name]['column'], $order); @@ -1588,12 +1589,12 @@ class Database extends BackendPluginBase { $fulltext_field_information = array(); foreach ($fulltext_fields as $name) { if (!isset($fields[$name])) { - throw new SearchApiException("Unknown field {$name} specified as search target."); + throw new SearchApiException("Unknown field $name specified as search target."); } if (!Utility::isTextType($fields[$name]['type'])) { $types = $this->getDataTypePluginManager()->getInstances(); $type = $types[$fields[$name]['type']]->label(); - throw new SearchApiException("Cannot perform fulltext search on field {$name} of type {$type}."); + throw new SearchApiException("Cannot perform fulltext search on field $name of type $type."); } $fulltext_field_information[$name] = $fields[$name]; } @@ -2040,7 +2041,7 @@ class Database extends BackendPluginBase { $not_between = $operator == 'NOT BETWEEN'; if (!isset($fields[$field])) { - throw new SearchApiException("Unknown field in filter clause: {$field}."); + throw new SearchApiException("Unknown field in filter clause: $field."); } $field_info = $fields[$field]; // For NULL values, we can just use the single-values table, since we @@ -2330,7 +2331,8 @@ class Database extends BackendPluginBase { $index = $query->getIndex(); $db_info = $this->getIndexDbInfo($index); if (empty($db_info['field_tables'])) { - throw new SearchApiException("Unknown index {$index->id()}."); + $index_id = $index->id(); + throw new SearchApiException("Unknown index $index_id."); } $fields = $this->getFieldInfo($index); diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 6cb2860..d2fdfef 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -2,7 +2,6 @@ namespace Drupal\search_api\Entity; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; @@ -377,7 +376,8 @@ class Index extends ConfigEntityBase implements IndexInterface { $datasources = $this->getDatasources(); if (empty($datasources[$datasource_id])) { - throw new SearchApiException("The datasource with ID '{$datasource_id}' could not be retrieved for index {$this->label()}."); + $index_label = $this->label(); + throw new SearchApiException("The datasource with ID '$datasource_id' could not be retrieved for index $index_label."); } return $datasources[$datasource_id]; @@ -458,7 +458,8 @@ class Index extends ConfigEntityBase implements IndexInterface { } if (!($this->trackerInstance = \Drupal::service('plugin.manager.search_api.tracker')->createInstance($tracker_id, $configuration))) { - throw new SearchApiException("The tracker with ID '{$tracker_id}' could not be retrieved for index {$this->label()}."); + $index_label = $this->label(); + throw new SearchApiException("The tracker with ID '$tracker_id' could not be retrieved for index $index_label."); } } @@ -501,7 +502,8 @@ class Index extends ConfigEntityBase implements IndexInterface { if (!$this->serverInstance && $this->server) { $this->serverInstance = Server::load($this->server); if (!$this->serverInstance) { - throw new SearchApiException("The server with ID '{$this->server}' could not be retrieved for index {$this->label()}."); + $index_label = $this->label(); + throw new SearchApiException("The server with ID '$this->server' could not be retrieved for index $index_label."); } } @@ -672,12 +674,12 @@ class Index extends ConfigEntityBase implements IndexInterface { public function addField(FieldInterface $field) { $field_id = $field->getFieldIdentifier(); if (Utility::isFieldIdReserved($field_id)) { - throw new SearchApiException("{$field_id} is a reserved value and cannot be used as the machine name of a normal field."); + throw new SearchApiException("$field_id is a reserved value and cannot be used as the machine name of a normal field."); } $old_field = $this->getField($field_id); if ($old_field && $old_field != $field) { - throw new SearchApiException("Cannot add field with machine name {$field_id}: machine name is already taken."); + throw new SearchApiException("Cannot add field with machine name $field_id: machine name is already taken."); } $this->fieldInstances[$field_id] = $field; @@ -690,13 +692,13 @@ class Index extends ConfigEntityBase implements IndexInterface { */ public function renameField($old_field_id, $new_field_id) { if (!isset($this->getFields()[$old_field_id])) { - throw new SearchApiException("Could not rename field with machine name {$old_field_id}: no such field."); + throw new SearchApiException("Could not rename field with machine name $old_field_id: no such field."); } if (Utility::isFieldIdReserved($new_field_id)) { - throw new SearchApiException("{$new_field_id} is a reserved value and cannot be used as the machine name of a normal field."); + throw new SearchApiException("$new_field_id is a reserved value and cannot be used as the machine name of a normal field."); } if (isset($this->getFields()[$new_field_id])) { - throw new SearchApiException("{$new_field_id} already exists and can't be used as a new field id."); + throw new SearchApiException("$new_field_id already exists and can't be used as a new field id."); } $this->fieldInstances[$new_field_id] = $this->fieldInstances[$old_field_id]; @@ -714,7 +716,7 @@ class Index extends ConfigEntityBase implements IndexInterface { return $this; } if ($field->isIndexedLocked()) { - throw new SearchApiException("Cannot remove field with machine name {$field_id}: field is locked."); + throw new SearchApiException("Cannot remove field with machine name $field_id: field is locked."); } unset($this->fieldInstances[$field_id]); @@ -863,7 +865,8 @@ class Index extends ConfigEntityBase implements IndexInterface { return array(); } if (!$this->status) { - throw new SearchApiException("Couldn't index values on index {$this->label()}' (index is disabled)"); + $index_label = $this->label(); + throw new SearchApiException("Couldn't index values on index '$index_label' (index is disabled)"); } /** @var \Drupal\search_api\Item\ItemInterface[] $items */ diff --git a/src/Entity/Server.php b/src/Entity/Server.php index 84bdc21..62a7406 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -2,7 +2,6 @@ namespace Drupal\search_api\Entity; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\search_api\IndexInterface; @@ -132,7 +131,7 @@ class Server extends ConfigEntityBase implements ServerInterface { $config = $this->backend_config; $config['server'] = $this; if (!($this->backendPlugin = $backend_plugin_manager->createInstance($this->getBackendId(), $config))) { - throw new SearchApiException("The backend with ID '{$this->getBackendId()}' could not be retrieved for server '{$this->label()}."); + throw new SearchApiException("The backend with ID '" .$this->getBackendId() . "' could not be retrieved for server '" . $this->label() . "."); } } return $this->backendPlugin; @@ -277,7 +276,8 @@ class Server extends ConfigEntityBase implements ServerInterface { if ($server_task_manager->execute($this)) { return $this->getBackend()->indexItems($index, $items); } - throw new SearchApiException("Could not index items on index '{$index->label()}' because pending server tasks could not be executed."); + $index_label = $index->label(); + throw new SearchApiException("Could not index items on index '$index_label' because pending server tasks could not be executed."); } /** @@ -366,12 +366,9 @@ class Server extends ConfigEntityBase implements ServerInterface { } } if (!empty($e)) { - $args = array( - '%server' => $this->label(), - '@indexes' => implode(', ', $failed), - ); - $message = new FormattableMarkup('Deleting all items from server %server failed for the following (write-enabled) indexes: @indexes.', $args); - throw new SearchApiException($message, 0, $e); + $server_name = $this->label(); + $server_failed = implode(', ', $failed); + throw new SearchApiException("Deleting all items from server $server_name failed for the following (write-enabled) indexes: $server_failed.", 0, $e); } $types = array( diff --git a/src/IndexBatchHelper.php b/src/IndexBatchHelper.php index c70b620..d814aef 100644 --- a/src/IndexBatchHelper.php +++ b/src/IndexBatchHelper.php @@ -2,7 +2,6 @@ namespace Drupal\search_api; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\StringTranslation\TranslationInterface; /** @@ -93,7 +92,8 @@ class IndexBatchHelper { batch_set($batch_definition); } else { - throw new SearchApiException("Failed to create a batch with batch size {$batch_size} and limit {$limit} for index {$index->label()}."); + $index_label = $index->label(); + throw new SearchApiException("Failed to create a batch with batch size $batch_size and limit $limit for index $index_label."); } } diff --git a/src/Item/Field.php b/src/Item/Field.php index 3575f89..745ca3e 100644 --- a/src/Item/Field.php +++ b/src/Item/Field.php @@ -2,7 +2,6 @@ namespace Drupal\search_api\Item; -use Drupal\Component\Render\FormattableMarkup; use Drupal\search_api\Entity\Index; use Drupal\search_api\IndexInterface; use Drupal\search_api\SearchApiException; @@ -348,7 +347,9 @@ class Field implements \IteratorAggregate, FieldInterface { $definitions = $this->index->getPropertyDefinitions($this->getDatasourceId()); $definition = Utility::retrieveNestedProperty($definitions, $this->getPropertyPath()); if (!$definition) { - throw new SearchApiException("Could not retrieve data definition for field {$this->getLabel()} on index {$this->getIndex()->label()}."); + $field_label = $this->getLabel(); + $index_label = $this->getIndex()->label(); + throw new SearchApiException("Could not retrieve data definition for field $field_label on index $index_label."); } $this->dataDefinition = $definition; } @@ -367,7 +368,9 @@ class Field implements \IteratorAggregate, FieldInterface { */ public function setType($type) { if ($type != $this->type && $this->isTypeLocked()) { - throw new SearchApiException("Trying to change the type of field {$this->getLabel()} on index {$this->getIndex()->label()}, which is locked."); + $field_label = $this->getLabel(); + $index_label = $this->getIndex()->label(); + throw new SearchApiException("Trying to change the type of field $field_label on index $index_label, which is locked."); } $this->type = $type; return $this; diff --git a/src/Plugin/views/row/SearchApiRow.php b/src/Plugin/views/row/SearchApiRow.php index fc6227c..9789fa8 100644 --- a/src/Plugin/views/row/SearchApiRow.php +++ b/src/Plugin/views/row/SearchApiRow.php @@ -2,7 +2,6 @@ namespace Drupal\search_api\Plugin\views\row; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Logger\LoggerChannelInterface; @@ -121,7 +120,8 @@ class SearchApiRow extends RowPluginBase { $base_table = $view->storage->get('base_table'); $this->index = SearchApiQuery::getIndexFromTable($base_table, $this->getEntityTypeManager()); if (!$this->index) { - throw new \InvalidArgumentException(new FormattableMarkup('View %view is not based on Search API but tries to use its row plugin.', array('%view' => $view->storage->label()))); + $view_label = $view->storage->label(); + throw new \InvalidArgumentException("View $view_label is not based on Search API but tries to use its row plugin."); } } diff --git a/src/Processor/ProcessorPluginBase.php b/src/Processor/ProcessorPluginBase.php index c1abcdb..5ebb9e9 100644 --- a/src/Processor/ProcessorPluginBase.php +++ b/src/Processor/ProcessorPluginBase.php @@ -2,7 +2,6 @@ namespace Drupal\search_api\Processor; -use Drupal\Component\Render\FormattableMarkup; use Drupal\search_api\Datasource\DatasourceInterface; use Drupal\search_api\IndexInterface; use Drupal\search_api\Plugin\IndexPluginBase; @@ -118,10 +117,9 @@ abstract class ProcessorPluginBase extends IndexPluginBase implements ProcessorI if (!$field) { $property = Utility::retrieveNestedProperty($this->index->getPropertyDefinitions($datasource_id), $property_path); if (!$property) { - $args['%property'] = Utility::createCombinedId($datasource_id, $property_path); - $args['%processor'] = $this->label(); - $message = new FormattableMarkup('Could not find property %property which is required by the %processor processor.', $args); - throw new SearchApiException($message); + $property_id = Utility::createCombinedId($datasource_id, $property_path); + $processor_label = $this->label(); + throw new SearchApiException("Could not find property $property_id which is required by the $processor_label processor."); } $field = Utility::createFieldFromProperty($this->index, $property, $datasource_id, $property_path, NULL, $type); } diff --git a/src/Query/Query.php b/src/Query/Query.php index d0b3e36..dfcc9b0 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -2,7 +2,6 @@ namespace Drupal\search_api\Query; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\search_api\IndexInterface; use Drupal\search_api\SearchApiException; @@ -137,7 +136,8 @@ class Query implements QueryInterface { */ public function __construct(IndexInterface $index, ResultsCacheInterface $results_cache, array $options = array()) { if (!$index->status()) { - throw new SearchApiException("Can't search on index {$index->label()} which is disabled."); + $index_label = $index->label(); + throw new SearchApiException("Can't search on index $index_label which is disabled."); } $this->index = $index; $this->resultsCache = $results_cache; diff --git a/src/Utility.php b/src/Utility.php index 70b52df..5b63976 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -2,7 +2,6 @@ namespace Drupal\search_api; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface; @@ -643,11 +642,8 @@ class Utility { $type = $type_mapping[$property_type]; } else { - $args['%property'] = $property->getLabel(); - $args['%property_path'] = $property_path; - $args['%type'] = $property_type; - $message = new FormattableMarkup('No default data type mapping could be found for property %property (%property_path) of type %type.', $args); - throw new SearchApiException($message); + $property_name = $property->getLabel(); + throw new SearchApiException("No default data type mapping could be found for property $property_name ($property_path) of type $property_type."); } } diff --git a/tests/src/Kernel/ServerTaskTest.php b/tests/src/Kernel/ServerTaskTest.php index 7dd94eb..9228041 100644 --- a/tests/src/Kernel/ServerTaskTest.php +++ b/tests/src/Kernel/ServerTaskTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\search_api\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\search_api\Entity\Index; use Drupal\search_api\Entity\Server;