Exemple #1
0
/** Add daily changes if necessary */
function addDailyChanges($projectid)
{
    include "cdash/config.php";
    include_once "cdash/common.php";
    include_once "cdash/sendemail.php";
    $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}");
    pdo_select_db("{$CDASH_DB_NAME}", $db);
    $project_array = pdo_fetch_array(pdo_query("SELECT nightlytime,name,autoremovetimeframe,autoremovemaxbuilds,emailadministrator\n                                              FROM project WHERE id='{$projectid}'"));
    $date = "";
    // now
    list($previousdate, $currentstarttime, $nextdate) = get_dates($date, $project_array["nightlytime"]);
    $date = gmdate(FMT_DATE, $currentstarttime);
    // Check if we already have it somwhere
    $query = pdo_query("SELECT id FROM dailyupdate WHERE projectid='{$projectid}' AND date='{$date}'");
    if (pdo_num_rows($query) == 0) {
        $cvsauthors = array();
        pdo_query("INSERT INTO dailyupdate (projectid,date,command,type,status)\n               VALUES ({$projectid},'{$date}','NA','NA','0')");
        $updateid = pdo_insert_id("dailyupdate");
        $dates = get_related_dates($project_array["nightlytime"], $date);
        $commits = get_repository_commits($projectid, $dates);
        // Insert the commits
        foreach ($commits as $commit) {
            $filename = $commit['directory'] . "/" . $commit['filename'];
            $checkindate = $commit['time'];
            $author = addslashes($commit['author']);
            $email = '';
            if (isset($commit['email'])) {
                $email = addslashes($commit['email']);
            }
            $log = addslashes($commit['comment']);
            $revision = $commit['revision'];
            $priorrevision = $commit['priorrevision'];
            // Check if we have a robot file for this build
            $robot = pdo_query("SELECT authorregex FROM projectrobot\n                  WHERE projectid=" . qnum($projectid) . " AND robotname='" . $author . "'");
            if (pdo_num_rows($robot) > 0) {
                $robot_array = pdo_fetch_array($robot);
                $regex = $robot_array['authorregex'];
                preg_match($regex, $commit['comment'], $matches);
                if (isset($matches[1])) {
                    $author = addslashes($matches[1]);
                }
            }
            if (!in_array(stripslashes($author), $cvsauthors)) {
                $cvsauthors[] = stripslashes($author);
            }
            pdo_query("INSERT INTO dailyupdatefile (dailyupdateid,filename,checkindate,author,email,log,revision,priorrevision)\n                   VALUES ({$updateid},'{$filename}','{$checkindate}','{$author}','{$email}','{$log}','{$revision}','{$priorrevision}')");
            add_last_sql_error("addDailyChanges", $projectid);
        }
        // end foreach commit
        // If the project has the option to send an email to the author
        if ($project_array['emailadministrator']) {
            sendEmailUnregisteredUsers($projectid, $cvsauthors);
        }
        // Send an email if some expected builds have not been submitting
        sendEmailExpectedBuilds($projectid, $currentstarttime);
        // cleanBuildEmail
        cleanBuildEmail();
        cleanUserTemp();
        // If the status of daily update is set to 2 that means we should send an email
        $query = pdo_query("SELECT status FROM dailyupdate WHERE projectid='{$projectid}' AND date='{$date}'");
        $dailyupdate_array = pdo_fetch_array($query);
        $dailyupdate_status = $dailyupdate_array["status"];
        if ($dailyupdate_status == 2) {
            // Find the groupid
            $group_query = pdo_query("SELECT buildid,groupid FROM summaryemail WHERE date='{$date}'");
            while ($group_array = pdo_fetch_array($group_query)) {
                $groupid = $group_array["groupid"];
                $buildid = $group_array["buildid"];
                // Find if the build has any errors
                $builderror = pdo_query("SELECT count(buildid) FROM builderror WHERE buildid='{$buildid}' AND type='0'");
                $builderror_array = pdo_fetch_array($builderror);
                $nbuilderrors = $builderror_array[0];
                // Find if the build has any warnings
                $buildwarning = pdo_query("SELECT count(buildid) FROM builderror WHERE buildid='{$buildid}' AND type='1'");
                $buildwarning_array = pdo_fetch_array($buildwarning);
                $nbuildwarnings = $buildwarning_array[0];
                // Find if the build has any test failings
                if ($project_emailtesttimingchanged) {
                    $sql = "SELECT count(testid) FROM build2test WHERE buildid='{$buildid}' AND (status='failed' OR timestatus>" . qnum($project_testtimemaxstatus) . ")";
                } else {
                    $sql = "SELECT count(testid) FROM build2test WHERE buildid='{$buildid}' AND status='failed'";
                }
                $nfail_array = pdo_fetch_array(pdo_query($sql));
                $nfailingtests = $nfail_array[0];
                sendsummaryemail($projectid, $groupid, $nbuildwarnings, $nbuilderrors, $nfailingtests);
            }
        }
        pdo_query("UPDATE dailyupdate SET status='1' WHERE projectid='{$projectid}' AND date='{$date}'");
        // Remove the old logs
        include_once "models/errorlog.php";
        $ErrorLog = new ErrorLog();
        $ErrorLog->Clean(10);
        // 10 days
        // Clean the backup directory
        clean_backup_directory();
        // Remove the first builds of the project
        include_once "cdash/autoremove.php";
        removeFirstBuilds($projectid, $project_array["autoremovetimeframe"], $project_array["autoremovemaxbuilds"]);
        removeBuildsGroupwise($projectid, $project_array["autoremovemaxbuilds"]);
    }
}
Exemple #2
0
// nightly start time for "$projectname" on "$date"
@($projectname = $_GET["project"]);
if ($projectname != NULL) {
    $projectname = htmlspecialchars(pdo_real_escape_string($projectname));
}
@($date = $_GET["date"]);
if ($date != NULL) {
    $date = htmlspecialchars(pdo_real_escape_string($date));
}
$db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}");
pdo_select_db("{$CDASH_DB_NAME}", $db);
$project = pdo_query("SELECT id,nightlytime,bugtrackerurl,bugtrackerfileurl FROM project WHERE name='{$projectname}'");
$project_array = pdo_fetch_array($project);
$projectid = $project_array["id"];
checkUserPolicy(@$_SESSION['cdash']['loginid'], $projectid);
$dates = get_related_dates($projectname, $date);
$xml = begin_XML_for_XSLT();
$xml .= "<title>CDash : " . $projectname . "</title>";
$gmdate = gmdate(FMT_DATE, $dates['nightly-0']);
$nightlytime = $project_array["nightlytime"];
$xml .= get_cdash_dashboard_xml_by_name($projectname, $date);
list($previousdate, $currentstarttime, $nextdate, $today) = get_dates($date, $nightlytime);
$xml .= "<menu>";
$xml .= add_XML_value("previous", "viewChanges.php?project=" . urlencode($projectname) . "&date=" . $previousdate);
if ($date != "" && date(FMT_DATE, $currentstarttime) != date(FMT_DATE)) {
    $xml .= add_XML_value("next", "viewChanges.php?project=" . urlencode($projectname) . "&date=" . $nextdate);
} else {
    $xml .= add_XML_value("nonext", "1");
}
$xml .= add_XML_value("current", "viewChanges.php?project=" . urlencode($projectname) . "&date=");
$xml .= add_XML_value("back", "index.php?project=" . urlencode($projectname) . "&date=" . $today);