Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add progression display on CLI mode when update user from LDAP
  • Loading branch information
c12simple committed Nov 25, 2014
1 parent b6f9e98 commit 3ac8f8d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/src/core/classes/class.AJXP_ProgressBarCLI.php
Expand Up @@ -33,6 +33,7 @@ class AJXP_ProgressBarCLI {
private $lastsecond = 0;

public function init($currentValue = 0, $total, $name){
if(!(php_sapi_name() == "cli")) return;
$this->total = $total;
$this->strName = $name;
$this->startPoint = time();
Expand Down
16 changes: 15 additions & 1 deletion core/src/core/classes/class.AuthService.php
Expand Up @@ -966,7 +966,7 @@ public static function countUsersForRepository($repositoryId, $details = false)
* @param bool $recursive
* @return AbstractAjxpUser[]
*/
public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1, $limit = -1, $cleanLosts = true, $recursive = true)
public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1, $limit = -1, $cleanLosts = true, $recursive = true, $countCallback = null, $loopCallback = null)
{
$baseGroup = self::filterBaseGroup($baseGroup);
$authDriver = ConfService::getAuthDriverImpl();
Expand All @@ -979,10 +979,24 @@ public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1,
} else {
$users = $authDriver->listUsers($baseGroup);
}
$index = 0;

// Callback func for display progression on cli mode
if($countCallback != null){
call_user_func($countCallback, $index, count($users), "Update users");
}

foreach (array_keys($users) as $userId) {
if(($userId == "guest" && !ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth")) || $userId == "ajxp.admin.users" || $userId == "") continue;
if($regexp != null && !$authDriver->supportsUsersPagination() && !preg_match("/$regexp/i", $userId)) continue;
$allUsers[$userId] = $confDriver->createUserObject($userId);
$index++;

// Callback func for display progression on cli mode
if($countCallback != null){
call_user_func($loopCallback, $index);
}

if ($paginated) {
// Make sure to reload all children objects
foreach ($confDriver->getUserChildren($userId) as $childObject) {
Expand Down
Expand Up @@ -1673,8 +1673,15 @@ public function switchAction($action, $httpVars, $fileVars)

break;


// Action for update all Pydio's user from ldap in CLI mode
case "cli_update_user_list":
AuthService::listUsers();
if((php_sapi_name() == "cli")){
$progressBar = new AJXP_ProgressBarCLI();
$countCallback = array($progressBar, "init");
$loopCallback = array($progressBar, "update");
AuthService::listUsers("/", null, -1 , -1, true, true, $countCallback, $loopCallback);
}
break;

default:
Expand Down
14 changes: 14 additions & 0 deletions core/src/plugins/auth.ldap/class.ldapAuthDriver.php
Expand Up @@ -313,6 +313,14 @@ public function getUserEntries($login = null, $countOnly = false, $offset = -1,

$gotAllEntries = false;
$index = 0;

//Update progress bar in CLI mode
$isListAll = (($offset == -1) && ($limit == -1) && (is_null($login)) && $regexpOnSearchAttr && (php_sapi_name() == "cli"));
if($isListAll){
$progressBar = new AJXP_ProgressBarCLI();
$progressBar->init($index, $this->getCountFromCache()["count"], "Get ldap users");
}

do {
if ($isSupportPagedResult)
ldap_control_paged_result($this->ldapconn, $this->pageSize, true, $cookie);
Expand Down Expand Up @@ -354,6 +362,12 @@ public function getUserEntries($login = null, $countOnly = false, $offset = -1,

$allEntries[] = $entry;
$index++;

//Update progress bar in CLI mode
if(isset($progressBar))
$progressBar->update($index);


if (($offset != -1) && ($limit != -1) && $index > $offset + $limit)
break;
}
Expand Down

0 comments on commit 3ac8f8d

Please sign in to comment.