45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Console\Commands;
|
||
|
|
|
||
|
|
use App\Models\Layer;
|
||
|
|
use App\Models\Feature;
|
||
|
|
use Illuminate\Console\Command;
|
||
|
|
|
||
|
|
class MigrateGeojsonToFeatures extends Command
|
||
|
|
{
|
||
|
|
protected $signature = 'migrate:geojson-to-features';
|
||
|
|
protected $description = 'Migrate features from layer.geojson_data to features table';
|
||
|
|
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
$layers = Layer::whereNotNull('geojson_data')->get();
|
||
|
|
$totalFeatures = 0;
|
||
|
|
|
||
|
|
foreach ($layers as $layer) {
|
||
|
|
$geojson = $layer->geojson_data;
|
||
|
|
if (!isset($geojson['features'])) continue;
|
||
|
|
|
||
|
|
foreach ($geojson['features'] as $featureData) {
|
||
|
|
$geometry = $featureData['geometry'];
|
||
|
|
$props = $featureData['properties'] ?? [];
|
||
|
|
|
||
|
|
Feature::create([
|
||
|
|
'layer_id' => $layer->id,
|
||
|
|
'name' => $props['name'] ?? null,
|
||
|
|
'geometry' => $geometry,
|
||
|
|
'properties' => $props,
|
||
|
|
'template_id' => $props['template_id'] ?? null,
|
||
|
|
'progress' => $props['progress'] ?? 0,
|
||
|
|
'responsible' => $props['responsible'] ?? null,
|
||
|
|
]);
|
||
|
|
$totalFeatures++;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Opcional: Marcar la capa como migrada (podrías agregar columna 'migrated_at')
|
||
|
|
$this->info("Layer {$layer->id} ({$layer->name}) migrated.");
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->info("Total features migrated: {$totalFeatures}");
|
||
|
|
}
|
||
|
|
}
|