Deleting a batch of data

I want to delete more than 1000 rows from the table elgg_object_entity, and the related data at elgg_metadata and elgg_metastrings.

I tried to do a for loop in a plugin file using the fuction delete() but I only can delete 10 at a time.

<?php

    include_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

    admin_gatekeeper();

    for ($i=1200; $i<1210; $i++) {

$event = get_entity($i);

$rowsaffected = $event->delete();

   }

?>

Do exists a function or option to use instead?

Thanks.

 

  • are you on a cheap shared server hosting ?
    elgg is a big boy and needs bigger toys to play with ;-)
    if so -- you will have restrictions on server resources such as exec time.
    it's definitly not a case of elgg problems b/c of not having the facility
    but rather the under-powered server resources.
    try running that loop in smaller blocks...

  • It wasn't a restriction of the server, the problem was that at the range defined at the for loop, there was some inexisting guid. So the code worked this way:

     for ($i=21; $i<1420; $i++) {

    $event = get_entity($i);

    echo $event;

    if (!empty($event)) {

    $rowsaffected = $event->delete();

    }

    else {}

    }

     

    Thanks.