Skip to content
Snippets Groups Projects
Commit 7b8bb202 authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

Issue #3490816 by claudiu.cristea, socialnicheguru: Divison by Zero

parent 5ce841b1
No related branches found
No related tags found
1 merge request!162Issue #3490816 by claudiu.cristea, socialnicheguru: Divison by Zero
Pipeline #355279 passed
......@@ -20,8 +20,7 @@ function private_message_post_update_remove_orphaned_messages(array &$sandbox =
return t("Removing orphan private messages is only possible when the 'private_message' uses the standards SQL storage. Your project uses a different storage, you'll have to provide your own update path");
}
if (empty($sandbox['message_ids'])) {
$sandbox['current_id'] = 0;
if (!isset($sandbox['message_ids'])) {
$connection = \Drupal::database();
$query = $connection->select('private_messages', 'pm');
$query->fields('pm', ['id']);
......@@ -29,20 +28,16 @@ function private_message_post_update_remove_orphaned_messages(array &$sandbox =
$query->isNull('pmt.entity_id');
$sandbox['message_ids'] = $query->execute()->fetchCol();
$sandbox['total'] = count($sandbox['message_ids']);
$sandbox['current'] = 0;
}
$message_ids = array_slice($sandbox['message_ids'], $sandbox['current_id'], 200);
foreach ($message_ids as $message_id) {
$message = $message_storage->load($message_id);
if ($message) {
$message->delete();
}
$sandbox['current_id']++;
}
$message_ids = array_splice($sandbox['message_ids'], 0, 25);
$message_storage->delete($message_storage->loadMultiple($message_ids));
$sandbox['current'] += count($message_ids);
$sandbox['#finished'] = $sandbox['current_id'] / $sandbox['total'];
$sandbox['#finished'] = (int) empty($sandbox['message_ids']);
return t('Removed @current of @total orphaned private messages.', [
'@current' => $sandbox['current_id'],
'@current' => $sandbox['current'],
'@total' => $sandbox['total'],
]);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment