Skip to content

Commit b2979db

Browse files
committed
Do not delete groups if they still contain any projects or subgroups.
1 parent fe2ed2c commit b2979db

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/LdapSyncCommand.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,16 @@ private function deployGitlabUsersAndGroups(array $config, string $gitlabInstanc
12511251
continue;
12521252
}
12531253

1254+
if (is_array($gitlabGroupProjects = $gitlab->api("groups")->projects($gitlabGroupId)) && ($gitlabGroupProjectsNum = count($gitlabGroupProjects)) >= 1) {
1255+
$this->logger->info(sprintf("Not deleting Gitlab group #%d \"%s\" [%s]: It contains %d project(s).", $gitlabGroupId, $gitlabGroupName, $gitlabGroupPath, $gitlabGroupProjectsNum));
1256+
continue;
1257+
}
1258+
1259+
if (is_array($gitlabGroupSubGroups = $gitlab->api("groups")->subgroups($gitlabGroupId)) && ($gitlabGroupSubGroupsNum = count($gitlabGroupSubGroups)) >= 1) {
1260+
$this->logger->info(sprintf("Not deleting Gitlab group #%d \"%s\" [%s]: It contains %d subgroup(s).", $gitlabGroupId, $gitlabGroupName, $gitlabGroupPath, $gitlabGroupSubGroupsNum));
1261+
continue;
1262+
}
1263+
12541264
$this->logger->warning(sprintf("Deleting Gitlab group #%d \"%s\" [%s].", $gitlabGroupId, $gitlabGroupName, $gitlabGroupPath));
12551265
$gitlabGroup = null;
12561266

0 commit comments

Comments
 (0)