38 lines
2.0 KiB
PHP
38 lines
2.0 KiB
PHP
<?php
|
|
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
require dirname(__DIR__).'/vendor/autoload.php';
|
|
$app = require dirname(__DIR__).'/bootstrap/app.php';
|
|
$app->make(Kernel::class)->bootstrap();
|
|
$db = DB::connection();
|
|
$report = $db->transaction(function () use ($db) {
|
|
$db->statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY');
|
|
|
|
return [
|
|
'generated_at' => date(DATE_ATOM),
|
|
'target' => $db->selectOne('select current_database() as database, inet_server_port() as port'),
|
|
'projects' => $db->table('projects')->orderBy('code')->get(),
|
|
'dossiers' => $db->table('investment_dossiers')->orderBy('title')->get(),
|
|
'clusters' => $db->table('economic_clusters')->orderBy('code')->get(),
|
|
'cluster_projects' => $db->table('cluster_projects')->get(),
|
|
'opportunity_clusters' => $db->table('opportunity_clusters')->get(),
|
|
'value_chains' => $db->table('value_chains')->get(),
|
|
'value_chain_links' => $db->table('value_chain_links')->get(),
|
|
'project_locations' => $db->table('project_locations')->get(),
|
|
'opportunity_projects' => $db->table('opportunity_projects')->get(),
|
|
'opportunities' => $db->table('opportunities')->get(),
|
|
'profiles' => $db->table('opportunity_profiles')->get(),
|
|
'locations' => $db->table('geo_locations')->get(['id', 'name', 'location_type', 'parent_id', 'source_system', 'external_id', 'data_classification', 'deleted_at']),
|
|
'geometries' => $db->table('geo_geometries')->select(['id', 'geo_location_id', 'geometry_type', 'source_system', 'external_id', 'data_classification', 'deleted_at'])->selectRaw('ST_AsGeoJSON(geom) as geometry')->get(),
|
|
];
|
|
});
|
|
$directory = storage_path('app/private/anchor-project-reconciliation');
|
|
if (! is_dir($directory)) {
|
|
mkdir($directory, 0700, true);
|
|
}
|
|
$file = $directory.'/inventory-'.date('Ymd-His').'.json';
|
|
file_put_contents($file, json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
|
|
echo $file.PHP_EOL;
|