ldc-web/app/Models/Projects.php

103 lines
2.9 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class Projects extends Model
{
public function getDevWebIpAttribute() {
$value = Servers::find($this->dev_web_server_id);
if ($value)
$value = $value->ssh;
return $value;
}
public function getDevDbIpAttribute() {
$value = Servers::find($this->dev_db_server_id);
if ($value)
$value = $value->ssh;
return $value;
}
public function getProdWebIpAttribute() {
$value = Servers::find($this->prod_web_server_id);
if ($value)
$value = $value->ssh;
return $value;
}
public function getProdDbIpAttribute() {
$value = Servers::find($this->prod_db_server_id);
if ($value)
$value = $value->ssh;
return $value;
}
public function getCheckedAttribute() {
$value = ProjectsStatusChecker::select('updated_at')->where('project_uuid', '=', $this->uuid)->first();
if (!$value) {
$value = 'missing';
} else {
$value = $value->updated_at;
$dt = Carbon::now();
if ($dt->diffInMinutes($value) > 30) {
$value = 'false';
} else {
$value = 'true';
}
}
return $value;
}
public function getSitemapCheckedAttribute() {
$value = ProjectsStatusChecker::select('sitemap')->where('project_uuid', '=', $this->uuid)->first();
if(!$value) {
$value = 'missing';
} else {
$value = $value->sitemap;
}
return $value;
}
public function getRobotsCheckedAttribute() {
$value = ProjectsStatusChecker::select('robots')->where('project_uuid', '=', $this->uuid)->first();
if(!$value) {
$value = 'missing';
} else {
$value = $value->robots;
}
return $value;
}
public function getLogsCheckedAttribute() {
$value = ProjectsStatusChecker::select('logs')->where('project_uuid', '=', $this->uuid)->first();
if(!$value) {
$value = 'missing';
} else {
$value = $value->logs;
}
return $value;
}
public function getCodeAttribute() {
$value = ProjectsStatusChecker::select('code')->where('project_uuid', '=', $this->uuid)->first();
if(!$value) {
$value = 'missing';
} else {
$value = $value->code;
}
return $value;
}
public function getLogsHrAttribute() {
$value = ProjectsStatusChecker::select('logs')->where('project_uuid', '=', $this->uuid)->first();
return $this->human_filesize($value->logs);
}
private function human_filesize($size, $precision = 2) {
$i = floor(log($size, 1024));
return round($size / pow(1024, $i), [0,0,2,2,3][$i]).[' O',' Ko',' Mo',' Go',' To'][$i];
}
}