/
Requester.php
172 lines (131 loc) · 4.87 KB
/
Requester.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/*
* @author M2E Pro Developers Team
* @copyright 2011-2015 ESS-UA [M2E Pro]
* @license Commercial use is forbidden
*/
namespace Ess\M2ePro\Model\Ebay\Connector\Item;
abstract class Requester extends \Ess\M2ePro\Model\Ebay\Connector\Command\Pending\Requester
{
const TIMEOUT_INCREMENT_FOR_ONE_IMAGE = 30;
protected $isRealTime = false;
/** @var \Ess\M2ePro\Model\Ebay\Listing\Product\Action\Logger $logger */
protected $logger = NULL;
//########################################
public function setIsRealTime($isRealTime = true)
{
$this->isRealTime = $isRealTime;
return $this;
}
public function isRealTime()
{
return $this->isRealTime;
}
//########################################
protected function buildConnectionInstance()
{
$connection = parent::buildConnectionInstance();
$connection->setTimeout($this->getRequestTimeOut());
return $connection;
}
protected function getRequestTimeOut()
{
return 300;
}
//########################################
public function process()
{
if ($this->isRealTime()) {
try {
parent::process();
} catch (\Ess\M2ePro\Model\Exception\Connection $exception) {
if ($this->account->getChildObject()->isModeSandbox()) {
throw $exception;
}
$this->processResponser();
} catch (\Exception $exception) {
if (strpos($exception->getMessage(), 'code:34') === false ||
$this->account->getChildObject()->isModeSandbox()
) {
throw $exception;
}
$this->processResponser();
}
if ($this->getResponser()->getStatus() != \Ess\M2ePro\Helper\Data::STATUS_SUCCESS) {
$this->getLogger()->setStatus($this->getResponser()->getStatus());
}
$this->params['logs_action_id'] = $this->getResponser()->getLogsActionId();
return;
}
$this->eventBeforeExecuting();
$this->getProcessingRunner()->start();
}
//########################################
public function getStatus()
{
return $this->getLogger()->getStatus();
}
/**
* @return array|integer
*/
public function getLogsActionId()
{
return $this->params['logs_action_id'];
}
//########################################
abstract protected function getActionType();
abstract protected function getLogsAction();
protected function getOrmActionType()
{
switch ($this->getActionType()) {
case \Ess\M2ePro\Model\Listing\Product::ACTION_LIST:
return 'ListAction';
case \Ess\M2ePro\Model\Listing\Product::ACTION_RELIST:
return 'Relist';
case \Ess\M2ePro\Model\Listing\Product::ACTION_REVISE:
return 'Revise';
case \Ess\M2ePro\Model\Listing\Product::ACTION_STOP:
return 'Stop';
}
throw new \Ess\M2ePro\Model\Exception('Wrong Action type');
}
protected function getLockIdentifier()
{
if ($this->getActionType() == \Ess\M2ePro\Model\Listing\Product::ACTION_LIST) {
return 'list';
}
return strtolower($this->getOrmActionType());
}
//########################################
/**
* @return \Ess\M2ePro\Model\Ebay\Listing\Product\Action\Logger
* @throws \Ess\M2ePro\Model\Exception
*/
public function getLogger()
{
if (is_null($this->logger)) {
/** @var \Ess\M2ePro\Model\Ebay\Listing\Product\Action\Logger $logger */
$logger = $this->modelFactory->getObject('Ebay\Listing\Product\Action\Logger');
if (!isset($this->params['logs_action_id']) || !isset($this->params['status_changer'])) {
throw new \Ess\M2ePro\Model\Exception('Product Connector has not received some params');
}
$logger->setActionId((int)$this->params['logs_action_id']);
$logger->setAction($this->getLogsAction());
switch ($this->params['status_changer']) {
case \Ess\M2ePro\Model\Listing\Product::STATUS_CHANGER_UNKNOWN:
$initiator = \Ess\M2ePro\Helper\Data::INITIATOR_UNKNOWN;
break;
case \Ess\M2ePro\Model\Listing\Product::STATUS_CHANGER_USER:
$initiator = \Ess\M2ePro\Helper\Data::INITIATOR_USER;
break;
default:
$initiator = \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION;
break;
}
$logger->setInitiator($initiator);
$this->logger = $logger;
}
return $this->logger;
}
//########################################
}