Skip to content

Commit 15c2dd2

Browse files
committed
MAGETWO-70318: [Github #10041] Generate static content command still requires DB connection
1 parent 7c25d3f commit 15c2dd2

File tree

6 files changed

+122
-20
lines changed

6 files changed

+122
-20
lines changed

app/code/Magento/Translation/App/Config/Type/Translation.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
/**
1313
* Class which hold all translation sources and merge them
14-
* @deprecated translation config type was removed
1514
*/
1615
class Translation implements ConfigTypeInterface
1716
{

app/code/Magento/Translation/Model/ResourceModel/Translate.php

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
*/
66
namespace Magento\Translation\Model\ResourceModel;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\App\Config;
11+
use Magento\Translation\App\Config\Type\Translation;
12+
813
class Translate extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb implements
914
\Magento\Framework\Translate\ResourceInterface
1015
{
@@ -18,6 +23,16 @@ class Translate extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb imp
1823
*/
1924
protected $scope;
2025

26+
/**
27+
* @var Config
28+
*/
29+
private $appConfig;
30+
31+
/**
32+
* @var DeploymentConfig
33+
*/
34+
private $deployedConfig;
35+
2136
/**
2237
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
2338
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
@@ -57,21 +72,25 @@ public function getTranslationArray($storeId = null, $locale = null)
5772
if ($storeId === null) {
5873
$storeId = $this->getStoreId();
5974
}
75+
$locale = (string) $locale;
6076

77+
$data = $this->getAppConfig()->get(
78+
Translation::CONFIG_TYPE,
79+
$locale . '/' . $this->getStoreCode($storeId),
80+
[]
81+
);
6182
$connection = $this->getConnection();
62-
if (!$connection) {
63-
return [];
83+
if ($connection) {
84+
$select = $connection->select()
85+
->from($this->getMainTable(), ['string', 'translate'])
86+
->where('store_id IN (0 , :store_id)')
87+
->where('locale = :locale')
88+
->order('store_id');
89+
$bind = [':locale' => $locale, ':store_id' => $storeId];
90+
$dbData = $connection->fetchPairs($select, $bind);
91+
$data = array_replace($data, $dbData);
6492
}
65-
66-
$select = $connection->select()
67-
->from($this->getMainTable(), ['string', 'translate'])
68-
->where('store_id IN (0 , :store_id)')
69-
->where('locale = :locale')
70-
->order('store_id');
71-
72-
$bind = [':locale' => (string)$locale, ':store_id' => $storeId];
73-
74-
return $connection->fetchPairs($select, $bind);
93+
return $data;
7594
}
7695

7796
/**
@@ -115,6 +134,19 @@ public function getMainChecksum()
115134
return $this->getChecksum($this->getMainTable());
116135
}
117136

137+
/**
138+
* Get connection
139+
*
140+
* @return \Magento\Framework\DB\Adapter\AdapterInterface|false
141+
*/
142+
public function getConnection()
143+
{
144+
if (!$this->getDeployedConfig()->isDbAvailable()) {
145+
return false;
146+
}
147+
return parent::getConnection();
148+
}
149+
118150
/**
119151
* Retrieve current store identifier
120152
*
@@ -124,4 +156,39 @@ protected function getStoreId()
124156
{
125157
return $this->scopeResolver->getScope($this->scope)->getId();
126158
}
159+
160+
/**
161+
* Retrieve store code by store id
162+
*
163+
* @param int $storeId
164+
* @return string
165+
*/
166+
private function getStoreCode($storeId)
167+
{
168+
return $this->scopeResolver->getScope($storeId)->getCode();
169+
}
170+
171+
/**
172+
* @deprecated
173+
* @return DeploymentConfig
174+
*/
175+
private function getDeployedConfig()
176+
{
177+
if ($this->deployedConfig === null) {
178+
$this->deployedConfig = ObjectManager::getInstance()->get(DeploymentConfig::class);
179+
}
180+
return $this->deployedConfig;
181+
}
182+
183+
/**
184+
* @deprecated
185+
* @return Config
186+
*/
187+
private function getAppConfig()
188+
{
189+
if ($this->appConfig === null) {
190+
$this->appConfig = ObjectManager::getInstance()->get(Config::class);
191+
}
192+
return $this->appConfig;
193+
}
127194
}

app/code/Magento/Translation/Model/Source/InitialTranslationSource.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
/**
1616
* Class for reading translations from DB
17-
*
18-
* @deprecated translation config source was removed. This class is not used anymore
19-
* @see app/code/Magento/Translation/Model/ResourceModel/Translate.php
2017
*/
2118
class InitialTranslationSource implements ConfigSourceInterface
2219
{

app/code/Magento/Translation/Test/Unit/App/Config/Type/TranslationTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
/**
1616
* @covers \Magento\Translation\App\Config\Type\Translation
17-
*
18-
* @deprecated translation config source was removed.
1917
*/
2018
class TranslationTest extends \PHPUnit_Framework_TestCase
2119
{

app/code/Magento/Translation/Test/Unit/Model/Source/InitialTranslationSourceTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
* @covers \Magento\Translation\Model\Source\InitialTranslationSource
1919
* @package Magento\Translation\Test\Unit\Model\Source
2020
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21-
*
22-
* @deprecated translation config source was removed.
2321
*/
2422
class InitialTranslationSourceTest extends \PHPUnit_Framework_TestCase
2523
{

app/code/Magento/Translation/etc/di.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,47 @@
9393
</argument>
9494
</arguments>
9595
</type>
96+
<virtualType name="translationConfigInitialDataProvider" type="Magento\Framework\App\Config\InitialConfigSource">
97+
<arguments>
98+
<argument name="reader" xsi:type="object">Magento\Framework\App\DeploymentConfig\Reader</argument>
99+
<argument name="configType" xsi:type="const">Magento\Translation\App\Config\Type\Translation::CONFIG_TYPE</argument>
100+
<argument name="fileKey" xsi:type="const">Magento\Framework\Config\File\ConfigFilePool::APP_CONFIG</argument>
101+
</arguments>
102+
</virtualType>
103+
<virtualType name="translationConfigSourceAggregated" type="Magento\Framework\App\Config\ConfigSourceAggregated">
104+
<arguments>
105+
<argument name="sources" xsi:type="array">
106+
<item name="dynamic" xsi:type="array">
107+
<item name="source" xsi:type="object">Magento\Translation\Model\Source\InitialTranslationSource\Proxy</item>
108+
<item name="sortOrder" xsi:type="string">100</item>
109+
</item>
110+
<item name="initial" xsi:type="array">
111+
<item name="source" xsi:type="object">translationConfigInitialDataProvider</item>
112+
<item name="sortOrder" xsi:type="string">1000</item>
113+
</item>
114+
</argument>
115+
</arguments>
116+
</virtualType>
117+
<type name="Magento\Translation\App\Config\Type\Translation">
118+
<arguments>
119+
<argument name="source" xsi:type="object">translationConfigSourceAggregated</argument>
120+
</arguments>
121+
</type>
122+
<type name="Magento\Framework\App\Config">
123+
<arguments>
124+
<argument name="types" xsi:type="array">
125+
<item name="i18n" xsi:type="object">Magento\Translation\App\Config\Type\Translation</item>
126+
</argument>
127+
</arguments>
128+
</type>
129+
<type name="Magento\Deploy\Console\Command\App\ApplicationDumpCommand">
130+
<arguments>
131+
<argument name="sources" xsi:type="array">
132+
<item name="i18n" xsi:type="array">
133+
<item name="source" xsi:type="object">Magento\Translation\Model\Source\InitialTranslationSource</item>
134+
<item name="namespace" xsi:type="const">Magento\Translation\App\Config\Type\Translation::CONFIG_TYPE</item>
135+
</item>
136+
</argument>
137+
</arguments>
138+
</type>
96139
</config>

0 commit comments

Comments
 (0)