Skip to content
Snippets Groups Projects

Issue #3364912: Errors with NodeOrderManager::selectNodes() function

Files
6
+ 12
15
@@ -5,7 +5,6 @@ namespace Drupal\nodeorder;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\Entity\Vocabulary;
@@ -29,11 +28,11 @@ class NodeOrderManager implements NodeOrderManagerInterface {
protected $database;
/**
* Taxonomy term storage.
* Term tree loader.
*
* @var \Drupal\taxonomy\TermStorageInterface
* @var \Drupal\nodeorder\TermTreeLoaderInterface
*/
protected $termStorage;
protected $treeLoader;
/**
* Default cache bin.
@@ -49,17 +48,17 @@ class NodeOrderManager implements NodeOrderManagerInterface {
* The nodeorder config manager.
* @param \Drupal\Core\Database\Connection $database
* The current database connection.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
* @param \Drupal\nodeorder\TermTreeLoaderInterface $treeLoader
* Term tree loader.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* Default cache bin.
*
* @throws \Throwable
*/
public function __construct(ConfigManagerInterface $config_manager, Connection $database, EntityTypeManagerInterface $entity_type_manager, CacheBackendInterface $cache) {
public function __construct(ConfigManagerInterface $config_manager, Connection $database, TermTreeLoaderInterface $treeLoader, CacheBackendInterface $cache) {
$this->database = $database;
$this->configManager = $config_manager;
$this->termStorage = $entity_type_manager->getStorage('taxonomy_term');
$this->treeLoader = $treeLoader;
$this->cache = $cache;
}
@@ -176,16 +175,13 @@ class NodeOrderManager implements NodeOrderManagerInterface {
$depth = NULL;
}
foreach ($tids as $index => $tid) {
$term = $this->termStorage->load($tid);
$tree = $this->termStorage->loadTree($term->bundle(), $tid, $depth);
$descendant_tids[] = array_merge([$tid], array_map(function ($value) {
return $value->id();
}, $tree));
$tree = $this->treeLoader->descendantTidsByTermId($tid, $depth);
$descendant_tids[] = array_merge([$tid], $tree);
}
if ($operator == 'or') {
$args = call_user_func_array('array_merge', $descendant_tids);
$placeholders = db_placeholders($args, 'int');
$placeholders = $this->database->placeholders($args, 'int');
$sql = 'SELECT DISTINCT(n.nid), nd.sticky, nd.title, nd.created, tn.weight FROM {node} n LEFT JOIN {node_field_data} nd INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid IN (' . $placeholders . ') AND n.status = 1 ORDER BY ' . $order;
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid IN (' . $placeholders . ') AND n.status = 1';
}
@@ -210,7 +206,8 @@ class NodeOrderManager implements NodeOrderManagerInterface {
if ($count == -1) {
$count = $config->get('default_nodes_main');
}
$result = pager_query($sql, $count, 0, $sql_count, $args);
$query = $this->database->query($sql, $args);
$result = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit($count);
}
else {
if ($count == -1) {
Loading