Skip to content

Commit 638d7c6

Browse files
author
Ludovic Silvestre
committed
Solved a bug with the filtering of parameters. Now it accepts 0 as a non-empty value.
1 parent 8ef5bbd commit 638d7c6

File tree

10 files changed

+61
-17
lines changed

10 files changed

+61
-17
lines changed

lib/Redmine/Api/AbstractApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function delete($path)
9696
*/
9797
protected function isNotNull($var)
9898
{
99-
return !is_null($var);
99+
return !(is_null($var) || $var === false || $var === "" || ((is_array($var) || is_object($var)) && empty($var)));
100100
}
101101

102102
/**

lib/Redmine/Api/Group.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public function create(array $params = array())
5858
'name' => null,
5959
'user_ids' => null,
6060
);
61-
$params = array_filter(array_merge($defaults, $params));
61+
$params = array_filter(
62+
array_merge($defaults, $params),
63+
array($this, 'isNotNull')
64+
);
6265
if (
6366
!isset($params['name'])
6467
) {

lib/Redmine/Api/Issue.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ public function create(array $params = array())
127127
'watcher_user_ids' => null,
128128
);
129129
$params = $this->cleanParams($params);
130-
$params = array_filter(array_merge($defaults, $params));
130+
$params = array_filter(
131+
array_merge($defaults, $params),
132+
array($this, 'isNotNull')
133+
);
131134

132135
$xml = $this->buildXML($params);
133136

@@ -166,7 +169,10 @@ public function update($id, array $params)
166169
'due_date' => null,
167170
);
168171
$params = $this->cleanParams($params);
169-
$params = array_filter(array_merge($defaults, $params));
172+
$params = array_filter(
173+
array_merge($defaults, $params),
174+
array($this, 'isNotNull')
175+
);
170176

171177
$xml = $this->buildXML($params);
172178

lib/Redmine/Api/IssueCategory.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ public function create($project, array $params = array())
9090
'name' => null,
9191
'assigned_to_id' => null,
9292
);
93-
$params = array_filter(array_merge($defaults, $params));
93+
$params = array_filter(
94+
array_merge($defaults, $params),
95+
array($this, 'isNotNull')
96+
);
9497
if (
9598
!isset($params['name'])
9699
) {
@@ -119,7 +122,10 @@ public function update($id, array $params)
119122
'name' => null,
120123
'assigned_to_id' => null,
121124
);
122-
$params = array_filter(array_merge($defaults, $params));
125+
$params = array_filter(
126+
array_merge($defaults, $params),
127+
array($this, 'isNotNull')
128+
);
123129

124130
$xml = new SimpleXMLElement('<?xml version="1.0"?><issue_category></issue_category>');
125131
foreach ($params as $k => $v) {

lib/Redmine/Api/Membership.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public function create($project, array $params = array())
4242
'user_ids' => null,
4343
'role_ids' => null,
4444
);
45-
$params = array_filter(array_merge($defaults, $params));
45+
$params = array_filter(
46+
array_merge($defaults, $params),
47+
array($this, 'isNotNull')
48+
);
4649
if ((!isset($params['user_ids']) && !isset($params['user_id']))
4750
|| !isset($params['role_ids'])
4851
) {
@@ -67,7 +70,10 @@ public function update($id, array $params = array())
6770
$defaults = array(
6871
'role_ids' => null,
6972
);
70-
$params = array_filter(array_merge($defaults, $params));
73+
$params = array_filter(
74+
array_merge($defaults, $params),
75+
array($this, 'isNotNull')
76+
);
7177
if (!isset($params['role_ids'])) {
7278
throw new \Exception('Missing mandatory parameters');
7379
}

lib/Redmine/Api/Project.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ public function update($id, array $params)
122122
'identifier' => null,
123123
'description' => null,
124124
);
125-
$params = array_filter(array_merge($defaults, $params));
125+
$params = array_filter(
126+
array_merge($defaults, $params),
127+
array($this, 'isNotNull')
128+
);
126129

127130
$xml = $this->prepareParamsXml($params);
128131

lib/Redmine/Api/TimeEntry.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public function create(array $params = array())
5454
'activity_id' => null,
5555
'comments' => null,
5656
);
57-
$params = array_filter(array_merge($defaults, $params));
57+
$params = array_filter(
58+
array_merge($defaults, $params),
59+
array($this, 'isNotNull')
60+
);
5861
if (
5962
(!isset($params['issue_id']) && !isset($params['project_id']))
6063
|| !isset($params['hours'])
@@ -89,7 +92,10 @@ public function update($id, array $params)
8992
'activity_id' => null,
9093
'comments' => null,
9194
);
92-
$params = array_filter(array_merge($defaults, $params));
95+
$params = array_filter(
96+
array_merge($defaults, $params),
97+
array($this, 'isNotNull')
98+
);
9399

94100
$xml = new SimpleXMLElement('<?xml version="1.0"?><time_entry></time_entry>');
95101
foreach ($params as $k => $v) {

lib/Redmine/Api/User.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public function create(array $params = array())
101101
'mail' => null,
102102
// 'auth_source_id' => null,
103103
);
104-
$params = array_filter(array_merge($defaults, $params));
104+
$params = array_filter(
105+
array_merge($defaults, $params),
106+
array($this, 'isNotNull')
107+
);
105108
if (
106109
!isset($params['login'])
107110
|| !isset($params['lastname'])
@@ -110,7 +113,6 @@ public function create(array $params = array())
110113
) {
111114
throw new \Exception('Missing mandatory parameters');
112115
}
113-
114116
$xml = new SimpleXMLElement('<?xml version="1.0"?><user></user>');
115117
foreach ($params as $k => $v) {
116118
if ('custom_fields' === $k) {
@@ -142,7 +144,10 @@ public function update($id, array $params)
142144
'mail' => null,
143145
// 'auth_source_id' => null,
144146
);
145-
$params = array_filter(array_merge($defaults, $params));
147+
$params = array_filter(
148+
array_merge($defaults, $params),
149+
array($this, 'isNotNull')
150+
);
146151

147152
$xml = new SimpleXMLElement('<?xml version="1.0"?><user></user>');
148153
foreach ($params as $k => $v) {

lib/Redmine/Api/Version.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public function create($project, array $params = array())
9494
'sharing' => null,
9595
'due_date' => null,
9696
);
97-
$params = array_filter(array_merge($defaults, $params));
97+
$params = array_filter(
98+
array_merge($defaults, $params),
99+
array($this, 'isNotNull')
100+
);
98101
if (
99102
!isset($params['name'])
100103
) {
@@ -128,7 +131,10 @@ public function update($id, array $params)
128131
'sharing' => null,
129132
'due_date' => null,
130133
);
131-
$params = array_filter(array_merge($defaults, $params));
134+
$params = array_filter(
135+
array_merge($defaults, $params),
136+
array($this, 'isNotNull')
137+
);
132138
$this->validateStatus($params);
133139
$this->validateSharing($params);
134140

lib/Redmine/Api/Wiki.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public function create($project, $page, array $params = array())
6060
'comments' => null,
6161
'version' => null,
6262
);
63-
$params = array_filter(array_merge($defaults, $params));
63+
$params = array_filter(
64+
array_merge($defaults, $params),
65+
array($this, 'isNotNull')
66+
);
6467

6568
$xml = new SimpleXMLElement('<?xml version="1.0"?><wiki_page></wiki_page>');
6669
foreach ($params as $k => $v) {

0 commit comments

Comments
 (0)