Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ env:
- ORCA_PACKAGES_CONFIG_ALTER=../acquia_commercemanager/tests/packages_alter.yml
- ORCA_TELEMETRY_ENABLE=TRUE

#temporarily kill other jobs...
jobs:
fast_finish: true
include:
Expand All @@ -41,7 +42,6 @@ jobs:
- env: ORCA_JOB=INTEGRATED_DEV
- env: ORCA_JOB=CORE_NEXT
# Temporary allowances.
- env: ORCA_JOB=STATIC_CODE_ANALYSIS
- env: ORCA_JOB=DEPRECATED_CODE_SCAN
# You may need to allow the D9 readiness job to fail in the short term.
- { php: "7.3", env: ORCA_JOB=D9_READINESS }
Expand All @@ -51,6 +51,7 @@ before_install:
- ../orca/bin/travis/before_install.sh

install: ../orca/bin/travis/install.sh
#- ./tests/install.sh

before_script: ../orca/bin/travis/before_script.sh

Expand Down
2 changes: 1 addition & 1 deletion acquia_commercemanager.info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Acquia Commerce Manager
type: module
description: This module lays the foundation to use the Acquia Commerce Connector Service.
core: 8.x
core_version_requirement: ^8.7.7 || ^9
package: Commerce
hidden: true
11 changes: 3 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@
"commerceguys/intl": "~1.0",
"drupal/address": "^1.4.0",
"drupal/consumers": "^1.4",
"drupal/field_group": "^3.0@beta",
"drupal/core": "^8.7.7 || ^9",
"drupal/field_group": "3.x-dev",
"drupal/inline_entity_form": "^1.0@rc",
"drupal/key_value_field": "~1.0",
"drupal/pcb": "~1.0",
"drupal/pcb": "^2.0",
"drupal/simple_oauth": "^4"
},
"extra": {
"branch-alias": {
"dev-8.x-1.x": "1.x-dev"
},
"enable-patching": true,
"patches": {
"drupal/simple_oauth": {
"#3078547 - Merge Simple OAuth Extras in Simple OAuth": "https://www.drupal.org/files/issues/2020-04-07/3078547-install-field-definitions-43.patch"
}
}
},
"minimum-stability": "dev",
Expand Down
2 changes: 1 addition & 1 deletion features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Defines application features from the specific context.
*/
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
class FeatureContext extends RawDrupalContext {

private $simple_product;

Expand Down
2 changes: 1 addition & 1 deletion modules/acm/acm.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Acquia Commerce Manager
type: module
description: This module lays the foundation to use the Acquia Commerce Connector Service.
core: 8.x
core_version_requirement: ^8.7.7 || ^9
package: Commerce
libraries:
- acm/global_styles
Expand Down
5 changes: 3 additions & 2 deletions modules/acm/acm.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use Drupal\acm\User\CommerceAccountInterface;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;

/**
* For the all.
Expand Down Expand Up @@ -114,10 +115,10 @@ function acm_mail_tokens(array &$replacements, array $data, array $options) {
* they can change their password.
*/
function acm_commerce_user_pass_reset_url(CommerceAccountInterface $account, array $options = []) {
$timestamp = REQUEST_TIME;
$timestamp = \Drupal::time()->getRequestTime();
$langcode = isset($options['langcode']) ? $options['langcode'] : $account->getPreferredLangcode();
$email = $account->getEmail();
return \Drupal::url('acm.external_user_password_reset',
return Url::fromRoute('acm.external_user_password_reset',
[
'email' => base64_encode($email),
'timestamp' => $timestamp,
Expand Down
2 changes: 1 addition & 1 deletion modules/acm/acm.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ services:

acm.commerce_user_manager:
class: Drupal\acm\User\CommerceUserManager
arguments: ['@cache.commerce_user', '@acm.current_user']
arguments: ['@cache.commerce_user', '@acm.current_user', '@datetime.time']

acm.route_subscriber:
class: Drupal\acm\Routing\CommerceUserRoutes
Expand Down
5 changes: 3 additions & 2 deletions modules/acm/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "This module lays the foundation to use the Acquia Commerce Connector Service.",
"license": "GPL-2.0-or-later",
"require": {
"drupal/pcb": "~1.0",
"drupal/simple_oauth": "^3"
"drupal/core": "^8.7.7 || ^9",
"drupal/pcb": "^2.0",
"drupal/simple_oauth": "^4.0"
}
}
2 changes: 1 addition & 1 deletion modules/acm/src/Connector/TestAPIWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private function generateOrder($email = '', $status = 'shipped', $state = 'new')
$order['coupon'] = 'GREAT DEAL';
$order['status'] = $status;
$order['state'] = $state;
$order['created_at'] = REQUEST_TIME;
$order['created_at'] = \Drupal::time()->getRequestTime();
$order['order_id'] = $this->generateOrderId();

return $order;
Expand Down
29 changes: 20 additions & 9 deletions modules/acm/src/Controller/CommerceUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Drupal\acm\User\AccountProxyInterface;
use Drupal\acm\User\CommerceUserSession;
use Drupal\acm_cart\CartStorageInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\user\UserAuthInterface;
Expand All @@ -28,6 +28,13 @@ class CommerceUserController extends ControllerBase {
*/
protected $dateFormatter;

/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;

/**
* The session storage.
*
Expand Down Expand Up @@ -68,6 +75,8 @@ class CommerceUserController extends ControllerBase {
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\acm\SessionStoreInterface $session
* The session.
* @param \Drupal\user\UserAuthInterface $user_auth
Expand All @@ -79,8 +88,9 @@ class CommerceUserController extends ControllerBase {
* @param \Drupal\acm_cart\CartStorageInterface $cartStorage
* Cart Storage object.
*/
public function __construct(DateFormatterInterface $date_formatter, SessionStoreInterface $session, UserAuthInterface $user_auth, AccountProxyInterface $commerce_user_manager, APIWrapperInterface $api_wrapper, CartStorageInterface $cartStorage) {
public function __construct(DateFormatterInterface $date_formatter, TimeInterface $time, SessionStoreInterface $session, UserAuthInterface $user_auth, AccountProxyInterface $commerce_user_manager, APIWrapperInterface $api_wrapper, CartStorageInterface $cartStorage) {
$this->dateFormatter = $date_formatter;
$this->time = $time;
$this->session = $session;
$this->userAuth = $user_auth;
$this->commerceUserManager = $commerce_user_manager;
Expand All @@ -94,6 +104,7 @@ public function __construct(DateFormatterInterface $date_formatter, SessionStore
public static function create(ContainerInterface $container) {
return new static(
$container->get('date.formatter'),
$container->get('datetime.time'),
$container->get('acm.session_storage'),
$container->get('acm.auth'),
$container->get('acm.commerce_user_manager'),
Expand Down Expand Up @@ -218,23 +229,23 @@ public function resetPassLogin(Request $request, $email, $timestamp, $hash) {
$account = new CommerceUserSession($user);

// The current user is not logged in, so check the parameters.
$current = REQUEST_TIME;
$current = $this->time->getRequestTime();
// Time out, in seconds, until login URL expires.
$timeout = $this->config('user.settings')->get('password_reset_timeout');

if ($current - $timestamp > $timeout) {
drupal_set_message($this->t('you have tried to use a one-time password reset link that has expired. Please request a new one using the form below.'), 'error');
$this->messenger()->addError('you have tried to use a one-time password reset link that has expired. Please request a new one using the form below.');
return $this->redirect('acm.external_user_password');
}
elseif (($timestamp <= $current) && Crypt::hashEquals($hash, acm_commerce_user_pass_rehash($account, $timestamp))) {
elseif (($timestamp <= $current) && hash_equals($hash, acm_commerce_user_pass_rehash($account, $timestamp))) {
$password_values = $request->get('new_password');
$pass1 = trim($password_values['pass1']);
$pass2 = trim($password_values['pass2']);
if (strlen($pass1) > 0 || strlen($pass2) > 0) {
if (strcmp($pass1, $pass2)) {
// Passwords don't match, return back to the reset password page so
// they can correct.
drupal_set_message($this->t('The passwords you entered do not match.'), 'error');
$this->messenger()->addError('The passwords you entered do not match.');
return $this->redirect(
'acm.external_user_password_reset', [
'email' => base64_encode($email),
Expand All @@ -260,16 +271,16 @@ public function resetPassLogin(Request $request, $email, $timestamp, $hash) {
}

if ($updated_user) {
drupal_set_message($this->t('Your password has been updated.'));
$this->messenger()->addStatus('Your password has been updated.');
return $this->redirect('acm_customer.view_page');
}
else {
drupal_set_message($this->t('There was an issue updating your password.'), 'error');
$this->messenger()->addError('There was an issue updating your password.');
return $this->redirect('acm.external_user_password');
}
}

drupal_set_message($this->t('You have tried to use a one-time password reset link that has either been used or is no longer valid. Please request a new one using the form below.'), 'error');
$this->messenger()->addError('You have tried to use a one-time password reset link that has either been used or is no longer valid. Please request a new one using the form below.');
return $this->redirect('acm.external_user_password');
}

Expand Down
4 changes: 2 additions & 2 deletions modules/acm/src/Element/AcmAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public static function validateAddress(&$element, FormStateInterface $form_state

// Address is valid and no suggestion came back.
if (isset($response['result']['valid']) && empty($response['result']['suggested'])) {
drupal_set_message($address_review_text, 'status');
\Drupal::messenger()->addStatus($address_review_text);
}
// Address is in review and there's a suggestion that we use to pre-fill
// the address fields.
Expand All @@ -374,7 +374,7 @@ public static function validateAddress(&$element, FormStateInterface $form_state
}
}

drupal_set_message($address_review_text, 'status');
\Drupal::messenger()->addStatus($address_review_text);
}
// Address failed validation.
else {
Expand Down
4 changes: 2 additions & 2 deletions modules/acm/src/Form/CommerceUserLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$account = $this->commerceUserManager->getAccount();

if ($account && $account->isAnonymous()) {
drupal_set_message($this->t('There was an issue logging you in, please try again.'));
$this->messenger('There was an issue logging you in, please try again.');
}
else {
$this->logger('acm')->notice('Commerce session opened for %name.', ['%name' => $account->getUsername()]);
$this->logger('acm')->notice('Commerce session opened for %name.', ['%name' => $account->getAccountName()]);

// Convert the guest cart after login.
$customer_id = $account->id();
Expand Down
4 changes: 2 additions & 2 deletions modules/acm/src/Form/CommerceUserPasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
if ($ecomm_pass_reset) {
$this->apiWrapper->resetCustomerPassword($email);
$this->logger('acm')->notice('Password reset triggered for email %email.', ['%email' => $email]);
drupal_set_message($user_message);
$this->messenger->addMessage($user_message);
return;
}

Expand All @@ -146,7 +146,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$mail = \Drupal::service('plugin.manager.mail')->mail('acm', 'commerce_user_reset_password', $email, $langcode, $params, $site_mail);
if (!empty($mail)) {
$this->logger('acm')->notice('Password reset instructions mailed to %email.', ['%email' => $email]);
drupal_set_message($user_message);
$this->messenger->addMessage($user_message);
}

$form_state->setRedirect('acm.external_user_login');
Expand Down
4 changes: 2 additions & 2 deletions modules/acm/src/Form/CommerceUserPasswordTokenResetForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}

if ($updated_user) {
drupal_set_message($this->t('Your password has been updated.'));
$this->messenger->addStatus('Your password has been updated.');
return $this->redirect('acm_customer.view_page');
}
else {
drupal_set_message($this->t('There was an issue updating your password.'), 'error');
$this->messenger->addError('There was an issue updating your password.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/acm/src/Form/CommerceUserRegistrationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$account = new CommerceUserSession($customer);
$account->setAccessToken($token);
$this->currentUser->setAccount($account);
$this->logger('acm')->notice('Commerce session opened for %name.', ['%name' => $account->getUsername()]);
$this->logger('acm')->notice('Commerce session opened for %name.', ['%name' => $account->getAccountName()]);

// Convert the guest cart after login.
$customer_id = $account->id();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

// phpcs:ignore PHPCompatibility.Keywords.ForbiddenNamesAsDeclared.resourceFound
namespace Drupal\acm\Plugin\rest\resource;

use Drupal\acm\VerifyMappingInterface;
Expand Down
17 changes: 14 additions & 3 deletions modules/acm/src/User/CommerceUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\acm\User;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\CacheBackendInterface;

/**
Expand Down Expand Up @@ -32,17 +33,27 @@ class CommerceUserManager implements AccountProxyInterface, CommerceAccountInter
*/
protected $currentCommerceUser;

/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;

/**
* Constructor.
*
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend interface to use for temp storing user info.
* @param \Drupal\acm\CommerceAccountProxyInterface $current_commerce_user
* @param \Drupal\acm\User\CommerceAccountProxyInterface $current_commerce_user
* The current commerce user.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The Time service.
*/
public function __construct(CacheBackendInterface $cache, CommerceAccountProxyInterface $current_commerce_user) {
public function __construct(CacheBackendInterface $cache, CommerceAccountProxyInterface $current_commerce_user, TimeInterface $time) {
$this->cache = $cache;
$this->currentCommerceUser = $current_commerce_user;
$this->time = $time;
}

/**
Expand All @@ -67,7 +78,7 @@ public function setAccount($account = NULL) {

// Store the account for 5 minutes to prevent unnecessary API calls.
$access_token = $this->getAccessToken();
$expire = 600 + \Drupal::time()->getRequestTime();
$expire = 600 + $this->time->getRequestTime();
$this->cache->set(self::USER_STORAGE_KEY . ':' . $access_token, $account, $expire);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/acm/src/User/CommerceUserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function getDisplayName() {
public function getTimeZone() {
// Will return the value for system.date.timezone.default since this user
// is always anonymous in drupal.
return drupal_get_user_timezone();
return date_default_timezone_get();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Configuration for I18nHelper'
type: module
package: Testing
core: 8.x
core_version_requirement: ^8.7.7 || ^9
Loading