Skip to content

Commit

Permalink
Merge pull request #15 from kiwimarc/main
Browse files Browse the repository at this point in the history
Possible fix to issue #14
  • Loading branch information
pschuele authored Jan 24, 2024
2 parents d823a9d + 9343fec commit 1bd3e66
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tine20/Admin/Frontend/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,39 @@ public function deleteAccount(Zend_Console_Getopt $_opts): int
return 0;
}

/**
* Delete containers with no users
*
* @return void
*/
public function deleteUserlessContainers(Zend_Console_Getopt $opts)
{
if ($opts->d) {
echo "--DRY RUN--\n";
}
// Get an instance of Admin_Frontend_Json
$jsonFrontend = new Admin_Frontend_Json();

// Get all containers
$containers = $jsonFrontend->searchContainers([], null);

foreach ($containers['results'] as $container) {
// Check if the container has no users
if ($container['type'] == 'personal') {
try {
$user = Tinebase_User::getInstance()->getFullUserById($container['owner_id']);
} catch (Tinebase_Exception_NotFound) {
if ($opts->d) {
echo "--DRY RUN-- Found " . $container['name'] . PHP_EOL;
} else {
$jsonFrontend->deleteContainers([$container['id']]);
echo 'Deleted container ' . $container['name'] . ' with no users.' . PHP_EOL;
}
}
}
}
}

/**
* shorten loginnmes to fit ad samaccountname
*
Expand Down

0 comments on commit 1bd3e66

Please sign in to comment.