-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
223 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Settings plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusSettingsPlugin\CacheWarmer; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use MonsieurBiz\SyliusSettingsPlugin\Settings\RegistryInterface; | ||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Locale\Model\LocaleInterface; | ||
|
||
final class SettingsCacheWarmer implements SettingsCacheWarmerInterface | ||
{ | ||
public function __construct( | ||
private ChannelRepositoryInterface $channelRepository, | ||
private RegistryInterface $registry, | ||
private EntityManagerInterface $entityManager, | ||
) { | ||
} | ||
|
||
public function isOptional(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameters) | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
*/ | ||
public function warmUp(string $cacheDir): array | ||
{ | ||
if ( | ||
false === $this->entityManager->getConnection()->isConnected() | ||
|| false === $this->entityManager->getConnection()->getSchemaManager()->tablesExist('mbiz_settings_setting') | ||
) { | ||
return []; | ||
} | ||
|
||
$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; | ||
} | ||
|
||
$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); | ||
} | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Settings plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusSettingsPlugin\CacheWarmer; | ||
|
||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; | ||
|
||
interface SettingsCacheWarmerInterface extends CacheWarmerInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.