From 2052aaa443f6dbf048cfb7291f2fe886757ad79e Mon Sep 17 00:00:00 2001 From: Peter Lieverdink Date: Fri, 27 Oct 2023 12:15:29 +1100 Subject: [PATCH 1/2] fix: This is the controller we invoke, so make it return its response object. Even if nothing else happens to it, at least this way we do not trigger a spurious PHP error about needing to return a response. That will *hopefully* sort the last of the on-going GMS errors. Until the site is updated to Drupal 10. Refs: OPS-9090 --- .../src/Controller/PrintSectionController.php | 15 ++++++++++++--- .../src/Controller/ViewPdfController.php | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/html/modules/custom/gms_pdflink/src/Controller/PrintSectionController.php b/html/modules/custom/gms_pdflink/src/Controller/PrintSectionController.php index 1868d5a7..4a4c07f5 100644 --- a/html/modules/custom/gms_pdflink/src/Controller/PrintSectionController.php +++ b/html/modules/custom/gms_pdflink/src/Controller/PrintSectionController.php @@ -148,6 +148,7 @@ public function viewPrint($export_type, $entity_type, $entity_id) { $response = new RedirectResponse($base_url, 301); $response->send(); } + return $response; } @@ -208,9 +209,16 @@ public function downloadPdf($entity_type, $entity_id) { ' . $content . ' - '; - echo $html; - die; + '; + + // This could *possibly* be an HtmlResponse but things seem to work as-is. + $response = new Response(); + $response->headers->set('Pragma', 'no-cache'); + $response->headers->set('Content-type', 'text/html; charset=utf-8'); + $response->headers->set('Cache-control', 'private'); + $response->headers->set('Content-length', strlen($html)); + $response->setContent($html); + $response->send(); } else { global $base_url; @@ -218,6 +226,7 @@ public function downloadPdf($entity_type, $entity_id) { $response = new RedirectResponse($base_url, 301); $response->send(); } + return $response; } } diff --git a/html/modules/custom/gms_pdflink/src/Controller/ViewPdfController.php b/html/modules/custom/gms_pdflink/src/Controller/ViewPdfController.php index 1b9f5c07..e970d2ce 100644 --- a/html/modules/custom/gms_pdflink/src/Controller/ViewPdfController.php +++ b/html/modules/custom/gms_pdflink/src/Controller/ViewPdfController.php @@ -143,6 +143,7 @@ public function viewPrint($export_type, $entity_type, $entity_id) { $response = new RedirectResponse($base_url, 301); $response->send(); } + return $response; } } From ba62380b6b5c2ae2ffd4076ee9fa93de3b85a8ae Mon Sep 17 00:00:00 2001 From: Peter Lieverdink Date: Fri, 27 Oct 2023 12:38:55 +1100 Subject: [PATCH 2/2] chore: Add in Elastic APM so we may have an easier time of doing debugs in the future. Refs: OPS-IWANNASOIDO --- docker/99-elastic-apm-custom.ini | 19 +++++++++++++++++++ docker/Dockerfile | 6 ++++++ 2 files changed, 25 insertions(+) create mode 100644 docker/99-elastic-apm-custom.ini diff --git a/docker/99-elastic-apm-custom.ini b/docker/99-elastic-apm-custom.ini new file mode 100644 index 00000000..2d26cbf7 --- /dev/null +++ b/docker/99-elastic-apm-custom.ini @@ -0,0 +1,19 @@ +; This file contains the various settings for the Elastic APM PHP agent. For +; further details refers to the following URL: +; https://www.elastic.co/guide/en/apm/agent/php/current/configuration-reference.html +; + +[elastic] +elastic_apm.enabled = ${PHP_ELASTIC_APM_ENABLED} +;elastic_apm.api_key = "REPLACE_WITH_API_KEY" +elastic_apm.environment = "${PHP_ELASTIC_APM_ENVIRONMENT}" +elastic_apm.log_level = "INFO" +elastic_apm.log_level_stderr = "INFO" +elastic_apm.secret_token = "${PHP_ELASTIC_APM_TOKEN}" +;elastic_apm.server_timeout = "30s" +elastic_apm.server_url = "${PHP_ELASTIC_APM_SERVER}" +elastic_apm.service_name = "${PHP_ELASTIC_APM_SERVICE}" +elastic_apm.service_version = ${GIT_SHA} +;elastic_apm.transaction_max_spans = 500 +;elastic_apm.transaction_sample_rate = 1.0 +;elastic_apm.verify_server_cert = true diff --git a/docker/Dockerfile b/docker/Dockerfile index 992b6a0e..8822b418 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -61,3 +61,9 @@ COPY --from=builder /srv/www/composer.patches.json /srv/www/composer.patches.jso COPY --from=builder /srv/www/composer.lock /srv/www/composer.lock COPY --from=builder /srv/www/symfony.lock /srv/www/symfony.lock COPY --from=builder /srv/www/PATCHES /srv/www/PATCHES +COPY --from=builder /srv/www/docker/99-elastic-apm-custom.ini /tmp/99-elastic-apm-custom.ini + +RUN curl -L -o /tmp/apm-agent-php_all.apk https://github.com/elastic/apm-agent-php/releases/download/v1.10.0/apm-agent-php_1.10.0_all.apk && \ + apk add --allow-untrusted /tmp/apm-agent-php_all.apk && \ + rm -f /tmp/apm-agent-php_all.apk && \ + mv -f /tmp/99-elastic-apm-custom.ini /etc/php82/conf.d/99-elastic-apm-custom.ini