You are here

public function SimpleSitemapStorage::publish in Simple XML sitemap 4.x

File

src/Entity/SimpleSitemapStorage.php, line 166

Class

SimpleSitemapStorage

Namespace

Drupal\simple_sitemap\Entity

Code

public function publish(SimpleSitemap $entity) : void {
  $unpublished_chunk = $this->database
    ->query('SELECT MAX(id) FROM {simple_sitemap} WHERE type = :type AND status = :status', [
    ':type' => $entity
      ->id(),
    ':status' => self::SITEMAP_UNPUBLISHED,
  ])
    ->fetchField();

  // Only allow publishing a sitemap variant if there is an unpublished
  // sitemap variant, as publishing involves deleting the currently published
  // variant.
  if (FALSE !== $unpublished_chunk) {
    $this->database
      ->delete('simple_sitemap')
      ->condition('type', $entity
      ->id())
      ->condition('status', self::SITEMAP_PUBLISHED)
      ->execute();
    $this->database
      ->query('UPDATE {simple_sitemap} SET status = :status WHERE type = :type', [
      ':type' => $entity
        ->id(),
      ':status' => self::SITEMAP_PUBLISHED,
    ]);
  }
}