-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix admin got auto logged out when displaying large number of product reviews #40227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
Changes from all commits
6e8aa57
5af53da
1840736
7d96d70
4ab76c2
ed08e62
73e7edc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Various methods has been removed from here, this could be backward incompatible change. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,147 +3,79 @@ | |
| * Copyright 2013 Adobe | ||
| * All Rights Reserved. | ||
| */ | ||
|
|
||
| namespace Magento\Review\Helper\Action; | ||
|
|
||
| use Magento\Framework\Exception\LocalizedException; | ||
| use Magento\Framework\App\Helper\AbstractHelper; | ||
| use Magento\Review\Model\ResourceModel\Review\CollectionFactory; | ||
|
|
||
| /** | ||
| * Action pager helper for iterating over search results | ||
| * | ||
| * @api | ||
| * @since 100.0.2 | ||
| */ | ||
| class Pager extends \Magento\Framework\App\Helper\AbstractHelper | ||
| class Pager extends AbstractHelper | ||
| { | ||
| const STORAGE_PREFIX = 'search_result_ids'; | ||
|
|
||
| /** | ||
| * Storage id | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $_storageId = null; | ||
|
|
||
| /** | ||
| * Array of items | ||
| * Review collection model factory | ||
| * | ||
| * @var array | ||
| * @var CollectionFactory | ||
| */ | ||
| protected $_items = null; | ||
| protected $reviewCollectionFactory; | ||
|
|
||
| /** | ||
| * Backend session model | ||
| * Pager constructor. | ||
| * | ||
| * @var \Magento\Backend\Model\Session | ||
| */ | ||
| protected $_backendSession; | ||
|
|
||
| /** | ||
| * @param \Magento\Framework\App\Helper\Context $context | ||
| * @param \Magento\Backend\Model\Session $backendSession | ||
| * @param CollectionFactory $reviewCollectionFactory | ||
| */ | ||
| public function __construct( | ||
| \Magento\Framework\App\Helper\Context $context, | ||
| \Magento\Backend\Model\Session $backendSession | ||
| CollectionFactory $reviewCollectionFactory | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use ObjectManager to initialise this, and make it null by default |
||
| ) { | ||
| $this->_backendSession = $backendSession; | ||
| parent::__construct($context); | ||
| $this->reviewCollectionFactory = $reviewCollectionFactory; | ||
| } | ||
|
|
||
| /** | ||
| * Set storage id | ||
| * | ||
| * @param int $storageId | ||
| * @return void | ||
| */ | ||
| public function setStorageId($storageId) | ||
| { | ||
| $this->_storageId = $storageId; | ||
| } | ||
|
|
||
| /** | ||
| * Set items to storage | ||
| * | ||
| * @param array $items | ||
| * @return $this | ||
| */ | ||
| public function setItems(array $items) | ||
| { | ||
| $this->_items = $items; | ||
| $this->_backendSession->setData($this->_getStorageKey(), $this->_items); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * Load stored items | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function _loadItems() | ||
| { | ||
| if ($this->_items === null) { | ||
| $this->_items = (array)$this->_backendSession->getData($this->_getStorageKey()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get next item id | ||
| * Get the next review id. | ||
| * | ||
| * @param int $id | ||
| * @return int|bool | ||
| * @return int|false | ||
| */ | ||
| public function getNextItemId($id) | ||
| public function getNextItemId($id): int|false | ||
| { | ||
| $position = $this->_findItemPositionByValue($id); | ||
| if ($position === false || $position == count($this->_items) - 1) { | ||
| return false; | ||
| } | ||
|
|
||
| return $this->_items[$position + 1]; | ||
| return $this->getRelativeReviewId($id, 'gt', 'ASC'); | ||
| } | ||
|
|
||
| /** | ||
| * Get previous item id | ||
| * Get the previous review id. | ||
| * | ||
| * @param int $id | ||
| * @return int|bool | ||
| * @return int|false | ||
| */ | ||
| public function getPreviousItemId($id) | ||
| public function getPreviousItemId($id): int|false | ||
| { | ||
| $position = $this->_findItemPositionByValue($id); | ||
| if ($position === false || $position == 0) { | ||
| return false; | ||
| } | ||
|
|
||
| return $this->_items[$position - 1]; | ||
| return $this->getRelativeReviewId($id, 'lt', 'DESC'); | ||
| } | ||
|
|
||
| /** | ||
| * Return item position based on passed in value | ||
| * Get the review id based on comparison and order. | ||
| * | ||
| * @param mixed $value | ||
| * @return int|bool | ||
| */ | ||
| protected function _findItemPositionByValue($value) | ||
| { | ||
| $this->_loadItems(); | ||
| return array_search($value, $this->_items); | ||
| } | ||
|
|
||
| /** | ||
| * Get storage key | ||
| * | ||
| * @return string | ||
| * @throws \Magento\Framework\Exception\LocalizedException | ||
| * @param int $id | ||
| * @param string $operator | ||
| * @param string $order | ||
| * @return int|false | ||
| */ | ||
| protected function _getStorageKey() | ||
| private function getRelativeReviewId($id, $operator, $order): int|false | ||
| { | ||
| if (!$this->_storageId) { | ||
| throw new LocalizedException(__("The storage key wasn't set. Add the storage key and try again.")); | ||
| } | ||
|
|
||
| return self::STORAGE_PREFIX . $this->_storageId; | ||
| $collection = $this->reviewCollectionFactory->create(); | ||
| $collection->addFieldToFilter('main_table.review_id', [$operator => $id]) | ||
| ->setOrder('main_table.review_id', $order) | ||
| ->setPageSize(1) | ||
| ->setCurPage(1); | ||
|
|
||
| $item = $collection->getFirstItem(); | ||
| return $item->getId() ? (int)$item->getId() : false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; | ||
| use Magento\Framework\DB\Select; | ||
| use Magento\Framework\EntityManager\MetadataPool; | ||
| use Magento\Review\Helper\Action\Pager; | ||
|
|
||
| /** | ||
| * Review Product Collection | ||
|
|
@@ -405,6 +406,8 @@ public function getAllIds($limit = null, $offset = null) | |
| * Get result sorted ids | ||
| * | ||
| * @return array | ||
| * @deprecated This method is not being used to fetch ids anymore.We use it only to support backward compatibility | ||
| * @see Pager | ||
| */ | ||
| public function getResultingIds() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this method could be backward incompatible change. |
||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this method could backward incompatible change, third-party extensions may override this method.