sanitize($source['content_html']); $html = (new App\Services\CorridorAgribusiness)->enrich($original); $doc = new DOMDocument; $doc->loadHTML(''.$html); $xpath = new DOMXPath($doc); $groups = $xpath->query('//ul[starts-with(@id,"agronegocio-oportunidades-")]'); $entries = $xpath->query('//ul[starts-with(@id,"agronegocio-oportunidades-")]/li'); if ($groups->length !== 6 || $entries->length !== 34 || $sourceHash !== hash_file('sha256', $path)) { throw new RuntimeException('Incomplete integration or source changed.'); } // Removing only the additions must recover the exact sanitized original. foreach (iterator_to_array($groups) as $group) { $group->parentNode->removeChild($group->previousSibling); $group->parentNode->removeChild($group->nextSibling); $group->parentNode->removeChild($group); } $body = $doc->getElementsByTagName('body')->item(0); $recovered = implode('', array_map(fn ($node) => $doc->saveHTML($node), iterator_to_array($body->childNodes))); if ($recovered !== $original) { throw new RuntimeException('Original displayed content was changed.'); } echo json_encode(['source_sha256' => $sourceHash, 'source_unchanged' => true, 'original_display_preserved' => true, 'corridors' => 6, 'agribusiness_entries' => 34, 'database_writes' => 0], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).PHP_EOL;