Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use CDash\Database;
use CDash\Model\BuildUpdate;
use CDash\Model\Project;
use CDash\Model\Site;
use CDash\Model\SubProject;
use Exception;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -76,13 +75,11 @@ public function viewUpdatePageContent(): JsonResponse
$response['menu'] = $menu_response;

// Build
$site = new Site();
$site->Id = $build->SiteId;
$site_name = $site->GetName();
$site = $build->GetSite();

$build_response = [];
$build_response['site'] = $site_name;
$build_response['siteid'] = $site->Id;
$build_response['site'] = $site->name;
$build_response['siteid'] = $site->id;
$build_response['buildname'] = $build->Name;
$build_response['buildid'] = $build->Id;
$build_response['buildtime'] = date('D, d M Y H:i:s T', strtotime($build->StartTime . ' UTC'));
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/BuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
use App\Services\TestingDay;
use CDash\Database;
use CDash\Model\Build;
use CDash\Model\Site;
use App\Models\Site;
use CDash\Model\Project;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;

Expand Down Expand Up @@ -225,8 +226,7 @@ public function viewFiles(): View|RedirectResponse

$this->setBuildById((int) $_GET['buildid']);

$Site = new Site();
$Site->Id = $this->build->SiteId;
$Site = $this->build->GetSite();

@$date = $_GET['date'];
if ($date != null) {
Expand All @@ -246,8 +246,8 @@ public function viewFiles(): View|RedirectResponse
$xml .= '<buildid>' . $this->build->Id . '</buildid>';
$xml .= '<buildname>' . $this->build->Name . '</buildname>';
$xml .= '<buildstarttime>' . $this->build->StartTime . '</buildstarttime>';
$xml .= '<siteid>' . $Site->Id . '</siteid>';
$xml .= '<sitename>' . $Site->GetName() . '</sitename>';
$xml .= '<siteid>' . $Site->id . '</siteid>';
$xml .= '<sitename>' . $Site->name . '</sitename>';

$uploadFilesOrURLs = $this->build->GetUploadedFilesOrUrls();

Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/CoverageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use CDash\Model\CoverageFileLog;
use CDash\Model\CoverageSummary;
use CDash\Model\Project;
use CDash\Model\Site;
use CDash\Model\UserProject;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -293,9 +292,7 @@ public function manageCoverage(): View|RedirectResponse
$Build->FillFromId($Build->Id);
$xml .= '<build>';
$xml .= add_XML_value('id', $buildId);
$Site = new Site();
$Site->Id = $Build->SiteId;
$xml .= add_XML_value('name', $Site->GetName() . '-' . $Build->GetName() . ' [' . gmdate(FMT_DATETIME, strtotime($Build->StartTime)) . ']');
$xml .= add_XML_value('name', $Build->GetSite()->name . '-' . $Build->GetName() . ' [' . gmdate(FMT_DATETIME, strtotime($Build->StartTime)) . ']');
if ($buildid > 0 && $buildId == $buildid) {
$xml .= add_XML_value('selected', 1);
}
Expand Down
20 changes: 11 additions & 9 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use CDash\Model\BuildConfigure;
use CDash\Model\BuildUpdate;
use CDash\Model\Project;
use CDash\Model\Site;
use App\Models\Site;
use CDash\Model\UserProject;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
Expand Down Expand Up @@ -117,22 +118,23 @@ public function userPageContent(): JsonResponse
pdo_execute($stmt, [$userid]);
$query_params = [];
while ($row = $stmt->fetch()) {
$siteid = intval($row['siteid']);
$Site = new Site();
$Site->Id = $siteid;
$Site->Fill();
try {
$Site = Site::findOrFail($row['siteid']);
} catch (ModelNotFoundException $e) {
abort(500, 'Invalid relation between site2user and site tables.');
}

$site_response = [];
$site_response['id'] = $Site->Id;
$site_response['name'] = $Site->Name;
$site_response['outoforder'] = $Site->OutOfOrder;
$site_response['id'] = $Site->id;
$site_response['name'] = $Site->name;
$site_response['outoforder'] = $Site->outoforder;
$claimedsites[] = $site_response;

if (strlen($siteidwheresql) > 0) {
$siteidwheresql .= ' OR ';
}
$siteidwheresql .= " siteid=? ";
$query_params[] = $siteid;
$query_params[] = $Site->id;
}

// Look for all the projects
Expand Down
89 changes: 89 additions & 0 deletions app/Models/Site.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Models;

use CDash\Config;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Facades\DB;

/**
* @property int $id
* @property string $name
* @property string $ip
* @property string $latitude
* @property string $longitude
* @property int $outoforder
* @property SiteInformation $mostRecentInformation
*
* @mixin Builder<Site>
*/
class Site extends Model
{
protected $table = 'site';

public $timestamps = false;

protected $fillable = [
'name',
'ip',
'latitude',
'longitude',
'outoforder',
];

/**
* @return HasMany<SiteInformation>
*/
public function information(): HasMany
{
return $this->hasMany(SiteInformation::class, 'siteid');
}

/**
* Get the most recent information available
*
* @return HasOne<SiteInformation>
*/
public function mostRecentInformation(): HasOne
{
return $this->hasOne(SiteInformation::class, 'siteid')->ofMany('timestamp', 'max');
}

public function save(array $options = []): bool
{
if (strlen($this->ip) === 0) {
$this->LookupIP();
}

// Get the geolocation
if (strlen($this->latitude) === 0) {
$location = get_geolocation($this->ip);
$this->latitude = $location['latitude'];
$this->longitude = $location['longitude'];
}

return parent::save($options);
}

private function LookupIP(): void
{
global $PHP_ERROR_SUBMISSION_ID;
$submission_id = $PHP_ERROR_SUBMISSION_ID;

$config = Config::getInstance();
// In the async case, look up the IP recorded when the file was
// originally submitted...
if ($submission_id) {
$this->ip = DB::select('SELECT ip FROM submission2ip WHERE submissionid = ?', [$submission_id])[0]->ip;
} elseif ($config->get('CDASH_REMOTE_ADDR')) {
$this->ip = $config->get('CDASH_REMOTE_ADDR');
} elseif (!empty($_SERVER['REMOTE_ADDR'])) {
$this->ip = $_SERVER['REMOTE_ADDR'];
} else {
$this->ip = '';
}
}
}
104 changes: 104 additions & 0 deletions app/Models/SiteInformation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property string $timestamp
* @property int $processoris64bits
* @property string $processorvendor
* @property string $processorvendorid
* @property int $processorfamilyid
* @property int $processormodelid
* @property int $processorcachesize
* @property int $numberlogicalcpus
* @property int $numberphysicalcpus
* @property int $totalvirtualmemory
* @property int $totalphysicalmemory
* @property int $logicalprocessorsperphysical
* @property int $processorclockfrequency
* @property string $description
* @property int $siteid
*
* @mixin Builder<SiteInformation>
*/
class SiteInformation extends Model
{
protected $table = 'siteinformation';

public $timestamps = false;

protected $fillable = [
'timestamp',
'processoris64bits',
'processorvendor',
'processorvendorid',
'processorfamilyid',
'processormodelid',
'processorcachesize',
'numberlogicalcpus',
'numberphysicalcpus',
'totalvirtualmemory',
'totalphysicalmemory',
'logicalprocessorsperphysical',
'processorclockfrequency',
'description',
'siteid',
];

/**
* @return BelongsTo<Site, self>
*/
public function site(): BelongsTo
{
return $this->belongsTo('App\Models\Site', 'id');
}

public function SetValue(string $tag, string|int $value): void
{
switch ($tag) {
case 'DESCRIPTION':
$this->description = $value;
break;
case 'IS64BITS':
$this->processoris64bits = (int) $value;
break;
case 'VENDORSTRING':
$this->processorvendor = $value;
break;
case 'VENDORID':
$this->processorvendorid = $value;
break;
case 'FAMILYID':
$this->processorfamilyid = (int) $value;
break;
case 'MODELID':
$this->processormodelid = (int) $value;
break;
case 'PROCESSORCACHESIZE':
$this->processorcachesize = (int) $value;
break;
case 'NUMBEROFLOGICALCPU':
$this->numberlogicalcpus = (int) $value;
break;
case 'NUMBEROFPHYSICALCPU':
$this->numberphysicalcpus = (int) $value;
break;
case 'TOTALVIRTUALMEMORY':
$this->totalvirtualmemory = (int) $value;
break;
case 'TOTALPHYSICALMEMORY':
$this->totalphysicalmemory = (int) $value;
break;
case 'LOGICALPROCESSORSPERPHYSICAL':
$this->logicalprocessorsperphysical = (int) $value;
break;
case 'PROCESSORCLOCKFREQUENCY':
$this->processorclockfrequency = (int) $value;
break;
}
}
}
8 changes: 2 additions & 6 deletions app/Services/UnparsedSubmissionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
namespace App\Services;

use App\Jobs\ProcessSubmission;
use App\Services\AuthTokenService;
use CDash\Model\Build;
use CDash\Model\BuildFile;
use CDash\Model\PendingSubmissions;
use CDash\Model\Project;
use CDash\Model\Site;
use App\Models\Site;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
Expand Down Expand Up @@ -185,10 +184,7 @@ public function initializeBuild()
$this->build->SetStamp($this->buildstamp);

// Get the site id
$site = new Site();
$site->Name = $this->sitename;
$site->Insert();
$this->build->SiteId = $site->Id;
$this->build->SiteId = Site::firstOrCreate(['name' => $this->sitename])->id;

// Make this an "append" build, so that it doesn't result in a separate row
// from the rest of the "normal" submission.
Expand Down
13 changes: 4 additions & 9 deletions app/cdash/app/Controller/Api/TestDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
namespace CDash\Controller\Api;

use App\Models\BuildTest;
use App\Models\Test;
use App\Models\TestOutput;

use CDash\Database;
use CDash\Model\Build;
use CDash\Model\Project;
use CDash\Model\Site;
use App\Models\Site;

require_once 'include/repository.php';

Expand Down Expand Up @@ -59,9 +56,7 @@ public function getResponse()

$response = begin_JSON_response();

$site = new Site();
$site->Id = $this->build->SiteId;
$site->Fill();
$site = $this->build->GetSite();

$this->setDate($this->build->GetDate());

Expand Down Expand Up @@ -127,8 +122,8 @@ public function getResponse()
$test_response['buildid'] = $this->build->Id;
$test_response['build'] = $this->build->Name;
$test_response['buildstarttime'] = date(FMT_DATETIMESTD, strtotime($this->build->StartTime . ' UTC'));
$test_response['site'] = $site->Name;
$test_response['siteid'] = $site->Id;
$test_response['site'] = $site->name;
$test_response['siteid'] = $site->id;
$test_response['test'] = $testName;
$test_response['time'] = time_difference($testRow['time'], true, '', true);
$test_response['command'] = $testRow['command'];
Expand Down
6 changes: 0 additions & 6 deletions app/cdash/app/Controller/Api/TestGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@
namespace CDash\Controller\Api;

use App\Models\BuildTest;
use App\Models\Test;
use App\Models\TestOutput;

use CDash\Database;
use CDash\Model\Build;
use CDash\Model\Project;
use CDash\Model\Site;

require_once 'include/api_common.php';

Expand Down
Loading