Created
June 19, 2017 11:16
-
-
Save alexwilson/35eea6e908cfc06ded6ddff72070b2c0 to your computer and use it in GitHub Desktop.
eZDeleteUsers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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