|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Repositories\CacheWarmer\ProductVarcharCacheWarmer |
|
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 2019 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-product |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Repositories\CacheWarmer; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Utils\CacheKeys; |
|
24
|
|
|
use TechDivision\Import\Product\Utils\ParamNames; |
|
25
|
|
|
use TechDivision\Import\Product\Utils\SqlStatementKeys; |
|
26
|
|
|
use TechDivision\Import\Product\Repositories\ProductVarcharRepositoryInterface; |
|
27
|
|
|
use TechDivision\Import\Repositories\CacheWarmer\CacheWarmerInterface; |
|
28
|
|
|
use TechDivision\Import\Product\Utils\MemberNames; |
|
29
|
|
|
use TechDivision\Import\Repositories\StoreRepositoryInterface; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Cache warmer implementation that pre-load the available products. |
|
33
|
|
|
* |
|
34
|
|
|
* @author Tim Wagner <[email protected]> |
|
35
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
36
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
37
|
|
|
* @link https://github.com/techdivision/import-product |
|
38
|
|
|
* @link http://www.techdivision.com |
|
39
|
|
|
*/ |
|
40
|
|
|
class ProductVarcharCacheWarmer implements CacheWarmerInterface |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The repository with the cache that has to be warmed. |
|
45
|
|
|
* |
|
46
|
|
|
* @var \TechDivision\Import\Product\Repositories\ProductVarcharRepositoryInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $repository; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The store repository. |
|
52
|
|
|
* |
|
53
|
|
|
* @var \TechDivision\Import\Repositories\StoreRepositoryInterface |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $storeRepository; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Initialize the cache warmer with the repository that has to be warmed. |
|
59
|
|
|
* |
|
60
|
|
|
* @param \TechDivision\Import\Product\Repositories\ProductVarcharRepositoryInterface $repository The repository to warm |
|
61
|
|
|
* @param \TechDivision\Import\Repositories\StoreRepositoryInterface $storeRepository The store repository |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct( |
|
64
|
|
|
ProductVarcharRepositoryInterface $repository, |
|
65
|
|
|
StoreRepositoryInterface $storeRepository |
|
66
|
|
|
) { |
|
67
|
|
|
$this->repository = $repository; |
|
68
|
|
|
$this->storeRepository = $storeRepository; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Warms the cache for the passed repository. |
|
73
|
|
|
* |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
|
|
public function warm() |
|
77
|
|
|
{ |
|
78
|
|
|
|
|
79
|
|
|
// load the cache adapter |
|
80
|
|
|
/** @var \TechDivision\Import\Cache\CacheAdapterInterface $cacheAdapter */ |
|
81
|
|
|
$cacheAdapter = $this->repository->getCacheAdapter(); |
|
82
|
|
|
|
|
83
|
|
|
// load the available stores |
|
84
|
|
|
$stores = $this->storeRepository->findAll(); |
|
85
|
|
|
|
|
86
|
|
|
// iterate over the stores to prepare the cache |
|
87
|
|
|
foreach ($stores as $store) { |
|
88
|
|
|
// load the product varchar values we want to cache |
|
89
|
|
|
$productVarchars = $this->repository->findAllByAttributeCodeAndEntityTypeIdAndStoreId( |
|
90
|
|
|
$attributeCode = MemberNames::URL_KEY, |
|
91
|
|
|
$entityTypeId = 4, |
|
92
|
|
|
$store[MemberNames::STORE_ID] |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
// prepare the caches for the statements |
|
96
|
|
|
foreach ($productVarchars as $productVarchar) { |
|
97
|
|
|
// (re-)sinitialize the array for the cache keys |
|
98
|
|
|
$cacheKeys = array(); |
|
99
|
|
|
|
|
100
|
|
|
// prepare the unique cache key for the product |
|
101
|
|
|
$uniqueKey = array(CacheKeys::PRODUCT_VARCHAR => $productVarchar[$this->repository->getPrimaryKeyName()]); |
|
102
|
|
|
|
|
103
|
|
|
// prepare the cache key and add the URL key value to the cache |
|
104
|
|
|
$cacheKeys[$cacheAdapter->cacheKey( |
|
105
|
|
|
array( |
|
106
|
|
|
SqlStatementKeys::PRODUCT_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_STORE_ID_AND_VALUE => |
|
107
|
|
|
array( |
|
108
|
|
|
ParamNames::ATTRIBUTE_CODE => $attributeCode, |
|
109
|
|
|
ParamNames::ENTITY_TYPE_ID => $entityTypeId, |
|
110
|
|
|
ParamNames::STORE_ID => $productVarchar[MemberNames::STORE_ID], |
|
111
|
|
|
ParamNames::VALUE => $productVarchar[MemberNames::VALUE] |
|
112
|
|
|
) |
|
113
|
|
|
) |
|
114
|
|
|
)] = $uniqueKey; |
|
115
|
|
|
|
|
116
|
|
|
// add the EAV attribute option value to the cache |
|
117
|
|
|
$cacheAdapter->toCache($uniqueKey, $productVarchar, $cacheKeys); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: