function xmlsitemap_sitemap_save in XML sitemap 6.2
Same name and namespace in other branches
- 8 xmlsitemap.module \xmlsitemap_sitemap_save()
- 7.2 xmlsitemap.module \xmlsitemap_sitemap_save()
- 2.x xmlsitemap.module \xmlsitemap_sitemap_save()
Save changes to an XML sitemap or add a new XML sitemap.
@todo Save the sitemap's URL as a column?
Parameters
$sitemap: The XML sitemap array to be saved. If $sitemap->smid is omitted, a new XML sitemap will be added.
Related topics
5 calls to xmlsitemap_sitemap_save()
- XMLSitemapI18nWebTestCase::setUp in xmlsitemap_i18n/
xmlsitemap_i18n.test - Set up an administrative user account and testing keys.
- xmlsitemap_regenerate_batch_generate in ./
xmlsitemap.generate.inc - Batch callback; generate all pages of a sitemap.
- xmlsitemap_sitemap_edit_form_submit in ./
xmlsitemap.admin.inc - xmlsitemap_update_6202 in ./
xmlsitemap.install - Create the {xmlsitemap_sitemap} table and add the sitemap context data.
- _xmlsitemap_sitemap_rehash_all in ./
xmlsitemap.install
File
- ./
xmlsitemap.module, line 388 - Main file for the xmlsitemap module.
Code
function xmlsitemap_sitemap_save(stdClass &$sitemap) {
xmlsitemap_load_all_includes();
if (!isset($sitemap->context)) {
$sitemap->context = array();
}
// Make sure context is sorted before saving the hash.
$sitemap->is_new = empty($sitemap->smid);
$sitemap->old_smid = $sitemap->is_new ? NULL : $sitemap->smid;
$sitemap->smid = xmlsitemap_sitemap_get_context_hash($sitemap->context);
// If the context was changed, we need to perform additional actions.
if (!$sitemap->is_new && $sitemap->smid != $sitemap->old_smid) {
// Rename the files directory so the sitemap does not break.
$old_sitemap = (object) array(
'smid' => $sitemap->old_smid,
);
$old_dir = xmlsitemap_get_directory($old_sitemap);
$new_dir = xmlsitemap_get_directory($sitemap);
xmlsitemap_directory_move($old_dir, $new_dir);
// Change the smid field so drupal_write_record() does not fail.
db_query("UPDATE {xmlsitemap_sitemap} SET smid = '%s' WHERE smid = '%s'", $sitemap->smid, $sitemap->old_smid);
// Mark the sitemaps as needing regeneration.
variable_set('xmlsitemap_regenerate_needed', TRUE);
}
if ($sitemap->is_new) {
drupal_write_record('xmlsitemap_sitemap', $sitemap);
module_invoke_all('xmlsitemap_sitemap_insert', $sitemap);
}
else {
drupal_write_record('xmlsitemap_sitemap', $sitemap, array(
'smid',
));
module_invoke_all('xmlsitemap_sitemap_update', $sitemap);
}
return $sitemap;
}