<?php
// Assign a UUID to all users in LDAP

// This patch can no longer be executed as it required LDAP to function.
// Since the DB Patch tool requires the patches to be sequential and fails if a patch is missing, we have simply emptied
// this patch.

<?php
// Assign a UUID to all users in LDAP

/**
 * DbPatch makes the following variables available to PHP patches:
 *
 * @var $this       DbPatch_Command_Patch_PHP
 * @var $writer     DbPatch_Core_Writer
 * @var $db         Zend_Db_Adapter_Abstract
 * @var $phpFile    string
 */

$ldapConfig = EngineBlock_ApplicationSingleton::getInstance()->getConfiguration()->ldap;

$ldapOptions = array(
    'host'                 => $ldapConfig->host,
    'port'                 => $ldapConfig->port,
    'useSsl'               => $ldapConfig->useSsl,
    'username'             => $ldapConfig->userName,
    'password'             => $ldapConfig->password,
    'bindRequiresDn'       => $ldapConfig->bindRequiresDn,
    'accountDomainName'    => $ldapConfig->accountDomainName,
    'baseDn'               => $ldapConfig->baseDn
);

$ldapClient = new Zend_Ldap($ldapOptions);
$ldapClient->bind();

$writer->info("Retrieving all collabPerson entries from LDAP");

//$filter = '(&(objectclass=collabPerson))';
$filter = '(&(objectclass=collabPerson)(!(collabPersonUUID=*)))';

$users = $ldapClient->search($filter);
while (count($users) > 0) {
    $writer->info("Retrieved " . count($users) . " users from LDAP");
    foreach ($users as $user) {
        foreach ($user as $userKey => $userValue) {
            if (is_array($userValue) && count($userValue) === 1) {
                $user[$userKey] = $userValue[0];
            }
        }

        $user['collabpersonuuid'] = (string) \Ramsey\Uuid\Uuid::uuid4();

        $now = date(DATE_RFC822);
        $user['collabpersonlastupdated'] = $now;

        $dn = 'uid=' . $user['uid'] . ',o=' . $user['o'] . ',' . $ldapClient->getBaseDn();
        $ldapClient->update($dn, $user);

        $writer->info("Set UUID '{$user['collabpersonuuid']}' for DN: '$dn'");
    }
    $users = $ldapClient->search($filter);
}


--- 
+++ 
@@ -1,56 +1,6 @@
 <?php
 // Assign a UUID to all users in LDAP
 
-/**
- * DbPatch makes the following variables available to PHP patches:
- *
- * @var $this       DbPatch_Command_Patch_PHP
- * @var $writer     DbPatch_Core_Writer
- * @var $db         Zend_Db_Adapter_Abstract
- * @var $phpFile    string
- */
-
-$ldapConfig = EngineBlock_ApplicationSingleton::getInstance()->getConfiguration()->ldap;
-
-$ldapOptions = array(
-    'host'                 => $ldapConfig->host,
-    'port'                 => $ldapConfig->port,
-    'useSsl'               => $ldapConfig->useSsl,
-    'username'             => $ldapConfig->userName,
-    'password'             => $ldapConfig->password,
-    'bindRequiresDn'       => $ldapConfig->bindRequiresDn,
-    'accountDomainName'    => $ldapConfig->accountDomainName,
-    'baseDn'               => $ldapConfig->baseDn
-);
-
-$ldapClient = new Zend_Ldap($ldapOptions);
-$ldapClient->bind();
-
-$writer->info("Retrieving all collabPerson entries from LDAP");
-
-//$filter = '(&(objectclass=collabPerson))';
-$filter = '(&(objectclass=collabPerson)(!(collabPersonUUID=*)))';
-
-$users = $ldapClient->search($filter);
-while (count($users) > 0) {
-    $writer->info("Retrieved " . count($users) . " users from LDAP");
-    foreach ($users as $user) {
-        foreach ($user as $userKey => $userValue) {
-            if (is_array($userValue) && count($userValue) === 1) {
-                $user[$userKey] = $userValue[0];
-            }
-        }
-
-        $user['collabpersonuuid'] = (string) \Ramsey\Uuid\Uuid::uuid4();
-
-        $now = date(DATE_RFC822);
-        $user['collabpersonlastupdated'] = $now;
-
-        $dn = 'uid=' . $user['uid'] . ',o=' . $user['o'] . ',' . $ldapClient->getBaseDn();
-        $ldapClient->update($dn, $user);
-
-        $writer->info("Set UUID '{$user['collabpersonuuid']}' for DN: '$dn'");
-    }
-    $users = $ldapClient->search($filter);
-}
-
+// This patch can no longer be executed as it required LDAP to function.
+// Since the DB Patch tool requires the patches to be sequential and fails if a patch is missing, we have simply emptied
+// this patch.
Remove database patch that depends on LDAP
