Beispiel #1
0
 function testErrorLog()
 {
     $this->startCodeCoverage();
     $errorlog = new ErrorLog();
     $errorlog->Clean(7);
     $errorlog->BuildId = "foo";
     if ($errorlog->Insert()) {
         $this->fail("Insert() should return false when BuildId is non-numeric");
         return 1;
     }
     $errorlog->BuildId = 1;
     $errorlog->Description = "example error description";
     $errorlog->Insert();
     $this->pass("Passed");
     $this->stopCodeCoverage();
     return 0;
 }
Beispiel #2
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"]);
    }
}
Beispiel #3
0
 $role = 0;
 if ($projectid) {
     $project = pdo_query("SELECT name FROM project WHERE id='{$projectid}'");
     if (pdo_num_rows($project) > 0) {
         $project_array = pdo_fetch_array($project);
         $projectname = $project_array["name"];
     }
     $Project->Id = $projectid;
     $role = $Project->GetUserRole($userid);
 } else {
     $projectname = 'Global';
 }
 // If we should delete the log
 if (($User->IsAdmin() || $role > 1) && isset($_POST["deletelogs"])) {
     $ErrorLog = new ErrorLog();
     $ErrorLog->Clean(0, $projectid);
 } else {
     if (isset($_POST["deletelogs"])) {
         echo "You don't have the privileges to delete these logs.";
         exit;
     }
 }
 $xml = begin_XML_for_XSLT();
 $xml .= "<title>Error Log - " . $projectname . "</title>";
 if ($buildid) {
     $xml .= get_cdash_dashboard_xml(get_project_name($projectid), $date);
     // Get the errors
     $query = pdo_query("SELECT resourcetype,date,resourceid,description,type,buildid,projectid\n                     FROM errorlog WHERE projectid=" . qnum($projectid) . " AND buildid=" . qnum($buildid) . " ORDER BY date DESC");
 } else {
     if ($projectid) {
         $xml .= get_cdash_dashboard_xml(get_project_name($projectid), $date);