Commit 6bcafcdf authored by thalles's avatar thalles Committed by pifagor

Issue #3064349 by thalles, ilchovuchkov, pifagor: Replace deprecated functions db_query

parent aafa3256
......@@ -76,14 +76,15 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
public function testGetChunkCount() {
// Set a low chunk size for testing.
$this->config->set('chunk_size', 4)->save();
$database = \Drupal::database();
// Make the total number of links just equal to the chunk size.
$count = db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField();
$count = $database->query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField();
for ($i = $count; $i < 4; $i++) {
$this->addSitemapLink();
$this->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
}
$this->assertEqual(db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField(), 4);
$this->assertEqual($database->query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField(), 4);
// Add a disabled link, should not change the chunk count.
$this->addSitemapLink(['status' => FALSE]);
......@@ -94,13 +95,13 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$this->assertEqual(xmlsitemap_get_chunk_count(TRUE), 2);
// Change all links to disabled. The chunk count should be 1 not 0.
db_query("UPDATE {xmlsitemap} SET status = 0");
$database->query("UPDATE {xmlsitemap} SET status = 0");
$this->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
$this->assertEqual(xmlsitemap_get_link_count(), 0);
// Delete all links. The chunk count should be 1 not 0.
db_query("DELETE FROM {xmlsitemap}");
$this->assertEqual(db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField(), 0);
$database->query("DELETE FROM {xmlsitemap}");
$this->assertEqual($database->query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField(), 0);
$this->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
}
......
......@@ -289,7 +289,7 @@ function hook_xmlsitemap_sitemap_operations() {
* The XML sitemap object that was deleted.
*/
function hook_xmlsitemap_sitemap_delete(\Drupal\xmlsitemap\XmlSitemapInterface $sitemap) {
db_query("DELETE FROM {mytable} WHERE smid = '%s'", $sitemap->smid);
\Drupal::database()->query("DELETE FROM {mytable} WHERE smid = '%s'", $sitemap->smid);
}
/**
......
......@@ -727,10 +727,11 @@ function xmlsitemap_get_link_type_enabled_bundles($entity_type) {
*/
function xmlsitemap_get_link_type_indexed_status($entity_type_id, $bundle = '') {
$info = xmlsitemap_get_link_info($entity_type_id);
$database = \Drupal::database();
$entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
$status['indexed'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle", [':entity' => $entity_type_id, ':bundle' => $bundle])->fetchField();
$status['visible'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle AND status = 1 AND access = 1", [':entity' => $entity_type_id, ':bundle' => $bundle])->fetchField();
$status['indexed'] = $database->query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle", [':entity' => $entity_type_id, ':bundle' => $bundle])->fetchField();
$status['visible'] = $database->query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle AND status = 1 AND access = 1", [':entity' => $entity_type_id, ':bundle' => $bundle])->fetchField();
try {
$query = \Drupal::entityQuery($entity_type_id);
......@@ -1034,7 +1035,7 @@ function xmlsitemap_get_chunk_count($reset = FALSE) {
function xmlsitemap_get_link_count($reset = FALSE) {
static $count;
if (!isset($count) || $reset) {
$count = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE access = 1 AND status = 1")->fetchField();
$count = \Drupal::database()->query("SELECT COUNT(id) FROM {xmlsitemap} WHERE access = 1 AND status = 1")->fetchField();
}
return $count;
}
......
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