Files
lucent-laravel/src/Commands/RemoveOrphanEdgesCommand.php
T
2026-05-18 19:09:55 +03:00

41 lines
878 B
PHP

<?php
namespace Lucent\Commands;
use Illuminate\Console\Command;
use Lucent\Edge\EdgeService;
use Lucent\Query\Query;
class RemoveOrphanEdgesCommand extends Command
{
protected $signature = 'lucent:removeOrphanEdges';
protected $description = 'Searches and remove orphan edges';
public function __construct(
)
{
parent::__construct();
}
public function handle(EdgeService $edgeService, Query $query): void
{
$edges = $edgeService->findAll();
foreach ($edges as $edge){
$source = $query->filter(["id" => $edge->source])->run()->records;
$target = $query->filter(["id" => $edge->target])->run()->records;
if($source->isEmpty() || $target->isEmpty()){
$this->info("Edge is orphan");
$edgeService->remove($edge);
}
}
}
}