Initial commit - construprogress app
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user