Skip to content

Commit

Permalink
Cache isModuleOutputEnabled or isModuleEnabled status (#4323)
Browse files Browse the repository at this point in the history
* cache module output status

* revert config caching

#4323 (comment)

* added scope label to config

* deprecated Mage_Adminhtml_Block_Template::isOutputEnabled()

- use Mage_Core_Block_Template::isModuleOutputEnabled()

* use new method

* added Mage_Core_Block_Template::isModuleEnabled()

* moved to abstract class

* added Mage_Core_Model_Resource_Abstract::isModuleEnabled()

* added Mage_Eav_Model_Entity_Collection_Abstract::isModuleEnabled()

* use new methods

* use trait

* updated baseline

* copyright [skip ci]

* Revert "use trait"

This reverts commit 51c7171

* update

-see #4266

---------

Co-authored-by: Ng Kiat Siong <[email protected]>
  • Loading branch information
sreichel and kiatng authored Nov 26, 2024
1 parent f4a3568 commit ff2e140
Show file tree
Hide file tree
Showing 54 changed files with 124 additions and 81 deletions.
5 changes: 0 additions & 5 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4945,11 +4945,6 @@ parameters:
count: 1
path: app/code/core/Mage/Rating/Model/Resource/Rating.php

-
message: "#^Parameter \\#1 \\$object of method Mage_Rating_Model_Resource_Rating\\:\\:_getEntitySummaryData\\(\\) expects Mage_Rating_Model_Rating, Mage_Core_Model_Abstract given\\.$#"
count: 1
path: app/code/core/Mage/Rating/Model/Resource/Rating.php

-
message: "#^Variable \\$data in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function _prepareCollection()
if ($store = $this->getRequest()->getParam('store')) {
$websiteId = Mage::app()->getStore($store)->getWebsiteId();
}
if (Mage::helper('catalog')->isModuleEnabled('Mage_ProductAlert')) {
if ($this->isModuleEnabled('Mage_ProductAlert', 'catalog')) {
$collection = Mage::getModel('productalert/price')
->getCustomerCollection()
->join($productId, $websiteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function _prepareCollection()
if ($store = $this->getRequest()->getParam('store')) {
$websiteId = Mage::app()->getStore($store)->getWebsiteId();
}
if (Mage::helper('catalog')->isModuleEnabled('Mage_ProductAlert')) {
if ($this->isModuleEnabled('Mage_ProductAlert', 'catalog')) {
$collection = Mage::getModel('productalert/stock')
->getCustomerCollection()
->join($productId, $websiteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes extends Mage_Admi
protected function _prepareLayout()
{
parent::_prepareLayout();
if (Mage::helper('catalog')->isModuleEnabled('Mage_Cms')
if ($this->isModuleEnabled('Mage_Cms', 'catalog')
&& Mage::getSingleton('cms/wysiwyg_config')->isEnabled()
) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()

public function getBackordersOption()
{
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
if ($this->isModuleEnabled('Mage_CatalogInventory', 'catalog')) {
return Mage::getSingleton('cataloginventory/source_backorders')->toOptionArray();
}

Expand All @@ -44,7 +44,7 @@ public function getBackordersOption()
*/
public function getStockOption()
{
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
if ($this->isModuleEnabled('Mage_CatalogInventory', 'catalog')) {
return Mage::getSingleton('cataloginventory/source_stock')->toOptionArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function _sortValues($data)
public function getCustomerGroups($groupId = null)
{
if ($this->_customerGroups === null) {
if (!Mage::helper('catalog')->isModuleEnabled('Mage_Customer')) {
if (!$this->isModuleEnabled('Mage_Customer', 'catalog')) {
return [];
}
$collection = Mage::getModel('customer/group')->getCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function _prepareCollection()
->addFilterByRequiredOptions()
->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner');

if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
if ($this->isModuleEnabled('Mage_CatalogInventory', 'catalog')) {
Mage::getModel('cataloginventory/stock_item')->addCatalogInventoryToProductCollection($collection);
}
/** @var Mage_Catalog_Model_Product_Type_Configurable $productType */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()

protected function _prepareCollection()
{
if (Mage::helper('catalog')->isModuleEnabled('Mage_Tag')) {
if ($this->isModuleEnabled('Mage_Tag', 'catalog')) {
$collection = Mage::getModel('tag/tag')
->getCustomerCollection()
->addProductFilter($this->getProductId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function _prepareLayout()
]);
}

if (Mage::helper('core')->isModuleEnabled('Mage_CatalogInventory')) {
if ($this->isModuleEnabled('Mage_CatalogInventory')) {
$this->addTab('inventory', [
'label' => Mage::helper('catalog')->__('Inventory'),
'content' => $this->_translateHtml($this->getLayout()
Expand Down Expand Up @@ -131,7 +131,7 @@ protected function _prepareLayout()
}

if ($this->getRequest()->getParam('id', false)) {
if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')) {
if ($this->isModuleEnabled('Mage_Review', 'catalog')) {
if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')) {
$this->addTab('reviews', [
'label' => Mage::helper('catalog')->__('Product Reviews'),
Expand All @@ -140,7 +140,7 @@ protected function _prepareLayout()
]);
}
}
if (Mage::helper('catalog')->isModuleEnabled('Mage_Tag')) {
if ($this->isModuleEnabled('Mage_Tag', 'catalog')) {
if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')) {
$this->addTab('tags', [
'label' => Mage::helper('catalog')->__('Product Tags'),
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function _prepareCollection()
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');

if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
if ($this->isModuleEnabled('Mage_CatalogInventory', 'catalog')) {
$collection->joinField(
'qty',
'cataloginventory/stock_item',
Expand Down Expand Up @@ -216,7 +216,7 @@ protected function _prepareColumns()
]
);

if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
if ($this->isModuleEnabled('Mage_CatalogInventory', 'catalog')) {
$this->addColumn(
'qty',
[
Expand Down Expand Up @@ -284,7 +284,7 @@ protected function _prepareColumns()
]
);

if (Mage::helper('catalog')->isModuleEnabled('Mage_Rss') &&
if ($this->isModuleEnabled('Mage_Rss', 'catalog') &&
Mage::helper('rss')->isRssAdminCatalogNotifyStockEnabled()
) {
$this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS'));
Expand Down
12 changes: 9 additions & 3 deletions app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ protected function _beforeToHtml()
'url' => $this->getUrl('*/*/wishlist', ['_current' => true]),
]);

if (Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter') && Mage::getSingleton('admin/session')->isAllowed('newsletter/subscriber')) {
if ($this->isModuleOutputEnabled('Mage_Newsletter')
&& Mage::getSingleton('admin/session')->isAllowed('newsletter/subscriber')
) {
/** @var Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter $block */
$block = $this->getLayout()->createBlock('adminhtml/customer_edit_tab_newsletter');
$this->addTab('newsletter', [
Expand All @@ -83,15 +85,19 @@ protected function _beforeToHtml()
]);
}

if (Mage::helper('core')->isModuleOutputEnabled('Mage_Review') && Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings')) {
if ($this->isModuleOutputEnabled('Mage_Review')
&& Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings')
) {
$this->addTab('reviews', [
'label' => Mage::helper('customer')->__('Product Reviews'),
'class' => 'ajax',
'url' => $this->getUrl('*/*/productReviews', ['_current' => true]),
]);
}

if (Mage::helper('core')->isModuleEnabled('Mage_Tag') && Mage::getSingleton('admin/session')->isAllowed('catalog/tag')) {
if ($this->isModuleEnabled('Mage_Tag')
&& Mage::getSingleton('admin/session')->isAllowed('catalog/tag')
) {
$this->addTab('tags', [
'label' => Mage::helper('customer')->__('Product Tags'),
'class' => 'ajax',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()

protected function _prepareCollection()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) {
if (!$this->isModuleEnabled('Mage_Reports')) {
return $this;
}
$collection = Mage::getResourceModel('reports/order_collection')
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Dashboard/Sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function _construct()

protected function _prepareLayout()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) {
if (!$this->isModuleEnabled('Mage_Reports')) {
return $this;
}
$isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct()

protected function _prepareCollection()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_CatalogSearch')) {
if (!$this->isModuleEnabled('Mage_CatalogSearch')) {
return parent::_prepareCollection();
}
$this->_collection = Mage::getModel('catalogsearch/query')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct()

protected function _prepareCollection()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_CatalogSearch')) {
if (!$this->isModuleEnabled('Mage_CatalogSearch')) {
return parent::_prepareCollection();
}
$this->_collection = Mage::getModel('catalogsearch/query')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()

protected function _prepareCollection()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_Sales')) {
if (!$this->isModuleEnabled('Mage_Sales')) {
return $this;
}
if ($this->getParam('website')) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Dashboard/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function _construct()

protected function _prepareLayout()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) {
if (!$this->isModuleEnabled('Mage_Reports')) {
return $this;
}
$isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function _getHelper()
*/
public function isShow()
{
if (!$this->isOutputEnabled('Mage_AdminNotification')) {
if (!$this->isModuleOutputEnabled('Mage_AdminNotification')) {
return false;
}
if ($this->getRequest()->getControllerName() === 'notification') {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Notification/Window.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function canShow()
return false;
}

if (!$this->isOutputEnabled('Mage_AdminNotification')) {
if (!$this->isModuleOutputEnabled('Mage_AdminNotification')) {
$this->_available = false;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Review/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected function _prepareColumns()
]
);

if (Mage::helper('catalog')->isModuleEnabled('Mage_Rss') &&
if ($this->isModuleEnabled('Mage_Rss', 'catalog') &&
Mage::helper('rss')->isRssAdminCatalogReviewEnabled()
) {
$this->addRssList('rss/catalog/review', Mage::helper('catalog')->__('Pending Reviews RSS'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function _getGiftmessageSaveModel()

public function canDisplayGiftmessage(): bool
{
if (!Mage::helper('core')->isModuleOutputEnabled('Mage_GiftMessage')) {
if (!$this->isModuleOutputEnabled('Mage_GiftMessage')) {
return false;
}
/** @var Mage_GiftMessage_Helper_Message $helper */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function getItemOrigPrice($item)
*/
public function isGiftMessagesAvailable($item = null)
{
if (!Mage::helper('core')->isModuleOutputEnabled('Mage_GiftMessage')) {
if (!$this->isModuleOutputEnabled('Mage_GiftMessage')) {
return false;
}
/** @var Mage_GiftMessage_Helper_Message $helper */
Expand All @@ -150,7 +150,7 @@ public function isGiftMessagesAvailable($item = null)
*/
public function isAllowedForGiftMessage($item)
{
if (!Mage::helper('core')->isModuleOutputEnabled('Mage_GiftMessage')) {
if (!$this->isModuleOutputEnabled('Mage_GiftMessage')) {
return false;
}
return Mage::getSingleton('adminhtml/giftmessage_save')->getIsAllowedQuoteItem($item);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected function _prepareColumns()
*/
public function addRssFeedLink()
{
if (Mage::helper('sales')->isModuleOutputEnabled('Mage_Rss')) {
if ($this->isModuleOutputEnabled('Mage_Rss', 'sales')) {
$storeId = null;

$filterString = $this->getParam($this->getVarNameFilter(), '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getOrder()
*/
protected function _beforeToHtml()
{
if (Mage::helper('core')->isModuleOutputEnabled('Mage_GiftMessage')) {
if ($this->isModuleOutputEnabled('Mage_GiftMessage')) {
if ($this->getParentBlock() && ($order = $this->getOrder())) {
$this->setEntity($order);
}
Expand All @@ -66,7 +66,7 @@ protected function _beforeToHtml()
*/
protected function _prepareLayout()
{
if (Mage::helper('core')->isModuleOutputEnabled('Mage_GiftMessage')) {
if ($this->isModuleOutputEnabled('Mage_GiftMessage')) {
$this->setChild(
'save_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
Expand Down Expand Up @@ -280,7 +280,7 @@ public function getHtmlId()
*/
public function canDisplayGiftmessage()
{
if (!Mage::helper('core')->isModuleOutputEnabled('Mage_GiftMessage')) {
if (!$this->isModuleOutputEnabled('Mage_GiftMessage')) {
return false;
}
/** @var Mage_GiftMessage_Helper_Message $helper */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function getHtmlId()
*/
public function canDisplayGiftmessage()
{
if (!Mage::helper('core')->isModuleOutputEnabled('Mage_GiftMessage')) {
if (!$this->isModuleOutputEnabled('Mage_GiftMessage')) {
return false;
}
/** @var Mage_GiftMessage_Helper_Message $helper */
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public function canUseWebsiteValue($field)
protected function _canShowField($field)
{
$ifModuleEnabled = trim((string)$field->if_module_enabled);
if ($ifModuleEnabled && !Mage::helper('Core')->isModuleEnabled($ifModuleEnabled)) {
if ($ifModuleEnabled && !$this->isModuleEnabled($ifModuleEnabled)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ protected function _getFieldHtml($fieldset, $moduleName)
'inherit' => $inherit,
'can_use_default_value' => $this->getForm()->canUseDefaultValue($e),
'can_use_website_value' => $this->getForm()->canUseWebsiteValue($e),
'scope' => true,
'scope_label' => Mage::helper('adminhtml')->__('[STORE VIEW]'),
]
)->setRenderer($this->_getFieldRenderer());

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
{
$backupAvailable =
Mage::getSingleton('admin/session')->isAllowed('system/tools/backup')
&& Mage::helper('core')->isModuleEnabled('Mage_Backup')
&& $this->isModuleEnabled('Mage_Backup')
&& !Mage::getStoreConfigFlag('advanced/modules_disable_output/Mage_Backup');

$saveLabel = '';
Expand Down
13 changes: 3 additions & 10 deletions app/code/core/Mage/Adminhtml/Block/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,14 @@ public function getFormKey()
}

/**
* Check whether the module output is enabled
*
* Because many module blocks belong to Adminhtml module,
* the feature "Disable module output" doesn't cover Admin area
*
* @param string $moduleName Full module name
* @return bool
* @deprecated
* @see Mage_Core_Block_Template::isModuleOutputEnabled()
*/
public function isOutputEnabled($moduleName = null)
{
if ($moduleName === null) {
$moduleName = $this->getModuleName();
}

return Mage::helper('core')->isModuleOutputEnabled($moduleName);
return $this->isModuleOutputEnabled($moduleName);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Bundle/Model/Resource/Indexer/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected function _prepareBundlePriceByType($priceType, $entityIds = null)
// add enable products limitation
$statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond, true);
if (Mage::helper('core')->isModuleEnabled('Mage_Tax')) {
if ($this->isModuleEnabled('Mage_Tax')) {
$taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', 'e.entity_id', 'cs.store_id');
} else {
$taxClassId = new Zend_Db_Expr('0');
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Block/Product/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function addReviewSummaryTemplate($type, $template)
protected function _initReviewsHelperBlock()
{
if (!$this->_reviewsHelperBlock) {
if (!Mage::helper('catalog')->isModuleEnabled('Mage_Review')) {
if (!$this->isModuleEnabled('Mage_Review', 'catalog')) {
return false;
}

Expand Down
Loading

0 comments on commit ff2e140

Please sign in to comment.