Skip to content

Commit

Permalink
Merge pull request #423 from magento-cloud/MAGECLOUD-3195
Browse files Browse the repository at this point in the history
MAGECLOUD-3195: Fix patch "MAGETWO-57414__load_static_assets_without_…
  • Loading branch information
shiftedreality authored Feb 26, 2019
2 parents 5419380 + d0e56d4 commit 4b26fd2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"~2.1.4": "MAGETWO-57413__move_vendor_path_autoloader__2.1.4.patch"
},
"Allow static assets to be loaded without URL rewrites": {
"~2.1.4": "MAGETWO-57414__load_static_assets_without_rewrites__2.1.4.patch"
"2.1.4 - 2.1.16": "MAGETWO-57414__load_static_assets_without_rewrites__2.1.4.patch",
"~2.1.17": "MAGETWO-57414__load_static_assets_without_rewrites__2.1.17.patch"
},
"Don't attempt to use non-existent setup areas": {
"~2.1.4": "MAGETWO-45357__avoid_nonexistent_setup_area__2.1.4.patch"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Ticket MAGETWO-57414
diff -Naur a/vendor/magento/framework/App/StaticResource.php b/vendor/magento/framework/App/StaticResource.php
index d591deb..6344322 100644
--- a/vendor/magento/framework/App/StaticResource.php
+++ b/vendor/magento/framework/App/StaticResource.php
@@ -94,24 +94,40 @@ class StaticResource implements \Magento\Framework\AppInterface
{
// disabling profiling when retrieving static resource
\Magento\Framework\Profiler::reset();
- $appMode = $this->state->getMode();
- if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
+ $path = $this->getResourcePath();
+ if (!isset($path)) {
$this->response->setHttpResponseCode(404);
- } else {
- $path = $this->request->get('resource');
- $params = $this->parsePath($path);
- $this->state->setAreaCode($params['area']);
- $this->objectManager->configure($this->configLoader->load($params['area']));
- $file = $params['file'];
- unset($params['file']);
- $asset = $this->assetRepo->createAsset($file, $params);
- $this->response->setFilePath($asset->getSourceFile());
- $this->publisher->publish($asset);
+ return $this->response;
}
+
+ $params = $this->parsePath($path);
+ $this->state->setAreaCode($params['area']);
+ $this->objectManager->configure($this->configLoader->load($params['area']));
+ $file = $params['file'];
+ unset($params['file']);
+ $asset = $this->assetRepo->createAsset($file, $params);
+ $this->response->setFilePath($asset->getSourceFile());
+ $this->publisher->publish($asset);
return $this->response;
}

/**
+ * Retrieve the path from either the GET parameter or the request
+ * URI, depending on whether webserver rewrites are in use.
+ */
+ protected function getResourcePath() {
+ $path = $this->request->get('resource');
+ if (isset($path)) {
+ return $path;
+ }
+
+ $path = $this->request->getUri()->getPath();
+ if (preg_match("~^/static/(?:version\d*/)?(.*)$~", $path, $matches)) {
+ return $matches[1];
+ }
+ }
+
+ /**
* @inheritdoc
*/
public function catchException(Bootstrap $bootstrap, \Exception $exception)

0 comments on commit 4b26fd2

Please sign in to comment.