|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\AkeneoPimMiddlewareConnector\Business\Translator\Generator; |
|
9
|
|
|
|
|
10
|
|
|
use Orm\Zed\Locale\Persistence\SpyLocaleQuery; |
|
|
|
|
|
|
11
|
|
|
use Orm\Zed\Url\Persistence\SpyUrlQuery; |
|
|
|
|
|
|
12
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
|
|
|
|
|
|
13
|
|
|
use SprykerEco\Zed\AkeneoPimMiddlewareConnector\Dependency\Facade\AkeneoPimMiddlewareConnectorToUtilTextBridgeInterface; |
|
14
|
|
|
|
|
15
|
|
|
class UrlGeneratorStrategy implements UrlGeneratorStrategyInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var array<int> Keys are locale ids, values are locale names. |
|
19
|
|
|
*/ |
|
20
|
|
|
protected static $idLocaleBuffer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \SprykerEco\Zed\AkeneoPimMiddlewareConnector\Dependency\Facade\AkeneoPimMiddlewareConnectorToUtilTextBridgeInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $utilTextService; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param \SprykerEco\Zed\AkeneoPimMiddlewareConnector\Dependency\Facade\AkeneoPimMiddlewareConnectorToUtilTextBridgeInterface $textService |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(AkeneoPimMiddlewareConnectorToUtilTextBridgeInterface $textService) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->utilTextService = $textService; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $name |
|
37
|
|
|
* @param int $idLocale |
|
38
|
|
|
* @param string $identifier |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function generate(string $name, int $idLocale, string $identifier): string |
|
43
|
|
|
{ |
|
44
|
|
|
$abstractProductUrl = $this->utilTextService->generateSlug($name); |
|
45
|
|
|
$abstractProductUrl = '/' . substr($this->getLocaleNameById($idLocale), 0, 2) . '/' . $abstractProductUrl . '-' . md5($identifier); |
|
46
|
|
|
$this->cleanupRedirectUrls($abstractProductUrl); |
|
47
|
|
|
|
|
48
|
|
|
return $abstractProductUrl; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param int $localeId |
|
53
|
|
|
* |
|
54
|
|
|
* @return int |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function getLocaleNameById($localeId) |
|
57
|
|
|
{ |
|
58
|
|
|
if (!isset(static::$idLocaleBuffer[$localeId])) { |
|
59
|
|
|
static::$idLocaleBuffer[$localeId] = |
|
60
|
|
|
mb_strtolower(SpyLocaleQuery::create()->findOneByIdLocale($localeId)->getLocaleName()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return static::$idLocaleBuffer[$localeId]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $abstractProductUrl |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function cleanupRedirectUrls($abstractProductUrl) |
|
72
|
|
|
{ |
|
73
|
|
|
SpyUrlQuery::create() |
|
74
|
|
|
->filterByUrl($abstractProductUrl) |
|
75
|
|
|
->filterByFkResourceRedirect(null, Criteria::ISNOTNULL) |
|
76
|
|
|
->delete(); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths