Ejemplo n.º 1
0
     if (isset($_POST['confirm'])) {
         $via = isset($_POST['via']) ? $_POST['via'] : NULL;
         if (!isset($_POST['merge_Into']) || empty($_POST['merge_Into'])) {
             list($ret, $output) = pkgbase_delete($ids, NULL, $via);
             unset($_GET['ID']);
             unset($base_id);
         } else {
             $merge_base_id = pkgbase_from_name($_POST['merge_Into']);
             if (!$merge_base_id) {
                 $output = __("Cannot find package to merge votes and comments into.");
                 $ret = false;
             } elseif (in_array($merge_base_id, $ids)) {
                 $output = __("Cannot merge a package base with itself.");
                 $ret = false;
             } else {
                 list($ret, $output) = pkgbase_delete($ids, $merge_base_id, $via);
                 unset($_GET['ID']);
                 unset($base_id);
             }
         }
     } else {
         $output = __("The selected packages have not been deleted, check the confirmation checkbox.");
         $ret = false;
     }
 } elseif (current_action("do_Notify")) {
     list($ret, $output) = pkgbase_notify($ids);
 } elseif (current_action("do_UnNotify")) {
     list($ret, $output) = pkgbase_notify($ids, false);
 } elseif (current_action("do_DeleteComment")) {
     list($ret, $output) = pkgbase_delete_comment();
 } elseif (current_action("do_SetKeywords")) {
Ejemplo n.º 2
0
/**
 * File a deletion/orphan request against a package base
 *
 * @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 array Tuple of success/failure indicator and error message
 */
function pkgreq_file($ids, $type, $merge_into, $comments)
{
    if (!has_credential(CRED_PKGREQ_FILE)) {
        return array(false, __("You must be logged in to file package requests."));
    }
    if (!empty($merge_into) && !preg_match("/^[a-z0-9][a-z0-9\\.+_-]*\$/D", $merge_into)) {
        return array(false, __("Invalid name: only lowercase letters are allowed."));
    }
    if (!empty($merge_into) && !pkgbase_from_name($merge_into)) {
        return array(false, __("Cannot find package to merge votes and comments into."));
    }
    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 = intval($ids[0]);
    $pkgbase_name = pkgbase_name_from_id($base_id);
    if ($merge_into == $pkgbase_name) {
        return array(false, __("Cannot merge a package base with itself."));
    }
    $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 .= $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. */
    $params = array('request-open', $uid, $request_id, $type, $base_id);
    if ($type === 'merge') {
        $params[] = $merge_into;
    }
    notify($params, $comments);
    $auto_orphan_age = config_get('options', 'auto_orphan_age');
    $auto_delete_age = config_get('options', 'auto_delete_age');
    $details = pkgbase_get_details($base_id);
    if ($type == 'orphan' && $details['OutOfDateTS'] > 0 && time() - $details['OutOfDateTS'] >= $auto_orphan_age && $auto_orphan_age > 0) {
        /*
         * Close package request. NOTE: This needs to happen *before*
         * the actual disown operation. Otherwise, the former
         * maintainer will not be included in the Cc list of the
         * request notification email.
         */
        $out_of_date_time = gmdate("Y-m-d", intval($details["OutOfDateTS"]));
        pkgreq_close($request_id, "accepted", "The package base has been flagged out-of-date " . "since " . $out_of_date_time . ".", true);
        $q = "UPDATE PackageBases SET MaintainerUID = NULL ";
        $q .= "WHERE ID = " . $base_id;
        $dbh->exec($q);
    } else {
        if ($type == 'deletion' && $details['MaintainerUID'] == $uid && $details['SubmittedTS'] > 0 && $auto_delete_age > 0 && time() - $details['SubmittedTS'] <= $auto_delete_age) {
            /*
             * Close package request. NOTE: This needs to happen *before*
             * the actual deletion operation. Otherwise, the former
             * maintainer will not be included in the Cc list of the
             * request notification email.
             */
            pkgreq_close($request_id, "accepted", "Deletion of a fresh package requested by its " . "current maintainer.", true);
            pkgbase_delete(array($base_id), NULL, NULL, true);
        }
    }
    return array(true, __("Added request successfully."));
}