Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create BlockedBuild Eloquent model #1757

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/Models/BlockedBuild.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Models;

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

/**
* @property int $id
* @property int $projectid
* @property string $buildname
* @property string $sitename
* @property string $ipaddress
*
* @mixin Builder<BlockedBuild>
*/
class BlockedBuild extends Model
{
protected $table = 'blockbuild';

public $timestamps = false;

protected $fillable = [
'projectid',
'buildname',
'sitename',
'ipaddress',
];

protected $casts = [
'id' => 'integer',
'projectid' => 'integer',
];

/**
* @return BelongsTo<Project, self>
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class, 'id', 'projectid');
}
}
8 changes: 8 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,12 @@ public function builds(): HasMany
->orWhere('parentid', -1);
});
}

/**
* @return HasMany<BlockedBuild>
*/
public function blockedbuilds(): HasMany
{
return $this->hasMany(BlockedBuild::class, 'projectid', 'id');
}
}
18 changes: 11 additions & 7 deletions app/cdash/app/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -1264,17 +1264,21 @@ public function InitialSetup(): bool

public function AddBlockedBuild(string $buildname, string $sitename, string $ip): int
{
return DB::table('blockbuild')->insertGetId([
'projectid' => $this->Id,
'buildname' => $buildname,
'sitename' => $sitename,
'ip' => $ip,
]);
return EloquentProject::findOrFail((int) $this->Id)
->blockedbuilds()
->create([
'buildname' => $buildname,
'sitename' => $sitename,
'ipaddress' => $ip,
])->id;
}

public function RemoveBlockedBuild(int $id): void
{
DB::table('blockbuild')->delete($id);
EloquentProject::findOrFail((int) $this->Id)
->blockedbuilds()
->findOrFail($id)
->delete();
}

/** Delete old builds if this project has too many. */
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9383,6 +9383,11 @@ parameters:
count: 1
path: app/cdash/app/Model/Project.php

-
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\BlockedBuild\\>\\:\\:findOrFail\\(\\)\\.$#"
count: 1
path: app/cdash/app/Model/Project.php

-
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\Build\\>\\:\\:betweenDates\\(\\)\\.$#"
count: 1
Expand Down