Skip to content

Commit

Permalink
Merge pull request #4231 from nobuhiko/fixUpdatePlugin
Browse files Browse the repository at this point in the history
ユーザー独自プラグインのアップデートしてもスキーマがアップデートされない
  • Loading branch information
Kiyotaka Oku committed Nov 26, 2019
2 parents d48efb0 + 98a1d9c commit 37ab7e2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
30 changes: 30 additions & 0 deletions app/config/eccube/packages/codeception/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# https://github.com/symfony/demo/blob/master/config/packages/prod/doctrine.yaml
# https://symfony.com/doc/master/bundles/DoctrineBundle/configuration.html
doctrine:
orm:
metadata_cache_driver:
type: service
id: doctrine.app_cache_provider
query_cache_driver:
type: service
id: doctrine.app_cache_provider
result_cache_driver:
type: service
id: doctrine.app_cache_provider
second_level_cache:
region_cache_driver:
type: service
id: doctrine.app_cache_provider

services:
doctrine.app_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.app_cache_pool'

framework:
cache:
pools:
doctrine.app_cache_pool:
adapter: cache.app
Binary file modified codeception/_data/plugins/Horizon-1.0.1.tgz
Binary file not shown.
14 changes: 14 additions & 0 deletions codeception/acceptance/EA10PluginCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,13 @@ public function __construct(AcceptanceTester $I)
$this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
}

public function アップデート()
{
// アップデートで新たしいカラムが追加される
$this->columns[] = 'dtb_dash.new_column';
return parent::アップデート();
}

public static function start(AcceptanceTester $I)
{
return new self($I);
Expand All @@ -810,6 +817,13 @@ public function __construct(AcceptanceTester $I)
$this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
}

public function アップデート()
{
// アップデートで新たしいカラムが追加される
$this->columns[] = 'dtb_dash.new_column';
return parent::アップデート();
}

public static function start(AcceptanceTester $I)
{
$result = new self($I);
Expand Down
10 changes: 6 additions & 4 deletions codeception/acceptance/EF01TopCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public function _after(\AcceptanceTester $I)

private function clearDoctrineCache()
{
// APP_ENV=prodで実行した際は, 直接データを投入しても反映されないため,
// APP_ENV=prod/codeceptionで実行した際は, 直接データを投入しても反映されないため,
// キャッシュを削除して表示できるようにする
$fs = new Symfony\Component\Filesystem\Filesystem();
$cacheDir = __DIR__.'/../../var/cache/prod/pools';
if ($fs->exists($cacheDir)) {
$fs->remove($cacheDir);
foreach (['prod', 'codeception'] as $env) {
$cacheDir = __DIR__."/../../var/cache/${env}/pools";
if ($fs->exists($cacheDir)) {
$fs->remove($cacheDir);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Eccube/Service/PluginService.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ public function postInstall($config, $source)
*/
public function generateProxyAndUpdateSchema(Plugin $plugin, $config, $uninstall = false, $saveMode = true)
{
// キャッシュしたメタデータを利用しないようにキャッシュドライバを外しておく
$this->entityManager->getMetadataFactory()->setCacheDriver(null);

$this->generateProxyAndCallback(function ($generatedFiles, $proxiesDirectory) use ($saveMode) {
$this->schemaService->updateSchema($generatedFiles, $proxiesDirectory, $saveMode);
}, $plugin, $config, $uninstall);
Expand Down Expand Up @@ -747,6 +750,8 @@ public function updatePlugin(Plugin $plugin, $meta)

$em->persist($plugin);

$this->generateProxyAndUpdateSchema($plugin, $meta);

if ($plugin->isInitialized()) {
$this->callPluginManagerMethod($meta, 'update');
}
Expand Down
17 changes: 13 additions & 4 deletions src/Eccube/Util/CacheUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
Expand All @@ -29,21 +30,30 @@
*/
class CacheUtil implements EventSubscriberInterface
{

const DOCTRINE_APP_CACHE_KEY = 'doctrine.app_cache_pool';

private $clearCacheAfterResponse = false;

/**
* @var KernelInterface
*/
protected $kernel;
/**
* @var ContainerInterface
*/
private $container;

/**
* CacheUtil constructor.
*
* @param KernelInterface $kernel
* @param ContainerInterface $container
*/
public function __construct(KernelInterface $kernel)
public function __construct(KernelInterface $kernel, ContainerInterface $container)
{
$this->kernel = $kernel;
$this->container = $container;
}

/**
Expand Down Expand Up @@ -100,7 +110,6 @@ public function forceClearCache(PostResponseEvent $event)

/**
* Doctrineのキャッシュを削除します.
* APP_ENV=prodの場合のみ実行されます.
*
* @param null $env
*
Expand All @@ -110,15 +119,15 @@ public function forceClearCache(PostResponseEvent $event)
*/
public function clearDoctrineCache()
{
if ($this->kernel->getEnvironment() !== 'prod') {
if (!$this->container->has(self::DOCTRINE_APP_CACHE_KEY)) {
return;
}
$console = new Application($this->kernel);
$console->setAutoExit(false);

$command = [
'command' => 'cache:pool:clear',
'pools' => ['doctrine.app_cache_pool'],
'pools' => [self::DOCTRINE_APP_CACHE_KEY],
'--no-ansi' => true,
];

Expand Down

0 comments on commit 37ab7e2

Please sign in to comment.