Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ea4682

Browse files
authored
Fix db query running on composer install (#147)
1 parent 6ddb41f commit 8ea4682

1 file changed

Lines changed: 33 additions & 28 deletions

File tree

src/Extend/SitesLinkedToMagentoStores.php

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Collection;
66
use Illuminate\Support\Facades\Cache;
7+
use PDOException;
78
use Rapidez\Core\Facades\Rapidez;
89
use Statamic\Sites\Sites;
910

@@ -30,41 +31,45 @@ public function findByMageRunCode($code)
3031
protected function getSavedSites()
3132
{
3233
return Cache::rememberForever('statamic_sites', function () {
33-
$sites = [];
34-
$stores = Rapidez::getStores();
35-
$staticPaths = collect();
36-
$configModel = config('rapidez.models.config');
34+
try {
35+
$sites = [];
36+
$stores = Rapidez::getStores();
37+
$staticPaths = collect();
38+
$configModel = config('rapidez.models.config');
3739

38-
foreach ($stores as $store) {
39-
if (in_array($store['code'], config('rapidez.statamic.disabled_sites'))) {
40-
continue;
41-
}
40+
foreach ($stores as $store) {
41+
if (in_array($store['code'], config('rapidez.statamic.disabled_sites'))) {
42+
continue;
43+
}
4244

43-
Rapidez::setStore($store['store_id']);
45+
Rapidez::setStore($store['store_id']);
4446

45-
$locale = $configModel::getCachedByPath('general/locale/code');
46-
$lang = explode('_', $locale)[0] ?? '';
47-
$url = $configModel::getCachedByPath('web/secure/base_url');
47+
$locale = $configModel::getCachedByPath('general/locale/code');
48+
$lang = explode('_', $locale)[0] ?? '';
49+
$url = $configModel::getCachedByPath('web/secure/base_url');
4850

49-
$sites[$store['code']] = [
50-
'name' => $store['name'] ?? $store['code'],
51-
'locale' => $locale,
52-
'lang' => $lang,
53-
'url' => $url,
54-
'attributes' => [
55-
'magento_store_id' => $store['store_id'],
56-
'group' => $store['website_code'] ?? ''
57-
]
58-
];
51+
$sites[$store['code']] = [
52+
'name' => $store['name'] ?? $store['code'],
53+
'locale' => $locale,
54+
'lang' => $lang,
55+
'url' => $url,
56+
'attributes' => [
57+
'magento_store_id' => $store['store_id'],
58+
'group' => $store['website_code'] ?? ''
59+
]
60+
];
5961

60-
if (config('statamic.static_caching.strategy') === 'full') {
61-
$staticPaths->put($store['code'], public_path('static') . '/' . str($url)->replace('https://', '')->replaceLast('/', '')->value());
62+
if (config('statamic.static_caching.strategy') === 'full') {
63+
$staticPaths->put($store['code'], public_path('static') . '/' . str($url)->replace('https://', '')->replaceLast('/', '')->value());
64+
}
6265
}
63-
}
64-
65-
config(['statamic.static_caching.strategies.full.path' => $staticPaths->toArray()]);
6666

67-
return $sites ?: $this->getFallbackConfig();
67+
config(['statamic.static_caching.strategies.full.path' => $staticPaths->toArray()]);
68+
69+
return $sites ?: $this->getFallbackConfig();
70+
} catch (PDOException) {
71+
return $this->getFallbackConfig();
72+
}
6873
});
6974
}
7075
}

0 commit comments

Comments
 (0)