From 0a68a063bcf23b1d4b3e1c12b6963d42d1a876f7 Mon Sep 17 00:00:00 2001
From: Brian Canini <canini.16@osu.edu>
Date: Wed, 27 Jan 2021 16:09:58 -0500
Subject: [PATCH] Updating drupal/pantheon_advanced_page_cache (1.1.0 => 1.2.0)

---
 composer.json                                 |  2 +-
 composer.lock                                 | 16 ++--
 vendor/composer/installed.json                | 16 ++--
 .../.circleci/config.yml                      | 88 +++++++++----------
 .../.circleci/scripts/setup-drupal-repo.sh    | 20 +++++
 .../pantheon_advanced_page_cache/README.md    | 10 +++
 .../pantheon_advanced_page_cache.settings.yml |  1 +
 .../pantheon_advanced_page_cache.info.yml     |  6 +-
 .../pantheon_advanced_page_cache.install      | 13 +++
 .../pantheon_advanced_page_cache.services.yml |  2 +-
 .../CacheableResponseSubscriber.php           | 39 +++++++-
 .../behat/features/override_list_tag.feature  | 21 +++++
 ...pantheon_advanced_page_cache_test.info.yml |  6 +-
 13 files changed, 165 insertions(+), 75 deletions(-)
 create mode 100755 web/modules/pantheon_advanced_page_cache/.circleci/scripts/setup-drupal-repo.sh
 create mode 100644 web/modules/pantheon_advanced_page_cache/config/install/pantheon_advanced_page_cache.settings.yml
 create mode 100644 web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.install
 create mode 100644 web/modules/pantheon_advanced_page_cache/tests/behat/features/override_list_tag.feature

diff --git a/composer.json b/composer.json
index 6c97470805..1fe9250b8b 100644
--- a/composer.json
+++ b/composer.json
@@ -151,7 +151,7 @@
         "drupal/mobile_device_detection": "3.2",
         "drupal/module_filter": "3.1",
         "drupal/multiple_fields_remove_button": "^1.0@alpha",
-        "drupal/pantheon_advanced_page_cache": "1.1",
+        "drupal/pantheon_advanced_page_cache": "1.2",
         "drupal/paragraphs": "1.12",
         "drupal/pathauto": "1.8",
         "drupal/realname": "1.0.0-rc2",
diff --git a/composer.lock b/composer.lock
index 3cfc95e144..23bbea1cdd 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "483958ad644d5bd3351af88c32212e2b",
+    "content-hash": "98a67d5b8a5a722db167c54b0111285b",
     "packages": [
         {
             "name": "alchemy/zippy",
@@ -6576,17 +6576,17 @@
         },
         {
             "name": "drupal/pantheon_advanced_page_cache",
-            "version": "1.1.0",
+            "version": "1.2.0",
             "source": {
                 "type": "git",
                 "url": "https://git.drupalcode.org/project/pantheon_advanced_page_cache.git",
-                "reference": "8.x-1.1"
+                "reference": "8.x-1.2"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://ftp.drupal.org/files/projects/pantheon_advanced_page_cache-8.x-1.1.zip",
-                "reference": "8.x-1.1",
-                "shasum": "faef7abc7814c47dc0ba5cdb2c5a01f7386627ce"
+                "url": "https://ftp.drupal.org/files/projects/pantheon_advanced_page_cache-8.x-1.2.zip",
+                "reference": "8.x-1.2",
+                "shasum": "265f738df7e0d094f43b4f7a5b31ac3c5d799316"
             },
             "require": {
                 "drupal/core": "^8 || ^9"
@@ -6599,8 +6599,8 @@
             "type": "drupal-module",
             "extra": {
                 "drupal": {
-                    "version": "8.x-1.1",
-                    "datestamp": "1589904160",
+                    "version": "8.x-1.2",
+                    "datestamp": "1611003910",
                     "security-coverage": {
                         "status": "covered",
                         "message": "Covered by Drupal's security advisory policy"
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index e0aade52f2..5073324d1a 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -6778,18 +6778,18 @@
     },
     {
         "name": "drupal/pantheon_advanced_page_cache",
-        "version": "1.1.0",
-        "version_normalized": "1.1.0.0",
+        "version": "1.2.0",
+        "version_normalized": "1.2.0.0",
         "source": {
             "type": "git",
             "url": "https://git.drupalcode.org/project/pantheon_advanced_page_cache.git",
-            "reference": "8.x-1.1"
+            "reference": "8.x-1.2"
         },
         "dist": {
             "type": "zip",
-            "url": "https://ftp.drupal.org/files/projects/pantheon_advanced_page_cache-8.x-1.1.zip",
-            "reference": "8.x-1.1",
-            "shasum": "faef7abc7814c47dc0ba5cdb2c5a01f7386627ce"
+            "url": "https://ftp.drupal.org/files/projects/pantheon_advanced_page_cache-8.x-1.2.zip",
+            "reference": "8.x-1.2",
+            "shasum": "265f738df7e0d094f43b4f7a5b31ac3c5d799316"
         },
         "require": {
             "drupal/core": "^8 || ^9"
@@ -6802,8 +6802,8 @@
         "type": "drupal-module",
         "extra": {
             "drupal": {
-                "version": "8.x-1.1",
-                "datestamp": "1589904160",
+                "version": "8.x-1.2",
+                "datestamp": "1611003910",
                 "security-coverage": {
                     "status": "covered",
                     "message": "Covered by Drupal's security advisory policy"
diff --git a/web/modules/pantheon_advanced_page_cache/.circleci/config.yml b/web/modules/pantheon_advanced_page_cache/.circleci/config.yml
index 6c7397c29d..f07920472e 100644
--- a/web/modules/pantheon_advanced_page_cache/.circleci/config.yml
+++ b/web/modules/pantheon_advanced_page_cache/.circleci/config.yml
@@ -1,80 +1,72 @@
 version: 2
 # https://circleci.com/docs/configuration#machine
 jobs:
-    # @todo, separate build and test phases.
     build:
         docker:
-            # @todo, update container
-            - image: quay.io/pantheon-public/build-tools-ci:1.x
-        working_directory: ~/pantheon_advanced_page_cache
+            - image: quay.io/pantheon-public/build-tools-ci:6.x
         environment:
-            BASH_ENV: ~/.bashrc
-            TZ: "/usr/share/zoneinfo/America/Los_Angeles"
             TERMINUS_SITE: d9-papc2
         steps:
+            - run:
+                name: login-pantheon
+                command: terminus auth:login -n --machine-token="$TERMINUS_TOKEN"
+            # Start making a multidev right away in the background so that
+            # this slow step is done as soon as possible.
+            - run:
+                name: make-multidev
+                command: |
+                    terminus env:create $TERMINUS_SITE.dev ${CIRCLE_BUILD_NUM} || echo "mystery errors were being thrown by env:create so I am adding this OR (https://circleci.com/gh/pantheon-systems/pantheon_advanced_page_cache/610)"
+                    touch multidev-made.txt
+                background: true
             - checkout
-            - restore_cache:
-                key: dependency-cache-{{ checksum "composer.lock" }}
             - run:
                 name: Composer install
                 command: |
                   composer install
-                  drush help
-            - save_cache:
-                key: dependency-cache-{{ checksum "composer.lock" }}
-                paths:
-                  - ~/.composer/cache
+            - run:
+                name: Git Config
+                command: |
+                  git config --global user.email "$GitEmail"
+                  git config --global user.name "Circle CI"
+            - run:
+                # this configuration prevents a prompt from stopping git pushes.
+                name: ssh config
+                command: |
+                  touch $HOME/.ssh/config
+                  echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config"
             - run:
                 name: PHP Code Sniff
                 command: composer codesniff
             - run:
                 name: Unit Tests for Behat helper
                 command: composer phpunit
+#             - run:
+#                 # @todo, update core update mechanism for D9
+#                 name: apply upstream updates in dev
+#                 command: terminus connection:set $TERMINUS_SITE.dev git && terminus upstream:updates:apply $TERMINUS_SITE && terminus connection:set $TERMINUS_SITE.dev sftp
+
             - run:
-                name: login-pantheon
-                command: terminus auth:login -n --machine-token="$TERMINUS_TOKEN"
-            - run:
-                name: delete old sites
-                command: terminus env:list --field=id $TERMINUS_SITE | grep -v '[a-z]' | grep -Eo '[0-9]{1,9}' | sort --numeric-sort --reverse | sed 1,7d | xargs -n1 -I ENV terminus env:delete --yes $TERMINUS_SITE.ENV
+                name: Add modules to site
+                command: ./.circleci/scripts/setup-drupal-repo.sh
+
             - run:
-                name: ssh
+                name: Wait for multidev creation to be completed before doing site install.
                 command: |
-                  touch $HOME/.ssh/config
-                  echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config"
-            - run:
-                # @todo, update core update mechanism for D9
-                name: apply upstream updates in dev
-                command: terminus connection:set $TERMINUS_SITE.dev git && terminus upstream:updates:apply $TERMINUS_SITE && terminus connection:set $TERMINUS_SITE.dev sftp
-            - run:
-                name: make-multidev
-                command: terminus env:create $TERMINUS_SITE.dev ${CIRCLE_BUILD_NUM} || echo "mystery errors were being thrown by env:create so I am adding this OR (https://circleci.com/gh/pantheon-systems/pantheon_advanced_page_cache/610)"
+                    while [ ! -f multidev-made.txt ]
+                    do
+                      sleep 2
+                    done
+                    exit 0
+
             - run:
                 name: site install
                 command: |
                   terminus connection:set ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} sftp
-                  terminus drush ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} -- site-install -y
+                  terminus drush ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} -- site-install -y --quiet
                   terminus drush ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} -- cset system.performance cache.page.max_age 600 -y
 
             - run:
-                name: Permissions
-                command: |
-                  # composer will write to the default directory 
-                  $(terminus connection:info ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} --field=sftp_command) <<EOF
-                  chmod 755 code/web/sites/default
-                  exit
-                  EOF
-
-            - run:
-                name: Composer require papc
-                command: |
-                  terminus composer ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} -- config repositories.papc vcs git@github.com:pantheon-systems/pantheon_advanced_page_cache.git
-                  terminus composer ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} -- require drupal/pantheon_advanced_page_cache:dev-${CIRCLE_BRANCH}#${CIRCLE_SHA1}
-            - run:
-                name: composer require drupal/views_custom_cache_tag
-                command: |
-                  terminus composer ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} -- require drupal/views_custom_cache_tag
-            - run:
-                name: en -y views_custom_cache_tag_demo pantheon_advanced_page_cache
+                name: Enable modules
                 command: |
                   terminus drush ${TERMINUS_SITE}.${CIRCLE_BUILD_NUM} -- en -y views_custom_cache_tag_demo pantheon_advanced_page_cache
             - run:
diff --git a/web/modules/pantheon_advanced_page_cache/.circleci/scripts/setup-drupal-repo.sh b/web/modules/pantheon_advanced_page_cache/.circleci/scripts/setup-drupal-repo.sh
new file mode 100755
index 0000000000..90c19b121f
--- /dev/null
+++ b/web/modules/pantheon_advanced_page_cache/.circleci/scripts/setup-drupal-repo.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+set -e
+export TERMINUS_ENV=$CIRCLE_BUILD_NUM
+
+# Bring the code down to Circle so that modules can be added via composer.
+git clone $(terminus connection:info ${TERMINUS_SITE}.dev --field=git_url) --branch $TERMINUS_ENV drupal-site
+cd drupal-site
+
+
+composer -- config repositories.papc vcs git@github.com:pantheon-systems/pantheon_advanced_page_cache.git
+# Composer require the given commit of this module
+composer -- require drupal/views_custom_cache_tag "drupal/pantheon_advanced_page_cache:dev-${CIRCLE_BRANCH}#${CIRCLE_SHA1}"
+
+# Don't commit a submodule
+rm -rf web/modules/contrib/pantheon_advanced_page_cache/.git/
+
+# Make a git commit
+git add .
+git commit -m 'Result of build step'
+git push --set-upstream origin $TERMINUS_ENV
diff --git a/web/modules/pantheon_advanced_page_cache/README.md b/web/modules/pantheon_advanced_page_cache/README.md
index c2df80fb94..1ce74e3a31 100644
--- a/web/modules/pantheon_advanced_page_cache/README.md
+++ b/web/modules/pantheon_advanced_page_cache/README.md
@@ -22,6 +22,16 @@ A direct way of inspecting headers is with `curl -I`. This command will make a r
 
 `curl -IH "Pantheon-Debug:1" https://dev-cache-tags-demo.pantheonsite.io/ | grep -i Surrogate-Key-Raw`
 
+## Changing Listing Tags
+
+Prior to the 1.2 release, this module would change the cache tags used on default listings.
+This changing of was done to make cache hits more likely but resulted in [confusing cache clearing behavior](https://www.drupal.org/project/pantheon_advanced_page_cache/issues/2944229).
+Sites that installed this module prior to 1.2 should uninstall and reinstall or run this command to update their settings.
+
+```
+terminus drush [MACHINE-NAME-OF-SITE].[ENV-NAME] -- config:set pantheon_advanced_page_cache.settings --input-format=yaml   "override_list_tags" "false"
+```
+
 ## Limit on header size
 
 Pantheon's nginx configuration limits total header size to 32k.
diff --git a/web/modules/pantheon_advanced_page_cache/config/install/pantheon_advanced_page_cache.settings.yml b/web/modules/pantheon_advanced_page_cache/config/install/pantheon_advanced_page_cache.settings.yml
new file mode 100644
index 0000000000..68e445b930
--- /dev/null
+++ b/web/modules/pantheon_advanced_page_cache/config/install/pantheon_advanced_page_cache.settings.yml
@@ -0,0 +1 @@
+override_list_tags: false
\ No newline at end of file
diff --git a/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.info.yml b/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.info.yml
index e8ad3870f2..d276de1fd4 100644
--- a/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.info.yml
+++ b/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.info.yml
@@ -4,7 +4,7 @@ package: Performance and scalability
 type: module
 core_version_requirement: ^8 || ^9
 
-# Information added by Drupal.org packaging script on 2020-05-19
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2021-01-18
+version: '8.x-1.2'
 project: 'pantheon_advanced_page_cache'
-datestamp: 1589904163
+datestamp: 1611003913
diff --git a/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.install b/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.install
new file mode 100644
index 0000000000..eb7f642d69
--- /dev/null
+++ b/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.install
@@ -0,0 +1,13 @@
+<?php
+
+/**
+ * @file
+ * Update functions for the Pantheon Advanced Page Cache module.
+ */
+
+/**
+ * Set override_list_tags to TRUE for backwards compatibility. We recommend manually changing to FALSE for more consistent clearing. See README
+ */
+function pantheon_advanced_page_cache_update_8001() {
+  \Drupal::configFactory()->getEditable('pantheon_advanced_page_cache.settings')->set('override_list_tags', TRUE)->save();
+}
diff --git a/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.services.yml b/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.services.yml
index 6b0326c924..266c2398dd 100644
--- a/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.services.yml
+++ b/web/modules/pantheon_advanced_page_cache/pantheon_advanced_page_cache.services.yml
@@ -8,6 +8,6 @@ services:
       - { name: cache_tags_invalidator }
   pantheon_advanced_page_cache.cacheable_response_subscriber:
     class: Drupal\pantheon_advanced_page_cache\EventSubscriber\CacheableResponseSubscriber
-    arguments: ['@logger.channel.pantheon_advanced_page_cache']
+    arguments: ['@logger.channel.pantheon_advanced_page_cache', '@config.factory']
     tags:
       - { name: event_subscriber }
diff --git a/web/modules/pantheon_advanced_page_cache/src/EventSubscriber/CacheableResponseSubscriber.php b/web/modules/pantheon_advanced_page_cache/src/EventSubscriber/CacheableResponseSubscriber.php
index 905b5356ce..b9a72a9bc6 100644
--- a/web/modules/pantheon_advanced_page_cache/src/EventSubscriber/CacheableResponseSubscriber.php
+++ b/web/modules/pantheon_advanced_page_cache/src/EventSubscriber/CacheableResponseSubscriber.php
@@ -8,6 +8,7 @@
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use Psr\Log\LoggerInterface;
 use Drupal\Core\Logger\RfcLogLevel;
+use Drupal\Core\Config\ConfigFactoryInterface;
 
 /**
  * Adds Surrogate-Key header to cacheable master responses.
@@ -21,14 +22,44 @@ class CacheableResponseSubscriber implements EventSubscriberInterface {
    */
   protected $logger;
 
+  /**
+   * Configuration Factory.
+   *
+   * @var \Drupal\Core\Config\ConfigFactoryInterface
+   */
+  protected $configFactory;
+
   /**
    * Constructs a new DefaultExceptionHtmlSubscriber.
    *
    * @param \Psr\Log\LoggerInterface $logger
    *   The logger service.
+   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+   *   Configuration for this module.
    */
-  public function __construct(LoggerInterface $logger) {
+  public function __construct(LoggerInterface $logger, ConfigFactoryInterface $config_factory = NULL) {
+    if (!$config_factory instanceof ConfigFactoryInterface) {
+      @trigger_error('Not passing the config factory service as the second parameter to ' . __METHOD__ . ' is deprecated in pantheon_advanced_page_cache:8.x-1.2 and will throw a type error in pantheon_advanced_page_cache:8.x-2.0. Pass an instance of \\Drupal\\Core\\Config\\ConfigFactoryInterface. See https://www.drupal.org/node/2944229', E_USER_DEPRECATED);
+      $config_factory = \Drupal::service('config.factory');
+    }
     $this->logger = $logger;
+    $this->configFactory = $config_factory;
+  }
+
+  /**
+   * Returns whether entity_list tags should be overridden.
+   *
+   * Overriding these tags was the initial behavior of the 1.0 version of this
+   * module. That is no longer recommended.
+   */
+  public function getOverrideListTagsSetting() {
+    $config = $this->configFactory->get('pantheon_advanced_page_cache.settings');
+    // Only return FALSE if this config value is really set to false.
+    // A null value should return TRUE for backwards compatibility.
+    if ($config->get('override_list_tags') === FALSE) {
+      return FALSE;
+    }
+    return TRUE;
   }
 
   /**
@@ -49,8 +80,10 @@ public function onRespond(FilterResponseEvent $event) {
 
       // Rename all _list cache tags to _emit_list to avoid clearing list cache
       // tags by default.
-      foreach ($tags as $key => $tag) {
-        $tags[$key] = str_replace('_list', '_emit_list', $tag);
+      if ($this->getOverrideListTagsSetting()) {
+        foreach ($tags as $key => $tag) {
+          $tags[$key] = str_replace('_list', '_emit_list', $tag);
+        }
       }
 
       $tags_string = implode(' ', $tags);
diff --git a/web/modules/pantheon_advanced_page_cache/tests/behat/features/override_list_tag.feature b/web/modules/pantheon_advanced_page_cache/tests/behat/features/override_list_tag.feature
new file mode 100644
index 0000000000..a4ecbd1c4f
--- /dev/null
+++ b/web/modules/pantheon_advanced_page_cache/tests/behat/features/override_list_tag.feature
@@ -0,0 +1,21 @@
+Feature: Listing tags
+In order to control caching of lists
+As an administrator
+I want to toggle the setting for overriding cache tags
+
+  @api
+  Scenario: Core behavior
+    Given there are some "article" nodes
+    And "/" is caching
+    When a generate a "article" node
+    Then "/" has been purged
+    And "/" is caching
+
+  @api @current
+  Scenario: Old override
+    Given there are some "article" nodes
+    When I run drush "config:set pantheon_advanced_page_cache.settings --input-format=yaml   override_list_tags true"
+    And "/" is caching
+    When a generate a "article" node
+    And "/" has not been purged
+
diff --git a/web/modules/pantheon_advanced_page_cache/tests/modules/pantheon_advanced_page_cache_test/pantheon_advanced_page_cache_test.info.yml b/web/modules/pantheon_advanced_page_cache/tests/modules/pantheon_advanced_page_cache_test/pantheon_advanced_page_cache_test.info.yml
index 89b371af46..cfff256767 100644
--- a/web/modules/pantheon_advanced_page_cache/tests/modules/pantheon_advanced_page_cache_test/pantheon_advanced_page_cache_test.info.yml
+++ b/web/modules/pantheon_advanced_page_cache/tests/modules/pantheon_advanced_page_cache_test/pantheon_advanced_page_cache_test.info.yml
@@ -4,7 +4,7 @@ package: Testing
 type: module
 core_version_requirement: ^8 || ^9
 
-# Information added by Drupal.org packaging script on 2020-05-19
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2021-01-18
+version: '8.x-1.2'
 project: 'pantheon_advanced_page_cache'
-datestamp: 1589904163
+datestamp: 1611003913
-- 
GitLab