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

Switch key and value in listing #6

Closed
Eighke opened this issue Nov 12, 2012 · 6 comments
Closed

Switch key and value in listing #6

Eighke opened this issue Nov 12, 2012 · 6 comments

Comments

@Eighke
Copy link

Eighke commented Nov 12, 2012

Hi,

In Version, the listing() function uses the name as key. But the name isn't unique and if you used a name twice or more, only the last is sent back. This also is a problem in Project.

Would it not be better to use the ID as key?

$ret[(int) $e['id']] = $e['name']; 

And for getIdByName()

public function getIdByName($name)
{
  $arr = array_flip($this->listing());
@wsuff
Copy link
Contributor

wsuff commented Nov 13, 2012

Hmm. I haven't thought of this yet. Glad you raised the issue here at least for discussion. It sounds like it might be a wise idea. My only concern would be how do we warn users of the library of the change in behavior? I assume a change like this would require the user of the library to adjust their code to release the key is now the int id and not project name. Where else did you see this issue? It wasn't too clear to me from the post. Thanks for reporting it.

@kbsali
Copy link
Owner

kbsali commented Nov 13, 2012

Oh! That's a good point indeed. Although as it really happen to you before that you named 2 Versions or Projects the same way?
I'm not trying to argue your point, if the name is not unique then this indeed is a bug!

@wsuff : how about renaming the listing method "listingById()" and correcting all the listing() method with the changes proposed by @Eighke ? The change would then be almost transparent to anybody using the listing(). This is not a stable version anyway, so i would say this BC breaks are ok at such an early stage.

What do you think?

@Eighke
Copy link
Author

Eighke commented Nov 13, 2012

@kbsali yes I have some sub Projects with the same name. Something like :

  • Project 1
    • Frontend
    • Backend
  • Project 2
    • Backend
    • Engine

@wsuff , well good question. I checked, only Version and Project is affected. In the other class the name is unique. listingById() isn't a bad idea or maybe something like :

public function listing($project, $forceUpdate = false, $reverse = true)
{
    if (true === $forceUpdate || empty($this->versions)) {
        $this->all($project);
    }
    $ret = array();
    foreach ($this->versions['versions'] as $e) {
        $ret[$e[(int) 'id']] =  $e['name'];
    }

    return $reverse ? array_flip($ret) : $ret;
}

Dunno which one is the best option.

@wsuff
Copy link
Contributor

wsuff commented Nov 13, 2012

Ah. It makes more sense now. This wasn't a case I've noticed on my own install of Redmine yet since getting people to use a system after having none has been enough of challenge. =) listById() sounds ok to me. I can't really see any major downside to either proposed solution tho. Perhaps just a matter of preference and keeping consistence in the library.

Just realized this project is only month 1/2 old or so. Guess I lucked out that it was available when I went looking for one.

kbsali added a commit that referenced this issue Nov 19, 2012
@kbsali
Copy link
Owner

kbsali commented Nov 19, 2012

@Eighke thanks for pointing out this solution,
i've implemented it for Version and Project as you mentioned these were the 2 affected classes!
Please review the changes and close if ok.

@Eighke
Copy link
Author

Eighke commented Nov 22, 2012

Tested and approved. :)

Thanks.

@Eighke Eighke closed this as completed Nov 22, 2012
phungthuan99 added a commit to phungthuan99/php-redmine-api that referenced this issue Jul 2, 2021
Fatal error: Uncaught TypeError: Cannot assign int to property Redmine\Client\NativeCurlClient::$lastResponseContentType of type string in D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Client\NativeCurlClient.php:235 Stack trace: #0 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Client\NativeCurlClient.php(81): Redmine\Client\NativeCurlClient->request('get', '/users/current....') kbsali#1 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Api\AbstractApi.php(49): Redmine\Client\NativeCurlClient->requestGet('/users/current....') kbsali#2 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Api\User.php(121): Redmine\Api\AbstractApi->get('/users/current....') kbsali#3 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Api\User.php(66): Redmine\Api\User->show('current', Array) kbsali#4 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\cloodo.php(27): Redmine\Api\User->getCurrentUser(Array) kbsali#5 D:\xampp-v8\htdocs\wordpress\wp-settings.php(391): include_once('D:\\xampp-v8\\htd...') kbsali#6 D:\xampp-v8\htdocs\wordpress\wp-config.php(90): require_once('D:\\xampp-v8\\htd...') kbsali#7 D:\xampp-v8\htdocs\wordpress\wp-load.php(37): require_once('D:\\xampp-v8\\htd...') kbsali#8 D:\xampp-v8\htdocs\wordpress\wp-admin\admin.php(34): require_once('D:\\xampp-v8\\htd...') kbsali#9 {main} thrown in D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Client\NativeCurlClient.php on line 235
kbsali pushed a commit that referenced this issue Sep 22, 2021
* Fix $lastResponseContentType of type string

Fatal error: Uncaught TypeError: Cannot assign int to property Redmine\Client\NativeCurlClient::$lastResponseContentType of type string in D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Client\NativeCurlClient.php:235 Stack trace: #0 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Client\NativeCurlClient.php(81): Redmine\Client\NativeCurlClient->request('get', '/users/current....') #1 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Api\AbstractApi.php(49): Redmine\Client\NativeCurlClient->requestGet('/users/current....') #2 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Api\User.php(121): Redmine\Api\AbstractApi->get('/users/current....') #3 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Api\User.php(66): Redmine\Api\User->show('current', Array) #4 D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\cloodo.php(27): Redmine\Api\User->getCurrentUser(Array) #5 D:\xampp-v8\htdocs\wordpress\wp-settings.php(391): include_once('D:\\xampp-v8\\htd...') #6 D:\xampp-v8\htdocs\wordpress\wp-config.php(90): require_once('D:\\xampp-v8\\htd...') #7 D:\xampp-v8\htdocs\wordpress\wp-load.php(37): require_once('D:\\xampp-v8\\htd...') #8 D:\xampp-v8\htdocs\wordpress\wp-admin\admin.php(34): require_once('D:\\xampp-v8\\htd...') #9 {main} thrown in D:\xampp-v8\htdocs\wordpress\wp-content\plugins\wordpress-cloodo-plugins\libs\Redmine\Client\NativeCurlClient.php on line 235

* Create test for handling of missing content type

Co-authored-by: Art4 <art4@wlabs.de>
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

3 participants