function xmlsitemap_user_update_6201 in XML sitemap 6.2
Migrate 6.x-1.x user data.
File
- xmlsitemap_user/
xmlsitemap_user.install, line 73 - Install and uninstall schema and functions for the xmlsitemap_user module.
Code
function xmlsitemap_user_update_6201(&$context) {
$ret = array();
if (!db_table_exists('xmlsitemap_user')) {
// Skip if the 6.x-1.x table doesn't exist.
return $ret;
}
elseif (db_column_exists('xmlsitemap', 'sid')) {
// Skip if the main {xmlsitemap} table hasn't been upgraded yet.
$ret['#abort'] = array(
'success' => FALSE,
'query' => 'The primary xmlsitemap table upgrade has not yet been completed. Re-run the upgrade script.',
);
return $ret;
}
if (!isset($context['progress'])) {
$context['progress'] = $context['last'] = 0;
$context['count'] = db_result(db_query("SELECT COUNT(uid) FROM {xmlsitemap_user} WHERE priority_override <> -2 AND uid > %d", $context['last']));
}
drupal_load('module', 'xmlsitemap_user');
drupal_load('module', 'xmlsitemap');
$query = db_query_range("SELECT uid, priority_override FROM {xmlsitemap_user} WHERE priority_override <> -2 AND uid > %d ORDER BY uid", $context['last'], 0, 10);
while ($record = db_fetch_object($query)) {
if ($account = user_load($record->uid)) {
$link = xmlsitemap_user_create_link($account);
if ($record->priority_override == -1) {
$link['status'] = 0;
$link['status_override'] = 1;
}
elseif ($record->priority_override != -2) {
$link['priority'] = $record->priority_override;
$link['priority_override'] = 1;
}
xmlsitemap_link_save($link);
}
$context['last'] = $record->uid;
$context['progress']++;
}
$ret['#finished'] = empty($context['count']) ? 1 : $context['progress'] / $context['count'];
return $ret;
}