Skip to content

Commit

Permalink
tweak(Admin/Frontend/Cli): php 7.4 compatibility for deleteUserlessCo…
Browse files Browse the repository at this point in the history
…ntainers
  • Loading branch information
pschuele committed Mar 18, 2024
1 parent 2f253c9 commit de4844c
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions tine20/Admin/Frontend/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ public function deleteAccount(Zend_Console_Getopt $_opts): int
/**
* Delete containers with no users
*
* @return void
* @param Zend_Console_Getopt $opts
* @return int
*/
public function deleteUserlessContainers(Zend_Console_Getopt $opts)
public function deleteUserlessContainers(Zend_Console_Getopt $opts): int
{
if ($opts->d) {
echo "--DRY RUN--\n";
Expand All @@ -249,20 +250,22 @@ public function deleteUserlessContainers(Zend_Console_Getopt $opts)
$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;
}
// Check if the container has no users
if ($container['type'] == 'personal') {
try {
$user = Tinebase_User::getInstance()->getFullUserById($container['owner_id']);
} catch (Tinebase_Exception_NotFound $tenf) {
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;
}
}
}
}
}

return 0;
}

/**
Expand Down

0 comments on commit de4844c

Please sign in to comment.