Completed
Pull Request — master (#312)
by
unknown
26:01 queued 18:06
created
htdocs/okapi/services/users/by_internal_ids.php 1 patch
Braces   +14 added lines, -9 removed lines patch added patch discarded remove patch
@@ -23,14 +23,18 @@  discard block
 block discarded – undo
23 23
     public static function call(OkapiRequest $request)
24 24
     {
25 25
         $internal_ids = $request->get_parameter('internal_ids');
26
-        if (!$internal_ids) throw new ParamMissing('internal_ids');
26
+        if (!$internal_ids) {
27
+            throw new ParamMissing('internal_ids');
28
+        }
27 29
         $internal_ids = explode("|", $internal_ids);
28
-        if (count($internal_ids) > 500)
29
-            throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ".
30
+        if (count($internal_ids) > 500) {
31
+                    throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ".
30 32
                 "is 500. You provided ".count($internal_ids)." references.");
33
+        }
31 34
         $fields = $request->get_parameter('fields');
32
-        if (!$fields)
33
-            throw new ParamMissing('fields');
35
+        if (!$fields) {
36
+                    throw new ParamMissing('fields');
37
+        }
34 38
 
35 39
         # There's no need to validate the fields parameter as the 'users'
36 40
         # method does this (it will raise a proper exception on invalid values).
@@ -57,10 +61,11 @@  discard block
 block discarded – undo
57 61
         $results = array();
58 62
         foreach ($internal_ids as $internal_id)
59 63
         {
60
-            if (!isset($internalid2useruuid[$internal_id]))
61
-                $results[$internal_id] = null;
62
-            else
63
-                $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]];
64
+            if (!isset($internalid2useruuid[$internal_id])) {
65
+                            $results[$internal_id] = null;
66
+            } else {
67
+                            $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]];
68
+            }
64 69
         }
65 70
 
66 71
         return Okapi::formatted_response($request, $results);
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_username.php 1 patch
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,14 +26,17 @@  discard block
 block discarded – undo
26 26
     public static function call(OkapiRequest $request)
27 27
     {
28 28
         $username = $request->get_parameter('username');
29
-        if (!$username) throw new ParamMissing('username');
29
+        if (!$username) {
30
+            throw new ParamMissing('username');
31
+        }
30 32
 
31 33
         # Fix for issue 339:
32 34
         # Catch pipe chars here, because services/users/by_usernames would split up the name.
33 35
         # OC databases do not contain user names with pipe chars.
34 36
 
35
-        if (strstr($username,'|'))
36
-            throw new InvalidParam('username', "There is no user by this username.");
37
+        if (strstr($username,'|')) {
38
+                    throw new InvalidParam('username', "There is no user by this username.");
39
+        }
37 40
         $fields = $request->get_parameter('fields');
38 41
 
39 42
         # There's no need to validate the fields parameter.
@@ -42,8 +45,9 @@  discard block
 block discarded – undo
42 45
             $request->consumer, $request->token, array('usernames' => $username,
43 46
             'fields' => $fields)));
44 47
         $result = $results[$username];
45
-        if ($result == null)
46
-            throw new InvalidParam('username', "There is no user by this username.");
48
+        if ($result == null) {
49
+                    throw new InvalidParam('username', "There is no user by this username.");
50
+        }
47 51
         return Okapi::formatted_response($request, $result);
48 52
     }
49 53
 }
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_internal_id.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@  discard block
 block discarded – undo
23 23
     public static function call(OkapiRequest $request)
24 24
     {
25 25
         $internal_id = $request->get_parameter('internal_id');
26
-        if (!$internal_id) throw new ParamMissing('internal_id');
26
+        if (!$internal_id) {
27
+            throw new ParamMissing('internal_id');
28
+        }
27 29
         $fields = $request->get_parameter('fields');
28 30
 
29 31
         # There's no need to validate the fields parameter.
@@ -32,8 +34,9 @@  discard block
 block discarded – undo
32 34
             $request->consumer, $request->token, array('internal_ids' => $internal_id,
33 35
             'fields' => $fields)));
34 36
         $result = $results[$internal_id];
35
-        if ($result == null)
36
-            throw new InvalidParam('internal_id', "There is no user by this internal_id.");
37
+        if ($result == null) {
38
+                    throw new InvalidParam('internal_id', "There is no user by this internal_id.");
39
+        }
37 40
         return Okapi::formatted_response($request, $result);
38 41
     }
39 42
 }
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_usernames.php 1 patch
Braces   +14 added lines, -9 removed lines patch added patch discarded remove patch
@@ -24,14 +24,18 @@  discard block
 block discarded – undo
24 24
     public static function call(OkapiRequest $request)
25 25
     {
26 26
         $usernames = $request->get_parameter('usernames');
27
-        if (!$usernames) throw new ParamMissing('usernames');
27
+        if (!$usernames) {
28
+            throw new ParamMissing('usernames');
29
+        }
28 30
         $usernames = explode("|", $usernames);
29
-        if (count($usernames) > 500)
30
-            throw new InvalidParam('usernames', "Maximum allowed number of referenced users ".
31
+        if (count($usernames) > 500) {
32
+                    throw new InvalidParam('usernames', "Maximum allowed number of referenced users ".
31 33
                 "is 500. You provided ".count($usernames)." usernames.");
34
+        }
32 35
         $fields = $request->get_parameter('fields');
33
-        if (!$fields)
34
-            throw new ParamMissing('fields');
36
+        if (!$fields) {
37
+                    throw new ParamMissing('fields');
38
+        }
35 39
 
36 40
         # There's no need to validate the fields parameter as the 'users'
37 41
         # method does this (it will raise a proper exception on invalid values).
@@ -65,10 +69,11 @@  discard block
 block discarded – undo
65 69
         $results = array();
66 70
         foreach ($usernames as $username)
67 71
         {
68
-            if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')]))
69
-                $results[$username] = null;
70
-            else
71
-                $results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]];
72
+            if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')])) {
73
+                            $results[$username] = null;
74
+            } else {
75
+                            $results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]];
76
+            }
72 77
         }
73 78
 
74 79
         return Okapi::formatted_response($request, $results);
Please login to merge, or discard this patch.
htdocs/okapi/services/users/users.php 1 patch
Braces   +25 added lines, -17 removed lines patch added patch discarded remove patch
@@ -28,18 +28,23 @@  discard block
 block discarded – undo
28 28
     public static function call(OkapiRequest $request)
29 29
     {
30 30
         $user_uuids = $request->get_parameter('user_uuids');
31
-        if (!$user_uuids) throw new ParamMissing('user_uuids');
31
+        if (!$user_uuids) {
32
+            throw new ParamMissing('user_uuids');
33
+        }
32 34
         $user_uuids = explode("|", $user_uuids);
33
-        if (count($user_uuids) > 500)
34
-            throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ".
35
+        if (count($user_uuids) > 500) {
36
+                    throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ".
35 37
                 "is 500. You provided ".count($user_uuids)." user IDs.");
38
+        }
36 39
         $fields = $request->get_parameter('fields');
37
-        if (!$fields)
38
-            throw new ParamMissing('fields');
40
+        if (!$fields) {
41
+                    throw new ParamMissing('fields');
42
+        }
39 43
         $fields = explode("|", $fields);
40
-        foreach ($fields as $field)
41
-            if (!in_array($field, self::$valid_field_names))
44
+        foreach ($fields as $field) {
45
+                    if (!in_array($field, self::$valid_field_names))
42 46
                 throw new InvalidParam('fields', "'$field' is not a valid field code.");
47
+        }
43 48
         $rs = Db::query("
44 49
             select user_id, uuid, username, admin, latitude, longitude, date_created
45 50
             from user
@@ -115,8 +120,7 @@  discard block
 block discarded – undo
115 120
                     from user
116 121
                     where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid)))."')
117 122
                 ");
118
-            }
119
-            else
123
+            } else
120 124
             {
121 125
                 # OCDE stores user stats in 'stat_user' table.
122 126
 
@@ -153,8 +157,9 @@  discard block
 block discarded – undo
153 157
                     group by user_id
154 158
                 ");
155 159
                 $rcmds_counts = array();
156
-                while ($row = Db::fetch_assoc($rs))
157
-                    $rcmds_counts[$row['user_id']] = $row['rcmds_given'];
160
+                while ($row = Db::fetch_assoc($rs)) {
161
+                                    $rcmds_counts[$row['user_id']] = $row['rcmds_given'];
162
+                }
158 163
                 foreach ($extras as $user_id => &$extra_ref)
159 164
                 {
160 165
                     $extra_ref['rcmds_given'] = isset($rcmds_counts[$user_id]) ? 0 + $rcmds_counts[$user_id] : 0;
@@ -165,18 +170,21 @@  discard block
 block discarded – undo
165 170
 
166 171
             foreach (array('caches_found', 'caches_notfound', 'caches_hidden', 'rcmds_given') as $field)
167 172
             {
168
-                if (!in_array($field, $fields))
169
-                    continue;
170
-                foreach ($results as $uuid => &$result_ref)
171
-                    $result_ref[$field] = $extras[$uuid2id[$uuid]][$field];
173
+                if (!in_array($field, $fields)) {
174
+                                    continue;
175
+                }
176
+                foreach ($results as $uuid => &$result_ref) {
177
+                                    $result_ref[$field] = $extras[$uuid2id[$uuid]][$field];
178
+                }
172 179
             }
173 180
         }
174 181
 
175 182
         # Check which user IDs were not found and mark them with null.
176 183
 
177
-        foreach ($user_uuids as $user_uuid)
178
-            if (!isset($results[$user_uuid]))
184
+        foreach ($user_uuids as $user_uuid) {
185
+                    if (!isset($results[$user_uuid]))
179 186
                 $results[$user_uuid] = null;
187
+        }
180 188
 
181 189
         return Okapi::formatted_response($request, $results);
182 190
     }
Please login to merge, or discard this patch.
htdocs/okapi/services/users/user.php 1 patch
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -33,8 +33,7 @@  discard block
 block discarded – undo
33 33
                 $tmp = OkapiServiceRunner::call('services/users/by_internal_id', new OkapiInternalRequest(
34 34
                     $request->consumer, null, array('internal_id' => $request->token->user_id, 'fields' => 'uuid')));
35 35
                 $user_uuid = $tmp['uuid'];
36
-            }
37
-            else
36
+            } else
38 37
             {
39 38
                 throw new BadRequest("You must either: 1. supply the user_uuid argument, or "
40 39
                     ."2. sign your request with an Access Token.");
@@ -49,8 +48,9 @@  discard block
 block discarded – undo
49 48
             $request->consumer, $request->token, array('user_uuids' => $user_uuid,
50 49
             'fields' => $fields)));
51 50
         $result = $results[$user_uuid];
52
-        if ($result == null)
53
-            throw new InvalidParam('user_uuid', "There is no user by this ID.");
51
+        if ($result == null) {
52
+                    throw new InvalidParam('user_uuid', "There is no user by this ID.");
53
+        }
54 54
         return Okapi::formatted_response($request, $result);
55 55
     }
56 56
 }
Please login to merge, or discard this patch.
htdocs/okapi/services/oauth/authorize.php 1 patch
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,13 +21,17 @@
 block discarded – undo
21 21
     public static function call(OkapiRequest $request)
22 22
     {
23 23
         $token_key = $request->get_parameter('oauth_token');
24
-        if (!$token_key)
25
-            throw new ParamMissing("oauth_token");
24
+        if (!$token_key) {
25
+                    throw new ParamMissing("oauth_token");
26
+        }
26 27
         $langpref = $request->get_parameter('langpref');
27 28
         $interactivity = $request->get_parameter('interactivity');
28
-        if (!$interactivity) $interactivity = 'minimal';
29
-        if (!in_array($interactivity, array('minimal', 'confirm_user')))
30
-            throw new InvalidParam('interactivity', $interactivity);
29
+        if (!$interactivity) {
30
+            $interactivity = 'minimal';
31
+        }
32
+        if (!in_array($interactivity, array('minimal', 'confirm_user'))) {
33
+                    throw new InvalidParam('interactivity', $interactivity);
34
+        }
31 35
 
32 36
         # Redirect to the "apps" folder. This is done there (not here)
33 37
         # because: 1) we don't want any cookie or session-handling
Please login to merge, or discard this patch.
htdocs/okapi/services/attrs/attribute_index.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,13 +30,19 @@
 block discarded – undo
30 30
         # Read the parameters.
31 31
 
32 32
         $langpref = $request->get_parameter('langpref');
33
-        if (!$langpref) $langpref = "en";
33
+        if (!$langpref) {
34
+            $langpref = "en";
35
+        }
34 36
 
35 37
         $fields = $request->get_parameter('fields');
36
-        if (!$fields) $fields = "name";
38
+        if (!$fields) {
39
+            $fields = "name";
40
+        }
37 41
 
38 42
         $only_locally_used = $request->get_parameter('only_locally_used');
39
-        if (!$only_locally_used) $only_locally_used = "false";
43
+        if (!$only_locally_used) {
44
+            $only_locally_used = "false";
45
+        }
40 46
         $only_locally_used = ($only_locally_used == "true");
41 47
 
42 48
         # Get the list of attributes and filter the A-codes based on the
Please login to merge, or discard this patch.
htdocs/okapi/services/attrs/attributes.php 1 patch
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -35,26 +35,36 @@  discard block
 block discarded – undo
35 35
         # Read the parameters.
36 36
 
37 37
         $acodes = $request->get_parameter('acodes');
38
-        if (!$acodes) throw new ParamMissing('acodes');
38
+        if (!$acodes) {
39
+            throw new ParamMissing('acodes');
40
+        }
39 41
         $acodes = explode("|", $acodes);
40 42
 
41 43
         $langpref = $request->get_parameter('langpref');
42
-        if (!$langpref) $langpref = "en";
44
+        if (!$langpref) {
45
+            $langpref = "en";
46
+        }
43 47
         $langpref = explode("|", $langpref);
44 48
 
45 49
         $fields = $request->get_parameter('fields');
46
-        if (!$fields) $fields = "name";
50
+        if (!$fields) {
51
+            $fields = "name";
52
+        }
47 53
         $fields = explode("|", $fields);
48 54
         foreach ($fields as $field)
49 55
         {
50
-            if (!in_array($field, self::$valid_field_names))
51
-                throw new InvalidParam('fields', "'$field' is not a valid field code.");
56
+            if (!in_array($field, self::$valid_field_names)) {
57
+                            throw new InvalidParam('fields', "'$field' is not a valid field code.");
58
+            }
52 59
         }
53 60
 
54 61
         $forward_compatible = $request->get_parameter('forward_compatible');
55
-        if (!$forward_compatible) $forward_compatible = "true";
56
-        if (!in_array($forward_compatible, array("true", "false")))
57
-            throw new InvalidParam('forward_compatible');
62
+        if (!$forward_compatible) {
63
+            $forward_compatible = "true";
64
+        }
65
+        if (!in_array($forward_compatible, array("true", "false"))) {
66
+                    throw new InvalidParam('forward_compatible');
67
+        }
58 68
         $forward_compatible = ($forward_compatible == "true");
59 69
 
60 70
         # Load the attributes (all of them).
@@ -133,8 +143,9 @@  discard block
 block discarded – undo
133 143
                 continue;
134 144
             }
135 145
             $clean_row = array();
136
-            foreach ($fields as $field)
137
-                $clean_row[$field] = $attr_ref[$field];
146
+            foreach ($fields as $field) {
147
+                            $clean_row[$field] = $attr_ref[$field];
148
+            }
138 149
             $attr_ref = $clean_row;
139 150
         }
140 151
 
Please login to merge, or discard this patch.