kbsali / php-redmine-api

A simple PHP Redmine API client, Object Oriented

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The function 'getIdByUsername' return 'false' for some users.

pde159 opened this issue · comments

Hello,

The function 'getIdByUsername' return 'false' for some users.

I see this function calling the 'listing' function to retrieve all users but this one is limited to 25.
Then, it explain why some users are not available via 'getIdByUsername'.

So I tried to use the function like this :

$redmine->provider->user->getIdByUsername('myusername', ['limit' => 100,'offset' => 0]));

but this has no effect ...

So my actual workaround is to add in src/Redmine/Api/User.php a line where i force param line 42

$params = ['limit' => 100, 'offset' => 0];

my php version PHP 8.0.3 (cli) (built: Mar 2 2021 16:37:06) ( NTS gcc x86_64 )
running on centOS 7 3.10.0-1160.15.2.el7.x86_64

Regards,

The user API class has a built-in cache for retrieved users. If you call listing() the first time then the cache will be filled up with this result. Then when you call getIdByUsername('myusername', ['limit' => 100,'offset' => 0])); the method will ignore the params and will only search in the cache.

This said you should first rebuild the user cache with the needed params and after that call getIdByUsername():

// Rebuild user cache
$client->getApi('user')->all(['limit' => 100,'offset' => 0]);

// Get Id for username
$id = $client->getApi('user')->getIdByUsername('myusername');

This should now work as expected.

As a side note: I've noted that you are using the old magic getter for api instances ($redmine->provider->user). Starting with v1.7.0 this behavior is deprecated and you should use getApi() instead.

-$redmine->provider->user
+$redmine->provider->getApi('user')

hello @Art4 ,

Great, thank you for the help. i'm gonna try this as soon as possible.
I was already migrating my code with new NativeClient syntax but it is for a next release of my product ;)

Hey, It's been a while and I hope you were able to solve your problem. I'm going to close this issue, but feel free to reopen it if you continue to have problems.