Files
nutzwerte_fi4/app/Console/Commands/FixMethodRelations.php
T

62 lines
1.6 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Projekte;
use App\Models\ProjektMethode;
use App\Models\ProjektObjekteImDetail;
use Illuminate\Console\Command;
class FixMethodRelations extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*
* app:fix-method-relations
*/
protected $signature = 'app:fixdb1 {--d}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fix relation in table "projekt_objekte_im_details" mit "projekt_methodes" id';
/**
* Execute the console command.
*/
public function handle()
{
Notice::note('Start FixMethodRelations', 'b');
$projekte = Projekte::get();
foreach ($projekte as $projekt) {
$projektid = $projekt->id;
$methoden = ProjektMethode::where('projekte_id', $projektid)->pluck('id', 'raumart')->toArray();
$res = ProjektObjekteImDetail::where('projekte_id', $projektid)->get();
foreach ($res as $value) {
if (! $value->projekt_methode_id) {
if (isset($methoden[$value->raumart])) {
$projekt_methode_id = $methoden[$value->raumart];
ProjektObjekteImDetail::where('id', $value->id)->update(['projekt_methode_id' => $projekt_methode_id]);
} else {
Notice::note('Error: Methode für Raumart '.$value->raumart.' in Projekt'.$projekt->interner_name.' Id '.$projekt->id.' Methode missing', 'r');
}
}
}
}
}
}