1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
7
|
|
|
* @package Controller |
8
|
|
|
* @subpackage Jobs |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\Controller\Jobs\Order\Service\Async; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Updates the payment or delivery status for services with asynchronous methods. |
17
|
|
|
* |
18
|
|
|
* @package Controller |
19
|
|
|
* @subpackage Jobs |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\Controller\Jobs\Base |
23
|
|
|
implements \Aimeos\Controller\Jobs\Iface |
24
|
|
|
{ |
25
|
|
|
/** controller/jobs/order/service/async/name |
26
|
|
|
* Class name of the used order service async scheduler controller implementation |
27
|
|
|
* |
28
|
|
|
* Each default job controller can be replace by an alternative imlementation. |
29
|
|
|
* To use this implementation, you have to set the last part of the class |
30
|
|
|
* name as configuration value so the controller factory knows which class it |
31
|
|
|
* has to instantiate. |
32
|
|
|
* |
33
|
|
|
* For example, if the name of the default class is |
34
|
|
|
* |
35
|
|
|
* \Aimeos\Controller\Jobs\Order\Service\Async\Standard |
36
|
|
|
* |
37
|
|
|
* and you want to replace it with your own version named |
38
|
|
|
* |
39
|
|
|
* \Aimeos\Controller\Jobs\Order\Service\Async\Myasync |
40
|
|
|
* |
41
|
|
|
* then you have to set the this configuration option: |
42
|
|
|
* |
43
|
|
|
* controller/jobs/order/service/async/name = Myasync |
44
|
|
|
* |
45
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
46
|
|
|
* so take care that the configuration value is exactly named like the last |
47
|
|
|
* part of the class name. |
48
|
|
|
* |
49
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
50
|
|
|
* characters are possible! You should always start the last part of the class |
51
|
|
|
* name with an upper case character and continue only with lower case characters |
52
|
|
|
* or numbers. Avoid chamel case names like "MyAsync"! |
53
|
|
|
* |
54
|
|
|
* @param string Last part of the class name |
55
|
|
|
* @since 2014.07 |
56
|
|
|
*/ |
57
|
|
|
|
58
|
|
|
/** controller/jobs/order/service/async/decorators/excludes |
59
|
|
|
* Excludes decorators added by the "common" option from the order service async controllers |
60
|
|
|
* |
61
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
62
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
63
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
64
|
|
|
* modify what is returned to the caller. |
65
|
|
|
* |
66
|
|
|
* This option allows you to remove a decorator added via |
67
|
|
|
* "controller/jobs/common/decorators/default" before they are wrapped |
68
|
|
|
* around the job controller. |
69
|
|
|
* |
70
|
|
|
* controller/jobs/order/service/async/decorators/excludes = array( 'decorator1' ) |
71
|
|
|
* |
72
|
|
|
* This would remove the decorator named "decorator1" from the list of |
73
|
|
|
* common decorators ("\Aimeos\Controller\Jobs\Common\Decorator\*") added via |
74
|
|
|
* "controller/jobs/common/decorators/default" to this job controller. |
75
|
|
|
* |
76
|
|
|
* @param array List of decorator names |
77
|
|
|
* @since 2015.09 |
78
|
|
|
* @see controller/jobs/common/decorators/default |
79
|
|
|
* @see controller/jobs/order/service/async/decorators/global |
80
|
|
|
* @see controller/jobs/order/service/async/decorators/local |
81
|
|
|
*/ |
82
|
|
|
|
83
|
|
|
/** controller/jobs/order/service/async/decorators/global |
84
|
|
|
* Adds a list of globally available decorators only to the order service async controllers |
85
|
|
|
* |
86
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
87
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
88
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
89
|
|
|
* modify what is returned to the caller. |
90
|
|
|
* |
91
|
|
|
* This option allows you to wrap global decorators |
92
|
|
|
* ("\Aimeos\Controller\Jobs\Common\Decorator\*") around the job controller. |
93
|
|
|
* |
94
|
|
|
* controller/jobs/order/service/async/decorators/global = array( 'decorator1' ) |
95
|
|
|
* |
96
|
|
|
* This would add the decorator named "decorator1" defined by |
97
|
|
|
* "\Aimeos\Controller\Jobs\Common\Decorator\Decorator1" only to this job controller. |
98
|
|
|
* |
99
|
|
|
* @param array List of decorator names |
100
|
|
|
* @since 2015.09 |
101
|
|
|
* @see controller/jobs/common/decorators/default |
102
|
|
|
* @see controller/jobs/order/service/async/decorators/excludes |
103
|
|
|
* @see controller/jobs/order/service/async/decorators/local |
104
|
|
|
*/ |
105
|
|
|
|
106
|
|
|
/** controller/jobs/order/service/async/decorators/local |
107
|
|
|
* Adds a list of local decorators only to the order service async controllers |
108
|
|
|
* |
109
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
110
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
111
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
112
|
|
|
* modify what is returned to the caller. |
113
|
|
|
* |
114
|
|
|
* This option allows you to wrap local decorators |
115
|
|
|
* ("\Aimeos\Controller\Jobs\Order\Service\Async\Decorator\*") around this job controller. |
116
|
|
|
* |
117
|
|
|
* controller/jobs/order/service/async/decorators/local = array( 'decorator2' ) |
118
|
|
|
* |
119
|
|
|
* This would add the decorator named "decorator2" defined by |
120
|
|
|
* "\Aimeos\Controller\Jobs\Order\Service\Async\Decorator\Decorator2" only to this job |
121
|
|
|
* controller. |
122
|
|
|
* |
123
|
|
|
* @param array List of decorator names |
124
|
|
|
* @since 2015.09 |
125
|
|
|
* @see controller/jobs/common/decorators/default |
126
|
|
|
* @see controller/jobs/order/service/async/decorators/excludes |
127
|
|
|
* @see controller/jobs/order/service/async/decorators/global |
128
|
|
|
*/ |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns the localized name of the job. |
133
|
|
|
* |
134
|
|
|
* @return string Name of the job |
135
|
|
|
*/ |
136
|
|
|
public function getName() : string |
137
|
|
|
{ |
138
|
|
|
return $this->context()->translate( 'controller/jobs', 'Batch update of payment/delivery status' ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Returns the localized description of the job. |
144
|
|
|
* |
145
|
|
|
* @return string Description of the job |
146
|
|
|
*/ |
147
|
|
|
public function getDescription() : string |
148
|
|
|
{ |
149
|
|
|
return $this->context()->translate( 'controller/jobs', 'Executes payment or delivery service providers that uses batch updates' ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Executes the job. |
155
|
|
|
* |
156
|
|
|
* @throws \Aimeos\Controller\Jobs\Exception If an error occurs |
157
|
|
|
*/ |
158
|
|
|
public function run() |
159
|
|
|
{ |
160
|
|
|
$context = $this->context(); |
161
|
|
|
$manager = \Aimeos\MShop::create( $context, 'service' ); |
162
|
|
|
|
163
|
|
|
$filter = $manager->filter(); |
164
|
|
|
$cursor = $manager->cursor( $filter ); |
165
|
|
|
|
166
|
|
|
while( $items = $manager->iterate( $cursor ) ) |
167
|
|
|
{ |
168
|
|
|
foreach( $items as $item ) |
169
|
|
|
{ |
170
|
|
|
try |
171
|
|
|
{ |
172
|
|
|
$manager->getProvider( $item, $item->getType() )->updateAsync(); |
173
|
|
|
} |
174
|
|
|
catch( \Exception $e ) |
175
|
|
|
{ |
176
|
|
|
$str = 'Executing updateAsyc() of "%1$s" failed: %2$s'; |
177
|
|
|
$msg = sprintf( $str, $item->getProvider(), $e->getMessage() . "\n" . $e->getTraceAsString() ); |
178
|
|
|
$context->logger()->error( $msg, 'order/service/async' ); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|