Skip to content

Instantly share code, notes, and snippets.

@alexwilson
Created June 19, 2017 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexwilson/35eea6e908cfc06ded6ddff72070b2c0 to your computer and use it in GitHub Desktop.
Save alexwilson/35eea6e908cfc06ded6ddff72070b2c0 to your computer and use it in GitHub Desktop.
eZDeleteUsers.php
#!/usr/bin/env php
<?php
include_once('autoload.php');
ini_set("memory_limit", "-1");
ini_set("date.timezone", "Europe/London");
$cli =& eZCLI::instance();
$script =& eZScript::instance();
$script->startup();
$script->initialize();
$userCreatorId = eZINI::instance()->variable("UserSettings", "UserCreatorID");
$user = eZUser::fetch($userCreatorId);
eZUser::setCurrentlyLoggedInUser($user, $userCreatorId);
$users = eZContentObjectTreeNode::fetch(5);
print "Retrieved users node.".PHP_EOL;
$batchedUsersToDelete = array_chunk(array_map(function($node) {
return $node->attribute('main_node_id');
}, $users->subTree(array(
'ClassFilterType' => 'include',
'ClassFilterArray' => array(52)
))), 50);
print "Batched users.".PHP_EOL;
$totalBatches = count($batchedUsersToDelete);
foreach ($batchedUsersToDelete as $index => $batch) {
$index++; // Make human-readable.
print "Processing {$index}/{$totalBatches}".PHP_EOL;
eZContentObjectTreeNode::removeSubtrees($batch, false);
}
$script->shutdown();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment