diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-28 20:05:18 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-28 20:05:18 -0400 |
commit | 7e3b796de82f24f91930e96866c6c5f15ec04096 (patch) | |
tree | 88e86efd48673e3fd6213642ab23dd7391bbd544 | |
parent | 5bc061923493ae3751cdfbca1ec844d25d46815c (diff) | |
download | nextcloud-server-7e3b796de82f24f91930e96866c6c5f15ec04096.tar.gz nextcloud-server-7e3b796de82f24f91930e96866c6c5f15ec04096.zip |
More elegant solution for preparing IN ?s, thanks icewind
-rw-r--r-- | apps/files_sharing/lib_share.php | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index d0d73747942..df462c699ea 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -80,18 +80,6 @@ class OC_SHARE { } /** - * Create a string of ?s based on the specified count - * @return A string to be placed inside the IN operator in a query for uid_shared_with - */ - private static function prepareIN($count) { - $questionMarks = "?"; - for($i = 1; $i < $count; $i++) { - $questionMarks .= ",?"; - } - return $questionMarks; - } - - /** * Create a new entry in the database for a file inside a shared folder * * $oldTarget and $newTarget may be the same value. $oldTarget exists in case the file is being moved outside of the folder @@ -143,7 +131,7 @@ class OC_SHARE { $folder = preg_replace('{(/)\1+}', "/", $folder); $length = strlen($folder); $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with IN(".self::prepareIN(count($userAndGroups)).")"); + $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).")"); return $query->execute(array_merge(array($length, $folder, $length, $folder), $userAndGroups))->fetchAll(); } @@ -157,7 +145,7 @@ class OC_SHARE { $target = rtrim($target, "/"); $target = preg_replace('{(/)\1+}', "/", $target); $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".self::prepareIN(count($userAndGroups)).") LIMIT 1"); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).") LIMIT 1"); // Prevent searching for user directory e.g. '/MTGap/files' $userDirectory = substr($target, 0, strpos($target, "files") + 5); while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { @@ -186,7 +174,7 @@ class OC_SHARE { $target = rtrim($target, "/"); $target = preg_replace('{(/)\1+}', "/", $target); $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".self::prepareIN(count($userAndGroups)).") LIMIT 1"); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).") LIMIT 1"); $result = $query->execute(array_merge(array($target), $userAndGroups))->fetchAll(); if (count($result) > 0) { return $result[0]['source']; @@ -207,7 +195,7 @@ class OC_SHARE { */ public static function isWriteable($target) { $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".self::prepareIN(count($userAndGroups)).") LIMIT 1"); + $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).") LIMIT 1"); $result = $query->execute(array_merge(array($target), $userAndGroups))->fetchAll(); if (count($result) > 0) { return $result[0]['is_writeable']; |