Skip to content

Commit

Permalink
#94738 use serializer, catch thrown exception when image is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwaclawczyk committed Jul 9, 2024
1 parent 2bf3811 commit 9463f36
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
11 changes: 6 additions & 5 deletions Model/Menu/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,12 @@ public function setSelectedItemId($selectedItemId)
public function getCustomerGroups()
{
$customerGroups = $this->_getData(NodeInterface::CUSTOMER_GROUPS);
if ($customerGroups !== null) {
$customerGroups = explode(',', $customerGroups);
if (is_array($customerGroups) && !empty($customerGroups)) {
return $customerGroups;
}
if ($customerGroups == null) {
return [];
}
$customerGroups = explode(',', $customerGroups);
if (is_array($customerGroups) && !empty($customerGroups)) {
return $customerGroups;
}

return [];
Expand Down
6 changes: 1 addition & 5 deletions Model/Menu/Node/Image/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ public function getImageSize(string $file): array
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$fileFullPath = $mediaDirectory->getAbsolutePath(self::PATH . $file);

try {
return getimagesize($fileFullPath);
} catch (Exception $e) {
return [];
}
return getimagesize($fileFullPath);
}

private function getAbsolutePath(): string
Expand Down
18 changes: 16 additions & 2 deletions Model/ResourceModel/Menu/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@

namespace Snowdog\Menu\Model\ResourceModel\Menu;

use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Serialize\SerializerInterface;

class Node extends AbstractDb
{
protected $serializer;

public function __construct(
Context $context,
SerializerInterface $serializer,
$connectionName = null
) {
$this->serializer = $serializer;
parent::__construct($context, $connectionName);
}

protected function _construct()
{
$this->_init('snowmenu_node', 'node_id');
}

protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
protected function _afterSave(AbstractModel $object)
{
$connection = $this->getConnection();
$connection->delete('snowmenu_customer', ['node_id = ?' => $object->getNodeId()]);

$nodeCustomerGroups = $object->getData('customer_groups');
if ($nodeCustomerGroups && is_string($nodeCustomerGroups)) {
$nodeCustomerGroups = json_decode($nodeCustomerGroups);
$nodeCustomerGroups = $this->serializer->unserialize($nodeCustomerGroups);
}
$insertData = [];
foreach ($nodeCustomerGroups ?? [] as $customerGroup) {
Expand Down
6 changes: 5 additions & 1 deletion Service/Menu/SaveRequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ private function processImageParameters(array $nodeData, NodeInterface &$nodeObj
if (empty($nodeData[NodeInterface::IMAGE_WIDTH])
|| empty($nodeData[NodeInterface::IMAGE_HEIGHT])
) {
$imageSize = $this->nodeImageFile->getImageSize($nodeData[NodeInterface::IMAGE]);
try {
$imageSize = $this->nodeImageFile->getImageSize($nodeData[NodeInterface::IMAGE]);
} catch (\Exception $e) {
$imageSize = null;
}

if (!empty($imageSize)) {
$nodeObject
Expand Down

0 comments on commit 9463f36

Please sign in to comment.