You are here

function _xmlsitemap_check_changed_link in XML sitemap 7.2

Same name and namespace in other branches
  1. 6.2 xmlsitemap.module \_xmlsitemap_check_changed_link()

Check if there is sitemap link is changed from the existing data.

@codingStandardsIgnoreStart

Parameters

array $link: An array of the sitemap link.

array $original_link: An optional array of the existing data. This should only contain the fields necessary for comparison. If not provided the existing data will be loaded from the database.

bool $flag: An optional boolean that if TRUE, will set the regenerate needed flag if there is a match. Defaults to FALSE.

Return value

bool TRUE if the link is changed, or FALSE otherwise.

Related topics

1 call to _xmlsitemap_check_changed_link()
xmlsitemap_link_save in ./xmlsitemap.module
Saves or updates a sitemap link.

File

./xmlsitemap.module, line 834
xmlsitemap XML sitemap

Code

function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $flag = FALSE) {

  // @codingStandardsIgnoreEnd
  $changed = FALSE;
  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, array(
      ':type' => $link['type'],
      ':id' => $link['id'],
    ))
      ->fetchAssoc();
  }
  if (!$original_link) {
    if ($link['access'] && $link['status']) {

      // Adding a new visible link.
      $changed = TRUE;
    }
  }
  else {
    if (!($original_link['access'] && $original_link['status']) && $link['access'] && $link['status']) {

      // Changing a non-visible link to a visible link.
      $changed = TRUE;
    }
    elseif ($original_link['access'] && $original_link['status'] && array_diff_assoc($original_link, $link)) {

      // Changing a visible link.
      $changed = TRUE;
    }
  }
  if ($changed && $flag) {
    variable_set('xmlsitemap_regenerate_needed', TRUE);
  }
  return $changed;
}