[aur-dev] [PATCH 1/3] aur.inc.php: allow all functions using DB to take handle as arg
This prevents needless calls to db_connect() if we already have a reference to a handle we can pass into a function. Although the current underlying implementation using mysql_connect() will return the same connection if all parameters are the same, this might not be true if we switch to a more modern (e.g. PDO) interface. In the face of safe transactions, it is extremely important all actions are being taken over the same connection to the database. Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/aur.inc.php | 74 +++++++++++++++++++++++++++++++++----------------- 1 files changed, 49 insertions(+), 25 deletions(-) diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 55cc8a9..0927604 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -17,7 +17,7 @@ include_once("cachefuncs.inc.php"); # see if the visitor is already logged in # -function check_sid() { +function check_sid($dbh=NULL) { global $_COOKIE; global $LOGIN_TIMEOUT; @@ -25,7 +25,9 @@ function check_sid() { $failed = 0; # the visitor is logged in, try and update the session # - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT LastUpdateTS, UNIX_TIMESTAMP() FROM Sessions "; $q.= "WHERE SessionID = '" . mysql_real_escape_string($_COOKIE["AURSID"]) . "'"; $result = db_query($q, $dbh); @@ -97,11 +99,13 @@ function new_sid() { # obtain the username if given their Users.ID # -function username_from_id($id="") { +function username_from_id($id="", $dbh=NULL) { if (!$id) { return ""; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Username FROM Users WHERE ID = " . mysql_real_escape_string($id); $result = db_query($q, $dbh); if (!$result) { @@ -115,11 +119,13 @@ function username_from_id($id="") { # obtain the username if given their current SID # -function username_from_sid($sid="") { +function username_from_sid($sid="", $dbh=NULL) { if (!$sid) { return ""; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Username "; $q.= "FROM Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -135,11 +141,13 @@ function username_from_sid($sid="") { # obtain the email address if given their current SID # -function email_from_sid($sid="") { +function email_from_sid($sid="", $dbh=NULL) { if (!$sid) { return ""; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Email "; $q.= "FROM Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -156,11 +164,13 @@ function email_from_sid($sid="") { # obtain the account type if given their current SID # Return either "", "User", "Trusted User", "Developer" # -function account_from_sid($sid="") { +function account_from_sid($sid="", $dbh=NULL) { if (!$sid) { return ""; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT AccountType "; $q.= "FROM Users, AccountTypes, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -177,11 +187,13 @@ function account_from_sid($sid="") { # obtain the Users.ID if given their current SID # -function uid_from_sid($sid="") { +function uid_from_sid($sid="", $dbh=NULL) { if (!$sid) { return ""; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Users.ID "; $q.= "FROM Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -251,7 +263,7 @@ function db_query($query="", $db_handle="") { # set up the visitor's language # -function set_lang() { +function set_lang($dbh=NULL) { global $LANG; global $SUPPORTED_LANGS; global $PERSISTENT_COOKIE_TIMEOUT; @@ -272,7 +284,9 @@ function set_lang() { } elseif (isset($_COOKIE["AURSID"])) { # No language but a session; use default lang preference # - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT LangPreference FROM Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; $q.= "AND Sessions.SessionID = '"; @@ -332,15 +346,17 @@ function html_footer($ver="") { # check to see if the user can submit a package # -function can_submit_pkg($name="", $sid="") { +function can_submit_pkg($name="", $sid="", $dbh=NULL) { if (!$name || !$sid) {return 0;} - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT MaintainerUID "; $q.= "FROM Packages WHERE Name = '".mysql_real_escape_string($name)."'"; $result = db_query($q, $dbh); if (mysql_num_rows($result) == 0) {return 1;} $row = mysql_fetch_row($result); - $my_uid = uid_from_sid($sid); + $my_uid = uid_from_sid($sid, $dbh); if ($row[0] === NULL || $row[0] == $my_uid) { return 1; @@ -401,12 +417,14 @@ function chmod_group($path) { # obtain the uid given a Users.Username # -function uid_from_username($username="") +function uid_from_username($username="", $dbh=NULL) { if (!$username) { return ""; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT ID FROM Users WHERE Username = '".mysql_real_escape_string($username) ."'"; $result = db_query($q, $dbh); @@ -420,12 +438,14 @@ function uid_from_username($username="") # obtain the uid given a Users.Email # -function uid_from_email($email="") +function uid_from_email($email="", $dbh=NULL) { if (!$email) { return ""; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT ID FROM Users WHERE Email = '".mysql_real_escape_string($email) ."'"; $result = db_query($q, $dbh); @@ -479,9 +499,11 @@ function mkurl($append) { return substr($out, 5); } -function get_salt($user_id) +function get_salt($user_id, $dbh=NULL) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $salt_q = "SELECT Salt FROM Users WHERE ID = " . $user_id; $result = db_query($salt_q, $dbh); if ($result) { @@ -491,9 +513,11 @@ function get_salt($user_id) return; } -function save_salt($user_id, $passwd) +function save_salt($user_id, $passwd, $dbh=NULL) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $salt = generate_salt(); $hash = salted_hash($passwd, $salt); $salting_q = "UPDATE Users SET Salt = '" . $salt . "', " . -- 1.7.6
Allows handle reuse if one is available. Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 164 ++++++++++++++++++++++++++++------------------ 1 files changed, 101 insertions(+), 63 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 8cd1c61..65758c8 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -4,12 +4,14 @@ include_once("config.inc.php"); # Make sure this visitor can delete the requested package comment # They can delete if they were the comment submitter, or if they are a TU/Dev # -function canDeleteComment($comment_id=0, $atype="", $uid=0) { +function canDeleteComment($comment_id=0, $atype="", $uid=0, $dbh=NULL) { if ($atype == "Trusted User" || $atype == "Developer") { # A TU/Dev can delete any comment return TRUE; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT COUNT(ID) AS CNT "; $q.= "FROM PackageComments "; $q.= "WHERE ID = " . intval($comment_id); @@ -74,9 +76,11 @@ function canSubmitBlacklisted($atype = "") { # grab the current list of PackageCategories # -function pkgCategories() { +function pkgCategories($dbh=NULL) { $cats = array(); - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT * FROM PackageCategories WHERE ID != 1 "; $q.= "ORDER BY Category ASC"; $result = db_query($q, $dbh); @@ -90,9 +94,11 @@ function pkgCategories() { # check to see if the package name exists # -function package_exists($name="") { +function package_exists($name="", $dbh=NULL) { if (!$name) {return NULL;} - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT ID FROM Packages "; $q.= "WHERE Name = '".mysql_real_escape_string($name)."' "; $result = db_query($q, $dbh); @@ -103,11 +109,13 @@ function package_exists($name="") { # grab package dependencies # -function package_dependencies($pkgid=0) { +function package_dependencies($pkgid, $dbh=NULL) { $deps = array(); $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT pd.DepName, pd.DepCondition, p.ID FROM PackageDepends pd "; $q.= "LEFT JOIN Packages p ON pd.DepName = p.Name "; $q.= "WHERE pd.PackageID = ". $pkgid . " "; @@ -121,10 +129,12 @@ function package_dependencies($pkgid=0) { return $deps; } -function package_required($name="") { +function package_required($name="", $dbh=NULL) { $deps = array(); if ($name != "") { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT p.Name, PackageID FROM PackageDepends pd "; $q.= "JOIN Packages p ON pd.PackageID = p.ID "; $q.= "WHERE DepName = '".mysql_real_escape_string($name)."' "; @@ -139,10 +149,12 @@ function package_required($name="") { } # Return the number of comments for a specified package -function package_comments_count($pkgid = 0) { +function package_comments_count($pkgid, $dbh=NULL) { $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT COUNT(*) FROM PackageComments "; $q.= "WHERE PackageID = " . $pkgid; $q.= " AND DelUsersID IS NULL"; @@ -157,11 +169,13 @@ function package_comments_count($pkgid = 0) { } # Return an array of package comments -function package_comments($pkgid = 0) { +function package_comments($pkgid, $dbh=NULL) { $comments = array(); $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT PackageComments.ID, UserName, UsersID, Comments, CommentTS "; $q.= "FROM PackageComments, Users "; $q.= "WHERE PackageComments.UsersID = Users.ID"; @@ -188,11 +202,13 @@ function package_comments($pkgid = 0) { # grab package sources # -function package_sources($pkgid=0) { +function package_sources($pkgid, $dbh=NULL) { $sources = array(); $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Source FROM PackageSources "; $q.= "WHERE PackageID = " . $pkgid; $q.= " ORDER BY Source"; @@ -208,10 +224,12 @@ function package_sources($pkgid=0) { # grab array of Package.IDs that I've voted for: $pkgs[1234] = 1, ... # -function pkgvotes_from_sid($sid="") { +function pkgvotes_from_sid($sid="", $dbh=NULL) { $pkgs = array(); if (!$sid) {return $pkgs;} - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT PackageID "; $q.= "FROM PackageVotes, Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -229,10 +247,12 @@ function pkgvotes_from_sid($sid="") { # array of package ids that you're being notified for # *yoink* # -function pkgnotify_from_sid($sid="") { +function pkgnotify_from_sid($sid="", $dbh=NULL) { $pkgs = array(); if (!$sid) {return $pkgs;} - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT PkgID "; $q.= "FROM CommentNotify, Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -249,11 +269,13 @@ function pkgnotify_from_sid($sid="") { # get name of package based on pkgid # -function pkgname_from_id($pkgid=0) { +function pkgname_from_id($pkgid, $dbh=NULL) { $pkgid = intval($pkgid); $name = ""; if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Name FROM Packages WHERE ID = " . $pkgid; $result = db_query($q, $dbh); if (mysql_num_rows($result) > 0) { @@ -265,8 +287,10 @@ function pkgname_from_id($pkgid=0) { # Check if a package name is blacklisted. # -function pkgname_is_blacklisted($name) { - $dbh = db_connect(); +function pkgname_is_blacklisted($name, $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT COUNT(*) FROM PackageBlacklist WHERE Name = '" . mysql_real_escape_string($name) . "'"; $result = db_query($q, $dbh); @@ -276,15 +300,15 @@ function pkgname_is_blacklisted($name) { # display package details # -function package_details($id=0, $SID="") { - $atype = account_from_sid($SID); - $uid = uid_from_sid($SID); +function package_details($id=0, $SID="", $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Packages.*,Category "; $q.= "FROM Packages,PackageCategories "; $q.= "WHERE Packages.CategoryID = PackageCategories.ID "; $q.= "AND Packages.ID = " . intval($id); - $dbh = db_connect(); $results = db_query($q, $dbh); if (!$results) { @@ -306,7 +330,7 @@ function package_details($id=0, $SID="") { } # Print Comments - $comments = package_comments($id); + $comments = package_comments($id, $dbh); if (!empty($comments)) { include('pkg_comments.php'); } @@ -360,17 +384,18 @@ function package_details($id=0, $SID="") { * do_Notify - Enable notification * do_UnNotify - Disable notification */ -function pkg_search_page($SID="") { - // establish a db connection - $dbh = db_connect(); +function pkg_search_page($SID="", $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } // get commonly used variables... // TODO: REDUCE DB HITS. // grab info for user if they're logged in if ($SID) - $myuid = uid_from_sid($SID); + $myuid = uid_from_sid($SID, $dbh); // get a list of package categories - $cats = pkgCategories(); //meow + $cats = pkgCategories($dbh); //meow // sanitize paging variables // @@ -440,7 +465,7 @@ function pkg_search_page($SID="") { } # Search by submitter elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") { - $q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'])." "; + $q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'], $dbh)." "; } # Search by name elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") { @@ -594,7 +619,7 @@ function sanitize_ids($ids) { * * @return string Translated success or error messages */ -function pkg_flag ($atype, $ids, $action = True) { +function pkg_flag ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can flag packages."); @@ -612,7 +637,9 @@ function pkg_flag ($atype, $ids, $action = True) { } } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "UPDATE Packages SET"; if ($action) { @@ -627,9 +654,9 @@ function pkg_flag ($atype, $ids, $action = True) { if ($action) { # Notify of flagging by email - $f_name = username_from_sid($_COOKIE['AURSID']); - $f_email = email_from_sid($_COOKIE['AURSID']); - $f_uid = uid_from_sid($_COOKIE['AURSID']); + $f_name = username_from_sid($_COOKIE['AURSID'], $dbh); + $f_email = email_from_sid($_COOKIE['AURSID'], $dbh); + $f_uid = uid_from_sid($_COOKIE['AURSID'], $dbh); $q = "SELECT Packages.Name, Users.Email, Packages.ID "; $q.= "FROM Packages, Users "; $q.= "WHERE Packages.ID IN (" . implode(",", $ids) .") "; @@ -662,7 +689,7 @@ function pkg_flag ($atype, $ids, $action = True) { * * @return string Translated error or success message */ -function pkg_delete ($atype, $ids) { +function pkg_delete ($atype, $ids, $dbh=NULL) { if (!$atype) { return __("You must be logged in before you can delete packages."); } @@ -677,7 +704,9 @@ function pkg_delete ($atype, $ids) { return __("You did not select any packages to delete."); } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "DELETE FROM Packages WHERE ID IN (" . implode(",", $ids) . ")"; $result = db_query($q, $dbh); @@ -693,7 +722,7 @@ function pkg_delete ($atype, $ids) { * * @return string Translated error or success message */ -function pkg_adopt ($atype, $ids, $action = True) { +function pkg_adopt ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can adopt packages."); @@ -711,13 +740,15 @@ function pkg_adopt ($atype, $ids, $action = True) { } } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $field = "MaintainerUID"; $q = "UPDATE Packages "; if ($action) { - $user = uid_from_sid($_COOKIE["AURSID"]); + $user = uid_from_sid($_COOKIE["AURSID"], $dbh); } else { $user = 'NULL'; } @@ -729,13 +760,13 @@ function pkg_adopt ($atype, $ids, $action = True) { # Regular users may only adopt orphan packages from unsupported $q.= "AND $field IS NULL "; } else if ($atype == "User") { - $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]); + $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"], $dbh); } db_query($q, $dbh); if ($action) { - pkg_notify(account_from_sid($_COOKIE["AURSID"]), $ids); + pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), $ids, $dbh); return __("The selected packages have been adopted."); } else { return __("The selected packages have been disowned."); @@ -751,7 +782,7 @@ function pkg_adopt ($atype, $ids, $action = True) { * * @return string Translated error or success message */ -function pkg_vote ($atype, $ids, $action = True) { +function pkg_vote ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can vote for packages."); @@ -769,9 +800,11 @@ function pkg_vote ($atype, $ids, $action = True) { } } - $dbh = db_connect(); - $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); - $uid = uid_from_sid($_COOKIE["AURSID"]); + if(!$dbh) { + $dbh = db_connect(); + } + $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"], $dbh); + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh); $first = 1; foreach ($ids as $pid) { @@ -836,7 +869,7 @@ function pkg_vote ($atype, $ids, $action = True) { * @param array $ids Array of package IDs to toggle, formatted as $package_id * @return string Translated error or success message */ -function pkg_notify ($atype, $ids, $action = True) { +function pkg_notify ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { # return __("You must be logged in before you can get notifications on comments."); return; @@ -847,8 +880,10 @@ function pkg_notify ($atype, $ids, $action = True) { return __("Couldn't add to notification list."); } - $dbh = db_connect(); - $uid = uid_from_sid($_COOKIE["AURSID"]); + if(!$dbh) { + $dbh = db_connect(); + } + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh); $output = ""; @@ -912,7 +947,7 @@ function pkg_notify ($atype, $ids, $action = True) { * @param string $atype Account type, output of account_from_sid * @return string Translated error or success message */ -function pkg_delete_comment($atype) { +function pkg_delete_comment($atype, $dbh=NULL) { if (!$atype) { return __("You must be logged in before you can edit package information."); } @@ -924,10 +959,11 @@ function pkg_delete_comment($atype) { return __("Missing comment ID."); } - $uid = uid_from_sid($_COOKIE["AURSID"]); - if (canDeleteComment($comment_id, $atype, $uid)) { - - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh); + if (canDeleteComment($comment_id, $atype, $uid, $dbh)) { $q = "UPDATE PackageComments "; $q.= "SET DelUsersID = ".$uid." "; $q.= "WHERE ID = ".intval($comment_id); @@ -944,7 +980,7 @@ function pkg_delete_comment($atype) { * @param string $atype Account type, output of account_from_sid * @return string Translated error or success message */ -function pkg_change_category($atype) { +function pkg_change_category($atype, $dbh=NULL) { if (!$atype) { return __("You must be logged in before you can edit package information."); } @@ -956,7 +992,10 @@ function pkg_change_category($atype) { return __("Missing category ID."); } - $catArray = pkgCategories(); + if(!$dbh) { + $dbh = db_connect(); + } + $catArray = pkgCategories($dbh); if (!array_key_exists($category_id, $catArray)) { return __("Invalid category ID."); } @@ -968,7 +1007,6 @@ function pkg_change_category($atype) { } # Verify package ownership - $dbh = db_connect(); $q = "SELECT Packages.MaintainerUID "; $q.= "FROM Packages "; $q.= "WHERE Packages.ID = ".$pid; @@ -980,7 +1018,7 @@ function pkg_change_category($atype) { return __("You are not allowed to change this package category."); } - $uid = uid_from_sid($_COOKIE["AURSID"]); + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh); if ($uid == $pkg["MaintainerUID"] or ($atype == "Developer" or $atype == "Trusted User")) { $q = "UPDATE Packages "; -- 1.7.6
On Wed, Aug 10, 2011 at 06:20:06PM -0500, Dan McGee wrote:
Allows handle reuse if one is available.
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 164 ++++++++++++++++++++++++++++------------------ 1 files changed, 101 insertions(+), 63 deletions(-)
This one looks good to me, except for two lines you probably removed unintentionally (see below). This also needs to be rebased on the package merging patches in my working tree. I fixed the missing lines issue and pushed a rebased version of this patch to my working branch.
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 8cd1c61..65758c8 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -4,12 +4,14 @@ include_once("config.inc.php"); # Make sure this visitor can delete the requested package comment # They can delete if they were the comment submitter, or if they are a TU/Dev # -function canDeleteComment($comment_id=0, $atype="", $uid=0) { +function canDeleteComment($comment_id=0, $atype="", $uid=0, $dbh=NULL) { if ($atype == "Trusted User" || $atype == "Developer") { # A TU/Dev can delete any comment return TRUE; } - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT COUNT(ID) AS CNT "; $q.= "FROM PackageComments "; $q.= "WHERE ID = " . intval($comment_id); @@ -74,9 +76,11 @@ function canSubmitBlacklisted($atype = "") {
# grab the current list of PackageCategories # -function pkgCategories() { +function pkgCategories($dbh=NULL) { $cats = array(); - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT * FROM PackageCategories WHERE ID != 1 "; $q.= "ORDER BY Category ASC"; $result = db_query($q, $dbh); @@ -90,9 +94,11 @@ function pkgCategories() {
# check to see if the package name exists # -function package_exists($name="") { +function package_exists($name="", $dbh=NULL) { if (!$name) {return NULL;} - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT ID FROM Packages "; $q.= "WHERE Name = '".mysql_real_escape_string($name)."' "; $result = db_query($q, $dbh); @@ -103,11 +109,13 @@ function package_exists($name="") {
# grab package dependencies # -function package_dependencies($pkgid=0) { +function package_dependencies($pkgid, $dbh=NULL) { $deps = array(); $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT pd.DepName, pd.DepCondition, p.ID FROM PackageDepends pd "; $q.= "LEFT JOIN Packages p ON pd.DepName = p.Name "; $q.= "WHERE pd.PackageID = ". $pkgid . " "; @@ -121,10 +129,12 @@ function package_dependencies($pkgid=0) { return $deps; }
-function package_required($name="") { +function package_required($name="", $dbh=NULL) { $deps = array(); if ($name != "") { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT p.Name, PackageID FROM PackageDepends pd "; $q.= "JOIN Packages p ON pd.PackageID = p.ID "; $q.= "WHERE DepName = '".mysql_real_escape_string($name)."' "; @@ -139,10 +149,12 @@ function package_required($name="") { }
# Return the number of comments for a specified package -function package_comments_count($pkgid = 0) { +function package_comments_count($pkgid, $dbh=NULL) { $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT COUNT(*) FROM PackageComments "; $q.= "WHERE PackageID = " . $pkgid; $q.= " AND DelUsersID IS NULL"; @@ -157,11 +169,13 @@ function package_comments_count($pkgid = 0) { }
# Return an array of package comments -function package_comments($pkgid = 0) { +function package_comments($pkgid, $dbh=NULL) { $comments = array(); $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT PackageComments.ID, UserName, UsersID, Comments, CommentTS "; $q.= "FROM PackageComments, Users "; $q.= "WHERE PackageComments.UsersID = Users.ID"; @@ -188,11 +202,13 @@ function package_comments($pkgid = 0) {
# grab package sources # -function package_sources($pkgid=0) { +function package_sources($pkgid, $dbh=NULL) { $sources = array(); $pkgid = intval($pkgid); if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Source FROM PackageSources "; $q.= "WHERE PackageID = " . $pkgid; $q.= " ORDER BY Source"; @@ -208,10 +224,12 @@ function package_sources($pkgid=0) {
# grab array of Package.IDs that I've voted for: $pkgs[1234] = 1, ... # -function pkgvotes_from_sid($sid="") { +function pkgvotes_from_sid($sid="", $dbh=NULL) { $pkgs = array(); if (!$sid) {return $pkgs;} - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT PackageID "; $q.= "FROM PackageVotes, Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -229,10 +247,12 @@ function pkgvotes_from_sid($sid="") { # array of package ids that you're being notified for # *yoink* # -function pkgnotify_from_sid($sid="") { +function pkgnotify_from_sid($sid="", $dbh=NULL) { $pkgs = array(); if (!$sid) {return $pkgs;} - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT PkgID "; $q.= "FROM CommentNotify, Users, Sessions "; $q.= "WHERE Users.ID = Sessions.UsersID "; @@ -249,11 +269,13 @@ function pkgnotify_from_sid($sid="") {
# get name of package based on pkgid # -function pkgname_from_id($pkgid=0) { +function pkgname_from_id($pkgid, $dbh=NULL) { $pkgid = intval($pkgid); $name = ""; if ($pkgid > 0) { - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT Name FROM Packages WHERE ID = " . $pkgid; $result = db_query($q, $dbh); if (mysql_num_rows($result) > 0) { @@ -265,8 +287,10 @@ function pkgname_from_id($pkgid=0) {
# Check if a package name is blacklisted. # -function pkgname_is_blacklisted($name) { - $dbh = db_connect(); +function pkgname_is_blacklisted($name, $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } $q = "SELECT COUNT(*) FROM PackageBlacklist WHERE Name = '" . mysql_real_escape_string($name) . "'"; $result = db_query($q, $dbh);
@@ -276,15 +300,15 @@ function pkgname_is_blacklisted($name) {
# display package details # -function package_details($id=0, $SID="") { - $atype = account_from_sid($SID); - $uid = uid_from_sid($SID);
These two lines shouldn't be removed.
+function package_details($id=0, $SID="", $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + }
$q = "SELECT Packages.*,Category "; $q.= "FROM Packages,PackageCategories "; $q.= "WHERE Packages.CategoryID = PackageCategories.ID "; $q.= "AND Packages.ID = " . intval($id); - $dbh = db_connect(); $results = db_query($q, $dbh);
if (!$results) { @@ -306,7 +330,7 @@ function package_details($id=0, $SID="") { }
# Print Comments - $comments = package_comments($id); + $comments = package_comments($id, $dbh); if (!empty($comments)) { include('pkg_comments.php'); } @@ -360,17 +384,18 @@ function package_details($id=0, $SID="") { * do_Notify - Enable notification * do_UnNotify - Disable notification */ -function pkg_search_page($SID="") { - // establish a db connection - $dbh = db_connect(); +function pkg_search_page($SID="", $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + }
// get commonly used variables... // TODO: REDUCE DB HITS. // grab info for user if they're logged in if ($SID) - $myuid = uid_from_sid($SID); + $myuid = uid_from_sid($SID, $dbh); // get a list of package categories - $cats = pkgCategories(); //meow + $cats = pkgCategories($dbh); //meow
// sanitize paging variables // @@ -440,7 +465,7 @@ function pkg_search_page($SID="") { } # Search by submitter elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") { - $q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'])." "; + $q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'], $dbh)." "; } # Search by name elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") { @@ -594,7 +619,7 @@ function sanitize_ids($ids) { * * @return string Translated success or error messages */ -function pkg_flag ($atype, $ids, $action = True) { +function pkg_flag ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can flag packages."); @@ -612,7 +637,9 @@ function pkg_flag ($atype, $ids, $action = True) { } }
- $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + }
$q = "UPDATE Packages SET"; if ($action) { @@ -627,9 +654,9 @@ function pkg_flag ($atype, $ids, $action = True) {
if ($action) { # Notify of flagging by email - $f_name = username_from_sid($_COOKIE['AURSID']); - $f_email = email_from_sid($_COOKIE['AURSID']); - $f_uid = uid_from_sid($_COOKIE['AURSID']); + $f_name = username_from_sid($_COOKIE['AURSID'], $dbh); + $f_email = email_from_sid($_COOKIE['AURSID'], $dbh); + $f_uid = uid_from_sid($_COOKIE['AURSID'], $dbh); $q = "SELECT Packages.Name, Users.Email, Packages.ID "; $q.= "FROM Packages, Users "; $q.= "WHERE Packages.ID IN (" . implode(",", $ids) .") "; @@ -662,7 +689,7 @@ function pkg_flag ($atype, $ids, $action = True) { * * @return string Translated error or success message */ -function pkg_delete ($atype, $ids) { +function pkg_delete ($atype, $ids, $dbh=NULL) { if (!$atype) { return __("You must be logged in before you can delete packages."); } @@ -677,7 +704,9 @@ function pkg_delete ($atype, $ids) { return __("You did not select any packages to delete."); }
- $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } $q = "DELETE FROM Packages WHERE ID IN (" . implode(",", $ids) . ")"; $result = db_query($q, $dbh);
@@ -693,7 +722,7 @@ function pkg_delete ($atype, $ids) { * * @return string Translated error or success message */ -function pkg_adopt ($atype, $ids, $action = True) { +function pkg_adopt ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can adopt packages."); @@ -711,13 +740,15 @@ function pkg_adopt ($atype, $ids, $action = True) { } }
- $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + }
$field = "MaintainerUID"; $q = "UPDATE Packages ";
if ($action) { - $user = uid_from_sid($_COOKIE["AURSID"]); + $user = uid_from_sid($_COOKIE["AURSID"], $dbh); } else { $user = 'NULL'; } @@ -729,13 +760,13 @@ function pkg_adopt ($atype, $ids, $action = True) { # Regular users may only adopt orphan packages from unsupported $q.= "AND $field IS NULL "; } else if ($atype == "User") { - $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]); + $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"], $dbh); }
db_query($q, $dbh);
if ($action) { - pkg_notify(account_from_sid($_COOKIE["AURSID"]), $ids); + pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), $ids, $dbh); return __("The selected packages have been adopted."); } else { return __("The selected packages have been disowned."); @@ -751,7 +782,7 @@ function pkg_adopt ($atype, $ids, $action = True) { * * @return string Translated error or success message */ -function pkg_vote ($atype, $ids, $action = True) { +function pkg_vote ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can vote for packages."); @@ -769,9 +800,11 @@ function pkg_vote ($atype, $ids, $action = True) { } }
- $dbh = db_connect(); - $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); - $uid = uid_from_sid($_COOKIE["AURSID"]); + if(!$dbh) { + $dbh = db_connect(); + } + $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"], $dbh); + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
$first = 1; foreach ($ids as $pid) { @@ -836,7 +869,7 @@ function pkg_vote ($atype, $ids, $action = True) { * @param array $ids Array of package IDs to toggle, formatted as $package_id * @return string Translated error or success message */ -function pkg_notify ($atype, $ids, $action = True) { +function pkg_notify ($atype, $ids, $action=True, $dbh=NULL) { if (!$atype) { # return __("You must be logged in before you can get notifications on comments."); return; @@ -847,8 +880,10 @@ function pkg_notify ($atype, $ids, $action = True) { return __("Couldn't add to notification list."); }
- $dbh = db_connect(); - $uid = uid_from_sid($_COOKIE["AURSID"]); + if(!$dbh) { + $dbh = db_connect(); + } + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
$output = "";
@@ -912,7 +947,7 @@ function pkg_notify ($atype, $ids, $action = True) { * @param string $atype Account type, output of account_from_sid * @return string Translated error or success message */ -function pkg_delete_comment($atype) { +function pkg_delete_comment($atype, $dbh=NULL) { if (!$atype) { return __("You must be logged in before you can edit package information."); } @@ -924,10 +959,11 @@ function pkg_delete_comment($atype) { return __("Missing comment ID."); }
- $uid = uid_from_sid($_COOKIE["AURSID"]); - if (canDeleteComment($comment_id, $atype, $uid)) { - - $dbh = db_connect(); + if(!$dbh) { + $dbh = db_connect(); + } + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh); + if (canDeleteComment($comment_id, $atype, $uid, $dbh)) { $q = "UPDATE PackageComments "; $q.= "SET DelUsersID = ".$uid." "; $q.= "WHERE ID = ".intval($comment_id); @@ -944,7 +980,7 @@ function pkg_delete_comment($atype) { * @param string $atype Account type, output of account_from_sid * @return string Translated error or success message */ -function pkg_change_category($atype) { +function pkg_change_category($atype, $dbh=NULL) { if (!$atype) { return __("You must be logged in before you can edit package information."); } @@ -956,7 +992,10 @@ function pkg_change_category($atype) { return __("Missing category ID."); }
- $catArray = pkgCategories(); + if(!$dbh) { + $dbh = db_connect(); + } + $catArray = pkgCategories($dbh); if (!array_key_exists($category_id, $catArray)) { return __("Invalid category ID."); } @@ -968,7 +1007,6 @@ function pkg_change_category($atype) { }
# Verify package ownership - $dbh = db_connect(); $q = "SELECT Packages.MaintainerUID "; $q.= "FROM Packages "; $q.= "WHERE Packages.ID = ".$pid; @@ -980,7 +1018,7 @@ function pkg_change_category($atype) { return __("You are not allowed to change this package category."); }
- $uid = uid_from_sid($_COOKIE["AURSID"]); + $uid = uid_from_sid($_COOKIE["AURSID"], $dbh); if ($uid == $pkg["MaintainerUID"] or ($atype == "Developer" or $atype == "Trusted User")) { $q = "UPDATE Packages "; -- 1.7.6
On Thu, Aug 11, 2011 at 8:24 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Wed, Aug 10, 2011 at 06:20:06PM -0500, Dan McGee wrote:
Allows handle reuse if one is available.
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 164 ++++++++++++++++++++++++++++------------------ 1 files changed, 101 insertions(+), 63 deletions(-)
This one looks good to me, except for two lines you probably removed unintentionally (see below). This also needs to be rebased on the package merging patches in my working tree. I fixed the missing lines issue and pushed a rebased version of this patch to my working branch. I see and updated lukas/wip but not lukas/working, is that what you meant?
@@ -276,15 +300,15 @@ function pkgname_is_blacklisted($name) {
# display package details # -function package_details($id=0, $SID="") { - $atype = account_from_sid($SID); - $uid = uid_from_sid($SID);
These two lines shouldn't be removed.
I'll make it more clear and increase my patch count, but they most definitely should and it wasn't unintentional at all. It also removes two completely useless queries for every single package load (actually 4 total if I interpreted the code right when writing this patch, but that is a different story). Find where these variables are used and I'll buy you a beer. Anyway, split into two patches, based on master, on my working branch. If you want rebased patches, then push the work you want it based on to master please- it isn't fun to aim at moving targets, which is what I consider any other working branch. -Dan
These were never used in the function, causing at least two totally unnecessary queries, and potentially two more as each retrieved a DB handle and would execute the 'SET NAMES...' bit in there. Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index ca6a0f9..65758c8 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -301,9 +301,6 @@ function pkgname_is_blacklisted($name, $dbh=NULL) { # display package details # function package_details($id=0, $SID="", $dbh=NULL) { - $atype = account_from_sid($SID); - $uid = uid_from_sid($SID); - if(!$dbh) { $dbh = db_connect(); } -- 1.7.6
On Thu, Aug 11, 2011 at 08:42:34AM -0500, Dan McGee wrote:
On Thu, Aug 11, 2011 at 8:24 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Wed, Aug 10, 2011 at 06:20:06PM -0500, Dan McGee wrote:
Allows handle reuse if one is available.
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 164 ++++++++++++++++++++++++++++------------------ 1 files changed, 101 insertions(+), 63 deletions(-)
This one looks good to me, except for two lines you probably removed unintentionally (see below). This also needs to be rebased on the package merging patches in my working tree. I fixed the missing lines issue and pushed a rebased version of this patch to my working branch. I see and updated lukas/wip but not lukas/working, is that what you meant?
@@ -276,15 +300,15 @@ function pkgname_is_blacklisted($name) {
# display package details # -function package_details($id=0, $SID="") { - $atype = account_from_sid($SID); - $uid = uid_from_sid($SID);
These two lines shouldn't be removed.
I'll make it more clear and increase my patch count, but they most definitely should and it wasn't unintentional at all. It also removes two completely useless queries for every single package load (actually 4 total if I interpreted the code right when writing this patch, but that is a different story). Find where these variables are used and I'll buy you a beer.
Apply that patch, go to any package details page and you won't be able to vote, enable notifications, ... ---- Notice: Undefined variable: uid in /srv/http/aur/web/template/pkg_details.php on line 4 Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 5 Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 5 Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 50 Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 50 ---- Can I choose any beer I want? :)
Anyway, split into two patches, based on master, on my working branch. If you want rebased patches, then push the work you want it based on to master please- it isn't fun to aim at moving targets, which is what I consider any other working branch.
Those patches are still being discussed on the ML. I will push them as soon as there are no more objections.
On Thu, Aug 11, 2011 at 8:53 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Thu, Aug 11, 2011 at 08:42:34AM -0500, Dan McGee wrote:
On Thu, Aug 11, 2011 at 8:24 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Wed, Aug 10, 2011 at 06:20:06PM -0500, Dan McGee wrote:
Allows handle reuse if one is available.
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 164 ++++++++++++++++++++++++++++------------------ 1 files changed, 101 insertions(+), 63 deletions(-)
This one looks good to me, except for two lines you probably removed unintentionally (see below). This also needs to be rebased on the package merging patches in my working tree. I fixed the missing lines issue and pushed a rebased version of this patch to my working branch. I see and updated lukas/wip but not lukas/working, is that what you meant?
@@ -276,15 +300,15 @@ function pkgname_is_blacklisted($name) {
# display package details # -function package_details($id=0, $SID="") { - $atype = account_from_sid($SID); - $uid = uid_from_sid($SID);
These two lines shouldn't be removed.
I'll make it more clear and increase my patch count, but they most definitely should and it wasn't unintentional at all. It also removes two completely useless queries for every single package load (actually 4 total if I interpreted the code right when writing this patch, but that is a different story). Find where these variables are used and I'll buy you a beer.
Apply that patch, go to any package details page and you won't be able to vote, enable notifications, ...
Ew. Why isn't this being done in the template itself, just as we don't pass along magic submitter, maintainer, updated_time, etc. magic variables that just have to be defined?
---- Notice: Undefined variable: uid in /srv/http/aur/web/template/pkg_details.php on line 4
Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 5
Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 5
Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 50
Notice: Undefined variable: atype in /srv/http/aur/web/template/pkg_details.php on line 50 ----
Can I choose any beer I want? :) Next time I see you, first round on me of anything you choose.
Anyway, split into two patches, based on master, on my working branch. If you want rebased patches, then push the work you want it based on to master please- it isn't fun to aim at moving targets, which is what I consider any other working branch.
Those patches are still being discussed on the ML. I will push them as soon as there are no more objections.
These were never used in the function. Where they are used is in the pkg_details.php template, so move them closer to their actual usage so as not to confuse poor programmers such as myself. Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 3 --- web/template/pkg_details.php | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 6e86470..4243991 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -301,9 +301,6 @@ function pkgname_is_blacklisted($name, $dbh=NULL) { # display package details # function package_details($id=0, $SID="", $dbh=NULL) { - $atype = account_from_sid($SID); - $uid = uid_from_sid($SID); - if(!$dbh) { $dbh = db_connect(); } diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 5239123..c03493d 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -1,4 +1,6 @@ <?php +$atype = account_from_sid($SID); +$uid = uid_from_sid($SID); $pkgid = intval($_REQUEST['ID']); if ($uid == $row["MaintainerUID"] or -- 1.7.6
On Thu, Aug 11, 2011 at 09:04:01AM -0500, Dan McGee wrote:
These were never used in the function. Where they are used is in the pkg_details.php template, so move them closer to their actual usage so as not to confuse poor programmers such as myself.
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/lib/pkgfuncs.inc.php | 3 --- web/template/pkg_details.php | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-)
Applied, thanks.
Add BEGIN and COMMIT statements where it makes sense to do so. This allows the entire package creation or update process to be atomic and not be seen until it is complete. Signed-off-by: Dan McGee <dan@archlinux.org> --- web/html/pkgsubmit.php | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index 6d1b11f..2aa5df2 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -299,6 +299,7 @@ if ($uid): if (!$error) { $dbh = db_connect(); + db_query("BEGIN", $dbh); $q = "SELECT * FROM Packages WHERE Name = '" . mysql_real_escape_string($new_pkgbuild['pkgname']) . "'"; $result = db_query($q, $dbh); @@ -391,9 +392,12 @@ if ($uid): # If we just created this package, or it was an orphan and we # auto-adopted, add submitting user to the notification list. if (!$pdata || $pdata["MaintainerUID"] === NULL) { - pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($packageID)); + pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), array($packageID), True, $dbh); } + # Entire package creation process is atomic + db_query("COMMIT", $dbh); + header('Location: packages.php?ID=' . $packageID); } -- 1.7.6
On Wed, Aug 10, 2011 at 06:20:07PM -0500, Dan McGee wrote:
Add BEGIN and COMMIT statements where it makes sense to do so. This allows the entire package creation or update process to be atomic and not be seen until it is complete.
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/html/pkgsubmit.php | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index 6d1b11f..2aa5df2 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -299,6 +299,7 @@ if ($uid): if (!$error) {
$dbh = db_connect(); + db_query("BEGIN", $dbh);
$q = "SELECT * FROM Packages WHERE Name = '" . mysql_real_escape_string($new_pkgbuild['pkgname']) . "'"; $result = db_query($q, $dbh); @@ -391,9 +392,12 @@ if ($uid): # If we just created this package, or it was an orphan and we # auto-adopted, add submitting user to the notification list. if (!$pdata || $pdata["MaintainerUID"] === NULL) { - pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($packageID)); + pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), array($packageID), True, $dbh);
Changed "True" to "true". Sorry for being pedantic but we always use lowercase here :)
}
+ # Entire package creation process is atomic + db_query("COMMIT", $dbh); + header('Location: packages.php?ID=' . $packageID); }
-- 1.7.6
On Thu, Aug 11, 2011 at 8:38 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Wed, Aug 10, 2011 at 06:20:07PM -0500, Dan McGee wrote:
Add BEGIN and COMMIT statements where it makes sense to do so. This allows the entire package creation or update process to be atomic and not be seen until it is complete.
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/html/pkgsubmit.php | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index 6d1b11f..2aa5df2 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -299,6 +299,7 @@ if ($uid): if (!$error) {
$dbh = db_connect(); + db_query("BEGIN", $dbh);
$q = "SELECT * FROM Packages WHERE Name = '" . mysql_real_escape_string($new_pkgbuild['pkgname']) . "'"; $result = db_query($q, $dbh); @@ -391,9 +392,12 @@ if ($uid): # If we just created this package, or it was an orphan and we # auto-adopted, add submitting user to the notification list. if (!$pdata || $pdata["MaintainerUID"] === NULL) { - pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($packageID)); + pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), array($packageID), True, $dbh);
Changed "True" to "true". Sorry for being pedantic but we always use lowercase here :)
Ack. I was working in pkgfuncs where you do not. It seems to be a coding style per file around here... $ git grep 'True' | cat web/html/packages.php: $output = pkg_flag($atype, $ids, True); web/html/packages.php: $output = pkg_adopt($atype, $ids, True); web/html/packages.php: $output = pkg_vote($atype, $ids, True); web/html/pkgsubmit.php: pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), array($packageID), True, $dbh); web/lib/pkgfuncs.inc.php: * @param boolean $action True flags out-of-date, false un-flags. Flags by web/lib/pkgfuncs.inc.php:function pkg_flag ($atype, $ids, $action=True, $dbh=NULL) { web/lib/pkgfuncs.inc.php:function pkg_adopt ($atype, $ids, $action=True, $dbh=NULL) { web/lib/pkgfuncs.inc.php:function pkg_vote ($atype, $ids, $action=True, $dbh=NULL) { web/lib/pkgfuncs.inc.php:function pkg_notify ($atype, $ids, $action=True, $dbh=NULL) { web/lib/pkgfuncs.inc.php: $first = True; -Dan
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/html/packages.php | 6 +++--- web/lib/pkgfuncs.inc.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/web/html/packages.php b/web/html/packages.php index 4a1fa88..16ec45f 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -37,15 +37,15 @@ if (isset($_POST['IDs'])) { # Determine what action to do $output = ""; if (current_action("do_Flag")) { - $output = pkg_flag($atype, $ids, True); + $output = pkg_flag($atype, $ids, true); } elseif (current_action("do_UnFlag")) { $output = pkg_flag($atype, $ids, False); } elseif (current_action("do_Adopt")) { - $output = pkg_adopt($atype, $ids, True); + $output = pkg_adopt($atype, $ids, true); } elseif (current_action("do_Disown")) { $output = pkg_adopt($atype, $ids, False); } elseif (current_action("do_Vote")) { - $output = pkg_vote($atype, $ids, True); + $output = pkg_vote($atype, $ids, true); } elseif (current_action("do_UnVote")) { $output = pkg_vote($atype, $ids, False); } elseif (current_action("do_Delete")) { diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 65758c8..4243991 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -614,12 +614,12 @@ function sanitize_ids($ids) { * * @param string $atype Account type, output of account_from_sid * @param array $ids Array of package IDs to flag/unflag - * @param boolean $action True flags out-of-date, false un-flags. Flags by + * @param boolean $action true flags out-of-date, false un-flags. Flags by * default * * @return string Translated success or error messages */ -function pkg_flag ($atype, $ids, $action=True, $dbh=NULL) { +function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can flag packages."); @@ -722,7 +722,7 @@ function pkg_delete ($atype, $ids, $dbh=NULL) { * * @return string Translated error or success message */ -function pkg_adopt ($atype, $ids, $action=True, $dbh=NULL) { +function pkg_adopt ($atype, $ids, $action=true, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can adopt packages."); @@ -782,7 +782,7 @@ function pkg_adopt ($atype, $ids, $action=True, $dbh=NULL) { * * @return string Translated error or success message */ -function pkg_vote ($atype, $ids, $action=True, $dbh=NULL) { +function pkg_vote ($atype, $ids, $action=true, $dbh=NULL) { if (!$atype) { if ($action) { return __("You must be logged in before you can vote for packages."); @@ -869,7 +869,7 @@ function pkg_vote ($atype, $ids, $action=True, $dbh=NULL) { * @param array $ids Array of package IDs to toggle, formatted as $package_id * @return string Translated error or success message */ -function pkg_notify ($atype, $ids, $action=True, $dbh=NULL) { +function pkg_notify ($atype, $ids, $action=true, $dbh=NULL) { if (!$atype) { # return __("You must be logged in before you can get notifications on comments."); return; @@ -887,7 +887,7 @@ function pkg_notify ($atype, $ids, $action=True, $dbh=NULL) { $output = ""; - $first = True; + $first = true; # There currently shouldn't be multiple requests here, but the # format in which it's sent requires this. -- 1.7.6
On Thu, Aug 11, 2011 at 08:45:31AM -0500, Dan McGee wrote:
Signed-off-by: Dan McGee <dan@archlinux.org> --- web/html/packages.php | 6 +++--- web/lib/pkgfuncs.inc.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-)
Ack. Thanks!
participants (3)
-
Dan McGee
-
Dan McGee
-
Lukas Fleischer