Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: avoid error during warmup e.g. new properties on channel #77

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/CacheWarmer/SettingsCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace MonsieurBiz\SyliusSettingsPlugin\CacheWarmer;

use Doctrine\ORM\EntityManagerInterface;
use Exception;
use MonsieurBiz\SyliusSettingsPlugin\Settings\RegistryInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
Expand Down Expand Up @@ -46,26 +47,31 @@ public function warmUp(string $cacheDir): array
return [];
}

$settings = $this->registry->getAllSettings();
foreach ($settings as $setting) {
$setting->getSettingsByChannelAndLocale();
$setting->getSettingsByChannelAndLocale(null, null, true);
try {
$settings = $this->registry->getAllSettings();
foreach ($settings as $setting) {
$setting->getSettingsByChannelAndLocale();
$setting->getSettingsByChannelAndLocale(null, null, true);

/** @var ChannelInterface $channel */
foreach ($this->channelRepository->findAll() as $channel) {
if (null === $channel->getCode()) {
continue;
}
/** @var ChannelInterface $channel */
foreach ($this->channelRepository->findAll() as $channel) {
if (null === $channel->getCode()) {
continue;
}

$setting->getSettingsByChannelAndLocale($channel);
$setting->getSettingsByChannelAndLocale($channel, null, true);
$setting->getSettingsByChannelAndLocale($channel);
$setting->getSettingsByChannelAndLocale($channel, null, true);

/** @var LocaleInterface $locale */
foreach ($channel->getLocales() as $locale) {
$setting->getSettingsByChannelAndLocale($channel, $locale->getCode());
$setting->getSettingsByChannelAndLocale($channel, $locale->getCode(), true);
/** @var LocaleInterface $locale */
foreach ($channel->getLocales() as $locale) {
$setting->getSettingsByChannelAndLocale($channel, $locale->getCode());
$setting->getSettingsByChannelAndLocale($channel, $locale->getCode(), true);
}
}
}
} catch (Exception) {
// If an exception is thrown, we just ignore it and return an empty array
// e.g. if upgrade Sylius and a new channel property is added to the ChannelInterface
}

return [];
Expand Down
Loading