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-2022 |
7
|
|
|
* @package Controller |
8
|
|
|
* @subpackage Jobs |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\Controller\Jobs\Order\Cleanup\Unfinished; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Order cleanup job controller for removing unfinished orders. |
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/cleanup/unfinished/name |
26
|
|
|
* Class name of the used order cleanup unfinished 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\Cleanup\Unfinished\Standard |
36
|
|
|
* |
37
|
|
|
* and you want to replace it with your own version named |
38
|
|
|
* |
39
|
|
|
* \Aimeos\Controller\Jobs\Order\Cleanup\Unfinished\Myunfinished |
40
|
|
|
* |
41
|
|
|
* then you have to set the this configuration option: |
42
|
|
|
* |
43
|
|
|
* controller/jobs/order/cleanup/unfinished/name = Myunfinished |
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 "MyUnfinished"! |
53
|
|
|
* |
54
|
|
|
* @param string Last part of the class name |
55
|
|
|
* @since 2014.03 |
56
|
|
|
*/ |
57
|
|
|
|
58
|
|
|
/** controller/jobs/order/cleanup/unfinished/decorators/excludes |
59
|
|
|
* Excludes decorators added by the "common" option from the order cleanup unfinished 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/cleanup/unfinished/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/cleanup/unfinished/decorators/global |
80
|
|
|
* @see controller/jobs/order/cleanup/unfinished/decorators/local |
81
|
|
|
*/ |
82
|
|
|
|
83
|
|
|
/** controller/jobs/order/cleanup/unfinished/decorators/global |
84
|
|
|
* Adds a list of globally available decorators only to the order cleanup unfinished 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/cleanup/unfinished/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/cleanup/unfinished/decorators/excludes |
103
|
|
|
* @see controller/jobs/order/cleanup/unfinished/decorators/local |
104
|
|
|
*/ |
105
|
|
|
|
106
|
|
|
/** controller/jobs/order/cleanup/unfinished/decorators/local |
107
|
|
|
* Adds a list of local decorators only to the order cleanup unfinished 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\Cleanup\Unfinished\Decorator\*") around this job controller. |
116
|
|
|
* |
117
|
|
|
* controller/jobs/order/cleanup/unfinished/decorators/local = array( 'decorator2' ) |
118
|
|
|
* |
119
|
|
|
* This would add the decorator named "decorator2" defined by |
120
|
|
|
* "\Aimeos\Controller\Jobs\Order\Cleanup\Unfinished\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/cleanup/unfinished/decorators/excludes |
127
|
|
|
* @see controller/jobs/order/cleanup/unfinished/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', 'Removes unfinished orders' ); |
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', 'Deletes unfinished orders an makes their products and coupon codes available again' ); |
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, 'order' ); |
162
|
|
|
$baseManager = \Aimeos\MShop::create( $context, 'order/base' ); |
163
|
|
|
$controller = \Aimeos\Controller\Common\Order\Factory::create( $context ); |
164
|
|
|
|
165
|
|
|
$filter = $manager->filter() |
166
|
|
|
->add( 'order.statuspayment', '==', -1 ) |
167
|
|
|
->add( 'order.mtime', '<', $this->ctime() ); |
168
|
|
|
$cursor = $manager->cursor( $filter ); |
169
|
|
|
|
170
|
|
|
while( $items = $manager->iterate( $cursor ) ) |
171
|
|
|
{ |
172
|
|
|
foreach( $items as $item ) { |
173
|
|
|
$controller->unblock( $item ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$baseManager->delete( $items->getBaseId() ); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Returns the creation time when orders can be deleted |
183
|
|
|
* |
184
|
|
|
* @return string Date/time in "YYYY-mm-dd HH:mm:ss" format |
185
|
|
|
*/ |
186
|
|
|
protected function ctime() : string |
187
|
|
|
{ |
188
|
|
|
/** controller/jobs/order/cleanup/unfinished/keep-hours |
189
|
|
|
* Release the ordered products after the configured time if no payment was confirmed |
190
|
|
|
* |
191
|
|
|
* After a customer creates an order and before he is redirected to the |
192
|
|
|
* payment provider (if necessary), the ordered products, coupon codes, |
193
|
|
|
* etc. are blocked for that customer. Normally, they should be released |
194
|
|
|
* a certain amount of time if no payment confirmation arrives so |
195
|
|
|
* customers can order the products and use the coupon codes again. |
196
|
|
|
* |
197
|
|
|
* The configured number of hours should be high enough to avoid releasing |
198
|
|
|
* products and coupon codes in case of temporary technical problems! |
199
|
|
|
* |
200
|
|
|
* The unfinished orders are deleted afterwards to keep the database clean. |
201
|
|
|
* |
202
|
|
|
* @param integer Number of hours |
203
|
|
|
* @since 2014.07 |
204
|
|
|
*/ |
205
|
|
|
$hours = $this->context()->config()->get( 'controller/jobs/order/cleanup/unfinished/keep-hours', 24 ); |
206
|
|
|
return date( 'Y-m-d H:i:s', time() - 3600 * $hours ); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|