Commit cc0ea0ba5fd11ae75734081d9ed0576d4cb5c8bc
1 parent
8b26c067
KTS-4246. Added a check to stop the plugin from being registered on every page load.
Committed by: Megan Watson Reviewed by: Kevin Fourie
Showing
3 changed files
with
21 additions
and
17 deletions
lib/plugins/plugin.inc.php
| @@ -334,6 +334,11 @@ class KTPlugin { | @@ -334,6 +334,11 @@ class KTPlugin { | ||
| 334 | $sql = "SELECT id FROM plugin_helper WHERE namespace = '{$sNamespace}' AND classtype = '{$type}'"; | 334 | $sql = "SELECT id FROM plugin_helper WHERE namespace = '{$sNamespace}' AND classtype = '{$type}'"; |
| 335 | $res = DBUtil::getOneResult($sql); | 335 | $res = DBUtil::getOneResult($sql); |
| 336 | 336 | ||
| 337 | + // if record exists - ignore it. | ||
| 338 | + if(!empty($res)){ | ||
| 339 | + return true; | ||
| 340 | + } | ||
| 341 | + | ||
| 337 | $aValues = array(); | 342 | $aValues = array(); |
| 338 | $aValues['namespace'] = $sNamespace; | 343 | $aValues['namespace'] = $sNamespace; |
| 339 | $aValues['plugin'] = (!empty($this->sNamespace)) ? $this->sNamespace : $sNamespace; | 344 | $aValues['plugin'] = (!empty($this->sNamespace)) ? $this->sNamespace : $sNamespace; |
| @@ -343,16 +348,6 @@ class KTPlugin { | @@ -343,16 +348,6 @@ class KTPlugin { | ||
| 343 | $aValues['viewtype'] = $view; | 348 | $aValues['viewtype'] = $view; |
| 344 | $aValues['classtype'] = $type; | 349 | $aValues['classtype'] = $type; |
| 345 | 350 | ||
| 346 | - // if record exists - update it. | ||
| 347 | - if(!empty($res)){ | ||
| 348 | - $id = $res['id']; | ||
| 349 | - $updateRes = DBUtil::autoUpdate('plugin_helper', $aValues, $id); | ||
| 350 | - if(PEAR::isError($updateRes)){ | ||
| 351 | - return $updateRes; | ||
| 352 | - } | ||
| 353 | - return true; | ||
| 354 | - } | ||
| 355 | - | ||
| 356 | // Insert into DB | 351 | // Insert into DB |
| 357 | $res = DBUtil::autoInsert('plugin_helper', $aValues); | 352 | $res = DBUtil::autoInsert('plugin_helper', $aValues); |
| 358 | if(PEAR::isError($res)){ | 353 | if(PEAR::isError($res)){ |
| @@ -426,6 +421,7 @@ class KTPlugin { | @@ -426,6 +421,7 @@ class KTPlugin { | ||
| 426 | if(!$res){ | 421 | if(!$res){ |
| 427 | return false; | 422 | return false; |
| 428 | } | 423 | } |
| 424 | + return true; | ||
| 429 | 425 | ||
| 430 | // Get actions, portlets, etc, create arrays as part of plugin | 426 | // Get actions, portlets, etc, create arrays as part of plugin |
| 431 | $query = "SELECT * FROM plugin_helper h WHERE plugin = '{$this->sNamespace}'"; | 427 | $query = "SELECT * FROM plugin_helper h WHERE plugin = '{$this->sNamespace}'"; |
lib/plugins/pluginregistry.inc.php
| @@ -60,8 +60,15 @@ class KTPluginRegistry { | @@ -60,8 +60,15 @@ class KTPluginRegistry { | ||
| 60 | $sFilename = (!empty($sFilename)) ? KTPlugin::_fixFilename($sFilename) : ''; | 60 | $sFilename = (!empty($sFilename)) ? KTPlugin::_fixFilename($sFilename) : ''; |
| 61 | $this->_aPluginDetails[$sNamespace] = array($sClassName, $sNamespace, $sFilename); | 61 | $this->_aPluginDetails[$sNamespace] = array($sClassName, $sNamespace, $sFilename); |
| 62 | 62 | ||
| 63 | - $object = $sClassName.'|'.$sNamespace.'|'.$sFilename; | ||
| 64 | - KTPlugin::registerPluginHelper($sNamespace, $sClassName, $sFilename, $object, 'general', 'plugin'); | 63 | + /* |
| 64 | + Check whether the system is registering or not. If true, register the plugin in plugin_helper. | ||
| 65 | + If false, skip. | ||
| 66 | + This check has been put in place to prevent the plugin being registered on every page load. | ||
| 67 | + */ | ||
| 68 | + if(isset($_SESSION['plugins_registerplugins']) && $_SESSION['plugins_registerplugins']){ | ||
| 69 | + $object = $sClassName.'|'.$sNamespace.'|'.$sFilename; | ||
| 70 | + KTPlugin::registerPluginHelper($sNamespace, $sClassName, $sFilename, $object, 'general', 'plugin'); | ||
| 71 | + } | ||
| 65 | } | 72 | } |
| 66 | 73 | ||
| 67 | function &getPlugin($sNamespace) { | 74 | function &getPlugin($sNamespace) { |
lib/plugins/pluginutil.inc.php
| @@ -161,7 +161,6 @@ class KTPluginUtil { | @@ -161,7 +161,6 @@ class KTPluginUtil { | ||
| 161 | if($sType != 'dashboard'){ | 161 | if($sType != 'dashboard'){ |
| 162 | $sType = 'general'; | 162 | $sType = 'general'; |
| 163 | } | 163 | } |
| 164 | - $GLOBALS['_KT_PLUGIN'] = array(); | ||
| 165 | 164 | ||
| 166 | $aPlugins = array(); | 165 | $aPlugins = array(); |
| 167 | $aPluginHelpers = array(); | 166 | $aPluginHelpers = array(); |
| @@ -573,13 +572,15 @@ class KTPluginUtil { | @@ -573,13 +572,15 @@ class KTPluginUtil { | ||
| 573 | /* Sort the plugins by priority */ | 572 | /* Sort the plugins by priority */ |
| 574 | asort($plugins); | 573 | asort($plugins); |
| 575 | 574 | ||
| 575 | + /* | ||
| 576 | + Add a check to indicate that plugin registration is occuring. | ||
| 577 | + This check has been put in place to prevent the plugin being registered on every page load. | ||
| 578 | + */ | ||
| 579 | + $_SESSION['plugins_registerplugins'] = true; | ||
| 576 | foreach($plugins as $sFile => $priority) { | 580 | foreach($plugins as $sFile => $priority) { |
| 577 | require_once($sFile); | 581 | require_once($sFile); |
| 578 | } | 582 | } |
| 579 | - | ||
| 580 | - | ||
| 581 | - | ||
| 582 | - | 583 | + $_SESSION['plugins_registerplugins'] = false; |
| 583 | 584 | ||
| 584 | $oRegistry =& KTPluginRegistry::getSingleton(); | 585 | $oRegistry =& KTPluginRegistry::getSingleton(); |
| 585 | $aRegistryList = $oRegistry->getPlugins(); | 586 | $aRegistryList = $oRegistry->getPlugins(); |