|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of EC-CUBE |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* http://www.lockon.co.jp/ |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
12
|
|
|
* of the License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program; if not, write to the Free Software |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Doctrine\EventSubscriber; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\Common\EventSubscriber; |
|
28
|
|
|
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; |
|
29
|
|
|
use Doctrine\ORM\Events; |
|
30
|
|
|
use Eccube\Application; |
|
31
|
|
|
|
|
32
|
|
|
class ClearCacheEventSubscriber implements EventSubscriber |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var array 対象のエンティティクラス名(FQDN) |
|
36
|
|
|
*/ |
|
37
|
|
|
private $classes; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var Application |
|
41
|
|
|
*/ |
|
42
|
|
|
private $app; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param Application $app |
|
46
|
|
|
*/ |
|
47
|
1059 |
|
public function __construct(Application $app) |
|
48
|
|
|
{ |
|
49
|
1059 |
|
$this->app = $app; |
|
50
|
|
|
|
|
51
|
1059 |
|
$this->classes = array( |
|
52
|
1059 |
|
'Eccube\Entity\BaseInfo', |
|
53
|
1059 |
|
'Eccube\Entity\Category', |
|
54
|
1059 |
|
'Eccube\Entity\PageLayout', |
|
55
|
1059 |
|
'Eccube\Entity\Block', |
|
56
|
1059 |
|
'Eccube\Entity\BlockPosition', |
|
57
|
|
|
); |
|
58
|
1059 |
|
} |
|
59
|
|
|
|
|
60
|
1059 |
|
public function getSubscribedEvents() |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
1059 |
|
$options = $this->app['config']['doctrine_cache']; |
|
63
|
1059 |
|
$clearCache = $options['result_cache']['clear_cache']; |
|
64
|
|
|
|
|
65
|
1059 |
|
if ($clearCache) { |
|
66
|
|
|
return array( |
|
67
|
1059 |
|
Events::postPersist, |
|
68
|
1059 |
|
Events::postRemove, |
|
69
|
1059 |
|
Events::postUpdate, |
|
70
|
1059 |
|
); |
|
71
|
|
|
} |
|
72
|
|
|
// キャッシュの削除オプションが無効の場合は、イベントを定義せず空の配列を返す. |
|
73
|
|
|
return array(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
640 |
|
public function postPersist(LifecycleEventArgs $args) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
640 |
|
$this->app['monolog']->debug('clear result cache: postPersist'); |
|
79
|
640 |
|
$this->clearCache($args); |
|
80
|
640 |
|
} |
|
81
|
|
|
|
|
82
|
107 |
|
public function postRemove(LifecycleEventArgs $args) |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
107 |
|
$this->app['monolog']->debug('clear result cache: postRemove'); |
|
85
|
107 |
|
$this->clearCache($args); |
|
86
|
107 |
|
} |
|
87
|
|
|
|
|
88
|
393 |
|
public function postUpdate(LifecycleEventArgs $args) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
393 |
|
$this->app['monolog']->debug('clear result cache: postUpdate'); |
|
91
|
393 |
|
$this->clearCache($args); |
|
92
|
393 |
|
} |
|
93
|
|
|
|
|
94
|
661 |
|
protected function clearCache(LifecycleEventArgs $args) |
|
95
|
|
|
{ |
|
96
|
661 |
|
$entity = $args->getObject(); |
|
97
|
661 |
|
$classes = $this->classes; |
|
98
|
661 |
|
foreach ($classes as $class) { |
|
99
|
661 |
|
if ($entity instanceof $class) { |
|
100
|
90 |
|
$this->app['monolog']->debug('clear result cache: '.$class); |
|
101
|
90 |
|
$cache = $args->getObjectManager()->getConfiguration()->getResultCacheImpl(); |
|
|
|
|
|
|
102
|
90 |
|
$cache->deleteAll(); |
|
103
|
90 |
|
break; |
|
104
|
|
|
} |
|
105
|
661 |
|
} |
|
106
|
661 |
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|