Commit 9f67785f authored by Anton Kuzmenko's avatar Anton Kuzmenko
Browse files

Issue #3141821: Automated Drupal 9 compatibility fixes

parent b20cf99c
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -15,4 +15,3 @@
    "MongoDB"
  ]
}
+8 −8
Original line number Diff line number Diff line
@@ -41,11 +41,11 @@ class SupercookieAdminSettingsForm extends ConfigFormBase {
    $database = Database::getConnectionInfo();
    $date_formatter = \Drupal::service('date.formatter');

    drupal_set_message(t('Changing the %expiration, %cookie or %header values will invalidate all current supercookie data. Users will receive a new supercookie when they next visit the site.', array(
    $this->messenger()->addWarning(t('Changing the %expiration, %cookie or %header values will invalidate all current supercookie data. Users will receive a new supercookie when they next visit the site.', array(
      '%expiration' => t('Cookie expiration'),
      '%cookie' => t('Cookie name'),
      '%header' => t('HTTP header'),
    )), 'warning', FALSE);
    )), FALSE);

    $form['intro'] = array(
      '#markup' => '<p>' . t("Supercookie values will be unique across @report within the specified expiration interval.</p>", array(
@@ -154,8 +154,8 @@ MONGODB;
      '#type' => 'details',
      '#title' => t('Obfuscation'),
      '#description' => t("Supercookies have been criticized as a means of silently gathering user data. While this module only stores a hash of the user agent and server-side variables collected from the user, you may still wish to obfuscate the default machine names and @alias (the current alias is %alias).", array(
        '@alias' => Link::fromTextAndUrl(t('alias the "supercookie" path'), Url::fromRoute('path.admin_overview'))->toString(),
        '%alias' => \Drupal::service('path.alias_manager')->getAliasByPath('/supercookie'),
        '@alias' => Link::fromTextAndUrl(t('alias the "supercookie" path'), Url::fromRoute('entity.path_alias.collection'))->toString(),
        '%alias' => \Drupal::service('path_alias.manager')->getAliasByPath('/supercookie'),
      )),
      '#open' => TRUE,
    );
@@ -204,8 +204,8 @@ MONGODB;
      ->set('supercookie_track_tid', $form_state->getValue('supercookie_track_tid'))
      ->save();

    drupal_get_messages();
    drupal_set_message(t('The configuration options have been saved.'));
    $this->messenger()->deleteAll();
    $this->messenger()->addStatus(t('The configuration options have been saved.'));

    $truncate = FALSE;
    if (!$truncate && $config->get('supercookie_expire') != $form['options']['supercookie_expire']['#default_value']) {
@@ -229,10 +229,10 @@ MONGODB;
          ->execute();
      }

      drupal_set_message(t('Cleared all supercookie sessions.'));
      $this->messenger()->addStatus(t('Cleared all supercookie sessions.'));
    }
    else {
      drupal_set_message(t('All data has been preserved.'));
      $this->messenger()->addStatus(t('All data has been preserved.'));
    }

    parent::submitForm($form, $form_state);
+5 −6
Original line number Diff line number Diff line
@@ -45,8 +45,7 @@ class SupercookieManager {
      ->get();

    $this->mongodb = $this->config['supercookie_mongodb'] && class_exists('\MongoDB\Client');
    $this->mongodbConn = $settings->get('mongodb');
    $this->mongodbConn = $this->mongodbConn['default'];
    $this->mongodbConn = $this->mongodb ?? $settings->get('mongodb')['default'];

    return $this;
  }
@@ -406,7 +405,7 @@ class SupercookieManager {
  public function save($timestamp) {

    // Ignore client time; use server time exclusively.
    $timestamp = REQUEST_TIME;
    $timestamp = \Drupal::time()->getRequestTime();
    $expires = $this->config['supercookie_expire'];
    if ($expires == 'calendar_day') {
      $expires = strtotime(date('Y-m-d', $timestamp) . ' + 1 day');
@@ -528,9 +527,9 @@ class SupercookieManager {
      'user' => $uname,
      'cookie' => $object->scid,
      'hash' => $object->data,
      'created' => format_date($object->created, 'e'),
      'modified' => format_date($object->modified, 'e'),
      'expires' => format_date($object->expires, 'e'),
      'created' => \Drupal::service('date.formatter')->format($object->created, 'e'),
      'modified' => \Drupal::service('date.formatter')->format($object->modified, 'e'),
      'expires' => \Drupal::service('date.formatter')->format($object->expires, 'e'),
    );

    // Try to unserialize row blobs.
+2 −2
Original line number Diff line number Diff line
@@ -4,10 +4,10 @@ namespace Drupal\supercookie;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Path\AliasManager;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Path\PathValidator;
use Drupal\node\Entity\Node;
use Drupal\path_alias\AliasManager;

/**
 * Handles HTTP responses for Supercookie requests.
@@ -139,7 +139,7 @@ class SupercookieResponse {
    $once = &drupal_static(get_class($this) . Unicode::ucwords(__FUNCTION__), FALSE);
    if (empty($once)) {
      if (empty($supercookie->dnt)) {
        $this->request->server->set('HTTP_' . str_replace('-', '_', Unicode::strtoupper($this->config['supercookie_name_header'])), $supercookie->data);
        $this->request->server->set('HTTP_' . str_replace('-', '_', mb_strtoupper($this->config['supercookie_name_header'])), $supercookie->data);
        header($supercookie->config['supercookie_name_header'] . ': ' . $supercookie->data, TRUE);
        setcookie($supercookie->config['supercookie_name_server'], $supercookie->data, $supercookie->expires, '/');
      }
+1 −1
Original line number Diff line number Diff line
name: Supercookie
type: module
core: 8.x
core_version_requirement: ^8.8 || ^9
description: "Set a persistent cookie regardless of a user's browser settings."
configure: supercookie.admin_settings_form
libraries:
Loading