public function testManageClientTest()
 {
     // set the repository for the project
     $project = new Project();
     $project->Id = 3;
     $project->Fill();
     $project->AddRepositories(array('git://fake/repo.git'), array(''), array(''), array(''));
     // submit a mock machine config xml
     $machineDescription = dirname(__FILE__) . '/data/camelot.cdash.xml';
     $result = $this->uploadfile($this->url . '/submit.php?sitename=camelot.kitware&systemname=Ubuntu32&submitinfo=1', $machineDescription);
     if ($this->findString($result, 'error') || $this->findString($result, 'Warning') || $this->findString($result, 'Notice')) {
         $this->assertEqual($result, "\n");
         return false;
     }
     // schedule a job for the machine
     $this->login();
     $this->connect($this->url . '/manageClient.php?projectid=3');
     $scriptContents = 'message("hello world")';
     $this->setField('clientscript', $scriptContents);
     $this->clickSubmitByName('submit');
     // get the site id
     $siteid = $this->get($this->url . '/submit.php?sitename=camelot.kitware&systemname=Ubuntu32&getsiteid=1');
     // wait a few seconds so that we know we are ahead of the schedule time
     sleep(5);
     // verify that we receive the correct script when we query for a job
     $content = $this->get($this->url . '/submit.php?getjob=1&siteid=' . $siteid);
     if (!$this->findString($content, 'message("hello world")')) {
         $this->fail('Wrong script was sent: expected hello world script but got: ' . $content . ' for siteid=' . $siteid);
         return false;
     }
     $this->pass('Passed');
     return 0;
 }
 public function testSetupRepositories()
 {
     $insight = new Project();
     $row = pdo_single_row_query("SELECT id FROM project where name='InsightExample'");
     $insight->Id = $row['id'];
     $insight->Fill();
     $insight->AddRepositories(array(':pserver:anoncvs@itk.org:/cvsroot/Insight'), array('anoncvs'), array(''), array(''));
     $insight->CTestTemplateScript = 'client testing works';
     $insight->Save();
     $pub = new Project();
     $row = pdo_single_row_query("SELECT id FROM project where name='PublicDashboard'");
     $pub->Id = $row['id'];
     $pub->Fill();
     $pub->AddRepositories(array('git://cmake.org/cmake.git'), array(''), array(''), array(''));
     $pub->CvsViewerType = 'gitweb';
     $pub->CvsUrl = 'cmake.org/gitweb?p=cmake.git';
     $pub->Save();
     $email = new Project();
     $row = pdo_single_row_query("SELECT id FROM project where name='EmailProjectExample'");
     $email->Id = $row['id'];
     $email->Fill();
     $email->AddRepositories(array('https://www.kitware.com/svn/CDash/trunk'), array(''), array(''), array(''));
     $pub->CvsViewerType = 'websvn';
     $email->CvsUrl = 'https://www.kitware.com/svn/CDash/trunk';
     $email->Save();
 }
Example #3
0
 public function createProject($input_settings, $update = false)
 {
     require_once 'models/project.php';
     if ($update) {
         // Updating an existing project.
         if (!array_key_exists('Id', $input_settings)) {
             $this->fail("Project Id must be set");
             return false;
         }
         // Load its current settings.
         $project = new Project();
         $project->Id = $input_settings['Id'];
         $project->Fill();
         $settings = get_object_vars($project);
         $submit_button = 'Update';
     } else {
         // Create a new project.
         if (!array_key_exists('Name', $input_settings)) {
             $this->fail("Project name must be set");
             return false;
         }
         // Specify some default settings.
         $settings = array('AutoremoveMaxBuilds' => 500, 'AutoremoveTimeframe' => 60, 'CoverageThreshold' => 70, 'CvsViewerType' => 'viewcvs', 'EmailBrokenSubmission' => 1, 'EmailMaxChars' => 255, 'EmailMaxItems' => 5, 'NightlyTime' => '01:00:00 UTC', 'Public' => 1, 'ShowCoverageCode' => 1, 'TestTimeMaxStatus' => 3, 'TestTimeStd' => 4, 'TestTimeStdThreshold' => 1, 'UploadQuota' => 1);
         $submit_button = 'Submit';
     }
     // Override default/existing settings with those we wish to change.
     foreach ($input_settings as $k => $v) {
         $settings[$k] = $v;
     }
     // Login as admin.
     $client = new GuzzleHttp\Client(['cookies' => true]);
     global $CDASH_BASE_URL;
     try {
         $response = $client->request('POST', $CDASH_BASE_URL . '/user.php', ['form_params' => ['login' => 'simpletest@localhost', 'passwd' => 'simpletest', 'sent' => 'Login >>']]);
     } catch (GuzzleHttp\Exception\ClientException $e) {
         $this->fail($e->getMessage());
         return false;
     }
     // Create project.
     try {
         $response = $client->request('POST', $CDASH_BASE_URL . '/api/v1/project.php', ['json' => [$submit_button => true, 'project' => $settings]]);
     } catch (GuzzleHttp\Exception\ClientException $e) {
         $this->fail($e->getMessage());
         return false;
     }
     $response_array = json_decode($response->getBody(), true);
     $projectid = $response_array['project']['Id'];
     // Make sure all of our settings were applied successfully.
     $project = new Project();
     $project->Id = $projectid;
     $project->Fill();
     if (!$project->Exists()) {
         $this->fail("Project does not exist after it should have been created");
     }
     foreach ($input_settings as $k => $v) {
         if ($k === 'repositories') {
             // Special handling for repositories as these aren't
             // simple project properties.
             $added_repos = $v;
             $num_added_repos = count($added_repos);
             $project_repos = $project->GetRepositories();
             $matches_found = 0;
             foreach ($project_repos as $project_repo) {
                 foreach ($added_repos as $added_repo) {
                     if ($project_repo['url'] === $added_repo['url'] && $project_repo['branch'] === $added_repo['branch'] && $project_repo['username'] === $added_repo['username'] && $project_repo['password'] === $added_repo['password']) {
                         $matches_found++;
                     }
                 }
             }
             if ($matches_found != count($added_repos)) {
                 $this->fail("Attempted to add {$num_added_repos} but only found {$matches_found}");
             }
         } else {
             $found_value = $project->{$k};
             if ($found_value != $v) {
                 $this->fail("Expected {$v} but found {$found_value} for {$k}");
             }
         }
     }
     return $projectid;
 }
Example #4
0
/** Main function to send email if necessary */
function sendemail($handler, $projectid)
{
    include 'config/config.php';
    include_once 'include/common.php';
    require_once 'include/pdo.php';
    require_once 'models/build.php';
    require_once 'models/project.php';
    require_once 'models/buildgroup.php';
    $Project = new Project();
    $Project->Id = $projectid;
    $Project->Fill();
    $sendEmail = null;
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/sendemail.php')) {
        include_once 'local/sendemail.php';
        $sendEmail = new SendEmail();
        $sendEmail->SetProjectId($projectid);
    }
    // If we shouldn't sent any emails we stop
    if ($Project->EmailBrokenSubmission == 0) {
        return;
    }
    // If the handler has a buildid (it should), we use it
    if (isset($handler->BuildId) && $handler->BuildId > 0) {
        $buildid = $handler->BuildId;
    } else {
        // Get the build id
        $name = $handler->getBuildName();
        $stamp = $handler->getBuildStamp();
        $sitename = $handler->getSiteName();
        $buildid = get_build_id($name, $stamp, $projectid, $sitename);
    }
    if ($buildid < 0) {
        return;
    }
    //add_log("Buildid ".$buildid,"sendemail ".$Project->Name,LOG_INFO);
    //  Check if the group as no email
    $Build = new Build();
    $Build->Id = $buildid;
    $groupid = $Build->GetGroup();
    $BuildGroup = new BuildGroup();
    $BuildGroup->SetId($groupid);
    // If we specified no email we stop here
    if ($BuildGroup->GetSummaryEmail() == 2) {
        return;
    }
    $emailCommitters = $BuildGroup->GetEmailCommitters();
    $errors = check_email_errors($buildid, $Project->EmailTestTimingChanged, $Project->TestTimeMaxStatus, !$Project->EmailRedundantFailures);
    // We have some fixes
    if ($errors['hasfixes']) {
        $Build->FillFromId($Build->Id);
        // Get the list of person who should get the email
        $lookup_result = lookup_emails_to_send($errors, $buildid, $projectid, $Build->Type, true, $emailCommitters);
        $userids = $lookup_result['userids'];
        foreach ($userids as $userid) {
            $emailtext = array();
            $emailtext['nfixes'] = 0;
            // Check if an email has been sent already for this user
            foreach ($errors['fixes'] as $fixkey => $nfixes) {
                if ($nfixes == 0) {
                    continue;
                }
                if (!check_email_sent($userid, $buildid, $fixkey)) {
                    $emailtext['category'][$fixkey] = $nfixes;
                    $emailtext['nfixes'] = 1;
                }
            }
            // Send the email
            if ($emailtext['nfixes'] == 1) {
                send_email_fix_to_user($userid, $emailtext, $Build, $Project);
            }
        }
    }
    // No error we return
    if (!$errors['errors']) {
        return;
    }
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/sendemail.php')) {
        $sendEmail->BuildId = $Build->Id;
        $sendEmail->Errors = $errors;
    }
    // If we should send a summary email
    if ($BuildGroup->GetSummaryEmail() == 1) {
        // Send the summary email
        sendsummaryemail($projectid, $groupid, $errors, $buildid);
        if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/sendemail.php')) {
            $sendEmail->SendSummary();
        }
        return;
    }
    $Build->FillFromId($Build->Id);
    // Send build error
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/sendemail.php')) {
        $sendEmail->SendBuildError();
    }
    // Lookup the list of people who should get the email, both registered
    // users *and* committers:
    //
    $lookup_result = lookup_emails_to_send($errors, $buildid, $projectid, $Build->Type, false, $emailCommitters);
    // Loop through the *registered* users:
    //
    $userids = $lookup_result['userids'];
    foreach ($userids as $userid) {
        send_error_email($userid, '', $sendEmail, $errors, $Build, $Project);
    }
    // Loop through "other" users, if necessary:
    //
    // ...people who committed code, but are *not* registered CDash users, but
    // only if the 'emailcommitters' field is on for this build group.
    //
    if ($emailCommitters) {
        $committeremails = $lookup_result['committeremails'];
        foreach ($committeremails as $committeremail) {
            send_error_email(0, $committeremail, $sendEmail, $errors, $Build, $Project, getHandlerErrorKeyPrefix($handler));
        }
    }
}
Example #5
0
        return;
    } else {
        // redirect to the install.php script
        $response = array();
        $response['redirect'] = get_server_URI() . '/install.php';
        echo json_encode($response);
        return;
    }
    return;
}
@($projectname = $_GET['project']);
$projectname = htmlspecialchars(pdo_real_escape_string($projectname));
$projectid = get_project_id($projectname);
$Project = new Project();
$Project->Id = $projectid;
$Project->Fill();
@($date = $_GET['date']);
if ($date != null) {
    $date = htmlspecialchars(pdo_real_escape_string($date));
}
echo_main_dashboard_JSON($Project, $date);
// Generate the main dashboard JSON response.
function echo_main_dashboard_JSON($project_instance, $date)
{
    $start = microtime_float();
    $noforcelogin = 1;
    include_once dirname(dirname(dirname(__DIR__))) . '/config/config.php';
    require_once 'include/pdo.php';
    include 'public/login.php';
    include_once 'models/banner.php';
    include_once 'models/build.php';
Example #6
0
 public function GetCTestScript()
 {
     if (!$this->Id || !$this->SiteId) {
         add_log('ClientJobSchedule:GetCTestScript', 'Id not set');
         return;
     }
     include 'config/config.php';
     // Update the current run
     pdo_query("UPDATE client_jobschedule SET lastrun='" . date(FMT_DATETIMESTD) . "' WHERE id=" . qnum($this->Id));
     $ClientSite = new ClientSite();
     $ClientSite->Id = $this->SiteId;
     // Create a job
     $job = new ClientJob();
     $job->ScheduleId = $this->Id;
     $job->StartDate = date('Y-m-d H:i:s');
     $job->EndDate = date('1980-01-01 00:00:00');
     $job->Status = CDASH_JOB_RUNNING;
     $job->SiteId = $this->SiteId;
     $job->OsId = $ClientSite->GetOS();
     // Determine the appropriate CMake id (get the newest version)
     $cmake = pdo_query('SELECT sc.cmakeid FROM client_cmake,client_site2cmake AS sc
                   LEFT JOIN client_jobschedule2cmake AS jc ON (jc.cmakeid=sc.cmakeid)
                   WHERE client_cmake.id=sc.cmakeid AND sc.siteid=' . $this->SiteId . '
                   ORDER BY client_cmake.version DESC LIMIT 1');
     $cmake_array = pdo_fetch_array($cmake);
     $job->CMakeId = $cmake_array[0];
     // Determine the appropriate compiler
     $compiler = pdo_query('SELECT sc.compilerid FROM client_compiler,client_site2compiler AS sc
                      LEFT JOIN client_jobschedule2compiler AS jc ON (jc.compilerid=sc.compilerid)
                      WHERE client_compiler.id=sc.compilerid AND sc.siteid=' . $this->SiteId . '
                      ORDER BY client_compiler.version DESC LIMIT 1');
     $compiler_array = pdo_fetch_array($compiler);
     $job->CompilerId = $compiler_array[0];
     $job->Save();
     $Project = new Project();
     $Project->Id = $this->GetProjectId();
     $Project->Fill();
     $compiler = new ClientCompiler();
     $compiler->Id = $job->CompilerId;
     $os = new ClientOS();
     $os->Id = $job->OsId;
     // Initialize the variables
     $buildtype = 'Experimental';
     //default
     switch ($this->GetType()) {
         case CDASH_JOB_EXPERIMENTAL:
             $buildtype = 'Experimental';
             break;
         case CDASH_JOB_NIGHTLY:
             $buildtype = 'Nightly';
             break;
         case CDASH_JOB_CONTINUOUS:
             $buildtype = 'Continuous';
             break;
     }
     $ctest_script = '#' . $this->Id . "\n";
     $ctest_script .= '#' . $Project->Name . "\n";
     $ctest_script .= 'SET(JOB_BUILDTYPE ' . $buildtype . ')' . "\n";
     $ctest_script .= 'SET(PROJECT_NAME "' . $Project->Name . '")' . "\n";
     if (strlen($this->GetModule()) > 0) {
         $ctest_script .= 'SET(JOB_MODULE "' . $this->GetModule() . '")' . "\n";
     }
     if (strlen($this->GetTag()) > 0) {
         $ctest_script .= 'SET(JOB_TAG "' . $this->GetTag() . '")' . "\n";
     }
     if (strlen($this->GetBuildNameSuffix()) > 0) {
         $ctest_script .= 'SET(JOB_BUILDNAME_SUFFIX "' . $this->GetBuildNameSuffix() . '")' . "\n";
     }
     $ctest_script .= 'SET(JOB_CMAKE_GENERATOR "' . $ClientSite->GetCompilerGenerator($job->CompilerId) . '")' . "\n";
     $ctest_script .= 'SET(JOB_BUILD_CONFIGURATION "' . $this->BuildConfigurations[$this->GetBuildConfiguration()] . '")' . "\n";
     $ctest_script .= 'SET(CLIENT_BASE_DIRECTORY "' . $ClientSite->GetBaseDirectory() . '")' . "\n";
     $ctest_script .= 'SET(CLIENT_CMAKE_PATH "' . $ClientSite->GetCMakePath($job->CMakeId) . '")' . "\n";
     $ctest_script .= 'SET(CLIENT_SITE "' . $ClientSite->GetName() . '")' . "\n";
     $ctest_script .= 'SET(JOB_OS_NAME "' . $os->GetName() . '")' . "\n";
     $ctest_script .= 'SET(JOB_OS_VERSION "' . $os->GetVersion() . '")' . "\n";
     $ctest_script .= 'SET(JOB_OS_BITS "' . $os->GetBits() . '")' . "\n";
     $ctest_script .= 'SET(JOB_COMPILER_NAME "' . $compiler->GetName() . '")' . "\n";
     $ctest_script .= 'SET(JOB_COMPILER_VERSION "' . $compiler->GetVersion() . '")' . "\n";
     $ctest_script .= 'SET(JOB_REPOSITORY "' . $this->GetRepository() . '")' . "\n";
     // Set the program variables
     $programs = $ClientSite->GetPrograms();
     $currentname = '';
     foreach ($programs as $program) {
         $program_name = strtoupper($program['name']);
         $program_version = str_replace('.', '_', strtoupper($program['version']));
         if ($program['name'] != $currentname) {
             $ctest_script .= 'SET(CLIENT_EXECUTABLE_' . $program_name . ' "' . $program['path'] . '")' . "\n";
             $currentname = $program['name'];
         }
         $ctest_script .= 'SET(CLIENT_EXECUTABLE_' . $program_name . '_' . $program_version . ' "' . $program['path'] . '")' . "\n";
     }
     if ($CDASH_USE_HTTPS === true) {
         $ctest_script .= 'set(CTEST_DROP_METHOD "https")' . "\n";
     } else {
         $ctest_script .= 'set(CTEST_DROP_METHOD "http")' . "\n";
     }
     $serverName = $CDASH_SERVER_NAME;
     if (strlen($serverName) == 0) {
         $serverName = $_SERVER['SERVER_NAME'];
     }
     $ctest_script .= 'set(CTEST_DROP_SITE "' . $serverName . '")' . "\n";
     $dropLocation = dirname($_SERVER['PHP_SELF']) . '/submit.php?project=' . urlencode($Project->Name);
     $dropLocation .= '&clientscheduleid=' . $this->Id;
     $ctest_script .= 'set(CTEST_DROP_LOCATION "' . $dropLocation . '")' . "\n";
     $ctest_script .= 'set(JOB_DROP_LOCATION "' . $dropLocation . '")' . "\n";
     $ctest_script .= 'set(JOB_DROP_SITE "' . $serverName . '")' . "\n";
     $ctest_script .= 'set(CTEST_DROP_SITE_CDASH TRUE)' . "\n";
     $ctest_script .= 'set(CTEST_NOTES_FILES ${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME})' . "\n";
     // Make the cache available
     $ctest_script .= 'set(JOB_INITIAL_CACHE "' . $this->GetCMakeCache() . '\\n")' . "\n";
     // Set the macro to warn CDash that the script failed
     $ctest_script .= "\n" . 'MACRO(JOB_FAILED)' . "\n";
     $uri = $_SERVER['REQUEST_URI'];
     $pos = strpos($uri, 'submit.php');
     if ($pos !== false) {
         $uri = substr($uri, 0, $pos + 10);
     }
     $ctest_script .= '  file(DOWNLOAD "${CTEST_DROP_METHOD}://${CTEST_DROP_SITE}' . $uri . '?siteid=' . $this->SiteId . '&jobfailed=1" "${CLIENT_BASE_DIRECTORY}/scriptfailed.txt")' . "\n";
     $ctest_script .= '  return()' . "\n";
     $ctest_script .= 'ENDMACRO(JOB_FAILED)' . "\n\n";
     if (strlen(trim($this->GetClientScript())) > 0) {
         $ctest_script .= $this->GetClientScript();
     } elseif (strlen($Project->CTestTemplateScript) > 0) {
         $ctest_script .= $Project->CTestTemplateScript;
     } else {
         $ctest_script .= $Project->getDefaultJobTemplateScript();
     }
     return $ctest_script;
 }
Example #7
0
$response = begin_JSON_response();
$response['title'] = 'CDash : Compare Coverage';
$response['showcalendar'] = 1;
// Check if a valid project was specified.
$projectname = $_GET['project'];
$projectname = htmlspecialchars(pdo_real_escape_string($projectname));
$projectid = get_project_id($projectname);
if ($projectid < 1) {
    $response['error'] = 'This project does not exist. Maybe the URL you are trying to access is wrong.';
    echo json_encode($response);
    http_response_code(400);
    return;
}
$project_instance = new Project();
$project_instance->Id = $projectid;
$project_instance->Fill();
@($date = $_GET['date']);
if ($date != null) {
    $date = htmlspecialchars(pdo_real_escape_string($date));
}
$logged_in = false;
if (isset($_SESSION['cdash']) && isset($_SESSION['cdash']['loginid'])) {
    $logged_in = true;
}
if (!checkUserPolicy(@$_SESSION['cdash']['loginid'], $projectid, 1)) {
    if ($logged_in) {
        $response['error'] = 'You do not have permission to access this page.';
        echo json_encode($response);
        http_response_code(403);
    } else {
        $response['requirelogin'] = 1;
Example #8
0
 /** Function endElement */
 public function endElement($parser, $name)
 {
     $parent = $this->getParent();
     // should be before endElement
     parent::endElement($parser, $name);
     if ($this->UploadError) {
         return;
     }
     if ($name == 'FILE' && $parent == 'UPLOAD') {
         $this->UploadFile->BuildId = $this->BuildId;
         // Close base64 temporary file writing handler
         fclose($this->Base64TmpFileWriteHandle);
         unset($this->Base64TmpFileWriteHandle);
         // Decode file using 'read by chunk' approach to minimize memory footprint
         // Note: Using stream_filter_append/stream_copy_to_stream is more efficient but
         // return an "invalid byte sequence" on windows
         $rhandle = fopen($this->Base64TmpFilename, 'r');
         $whandle = fopen($this->TmpFilename, 'w+');
         $chunksize = 4096;
         while (!feof($rhandle)) {
             fwrite($whandle, base64_decode(fread($rhandle, $chunksize)));
         }
         fclose($rhandle);
         unset($rhandle);
         fclose($whandle);
         unset($whandle);
         // Delete base64 encoded file
         $success = cdash_unlink($this->Base64TmpFilename);
         if (!$success) {
             add_log("Failed to delete file '" . $this->Base64TmpFilename . "'", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_WARNING);
         }
         // Check file size against the upload quota
         $upload_file_size = filesize($this->TmpFilename);
         $Project = new Project();
         $Project->Id = $this->projectid;
         $Project->Fill();
         if ($upload_file_size > $Project->UploadQuota) {
             add_log("Size of uploaded file {$this->TmpFilename} is {$upload_file_size} bytes, which is greater " . "than the total upload quota for this project ({$Project->UploadQuota} bytes)", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR);
             $this->UploadError = true;
             cdash_unlink($this->TmpFilename);
             return;
         }
         // Compute SHA1 of decoded file
         $upload_file_sha1 = sha1_file($this->TmpFilename);
         // TODO Check if a file if same buildid, sha1 and name has already been uploaded
         $this->UploadFile->Sha1Sum = $upload_file_sha1;
         $this->UploadFile->Filesize = $upload_file_size;
         // Extension of the file indicates if it's a data file that should be hosted on CDash of if
         // an URL should just be considered. File having extension ".url" are expected to contain an URL.
         $path_parts = pathinfo($this->UploadFile->Filename);
         $ext = $path_parts['extension'];
         if ($ext == "url") {
             $this->UploadFile->IsUrl = true;
             // Read content of the file
             $url_length = 255;
             // max length of 'uploadfile.filename' field
             $this->UploadFile->Filename = trim(file_get_contents($this->TmpFilename, NULL, NULL, 0, $url_length));
             cdash_unlink($this->TmpFilename);
             //add_log("this->UploadFile->Filename '".$this->UploadFile->Filename."'", __FILE__.':'.__LINE__.' - '.__FUNCTION__, LOG_INFO);
         } else {
             $this->UploadFile->IsUrl = false;
             $upload_dir = realpath($GLOBALS['CDASH_UPLOAD_DIRECTORY']);
             if (!$upload_dir) {
                 add_log("realpath cannot resolve CDASH_UPLOAD_DIRECTORY '" . $GLOBALS['CDASH_UPLOAD_DIRECTORY'] . "' with cwd '" . getcwd() . "'", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_WARNING);
             }
             $upload_dir .= '/' . $this->UploadFile->Sha1Sum;
             $uploadfilepath = $upload_dir . '/' . $this->UploadFile->Sha1Sum;
             // Check if upload directory should be created
             if (!file_exists($upload_dir)) {
                 $success = mkdir($upload_dir);
                 if (!$success) {
                     add_log("Failed to create directory '" . $upload_dir . "'", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR);
                     $this->UploadError = true;
                     return;
                 }
             }
             // Check if file has already been referenced
             if (!file_exists($uploadfilepath)) {
                 $success = rename($this->TmpFilename, $uploadfilepath);
                 if (!$success) {
                     add_log("Failed to rename file '" . $this->TmpFilename . "' into '" . $uploadfilepath . "'", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR);
                     $this->UploadError = true;
                     return;
                 }
             } else {
                 // Delete decoded temporary file since it has already been addressed
                 $success = cdash_unlink($this->TmpFilename);
                 if (!$success) {
                     add_log("Failed to delete file '" . $this->TmpFilename . "'", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_WARNING);
                 }
             }
             // Generate symlink name
             $symlinkName = $path_parts['basename'];
             // Check if symlink should be created
             $createSymlink = !file_exists($upload_dir . '/' . $symlinkName);
             if ($createSymlink) {
                 // Create symlink
                 if (function_exists("symlink")) {
                     $success = symlink($uploadfilepath, $upload_dir . '/' . $symlinkName);
                 } else {
                     $success = 0;
                 }
                 if (!$success) {
                     // Log actual non-testing symlink failure as an error:
                     $level = LOG_ERR;
                     // But if testing, log as info only:
                     if ($GLOBALS['CDASH_TESTING_MODE']) {
                         $level = LOG_INFO;
                     }
                     add_log("Failed to create symlink [target:'" . $uploadfilepath . "', name: '" . $upload_dir . '/' . $symlinkName . "']", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, $level);
                     // Fall back to a full copy if symlink does not exist, or if it failed:
                     $success = copy($uploadfilepath, $upload_dir . '/' . $symlinkName);
                     if (!$success) {
                         add_log("Failed to copy file (symlink fallback) [target:'" . $uploadfilepath . "', name: '" . $upload_dir . '/' . $symlinkName . "']", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR);
                         $this->UploadError = true;
                         return;
                     }
                 }
             }
         }
         // Update model
         $success = $this->UploadFile->Insert();
         if (!$success) {
             add_log("UploadFile model - Failed to insert row associated with file: '" . $this->UploadFile->Filename . "'", __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR);
         }
         $Project->CullUploadedFiles();
         // Reset UploadError so that the handler could attempt to process following files
         $this->UploadError = false;
     }
 }
Example #9
0
/** Find changes for a "version only" update. */
function perform_version_only_diff($update, $projectid)
{
    // Return early if we don't have a current revision.
    if (empty($update->Revision)) {
        return;
    }
    // Return early if this project doesn't have a remote repository viewer.
    require_once 'models/buildupdate.php';
    require_once 'models/project.php';
    $project = new Project();
    $project->Id = $projectid;
    $project->Fill();
    if (strlen($project->CvsUrl) === 0 || strlen($project->CvsViewerType) === 0) {
        return;
    }
    // Return early if we don't have an implementation for this repository viewer.
    $viewertype = strtolower($project->CvsViewerType);
    $function_name = 'perform_' . $viewertype . '_version_only_diff';
    if (!function_exists($function_name)) {
        return;
    }
    // Return early if we don't have a previous build to compare against.
    require_once 'models/build.php';
    $build = new Build();
    $build->Id = $update->BuildId;
    $previous_buildid = $build->GetPreviousBuildId();
    if ($previous_buildid < 1) {
        return;
    }
    // Get the revision for the previous build.
    $pdo = get_link_identifier()->getPdo();
    $stmt = $pdo->prepare('SELECT revision FROM buildupdate AS bu
            INNER JOIN build2update AS b2u ON (b2u.updateid=bu.id)
            WHERE b2u.buildid=?');
    $stmt->execute(array($previous_buildid));
    $row = $stmt->fetch();
    if (empty($row) || !isset($row['revision'])) {
        return;
    }
    $previous_revision = $row['revision'];
    if (empty($previous_revision)) {
        return;
    }
    // Record the previous revision in the buildupdate table.
    $stmt = $pdo->prepare('UPDATE buildupdate SET priorrevision=? WHERE id=?');
    $stmt->execute(array($previous_revision, $update->UpdateId));
    // Call the implementation specific to this repository viewer.
    $update->Append = true;
    return $function_name($project, $update, $previous_revision);
}