count spatial plannings business and non business and create pbg task detail and add to syncrone daily
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\SpatialPlanning;
|
||||
use App\Models\RetributionProposal;
|
||||
|
||||
class CheckSpatialPlanningConstraints extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'spatial:check-constraints';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Check spatial planning foreign key constraints and show statistics';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Checking Spatial Planning Constraints...');
|
||||
$this->newLine();
|
||||
|
||||
try {
|
||||
// Get total spatial plannings
|
||||
$totalSpatialPlannings = SpatialPlanning::count();
|
||||
|
||||
// Get spatial plannings with retribution proposals
|
||||
$withProposals = SpatialPlanning::whereHas('retributionProposals')->count();
|
||||
|
||||
// Get spatial plannings without retribution proposals
|
||||
$withoutProposals = SpatialPlanning::whereDoesntHave('retributionProposals')->count();
|
||||
|
||||
// Get total retribution proposals
|
||||
$totalProposals = RetributionProposal::count();
|
||||
|
||||
// Get retribution proposals linked to spatial plannings
|
||||
$linkedProposals = RetributionProposal::whereNotNull('spatial_planning_id')->count();
|
||||
|
||||
// Get standalone retribution proposals
|
||||
$standaloneProposals = RetributionProposal::whereNull('spatial_planning_id')->count();
|
||||
|
||||
// Display statistics
|
||||
$this->table(
|
||||
['Metric', 'Count'],
|
||||
[
|
||||
['Total Spatial Plannings', $totalSpatialPlannings],
|
||||
['├─ With Retribution Proposals', $withProposals],
|
||||
['└─ Without Retribution Proposals', $withoutProposals],
|
||||
['', ''],
|
||||
['Total Retribution Proposals', $totalProposals],
|
||||
['├─ Linked to Spatial Planning', $linkedProposals],
|
||||
['└─ Standalone Proposals', $standaloneProposals],
|
||||
]
|
||||
);
|
||||
|
||||
$this->newLine();
|
||||
|
||||
// Show constraint implications
|
||||
if ($withProposals > 0) {
|
||||
$this->warn("⚠️ CONSTRAINT WARNING:");
|
||||
$this->warn(" {$withProposals} spatial plannings have retribution proposals linked to them.");
|
||||
$this->warn(" These cannot be deleted directly due to foreign key constraints.");
|
||||
$this->newLine();
|
||||
|
||||
$this->info("💡 TRUNCATE OPTIONS:");
|
||||
$this->info(" • Use --truncate to delete ALL data (spatial plannings + linked proposals)");
|
||||
$this->info(" • Use --safe-truncate to delete only spatial plannings without proposals");
|
||||
$this->info(" • Manual cleanup: Delete proposals first, then spatial plannings");
|
||||
} else {
|
||||
$this->info("✅ No foreign key constraints found.");
|
||||
$this->info(" All spatial plannings can be safely truncated.");
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
|
||||
// Show example commands
|
||||
$this->info("📋 EXAMPLE COMMANDS:");
|
||||
$this->info(" php artisan spatial:init --truncate # Delete all data (smart method)");
|
||||
$this->info(" php artisan spatial:init --safe-truncate # Delete safe data only");
|
||||
$this->info(" php artisan spatial:init --force-truncate # Force truncate (disable FK checks)");
|
||||
$this->info(" php artisan spatial:init file.csv --truncate # Import with truncate");
|
||||
|
||||
return 0;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error checking constraints: ' . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ClearDatabaseSessions extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'session:clear-db {--force : Force the operation without confirmation}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Clear all database sessions';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!$this->option('force') && !$this->confirm('Are you sure you want to clear all database sessions?')) {
|
||||
$this->info('Operation cancelled.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
$count = DB::table('sessions')->count();
|
||||
DB::table('sessions')->delete();
|
||||
|
||||
$this->info("Successfully cleared {$count} database sessions.");
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Failed to clear database sessions: ' . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,54 +42,4 @@ class ScrapingData extends Command
|
||||
|
||||
$this->info("Scraping job dispatched successfully");
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
// public function handle()
|
||||
// {
|
||||
|
||||
// try {
|
||||
// // Create a record with "processing" status
|
||||
// $import_datasource = ImportDatasource::create([
|
||||
// 'message' => 'Initiating scraping...',
|
||||
// 'response_body' => null,
|
||||
// 'status' => 'processing',
|
||||
// 'start_time' => now()
|
||||
// ]);
|
||||
|
||||
// // Run the service
|
||||
// $service_google_sheet = new ServiceGoogleSheet();
|
||||
// $service_google_sheet->run_service();
|
||||
|
||||
// // Run the ServicePbgTask with injected Guzzle Client
|
||||
// $this->service_pbg_task->run_service();
|
||||
|
||||
// // run the service pbg task assignments
|
||||
// $this->service_tab_pbg_task->run_service();
|
||||
|
||||
// // Update the record status to "success" after completion
|
||||
// $import_datasource->update([
|
||||
// 'status' => 'success',
|
||||
// 'message' => 'Scraping completed successfully.',
|
||||
// 'finish_time' => now()
|
||||
// ]);
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
|
||||
// // Log the error for debugging
|
||||
// Log::error('Scraping failed: ' . $e->getMessage(), ['trace' => $e->getTraceAsString()]);
|
||||
|
||||
// // Handle errors by updating the status to "failed"
|
||||
// if (isset($import_datasource)) {
|
||||
// $import_datasource->update([
|
||||
// 'status' => 'failed',
|
||||
// 'response_body' => 'Error: ' . $e->getMessage(),
|
||||
// 'finish_time' => now()
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user