Commit 75561ce5 authored by jzavrl's avatar jzavrl Committed by borisson_

Issue #2880344 by jzavrl, Munavijayalakshmi, arunkumark, borisson_: Removed...

Issue #2880344 by jzavrl, Munavijayalakshmi, arunkumark, borisson_: Removed deprecated Database queries
parent 29b27d5d
......@@ -2,6 +2,7 @@
namespace Drupal\core_search_facets;
use Drupal\Core\Database\Query\Condition;
use Drupal\search\SearchQuery;
/**
......@@ -41,7 +42,7 @@ class FacetsQuery extends SearchQuery {
* An associative array of query information.
*
* @return FacetsQuery
* An instance of this class.
* An instance of this class.
*/
public function addFacetField(array $query_info) {
foreach ($query_info['fields'] as $field_info) {
......@@ -58,7 +59,7 @@ class FacetsQuery extends SearchQuery {
// Adds OR conditions.
if (!empty($this->words)) {
$or = db_or();
$or = new Condition('OR');
foreach ($this->words as $word) {
$or->condition('i.word', $word);
}
......@@ -91,7 +92,7 @@ class FacetsQuery extends SearchQuery {
->addMetaData('normalize', $this->normalize);
// Adds subquery to group the results in the r table.
$subquery = db_select($this->query, 'r')
$subquery = \Drupal::database()->select($this->query, 'r')
->fields('r', array('value'))
->groupBy('r.value');
......
......@@ -2,6 +2,8 @@
namespace Drupal\core_search_facets\Plugin\facets\facet_source;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface;
use Drupal\facets\FacetInterface;
......@@ -66,6 +68,20 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
*/
protected $request;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The current primary database.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
......@@ -81,26 +97,33 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* The plugin manager for core search plugins.
* @param \Symfony\Component\HttpFoundation\Request $request
* The master request.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Database\Connection $database
* The current primary database.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryTypePluginManager $query_type_plugin_manager, SearchPluginManager $search_manager, Request $request) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryTypePluginManager $query_type_plugin_manager, SearchPluginManager $search_manager, Request $request, ModuleHandlerInterface $module_handler, Connection $database) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $query_type_plugin_manager);
$this->searchManager = $search_manager;
$this->request = clone $request;
$this->setSearchKeys($this->request->query->get('keys'));
$this->moduleHandler = $module_handler;
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.facets.query_type'),
$container->get('plugin.manager.search'),
$container->get('request_stack')->getMasterRequest()
$container->get('request_stack')->getMasterRequest(),
$container->get('module_handler'),
$container->get('database')
);
}
......@@ -182,8 +205,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* {@inheritdoc}
*/
public function isRenderedInCurrentRequest() {
$request = \Drupal::requestStack()->getMasterRequest();
$search_page = $request->attributes->get('entity');
$search_page = $this->request->attributes->get('entity');
if ($search_page instanceof SearchPageInterface) {
$facet_source_id = 'core_node_search:' . $search_page->id();
if ($facet_source_id == $this->getPluginId()) {
......@@ -198,7 +220,6 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['field_identifier'] = [
'#type' => 'select',
'#options' => $this->getFields(),
......@@ -219,7 +240,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
$facet_fields = $this->getDefaultFields();
// Get the allowed field types.
$allowed_field_types = \Drupal::moduleHandler()->invokeAll('facets_core_allowed_field_types', array($field_types = []));
$allowed_field_types = $this->moduleHandler->invokeAll('facets_core_allowed_field_types', array($field_types = []));
// Get the current field instances and detect if the field type is allowed.
$fields = FieldConfig::loadMultiple();
......@@ -261,7 +282,9 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
*/
public function getFacetQueryExtender() {
if (!$this->facetQueryExtender) {
$this->facetQueryExtender = db_select('search_index', 'i', array('target' => 'replica'))->extend('Drupal\core_search_facets\FacetsQuery');
$this->facetQueryExtender = $this->database
->select('search_index', 'i', array('target' => 'replica'))
->extend('Drupal\core_search_facets\FacetsQuery');
$this->facetQueryExtender->join('node_field_data', 'n', 'n.nid = i.sid AND n.langcode = i.langcode');
$this->facetQueryExtender
// ->condition('n.status', 1).
......@@ -337,7 +360,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* @TODO move to the Base class???
*/
public function hasFacets() {
$manager = \Drupal::service('entity_type.manager')->getStorage('facets_facet');
$manager = $this->entityTypeManager->getStorage('facets_facet');
$facets = $manager->loadMultiple();
foreach ($facets as $facet) {
if ($facet->getFacetSourceId() == $this->getPluginId()) {
......
......@@ -2,7 +2,10 @@
namespace Drupal\facets\Plugin\facets\hierarchy;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\Condition;
use Drupal\facets\Hierarchy\HierarchyPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Taxonomy hierarchy.
......@@ -15,6 +18,42 @@ use Drupal\facets\Hierarchy\HierarchyPluginBase;
*/
class Taxonomy extends HierarchyPluginBase {
/**
* The current primary database.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Database\Connection $database
* The current primary database.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('database')
);
}
/**
* {@inheritdoc}
*/
......@@ -33,8 +72,7 @@ class Taxonomy extends HierarchyPluginBase {
public function getNestedChildIds($id) {
$children = &drupal_static(__FUNCTION__, []);
if (!isset($children[$id])) {
// TODO: refactor to swap out deprecated db_select.
$query = db_select('taxonomy_term_hierarchy', 'h');
$query = $this->database->select('taxonomy_term_hierarchy', 'h');
$query->addField('h', 'tid');
$query->condition('h.parent', $id);
$queried_children = $query->execute()->fetchCol();
......@@ -51,12 +89,10 @@ class Taxonomy extends HierarchyPluginBase {
* {@inheritdoc}
*/
public function getChildIds(array $ids) {
// TODO: refactor to swap out deprecated db_select.
// TODO: also check if this query does not too much, plain d7 c/p here.
$result = db_select('taxonomy_term_hierarchy', 'th')
$result = $this->database->select('taxonomy_term_hierarchy', 'th')
->fields('th', array('tid', 'parent'))
->condition('th.parent', '0', '>')
->condition(db_or()
->condition((new Condition('OR'))
->condition('th.tid', $ids, 'IN')
->condition('th.parent', $ids, 'IN')
)
......@@ -79,11 +115,10 @@ class Taxonomy extends HierarchyPluginBase {
* Returns FALSE if no parent is found, else parent tid.
*/
protected function taxonomyGetParent($tid) {
// TODO: refactor to swap out deprecated db_select.
$parent = &drupal_static(__FUNCTION__, []);
if (!isset($parent[$tid])) {
$query = db_select('taxonomy_term_hierarchy', 'h');
$query = $this->database->select('taxonomy_term_hierarchy', 'h');
$query->addField('h', 'parent');
$query->condition('h.tid', $tid);
$parent[$tid] = $query->execute()->fetchField();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment