|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
|
6
|
|
|
* @package Controller |
|
7
|
|
|
* @subpackage Jobs |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Jobs\Subscription\Process\End; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Job controller for subscription processs end. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Jobs |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Controller\Jobs\Subscription\Process\Base |
|
|
|
|
|
|
22
|
|
|
implements \Aimeos\Controller\Jobs\Iface |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Returns the localized name of the job. |
|
26
|
|
|
* |
|
27
|
|
|
* @return string Name of the job |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getName() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Subscription process end' ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Returns the localized description of the job. |
|
37
|
|
|
* |
|
38
|
|
|
* @return string Description of the job |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getDescription() |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Terminates expired subscriptions' ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Executes the job. |
|
48
|
|
|
* |
|
49
|
|
|
* @throws \Aimeos\Controller\Jobs\Exception If an error occurs |
|
50
|
|
|
*/ |
|
51
|
|
|
public function run() |
|
52
|
|
|
{ |
|
53
|
|
|
$context = $this->getContext(); |
|
54
|
|
|
$config = $context->getConfig(); |
|
55
|
|
|
$logger = $context->getLogger(); |
|
56
|
|
|
|
|
57
|
|
|
/** controller/common/subscription/process/processors |
|
58
|
|
|
* List of processor names that should be executed for subscriptions |
|
59
|
|
|
* |
|
60
|
|
|
* For each subscription a number of processors for different tasks can be executed. |
|
61
|
|
|
* They can for example add a group to the customers' account during the customer |
|
62
|
|
|
* has an active subscribtion. |
|
63
|
|
|
* |
|
64
|
|
|
* @param array List of processor names |
|
65
|
|
|
* @since 2018.04 |
|
66
|
|
|
* @category Developer |
|
67
|
|
|
*/ |
|
68
|
|
|
$names = (array) $config->get( 'controller/common/subscription/process/processors', [] ); |
|
69
|
|
|
|
|
70
|
|
|
$processors = $this->getProcessors( $names ); |
|
71
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'subscription' ); |
|
72
|
|
|
|
|
73
|
|
|
$search = $manager->createSearch( true ); |
|
74
|
|
|
$expr = [ |
|
75
|
|
|
$search->compare( '<', 'subscription.dateend', date( 'Y-m-d' ) ), |
|
76
|
|
|
$search->getConditions(), |
|
77
|
|
|
]; |
|
78
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
|
79
|
|
|
$search->setSortations( [$search->sort( '+', 'subscription.id' )] ); |
|
80
|
|
|
|
|
81
|
|
|
$start = 0; |
|
82
|
|
|
|
|
83
|
|
|
do |
|
84
|
|
|
{ |
|
85
|
|
|
$search->setSlice( $start, 100 ); |
|
86
|
|
|
$items = $manager->searchItems( $search ); |
|
87
|
|
|
|
|
88
|
|
|
foreach( $items as $item ) |
|
89
|
|
|
{ |
|
90
|
|
|
try |
|
91
|
|
|
{ |
|
92
|
|
|
foreach( $processors as $processor ) { |
|
93
|
|
|
$processor->end( $item ); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$item->setStatus( 0 ); |
|
97
|
|
|
$manager->saveItem( $item ); |
|
98
|
|
|
} |
|
99
|
|
|
catch( \Exception $e ) |
|
100
|
|
|
{ |
|
101
|
|
|
$msg = 'Unable to process subscription with ID "%1$S": %2$s'; |
|
102
|
|
|
$logger->log( sprintf( $msg, $item->getId(), $e->getMessage() ) ); |
|
103
|
|
|
$logger->log( $e->getTraceAsString() ); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$count = count( $items ); |
|
108
|
|
|
$start += $count; |
|
109
|
|
|
} |
|
110
|
|
|
while( $count === $search->getSliceSize() ); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|