Skip to content
Snippets Groups Projects

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

Merged Issue #3490816 by claudiu.cristea, socialnicheguru: Divison by Zero
Merged Claudiu Cristea requested to merge cherry-pick-a8d09180 into 4.x
1 file
+ 7
12
Compare changes
  • Side-by-side
  • Inline
@@ -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'],
]);
}
Loading