Skip to content

Commit

Permalink
Merge pull request #1597 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleksii Korshenko authored Oct 19, 2017
2 parents ad44399 + 2a77940 commit 0c846b5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private function cacheProduct($cacheKey, \Magento\Catalog\Api\Data\ProductInterf
if ($this->cacheLimit && count($this->instances) > $this->cacheLimit) {
$offset = round($this->cacheLimit / -2);
$this->instancesById = array_slice($this->instancesById, $offset, null, true);
$this->instances = array_slice($this->instances, $offset);
$this->instances = array_slice($this->instances, $offset, null, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public function __construct(
public function getLinks()
{
$this->_purchased = $this->_purchasedFactory->create()->load(
$this->getItem()->getId(),
$this->getItem()->getOrderItemId(),
'order_item_id'
);
$purchasedLinks = $this->_itemsFactory->create()->addFieldToFilter(
'order_item_id',
$this->getItem()->getId()
$this->getItem()->getOrderItemId()
);
$this->_purchased->setPurchasedItems($purchasedLinks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testGetLinks()
{
$item = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
->disableOriginalConstructor()
->setMethods(['getId'])
->setMethods(['getOrderItemId'])
->getMock();
$linkPurchased = $this->getMockBuilder(\Magento\Downloadable\Model\Link\Purchased::class)
->disableOriginalConstructor()
Expand All @@ -73,12 +73,12 @@ public function testGetLinks()

$this->block->setData('item', $item);
$this->purchasedFactory->expects($this->once())->method('create')->willReturn($linkPurchased);
$linkPurchased->expects($this->once())->method('load')->with('itemId', 'order_item_id')->willReturnSelf();
$item->expects($this->any())->method('getId')->willReturn('itemId');
$linkPurchased->expects($this->once())->method('load')->with('orderItemId', 'order_item_id')->willReturnSelf();
$item->expects($this->any())->method('getOrderItemId')->willReturn('orderItemId');
$this->itemsFactory->expects($this->once())->method('create')->willReturn($itemCollection);
$itemCollection->expects($this->once())
->method('addFieldToFilter')
->with('order_item_id', 'itemId')
->with('order_item_id', 'orderItemId')
->willReturnSelf();

$this->assertEquals($linkPurchased, $this->block->getLinks());
Expand Down
72 changes: 45 additions & 27 deletions phpserver/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,74 +28,92 @@
$val = json_encode($val);
}

echo 'debug: ' . $val . PHP_EOL . '<br/>' . PHP_EOL;
error_log('debug: '.$val);
};

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

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

$path = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$url = pathinfo(substr($_SERVER["REQUEST_URI"], 1));
$route = parse_url(substr($_SERVER["REQUEST_URI"], 1))["path"];

$debug($path);
$debug($route);
$pathinfo = pathinfo($route);
$ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';

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

$debug($route);
$debug(strpos($route, 'errors/default/css/'));
$debug("route: $route");

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

$debug($route);

if (strpos($route, 'static/version') === 0) {
$redirectRoute = preg_replace("/version\d+\//", "", $route, 1);
$redirectDebugInfo = "redirect static version string to: " . $redirectRoute;
$debug($redirectDebugInfo);
header('Location: /' . $redirectRoute);
exit;
}
$magentoPackagePubDir = __DIR__."/../pub";

if (strpos($route, 'media/') === 0 ||
strpos($route, 'opt/') === 0 ||
strpos($route, 'static/') === 0 ||
strpos($route, 'errors/default/css/') === 0 ||
strpos($route, 'errors/default/images/') === 0
) {
$magentoPackagePubDir = __DIR__ . "/../pub";
$origFile = $magentoPackagePubDir.'/'.$route;

if (strpos($route, 'static/version') === 0) {
$route = preg_replace('#static/(version\d+/)?#', 'static/', $route, 1);
}
$file = $magentoPackagePubDir.'/'.$route;

$file = $magentoPackagePubDir . '/' . $route;
$debug($file);
if (file_exists($file)) {
$debug("file: $file");

if (file_exists($origFile)) {
$debug('file exists');
return false;
} else if (file_exists($file)) {
$mimeTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'jpg' => 'image/jpg',
'png' => 'image/png',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
'map' => 'application/json',
'woff' => 'application/x-woff',
'woff2' => 'application/font-woff2',
'html' => 'text/html',
];

$type = isset($mimeTypes[$ext]) && $mimeTypes[$ext];
if ($type) {
header("Content-Type: $type");
}
readfile($file);
return;
} else {
$debug('file does not exist');
if (strpos($route, 'static/') === 0) {
$route = preg_replace('#static/#', '', $route, 1);
$_GET['resource'] = $route;
include $magentoPackagePubDir . '/static.php';
$debug("static: $route");
include($magentoPackagePubDir.'/static.php');
exit;
} elseif (strpos($route, 'media/') === 0) {
include $magentoPackagePubDir . '/get.php';
$debug("media: $route");
include($magentoPackagePubDir.'/get.php');
exit;
}
}
} else {
$debug("thunk to index in $route");
include($magentoPackagePubDir.'/index.php');
}

header('HTTP/1.0 404 Not Found');
}

0 comments on commit 0c846b5

Please sign in to comment.