Unverified Commit 126cf96e authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #2416983 by Dave Reid: Added hook_xmlsitemap_rebuild_clear()

parent e614903a
......@@ -395,6 +395,9 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
*/
public function rebuildBatchClear(array $entity_type_ids, $save_custom, &$context) {
if (!empty($entity_type_ids)) {
// Let other modules respond to the rebuild clearing.
$this->moduleHandler->invokeAll('xmlsitemap_rebuild_clear', [$entity_type_ids, $save_custom]);
$query = db_delete('xmlsitemap');
$query->condition('type', $entity_type_ids, 'IN');
......
......@@ -82,7 +82,7 @@ function hook_xmlsitemap_link_alter(&$link) {
* @see hook_xmlsitemap_link_update()
*/
function hook_xmlsitemap_link_insert(array $link) {
db_insert('mytable')
\Drupal::database()->insert('mytable')
->fields([
'link_type' => $link['type'],
'link_id' => $link['id'],
......@@ -101,7 +101,7 @@ function hook_xmlsitemap_link_insert(array $link) {
* @see hook_xmlsitemap_link_insert()
*/
function hook_xmlsitemap_link_update(array $link) {
db_update('mytable')
\Drupal::database()->update('mytable')
->fields([
'link_type' => $link['type'],
'link_id' => $link['id'],
......@@ -110,6 +110,20 @@ function hook_xmlsitemap_link_update(array $link) {
->execute();
}
/**
* Respond to XML sitemap link clearing and rebuilding.
*
* @param array $entity_type_ids
* An array of entity type IDs that are being rebuilt.
* @param bool $save_custom
* If links with overridden status and/or priority are being removed or not.
*/
function hook_xmlsitemap_rebuild_clear(array $entity_type_ids, $save_custom) {
\Drupal::database()->delete('mytable')
->condition('link_type', $types, 'IN')
->execute();
}
/**
* Index links for the XML sitemaps.
*/
......
......@@ -103,6 +103,7 @@ function xmlsitemap_hook_info() {
'query_xmlsitemap_generate_alter',
'query_xmlsitemap_link_bundle_access_alter',
'form_xmlsitemap_sitemap_edit_form_alter',
'xmlsitemap_rebuild_clear',
];
$hooks = array_combine($hooks, $hooks);
......
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