Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: multiPageSearch funcation added for Pagination while searchi… #9

Closed
wants to merge 2 commits into from

Conversation

ArchTaqi
Copy link

Most of Active directory has a limit of request users like 1k or 5k and if you need to get more users like 10k we need to use search and get users data with pagination. So added Multi page search to the lib. below is the the code to call this function.

        $users = $this->zendLdap->multiPageSearch($filter, $baseDn, $scope, $fields);
        return $users;

@froschdesign
Copy link
Member

@heiglandreas
This is a reopened pull request from the old repository.
It would be great if you could look at this. Thanks in advance!

@froschdesign froschdesign linked an issue May 28, 2020 that may be closed by this pull request
2 tasks
@froschdesign
Copy link
Member

froschdesign commented May 28, 2020

@ArchTaqi
Thanks for your contribution!

Please have a look on Travis there are some problems listed: https://travis-ci.com/github/laminas/laminas-ldap/jobs/340791227#L836
If you could fix the points, it would simplify the review. Thanks!

} while ($cookie);
ErrorHandler::stop();

if (count($results) == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use truthy check:

Suggested change
if (count($results) == 0) {
if (! $results) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather see this test here:

Suggested change
if (count($results) == 0) {
if ($results === []) {

This checks for an untouched $results. As soon as something is in that array we have to assume something worked correctly.

Copy link
Contributor

@heiglandreas heiglandreas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I'm not 💯% happy with hiding a multipaged search behind as function as you never know how much resources it will cost. Given larege company directories such a query can return hundrets of thousands of entries. In a not realy memory efficient structure like an array.

So finding a way to return an iterable for this use-case that yields the always current result might be a better approach.

But before we do not have a way to aggregate paged results in such a memory efficient way it is better to use thins approach.

Oh. And I'm also missing some tests here ;-)

$attributes
);

foreach (ldap_get_entries($resource, $result) as $item){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see an issue here as ldap_get_entries returns a rather awkward array containing an entry count followed by a numerically indext list of entries. So for each iteration in the do...while we will have an entry count pushed to the results array. I doubt that is what you had in mind...

);

foreach (ldap_get_entries($resource, $result) as $item){
array_push($results, (array)$item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This array_push causes the values of the count entries to be added multiple times as array.

So you weill have some arbitrary array entries in the result that contain [$pagesize] ...

} while ($cookie);
ErrorHandler::stop();

if (count($results) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather see this test here:

Suggested change
if (count($results) == 0) {
if ($results === []) {

This checks for an untouched $results. As soon as something is in that array we have to assume something worked correctly.

$$key = $value;
break;
case 'attributes':
if (is_array($value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when $value is not an array?

@geerteltink geerteltink changed the base branch from master to 2.11.x September 11, 2020 12:59
@ArchTaqi ArchTaqi closed this by deleting the head repository Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Added Pagination while searching users.
6 participants