Skip to content

Commit

Permalink
refactor: namespace models
Browse files Browse the repository at this point in the history
This involves changing file names to reflect class names
  • Loading branch information
bryonbean authored and zackgalbreath committed Apr 2, 2018
1 parent 9d4a934 commit 36da03e
Show file tree
Hide file tree
Showing 207 changed files with 848 additions and 596 deletions.
2 changes: 1 addition & 1 deletion app/Controller/Auth/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use CDash\Config;
use CDash\System;
use User;
use CDash\Model\User;

/**
* Class Session
Expand Down
8 changes: 4 additions & 4 deletions models/authtoken.php → app/Model/AuthToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

require_once('models/user.php');
use CDash\Database;

/** AuthToken class */
class AuthToken
Expand All @@ -30,7 +31,7 @@ class AuthToken
public function __construct()
{
$this->Filled = false;
$this->PDO = get_link_identifier()->getPdo();
$this->PDO = Database::getInstance()->getPdo();
}

// Generate a new authentication token.
Expand Down Expand Up @@ -179,7 +180,7 @@ public static function getTokensForUser($userid)
if (!$userid) {
return;
}
$pdo = get_link_identifier()->getPdo();
$pdo = Database::getInstance()->getPdo();
$stmt = $pdo->prepare(
'SELECT hash FROM authtoken WHERE userid = ? ORDER BY expires ASC');
pdo_execute($stmt, [$userid]);
Expand All @@ -195,7 +196,6 @@ public static function getTokensForUser($userid)
// Get JSON representation of this object.
public function marshal()
{
require_once 'models/user.php';
$marshaledAuthToken = [];

if (!$this->Fill()) {
Expand Down
1 change: 1 addition & 0 deletions models/banner.php → app/Model/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

use CDash\Database;

Expand Down
53 changes: 20 additions & 33 deletions models/build.php → app/Model/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,15 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

include_once 'include/common.php';
include_once 'include/ctestparserutils.php';
include_once 'include/repository.php';
include_once 'models/builderror.php';
include_once 'models/buildfailure.php';
include_once 'models/builderrordiff.php';
include_once 'models/buildinformation.php';
include_once 'models/buildusernote.php';
include_once 'models/constants.php';
include_once 'models/label.php';
include_once 'models/subproject.php';
include_once 'models/test.php';
include_once 'models/uploadfile.php';
include_once 'models/user.php';
include_once 'models/userproject.php';

use CDash\Config;
use CDash\Log;

use CDash\Collection\TestCollection;
use CDash\Database;
use PDO;

class Build
{
Expand Down Expand Up @@ -169,7 +157,7 @@ public function SetSubProject($subproject)
if (empty($this->ProjectId)) {
add_log('ProjectId not set' . $subproject, 'Build::SetSubProject', LOG_ERR,
$this->ProjectId, $this->Id,
CDASH_OBJECT_BUILD, $this->Id);
Object::BUILD, $this->Id);
return false;
}

Expand Down Expand Up @@ -214,7 +202,7 @@ public function SetSubProject($subproject)
$Label->Insert();

add_log('New subproject detected: ' . $subproject, 'Build::SetSubProject',
LOG_INFO, $this->ProjectId, $this->Id, CDASH_OBJECT_BUILD, $this->Id);
LOG_INFO, $this->ProjectId, $this->Id, Object::BUILD, $this->Id);
return true;
}

Expand Down Expand Up @@ -758,7 +746,7 @@ public function InsertLabelAssociations()
} else {
add_log('No Build::Id - cannot call $label->Insert...', 'Build::InsertLabelAssociations', LOG_ERR,
$this->ProjectId, $this->Id,
CDASH_OBJECT_BUILD, $this->Id);
Object::BUILD, $this->Id);
return false;
}
}
Expand Down Expand Up @@ -944,7 +932,7 @@ public function Save()
} elseif ($this->ParentId > 0) {
// If we just created a child build, associate it with
// the parent's updates (if any).
require_once 'models/buildupdate.php';

BuildUpdate::AssignUpdateToChild($this->Id, $this->ParentId);
}
} else {
Expand Down Expand Up @@ -1071,7 +1059,7 @@ public function GetMissingTests()
{
if (!$this->Id) {
add_log('BuildId is not set', 'Build::GetMissingTests', LOG_ERR,
$this->ProjectId, $this->Id, CDASH_OBJECT_BUILD, $this->Id);
$this->ProjectId, $this->Id, Object::BUILD, $this->Id);
return false;
}

Expand Down Expand Up @@ -1126,7 +1114,7 @@ private function GetTests($criteria, $maxitems = 0)
{
if (!$this->Id) {
add_log('BuildId is not set', 'Build::GetTests', LOG_ERR,
$this->ProjectId, $this->Id, CDASH_OBJECT_BUILD, $this->Id);
$this->ProjectId, $this->Id, Object::BUILD, $this->Id);
return false;
}

Expand Down Expand Up @@ -1205,7 +1193,7 @@ public function GetErrorDifferences()
{
if (!$this->Id) {
add_log('BuildId is not set', 'Build::GetErrorDifferences', LOG_ERR,
$this->ProjectId, $this->Id, CDASH_OBJECT_BUILD, $this->Id);
$this->ProjectId, $this->Id, Object::BUILD, $this->Id);
return false;
}

Expand Down Expand Up @@ -1278,7 +1266,7 @@ public function ComputeDifferences()
if (!$this->Id) {
add_log('BuildId is not set', 'Build::ComputeDifferences', LOG_ERR,
$this->ProjectId, $this->Id,
CDASH_OBJECT_BUILD, $this->Id);
Object::BUILD, $this->Id);
return false;
}

Expand All @@ -1298,7 +1286,7 @@ public function ComputeConfigureDifferences()
{
if (!$this->Id) {
add_log('BuildId is not set', 'Build::ComputeConfigureDifferences',
LOG_ERR, $this->ProjectId, $this->Id, CDASH_OBJECT_BUILD,
LOG_ERR, $this->ProjectId, $this->Id, Object::BUILD,
$this->Id);
return false;
}
Expand Down Expand Up @@ -1374,13 +1362,13 @@ public function ComputeTestTiming()
{
if (!$this->Id) {
add_log('BuildId is not set', 'Build::ComputeTestTiming', LOG_ERR,
$this->ProjectId, $this->Id, CDASH_OBJECT_BUILD, $this->Id);
$this->ProjectId, $this->Id, Object::BUILD, $this->Id);
return false;
}

if (!$this->ProjectId) {
add_log('ProjectId is not set', 'Build::ComputeTestTiming', LOG_ERR,
$this->ProjectId, $this->Id, CDASH_OBJECT_BUILD, $this->Id);
$this->ProjectId, $this->Id, Object::BUILD, $this->Id);
return false;
}

Expand Down Expand Up @@ -1542,7 +1530,7 @@ public function ComputeUpdateStatistics()
{
if (!$this->Id) {
add_log('Id is not set', 'Build::ComputeUpdateStatistics', LOG_ERR,
$this->ProjectId, $this->Id, CDASH_OBJECT_BUILD, $this->Id);
$this->ProjectId, $this->Id, Object::BUILD, $this->Id);
return false;
}

Expand Down Expand Up @@ -1639,7 +1627,6 @@ private function AddUpdateStatistics($author, $email, $checkindate, $firstbuild,
$warningdiff, $errordiff, $testdiff)
{
// Find user by email address.
require_once('models/user.php');
$user = new User();
$userid = $user->GetIdFromEmail($email);
if (!$userid) {
Expand Down Expand Up @@ -2179,7 +2166,7 @@ public function UpdateBuild($buildid, $newErrors, $newWarnings)
add_log("$buildid is its own parent",
'Build::UpdateBuild', LOG_ERR,
$this->ProjectId, $this->Id,
CDASH_OBJECT_BUILD, $this->Id);
Object::BUILD, $this->Id);
return;
}
$this->UpdateBuild($parentid, $newErrors, $newWarnings);
Expand Down Expand Up @@ -2445,7 +2432,7 @@ public static function GetTestingDate($build_start_time,
// If the build was started after the nightly start time
// then it should appear on the dashboard results for the
// subsequent day.
$build_datetime = new DateTime($build_start_time);
$build_datetime = new \DateTime($build_start_time);
$build_start_timestamp = $build_datetime->getTimestamp();

if (date(FMT_TIME, $nightly_start_timestamp) < '12:00:00') {
Expand All @@ -2454,7 +2441,7 @@ public static function GetTestingDate($build_start_time,
if (date(FMT_TIME, $build_start_timestamp) <
date(FMT_TIME, $nightly_start_timestamp)
) {
$build_datetime->sub(new DateInterval('P1D'));
$build_datetime->sub(new \DateInterval('P1D'));
$build_start_timestamp = $build_datetime->getTimestamp();
}
} else {
Expand All @@ -2463,7 +2450,7 @@ public static function GetTestingDate($build_start_time,
if (date(FMT_TIME, $build_start_timestamp) >=
date(FMT_TIME, $nightly_start_timestamp)
) {
$build_datetime->add(new DateInterval('P1D'));
$build_datetime->add(new \DateInterval('P1D'));
$build_start_timestamp = $build_datetime->getTimestamp();
}
}
Expand Down Expand Up @@ -2529,7 +2516,7 @@ public function SetParentId($parentid)
add_log("Attempt to mark build $this->Id as its own parent",
'Build::SetParentId', LOG_ERR,
$this->ProjectId, $this->Id,
CDASH_OBJECT_BUILD, $this->Id);
Object::BUILD, $this->Id);
return;
}
$this->ParentId = $parentid;
Expand Down
20 changes: 10 additions & 10 deletions models/buildconfigure.php → app/Model/BuildConfigure.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

include_once 'models/buildconfigureerror.php';
include_once 'models/buildconfigureerrordiff.php';
include_once 'models/constants.php';
use PDO;
use CDash\Database;

/** BuildConfigure class */
class BuildConfigure
Expand All @@ -40,7 +40,7 @@ class BuildConfigure
*/
public function __construct()
{
$this->PDO = get_link_identifier()->getPdo();
$this->PDO = Database::getInstance()->getPdo();
}

public function AddError($error)
Expand Down Expand Up @@ -118,13 +118,13 @@ public function ExistsByBuildId()
if (!$this->BuildId) {
add_log('BuildId not set',
'BuildConfigure::Exists', LOG_ERR,
0, 0, CDASH_OBJECT_CONFIGURE, 0);
0, 0, Object::CONFIGURE, 0);
return false;
}
if (!is_numeric($this->BuildId)) {
add_log('BuildId is not numeric',
'BuildConfigure::Exists', LOG_ERR,
0, 0, CDASH_OBJECT_CONFIGURE, 0);
0, 0, Object::CONFIGURE, 0);
return false;
}

Expand All @@ -148,7 +148,7 @@ public function Delete()
if (!$this->Exists()) {
add_log('this configure does not exist',
'BuildConfigure::Delete', LOG_ERR,
0, 0, CDASH_OBJECT_CONFIGURE, 0);
0, 0, Object::CONFIGURE, 0);
return false;
}

Expand Down Expand Up @@ -191,7 +191,7 @@ public function InsertLabelAssociations()
} else {
add_log('No BuildConfigure::BuildId - cannot call $label->Insert...',
'BuildConfigure::InsertLabelAssociations', LOG_ERR,
0, $this->BuildId, CDASH_OBJECT_CONFIGURE, $this->BuildId);
0, $this->BuildId, Object::CONFIGURE, $this->BuildId);
}
}

Expand All @@ -202,14 +202,14 @@ public function Insert()
if (!$this->BuildId) {
add_log('BuildId not set',
'BuildConfigure::Insert', LOG_ERR,
0, 0, CDASH_OBJECT_CONFIGURE, $this->Id);
0, 0, Object::CONFIGURE, $this->Id);
return false;
}

if ($this->ExistsByBuildId()) {
add_log('This build already has a configure',
'BuildConfigure::Insert', LOG_ERR,
0, $this->BuildId, CDASH_OBJECT_CONFIGURE, $this->Id);
0, $this->BuildId, Object::CONFIGURE, $this->Id);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

use CDash\Database;

/** BuildConfigureError class */
class BuildConfigureError
Expand All @@ -24,7 +27,7 @@ class BuildConfigureError

public function __construct()
{
$this->PDO = get_link_identifier()->getPdo();
$this->PDO = Database::getInstance()->getPdo();
}

/** Return if exists */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

/** BuildConfigureErrorDiff class */
class BuildConfigureErrorDiff
Expand Down
6 changes: 5 additions & 1 deletion models/builderror.php → app/Model/BuildError.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

use PDO;
use CDash\Database;

/** BuildError */
class BuildError
Expand All @@ -31,7 +35,7 @@ class BuildError

public function __construct()
{
$this->PDO = get_link_identifier()->getPdo();
$this->PDO = Database::getInstance()->getPdo();
}

// Insert in the database (no update possible)
Expand Down
1 change: 1 addition & 0 deletions models/builderrordiff.php → app/Model/BuildErrorDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

/** BuildErrorDiff */
class BuildErrorDiff
Expand Down
6 changes: 4 additions & 2 deletions models/buildfailure.php → app/Model/BuildFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
namespace CDash\Model;

include_once 'models/label.php';
use PDO;
use CDash\Database;

/** BuildFailure */
class BuildFailure
Expand All @@ -38,7 +40,7 @@ class BuildFailure
public function __construct()
{
$this->Arguments = array();
$this->PDO = get_link_identifier()->getPdo();
$this->PDO = Database::getInstance()->getPdo();
}

public function AddLabel($label)
Expand Down
Loading

0 comments on commit 36da03e

Please sign in to comment.