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

Find a project, limit 25 #46

Closed
VoidAndAny opened this issue Dec 3, 2013 · 7 comments
Closed

Find a project, limit 25 #46

VoidAndAny opened this issue Dec 3, 2013 · 7 comments

Comments

@VoidAndAny
Copy link

When I search a project with getIdByName, my projects are not found if they are not in the 25 first one.

Indeed "getIdByName" call "listing" function to construct an array of projects.
"Listing" call "all" function because $this->projects is empty and finally "all" function call "retrieveAll" function of AbstractApi.

The problem is that "retrieveAll" function has a default limitation of 25 items so if my project isn't in the first 25 ones it isn't found.

The only way I found for the moment is to call "all" function with a big limit value (200 as I have 160 projects) before calling getIdByName.
But I will need to change this value when I will have more than 200 projects.

Any advice ?

@MichaelKling
Copy link
Contributor

You could call the all function with a filter searching for the specific project id (there are lot of undocumented features in the api - its worth a try).

@JanMalte
Copy link
Contributor

I can confirm this issue. But you can't rely only on the name, as it can be the same for multiple projects. Only the identifier and the ID of a Redmine project are unique.

@Henry31
Copy link

Henry31 commented Sep 26, 2014

we have the same issue here, too!

@Henry31
Copy link

Henry31 commented Mar 19, 2015

As a workaround i check the output against my limit.

if ($project['total_count'][0] >= $project_limit) {
  //warning
}

@ferdynator
Copy link
Contributor

I've changed the AbstractApi::retrieveAll method to work around this:

protected function retrieveAll($endpoint, array $params = array())
{
    $defaults = array(
        'limit' => 100,
        'offset' => 0,
    );
    $params = $this->sanitizeParams($defaults, $params);

    $ret = array();

    $limit = $params['limit'];
    $offset = $params['offset'];
    $totalCount = 101;

    while ($offset < $totalCount) {

        $newDataSet = (array) $this->get($endpoint.'?'.http_build_query($params));
        $ret = array_merge_recursive($ret, $newDataSet);

        if (empty($newDataSet) || !isset($newDataSet['limit']) || !isset($newDataSet['total_count'])) {
            $totalCount = 0;
        } else {
            $totalCount = $newDataSet['total_count'];
            $offset += $limit;
            $params['offset'] = $offset;
        }
    }

    return $ret;
}

This solves the issue but many tests fail. Can anyone confirm my solution? If it works for you I will update the tests correctly and create a PR

@kbsali
Copy link
Owner

kbsali commented Jun 9, 2015

@VoidAndAny, it's been a loooong time since you raised this issue... see @ferdynator 's last comment, should this still be needful to you!

@Detzler
Copy link

Detzler commented May 3, 2016

retrieveAll says: "Retrieves all the elements of a given endpoint (even if the total number of elements is greater than 100)."

It doesn't do what it should. Please fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants