Message delete

I wrote a script for mass deletion of messages from inbox and outbox for all users. It seems to work as messages are not displayed anymore in boxes.

But using the following code for counting the number of messages, i see the same number as before deletion.

$messages_in = elgg_get_entities_from_metadata(array(
'type' => 'object',
'subtype' => 'messages',
'metadata_name' => 'toId', //inbox
'full_view' => false,
'count' => TRUE,
'limit' => 0
));

So the question is.... the messages are really deleted from db? Or what is wrong in this code?

Thanks in adnvance

 

  • There are two entities for each message: one belongs to the sender of the message, the other to the receiver. Without any knowledge about what your script deletes exactly it's quite impossible to tell you what's going on. But if counting the message entities by elgg_get_entities_from_metadata() results in the same number of messages I would say there are at least these message entities still in the database.

  • @iionly: Thanks for your reply. I use the following code for deletting messages.

    $messages = elgg_get_entities_from_metadata(array(
    'type' => 'object',
    'subtype' => 'messages',
    'metadata_name' => toId,
    'full_view' => false,
    'limit' => 200
    ));

    if(is_array($messages) && count($messages) > 0){
    foreach ($messages as $m) {
    if (!$m->delete()) {
    echo elgg_echo('emptymailbox:settings:batchempty:messagenotdeleted');
    } else {
    echo elgg_echo('emptymailbox:settings:batchempty:messagedeleted');
    }
    }
    }

    With this code I was supposed to to delete all messages from all user's inbox. Finally it worked but the fact that I was seeing the same number of messages at inboxes and outboxes, I thought it didn't work.

    So all is good. Thanks again.