Jelajahi Sumber

#5177 Content cache: menu cache invalidation

Alex Trofimov 1 tahun lalu
induk
melakukan
44f7cc32d5

+ 6 - 0
inc/utils.inc.php

@@ -2842,6 +2842,12 @@ function bx_content_cache_del($sKey)
     return $oCache->delData('content_' . $sKey . '_' . bx_site_hash() . '.php');
     return $oCache->delData('content_' . $sKey . '_' . bx_site_hash() . '.php');
 }
 }
 
 
+function bx_content_cache_del_by_prefix($sPrefix)
+{
+    $oCache = bx_content_cache_obj();
+    return $oCache->removeAllByPrefix('content_' . $sPrefix);
+}
+
 function bx_content_cache_obj()
 function bx_content_cache_obj()
 {
 {
     if (isset($GLOBALS['bxCacheContentObj']))
     if (isset($GLOBALS['bxCacheContentObj']))

+ 1 - 1
install/sql/system.sql

@@ -4827,7 +4827,7 @@ INSERT INTO `sys_objects_menu` (`object`, `title`, `set_name`, `module`, `templa
 ('sys_studio_account_popup', '_sys_menu_title_studio_account_popup', 'sys_studio_account_popup', 'system', 4, 0, 1, 'BxTemplStudioMenuAccountPopup', '');
 ('sys_studio_account_popup', '_sys_menu_title_studio_account_popup', 'sys_studio_account_popup', 'system', 4, 0, 1, 'BxTemplStudioMenuAccountPopup', '');
 
 
 UPDATE `sys_objects_menu` SET `cache` = 'per_acl' WHERE `object` IN('sys_site', 'sys_account_notifications', 'sys_add_content', 'sys_toolbar_site', 'sys_footer', 'sys_site_submenu', 'sys_homepage_submenu', 'sys_homepage', 'sys_application', 'sys_site_in_panel');
 UPDATE `sys_objects_menu` SET `cache` = 'per_acl' WHERE `object` IN('sys_site', 'sys_account_notifications', 'sys_add_content', 'sys_toolbar_site', 'sys_footer', 'sys_site_submenu', 'sys_homepage_submenu', 'sys_homepage', 'sys_application', 'sys_site_in_panel');
-UPDATE `sys_objects_menu` SET `cache` = 'sys_site' WHERE `object` IN('sys_toolbar_member');
+UPDATE `sys_objects_menu` SET `cache` = 'per_user' WHERE `object` IN('sys_toolbar_member');
 
 
 CREATE TABLE IF NOT EXISTS `sys_menu_sets` (
 CREATE TABLE IF NOT EXISTS `sys_menu_sets` (
   `set_name` varchar(64) NOT NULL,
   `set_name` varchar(64) NOT NULL,

+ 39 - 10
studio/template/scripts/BxBaseStudioNavigationItems.php

@@ -79,11 +79,12 @@ class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
 
 
             bx_import('BxDolStudioUtils');
             bx_import('BxDolStudioUtils');
             $iId = (int)$oForm->insert(array('module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'name' => $sName, 'active' => 1, 'order' => $this->oDb->getItemOrderMax($this->sSet) + 1));
             $iId = (int)$oForm->insert(array('module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'name' => $sName, 'active' => 1, 'order' => $this->oDb->getItemOrderMax($this->sSet) + 1));
-            if($iId != 0)
+            if($iId != 0) {
+                $this->onMenuItemsChanged();
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
-            else
+            } else {
                 $aRes = array('msg' => _t('_adm_nav_err_items_create'));
                 $aRes = array('msg' => _t('_adm_nav_err_items_create'));
-
+            }
             echoJson($aRes);
             echoJson($aRes);
         }
         }
         else {
         else {
@@ -153,11 +154,12 @@ class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
             if($sTarget === false && !in_array($aItem['target'], array('', '_blank')))
             if($sTarget === false && !in_array($aItem['target'], array('', '_blank')))
                 unset($oForm->aInputs['target']);
                 unset($oForm->aInputs['target']);
 
 
-            if($oForm->update($aItem['id']) !== false)
+            if($oForm->update($aItem['id']) !== false) {
+                $this->onMenuItemsChanged();
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
-            else
+            } else {
                 $aRes = array('msg' => _t('_adm_nav_err_items_edit'));
                 $aRes = array('msg' => _t('_adm_nav_err_items_edit'));
-
+            }
             echoJson($aRes);
             echoJson($aRes);
         }
         }
         else {
         else {
@@ -198,9 +200,19 @@ class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
             $iAffected++;
             $iAffected++;
         }
         }
 
 
+        if ($iAffected)
+            $this->onMenuItemsChanged(); 
+
         echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_items_delete')));
         echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_items_delete')));
     }
     }
 
 
+    public function performActionReorder()
+    {        
+        $mixed = parent::performActionReorder();
+        $this->onMenuItemsChanged();
+        return $mixed;
+    }
+
     public function performActionShowTo()
     public function performActionShowTo()
     {
     {
         $sAction = 'show_to';
         $sAction = 'show_to';
@@ -295,11 +307,12 @@ class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
         $oForm->initChecker();
         $oForm->initChecker();
 
 
         if($oForm->isSubmittedAndValid()) {
         if($oForm->isSubmittedAndValid()) {
-            if($oForm->updateWithVisibility($aItem['id']) !== false)
+            if($oForm->updateWithVisibility($aItem['id']) !== false) {
+                $this->onMenuItemsChanged();
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
-            else
+            } else {
                 $aRes = array('msg' => _t('_adm_nav_err_items_show_to'));
                 $aRes = array('msg' => _t('_adm_nav_err_items_show_to'));
-
+            }
             echoJson($aRes);
             echoJson($aRes);
         }
         }
         else {
         else {
@@ -339,8 +352,10 @@ class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
                 exit;
                 exit;
             }
             }
 
 
-        if($this->oDb->updateItem($aItem['id'], array('icon' => '')) !== false)
+        if($this->oDb->updateItem($aItem['id'], array('icon' => '')) !== false) {
+            $this->onMenuItemsChanged();
             echoJson(array('grid' => $this->getCode(false), 'blink' => $iId, 'preview' => $this->_getIconPreview($aItem['id']), 'eval' => $this->getJsObject() . ".onDeleteIcon(oData)"));
             echoJson(array('grid' => $this->getCode(false), 'blink' => $iId, 'preview' => $this->_getIconPreview($aItem['id']), 'eval' => $this->getJsObject() . ".onDeleteIcon(oData)"));
+        }
     }
     }
 
 
     public function getJsObject()
     public function getJsObject()
@@ -1009,6 +1024,20 @@ class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
     {
     {
     	return $aRow['module'] != BX_DOL_STUDIO_MODULE_SYSTEM;
     	return $aRow['module'] != BX_DOL_STUDIO_MODULE_SYSTEM;
     }
     }
+
+    protected function onMenuItemsChanged()
+    {
+        bx_alert('system', 'menu_items_changed', 0, 0, array(
+            'set' => $this->sSet
+        ));
+
+        // clear all menus cache related to the current set
+        $aMenus = [];
+        $this->oDb->getMenus(array('type' => 'by_set_name', 'value' => $this->sSet), $aMenus, false);
+        foreach($aMenus as $aMenu) {
+            bx_content_cache_del_by_prefix('menu_' . $aMenu['object']);
+        }        
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 4 - 2
studio/template/scripts/BxBaseStudioNavigationMenus.php

@@ -105,10 +105,12 @@ class BxBaseStudioNavigationMenus extends BxDolStudioNavigationMenus
             }
             }
             unset($oForm->aInputs['set_title']);
             unset($oForm->aInputs['set_title']);
 
 
-            if($oForm->update($aMenu['id']) !== false)
+            if($oForm->update($aMenu['id']) !== false) {
+                bx_content_cache_del_by_prefix('menu_' . $aMenu['object']); 
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $aMenu['id']);
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $aMenu['id']);
-            else
+            } else {
                 $aRes = array('msg' => _t('_adm_nav_err_menus_edit'));
                 $aRes = array('msg' => _t('_adm_nav_err_menus_edit'));
+            }
 
 
             echoJson($aRes);
             echoJson($aRes);
         }
         }