Reconciliar fontes instaladas 423bd512d8c5 com main
This commit is contained in:
@@ -40,7 +40,7 @@ final class LegacyContent
|
||||
abort_unless($this->available(), 404);
|
||||
$identity = config('legacy_content.articles.'.$slug);
|
||||
abort_unless(is_array($identity) && ($identity['publishable'] ?? false), 404);
|
||||
$row = $this->publicResources()->where('d.external_id', $identity['external_id'])->first();
|
||||
$row = $this->identityResources()->get($identity['external_id']);
|
||||
abort_unless($row !== null, 404);
|
||||
$binary = app(VerifiedDocumentBinary::class)->respond($row);
|
||||
$bytes = $binary instanceof BinaryFileResponse ? file_get_contents($binary->getFile()->getPathname()) : $binary->getContent();
|
||||
@@ -106,7 +106,7 @@ final class LegacyContent
|
||||
public function articleForResource(int $resourceId): array
|
||||
{
|
||||
abort_unless($this->available(), 404);
|
||||
$externalId = $this->publicResources()->where('r.id', $resourceId)->first()?->external_id;
|
||||
$externalId = $this->identityResources()->firstWhere('resource_id', $resourceId)?->legacy_identity;
|
||||
foreach (config('legacy_content.articles', []) as $slug => $identity) {
|
||||
if ($identity['external_id'] === $externalId && $identity['publishable']) {
|
||||
return $this->article($slug);
|
||||
@@ -132,7 +132,7 @@ final class LegacyContent
|
||||
private function related(string $group, ?string $except = null): array
|
||||
{
|
||||
$identities = array_filter(config('legacy_content.articles', []), fn ($identity, $slug) => $identity['group'] === $group && $identity['publishable'] && $slug !== $except, ARRAY_FILTER_USE_BOTH);
|
||||
$resources = $this->publicResources()->whereIn('d.external_id', array_column($identities, 'external_id'))->get()->keyBy('external_id');
|
||||
$resources = $this->identityResources();
|
||||
$result = [];
|
||||
foreach ($identities as $slug => $identity) {
|
||||
$row = $resources->get($identity['external_id']);
|
||||
@@ -146,8 +146,7 @@ final class LegacyContent
|
||||
|
||||
private function localLinks(string $html): string
|
||||
{
|
||||
$public = $this->publicResources()->whereIn('d.external_id', array_column(config('legacy_content.articles', []), 'external_id'))
|
||||
->get()->keyBy('external_id');
|
||||
$public = $this->identityResources();
|
||||
$links = [];
|
||||
foreach (config('legacy_content.articles', []) as $slug => $identity) {
|
||||
if ($identity['publishable'] && $public->get($identity['external_id'])?->source_url === $identity['source_url']) {
|
||||
@@ -208,6 +207,39 @@ final class LegacyContent
|
||||
});
|
||||
}
|
||||
|
||||
/** Resolve explicit transport aliases without changing original IDs, versions or relations. */
|
||||
private function identityResources(): \Illuminate\Support\Collection
|
||||
{
|
||||
$identities = array_column(config('legacy_content.articles', []), 'external_id');
|
||||
$aliases = config('legacy_content_aliases', []);
|
||||
$rows = $this->publicResources()->where(function ($query) use ($identities, $aliases) {
|
||||
$query->whereIn('d.external_id', $identities);
|
||||
if ($aliases !== []) {
|
||||
$query->orWhereIn('r.id', array_column($aliases, 'resource_id'));
|
||||
}
|
||||
})->get();
|
||||
$resolved = collect();
|
||||
foreach ($rows as $row) {
|
||||
$identity = in_array($row->external_id, $identities, true) ? $row->external_id : null;
|
||||
foreach ($aliases as $original => $alias) {
|
||||
if ((int) $row->resource_id === (int) $alias['resource_id']
|
||||
&& $row->external_id === $alias['external_id']
|
||||
&& hash_equals($alias['sha256'], trim($row->sha256))
|
||||
&& $row->source_url === $alias['source_url']) {
|
||||
abort_if($identity !== null && $identity !== $original, 409, 'Correspondência de artigo em reconciliação.');
|
||||
$identity = $original;
|
||||
}
|
||||
}
|
||||
if ($identity === null) {
|
||||
continue;
|
||||
}
|
||||
abort_if($resolved->has($identity), 409, 'Correspondência de artigo em reconciliação.');
|
||||
$row->legacy_identity = $identity;
|
||||
$resolved->put($identity, $row);
|
||||
}
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
private function publicResources(): Builder
|
||||
{
|
||||
return DB::table('portal_resources as r')->join('documents as d', 'd.id', '=', 'r.document_id')
|
||||
|
||||
Reference in New Issue
Block a user