11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2020 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
1111use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
1212use Magento \Framework \GraphQl \Query \ResolverInterface ;
1313use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
14+ use Magento \Framework \Lock \LockManagerInterface ;
1415use Magento \GraphQl \Model \Query \ContextInterface ;
1516use Magento \Sales \Model \Reorder \Data \Error ;
1617use Magento \Sales \Model \OrderFactory ;
@@ -26,6 +27,10 @@ class Reorder implements ResolverInterface
2627 */
2728 private const ARGUMENT_ORDER_NUMBER = 'orderNumber ' ;
2829
30+ private const LOCK_PREFIX = 'reorder_lock_ ' ;
31+
32+ private const LOCK_TIMEOUT = 60 ;
33+
2934 /**
3035 * @var OrderFactory
3136 */
@@ -36,16 +41,24 @@ class Reorder implements ResolverInterface
3641 */
3742 private $ reorder ;
3843
44+ /**
45+ * @var LockManagerInterface
46+ */
47+ private $ lockManager ;
48+
3949 /**
4050 * @param \Magento\Sales\Model\Reorder\Reorder $reorder
4151 * @param OrderFactory $orderFactory
52+ * @param LockManagerInterface $lockManager
4253 */
4354 public function __construct (
4455 \Magento \Sales \Model \Reorder \Reorder $ reorder ,
45- OrderFactory $ orderFactory
56+ OrderFactory $ orderFactory ,
57+ LockManagerInterface $ lockManager
4658 ) {
4759 $ this ->orderFactory = $ orderFactory ;
4860 $ this ->reorder = $ reorder ;
61+ $ this ->lockManager = $ lockManager ;
4962 }
5063
5164 /**
@@ -74,7 +87,18 @@ public function resolve(
7487 );
7588 }
7689
77- $ reorderOutput = $ this ->reorder ->execute ($ orderNumber , $ storeId );
90+ $ lockName = implode ('_ ' , [$ currentUserId , $ storeId , $ orderNumber ]);
91+ if ($ this ->lockManager ->lock (self ::LOCK_PREFIX . $ lockName , self ::LOCK_TIMEOUT )) {
92+ try {
93+ $ reorderOutput = $ this ->reorder ->execute ($ orderNumber , $ storeId );
94+ } finally {
95+ $ this ->lockManager ->unlock (self ::LOCK_PREFIX . $ lockName );
96+ }
97+ } else {
98+ throw new \Magento \Framework \Exception \LocalizedException (
99+ __ ('The reorder is locked for processing. The concurrent request has been aborted. ' )
100+ );
101+ }
78102
79103 return [
80104 'cart ' => [
0 commit comments