public function XmlSitemapLinkStorage::checkChangedLink in XML sitemap 2.x
Same name and namespace in other branches
- 8 src/XmlSitemapLinkStorage.php \Drupal\xmlsitemap\XmlSitemapLinkStorage::checkChangedLink()
Check if there is sitemap link is changed from the existing data.
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.
Overrides XmlSitemapLinkStorageInterface::checkChangedLink
1 call to XmlSitemapLinkStorage::checkChangedLink()
- XmlSitemapLinkStorage::save in src/
XmlSitemapLinkStorage.php - Saves or updates a sitemap link.
File
- src/
XmlSitemapLinkStorage.php, line 212
Class
- XmlSitemapLinkStorage
- XmlSitemap link storage service class.
Namespace
Drupal\xmlsitemapCode
public function checkChangedLink(array $link, array $original_link = NULL, $flag = FALSE) {
$changed = FALSE;
if ($original_link === NULL) {
// Load only the fields necessary for data to be changed in the sitemap.
$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) {
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) {
$this->state
->set('xmlsitemap_regenerate_needed', TRUE);
}
return $changed;
}