Exemple #1
0
 /**
  * @param int $offset
  */
 public function syncGroups($offset = 0)
 {
     $this->logger->info('Processing groups ' . $offset . ' to ' . ($offset + self::BATCH_SIZE) . '...');
     $ldapGroups = $this->ldap->findGroups($offset, self::BATCH_SIZE);
     $grouphubGroups = $this->api->findLdapGroups($offset, self::BATCH_SIZE);
     if (count($ldapGroups) === 0 && count($grouphubGroups) === 0) {
         $this->logger->info('Done syncing groups!');
         return;
     }
     $index = $grouphubGroups->synchronize($ldapGroups, true);
     $this->logger->info(' - Going to add ' . count($grouphubGroups->getAddedElements()) . ' groups to Grouphub...');
     foreach ($grouphubGroups->getAddedElements() as $element) {
         /** @var Group $element */
         $element = $this->api->addGroup($element);
         $this->syncGroupUsers($element);
     }
     $this->logger->info(' - Going to update ' . count($grouphubGroups->getUpdatedElements()) . ' groups in Grouphub...');
     foreach ($grouphubGroups->getUpdatedElements() as $element) {
         /** @var Group[] $element */
         $this->api->updateGroup($element['old']->getId(), $element['new']);
         $this->syncGroupUsers($element['old']);
     }
     $this->logger->info(' - Going to remove ' . count($grouphubGroups->getRemovedElements()) . ' groups from Grouphub...');
     foreach ($grouphubGroups->getRemovedElements() as $element) {
         /** @var Group $element */
         $this->api->removeGroup($element->getId());
     }
     foreach ($grouphubGroups->getEqualElementIndexes() as $index) {
         /** @var Group $element */
         $this->syncGroupUsers($grouphubGroups[$index]);
     }
     $this->syncGroups($offset + $index + 1);
 }