/**
  * calls map() on the given mapper and asserts result for true
  * @param \OCA\User_LDAP\Mapping\AbstractMapping $mapper
  * @param array $data
  */
 protected function mapEntries($mapper, $data)
 {
     foreach ($data as $entry) {
         $done = $mapper->map($entry['dn'], $entry['name'], $entry['uuid']);
         $this->assertTrue($done);
     }
 }
Esempio n. 2
0
 /**
  * creates a unique name for internal ownCloud use for groups. Don't call it directly.
  * @param string $name the display name of the object
  * @return string|false with with the name to use in ownCloud or false if unsuccessful.
  *
  * Instead of using this method directly, call
  * createAltInternalOwnCloudName($name, false)
  *
  * Group names are also used as display names, so we do a sequential
  * numbering, e.g. Developers_42 when there are 41 other groups called
  * "Developers"
  */
 private function _createAltInternalOwnCloudNameForGroups($name)
 {
     $usedNames = $this->groupMapper->getNamesBySearch($name . '_%');
     if (!$usedNames || count($usedNames) === 0) {
         $lastNo = 1;
         //will become name_2
     } else {
         natsort($usedNames);
         $lastName = array_pop($usedNames);
         $lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1));
     }
     $altName = $name . '_' . strval($lastNo + 1);
     unset($usedNames);
     $attempts = 1;
     while ($attempts < 21) {
         // Check to be really sure it is unique
         // while loop is just a precaution. If a name is not generated within
         // 20 attempts, something else is very wrong. Avoids infinite loop.
         if (!\OC_Group::groupExists($altName)) {
             return $altName;
         }
         $altName = $name . '_' . ($lastNo + $attempts);
         $attempts++;
     }
     return false;
 }