Skip to content

Commit 0c846b5

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1597 from magento-engcom/develop-prs
Public Pull Requests #11537 ProductRepository sku cache is corrupted when cacheLimit is reached by @heldchen #11024 Download link does not get rendered in invoice email by @skymeissner #10500 Improvements to the phpserver router by @aredridel
2 parents ad44399 + 2a77940 commit 0c846b5

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private function cacheProduct($cacheKey, \Magento\Catalog\Api\Data\ProductInterf
312312
if ($this->cacheLimit && count($this->instances) > $this->cacheLimit) {
313313
$offset = round($this->cacheLimit / -2);
314314
$this->instancesById = array_slice($this->instancesById, $offset, null, true);
315-
$this->instances = array_slice($this->instances, $offset);
315+
$this->instances = array_slice($this->instances, $offset, null, true);
316316
}
317317
}
318318

app/code/Magento/Downloadable/Block/Sales/Order/Email/Items/Downloadable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public function __construct(
7070
public function getLinks()
7171
{
7272
$this->_purchased = $this->_purchasedFactory->create()->load(
73-
$this->getItem()->getId(),
73+
$this->getItem()->getOrderItemId(),
7474
'order_item_id'
7575
);
7676
$purchasedLinks = $this->_itemsFactory->create()->addFieldToFilter(
7777
'order_item_id',
78-
$this->getItem()->getId()
78+
$this->getItem()->getOrderItemId()
7979
);
8080
$this->_purchased->setPurchasedItems($purchasedLinks);
8181

app/code/Magento/Downloadable/Test/Unit/Block/Sales/Order/Email/Items/DownloadableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testGetLinks()
5959
{
6060
$item = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
6161
->disableOriginalConstructor()
62-
->setMethods(['getId'])
62+
->setMethods(['getOrderItemId'])
6363
->getMock();
6464
$linkPurchased = $this->getMockBuilder(\Magento\Downloadable\Model\Link\Purchased::class)
6565
->disableOriginalConstructor()
@@ -73,12 +73,12 @@ public function testGetLinks()
7373

7474
$this->block->setData('item', $item);
7575
$this->purchasedFactory->expects($this->once())->method('create')->willReturn($linkPurchased);
76-
$linkPurchased->expects($this->once())->method('load')->with('itemId', 'order_item_id')->willReturnSelf();
77-
$item->expects($this->any())->method('getId')->willReturn('itemId');
76+
$linkPurchased->expects($this->once())->method('load')->with('orderItemId', 'order_item_id')->willReturnSelf();
77+
$item->expects($this->any())->method('getOrderItemId')->willReturn('orderItemId');
7878
$this->itemsFactory->expects($this->once())->method('create')->willReturn($itemCollection);
7979
$itemCollection->expects($this->once())
8080
->method('addFieldToFilter')
81-
->with('order_item_id', 'itemId')
81+
->with('order_item_id', 'orderItemId')
8282
->willReturnSelf();
8383

8484
$this->assertEquals($linkPurchased, $this->block->getLinks());

phpserver/router.php

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,74 +28,92 @@
2828
$val = json_encode($val);
2929
}
3030

31-
echo 'debug: ' . $val . PHP_EOL . '<br/>' . PHP_EOL;
31+
error_log('debug: '.$val);
3232
};
3333

3434
/**
35-
* Note: the code below is experimental and not intended to be used outside development environment.
36-
* The code is protected against running outside of PHP built-in web server.
35+
* Caution, this is very experimental stuff
36+
* no guarantee for working result
37+
* has tons of potential big security holes
3738
*/
3839

3940
if (php_sapi_name() === 'cli-server') {
40-
$debug($_SERVER["REQUEST_URI"]);
41+
$debug("URI: {$_SERVER["REQUEST_URI"]}");
4142
if (preg_match('/^\/(index|get|static)\.php(\/)?/', $_SERVER["REQUEST_URI"])) {
4243
return false; // serve the requested resource as-is.
4344
}
4445

4546
$path = pathinfo($_SERVER["SCRIPT_FILENAME"]);
4647
$url = pathinfo(substr($_SERVER["REQUEST_URI"], 1));
4748
$route = parse_url(substr($_SERVER["REQUEST_URI"], 1))["path"];
48-
49-
$debug($path);
50-
$debug($route);
49+
$pathinfo = pathinfo($route);
50+
$ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';
5151

5252
if ($path["basename"] == 'favicon.ico') {
5353
return false;
5454
}
5555

56-
$debug($route);
57-
$debug(strpos($route, 'errors/default/css/'));
56+
$debug("route: $route");
5857

5958
if (strpos($route, 'pub/errors/default/') === 0) {
6059
$route = preg_replace('#pub/errors/default/#', 'errors/default/', $route, 1);
6160
}
6261

63-
$debug($route);
64-
65-
if (strpos($route, 'static/version') === 0) {
66-
$redirectRoute = preg_replace("/version\d+\//", "", $route, 1);
67-
$redirectDebugInfo = "redirect static version string to: " . $redirectRoute;
68-
$debug($redirectDebugInfo);
69-
header('Location: /' . $redirectRoute);
70-
exit;
71-
}
62+
$magentoPackagePubDir = __DIR__."/../pub";
7263

7364
if (strpos($route, 'media/') === 0 ||
7465
strpos($route, 'opt/') === 0 ||
7566
strpos($route, 'static/') === 0 ||
7667
strpos($route, 'errors/default/css/') === 0 ||
7768
strpos($route, 'errors/default/images/') === 0
7869
) {
79-
$magentoPackagePubDir = __DIR__ . "/../pub";
70+
$origFile = $magentoPackagePubDir.'/'.$route;
71+
72+
if (strpos($route, 'static/version') === 0) {
73+
$route = preg_replace('#static/(version\d+/)?#', 'static/', $route, 1);
74+
}
75+
$file = $magentoPackagePubDir.'/'.$route;
8076

81-
$file = $magentoPackagePubDir . '/' . $route;
82-
$debug($file);
83-
if (file_exists($file)) {
77+
$debug("file: $file");
78+
79+
if (file_exists($origFile)) {
8480
$debug('file exists');
8581
return false;
82+
} else if (file_exists($file)) {
83+
$mimeTypes = [
84+
'css' => 'text/css',
85+
'js' => 'application/javascript',
86+
'jpg' => 'image/jpg',
87+
'png' => 'image/png',
88+
'gif' => 'image/gif',
89+
'svg' => 'image/svg+xml',
90+
'map' => 'application/json',
91+
'woff' => 'application/x-woff',
92+
'woff2' => 'application/font-woff2',
93+
'html' => 'text/html',
94+
];
95+
96+
$type = isset($mimeTypes[$ext]) && $mimeTypes[$ext];
97+
if ($type) {
98+
header("Content-Type: $type");
99+
}
100+
readfile($file);
101+
return;
86102
} else {
87103
$debug('file does not exist');
88104
if (strpos($route, 'static/') === 0) {
89-
$route = preg_replace('#static/#', '', $route, 1);
90105
$_GET['resource'] = $route;
91-
include $magentoPackagePubDir . '/static.php';
106+
$debug("static: $route");
107+
include($magentoPackagePubDir.'/static.php');
92108
exit;
93109
} elseif (strpos($route, 'media/') === 0) {
94-
include $magentoPackagePubDir . '/get.php';
110+
$debug("media: $route");
111+
include($magentoPackagePubDir.'/get.php');
95112
exit;
96113
}
97114
}
115+
} else {
116+
$debug("thunk to index in $route");
117+
include($magentoPackagePubDir.'/index.php');
98118
}
99-
100-
header('HTTP/1.0 404 Not Found');
101119
}

0 commit comments

Comments
 (0)