command rename
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user