Unverified Commit c1c56549 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid
Browse files

Issue #2991052 by chilic, Dave Reid: Fixed Invalid parameter number errors...

Issue #2991052 by chilic, Dave Reid: Fixed Invalid parameter number errors when XmlSitemapLinkStorage may not use IN when array conditions. Injects database connection into XmlSitemapLinkStorage.
parent 55c8929a
......@@ -2,6 +2,7 @@
namespace Drupal\xmlsitemap;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\Merge;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Language\LanguageInterface;
......@@ -37,6 +38,13 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
*/
protected $anonymousUser;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a XmlSitemapLinkStorage object.
*
......@@ -44,11 +52,14 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
* The state handler.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler) {
public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, Connection $connection) {
$this->state = $state;
$this->moduleHandler = $module_handler;
$this->anonymousUser = new AnonymousUserSession();
$this->connection = $connection;
}
/**
......@@ -135,8 +146,8 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
$this->checkChangedLink($link, NULL, TRUE);
}
$queryStatus = \Drupal::database()->merge('xmlsitemap')
->key([
$queryStatus = $this->connection->merge('xmlsitemap')
->keys([
'type' => $link['type'],
'id' => $link['id'],
'language' => $link['language'],
......@@ -176,7 +187,7 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
if ($original_link === NULL) {
// Load only the fields necessary for data to be changed in the sitemap.
$original_link = db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id", 0, 1, [':type' => $link['type'], ':id' => $link['id']])->fetchAssoc();
$original_link = $this->connection->queryRange("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id", 0, 1, [':type' => $link['type'], ':id' => $link['id']])->fetchAssoc();
}
if (!$original_link) {
......@@ -211,10 +222,11 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
$conditions['status'] = (!empty($updates['status']) && empty($conditions['status'])) ? 0 : 1;
$conditions['access'] = (!empty($updates['access']) && empty($conditions['access'])) ? 0 : 1;
$query = db_select('xmlsitemap');
$query = $this->connection->select('xmlsitemap');
$query->addExpression('1');
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
$operator = is_array($value) ? 'IN' : '=';
$query->condition($field, $value, $operator);
}
$query->range(0, 1);
$changed = $query->execute()->fetchField();
......@@ -246,7 +258,7 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
}
// @todo Add a hook_xmlsitemap_link_delete() hook invoked here.
$query = db_delete('xmlsitemap');
$query = $this->connection->delete('xmlsitemap');
foreach ($conditions as $field => $value) {
$operator = is_array($value) ? 'IN' : '=';
$query->condition($field, $value, $operator);
......@@ -266,10 +278,11 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
}
// Process updates.
$query = db_update('xmlsitemap');
$query = $this->connection->update('xmlsitemap');
$query->fields($updates);
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
$operator = is_array($value) ? 'IN' : '=';
$query->condition($field, $value, $operator);
}
return $query->execute();
......@@ -287,11 +300,12 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
* {@inheritdoc}
*/
public function loadMultiple(array $conditions = []) {
$query = db_select('xmlsitemap');
$query = $this->connection->select('xmlsitemap');
$query->fields('xmlsitemap');
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
$operator = is_array($value) ? 'IN' : '=';
$query->condition($field, $value, $operator);
}
$links = $query->execute()->fetchAll(\PDO::FETCH_ASSOC);
......
......@@ -6,7 +6,7 @@ services:
- { name: xmlsitemap_generator }
xmlsitemap.link_storage:
class: Drupal\xmlsitemap\XmlSitemapLinkStorage
arguments: ['@state', '@module_handler']
arguments: ['@state', '@module_handler', '@database']
tags:
- { name: xmlsitemap.link_storage }
logger.channel.xmlsitemap:
......
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