Skip to content

Commit

Permalink
Merge branch 'next-7716/clear-cache-plugin-update' into 'master'
Browse files Browse the repository at this point in the history
NEXT-7716 - Fix DI container error after plugin upload

See merge request shopware/6/product/platform!1960
  • Loading branch information
OliverSkroblin committed Apr 2, 2020
2 parents f14dbc3 + b6a41c9 commit ef05a6a
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 80 deletions.
18 changes: 5 additions & 13 deletions CHANGELOG-6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* Added `sw-multi-tag-select` component which can now be used to allow users to enter data into a tagged input field
* Added `sw-multi-tag-ip-select` as an extension which includes IP-validation
* The `sw-multi-ip-select`-component is now deprecated and will be removed with version 6.4

* Replaced Store based datahandling with repository based datahandling in media specific components and modules, including the following changes
* sw-tag-field
* Added injection of `repositoryFactory`
Expand Down Expand Up @@ -248,12 +247,9 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* Added an error notification for user when he deletes a customer group that has a SalesChannel and/or a customer assigned to it.
* Added `bulk-modal-cancel`, `bulk-modal-delete-items`, `delete-modal-cancel` and `delete-modal-delete-item` slots to `sw-entity-listing.html.twig`
* Added twig blocks `sw_cms_page_form_section_empty_state_block_text` and `sw_cms_page_form_section_empty_state_block` to `sw-cms-page-form.html.twig`

* Removed `v-fixed` directive in `sw-entity-single-select` of `sw-order-product-select`
* The `fixed` directive is now deprecated and will be removed with version 6.4
* Added `sw-order-promotion-tag-input` component to handle showing promotion code list, entering and removing promotion code
* Added `sw-order-create-invalid-promotion-modal` component to show recent invalid promotion codes after clicking on Save Order button

* The `fixed` directive is now deprecated and will be removed with version 6.4
* Ordered settings items on settings list index page alphabetically
* Show error when theme compiling in theme manager throws an error
Expand All @@ -263,7 +259,6 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* Add `Hide products after clearance` option in `Setting -> Shop -> Listing`
* Add `Listing` tab in the `Storefront presentation` modal to configure the variant preselection
* Updated Node Dependencies

* Added new `sw-settings-captcha-select` component
* This component allows users to define active captchas via `Settings -> Basic information`
* Fix renaming of duplicated media names
Expand Down Expand Up @@ -324,7 +319,6 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* `sw-entity-multi-id-select`
* `sw-text-editor`
* `sw-media-field`

* Added `trackingUrl` property to the `Shopware\Core\Checkout\Shipping\ShippingMethodEntity.php`
* Added `\Shopware\Core\Framework\Adapter\Twig\NamespaceHierarchy\NamespaceHierarchyBuilder` and `\Shopware\Core\Framework\Adapter\Twig\NamespaceHierarchy\TemplateNamespaceHierarchyBuilderInterface`, that allows to modify twig namespace inheritance
* Deprecated `\Shopware\Core\Framework\Adapter\Twig\TemplateFinderInterface::registerBundles` use `TemplateNamespaceHierarchyBuilderInterface` to modify twig namespace hierarchy.
Expand Down Expand Up @@ -387,8 +381,6 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* When the new field and the old field is send, the converter will prefer the new field
* Added new header `sw-ignore-deprecations` to ignore deprecations and receive all fields
* This header is used now in all api calls in the administration


* Deprecated `\Shopware\Core\Framework\DataAbstractionLayer\Indexing\IndexerRegistry` use `\Shopware\Core\Framework\DataAbstractionLayer\Indexing\IndexerRegistry` instead
* Added `\Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemCollection::getPayloadsProperty` function which allows to extract a property value of all line item payloads.
* Added `\Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemCollection::filterByType` function which allows to filter the line item collection by the provided line item type
Expand All @@ -414,12 +406,11 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* Deprecated `\Shopware\Elasticsearch\Framework\Indexing\EntityIndexer`, use `\Shopware\Elasticsearch\Framework\Indexing\ElasticsearchIndexer` instead
* Deprecated `\Shopware\Core\Framework\DataAbstractionLayer\Indexing\IndexerInterface`, use `\Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexer` instead
* Fixed a bug when the criteria contains a list of ids and no sortings, queries or a term, the search result will be sorted by the provided ids
* Added new route `/api/v{version}/_action/container_cache` which clears the Symfony Container cache

* Storefront
Deprecated `$connection->executeQuery()` for write operations
* Added `\Shopware\Core\Framework\Api\Controller\CaptchaController` which provides a list of all available captchas to the administration

* Storefront
* Deprecated `$connection->executeQuery()` for write operations
* The `theme.json` now supports a new option for the `style` files. The placeholder `@StorefrontBootstrap` gives you the ability to use the Bootstrap SCSS without the Shopware Storefront "skin":
```json
{
Expand Down Expand Up @@ -458,6 +449,7 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* Non ES5 modules are now compiled with babel to support IE11
* Terser Minifier works now in ES5 for better IE11 support
* Add babel polyfill for IE11
* Added `rel="noopener"` to all `target="_blank"` links

**Removals**

Expand Down Expand Up @@ -551,10 +543,10 @@ To get the diff between two versions, go to https://github.com/shopware/platform
* Add `rel="noopener"` to all `target="_blank"` links
* Fix wrong behavior of switch fields, checkboxes and radio fields when clicking on the label
* Moved bearerAuth location from localStorage to Cookies
* Removed `v-fixed` directive in `sw-entity-single-select` of `sw-order-product-select`

* Core
*

* Storefront
* Removed duplicated `StorefrontPluginRegistryInterface` param from `\Shopware\Storefront\Theme\ThemeService`s constructor.
* Add `rel="noopener"` to all `target="_blank"` links
* Removed duplicated `StorefrontPluginRegistryInterface` param from `\Shopware\Storefront\Theme\ThemeService`s constructor
4 changes: 2 additions & 2 deletions UPGRADE-6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ Core
* Define permissions for AdminOrders at class `SalesChannelProxyController` within the array constant `ADMIN_ORDER_PERMISSIONS`.
* Define permissions for the Recalculation at class `OrderConverter` within the array constant `ADMIN_EDIT_ORDER_PERMISSIONS`.
* Extended permissions with subscribe event `SalesChannelContextPermissionsChangedEvent`, see detail at class `SalesChannelContextFactory`

* The usage of `$connection->executeQuery()` for write operations is deprecated, use
`$connection->executeUpdate()` instead.
* For the possibility to add individual product to across selling, you need to use a new field for creating a cross selling
* Please use type `productList` or `productStream` in order to create a corresponding cross selling
* The `\Shopware\Core\Framework\DataAbstractionLayer\EntityExtensionInterface` will be removed, extend from the abstract class `\Shopware\Core\Framework\DataAbstractionLayer\EntityExtension` instead.
* Deprecated `\Shopware\Core\Framework\Routing\RouteScopeInterface` use abstract class `\Shopware\Core\Framework\Routing\AbstractRouteScope` instead
* Deprecated `\Shopware\Core\Content\ContactForm\ContactFormService` use the new service `\Shopware\Core\Content\ContactForm\SalesChannel\ContactFormRoute` instead

* Deprecated `\Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingGateway` use `\Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingRouteInterface` instead
* Deprecated `\Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingGatewayInterface` use `\Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingRouteInterface` instead
* Deprecated `\Shopware\Core\Content\Product\SalesChannel\Search\ProductSearchGateway` use `\Shopware\Core\Content\Product\SalesChannel\Search\ProductSearchRouteInterface` instead
Expand All @@ -85,6 +83,8 @@ Core
* `\Shopware\Core\Checkout\Customer\SalesChannel\RegisterRouteInterface`
* `\Shopware\Core\Checkout\Customer\SalesChannel\RegisterConfirmRouteInterface`
* Deprecated `\Shopware\Core\Checkout\Promotion\Cart\Discount\DiscountPackagerInterface` use `\Shopware\Core\Checkout\Promotion\Cart\Discount\DiscountPackager` instead
* Added optional second parameter `$context` to `\Shopware\Core\Framework\Plugin\PluginManagementService::uploadPlugin` and `\Shopware\Core\Framework\Plugin\PluginManagementService::deletePlugin`. It will be required in 6.3.0
* Deprecated `\Shopware\Core\Framework\Plugin\PluginManagementService::extractPluginZip` which will be private in 6.3.0

Administration
--------------
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<file name="platform/src/Core/Framework/Test/FeatureFlag/FeatureTest.php"/>
</errorLevel>
</MissingFile>
<UndefinedClass>
<errorLevel type="info">
<referencedClass name="SwagTest\SwagTest"/>
</errorLevel>
</UndefinedClass>

<LessSpecificReturnType errorLevel="info"/>

Expand Down
4 changes: 3 additions & 1 deletion src/Administration/Resources/app/administration/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module.exports = {

globals: {
Shopware: true,
VueJS: true
VueJS: true,
Cypress: true,
cy: true,
},

plugins: ['jest'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Administration: Check module navigation in settings', () => {
cy.get('.sw-tabs-item[title="System"]').click();
cy.get('a[href="#/sw/plugin/index"]').click();
cy.wait('@refresh').then((xhr) => {
expect(xhr).to.have.property('status', 200);
expect(xhr).to.have.property('status', 204);
});
cy.wait('@getData').then((xhr) => {
expect(xhr).to.have.property('status', 200);
Expand Down
23 changes: 17 additions & 6 deletions src/Core/Framework/Adapter/Cache/CacheClearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public function clear(): void
$this->cleanupOldCacheDirectories();
}

public function clearContainerCache(): void
{
$finder = (new Finder())->in($this->cacheDir)->directories()->name('Container*');
$containerCaches = [];

foreach ($finder->getIterator() as $containerPaths) {
$containerCaches[] = $containerPaths->getRealPath();
}

$this->filesystem->remove($containerCaches);
}

public function deleteItems(array $keys): void
{
foreach ($this->adapters as $adapter) {
Expand All @@ -115,24 +127,23 @@ public function prune(): void

private function cleanupOldCacheDirectories(): void
{
$finder = new Finder();

$finder->directories()
$finder = (new Finder())
->directories()
->name($this->environment . '*')
->in(dirname($this->cacheDir) . '/');
->in(\dirname($this->cacheDir) . '/');

if (!$finder->hasResults()) {
return;
}

$remove = [];
foreach ($finder as $directory) {
foreach ($finder->getIterator() as $directory) {
if ($directory->getPathname() !== $this->cacheDir) {
$remove[] = $directory->getPathname();
}
}

if (!empty($remove)) {
if ($remove !== []) {
$this->filesystem->remove($remove);
}
}
Expand Down
44 changes: 30 additions & 14 deletions src/Core/Framework/Api/Controller/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Adapter\TraceableAdapter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
Expand All @@ -23,7 +24,7 @@ class CacheController extends AbstractController
/**
* @var CacheClearer
*/
private $cache;
private $cacheClearer;

/**
* @var AdapterInterface
Expand All @@ -36,7 +37,7 @@ class CacheController extends AbstractController
private $indexerMessageSender;

/**
* @var CacheWarmer
* @var CacheWarmer|null
*/
private $cacheWarmer;

Expand All @@ -46,13 +47,13 @@ class CacheController extends AbstractController
private $indexerRegistry;

public function __construct(
CacheClearer $cache,
CacheClearer $cacheClearer,
AdapterInterface $adapter,
IndexerMessageSender $indexerMessageSender,
CacheWarmer $cacheWarmer,
?CacheWarmer $cacheWarmer,
EntityIndexerRegistry $indexerRegistry
) {
$this->cache = $cache;
$this->cacheClearer = $cacheClearer;
$this->adapter = $adapter;
$this->indexerMessageSender = $indexerMessageSender;
$this->cacheWarmer = $cacheWarmer;
Expand All @@ -74,41 +75,56 @@ public function info(): JsonResponse
/**
* @Route("/api/v{version}/_action/index", name="api.action.cache.index", methods={"POST"})
*/
public function index(): JsonResponse
public function index(): Response
{
$this->indexerMessageSender->partial(new \DateTime());

$this->indexerRegistry->sendIndexingMessage();

return new JsonResponse();
return new Response('', Response::HTTP_NO_CONTENT);
}

/**
* @Route("/api/v{version}/_action/cache_warmup", name="api.action.cache.delete_and_warmup", methods={"DELETE"})
*/
public function clearCacheAndScheduleWarmUp(): JsonResponse
public function clearCacheAndScheduleWarmUp(): Response
{
if ($this->cacheWarmer === null) {
throw new \RuntimeException('Storefront is not installed');
}

$this->cacheWarmer->warmUp(Random::getAlphanumericString(32));

return new JsonResponse();
return new Response('', Response::HTTP_NO_CONTENT);
}

/**
* @Route("/api/v{version}/_action/cache", name="api.action.cache.delete", methods={"DELETE"})
*/
public function clearCache(): JsonResponse
public function clearCache(): Response
{
$this->cacheClearer->clear();

return new Response('', Response::HTTP_NO_CONTENT);
}

/**
* @Route("/api/v{version}/_action/container_cache", name="api.action.container-cache.delete", methods={"DELETE"})
*/
public function clearContainerCache(): Response
{
$this->cache->clear();
$this->cacheClearer->clearContainerCache();

return new JsonResponse();
return new Response('', Response::HTTP_NO_CONTENT);
}

private function getUsedCache(AdapterInterface $adapter): string
{
if ($adapter instanceof TagAwareAdapter || $adapter instanceof TraceableAdapter) {
// Do not declare function as static
$func = \Closure::bind(function () use ($adapter) {
return $adapter->pool;
}, $adapter, get_class($adapter));
}, $adapter, \get_class($adapter));

$adapter = $func();
}
Expand All @@ -117,7 +133,7 @@ private function getUsedCache(AdapterInterface $adapter): string
return $this->getUsedCache($adapter);
}

$name = get_class($adapter);
$name = \get_class($adapter);
$parts = explode('\\', $name);
$name = str_replace('Adapter', '', end($parts));

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Framework/DependencyInjection/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
<argument type="service" id="Shopware\Core\Framework\Adapter\Cache\CacheClearer"/>
<argument type="service" id="cache.object"/>
<argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Indexing\MessageQueue\IndexerMessageSender"/>
<argument type="service" id="Shopware\Storefront\Framework\Cache\CacheWarmer\CacheWarmer"/>
<argument type="service" id="Shopware\Storefront\Framework\Cache\CacheWarmer\CacheWarmer" on-invalid="null"/>
<argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry"/>
<call method="setContainer">
<argument type="service" id="service_container"/>
Expand Down
1 change: 1 addition & 0 deletions src/Core/Framework/DependencyInjection/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<argument type="service" id="Shopware\Core\Framework\Plugin\PluginExtractor"/>
<argument type="service" id="Shopware\Core\Framework\Plugin\PluginService"/>
<argument type="service" id="Symfony\Component\Filesystem\Filesystem"/>
<argument type="service" id="Shopware\Core\Framework\Adapter\Cache\CacheClearer"/>
</service>

<service id="Shopware\Core\Framework\Plugin\PluginExtractor">
Expand Down
11 changes: 4 additions & 7 deletions src/Core/Framework/Plugin/Api/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ public function uploadPlugin(Request $request, Context $context): Response
}

try {
$this->pluginManagementService->uploadPlugin($file);
$this->pluginManagementService->uploadPlugin($file, $context);
} catch (\Exception $e) {
unlink($file->getPathname());

throw $e;
}
$this->pluginService->refreshPlugins($context, new NullIO());

return new Response(null, Response::HTTP_NO_CONTENT);
return new Response('', Response::HTTP_NO_CONTENT);
}

/**
Expand All @@ -107,9 +106,7 @@ public function deletePlugin(QueryDataBag $queryParams, int $version, Context $c
throw new CanNotDeletePluginManagedByComposerException('can not delete plugins managed by composer');
}

$this->pluginManagementService->deletePlugin($plugin);

$this->pluginService->refreshPlugins($context, new NullIO());
$this->pluginManagementService->deletePlugin($plugin, $context);

return new JsonResponse($this->apiVersionConverter->convertEntity(
$this->pluginDefinition,
Expand All @@ -125,7 +122,7 @@ public function refreshPlugin(Request $request, Context $context): Response
{
$this->pluginService->refreshPlugins($context, new NullIO());

return new Response();
return new Response('', Response::HTTP_NO_CONTENT);
}

/**
Expand Down
Loading

0 comments on commit ef05a6a

Please sign in to comment.