MDL-63690 core_privacy: Handle when add_users() receives an empty array
[moodle.git] / privacy / classes / local / request / userlist.php
index 0664f14..171ccc0 100644 (file)
@@ -80,12 +80,13 @@ class userlist extends userlist_base {
     public function add_users(array $userids) : userlist {
         global $DB;
 
-        list($useridsql, $useridparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
-        $sql = "SELECT DISTINCT u.id
-                  FROM {user} u
-                 WHERE u.id {$useridsql}";
-        $this->add_from_sql('id', $sql, $useridparams);
-
+        if (!empty($userids)) {
+            list($useridsql, $useridparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
+            $sql = "SELECT DISTINCT u.id
+                      FROM {user} u
+                     WHERE u.id {$useridsql}";
+            $this->add_from_sql('id', $sql, $useridparams);
+        }
         return $this;
     }