|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Repositories\CacheWarmer\EavAttributeOptionValueCacheWarmer |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Repositories\CacheWarmer; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\MemberNames; |
|
24
|
|
|
use TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Cache warmer implementation to pre-load EAV attribute option value data. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Tim Wagner <[email protected]> |
|
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
32
|
|
|
* @link https://github.com/techdivision/import |
|
33
|
|
|
* @link http://www.techdivision.com |
|
34
|
|
|
*/ |
|
35
|
|
|
class EavAttributeOptionValueCacheWarmer implements CacheWarmerInterface |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The repository with the cache that has to be warmed. |
|
40
|
|
|
* |
|
41
|
|
|
* @var \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $repository; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Initialize the cache warmer with the repository that has to be warmed. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface $repository The repository to warm |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct(EavAttributeOptionValueRepositoryInterface $repository) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->repository = $repository; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Warms the cache for the passed repository. |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function warm() |
|
61
|
|
|
{ |
|
62
|
|
|
|
|
63
|
|
|
// load the repositories utility class name |
|
64
|
|
|
$utilityClassName = $this->repository->getUtilityClassName(); |
|
65
|
|
|
|
|
66
|
|
|
// prepare the caches for the statements |
|
67
|
|
|
foreach ($this->repository->findAll() as $eavAttributeOptionValue) { |
|
68
|
|
|
// prepare the cache key and add the option value to the cache |
|
69
|
|
|
$cacheKey1 = $this->repository->cacheKey( |
|
70
|
|
|
$utilityClassName::EAV_ATTRIBUTE_OPTION_VALUE_BY_OPTION_ID_AND_STORE_ID, |
|
71
|
|
|
array( |
|
72
|
|
|
MemberNames::STORE_ID => $eavAttributeOptionValue[MemberNames::STORE_ID], |
|
73
|
|
|
MemberNames::OPTION_ID => $eavAttributeOptionValue[MemberNames::OPTION_ID] |
|
74
|
|
|
) |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
// prepare the cache key and add the option value to the cache |
|
78
|
|
|
$cacheKey2 = $this->repository->cacheKey( |
|
79
|
|
|
$utilityClassName::EAV_ATTRIBUTE_OPTION_VALUE_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE, |
|
80
|
|
|
array( |
|
81
|
|
|
MemberNames::ATTRIBUTE_CODE => $eavAttributeOptionValue[MemberNames::ATTRIBUTE_CODE], |
|
82
|
|
|
MemberNames::STORE_ID => $eavAttributeOptionValue[MemberNames::STORE_ID], |
|
83
|
|
|
MemberNames::VALUE => $eavAttributeOptionValue[MemberNames::VALUE] |
|
84
|
|
|
) |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
// add the EAV attribute option value to the cache |
|
88
|
|
|
$this->repository->toCache( |
|
89
|
|
|
$eavAttributeOptionValue[MemberNames::VALUE_ID], |
|
90
|
|
|
$eavAttributeOptionValue, |
|
91
|
|
|
array( |
|
92
|
|
|
$cacheKey1 => $eavAttributeOptionValue[MemberNames::VALUE_ID], |
|
93
|
|
|
$cacheKey2 => $eavAttributeOptionValue[MemberNames::VALUE_ID] |
|
94
|
|
|
) |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|