[aur-dev] [PATCH 1/2] Split out package request functions
Move package request functions to a separate unit pkgreqfuncs.inc.php. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgbasefuncs.inc.php | 186 +----------------------------------------- web/lib/pkgreqfuncs.inc.php | 188 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 185 deletions(-) create mode 100644 web/lib/pkgreqfuncs.inc.php diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 9f3439d..c597911 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -1,5 +1,6 @@ <?php include_once("config.inc.php"); +include_once("pkgreqfuncs.inc.php"); /** * Get all package categories stored in the database @@ -972,188 +973,3 @@ function pkgbase_update_category($base_id, $category_id) { $category_id, $base_id); $dbh->exec($q); } - -/** - * Get a list of all package requests - * - * @return array List of pacakge requests with details - */ -function pkgbase_request_list() { - $dbh = DB::connect(); - - $q = "SELECT PackageRequests.ID, "; - $q.= "PackageRequests.PackageBaseID AS BaseID, "; - $q.= "PackageRequests.PackageBaseName AS Name, "; - $q.= "PackageRequests.MergeBaseName AS MergeInto, "; - $q.= "RequestTypes.Name AS Type, PackageRequests.Comments, "; - $q.= "Users.Username AS User, PackageRequests.RequestTS, "; - $q.= "PackageRequests.Status "; - $q.= "FROM PackageRequests INNER JOIN RequestTypes ON "; - $q.= "RequestTypes.ID = PackageRequests.ReqTypeID "; - $q.= "INNER JOIN Users ON Users.ID = PackageRequests.UsersID "; - $q.= "ORDER BY Status ASC, RequestTS DESC"; - - return $dbh->query($q)->fetchAll(); -} - -/** - * File a deletion/orphan request against a package base - * - * @global string $AUR_LOCATION The AUR's URL used for notification e-mails - * @global string $AUR_REQUEST_ML The request notification mailing list - * @param string $ids The package base IDs to file the request against - * @param string $type The type of the request - * @param string $merge_into The target of a merge operation - * @param string $comments The comments to be added to the request - * - * @return void - */ -function pkgbase_file_request($ids, $type, $merge_into, $comments) { - global $AUR_LOCATION; - global $AUR_REQUEST_ML; - - if (empty($comments)) { - return array(false, __("The comment field must not be empty.")); - } - - $dbh = DB::connect(); - $uid = uid_from_sid($_COOKIE["AURSID"]); - - /* TODO: Allow for filing multiple requests at once. */ - $base_id = $ids[0]; - $pkgbase_name = pkgbase_name_from_id($base_id); - - $q = "SELECT ID FROM RequestTypes WHERE Name = " . $dbh->quote($type); - $result = $dbh->query($q); - if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $type_id = $row['ID']; - } else { - return array(false, __("Invalid request type.")); - } - - $q = "INSERT INTO PackageRequests "; - $q.= "(ReqTypeID, PackageBaseID, PackageBaseName, MergeBaseName, "; - $q.= "UsersID, Comments, RequestTS) VALUES (" . $type_id . ", "; - $q.= intval($base_id) . ", " . $dbh->quote($pkgbase_name) . ", "; - $q.= $dbh->quote($merge_into) . ", " . $uid . ", "; - $q.= $dbh->quote($comments) . ", UNIX_TIMESTAMP())"; - $dbh->exec($q); - $request_id = $dbh->lastInsertId(); - - /* - * Send e-mail notifications. - * TODO: Move notification logic to separate function where it belongs. - */ - $q = "SELECT Users.Email "; - $q.= "FROM Users INNER JOIN PackageBases "; - $q.= "ON PackageBases.MaintainerUID = Users.ID "; - $q.= "WHERE PackageBases.ID = " . intval($base_id); - $result = $dbh->query($q); - if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $bcc = $row['Email']; - } else { - unset($bcc); - } - - $q = "SELECT Name FROM PackageBases WHERE ID = "; - $q.= intval($base_id); - $result = $dbh->query($q); - $row = $result->fetch(PDO::FETCH_ASSOC); - - /* - * TODO: Add native language emails for users, based on their - * preferences. Simply making these strings translatable won't - * work, users would be getting emails in the language that the - * user who posted the comment was in. - */ - $username = username_from_sid($_COOKIE['AURSID']); - $body = - $username . " [1] filed a " . $type . " request for " . - $row['Name'] . " [2]:\n\n" . $comments . "\n\n" . - "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n" . - "[2] " . $AUR_LOCATION . get_pkgbase_uri($row['Name']) . "\n"; - $body = wordwrap($body, 70); - $headers = "MIME-Version: 1.0\r\n" . - "Content-type: text/plain; charset=UTF-8\r\n"; - if (!empty($bcc)) { - $headers .= "Bcc: $bcc\r\n"; - } - $thread_id = "<pkg-request-" . $request_id . "@aur.archlinux.org>"; - $headers .= "Reply-to: noreply@aur.archlinux.org\r\n" . - "From: notify@aur.archlinux.org\r\n" . - "In-Reply-To: $thread_id\r\n" . - "References: $thread_id\r\n" . - "X-Mailer: AUR"; - @mail($AUR_REQUEST_ML, "[PRQ#" . $request_id . "] " . ucfirst($type) . - " Request for " . $row['Name'], $body, - $headers); - - return array(true, __("Added request successfully.")); -} - -/** - * Close a deletion/orphan request - * - * @global string $AUR_LOCATION The AUR's URL used for notification e-mails - * @global string $AUR_REQUEST_ML The request notification mailing list - * @param int $id The package request to close - * - * @return void - */ -function pkgbase_close_request($id) { - global $AUR_LOCATION; - global $AUR_REQUEST_ML; - - $dbh = DB::connect(); - $id = intval($id); - - if (!check_user_privileges()) { - return array(false, __("Only TUs and developers can close requests.")); - } - - $q = "UPDATE PackageRequests SET Status = 1 WHERE ID = " . intval($id); - $dbh->exec($q); - - /* - * Send e-mail notifications. - * TODO: Move notification logic to separate function where it belongs. - */ - $q = "SELECT Users.Email "; - $q.= "FROM Users INNER JOIN PackageBases "; - $q.= "ON PackageBases.MaintainerUID = Users.ID "; - $q.= "INNER JOIN PackageRequests "; - $q.= "ON PackageRequests.PackageBaseID = PackageBases.ID "; - $q.= "WHERE PackageRequests.ID = " . $id; - $result = $dbh->query($q); - if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $bcc = $row['Email']; - } else { - unset($bcc); - } - - /* - * TODO: Add native language emails for users, based on their - * preferences. Simply making these strings translatable won't - * work, users would be getting emails in the language that the - * user who posted the comment was in. - */ - $username = username_from_sid($_COOKIE['AURSID']); - $body = $username . " [1] closed request #" . intval($id) . ".\n\n" . - "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n"; - $body = wordwrap($body, 70); - $headers = "MIME-Version: 1.0\r\n" . - "Content-type: text/plain; charset=UTF-8\r\n"; - if (!empty($bcc)) { - $headers .= "Bcc: $bcc\r\n"; - } - $thread_id = "<pkg-request-" . $id . "@aur.archlinux.org>"; - $headers .= "Reply-to: noreply@aur.archlinux.org\r\n" . - "From: notify@aur.archlinux.org\r\n" . - "In-Reply-To: $thread_id\r\n" . - "References: $thread_id\r\n" . - "X-Mailer: AUR"; - @mail($AUR_REQUEST_ML, "[PRQ#" . $id . "] Request Closed", $body, - $headers); - - return array(true, __("Request closed successfully.")); -} diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php new file mode 100644 index 0000000..7ba596a --- /dev/null +++ b/web/lib/pkgreqfuncs.inc.php @@ -0,0 +1,188 @@ +<?php +include_once("config.inc.php"); +include_once("pkgbasefuncs.inc.php"); + +/** + * Get a list of all package requests + * + * @return array List of pacakge requests with details + */ +function pkgbase_request_list() { + $dbh = DB::connect(); + + $q = "SELECT PackageRequests.ID, "; + $q.= "PackageRequests.PackageBaseID AS BaseID, "; + $q.= "PackageRequests.PackageBaseName AS Name, "; + $q.= "PackageRequests.MergeBaseName AS MergeInto, "; + $q.= "RequestTypes.Name AS Type, PackageRequests.Comments, "; + $q.= "Users.Username AS User, PackageRequests.RequestTS, "; + $q.= "PackageRequests.Status "; + $q.= "FROM PackageRequests INNER JOIN RequestTypes ON "; + $q.= "RequestTypes.ID = PackageRequests.ReqTypeID "; + $q.= "INNER JOIN Users ON Users.ID = PackageRequests.UsersID "; + $q.= "ORDER BY Status ASC, RequestTS DESC"; + + return $dbh->query($q)->fetchAll(); +} + +/** + * File a deletion/orphan request against a package base + * + * @global string $AUR_LOCATION The AUR's URL used for notification e-mails + * @global string $AUR_REQUEST_ML The request notification mailing list + * @param string $ids The package base IDs to file the request against + * @param string $type The type of the request + * @param string $merge_into The target of a merge operation + * @param string $comments The comments to be added to the request + * + * @return void + */ +function pkgbase_file_request($ids, $type, $merge_into, $comments) { + global $AUR_LOCATION; + global $AUR_REQUEST_ML; + + if (empty($comments)) { + return array(false, __("The comment field must not be empty.")); + } + + $dbh = DB::connect(); + $uid = uid_from_sid($_COOKIE["AURSID"]); + + /* TODO: Allow for filing multiple requests at once. */ + $base_id = $ids[0]; + $pkgbase_name = pkgbase_name_from_id($base_id); + + $q = "SELECT ID FROM RequestTypes WHERE Name = " . $dbh->quote($type); + $result = $dbh->query($q); + if ($row = $result->fetch(PDO::FETCH_ASSOC)) { + $type_id = $row['ID']; + } else { + return array(false, __("Invalid request type.")); + } + + $q = "INSERT INTO PackageRequests "; + $q.= "(ReqTypeID, PackageBaseID, PackageBaseName, MergeBaseName, "; + $q.= "UsersID, Comments, RequestTS) VALUES (" . $type_id . ", "; + $q.= intval($base_id) . ", " . $dbh->quote($pkgbase_name) . ", "; + $q.= $dbh->quote($merge_into) . ", " . $uid . ", "; + $q.= $dbh->quote($comments) . ", UNIX_TIMESTAMP())"; + $dbh->exec($q); + $request_id = $dbh->lastInsertId(); + + /* + * Send e-mail notifications. + * TODO: Move notification logic to separate function where it belongs. + */ + $q = "SELECT Users.Email "; + $q.= "FROM Users INNER JOIN PackageBases "; + $q.= "ON PackageBases.MaintainerUID = Users.ID "; + $q.= "WHERE PackageBases.ID = " . intval($base_id); + $result = $dbh->query($q); + if ($row = $result->fetch(PDO::FETCH_ASSOC)) { + $bcc = $row['Email']; + } else { + unset($bcc); + } + + $q = "SELECT Name FROM PackageBases WHERE ID = "; + $q.= intval($base_id); + $result = $dbh->query($q); + $row = $result->fetch(PDO::FETCH_ASSOC); + + /* + * TODO: Add native language emails for users, based on their + * preferences. Simply making these strings translatable won't + * work, users would be getting emails in the language that the + * user who posted the comment was in. + */ + $username = username_from_sid($_COOKIE['AURSID']); + $body = + $username . " [1] filed a " . $type . " request for " . + $row['Name'] . " [2]:\n\n" . $comments . "\n\n" . + "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n" . + "[2] " . $AUR_LOCATION . get_pkgbase_uri($row['Name']) . "\n"; + $body = wordwrap($body, 70); + $headers = "MIME-Version: 1.0\r\n" . + "Content-type: text/plain; charset=UTF-8\r\n"; + if (!empty($bcc)) { + $headers .= "Bcc: $bcc\r\n"; + } + $thread_id = "<pkg-request-" . $request_id . "@aur.archlinux.org>"; + $headers .= "Reply-to: noreply@aur.archlinux.org\r\n" . + "From: notify@aur.archlinux.org\r\n" . + "In-Reply-To: $thread_id\r\n" . + "References: $thread_id\r\n" . + "X-Mailer: AUR"; + @mail($AUR_REQUEST_ML, "[PRQ#" . $request_id . "] " . ucfirst($type) . + " Request for " . $row['Name'], $body, + $headers); + + return array(true, __("Added request successfully.")); +} + +/** + * Close a deletion/orphan request + * + * @global string $AUR_LOCATION The AUR's URL used for notification e-mails + * @global string $AUR_REQUEST_ML The request notification mailing list + * @param int $id The package request to close + * + * @return void + */ +function pkgbase_close_request($id) { + global $AUR_LOCATION; + global $AUR_REQUEST_ML; + + $dbh = DB::connect(); + $id = intval($id); + + if (!check_user_privileges()) { + return array(false, __("Only TUs and developers can close requests.")); + } + + $q = "UPDATE PackageRequests SET Status = 1 WHERE ID = " . intval($id); + $dbh->exec($q); + + /* + * Send e-mail notifications. + * TODO: Move notification logic to separate function where it belongs. + */ + $q = "SELECT Users.Email "; + $q.= "FROM Users INNER JOIN PackageBases "; + $q.= "ON PackageBases.MaintainerUID = Users.ID "; + $q.= "INNER JOIN PackageRequests "; + $q.= "ON PackageRequests.PackageBaseID = PackageBases.ID "; + $q.= "WHERE PackageRequests.ID = " . $id; + $result = $dbh->query($q); + if ($row = $result->fetch(PDO::FETCH_ASSOC)) { + $bcc = $row['Email']; + } else { + unset($bcc); + } + + /* + * TODO: Add native language emails for users, based on their + * preferences. Simply making these strings translatable won't + * work, users would be getting emails in the language that the + * user who posted the comment was in. + */ + $username = username_from_sid($_COOKIE['AURSID']); + $body = $username . " [1] closed request #" . intval($id) . ".\n\n" . + "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n"; + $body = wordwrap($body, 70); + $headers = "MIME-Version: 1.0\r\n" . + "Content-type: text/plain; charset=UTF-8\r\n"; + if (!empty($bcc)) { + $headers .= "Bcc: $bcc\r\n"; + } + $thread_id = "<pkg-request-" . $id . "@aur.archlinux.org>"; + $headers .= "Reply-to: noreply@aur.archlinux.org\r\n" . + "From: notify@aur.archlinux.org\r\n" . + "In-Reply-To: $thread_id\r\n" . + "References: $thread_id\r\n" . + "X-Mailer: AUR"; + @mail($AUR_REQUEST_ML, "[PRQ#" . $id . "] Request Closed", $body, + $headers); + + return array(true, __("Request closed successfully.")); +} -- 2.0.1
Since these functions now reside in a separate module, use the module name as function name prefix. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/html/pkgbase.php | 4 ++-- web/html/pkgreq.php | 2 +- web/lib/pkgbasefuncs.inc.php | 4 ++-- web/lib/pkgreqfuncs.inc.php | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/web/html/pkgbase.php b/web/html/pkgbase.php index 0b0f6ef..6fdaf40 100644 --- a/web/html/pkgbase.php +++ b/web/html/pkgbase.php @@ -97,9 +97,9 @@ if (check_token()) { } elseif (current_action("do_ChangeCategory")) { list($ret, $output) = pkgbase_change_category($base_id, $atype); } elseif (current_action("do_FileRequest")) { - list($ret, $output) = pkgbase_file_request($ids, $_POST['type'], $_POST['merge_into'], $_POST['comments']); + list($ret, $output) = pkgreq_file($ids, $_POST['type'], $_POST['merge_into'], $_POST['comments']); } elseif (current_action("do_CloseRequest")) { - list($ret, $output) = pkgbase_close_request($_POST['reqid']); + list($ret, $output) = pkgreq_close($_POST['reqid']); } if (isset($_REQUEST['comment'])) { diff --git a/web/html/pkgreq.php b/web/html/pkgreq.php index 5d708fc..156645a 100644 --- a/web/html/pkgreq.php +++ b/web/html/pkgreq.php @@ -16,7 +16,7 @@ if (!isset($base_id)) { exit(); } - $results = pkgbase_request_list(); + $results = pkgreq_list(); $total = count($results); /* Sanitize paging variables. */ diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index c597911..ec48314 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -540,7 +540,7 @@ function pkgbase_delete ($atype, $base_ids, $merge_base_id, $via) { $dbh->exec($q); if ($via) { - pkgbase_close_request(intval($via)); + pkgreq_close(intval($via)); } return array(true, __("The selected packages have been deleted.")); @@ -598,7 +598,7 @@ function pkgbase_adopt ($atype, $base_ids, $action=true, $via) { $dbh->exec($q); if ($via) { - pkgbase_close_request(intval($via)); + pkgreq_close(intval($via)); } if ($action) { diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 7ba596a..47758c3 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -7,7 +7,7 @@ include_once("pkgbasefuncs.inc.php"); * * @return array List of pacakge requests with details */ -function pkgbase_request_list() { +function pkgreq_list() { $dbh = DB::connect(); $q = "SELECT PackageRequests.ID, "; @@ -37,7 +37,7 @@ function pkgbase_request_list() { * * @return void */ -function pkgbase_file_request($ids, $type, $merge_into, $comments) { +function pkgreq_file($ids, $type, $merge_into, $comments) { global $AUR_LOCATION; global $AUR_REQUEST_ML; @@ -129,7 +129,7 @@ function pkgbase_file_request($ids, $type, $merge_into, $comments) { * * @return void */ -function pkgbase_close_request($id) { +function pkgreq_close($id) { global $AUR_LOCATION; global $AUR_REQUEST_ML; -- 2.0.1
participants (1)
-
Lukas Fleischer