Files
Investidor-V2/tools/legacy-content-qa.php
nala 20971d523f
tests / ci (push) Canceled after 0s
oportunidades 6
2026-10-10 21:17:46 +02:00

35 lines
2.2 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
// Rehearsal of the existing library importer only. Publication remains an authenticated action.
require_once __DIR__.'/portal-qa-environment.php';
$target = portalQaEnvironment();
require dirname(__DIR__).'/vendor/autoload.php';
$app = require dirname(__DIR__).'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
portalQaAssertTarget($target);
$private = storage_path('app/private/investmoz-v2/portal-audit');
$actors = json_decode(file_get_contents($private.'/resource-http-actors-private.json'), true, 512, JSON_THROW_ON_ERROR);
$actor = User::findOrFail($actors['manager']['id']);
config(['portal.managers' => ['opportunity-manager@example.invalid', 'geo-manager-qa@example.invalid']]);
if (($argv[1] ?? '') === 'apply') {
// Guard above precedes every write. Existing importer previews before any application.
Artisan::call('documents:import-batch', ['manifest' => 'legacy-agronegocio/manifest.json']);
$preview = Artisan::output();
$exit = Artisan::call('documents:import-batch', ['manifest' => 'legacy-agronegocio/manifest.json', '--apply' => true, '--actor' => (string) $actor->id]);
file_put_contents($private.'/legacy-import-preview-qa.txt', $preview.Artisan::output());
if ($exit !== 0) {
throw new RuntimeException('Legacy QA library import failed; inspect private preview.');
}
}
$resources = DB::table('portal_resources as r')->join('documents as d', 'd.id', '=', 'r.document_id')
->whereIn('d.external_id', ['legacy-tempo-post-171985-20260420', 'legacy-tempo-agronegocio-image-'.substr(hash_file('sha256', storage_path('app/private/document-import-staging/legacy-agronegocio/Agronegocio.png')), 0, 16)])
->get(['r.id', 'r.document_id', 'r.title', 'r.source_url', 'r.metadata_version', 'r.published', 'd.sha256', 'd.malware_scan_status', 'd.malware_scanned_sha256', 'd.status', 'd.file_name']);
$proof = ['target' => $target, 'resources' => $resources, 'active_writes' => 0, 'interface_observed' => false];
file_put_contents($private.'/legacy-import-qa.json', json_encode($proof, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
echo json_encode($proof, JSON_UNESCAPED_UNICODE);