|
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\Unpaid; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Order cleanup job controller for removing unpaid 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/unpaid/name |
|
26
|
|
|
* Class name of the used order cleanup unpaid 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\Unpaid\Standard |
|
36
|
|
|
* |
|
37
|
|
|
* and you want to replace it with your own version named |
|
38
|
|
|
* |
|
39
|
|
|
* \Aimeos\Controller\Jobs\Order\Cleanup\Unpaid\Myunpaid |
|
40
|
|
|
* |
|
41
|
|
|
* then you have to set the this configuration option: |
|
42
|
|
|
* |
|
43
|
|
|
* controller/jobs/order/cleanup/unpaid/name = Myunpaid |
|
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 "MyUnpaid"! |
|
53
|
|
|
* |
|
54
|
|
|
* @param string Last part of the class name |
|
55
|
|
|
* @since 2014.07 |
|
56
|
|
|
*/ |
|
57
|
|
|
|
|
58
|
|
|
/** controller/jobs/order/cleanup/unpaid/decorators/excludes |
|
59
|
|
|
* Excludes decorators added by the "common" option from the order cleanup unpaid 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/unpaid/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/unpaid/decorators/global |
|
80
|
|
|
* @see controller/jobs/order/cleanup/unpaid/decorators/local |
|
81
|
|
|
*/ |
|
82
|
|
|
|
|
83
|
|
|
/** controller/jobs/order/cleanup/unpaid/decorators/global |
|
84
|
|
|
* Adds a list of globally available decorators only to the order cleanup unpaid 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/unpaid/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/unpaid/decorators/excludes |
|
103
|
|
|
* @see controller/jobs/order/cleanup/unpaid/decorators/local |
|
104
|
|
|
*/ |
|
105
|
|
|
|
|
106
|
|
|
/** controller/jobs/order/cleanup/unpaid/decorators/local |
|
107
|
|
|
* Adds a list of local decorators only to the order cleanup unpaid 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\Unpaid\Decorator\*") around this job controller. |
|
116
|
|
|
* |
|
117
|
|
|
* controller/jobs/order/cleanup/unpaid/decorators/local = array( 'decorator2' ) |
|
118
|
|
|
* |
|
119
|
|
|
* This would add the decorator named "decorator2" defined by |
|
120
|
|
|
* "\Aimeos\Controller\Jobs\Order\Cleanup\Unpaid\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/unpaid/decorators/excludes |
|
127
|
|
|
* @see controller/jobs/order/cleanup/unpaid/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 unpaid 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 unpaid orders to keep the database clean' ); |
|
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.mtime', '<', $this->mtime() ) |
|
167
|
|
|
->add( 'order.statuspayment', '<', \Aimeos\MShop\Order\Item\Base::PAY_REFUND ); |
|
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 modifiction time when orders can be deleted |
|
183
|
|
|
* |
|
184
|
|
|
* @return string Date/time in "YYYY-mm-dd HH:mm:ss" format |
|
185
|
|
|
*/ |
|
186
|
|
|
protected function mtime() : string |
|
187
|
|
|
{ |
|
188
|
|
|
/** controller/jobs/order/cleanup/unpaid/keep-days |
|
189
|
|
|
* Removes all orders from the database that are unpaid |
|
190
|
|
|
* |
|
191
|
|
|
* Orders with a payment status of deleted, canceled or refused are only |
|
192
|
|
|
* necessary for the records for a certain amount of time. Afterwards, |
|
193
|
|
|
* they can be deleted from the database most of the time. |
|
194
|
|
|
* |
|
195
|
|
|
* The number of days should be high enough to ensure that you keep the |
|
196
|
|
|
* orders as long as your customers will be asking what happend to their |
|
197
|
|
|
* orders. |
|
198
|
|
|
* |
|
199
|
|
|
* @param integer Number of days |
|
200
|
|
|
* @since 2014.07 |
|
201
|
|
|
* @category User |
|
202
|
|
|
*/ |
|
203
|
|
|
$days = $this->context()->config()->get( 'controller/jobs/order/cleanup/unpaid/keep-days', 3 ); |
|
204
|
|
|
return date( 'Y-m-d H:i:s', time() - 86400 * $days ); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|