From 856cbfa5e8b13ba026f3a4d78dd086a8c8386569 Mon Sep 17 00:00:00 2001
From: William Allen <16820599+williamjallen@users.noreply.github.com>
Date: Wed, 31 May 2023 21:00:13 -0400
Subject: [PATCH 1/2] Convert `SiteInformation` class to Eloquent
---
app/Models/SiteInformation.php | 89 +++++++
app/cdash/app/Model/Site.php | 9 +-
app/cdash/app/Model/SiteInformation.php | 217 ------------------
.../tests/case/CDash/TestUseCaseTest.php | 26 +--
app/cdash/xml_handlers/build_handler.php | 4 +-
app/cdash/xml_handlers/configure_handler.php | 4 +-
app/cdash/xml_handlers/coverage_handler.php | 2 +-
.../xml_handlers/coverage_junit_handler.php | 2 +-
.../xml_handlers/dynamic_analysis_handler.php | 4 +-
app/cdash/xml_handlers/note_handler.php | 2 +-
app/cdash/xml_handlers/testing_handler.php | 4 +-
.../xml_handlers/testing_junit_handler.php | 2 +-
app/cdash/xml_handlers/upload_handler.php | 2 +-
..._31_215559_siteinformation_primary_key.php | 31 +++
phpstan-baseline.neon | 109 ---------
15 files changed, 150 insertions(+), 357 deletions(-)
create mode 100644 app/Models/SiteInformation.php
delete mode 100644 app/cdash/app/Model/SiteInformation.php
create mode 100644 database/migrations/2023_05_31_215559_siteinformation_primary_key.php
diff --git a/app/Models/SiteInformation.php b/app/Models/SiteInformation.php
new file mode 100644
index 0000000000..06e49b302b
--- /dev/null
+++ b/app/Models/SiteInformation.php
@@ -0,0 +1,89 @@
+ '1980-01-01 00:00:00',
+ 'processoris64bits' => -1,
+ 'processorvendor' => -1,
+ 'processorvendorid' => -1,
+ 'processorfamilyid' => -1,
+ 'processormodelid' => -1,
+ 'processorcachesize' => -1,
+ 'numberlogicalcpus' => -1,
+ 'numberphysicalcpus' => -1,
+ 'totalvirtualmemory' => -1,
+ 'totalphysicalmemory' => -1,
+ 'logicalprocessorsperphysical' => -1,
+ 'processorclockfrequency' => -1,
+ 'description' => '',
+ 'siteid' => 0,
+ ];
+
+ public function save(array $options = [])
+ {
+ $this->processorcachesize = round($this->processorcachesize);
+ $this->numberlogicalcpus = round($this->numberlogicalcpus);
+ $this->numberphysicalcpus = round($this->numberphysicalcpus);
+ $this->totalphysicalmemory = round($this->totalphysicalmemory);
+ $this->logicalprocessorsperphysical = round($this->logicalprocessorsperphysical);
+ $this->processorclockfrequency = round($this->processorclockfrequency);
+
+ parent::save($options);
+ }
+
+ public function SetValue(string $tag, string|int $value): void
+ {
+ switch ($tag) {
+ case 'DESCRIPTION':
+ $this->description = $value;
+ break;
+ case 'IS64BITS':
+ $this->processoris64bits = $value;
+ break;
+ case 'VENDORSTRING':
+ $this->processorvendor = $value;
+ break;
+ case 'VENDORID':
+ $this->processorvendorid = $value;
+ break;
+ case 'FAMILYID':
+ $this->processorfamilyid = $value;
+ break;
+ case 'MODELID':
+ $this->processormodelid = $value;
+ break;
+ case 'PROCESSORCACHESIZE':
+ $this->processorcachesize = $value;
+ break;
+ case 'NUMBEROFLOGICALCPU':
+ $this->numberlogicalcpus = $value;
+ break;
+ case 'NUMBEROFPHYSICALCPU':
+ $this->numberphysicalcpus = $value;
+ break;
+ case 'TOTALVIRTUALMEMORY':
+ $this->totalvirtualmemory = $value;
+ break;
+ case 'TOTALPHYSICALMEMORY':
+ $this->totalphysicalmemory = $value;
+ break;
+ case 'LOGICALPROCESSORSPERPHYSICAL':
+ $this->logicalprocessorsperphysical = $value;
+ break;
+ case 'PROCESSORCLOCKFREQUENCY':
+ $this->processorclockfrequency = $value;
+ break;
+ }
+ }
+}
diff --git a/app/cdash/app/Model/Site.php b/app/cdash/app/Model/Site.php
index 92225268cc..b1b6974bd7 100644
--- a/app/cdash/app/Model/Site.php
+++ b/app/cdash/app/Model/Site.php
@@ -15,6 +15,8 @@
=========================================================================*/
namespace CDash\Model;
+use App\Models\SiteInformation;
+
use CDash\Config;
use CDash\Database;
@@ -40,13 +42,10 @@ public function __construct()
$this->PDO = Database::getInstance()->getPdo();
}
- /**
- * @param SiteInformation $information
- */
public function SetInformation(SiteInformation $information)
{
- $information->SiteId = $this->Id;
- $information->Save();
+ $information->siteid = $this->Id;
+ $information->save();
$this->Information = $information;
}
diff --git a/app/cdash/app/Model/SiteInformation.php b/app/cdash/app/Model/SiteInformation.php
deleted file mode 100644
index 7c38bc3b03..0000000000
--- a/app/cdash/app/Model/SiteInformation.php
+++ /dev/null
@@ -1,217 +0,0 @@
-TimeStamp = '1980-01-01 00:00:00';
- $this->ProcessorIs64Bits = -1;
- $this->ProcessorVendor = -1;
- $this->ProcessorVendorId = -1;
- $this->ProcessorFamilyId = -1;
- $this->ProcessorModelId = -1;
- $this->ProcessorCacheSize = -1;
- $this->NumberLogicalCpus = -1;
- $this->NumberPhysicalCpus = -1;
- $this->TotalVirtualMemory = -1;
- $this->TotalPhysicalMemory = -1;
- $this->LogicalProcessorsPerPhysical = -1;
- $this->ProcessorClockFrequency = -1;
- $this->Description = '';
- $this->SiteId = 0;
- }
-
- public function SetValue(string $tag, $value): void
- {
- switch ($tag) {
- case 'DESCRIPTION':
- $this->Description = $value;
- break;
- case 'IS64BITS':
- $this->ProcessorIs64Bits = $value;
- break;
- case 'VENDORSTRING':
- $this->ProcessorVendor = $value;
- break;
- case 'VENDORID':
- $this->ProcessorVendorId = $value;
- break;
- case 'FAMILYID':
- $this->ProcessorFamilyId = $value;
- break;
- case 'MODELID':
- $this->ProcessorModelId = $value;
- break;
- case 'PROCESSORCACHESIZE':
- $this->ProcessorCacheSize = $value;
- break;
- case 'NUMBEROFLOGICALCPU':
- $this->NumberLogicalCpus = $value;
- break;
- case 'NUMBEROFPHYSICALCPU':
- $this->NumberPhysicalCpus = $value;
- break;
- case 'TOTALVIRTUALMEMORY':
- $this->TotalVirtualMemory = $value;
- break;
- case 'TOTALPHYSICALMEMORY':
- $this->TotalPhysicalMemory = $value;
- break;
- case 'LOGICALPROCESSORSPERPHYSICAL':
- $this->LogicalProcessorsPerPhysical = $value;
- break;
- case 'PROCESSORCLOCKFREQUENCY':
- $this->ProcessorClockFrequency = $value;
- break;
- }
- }
-
- /** Check if the site already exists */
- public function Exists(): bool
- {
- // If no id specify return false
- if (!$this->SiteId) {
- return false;
- }
-
- $db = Database::getInstance();
-
- $query = $db->executePreparedSingleRow('
- SELECT count(*) AS c
- FROM siteinformation
- WHERE siteid=?
- ', [intval($this->SiteId)]);
- if (intval($query['c']) === 0) {
- return false;
- }
- return true;
- }
-
- /** Save the site information */
- public function Save()
- {
- $db = Database::getInstance();
- if ($this->Exists()) {
- // Update the project
- $query = $db->executePrepared('
- UPDATE siteinformation
- SET
- timestamp=?,
- processoris64bits=?,
- processorvendor=?,
- processorvendorid=?,
- processorfamilyid=?,
- processormodelid=?,
- processorcachesize=?,
- numberlogicalcpus=?,
- numberphysicalcpus=?,
- totalvirtualmemory=?,
- totalphysicalmemory=?,
- logicalprocessorsperphysical=?,
- processorclockfrequency=?,
- description=?
- WHERE siteid=?
- ', [
- $this->TimeStamp,
- $this->ProcessorIs64Bits,
- $this->ProcessorVendor,
- $this->ProcessorVendorId,
- $this->ProcessorFamilyId,
- $this->ProcessorModelId,
- round($this->ProcessorCacheSize),
- round($this->NumberLogicalCpus),
- round($this->NumberPhysicalCpus),
- $this->TotalVirtualMemory,
- round($this->TotalPhysicalMemory),
- round($this->LogicalProcessorsPerPhysical),
- round($this->ProcessorClockFrequency),
- $this->Description,
- intval($this->SiteId)
- ]);
-
- if ($query === false) {
- add_last_sql_error('SiteInformation Update');
- return false;
- }
- } else {
- $query = $db->executePrepared('
- INSERT INTO siteinformation (
- siteid,
- timestamp,
- processoris64bits,
- processorvendor,
- processorvendorid,
- processorfamilyid,
- processormodelid,
- processorcachesize,
- numberlogicalcpus,
- numberphysicalcpus,
- totalvirtualmemory,
- totalphysicalmemory,
- logicalprocessorsperphysical,
- processorclockfrequency,
- description
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- ', [
- intval($this->SiteId),
- $this->TimeStamp,
- $this->ProcessorIs64Bits,
- $this->ProcessorVendor,
- $this->ProcessorVendorId,
- intval($this->ProcessorFamilyId),
- intval($this->ProcessorModelId),
- round($this->ProcessorCacheSize),
- round($this->NumberLogicalCpus),
- round($this->NumberPhysicalCpus),
- round($this->TotalVirtualMemory),
- round($this->TotalPhysicalMemory),
- round($this->LogicalProcessorsPerPhysical),
- round($this->ProcessorClockFrequency),
- $this->Description
- ]);
-
- if ($query === false) {
- add_last_sql_error('SiteInformation Insert');
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/app/cdash/tests/case/CDash/TestUseCaseTest.php b/app/cdash/tests/case/CDash/TestUseCaseTest.php
index 560979c301..99954d3c7b 100644
--- a/app/cdash/tests/case/CDash/TestUseCaseTest.php
+++ b/app/cdash/tests/case/CDash/TestUseCaseTest.php
@@ -70,38 +70,38 @@ public function testTestUseCaseCreatesBuildAndSiteInformation()
$site = $build->getSite();
$information = $site->GetInformation();
- $this->assertEquals($information->Description, $siteInformation['Description']);
- $this->assertEquals($information->ProcessorIs64Bits, $siteInformation['Is64Bits']);
- $this->assertEquals($information->ProcessorVendor, $siteInformation['VendorString']);
- $this->assertEquals($information->ProcessorVendorId, $siteInformation['VendorID']);
- $this->assertEquals($information->ProcessorFamilyId, $siteInformation['FamilyID']);
- $this->assertEquals($information->ProcessorModelId, $siteInformation['ModelID']);
+ $this->assertEquals($information->description, $siteInformation['Description']);
+ $this->assertEquals($information->processoris64bits, $siteInformation['Is64Bits']);
+ $this->assertEquals($information->processorvendor, $siteInformation['VendorString']);
+ $this->assertEquals($information->processorvendorid, $siteInformation['VendorID']);
+ $this->assertEquals($information->processorfamilyid, $siteInformation['FamilyID']);
+ $this->assertEquals($information->processormodelid, $siteInformation['ModelID']);
$this->assertEquals(
- $information->ProcessorCacheSize,
+ $information->processorcachesize,
$siteInformation['ProcessorCacheSize']
);
$this->assertEquals(
- $information->NumberLogicalCpus,
+ $information->numberlogicalcpus,
$siteInformation['NumberOfLogicalCPU']
);
$this->assertEquals(
- $information->NumberPhysicalCpus,
+ $information->numberphysicalcpus,
$siteInformation['NumberOfPhysicalCPU']
);
$this->assertEquals(
- $information->TotalVirtualMemory,
+ $information->totalvirtualmemory,
$siteInformation['TotalVirtualMemory']
);
$this->assertEquals(
- $information->TotalPhysicalMemory,
+ $information->totalphysicalmemory,
$siteInformation['TotalPhysicalMemory']
);
$this->assertEquals(
- $information->LogicalProcessorsPerPhysical,
+ $information->logicalprocessorsperphysical,
$siteInformation['LogicalProcessorsPerPhysical']
);
$this->assertEquals(
- $information->ProcessorClockFrequency,
+ $information->processorclockfrequency,
$siteInformation['ProcessorClockFrequency']
);
$this->assertEquals($build->Information->OSName, $siteInformation['OSName']);
diff --git a/app/cdash/xml_handlers/build_handler.php b/app/cdash/xml_handlers/build_handler.php
index e124f0fe1f..ee72bf119f 100644
--- a/app/cdash/xml_handlers/build_handler.php
+++ b/app/cdash/xml_handlers/build_handler.php
@@ -33,7 +33,7 @@
use CDash\Model\Label;
use CDash\Model\Project;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
use CDash\Model\SubscriberInterface;
use CDash\Submission\CommitAuthorHandlerInterface;
use CDash\Submission\CommitAuthorHandlerTrait;
@@ -87,7 +87,7 @@ public function startElement($parser, $name, $attributes)
}
$this->Site->Insert();
- $siteInformation = $factory->create(SiteInformation::class);
+ $siteInformation = new SiteInformation();
$this->BuildInformation = $factory->create(BuildInformation::class);
$this->BuildName = "";
$this->BuildStamp = "";
diff --git a/app/cdash/xml_handlers/configure_handler.php b/app/cdash/xml_handlers/configure_handler.php
index 5f0ac6ecc8..5bcec916a4 100644
--- a/app/cdash/xml_handlers/configure_handler.php
+++ b/app/cdash/xml_handlers/configure_handler.php
@@ -31,7 +31,7 @@
use CDash\Model\BuildInformation;
use CDash\Model\Label;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
use CDash\Collection\BuildCollection;
use CDash\Model\SubscriberInterface;
@@ -77,7 +77,7 @@ public function startElement($parser, $name, $attributes)
}
$this->Site->Insert();
- $siteInformation = $this->ModelFactory->create(SiteInformation::class);
+ $siteInformation = new SiteInformation;
$this->BuildInformation = $this->ModelFactory->create(BuildInformation::class);
$this->BuildName = "";
$this->BuildStamp = "";
diff --git a/app/cdash/xml_handlers/coverage_handler.php b/app/cdash/xml_handlers/coverage_handler.php
index d726041bd5..34dee17d3f 100644
--- a/app/cdash/xml_handlers/coverage_handler.php
+++ b/app/cdash/xml_handlers/coverage_handler.php
@@ -24,7 +24,7 @@
use CDash\Model\Label;
use CDash\Model\Project;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
use CDash\Model\SubProject;
class CoverageHandler extends AbstractHandler
diff --git a/app/cdash/xml_handlers/coverage_junit_handler.php b/app/cdash/xml_handlers/coverage_junit_handler.php
index 5618dac04a..37acf162ca 100644
--- a/app/cdash/xml_handlers/coverage_junit_handler.php
+++ b/app/cdash/xml_handlers/coverage_junit_handler.php
@@ -23,7 +23,7 @@
use CDash\Model\CoverageSummary;
use CDash\Model\Label;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
class CoverageJUnitHandler extends AbstractHandler
{
diff --git a/app/cdash/xml_handlers/dynamic_analysis_handler.php b/app/cdash/xml_handlers/dynamic_analysis_handler.php
index 4a121adcdb..0151f17d94 100644
--- a/app/cdash/xml_handlers/dynamic_analysis_handler.php
+++ b/app/cdash/xml_handlers/dynamic_analysis_handler.php
@@ -30,7 +30,7 @@
use CDash\Model\DynamicAnalysis;
use CDash\Model\DynamicAnalysisSummary;
use CDash\Model\DynamicAnalysisDefect;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
use CDash\Model\BuildInformation;
use CDash\Model\SubscriberInterface;
@@ -75,7 +75,7 @@ public function startElement($parser, $name, $attributes)
}
$this->Site->Insert();
- $siteInformation = $factory->create(SiteInformation::class);
+ $siteInformation = new SiteInformation();
$this->BuildInformation = $factory->create(BuildInformation::class);
// Fill in the attribute
diff --git a/app/cdash/xml_handlers/note_handler.php b/app/cdash/xml_handlers/note_handler.php
index 2d3bd27374..a70783e4e7 100644
--- a/app/cdash/xml_handlers/note_handler.php
+++ b/app/cdash/xml_handlers/note_handler.php
@@ -23,7 +23,7 @@
use CDash\Model\BuildInformation;
use CDash\Model\BuildNote;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
class NoteHandler extends AbstractHandler
{
diff --git a/app/cdash/xml_handlers/testing_handler.php b/app/cdash/xml_handlers/testing_handler.php
index 2bac886cba..28f3977836 100644
--- a/app/cdash/xml_handlers/testing_handler.php
+++ b/app/cdash/xml_handlers/testing_handler.php
@@ -22,7 +22,7 @@
use CDash\Model\Label;
use CDash\Model\Project;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
use CDash\Model\SubscriberInterface;
use CDash\Submission\CommitAuthorHandlerInterface;
use CDash\Submission\CommitAuthorHandlerTrait;
@@ -88,7 +88,7 @@ public function startElement($parser, $name, $attributes)
}
$this->Site->Insert();
- $siteInformation = $factory->create(SiteInformation::class);
+ $siteInformation = new SiteInformation;
$this->BuildInformation = $factory->create(BuildInformation::class);
$this->BuildName = "";
$this->BuildStamp = "";
diff --git a/app/cdash/xml_handlers/testing_junit_handler.php b/app/cdash/xml_handlers/testing_junit_handler.php
index 92d65b66aa..262fb3e4f1 100644
--- a/app/cdash/xml_handlers/testing_junit_handler.php
+++ b/app/cdash/xml_handlers/testing_junit_handler.php
@@ -21,7 +21,7 @@
use CDash\Model\Build;
use CDash\Model\BuildInformation;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
class TestingJUnitHandler extends AbstractHandler
{
diff --git a/app/cdash/xml_handlers/upload_handler.php b/app/cdash/xml_handlers/upload_handler.php
index 2cf69be011..3887eb03bf 100644
--- a/app/cdash/xml_handlers/upload_handler.php
+++ b/app/cdash/xml_handlers/upload_handler.php
@@ -22,7 +22,7 @@
use CDash\Model\BuildInformation;
use CDash\Model\Label;
use CDash\Model\Site;
-use CDash\Model\SiteInformation;
+use App\Models\SiteInformation;
use CDash\Model\Project;
use CDash\Model\UploadFile;
diff --git a/database/migrations/2023_05_31_215559_siteinformation_primary_key.php b/database/migrations/2023_05_31_215559_siteinformation_primary_key.php
new file mode 100644
index 0000000000..53d2e910fb
--- /dev/null
+++ b/database/migrations/2023_05_31_215559_siteinformation_primary_key.php
@@ -0,0 +1,31 @@
+integer('id', true);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('siteinformation', function (Blueprint $table) {
+ $table->dropColumn('id');
+ });
+ }
+};
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index cf916a892a..742e875cbf 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -8463,115 +8463,6 @@ parameters:
count: 1
path: app/cdash/app/Model/Site.php
- -
- message: """
- #^Call to deprecated function add_last_sql_error\\(\\)\\:
- 04/22/2023$#
- """
- count: 2
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: """
- #^Call to deprecated method executePrepared\\(\\) of class CDash\\\\Database\\:
- 04/22/2023 Use Laravel query builder or Eloquent instead$#
- """
- count: 2
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: """
- #^Call to deprecated method executePreparedSingleRow\\(\\) of class CDash\\\\Database\\:
- 04/22/2023 Use Laravel query builder or Eloquent instead$#
- """
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Method CDash\\\\Model\\\\SiteInformation\\:\\:Save\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Method CDash\\\\Model\\\\SiteInformation\\:\\:SetValue\\(\\) has parameter \\$value with no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$Description has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$LogicalProcessorsPerPhysical has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$NumberLogicalCpus has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$NumberPhysicalCpus has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$ProcessorCacheSize has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$ProcessorClockFrequency has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$ProcessorFamilyId has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$ProcessorIs64Bits has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$ProcessorModelId has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$ProcessorVendor has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$ProcessorVendorId has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$SiteId has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$TimeStamp has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$TotalPhysicalMemory has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
- -
- message: "#^Property CDash\\\\Model\\\\SiteInformation\\:\\:\\$TotalVirtualMemory has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/SiteInformation.php
-
-
message: """
#^Call to deprecated function add_last_sql_error\\(\\)\\:
From 7b1263c8566afee35b30faad9de6418cefd5f7c6 Mon Sep 17 00:00:00 2001
From: William Allen <16820599+williamjallen@users.noreply.github.com>
Date: Wed, 31 May 2023 23:22:44 -0400
Subject: [PATCH 2/2] Convert `Site` class to Eloquent
---
app/Http/Controllers/AdminController.php | 9 +-
app/Http/Controllers/BuildController.php | 10 +-
app/Http/Controllers/CoverageController.php | 5 +-
app/Http/Controllers/UserController.php | 20 +-
app/Models/Site.php | 89 +++++++
app/Models/SiteInformation.php | 89 ++++---
app/Services/UnparsedSubmissionProcessor.php | 8 +-
app/cdash/app/Controller/Api/TestDetails.php | 13 +-
app/cdash/app/Controller/Api/TestGraph.php | 6 -
app/cdash/app/Controller/Api/ViewNotes.php | 5 +-
app/cdash/app/Controller/Api/ViewTest.php | 4 +-
app/cdash/app/Model/Build.php | 11 +-
app/cdash/app/Model/Site.php | 247 ------------------
.../Messaging/Subscription/Subscription.php | 11 +-
app/cdash/include/Test/CDashTestCase.php | 2 +-
app/cdash/include/common.php | 36 ++-
app/cdash/include/sendemail.php | 6 +-
app/cdash/public/api/v1/addBuild.php | 8 +-
app/cdash/public/api/v1/buildgroup.php | 9 +-
app/cdash/public/api/v1/manageBuildGroup.php | 7 +-
app/cdash/public/api/v1/viewBuildError.php | 7 +-
app/cdash/public/api/v1/viewConfigure.php | 8 +-
.../public/api/v1/viewDynamicAnalysis.php | 8 +-
.../public/api/v1/viewDynamicAnalysisFile.php | 7 +-
app/cdash/public/submit.php | 9 +-
app/cdash/tests/CMakeLists.txt | 1 -
.../CommitAuthorSubscriptionBuilderTest.php | 2 +-
.../UserSubscriptionBuilderTest.php | 3 +-
.../tests/case/CDash/TestUseCaseTest.php | 6 +-
app/cdash/tests/test_donehandler.php | 12 +-
app/cdash/tests/test_indexnextprevious.php | 7 +-
app/cdash/tests/test_putdynamicbuilds.php | 10 +-
app/cdash/tests/test_sitemodel.php | 137 ----------
app/cdash/xml_handlers/abstract_handler.php | 6 +-
.../actionable_build_interface.php | 2 +-
app/cdash/xml_handlers/build_handler.php | 16 +-
app/cdash/xml_handlers/configure_handler.php | 16 +-
app/cdash/xml_handlers/coverage_handler.php | 13 +-
.../xml_handlers/coverage_junit_handler.php | 13 +-
.../xml_handlers/coverage_log_handler.php | 12 +-
app/cdash/xml_handlers/done_handler.php | 2 +-
.../xml_handlers/dynamic_analysis_handler.php | 14 +-
app/cdash/xml_handlers/note_handler.php | 13 +-
app/cdash/xml_handlers/testing_handler.php | 14 +-
.../xml_handlers/testing_junit_handler.php | 26 +-
app/cdash/xml_handlers/update_handler.php | 13 +-
app/cdash/xml_handlers/upload_handler.php | 13 +-
phpstan-baseline.neon | 183 ++-----------
48 files changed, 311 insertions(+), 857 deletions(-)
create mode 100644 app/Models/Site.php
delete mode 100644 app/cdash/app/Model/Site.php
delete mode 100644 app/cdash/tests/test_sitemodel.php
diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php
index d5b971aadb..bc568368c3 100644
--- a/app/Http/Controllers/AdminController.php
+++ b/app/Http/Controllers/AdminController.php
@@ -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;
@@ -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'));
diff --git a/app/Http/Controllers/BuildController.php b/app/Http/Controllers/BuildController.php
index a41519a43d..60b2a55c96 100644
--- a/app/Http/Controllers/BuildController.php
+++ b/app/Http/Controllers/BuildController.php
@@ -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;
@@ -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) {
@@ -246,8 +246,8 @@ public function viewFiles(): View|RedirectResponse
$xml .= '' . $this->build->Id . '';
$xml .= '' . $this->build->Name . '';
$xml .= '' . $this->build->StartTime . '';
- $xml .= '' . $Site->Id . '';
- $xml .= '' . $Site->GetName() . '';
+ $xml .= '' . $Site->id . '';
+ $xml .= '' . $Site->name . '';
$uploadFilesOrURLs = $this->build->GetUploadedFilesOrUrls();
diff --git a/app/Http/Controllers/CoverageController.php b/app/Http/Controllers/CoverageController.php
index 88067e6707..5181b6c730 100644
--- a/app/Http/Controllers/CoverageController.php
+++ b/app/Http/Controllers/CoverageController.php
@@ -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;
@@ -293,9 +292,7 @@ public function manageCoverage(): View|RedirectResponse
$Build->FillFromId($Build->Id);
$xml .= '';
$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);
}
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 611d3ba1dc..b961aca7cd 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -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;
@@ -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
diff --git a/app/Models/Site.php b/app/Models/Site.php
new file mode 100644
index 0000000000..27f5c0f5ae
--- /dev/null
+++ b/app/Models/Site.php
@@ -0,0 +1,89 @@
+
+ */
+class Site extends Model
+{
+ protected $table = 'site';
+
+ public $timestamps = false;
+
+ protected $fillable = [
+ 'name',
+ 'ip',
+ 'latitude',
+ 'longitude',
+ 'outoforder',
+ ];
+
+ /**
+ * @return HasMany
+ */
+ public function information(): HasMany
+ {
+ return $this->hasMany(SiteInformation::class, 'siteid');
+ }
+
+ /**
+ * Get the most recent information available
+ *
+ * @return HasOne
+ */
+ 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 = '';
+ }
+ }
+}
diff --git a/app/Models/SiteInformation.php b/app/Models/SiteInformation.php
index 06e49b302b..a025e3081b 100644
--- a/app/Models/SiteInformation.php
+++ b/app/Models/SiteInformation.php
@@ -2,44 +2,59 @@
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
+ */
class SiteInformation extends Model
{
protected $table = 'siteinformation';
-// const CREATED_AT = 'timestamp';
- const CREATED_AT = null;
- const UPDATED_AT = null;
+ public $timestamps = false;
protected $fillable = [
- 'timestamp' => '1980-01-01 00:00:00',
- 'processoris64bits' => -1,
- 'processorvendor' => -1,
- 'processorvendorid' => -1,
- 'processorfamilyid' => -1,
- 'processormodelid' => -1,
- 'processorcachesize' => -1,
- 'numberlogicalcpus' => -1,
- 'numberphysicalcpus' => -1,
- 'totalvirtualmemory' => -1,
- 'totalphysicalmemory' => -1,
- 'logicalprocessorsperphysical' => -1,
- 'processorclockfrequency' => -1,
- 'description' => '',
- 'siteid' => 0,
+ 'timestamp',
+ 'processoris64bits',
+ 'processorvendor',
+ 'processorvendorid',
+ 'processorfamilyid',
+ 'processormodelid',
+ 'processorcachesize',
+ 'numberlogicalcpus',
+ 'numberphysicalcpus',
+ 'totalvirtualmemory',
+ 'totalphysicalmemory',
+ 'logicalprocessorsperphysical',
+ 'processorclockfrequency',
+ 'description',
+ 'siteid',
];
- public function save(array $options = [])
+ /**
+ * @return BelongsTo
+ */
+ public function site(): BelongsTo
{
- $this->processorcachesize = round($this->processorcachesize);
- $this->numberlogicalcpus = round($this->numberlogicalcpus);
- $this->numberphysicalcpus = round($this->numberphysicalcpus);
- $this->totalphysicalmemory = round($this->totalphysicalmemory);
- $this->logicalprocessorsperphysical = round($this->logicalprocessorsperphysical);
- $this->processorclockfrequency = round($this->processorclockfrequency);
-
- parent::save($options);
+ return $this->belongsTo('App\Models\Site', 'id');
}
public function SetValue(string $tag, string|int $value): void
@@ -49,7 +64,7 @@ public function SetValue(string $tag, string|int $value): void
$this->description = $value;
break;
case 'IS64BITS':
- $this->processoris64bits = $value;
+ $this->processoris64bits = (int) $value;
break;
case 'VENDORSTRING':
$this->processorvendor = $value;
@@ -58,31 +73,31 @@ public function SetValue(string $tag, string|int $value): void
$this->processorvendorid = $value;
break;
case 'FAMILYID':
- $this->processorfamilyid = $value;
+ $this->processorfamilyid = (int) $value;
break;
case 'MODELID':
- $this->processormodelid = $value;
+ $this->processormodelid = (int) $value;
break;
case 'PROCESSORCACHESIZE':
- $this->processorcachesize = $value;
+ $this->processorcachesize = (int) $value;
break;
case 'NUMBEROFLOGICALCPU':
- $this->numberlogicalcpus = $value;
+ $this->numberlogicalcpus = (int) $value;
break;
case 'NUMBEROFPHYSICALCPU':
- $this->numberphysicalcpus = $value;
+ $this->numberphysicalcpus = (int) $value;
break;
case 'TOTALVIRTUALMEMORY':
- $this->totalvirtualmemory = $value;
+ $this->totalvirtualmemory = (int) $value;
break;
case 'TOTALPHYSICALMEMORY':
- $this->totalphysicalmemory = $value;
+ $this->totalphysicalmemory = (int) $value;
break;
case 'LOGICALPROCESSORSPERPHYSICAL':
- $this->logicalprocessorsperphysical = $value;
+ $this->logicalprocessorsperphysical = (int) $value;
break;
case 'PROCESSORCLOCKFREQUENCY':
- $this->processorclockfrequency = $value;
+ $this->processorclockfrequency = (int) $value;
break;
}
}
diff --git a/app/Services/UnparsedSubmissionProcessor.php b/app/Services/UnparsedSubmissionProcessor.php
index e99c3496d6..39651d0164 100644
--- a/app/Services/UnparsedSubmissionProcessor.php
+++ b/app/Services/UnparsedSubmissionProcessor.php
@@ -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;
@@ -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.
diff --git a/app/cdash/app/Controller/Api/TestDetails.php b/app/cdash/app/Controller/Api/TestDetails.php
index 9469277e4d..31fc139f05 100644
--- a/app/cdash/app/Controller/Api/TestDetails.php
+++ b/app/cdash/app/Controller/Api/TestDetails.php
@@ -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';
@@ -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());
@@ -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'];
diff --git a/app/cdash/app/Controller/Api/TestGraph.php b/app/cdash/app/Controller/Api/TestGraph.php
index 38ff0c94c6..fcc3b85171 100644
--- a/app/cdash/app/Controller/Api/TestGraph.php
+++ b/app/cdash/app/Controller/Api/TestGraph.php
@@ -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';
diff --git a/app/cdash/app/Controller/Api/ViewNotes.php b/app/cdash/app/Controller/Api/ViewNotes.php
index 2395516648..a0db40cfdc 100644
--- a/app/cdash/app/Controller/Api/ViewNotes.php
+++ b/app/cdash/app/Controller/Api/ViewNotes.php
@@ -17,13 +17,10 @@
namespace CDash\Controller\Api;
use App\Models\BuildNote;
-use App\Models\Note;
use App\Services\TestingDay;
use CDash\Database;
use CDash\Model\Build;
-use CDash\Model\Site;
-use CDash\Model\Project;
class ViewNotes extends BuildApi
{
@@ -70,7 +67,7 @@ public function getResponse()
$response['menu'] = $menu;
// Build/site info.
- $site_name = $this->build->GetSite()->GetName();
+ $site_name = $this->build->GetSite()->name;
$response['build'] = Build::MarshalResponseArray($this->build, ['site' => $site_name]);
// Notes for this build.
diff --git a/app/cdash/app/Controller/Api/ViewTest.php b/app/cdash/app/Controller/Api/ViewTest.php
index 0da9b2377a..6cbe245914 100644
--- a/app/cdash/app/Controller/Api/ViewTest.php
+++ b/app/cdash/app/Controller/Api/ViewTest.php
@@ -22,8 +22,6 @@
use CDash\Database;
use CDash\Model\Build;
use CDash\Model\BuildInformation;
-use CDash\Model\Site;
-use CDash\Model\Project;
require_once 'include/filterdataFunctions.php';
@@ -160,7 +158,7 @@ public function getResponse()
$build_response = Build::MarshalResponseArray($this->build, [
'displaylabels' => $this->project->DisplayLabels,
- 'site' => $this->build->GetSite()->GetName(),
+ 'site' => $this->build->GetSite()->name,
'testtime' => $this->build->EndTime,
]);
diff --git a/app/cdash/app/Model/Build.php b/app/cdash/app/Model/Build.php
index 2087d76340..7805ed1ecb 100644
--- a/app/cdash/app/Model/Build.php
+++ b/app/cdash/app/Model/Build.php
@@ -2532,24 +2532,19 @@ public static function GetSubProjectBuild($parentid, $subprojectid)
/**
* Returns the current Build's Site property. This method lazily loads the Site if no such
* object exists.
- *
- * @return Site
*/
- public function GetSite()
+ public function GetSite(): \App\Models\Site
{
if (!$this->Site) {
- $this->Site = new Site();
- $this->Site->Id = $this->SiteId;
+ $this->Site = \App\Models\Site::find($this->SiteId);
}
return $this->Site;
}
/**
* Sets the current Build's Site property.
- *
- * @param Site $site
*/
- public function SetSite(Site $site)
+ public function SetSite(\App\Models\Site $site)
{
$this->Site = $site;
}
diff --git a/app/cdash/app/Model/Site.php b/app/cdash/app/Model/Site.php
deleted file mode 100644
index b1b6974bd7..0000000000
--- a/app/cdash/app/Model/Site.php
+++ /dev/null
@@ -1,247 +0,0 @@
-Ip = '';
- $this->Latitude = '';
- $this->Longitude = '';
- $this->OutOfOrder = 0;
- $this->Filled = false;
- $this->PDO = Database::getInstance()->getPdo();
- }
-
- public function SetInformation(SiteInformation $information)
- {
- $information->siteid = $this->Id;
- $information->save();
- $this->Information = $information;
- }
-
- /**
- * @return SiteInformation
- */
- public function GetInformation()
- {
- return $this->Information;
- }
-
- /** Check if the site already exists */
- public function Exists()
- {
- // If no id or name were specified return false.
- if (!$this->Id && !$this->Name) {
- return false;
- }
-
- if ($this->Id) {
- $stmt = $this->PDO->prepare(
- 'SELECT COUNT(*) AS c FROM site WHERE id = ?');
- pdo_execute($stmt, [$this->Id]);
- if ($stmt->fetchColumn() > 0) {
- return true;
- }
- }
- $stmt = $this->PDO->prepare(
- 'SELECT id FROM site WHERE name = :name');
- pdo_execute($stmt, [':name' => $this->Name]);
- $id = $stmt->fetchColumn();
- if ($id !== false) {
- $this->Id = $id;
- return true;
- }
- return false;
- }
-
- /** Update a site */
- public function Update()
- {
- if (!$this->Exists()) {
- return false;
- }
-
- // Update the site.
- $stmt = $this->PDO->prepare(
- 'UPDATE site
- SET name = :name, ip = :ip, latitude = :latitude,
- longitude = :longitude, outoforder = :outoforder
- WHERE id= :id');
- $stmt->bindParam(':name', $this->Name);
- $stmt->bindParam(':ip', $this->Ip);
- $stmt->bindParam(':latitude', $this->Latitude);
- $stmt->bindParam(':longitude', $this->Longitude);
- $stmt->bindParam(':outoforder', $this->OutOfOrder);
- $stmt->bindParam(':id', $this->Id);
-
- try {
- if ($stmt->execute()) {
- return true;
- }
- // The UPDATE statement didn't execute cleanly.
- $error_info = $stmt->errorInfo();
- $error = $error_info[2];
- throw new \Exception($error);
- } catch (\Exception $e) {
- // This error might be due to a unique key violation.
- // Check for an existing site with this name.
- $site = new Site();
- $site->Name = $this->Name;
- if ($site->Exists()) {
- $this->Id = $site->Id;
- return true;
- }
-
- // Otherwise log the error and return false.
- add_log($e->getMessage() . PHP_EOL . $e->getTraceAsString(),
- 'Site::Update', LOG_ERR);
- return false;
- }
- }
-
- public function LookupIP()
- {
- 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) {
- $stmt = $this->PDO->prepare(
- 'SELECT ip FROM submission2ip WHERE submissionid = ?');
- pdo_execute($stmt, [$submission_id]);
- $this->Ip = $stmt->fetchColumn();
- } 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 = '';
- }
- }
-
- /** Insert a new site */
- public function Insert()
- {
- // Don't attempt to save a Site that doesn't have a name.
- if (!$this->Name) {
- return false;
- }
-
- $justSetIP = false;
-
- if (strlen($this->Ip) == 0) {
- $this->LookupIP();
- $justSetIP = true;
- }
-
- if ($this->Exists()) {
- if ($justSetIP) {
- $this->Update();
- }
- return $this->Id;
- }
-
- // Get the geolocation
- if (strlen($this->Latitude) == 0) {
- $location = get_geolocation($this->Ip);
- $this->Latitude = $location['latitude'];
- $this->Longitude = $location['longitude'];
- }
-
- $stmt = $this->PDO->prepare(
- 'INSERT INTO site (name, ip, latitude, longitude)
- VALUES (:name, :ip, :latitude, :longitude)');
- $stmt->bindParam(':name', $this->Name);
- $stmt->bindParam(':ip', $this->Ip);
- $stmt->bindParam(':latitude', $this->Latitude);
- $stmt->bindParam(':longitude', $this->Longitude);
- try {
- if ($stmt->execute()) {
- $this->Id = pdo_insert_id('site');
- return true;
- }
- // The INSERT statement didn't execute cleanly.
- $error_info = $stmt->errorInfo();
- $error = $error_info[2];
- throw new \Exception($error);
- } catch (\Exception $e) {
- // This error might be due to a unique constraint violation.
- // Query for a previously existing site with this name.
- $site = new Site();
- $site->Name = $this->Name;
- if ($site->Exists()) {
- $this->Id = $site->Id;
- return true;
- }
- // Otherwise log the error and return false.
- add_log($e->getMessage() . PHP_EOL . $e->getTraceAsString(),
- 'Site::Update', LOG_ERR);
- return false;
- }
- }
-
- // Get the name of this site.
- public function GetName()
- {
- if (!$this->Fill()) {
- return false;
- }
- return $this->Name;
- }
-
- public function Fill()
- {
- if ($this->Filled) {
- return true;
- }
- if (!$this->Id) {
- add_log('Id not set', 'Site::Fill', LOG_ERR);
- return false;
- }
- $stmt = $this->PDO->prepare(
- 'SELECT * FROM site WHERE id = ?');
- if (!pdo_execute($stmt, [$this->Id])) {
- return false;
- }
- $row = $stmt->fetch();
- $this->Name = $row['name'];
- $this->Ip = $row['ip'];
- $this->Latitude = $row['latitude'];
- $this->Longitude = $row['longitude'];
- $this->OutOfOrder = $row['outoforder'];
- $this->Filled = true;
- return true;
- }
-}
diff --git a/app/cdash/include/Messaging/Subscription/Subscription.php b/app/cdash/include/Messaging/Subscription/Subscription.php
index a08c4d1b6b..3765688594 100644
--- a/app/cdash/include/Messaging/Subscription/Subscription.php
+++ b/app/cdash/include/Messaging/Subscription/Subscription.php
@@ -2,12 +2,11 @@
namespace CDash\Messaging\Subscription;
use CDash\Config;
-use CDash\Messaging\Notification\NotificationInterface;
use CDash\Messaging\Topic\TopicCollection;
use CDash\Model\Build;
use CDash\Model\BuildGroup;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\SubscriberInterface;
class Subscription implements SubscriptionInterface
@@ -92,11 +91,7 @@ public function getProject()
return $this->project;
}
- /**
- * @param Site $site
- * @return $this
- */
- public function setSite(Site $site)
+ public function setSite(Site $site): self
{
$this->site = $site;
return $this;
@@ -155,7 +150,7 @@ public function getBuildSummary()
$summary['build_group'] = $this->buildGroup->GetName();
$summary['project_name'] = $project->GetName();
$summary['project_url'] = "{$baseUrl}/index.php?project={$project->Name}";
- $summary['site_name'] = $this->site->Name;
+ $summary['site_name'] = $this->site->name;
$summary['build_name'] = '';
$summary['build_subproject_names'] = [];
$summary['labels'] = [];
diff --git a/app/cdash/include/Test/CDashTestCase.php b/app/cdash/include/Test/CDashTestCase.php
index 0dd7e2ea77..9a31fec091 100644
--- a/app/cdash/include/Test/CDashTestCase.php
+++ b/app/cdash/include/Test/CDashTestCase.php
@@ -21,7 +21,7 @@
use CDash\Model\Build;
use CDash\Model\BuildGroup;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\UserProject;
use CDash\ServiceContainer;
use DI\Container;
diff --git a/app/cdash/include/common.php b/app/cdash/include/common.php
index 65ff9199be..e055522b83 100644
--- a/app/cdash/include/common.php
+++ b/app/cdash/include/common.php
@@ -18,8 +18,6 @@
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
-use App\Http\Controllers\Auth\LoginController;
-use App\Services\ProjectPermissions;
use App\Services\TestingDay;
use CDash\Config;
@@ -28,7 +26,7 @@
use CDash\Model\Build;
use CDash\Model\Project;
use CDash\Model\UserProject;
-use CDash\Model\Site;
+use App\Models\Site;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
@@ -483,12 +481,11 @@ function update_site($siteid, $name,
$description, $ip, $latitude, $longitude, $nonewrevision = false,
$outoforder = 0)
{
- require_once 'include/pdo.php';
-
// Security checks
if (!is_numeric($siteid)) {
return;
}
+ $siteid = (int) $siteid;
$db = Database::getInstance();
@@ -513,11 +510,13 @@ function update_site($siteid, $name,
$description = pdo_real_escape_string($description);
// Update the basic information first
- $db->executePrepared('
- UPDATE site
- SET name=?, ip=? latitude=?, longitude=?, outoforder=?
- WHERE id=?
- ', [$name, $ip, $latitude, $longitude, $outoforder, $siteid]);
+ Site::findOrFail($siteid)->where([
+ 'name' => $name,
+ 'ip' => $ip,
+ 'latitude' => $latitude,
+ 'longitude' => $longitude,
+ 'outoforder' => $outoforder
+ ]);
add_last_sql_error('update_site');
@@ -1828,18 +1827,13 @@ function cast_data_for_JSON($value)
* Get the site ID for 'CDash Server'.
* This is the site associated with Aggregate Coverage builds.
*/
-function get_server_siteid()
+function get_server_siteid(): int
{
- $server = new Site();
- $server->Name = 'CDash Server';
- if (!$server->Exists()) {
- // Create it if it doesn't exist.
- // SERVER_ADDR is not guaranteed to exist on every web server
- $server_ip = @$_SERVER['SERVER_ADDR'];
- $server->Ip = $server_ip;
- $server->Insert();
- }
- return intval($server->Id);
+ $server = Site::firstOrCreate(['name' => 'CDash Server'], [
+ 'name' => 'CDash Server',
+ 'ip' => $_SERVER['SERVER_ADDR'] ?? '',
+ ]);
+ return $server->id;
}
/**
diff --git a/app/cdash/include/sendemail.php b/app/cdash/include/sendemail.php
index e805303add..46b81ad36a 100644
--- a/app/cdash/include/sendemail.php
+++ b/app/cdash/include/sendemail.php
@@ -30,7 +30,6 @@
use CDash\Model\BuildUpdate;
use CDash\Model\DynamicAnalysis;
use CDash\Model\Project;
-use CDash\Model\Site;
/** Check for errors for a given build. Return false if no errors */
function check_email_errors(int $buildid, bool $checktesttimeingchanged, int $testtimemaxstatus, bool $checkpreviouserrors): array
@@ -453,10 +452,9 @@ function generate_broken_build_message(array $emailtext, $Build, $Project): arra
$body .= 'SubProject: ' . $Build->GetSubProjectName() . "\n";
}
- $Site = new Site();
- $Site->Id = $Build->SiteId;
+ $Site = $Build->GetSite();
- $body .= 'Site: ' . $Site->GetName() . "\n";
+ $body .= 'Site: ' . $Site->name . "\n";
$body .= 'Build Name: ' . $Build->Name . "\n";
$body .= 'Build Time: ' . date(FMT_DATETIMETZ, strtotime($Build->StartTime . ' UTC')) . "\n";
$body .= 'Type: ' . $Build->Type . "\n";
diff --git a/app/cdash/public/api/v1/addBuild.php b/app/cdash/public/api/v1/addBuild.php
index a5045e7d9c..72f08381b8 100644
--- a/app/cdash/public/api/v1/addBuild.php
+++ b/app/cdash/public/api/v1/addBuild.php
@@ -20,7 +20,7 @@
use App\Services\AuthTokenService;
use CDash\Model\Build;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\ServiceContainer;
use Symfony\Component\HttpFoundation\Response;
@@ -39,17 +39,15 @@
// Get the id of the specified site.
$service = ServiceContainer::getInstance();
-$site = $service->create(Site::class);
$sitename = get_param('site');
-$site->Name = $sitename;
-$site->Insert();
+$site = Site::firstOrCreate(['name' => $sitename], ['name' => $sitename]);
// Populate a Build object with the properties needed to generate a UUID.
$build = $service->create(Build::class);
$build->Name = get_param('name');
$build->SetStamp(get_param('stamp'));
$build->ProjectId = $project->Id;
-$build->SiteId = $site->Id;
+$build->SiteId = $site->id;
$build->StartTime = gmdate(FMT_DATETIME);
$build->SubmitTime = $build->StartTime;
$subProjectName = get_param('subProjectName', false);
diff --git a/app/cdash/public/api/v1/buildgroup.php b/app/cdash/public/api/v1/buildgroup.php
index b3caedaffc..ddf5689b43 100644
--- a/app/cdash/public/api/v1/buildgroup.php
+++ b/app/cdash/public/api/v1/buildgroup.php
@@ -24,7 +24,7 @@
use CDash\Model\Build;
use CDash\Model\BuildGroup;
use CDash\Model\BuildGroupRule;
-use CDash\Model\Site;
+use App\Models\Site;
// Require administrative access to view this page.
init_api_request();
@@ -412,12 +412,11 @@ function rest_put($projectid)
$new_rule->ParentGroupId = $parentgroupid;
}
$sitename = $new_rule_request['site'];
- if ($sitename == 'Any') {
+ if ($sitename === 'Any') {
$siteid = 0;
} else {
- $site = new Site();
- $site->Name = $sitename;
- $siteid = $site->Exists() ? $site->Id : 0;
+ $site = Site::where(['name' => $sitename])->first();
+ $siteid = $site->id ?? 0;
}
if ($siteid > 0) {
$new_rule->SiteId = $siteid;
diff --git a/app/cdash/public/api/v1/manageBuildGroup.php b/app/cdash/public/api/v1/manageBuildGroup.php
index 6461035c38..8ca74f7333 100644
--- a/app/cdash/public/api/v1/manageBuildGroup.php
+++ b/app/cdash/public/api/v1/manageBuildGroup.php
@@ -23,7 +23,7 @@
use CDash\Database;
use CDash\Model\BuildGroup;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\UserProject;
use Illuminate\Support\Facades\Auth;
@@ -187,9 +187,8 @@
}
}
if (!$found) {
- $site = new Site();
- $site->Id = $siteid;
- $rule_response['sitename'] = $site->GetName();
+ $site = Site::find($siteid);
+ $rule_response['sitename'] = $site->name;
}
}
diff --git a/app/cdash/public/api/v1/viewBuildError.php b/app/cdash/public/api/v1/viewBuildError.php
index a6bd85705a..6126002397 100644
--- a/app/cdash/public/api/v1/viewBuildError.php
+++ b/app/cdash/public/api/v1/viewBuildError.php
@@ -43,7 +43,6 @@
use CDash\Model\BuildUpdate;
use CDash\Model\Label;
use CDash\Model\Project;
-use CDash\Model\Site;
use CDash\ServiceContainer;
use PDO;
@@ -75,8 +74,6 @@
$response = begin_JSON_response();
$response['title'] = "CDash : $project->Name";
-$siteid = $build->SiteId;
-
if (isset($_GET['type'])) {
$type = pdo_real_escape_numeric($_GET['type']);
} else {
@@ -114,10 +111,8 @@
$response['menu'] = $menu;
// Site
-$site = $service->get(Site::class);
-$site->Id = $siteid;
$extra_build_fields = [
- 'site' => $site->GetName()
+ 'site' => $build->GetSite()->name
];
// Update
diff --git a/app/cdash/public/api/v1/viewConfigure.php b/app/cdash/public/api/v1/viewConfigure.php
index f92dc301c6..6146f14eca 100644
--- a/app/cdash/public/api/v1/viewConfigure.php
+++ b/app/cdash/public/api/v1/viewConfigure.php
@@ -25,7 +25,6 @@
use CDash\Model\BuildConfigure;
use CDash\Model\Project;
-use CDash\Model\Site;
$pageTimer = new PageTimer();
@@ -89,11 +88,10 @@
$response['configures'] = $configures_response;
// Build
-$site = new Site();
-$site->Id = $build->SiteId;
+$site = $build->GetSite();
$build_response = [];
-$build_response['site'] = $site->GetName();
-$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['hassubprojects'] = $has_subprojects;
diff --git a/app/cdash/public/api/v1/viewDynamicAnalysis.php b/app/cdash/public/api/v1/viewDynamicAnalysis.php
index 976621ce30..753aaf6ec6 100644
--- a/app/cdash/public/api/v1/viewDynamicAnalysis.php
+++ b/app/cdash/public/api/v1/viewDynamicAnalysis.php
@@ -23,7 +23,7 @@
use App\Services\TestingDay;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use Illuminate\Support\Facades\DB;
$pageTimer = new PageTimer();
@@ -87,12 +87,8 @@
$response['menu'] = $menu;
// Build
-$site = new Site();
-$site->Id = $build->SiteId;
-$site_name = $site->GetName();
-
$build_response = [];
-$build_response['site'] = $site_name;
+$build_response['site'] = $build->GetSite()->name;
$build_response['buildname'] = $build->Name;
$build_response['buildid'] = $build->Id;
$build_response['buildtime'] = $build->StartTime;
diff --git a/app/cdash/public/api/v1/viewDynamicAnalysisFile.php b/app/cdash/public/api/v1/viewDynamicAnalysisFile.php
index 82c4998a1d..3ff0453fee 100644
--- a/app/cdash/public/api/v1/viewDynamicAnalysisFile.php
+++ b/app/cdash/public/api/v1/viewDynamicAnalysisFile.php
@@ -26,7 +26,6 @@
use CDash\Model\Build;
use CDash\Model\DynamicAnalysis;
use CDash\Model\Project;
-use CDash\Model\Site;
$pageTimer = new PageTimer();
$response = [];
@@ -70,12 +69,8 @@
$response['title'] = "$project->Name : Dynamic Analysis";
// Build
-$site = new Site();
-$site->Id = $build->SiteId;
-$site_name = $site->GetName();
-
$build_response = [];
-$build_response['site'] = $site_name;
+$build_response['site'] = $build->GetSite()->name;
$build_response['buildname'] = $build->Name;
$build_response['buildid'] = $build->Id;
$build_response['buildtime'] = $build->StartTime;
diff --git a/app/cdash/public/submit.php b/app/cdash/public/submit.php
index dd3277070e..071d026d0f 100644
--- a/app/cdash/public/submit.php
+++ b/app/cdash/public/submit.php
@@ -25,11 +25,9 @@
use CDash\Model\Build;
use CDash\Model\PendingSubmissions;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\ServiceContainer;
-use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Process\InputStream;
$config = Config::getInstance();
$service = ServiceContainer::getInstance();
@@ -220,10 +218,7 @@ function displayReturnStatus($statusarray, $response_code)
$build->SetSubProject(pdo_real_escape_string($_GET['subproject']));
}
- $site = $service->create(Site::class);
- $site->Name = pdo_real_escape_string($_GET['site']);
- $site->Insert();
- $build->SiteId = $site->Id;
+ $build->SiteId = Site::firstOrCreate(['name' => $_GET['site']], ['name' => $_GET['site']])->id;
$pendingSubmissions->Build = $build;
if ($build->AddBuild()) {
diff --git a/app/cdash/tests/CMakeLists.txt b/app/cdash/tests/CMakeLists.txt
index 6f9a29284e..6e0ec3edca 100644
--- a/app/cdash/tests/CMakeLists.txt
+++ b/app/cdash/tests/CMakeLists.txt
@@ -163,7 +163,6 @@ add_php_test(viewmap)
add_php_test(viewsubprojectdependencies)
add_php_test(buildmodel)
-add_php_test(sitemodel)
add_unit_test(/CDash/Model/PendingSubmissions)
add_php_test(projectxmlsequence)
add_php_test(uploadfile)
diff --git a/app/cdash/tests/case/CDash/Messaging/Subscription/CommitAuthorSubscriptionBuilderTest.php b/app/cdash/tests/case/CDash/Messaging/Subscription/CommitAuthorSubscriptionBuilderTest.php
index 8c010a364a..562b0a22b6 100644
--- a/app/cdash/tests/case/CDash/Messaging/Subscription/CommitAuthorSubscriptionBuilderTest.php
+++ b/app/cdash/tests/case/CDash/Messaging/Subscription/CommitAuthorSubscriptionBuilderTest.php
@@ -20,7 +20,7 @@
use CDash\Model\Build;
use CDash\Model\BuildGroup;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Test\BuildDiffForTesting;
use Tests\TestCase;
diff --git a/app/cdash/tests/case/CDash/Messaging/Subscription/UserSubscriptionBuilderTest.php b/app/cdash/tests/case/CDash/Messaging/Subscription/UserSubscriptionBuilderTest.php
index a995df7ef2..55678dfd19 100644
--- a/app/cdash/tests/case/CDash/Messaging/Subscription/UserSubscriptionBuilderTest.php
+++ b/app/cdash/tests/case/CDash/Messaging/Subscription/UserSubscriptionBuilderTest.php
@@ -20,10 +20,9 @@
use CDash\Messaging\Preferences\BitmaskNotificationPreferences;
use CDash\Messaging\Subscription\SubscriptionCollection;
use CDash\Messaging\Subscription\UserSubscriptionBuilder;
-use CDash\Model\Build;
use CDash\Model\BuildGroup;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\Subscriber;
use CDash\Test\BuildDiffForTesting;
use Tests\TestCase;
diff --git a/app/cdash/tests/case/CDash/TestUseCaseTest.php b/app/cdash/tests/case/CDash/TestUseCaseTest.php
index 99954d3c7b..088cee16b5 100644
--- a/app/cdash/tests/case/CDash/TestUseCaseTest.php
+++ b/app/cdash/tests/case/CDash/TestUseCaseTest.php
@@ -2,7 +2,6 @@
use CDash\Model\Build;
use CDash\Collection\BuildCollection;
-use CDash\Model\Site;
use CDash\Test\CDashUseCaseTestCase;
use CDash\Test\UseCase\TestUseCase;
use CDash\Test\UseCase\UseCase;
@@ -65,10 +64,9 @@ public function testTestUseCaseCreatesBuildAndSiteInformation()
->createSite($siteInformation);
$handler = $sut->build();
$builds = $handler->GetBuildCollection();
+ /** @var Build $build */
$build = $builds->current();
- /** @var Site $site */
- $site = $build->getSite();
- $information = $site->GetInformation();
+ $information = $build->GetSite()->mostRecentInformation;
$this->assertEquals($information->description, $siteInformation['Description']);
$this->assertEquals($information->processoris64bits, $siteInformation['Is64Bits']);
diff --git a/app/cdash/tests/test_donehandler.php b/app/cdash/tests/test_donehandler.php
index 465e3cc6f2..3631af3a65 100644
--- a/app/cdash/tests/test_donehandler.php
+++ b/app/cdash/tests/test_donehandler.php
@@ -6,7 +6,8 @@
use CDash\Model\Build;
use CDash\Model\PendingSubmissions;
-use CDash\Model\Site;
+use App\Models\Site;
+use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
class DoneHandlerTestCase extends KWWebTestCase
@@ -49,9 +50,8 @@ private function performTest($remote = false)
$build->Name = $buildname;
$projectid = get_project_id('InsightExample');
$build->ProjectId = $projectid;
- $site = new Site();
- $site->Id = 1;
- $build->SiteId = $site->Id;
+ $site = Site::find(1);
+ $build->SiteId = $site->id;
$stamp = '20181010-1410-Experimental';
$build->SetStamp($stamp);
$timestamp = 1539195000;
@@ -65,7 +65,7 @@ private function performTest($remote = false)
fwrite($handle, "$build->Id");
fclose($handle);
$received_buildid = $this->submission_assign_buildid(
- $tmpfname, 'InsightExample', $buildname, $site->GetName(), $stamp);
+ $tmpfname, 'InsightExample', $buildname, $site->name, $stamp);
if ($remote) {
Artisan::call('queue:work --once');
}
@@ -89,7 +89,7 @@ private function performTest($remote = false)
$pending->Recheck = 1;
$pending->Save();
- $this->submission_assign_buildid($tmpfname, 'InsightExample', $buildname, $site->GetName(), $stamp);
+ $this->submission_assign_buildid($tmpfname, 'InsightExample', $buildname, $site->name, $stamp);
if ($remote) {
foreach (range(0, 5) as $i) {
diff --git a/app/cdash/tests/test_indexnextprevious.php b/app/cdash/tests/test_indexnextprevious.php
index 6df0354b5a..b9f522ac2a 100644
--- a/app/cdash/tests/test_indexnextprevious.php
+++ b/app/cdash/tests/test_indexnextprevious.php
@@ -4,7 +4,7 @@
use CDash\Model\Build;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
class IndexNextPreviousTestCase extends KWWebTestCase
{
@@ -49,9 +49,8 @@ public function testIndexNextPrevious()
$build = new Build();
$build->Name = 'next-previous-build';
$build->ProjectId = $project->Id;
- $site = new Site();
- $site->Id = 1;
- $build->SiteId = $site->Id;
+ $site = Site::find(1);
+ $build->SiteId = $site->id;
$stamp = "$date-1410-$group";
$build->SetStamp($stamp);
$build->StartTime = gmdate(FMT_DATETIME, $timestamp);
diff --git a/app/cdash/tests/test_putdynamicbuilds.php b/app/cdash/tests/test_putdynamicbuilds.php
index 95e8bf0621..5682f1aa34 100644
--- a/app/cdash/tests/test_putdynamicbuilds.php
+++ b/app/cdash/tests/test_putdynamicbuilds.php
@@ -10,7 +10,7 @@
use CDash\Database;
use CDash\Model\BuildGroup;
-use CDash\Model\Site;
+use App\Models\Site;
class PutDynamicBuildsTestCase extends KWWebTestCase
{
@@ -89,17 +89,15 @@ public function testPutDynamicBuildsDiff()
// Verify that we can associate a dynamic build group with a rule that
// hasn't submitted any builds to this project yet.
- $site = new Site();
- $site->Id = 1;
- $site_name = $site->GetName();
+ $site = Site::find(1);
$build_rules = [
- [ 'match' => 'foo', 'parentgroupid' => $this->ParentGroupId, 'site' => $site_name ],
+ [ 'match' => 'foo', 'parentgroupid' => $this->ParentGroupId, 'site' => $site->name],
];
$starttime_stmt = $this->PDO->prepare("
SELECT starttime FROM build2grouprule
WHERE buildname = :buildname AND
parentgroupid = :parentgroupid AND
- siteid = $site->Id");
+ siteid = $site->id");
$this->verifyListGetsCreated($client, $starttime_stmt, $build_rules);
$this->login();
$this->get($this->url . "/api/v1/manageBuildGroup.php?projectid={$this->ProjectId}");
diff --git a/app/cdash/tests/test_sitemodel.php b/app/cdash/tests/test_sitemodel.php
deleted file mode 100644
index c78b1d02e3..0000000000
--- a/app/cdash/tests/test_sitemodel.php
+++ /dev/null
@@ -1,137 +0,0 @@
-site = null;
- $this->PDO = get_link_identifier()->getPdo();
- }
-
- public function __destruct()
- {
- $this->PDO->query("DELETE FROM site WHERE id = " . $this->site->Id);
- }
-
- public function testSiteModel()
- {
- $this->deleteLog($this->logfilename);
- $this->site = new Site();
-
- if ($this->site->Exists() !== false) {
- $this->fail('Exists did not return false for unnamed site');
- return 1;
- }
-
- if ($this->site->Update() !== false) {
- $this->fail('Update did not return false for unnamed site');
- return 1;
- }
-
- if ($this->site->Insert() !== false) {
- $this->fail('Insert did not return false for unnamed site');
- return 1;
- }
-
- if ($this->site->GetName() !== false) {
- $this->fail('GetName did not return false for unnamed site');
- return 1;
- }
-
- $this->site->Name = 'testsite';
-
- if ($this->site->Exists() !== false) {
- $this->fail('Exists did not return false for nonexistent site');
- return 1;
- }
-
- if ($this->site->Update() !== false) {
- $this->fail('Update did not return false for nonexistent site');
- return 1;
- }
-
- if (!$this->site->Insert()) {
- $this->fail('Insert returned false for named site');
- return 1;
- }
-
- if ($this->site->GetName() !== 'testsite') {
- $this->fail('GetName did not return expected value after Insert');
- return 1;
- }
-
- $this->site->Name = 'testsite2';
- if (!$this->site->Update()) {
- $this->fail('Update returned false for named site');
- return 1;
- }
-
- if ($this->site->GetName() !== 'testsite2') {
- $this->fail('GetName did not return expected value after Update');
- return 1;
- }
-
- // Create two sites with different names.
- $site3 = new Site();
- $site3->Name = 'testsite3';
- if (!$site3->Insert()) {
- $this->fail('Insert failed for site 3');
- }
- $site_3_id = $site3->Id;
- $site3->Id = null;
- if (!$site3->Exists()) {
- $this->fail('site 3 does not exist');
- }
- if ($site3->Id != $site_3_id) {
- $this->fail("Expected $site_3_id but found {$site3->Id} for site 3 ID");
- }
-
- $site4 = new Site();
- $site4->Name = 'testsite4';
- if (!$site4->Insert()) {
- $this->fail('Insert failed for site 4');
- }
- $site_4_id = $site4->Id;
- $site4->Id = null;
- if (!$site4->Exists()) {
- $this->fail('site 4 does not exist');
- }
- if ($site4->Id != $site_4_id) {
- $this->fail("Expected $site_4_id but found {$site4->Id} for site 4 ID");
- }
-
- if ($site3->Id == $site4->Id) {
- $this->fail("Site 3 and Site 4 have the same Id");
- }
-
- // Verify that we handle unique key constraint violations gracefully.
- $site3->Id = $site_4_id;
- $site3->Update();
- $log_contents = file_get_contents($this->logfilename);
- if (strpos($log_contents, 'PdoError') !== false) {
- $this->fail('PDO error logged for unique constraint violation');
- }
- if ($site3->Id != $site3->Id) {
- $this->fail("Site 3 Id not returned from Update()");
- }
-
- $stmt = $this->PDO->prepare('DELETE FROM site WHERE id = ?');
- pdo_execute($stmt, [$site_3_id]);
- pdo_execute($stmt, [$site_4_id]);
- return 0;
- }
-}
diff --git a/app/cdash/xml_handlers/abstract_handler.php b/app/cdash/xml_handlers/abstract_handler.php
index c1cf022a2d..14cbcbb0e1 100644
--- a/app/cdash/xml_handlers/abstract_handler.php
+++ b/app/cdash/xml_handlers/abstract_handler.php
@@ -22,7 +22,7 @@
use CDash\Config;
use CDash\Model\Build;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
abstract class AbstractHandler implements SaxHandler, CDashSubmissionHandlerInterface
{
@@ -97,12 +97,12 @@ public function endPrefixMapping($parser, $user_data, $prefix)
public function getSiteName()
{
- return $this->Site->Name;
+ return $this->Site->name;
}
public function getSiteId()
{
- return $this->Site->Id;
+ return $this->Site->id;
}
public function getBuildStamp()
diff --git a/app/cdash/xml_handlers/actionable_build_interface.php b/app/cdash/xml_handlers/actionable_build_interface.php
index 18dd1281ae..c97e5d3a54 100644
--- a/app/cdash/xml_handlers/actionable_build_interface.php
+++ b/app/cdash/xml_handlers/actionable_build_interface.php
@@ -6,7 +6,7 @@
use CDash\Model\Build;
use CDash\Model\BuildGroup;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\SubscriberInterface;
/**
diff --git a/app/cdash/xml_handlers/build_handler.php b/app/cdash/xml_handlers/build_handler.php
index ee72bf119f..4c8665c70e 100644
--- a/app/cdash/xml_handlers/build_handler.php
+++ b/app/cdash/xml_handlers/build_handler.php
@@ -32,7 +32,7 @@
use CDash\Model\BuildInformation;
use CDash\Model\Label;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
use CDash\Model\SubscriberInterface;
use CDash\Submission\CommitAuthorHandlerInterface;
@@ -80,12 +80,8 @@ public function startElement($parser, $name, $attributes)
$factory = $this->getModelFactory();
if ($name == 'SITE') {
- $this->Site = $factory->create(Site::class);
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation();
$this->BuildInformation = $factory->create(BuildInformation::class);
@@ -115,7 +111,7 @@ public function startElement($parser, $name, $attributes)
$this->BuildName = '(empty)';
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
} elseif ($name == 'SUBPROJECT') {
$this->SubProjectName = $attributes['NAME'];
if (!array_key_exists($this->SubProjectName, $this->SubProjects)) {
@@ -126,7 +122,7 @@ public function startElement($parser, $name, $attributes)
if (!empty($this->PullRequest)) {
$build->SetPullRequest($this->PullRequest);
}
- $build->SiteId = $this->Site->Id;
+ $build->SiteId = $this->Site->id;
$build->Name = $this->BuildName;
$build->SetStamp($this->BuildStamp);
$build->Generator = $this->Generator;
@@ -140,7 +136,7 @@ public function startElement($parser, $name, $attributes)
if (!empty($this->PullRequest)) {
$build->SetPullRequest($this->PullRequest);
}
- $build->SiteId = $this->Site->Id;
+ $build->SiteId = $this->Site->id;
$build->Name = $this->BuildName;
$build->SetStamp($this->BuildStamp);
$build->Generator = $this->Generator;
diff --git a/app/cdash/xml_handlers/configure_handler.php b/app/cdash/xml_handlers/configure_handler.php
index 5bcec916a4..905dd0773c 100644
--- a/app/cdash/xml_handlers/configure_handler.php
+++ b/app/cdash/xml_handlers/configure_handler.php
@@ -23,14 +23,12 @@
use CDash\Messaging\Subscription\UserSubscriptionBuilder;
use CDash\Messaging\Topic\ConfigureTopic;
use CDash\Messaging\Topic\TopicCollection;
-use CDash\Messaging\Topic\TopicInterface;
-use CDash\Model\ActionableTypes;
use CDash\Model\Build;
use CDash\Model\BuildConfigure;
use CDash\Model\BuildGroup;
use CDash\Model\BuildInformation;
use CDash\Model\Label;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
use CDash\Collection\BuildCollection;
@@ -70,12 +68,8 @@ public function startElement($parser, $name, $attributes)
parent::startElement($parser, $name, $attributes);
if ($name == 'SITE') {
- $this->Site = $this->ModelFactory->create(Site::class);
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $sitename = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $sitename], ['name' => $sitename]);
$siteInformation = new SiteInformation;
$this->BuildInformation = $this->ModelFactory->create(BuildInformation::class);
@@ -105,7 +99,7 @@ public function startElement($parser, $name, $attributes)
$this->BuildName = '(empty)';
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
} elseif ($name == 'SUBPROJECT') {
$this->SubProjectName = $attributes['NAME'];
if (!array_key_exists($this->SubProjectName, $this->SubProjects)) {
@@ -386,7 +380,7 @@ public function GetBuildGroup()
protected function CreateBuild()
{
$build = $this->ModelFactory->create(Build::class);
- $build->SiteId = $this->Site->Id;
+ $build->SiteId = $this->Site->id;
$build->Name = $this->BuildName;
$build->SetStamp($this->BuildStamp);
$build->Generator = $this->Generator;
diff --git a/app/cdash/xml_handlers/coverage_handler.php b/app/cdash/xml_handlers/coverage_handler.php
index 34dee17d3f..c4f2db6847 100644
--- a/app/cdash/xml_handlers/coverage_handler.php
+++ b/app/cdash/xml_handlers/coverage_handler.php
@@ -23,7 +23,7 @@
use CDash\Model\CoverageSummary;
use CDash\Model\Label;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
use CDash\Model\SubProject;
@@ -56,11 +56,8 @@ public function startElement($parser, $name, $attributes)
{
parent::startElement($parser, $name, $attributes);
if ($name == 'SITE') {
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation();
$buildInformation = new BuildInformation();
@@ -71,9 +68,9 @@ public function startElement($parser, $name, $attributes)
$buildInformation->SetValue($key, $value);
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
- $this->Build->SiteId = $this->Site->Id;
+ $this->Build->SiteId = $this->Site->id;
$this->Build->Name = $attributes['BUILDNAME'];
if (empty($this->Build->Name)) {
$this->Build->Name = '(empty)';
diff --git a/app/cdash/xml_handlers/coverage_junit_handler.php b/app/cdash/xml_handlers/coverage_junit_handler.php
index 37acf162ca..82d7576a32 100644
--- a/app/cdash/xml_handlers/coverage_junit_handler.php
+++ b/app/cdash/xml_handlers/coverage_junit_handler.php
@@ -22,7 +22,7 @@
use CDash\Model\CoverageFile;
use CDash\Model\CoverageSummary;
use CDash\Model\Label;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
class CoverageJUnitHandler extends AbstractHandler
@@ -50,11 +50,8 @@ public function startElement($parser, $name, $attributes)
parent::startElement($parser, $name, $attributes);
$parent = $this->getParent();
if ($name == 'SITE') {
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation();
$buildInformation = new BuildInformation();
@@ -65,9 +62,9 @@ public function startElement($parser, $name, $attributes)
$buildInformation->SetValue($key, $value);
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
- $this->Build->SiteId = $this->Site->Id;
+ $this->Build->SiteId = $this->Site->id;
$this->Build->Name = $attributes['BUILDNAME'];
if (empty($this->Build->Name)) {
$this->Build->Name = '(empty)';
diff --git a/app/cdash/xml_handlers/coverage_log_handler.php b/app/cdash/xml_handlers/coverage_log_handler.php
index fe017a0ae1..64e06597b2 100644
--- a/app/cdash/xml_handlers/coverage_log_handler.php
+++ b/app/cdash/xml_handlers/coverage_log_handler.php
@@ -20,7 +20,7 @@
use CDash\Model\CoverageFile;
use CDash\Model\CoverageFileLog;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\SubProject;
class CoverageLogHandler extends AbstractHandler
@@ -51,12 +51,10 @@ public function startElement($parser, $name, $attributes)
{
parent::startElement($parser, $name, $attributes);
if ($name == 'SITE') {
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
- $this->Build->SiteId = $this->Site->Id;
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
+
+ $this->Build->SiteId = $this->Site->id;
$this->Build->Name = $attributes['BUILDNAME'];
if (empty($this->Build->Name)) {
$this->Build->Name = '(empty)';
diff --git a/app/cdash/xml_handlers/done_handler.php b/app/cdash/xml_handlers/done_handler.php
index ffa9b9756c..44007ed235 100644
--- a/app/cdash/xml_handlers/done_handler.php
+++ b/app/cdash/xml_handlers/done_handler.php
@@ -102,7 +102,7 @@ public function text($parser, $data)
public function getSiteName()
{
- return $this->Build->GetSite()->GetName();
+ return $this->Build->GetSite()->name;
}
public function shouldRequeue()
diff --git a/app/cdash/xml_handlers/dynamic_analysis_handler.php b/app/cdash/xml_handlers/dynamic_analysis_handler.php
index 0151f17d94..0f21363eb6 100644
--- a/app/cdash/xml_handlers/dynamic_analysis_handler.php
+++ b/app/cdash/xml_handlers/dynamic_analysis_handler.php
@@ -26,7 +26,7 @@
use CDash\Model\Build;
use CDash\Model\BuildGroup;
use CDash\Model\Label;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\DynamicAnalysis;
use CDash\Model\DynamicAnalysisSummary;
use CDash\Model\DynamicAnalysisDefect;
@@ -68,12 +68,8 @@ public function startElement($parser, $name, $attributes)
$factory = $this->getModelFactory();
if ($name == 'SITE') {
- $this->Site = $factory->create(Site::class);
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation();
$this->BuildInformation = $factory->create(BuildInformation::class);
@@ -97,7 +93,7 @@ public function startElement($parser, $name, $attributes)
if (empty($this->BuildName)) {
$this->BuildName = '(empty)';
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
} elseif ($name == 'SUBPROJECT') {
$this->SubProjectName = $attributes['NAME'];
if (!array_key_exists($this->SubProjectName, $this->SubProjects)) {
@@ -267,7 +263,7 @@ private function createBuild($subprojectName)
$factory = $this->getModelFactory();
$build = $factory->create(Build::class);
- $build->SiteId = $this->Site->Id;
+ $build->SiteId = $this->Site->id;
$build->Name = $this->BuildName;
$build->SetStamp($this->BuildStamp);
diff --git a/app/cdash/xml_handlers/note_handler.php b/app/cdash/xml_handlers/note_handler.php
index a70783e4e7..c03b5a919f 100644
--- a/app/cdash/xml_handlers/note_handler.php
+++ b/app/cdash/xml_handlers/note_handler.php
@@ -22,7 +22,7 @@
use CDash\Model\BuildConfigure;
use CDash\Model\BuildInformation;
use CDash\Model\BuildNote;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
class NoteHandler extends AbstractHandler
@@ -50,11 +50,8 @@ public function startElement($parser, $name, $attributes)
{
parent::startElement($parser, $name, $attributes);
if ($name == 'SITE') {
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation();
$buildInformation = new BuildInformation();
@@ -65,9 +62,9 @@ public function startElement($parser, $name, $attributes)
$buildInformation->SetValue($key, $value);
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
- $this->Build->SiteId = $this->Site->Id;
+ $this->Build->SiteId = $this->Site->id;
$this->Build->Name = $attributes['BUILDNAME'];
if (empty($this->Build->Name)) {
$this->Build->Name = '(empty)';
diff --git a/app/cdash/xml_handlers/testing_handler.php b/app/cdash/xml_handlers/testing_handler.php
index 28f3977836..9ea0cbb644 100644
--- a/app/cdash/xml_handlers/testing_handler.php
+++ b/app/cdash/xml_handlers/testing_handler.php
@@ -21,7 +21,7 @@
use CDash\Model\Image;
use CDash\Model\Label;
use CDash\Model\Project;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
use CDash\Model\SubscriberInterface;
use CDash\Submission\CommitAuthorHandlerInterface;
@@ -78,15 +78,11 @@ public function startElement($parser, $name, $attributes)
$factory = $this->getModelFactory();
if ($name == 'SITE') {
- $this->Site = $factory->create(Site::class);
$this->Project = $factory->create(Project::class);
$this->Project->Id = $this->projectid;
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation;
$this->BuildInformation = $factory->create(BuildInformation::class);
@@ -115,7 +111,7 @@ public function startElement($parser, $name, $attributes)
if (empty($this->BuildName)) {
$this->BuildName = '(empty)';
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
} elseif ($name == 'SUBPROJECT') {
$this->SubProjectName = $attributes['NAME'];
if (!array_key_exists($this->SubProjectName, $this->SubProjects)) {
@@ -338,7 +334,7 @@ private function createBuild()
$build->SetPullRequest($this->PullRequest);
}
- $build->SiteId = $this->Site->Id;
+ $build->SiteId = $this->Site->id;
$build->Name = $this->BuildName;
$build->SubProjectName = $this->SubProjectName;
$build->SetStamp($this->BuildStamp);
diff --git a/app/cdash/xml_handlers/testing_junit_handler.php b/app/cdash/xml_handlers/testing_junit_handler.php
index 262fb3e4f1..ccb926924f 100644
--- a/app/cdash/xml_handlers/testing_junit_handler.php
+++ b/app/cdash/xml_handlers/testing_junit_handler.php
@@ -20,7 +20,7 @@
use CDash\Model\Build;
use CDash\Model\BuildInformation;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
class TestingJUnitHandler extends AbstractHandler
@@ -47,7 +47,6 @@ public function __construct($projectID)
{
parent::__construct($projectID);
$this->Build = new Build();
- $this->Site = new Site();
$this->UpdateEndTime = false;
$this->Group = 'Nightly';
@@ -73,11 +72,8 @@ public function startElement($parser, $name, $attributes)
if ($name == 'SITE') {
$this->HasSiteTag = true;
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation();
$buildInformation = new BuildInformation();
@@ -88,9 +84,9 @@ public function startElement($parser, $name, $attributes)
$buildInformation->SetValue($key, $value);
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
- $this->Build->SiteId = $this->Site->Id;
+ $this->Build->SiteId = $this->Site->id;
$this->Build->Name = $attributes['BUILDNAME'];
if (empty($this->Build->Name)) {
$this->Build->Name = '(empty)';
@@ -118,10 +114,9 @@ public function startElement($parser, $name, $attributes)
$this->Build->Information->CompilerVersion = $attributes['VALUE'];
break;
case 'hostname':
- if (empty($this->Site->Name)) {
- $this->Site->Name = $attributes['VALUE'];
- $this->Site->Insert();
- $this->Build->SiteId = $this->Site->Id;
+ if (empty($this->Site->name)) {
+ $this->Site = Site::firstOrCreate(['name' => $attributes['VALUE']], ['name' => $attributes['VALUE']]);
+ $this->Build->SiteId = $this->Site->id;
}
break;
case 'track':
@@ -162,9 +157,8 @@ public function startElement($parser, $name, $attributes)
if ($this->HasSiteTag == false) {
// Hostname is not necessarily defined
if (!empty($attributes['HOSTNAME'])) {
- $this->Site->Name = $attributes['HOSTNAME'];
- $this->Site->Insert();
- $this->Build->SiteId = $this->Site->Id;
+ $this->Site = Site::firstOrCreate(['name' => $attributes['HOSTNAME']], ['name' => $attributes['HOSTNAME']]);
+ $this->Build->SiteId = $this->Site->id;
}
$this->Build->Information = new BuildInformation();
diff --git a/app/cdash/xml_handlers/update_handler.php b/app/cdash/xml_handlers/update_handler.php
index 4c6aa6f42c..c3eee1a791 100644
--- a/app/cdash/xml_handlers/update_handler.php
+++ b/app/cdash/xml_handlers/update_handler.php
@@ -31,7 +31,7 @@
use CDash\Model\BuildUpdateFile;
use CDash\Model\Project;
use CDash\Model\Repository;
-use CDash\Model\Site;
+use App\Models\Site;
use CDash\Model\SubscriberInterface;
use CDash\Submission\CommitAuthorHandlerInterface;
@@ -50,7 +50,6 @@ public function __construct($projectID)
parent::__construct($projectID);
$factory = $this->getModelFactory();
$this->Build = $factory->create(Build::class);
- $this->Site = $factory->create(Site::class);
}
/** Start element */
@@ -79,9 +78,9 @@ public function endElement($parser, $name)
{
parent::endElement($parser, $name);
if ($name == 'SITE') {
- $this->Site->Insert();
+ $this->Site->save();
} elseif ($name == 'UPDATE') {
- $this->Build->SiteId = $this->Site->Id;
+ $this->Build->SiteId = $this->Site->id;
$start_time = gmdate(FMT_DATETIME, $this->StartTimeStamp);
$end_time = gmdate(FMT_DATETIME, $this->EndTimeStamp);
@@ -179,10 +178,8 @@ public function text($parser, $data)
$this->Update->Revision = $data;
break;
case 'SITE':
- $this->Site->Name = $data;
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
+ $sitename = !empty($data) ? $data : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $sitename], ['name' => $sitename]);
break;
case 'STARTTIME':
$this->StartTimeStamp = $data;
diff --git a/app/cdash/xml_handlers/upload_handler.php b/app/cdash/xml_handlers/upload_handler.php
index 3887eb03bf..f0176a9cac 100644
--- a/app/cdash/xml_handlers/upload_handler.php
+++ b/app/cdash/xml_handlers/upload_handler.php
@@ -21,7 +21,7 @@
use CDash\Model\Build;
use CDash\Model\BuildInformation;
use CDash\Model\Label;
-use CDash\Model\Site;
+use App\Models\Site;
use App\Models\SiteInformation;
use CDash\Model\Project;
use CDash\Model\UploadFile;
@@ -77,11 +77,8 @@ public function startElement($parser, $name, $attributes)
}
if ($name == 'SITE') {
- $this->Site->Name = $attributes['NAME'];
- if (empty($this->Site->Name)) {
- $this->Site->Name = '(empty)';
- }
- $this->Site->Insert();
+ $site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
+ $this->Site = Site::firstOrCreate(['name' => $site_name], ['name' => $site_name]);
$siteInformation = new SiteInformation();
$buildInformation = new BuildInformation();
@@ -92,9 +89,9 @@ public function startElement($parser, $name, $attributes)
$buildInformation->SetValue($key, $value);
}
- $this->Site->SetInformation($siteInformation);
+ $this->Site->mostRecentInformation()->save($siteInformation);
- $this->Build->SiteId = $this->Site->Id;
+ $this->Build->SiteId = $this->Site->id;
$this->Build->Name = $attributes['BUILDNAME'];
if (empty($this->Build->Name)) {
$this->Build->Name = '(empty)';
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 742e875cbf..98da5df7ff 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1382,6 +1382,21 @@ parameters:
count: 1
path: app/Models/BuildTest.php
+ -
+ message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
+ count: 1
+ path: app/Models/Site.php
+
+ -
+ message: "#^Method App\\\\Models\\\\Site\\:\\:mostRecentInformation\\(\\) throws checked exception InvalidArgumentException but it's missing from the PHPDoc @throws tag\\.$#"
+ count: 1
+ path: app/Models/Site.php
+
+ -
+ message: "#^Method App\\\\Models\\\\Site\\:\\:save\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
+ count: 1
+ path: app/Models/Site.php
+
-
message: "#^Call to function base64_decode\\(\\) requires parameter \\#2 to be set\\.$#"
count: 2
@@ -8346,123 +8361,6 @@ parameters:
count: 1
path: app/cdash/app/Model/Repository.php
- -
- message: """
- #^Call to deprecated function add_log\\(\\)\\:
- 04/04/2023 Use \\\\Illuminate\\\\Support\\\\Facades\\\\Log for logging instead$#
- """
- count: 3
- path: app/cdash/app/Model/Site.php
-
- -
- message: """
- #^Call to deprecated function pdo_execute\\(\\)\\:
- v2\\.5\\.0 01/22/2018$#
- """
- count: 4
- path: app/cdash/app/Model/Site.php
-
- -
- message: """
- #^Call to deprecated function pdo_insert_id\\(\\)\\:
- 04/01/2023$#
- """
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: """
- #^Call to deprecated method getPdo\\(\\) of class CDash\\\\Database\\:
- 04/22/2023 Use Laravel query builder or Eloquent instead$#
- """
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Method CDash\\\\Model\\\\Site\\:\\:Exists\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Method CDash\\\\Model\\\\Site\\:\\:Fill\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Method CDash\\\\Model\\\\Site\\:\\:GetName\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Method CDash\\\\Model\\\\Site\\:\\:Insert\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Method CDash\\\\Model\\\\Site\\:\\:LookupIP\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Method CDash\\\\Model\\\\Site\\:\\:SetInformation\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Method CDash\\\\Model\\\\Site\\:\\:Update\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$Filled has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$Id has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$Information has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$Ip has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$Latitude has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$Longitude has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$Name has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$OutOfOrder has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
- -
- message: "#^Property CDash\\\\Model\\\\Site\\:\\:\\$PDO has no type specified\\.$#"
- count: 1
- path: app/cdash/app/Model/Site.php
-
-
message: """
#^Call to deprecated function add_last_sql_error\\(\\)\\:
@@ -12214,11 +12112,6 @@ parameters:
count: 1
path: app/cdash/include/common.php
- -
- message: "#^Function get_server_siteid\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/include/common.php
-
-
message: "#^Function has_next_date\\(\\) has parameter \\$currentstarttime with no type specified\\.$#"
count: 1
@@ -17799,7 +17692,7 @@ parameters:
#^Call to deprecated function pdo_real_escape_string\\(\\)\\:
04/01/2023$#
"""
- count: 4
+ count: 3
path: app/cdash/public/submit.php
-
@@ -26471,50 +26364,6 @@ parameters:
count: 1
path: app/cdash/tests/test_setup_repositories.php
- -
- message: """
- #^Call to deprecated function get_link_identifier\\(\\)\\:
- 04/22/2023$#
- """
- count: 1
- path: app/cdash/tests/test_sitemodel.php
-
- -
- message: """
- #^Call to deprecated function pdo_execute\\(\\)\\:
- v2\\.5\\.0 01/22/2018$#
- """
- count: 2
- path: app/cdash/tests/test_sitemodel.php
-
- -
- message: """
- #^Call to deprecated method getPdo\\(\\) of class CDash\\\\Database\\:
- 04/22/2023 Use Laravel query builder or Eloquent instead$#
- """
- count: 1
- path: app/cdash/tests/test_sitemodel.php
-
- -
- message: "#^If condition is always true\\.$#"
- count: 1
- path: app/cdash/tests/test_sitemodel.php
-
- -
- message: "#^Method SiteModelTestCase\\:\\:testSiteModel\\(\\) has no return type specified\\.$#"
- count: 1
- path: app/cdash/tests/test_sitemodel.php
-
- -
- message: "#^Property SiteModelTestCase\\:\\:\\$PDO has no type specified\\.$#"
- count: 1
- path: app/cdash/tests/test_sitemodel.php
-
- -
- message: "#^Property SiteModelTestCase\\:\\:\\$site has no type specified\\.$#"
- count: 1
- path: app/cdash/tests/test_sitemodel.php
-
-
message: "#^Call to deprecated method pass\\(\\) of class SimpleTestCase\\.$#"
count: 1