function redirect_generate_batch_delete in Redirect 8
Same name and namespace in other branches
- 7.2 redirect.generate.inc \redirect_generate_batch_delete()
- 7 redirect.generate.inc \redirect_generate_batch_delete()
1 string reference to 'redirect_generate_batch_delete'
File
- ./
redirect.generate.inc, line 59 - Generate callbacks for the redirect module.
Code
function redirect_generate_batch_delete(array &$context) {
if (empty($context['sandbox'])) {
$context['sandbox'] = [];
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_rid'] = 0;
$context['sandbox']['max'] = Database::getConnection()
->query('SELECT COUNT(DISTINCT rid) FROM {redirect}')
->fetchField();
}
$limit = 20;
$rids = Database::getConnection()
->queryRange("SELECT rid FROM {redirect} WHERE rid > :rid ORDER BY rid", 0, $limit, [
':rid' => $context['sandbox']['current_rid'],
])
->fetchCol();
foreach (redirect_repository()
->loadMultiple($rids) as $redirect) {
$redirect
->delete();
}
// Update our progress information.
$context['sandbox']['progress'] += count($rids);
$context['sandbox']['current_rid'] = end($rids);
$context['message'] = t('Deleted URL redirect @rid.', [
'@rid' => end($rids),
]);
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] >= $context['sandbox']['max'];
}
}