Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - magento#18662: [Backport] move hardcoded MIME types from class private to DI configuration (by @gelanivishal)
 - magento#18659: [Backport] Fix for magento#12969 - server port detection for errors (by @gelanivishal)
 - magento#18657: [Backport] Create empty modelData array to avoid undefined var error (by @gelanivishal)


Fixed GitHub Issues:
 - magento#12969: processor.php getHostUrl() does not detect the server port correctly (reported by @boldhedgehog) has been fixed in magento#18659 by @gelanivishal in 2.2-develop branch
   Related commits:
     1. ef426a7
     2. 774a8a2
     3. 763be49
  • Loading branch information
magento-engcom-team authored Oct 17, 2018
2 parents 82b50ac + 6674052 commit cbd8d8a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
16 changes: 7 additions & 9 deletions app/code/Magento/Catalog/Model/ImageUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ class ImageUploader
/**
* List of allowed image mime types
*
* @var array
* @var string[]
*/
private $allowedMimeTypes = [
'image/jpg',
'image/jpeg',
'image/gif',
'image/png'
];
private $allowedMimeTypes;

/**
* ImageUploader constructor
Expand All @@ -89,6 +84,7 @@ class ImageUploader
* @param string $baseTmpPath
* @param string $basePath
* @param string[] $allowedExtensions
* @param string[] $allowedMimeTypes
*/
public function __construct(
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
Expand All @@ -98,7 +94,8 @@ public function __construct(
\Psr\Log\LoggerInterface $logger,
$baseTmpPath,
$basePath,
$allowedExtensions
$allowedExtensions,
$allowedMimeTypes = []
) {
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
Expand All @@ -108,6 +105,7 @@ public function __construct(
$this->baseTmpPath = $baseTmpPath;
$this->basePath = $basePath;
$this->allowedExtensions = $allowedExtensions;
$this->allowedMimeTypes = $allowedMimeTypes;
}

/**
Expand Down Expand Up @@ -167,7 +165,7 @@ public function getBasePath()
}

/**
* Retrieve base path
* Retrieve allowed extensions
*
* @return string[]
*/
Expand Down
13 changes: 11 additions & 2 deletions app/code/Magento/Catalog/Test/Unit/Model/ImageUploaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ class ImageUploaderTest extends \PHPUnit\Framework\TestCase
/**
* Allowed extensions
*
* @var string
* @var array
*/
private $allowedExtensions;

/**
* Allowed mime types
*
* @var array
*/
private $allowedMimeTypes;

protected function setUp()
{
$this->coreFileStorageDatabaseMock = $this->createMock(
Expand All @@ -97,6 +104,7 @@ protected function setUp()
$this->baseTmpPath = 'base/tmp/';
$this->basePath = 'base/real/';
$this->allowedExtensions = ['.jpg'];
$this->allowedMimeTypes = ['image/jpg', 'image/jpeg', 'image/gif', 'image/png'];

$this->imageUploader =
new \Magento\Catalog\Model\ImageUploader(
Expand All @@ -107,7 +115,8 @@ protected function setUp()
$this->loggerMock,
$this->baseTmpPath,
$this->basePath,
$this->allowedExtensions
$this->allowedExtensions,
$this->allowedMimeTypes
);
}

Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@
<item name="gif" xsi:type="string">gif</item>
<item name="png" xsi:type="string">png</item>
</argument>
<argument name="allowedMimeTypes" xsi:type="array">
<item name="jpg" xsi:type="string">image/jpg</item>
<item name="jpeg" xsi:type="string">image/jpeg</item>
<item name="gif" xsi:type="string">image/gif</item>
<item name="png" xsi:type="string">image/png</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\Catalog\Controller\Adminhtml\Category\Image\Upload">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
namespace Magento\Developer\Console\Command;

use Magento\Framework\App\State;
use Magento\Framework\Validator\Locale;
use Magento\Framework\View\Asset\Repository;
use Symfony\Component\Console\Command\Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function report()
$moduleData = $this->collect->getModuleData();
if (count($moduleData['changes']) > 0) {
foreach ($moduleData['changes'] as $change) {
$modelData = [];
switch ($change['type']) {
case Config::ENABLED:
$modelData = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function addCustomParameter($param, $value)
/**
* Wrapper for 'newrelic_notice_error' function
*
* @param Exception $exception
* @param \Exception $exception
* @return void
*/
public function reportError($exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected function setUp()
[
'baseTmpPath' => $this->mediaDirectory->getRelativePath('tmp'),
'basePath' => __DIR__,
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png']
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png'],
'allowedMimeTypes' => ['image/jpg', 'image/jpeg', 'image/gif', 'image/png']
]
);
}
Expand Down
7 changes: 5 additions & 2 deletions pub/errors/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,11 @@ public function getHostUrl()
$isSecure = (!empty($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'] != 'off');
$url = ($isSecure ? 'https://' : 'http://') . $host;

if (!empty($_SERVER['SERVER_PORT']) && !in_array($_SERVER['SERVER_PORT'], [80, 443])
$port = explode(':', $host);
if (isset($port[1]) && !in_array($port[1], [80, 443])
&& !preg_match('/.*?\:[0-9]+$/', $url)
) {
$url .= ':' . $_SERVER['SERVER_PORT'];
$url .= ':' . $port[1];
}
return $url;
}
Expand Down Expand Up @@ -379,6 +380,8 @@ protected function _loadXml($xmlFile)
}

/**
* Render page
*
* @param string $template
* @return string
*/
Expand Down

0 comments on commit cbd8d8a

Please sign in to comment.