Exemplo n.º 1
0
<?php

$pkgbuild_uri = sprintf(config_get('options', 'pkgbuild_uri'), urlencode($row['Name']));
$log_uri = sprintf(config_get('options', 'log_uri'), urlencode($row['Name']));
$snapshot_uri = sprintf(config_get('options', 'snapshot_uri'), urlencode($row['Name']));
$git_clone_uri_anon = sprintf(config_get('options', 'git_clone_uri_anon'), htmlspecialchars($row['Name']));
$git_clone_uri_priv = sprintf(config_get('options', 'git_clone_uri_priv'), htmlspecialchars($row['Name']));
$uid = uid_from_sid($SID);
$base_id = intval($row['ID']);
$keywords = pkgbase_get_keywords($base_id);
$submitter = username_from_id($row["SubmitterUID"]);
$maintainer = username_from_id($row["MaintainerUID"]);
$comaintainers = pkgbase_get_comaintainers($base_id);
$packager = username_from_id($row["PackagerUID"]);
if ($row["MaintainerUID"] !== NULL) {
    $maintainers = array_merge(array($row["MaintainerUID"]), pkgbase_get_comaintainer_uids(array($base_id)));
} else {
    $maintainers = array();
}
$unflaggers = array_merge($maintainers, array($row["FlaggerUID"]));
$votes = $row['NumVotes'];
$popularity = $row['Popularity'];
# In case of wanting to put a custom message
$msg = __('unknown');
# Print the timestamps for last updates
$updated_time = $row["ModifiedTS"] == 0 ? $msg : gmdate("Y-m-d H:i", intval($row["ModifiedTS"]));
$submitted_time = $row["SubmittedTS"] == 0 ? $msg : gmdate("Y-m-d H:i", intval($row["SubmittedTS"]));
$out_of_date_time = $row["OutOfDateTS"] == 0 ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"]));
$pkgs = pkgbase_get_pkgnames($base_id);
$base_uri = get_pkgbase_uri($row['Name']);
?>
Exemplo n.º 2
0
/**
 * Adopt or disown packages
 *
 * @param array $base_ids Array of package base IDs to adopt/disown
 * @param bool $action Adopts if true, disowns if false. Adopts by default
 * @param int $via Package request to close upon adoption
 *
 * @return array Tuple of success/failure indicator and error message
 */
function pkgbase_adopt($base_ids, $action = true, $via)
{
    $dbh = DB::connect();
    $uid = uid_from_sid($_COOKIE["AURSID"]);
    if (!$uid) {
        if ($action) {
            return array(false, __("You must be logged in before you can adopt packages."));
        } else {
            return array(false, __("You must be logged in before you can disown packages."));
        }
    }
    /* Verify package ownership. */
    $base_ids = sanitize_ids($base_ids);
    $q = "SELECT ID FROM PackageBases ";
    $q .= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
    if ($action && !has_credential(CRED_PKGBASE_ADOPT)) {
        /* Regular users may only adopt orphan packages. */
        $q .= "AND MaintainerUID IS NULL";
    }
    if (!$action && !has_credential(CRED_PKGBASE_DISOWN)) {
        /* Regular users may only disown their own packages. */
        $q .= "AND MaintainerUID = " . $uid;
    }
    $result = $dbh->query($q);
    $base_ids = $result->fetchAll(PDO::FETCH_COLUMN, 0);
    /* Error out if the list of remaining packages is empty. */
    if (empty($base_ids)) {
        if ($action) {
            return array(false, __("You did not select any packages to adopt."));
        } else {
            return array(false, __("You did not select any packages to disown."));
        }
    }
    /*
     * Close package request if the disownment was initiated through the
     * request interface. 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.
     */
    if ($via) {
        pkgreq_close(intval($via), 'accepted', '');
    }
    /* Scan through pending orphan requests and close them. */
    if (!$action) {
        $username = username_from_sid($_COOKIE['AURSID']);
        foreach ($base_ids as $base_id) {
            $pkgreq_ids = pkgreq_by_pkgbase($base_id, 'orphan');
            foreach ($pkgreq_ids as $pkgreq_id) {
                pkgreq_close(intval($pkgreq_id), 'accepted', 'The user ' . $username . ' disowned the package.', true);
            }
        }
    }
    /* Adopt or disown the package. */
    if ($action) {
        $q = "UPDATE PackageBases ";
        $q .= "SET MaintainerUID = {$uid} ";
        $q .= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
        $dbh->exec($q);
    } else {
        /* Update the co-maintainer list when disowning a package. */
        if (has_credential(CRED_PKGBASE_DISOWN)) {
            foreach ($base_ids as $base_id) {
                pkgbase_set_comaintainers($base_id, array());
            }
            $q = "UPDATE PackageBases ";
            $q .= "SET MaintainerUID = NULL ";
            $q .= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
            $dbh->exec($q);
        } else {
            foreach ($base_ids as $base_id) {
                $comaintainers = pkgbase_get_comaintainers($base_id);
                if (count($comaintainers) > 0) {
                    $uid = uid_from_username($comaintainers[0]);
                    $comaintainers = array_diff($comaintainers, array($comaintainers[0]));
                    pkgbase_set_comaintainers($base_id, $comaintainers);
                } else {
                    $uid = "NULL";
                }
                $q = "UPDATE PackageBases ";
                $q .= "SET MaintainerUID = " . $uid . " ";
                $q .= "WHERE ID = " . $base_id;
                $dbh->exec($q);
            }
        }
    }
    if ($action) {
        pkgbase_notify($base_ids);
        return array(true, __("The selected packages have been adopted."));
    } else {
        return array(true, __("The selected packages have been disowned."));
    }
}