Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed May 9, 2023
2 parents a7413b8 + 460ce65 commit 976591d
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function loadPrices($filter, $limit, $offset = null, $lowerPrice = null,
if (!is_null($upperPrice)) {
$select->where("$priceExpression < " . $this->_getComparingValue($upperPrice, $filter));
}
$select->order("$priceExpression ASC")->limit($limit, $offset);
$select->order(new Zend_Db_Expr("$priceExpression ASC"))->limit($limit, $offset);

return $this->_getReadAdapter()->fetchCol($select);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ public function loadNextPrices($filter, $price, $rightIndex, $upperPrice = null)
if (!is_null($upperPrice)) {
$pricesSelect->where("$priceExpression < " . $this->_getComparingValue($upperPrice, $filter));
}
$pricesSelect->order("$priceExpression DESC")->limit($rightIndex - $offset + 1, $offset - 1);
$pricesSelect->order(new Zend_Db_Expr("$priceExpression DESC"))->limit($rightIndex - $offset + 1, $offset - 1);

return array_reverse($this->_getReadAdapter()->fetchCol($pricesSelect));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ public function update($productId, $data)
$idBySku = $product->getIdBySku($productId);
$productId = $idBySku ? $idBySku : $productId;

$product->setStoreId($this->_getStoreId())
->load($productId);
/** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
$stockItem = Mage::getModel('cataloginventory/stock_item')
->setStoreId($this->_getStoreId())
->loadByProduct($productId);

if (!$product->getId()) {
if (!$stockItem->getId()) {
$this->_fault('not_exists');
}

$stockItem = $product->getStockItem();
$stockData = array_replace($stockItem->getData(), (array)$data);
$stockItem->setData($stockData);

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Controller/Request/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function getScheme()
{
return $this->getServer('HTTPS') == 'on'
|| $this->getServer('HTTP_X_FORWARDED_PROTO') == 'https'
|| (Mage::isInstalled() && Mage::app()->getStore()->isCurrentlySecure()) ?
|| (Mage::isInstalled() && Mage::app()->isCurrentlySecure()) ?
self::SCHEME_HTTPS :
self::SCHEME_HTTP;
}
Expand Down
31 changes: 31 additions & 0 deletions app/code/core/Mage/Core/Model/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,37 @@ public function setRequest(Mage_Core_Controller_Request_Http $request)
return $this;
}

/**
* @return bool
*/
public function isCurrentlySecure()
{
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
return true;
}

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
return true;
}

if (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == 443)) {
return true;
}

if (Mage::isInstalled()) {
$offloaderHeader = strtoupper(trim((string) Mage::getConfig()->getNode(Mage_Core_Model_Store::XML_PATH_OFFLOADER_HEADER, 'default')));
if ($offloaderHeader) {
$offloaderHeader = preg_replace('/[^A-Z]+/', '_', $offloaderHeader);
$offloaderHeader = strpos($offloaderHeader, 'HTTP_') === 0 ? $offloaderHeader : 'HTTP_' . $offloaderHeader;
if (!empty($_SERVER[$offloaderHeader]) && $_SERVER[$offloaderHeader] !== 'http') {
return true;
}
}
}

return false;
}

/**
* Retrieve response object
*
Expand Down
26 changes: 2 additions & 24 deletions app/code/core/Mage/Core/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,34 +749,12 @@ public function isFrontUrlSecure()
/**
* Check if request was secure
*
* @deprecated
* @return bool
*/
public function isCurrentlySecure()
{
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
return true;
}

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
return true;
}

if (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == 443)) {
return true;
}

if (Mage::isInstalled()) {
$offloaderHeader = strtoupper(trim((string) Mage::getStoreConfig(self::XML_PATH_OFFLOADER_HEADER)));
if ($offloaderHeader) {
$offloaderHeader = preg_replace('/[^A-Z]+/', '_', $offloaderHeader);
$offloaderHeader = strpos($offloaderHeader, 'HTTP_') === 0 ? $offloaderHeader : 'HTTP_' . $offloaderHeader;
if (!empty($_SERVER[$offloaderHeader]) && $_SERVER[$offloaderHeader] !== 'http') {
return true;
}
}
}

return false;
return Mage::app()->isCurrentlySecure();
}

/*************************************************************************************
Expand Down
4 changes: 4 additions & 0 deletions app/code/core/Mage/Core/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,10 @@
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<comment><![CDATA[
Provide the name of the request header set by the upstream proxy to indicate a secure connection.
The header <code>X-Forwarded-Proto: https</code> is already checked by default regardless of this configuration option.
]]></comment>
</offloader_header>
</fields>
</secure>
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Index/Model/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ public function logEvent(Varien_Object $entity, $entityType, $eventType, $doSave
* @param Varien_Object $entity
* @param string $entityType
* @param string $eventType
* @throws Exception
* @return Mage_Index_Model_Indexer
* @throws Exception|Throwable
*/
public function processEntityAction(Varien_Object $entity, $entityType, $eventType)
public function processEntityAction(Varien_Object $entity, $entityType, $eventType): Mage_Index_Model_Indexer
{
$event = $this->logEvent($entity, $entityType, $eventType, false);
/**
Expand Down
63 changes: 63 additions & 0 deletions app/code/core/Mage/Index/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
class Mage_Index_Model_Observer
{
public const OLD_INDEX_EVENT_THRESHOLD_SECONDS = 24 * 60 * 60;
public const OLD_INDEX_EVENT_DELETE_COUNT = 1000;

/**
* Indexer model
*
Expand All @@ -35,6 +38,7 @@ public function __construct()
* Store after commit observer. Process store related indexes
*
* @param Varien_Event_Observer $observer
* @throws Throwable
*/
public function processStoreSave(Varien_Event_Observer $observer)
{
Expand All @@ -50,6 +54,7 @@ public function processStoreSave(Varien_Event_Observer $observer)
* Store group after commit observer. Process store group related indexes
*
* @param Varien_Event_Observer $observer
* @throws Throwable
*/
public function processStoreGroupSave(Varien_Event_Observer $observer)
{
Expand All @@ -65,6 +70,7 @@ public function processStoreGroupSave(Varien_Event_Observer $observer)
* Website save after commit observer. Process website related indexes
*
* @param Varien_Event_Observer $observer
* @throws Throwable
*/
public function processWebsiteSave(Varien_Event_Observer $observer)
{
Expand All @@ -80,6 +86,7 @@ public function processWebsiteSave(Varien_Event_Observer $observer)
* Store after commit observer. Process store related indexes
*
* @param Varien_Event_Observer $observer
* @throws Throwable
*/
public function processStoreDelete(Varien_Event_Observer $observer)
{
Expand All @@ -95,6 +102,7 @@ public function processStoreDelete(Varien_Event_Observer $observer)
* Store group after commit observer. Process store group related indexes
*
* @param Varien_Event_Observer $observer
* @throws Throwable
*/
public function processStoreGroupDelete(Varien_Event_Observer $observer)
{
Expand All @@ -110,6 +118,7 @@ public function processStoreGroupDelete(Varien_Event_Observer $observer)
* Website save after commit observer. Process website related indexes
*
* @param Varien_Event_Observer $observer
* @throws Throwable
*/
public function processWebsiteDelete(Varien_Event_Observer $observer)
{
Expand All @@ -125,6 +134,7 @@ public function processWebsiteDelete(Varien_Event_Observer $observer)
* Config data after commit observer.
*
* @param Varien_Event_Observer $observer
* @throws Throwable
*/
public function processConfigDataSave(Varien_Event_Observer $observer)
{
Expand All @@ -135,4 +145,57 @@ public function processConfigDataSave(Varien_Event_Observer $observer)
Mage_Index_Model_Event::TYPE_SAVE
);
}

/**
* Clean old index events for indexers in manual mode
*
* @return void
* @throws Exception
*/
public function cleanOutdatedEvents()
{
$manualIndexProcessCollection = Mage::getSingleton('index/indexer')
->getProcessesCollection()
->addFieldToFilter('mode', Mage_Index_Model_Process::MODE_MANUAL);

$now = new DateTime();
/** @noinspection PhpUnhandledExceptionInspection */
$dateInterval = new DateInterval('PT' . self::OLD_INDEX_EVENT_THRESHOLD_SECONDS . 'S');
$oldEventsThreshold = $now
->sub($dateInterval)
->format(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT);

$coreResource = Mage::getSingleton('core/resource');
$writeConnection = $coreResource->getConnection('core_write');
$indexEventTableName = $coreResource->getTableName('index/event');

/** @var Mage_Index_Model_Process $process */
foreach ($manualIndexProcessCollection as $process) {
$unprocessedEventsCollection = $process
->getUnprocessedEventsCollection()
->addFieldToFilter('created_at', ['lt' => $oldEventsThreshold])
->load();

$i = 0;
$eventList = [];
/** @var Mage_Index_Model_Event $unprocessedEvent */
foreach ($unprocessedEventsCollection as $unprocessedEvent) {
$i++;
$eventList[] = $unprocessedEvent->getId();
if ($i === self::OLD_INDEX_EVENT_DELETE_COUNT) {
break;
}
}

if (!empty($eventList)) {
$where = new Zend_Db_Expr(
sprintf(
'event_id in (%s)',
implode(',', $eventList)
)
);
$writeConnection->delete($indexEventTableName, $where);
}
}
}
}
12 changes: 12 additions & 0 deletions app/code/core/Mage/Index/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
<version>1.6.0.0</version>
</Mage_Index>
</modules>
<crontab>
<jobs>
<index_clean_events>
<schedule>
<cron_expr>30 */4 * * *</cron_expr>
</schedule>
<run>
<model>index/observer::cleanOutdatedEvents</model>
</run>
</index_clean_events>
</jobs>
</crontab>
<global>
<helpers>
<index>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@
</script>

<?php echo $this->helper('core/js')->getTranslatorScript() ?>
<?php echo $this->getChildHtml('calendar'); ?>
<?php echo $this->getChildHtml('optional_zip_countries'); ?>
<?php echo $this->getChildHtml(); ?>

0 comments on commit 976591d

Please sign in to comment.