35 lines
2.6 KiB
PHP
35 lines
2.6 KiB
PHP
<?php
|
|
|
|
// Initial source loading only. Everyday editing and disclosure use the portal.
|
|
$options = getopt('', ['apply', 'actor:', 'organization:']);
|
|
foreach (['APP_ENV' => 'testing', 'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441',
|
|
'DB_DATABASE' => 'simulator_fiscal_delta_20261021_test', 'DB_USERNAME' => 'postgres', 'DB_PASSWORD' => '', 'DB_URL' => ''] as $k => $v) {
|
|
putenv($k.'='.$v); $_ENV[$k] = $_SERVER[$k] = $v;
|
|
}
|
|
require __DIR__.'/../vendor/autoload.php';
|
|
$app = require __DIR__.'/../bootstrap/app.php';
|
|
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Services\CorridorAgribusinessOpportunities;
|
|
$target = DB::selectOne('SELECT current_database() AS name, inet_server_port() AS port');
|
|
if (! app()->environment('testing') || $target->name !== 'simulator_fiscal_delta_20261021_test' || (int) $target->port !== 55441) throw new RuntimeException('Refusing non-QA target.');
|
|
config(['portal.profile_access_enabled' => true, 'portal.opportunity_specialized_drafts_enabled' => true]);
|
|
$service = app(CorridorAgribusinessOpportunities::class);
|
|
if (! isset($options['apply'])) {echo json_encode(['target' => $target, 'entries' => $service->entries(), 'writes' => 0], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); exit;}
|
|
$actor = App\Models\User::findOrFail($options['actor'] ?? 0);
|
|
$organization = $options['organization'] ?? '';
|
|
$request = Illuminate\Http\Request::create('/minhas-oportunidades/drafts', 'POST');
|
|
$request->setUserResolver(fn () => $actor); $app->instance('request', $request);
|
|
$dir = storage_path('app/private/agribusiness-opportunities-20261023');
|
|
if (! is_dir($dir)) mkdir($dir, 0700, true);
|
|
if (! file_exists($dir.'/before.json')) {
|
|
$before = [];
|
|
foreach (['opportunities', 'audit_events', 'development_corridors', 'portal_role_assignments', 'portal_resources', 'documents'] as $table) $before[$table] = DB::table($table)->orderBy('id')->get()->all();
|
|
file_put_contents($dir.'/before.json', json_encode($before, JSON_THROW_ON_ERROR));
|
|
}
|
|
$records = $service->register($actor, $organization);
|
|
$receipt = ['target' => $target, 'source_sha256' => $service::SOURCE_HASH, 'records' => $records, 'total' => count($records),
|
|
'new' => count(array_filter($records, fn ($r) => $r['created'])), 'published' => App\Models\Opportunity::whereIn('id', array_column($records, 'id'))->published()->count(), 'active_writes' => 0];
|
|
file_put_contents($dir.'/receipt.json', json_encode($receipt, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
|
|
echo json_encode($receipt, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).PHP_EOL;
|