ElggBatch::setIncrementOffset PHP Method

setIncrementOffset() public method

Increment the offset from the original options array? Setting to false is required for callbacks that delete rows.
public setIncrementOffset ( boolean $increment = true ) : void
$increment boolean Set to false when deleting data
return void
    public function setIncrementOffset($increment = true)
    {
        $this->incrementOffset = (bool) $increment;
    }

Usage Example

Esempio n. 1
0
function tidypics_batch_delete_images()
{
    // delete
    $log = elgg_get_config('tidypics_log');
    $log_time = elgg_get_config('tidypics_logtime');
    $options = array('type' => 'object', 'subtype' => 'image', 'metadata_name_value_pairs' => array('name' => 'tidypics_delete_check', 'value' => $log_time), 'limit' => false);
    $images = new ElggBatch('elgg_get_entities_from_metadata', $options);
    $images->setIncrementOffset(false);
    $total = elgg_get_entities_from_metadata(array_merge($options, array('count' => true)));
    file_put_contents($log, "Starting deletion of {$total} images" . "\n", FILE_APPEND);
    $i = 0;
    $count = 0;
    foreach ($images as $image) {
        $count++;
        if ($image->delete()) {
            $i++;
        }
        if ($count == 1 || !($count % 25)) {
            $time = date('m/d/Y g:i:s a');
            $j = $count - $i;
            $message = "Deleted {$i}, skipped {$j}, of {$total} images as of {$time}";
            file_put_contents($log, $message . "\n", FILE_APPEND);
        }
    }
    $message = '<div class="done">Completed: Deleted ' . $i . ', skipped ' . $j . ', of ' . $total . '</div>';
    file_put_contents($log, $message . "\n", FILE_APPEND);
}
All Usage Examples Of ElggBatch::setIncrementOffset