From 2b11bc0c80564f04a4d1a0d5b3b424c1a39f1c73 Mon Sep 17 00:00:00 2001 From: Taylor Dondich Date: Mon, 9 Dec 2019 11:06:29 -0800 Subject: [PATCH] PMC-1478 --- workflow/engine/classes/PmLicenseManager.php | 20 ++++++++-- workflow/engine/classes/model/AddonsStore.php | 10 ++++- workflow/engine/controllers/adminProxy.php | 10 ++++- .../engine/methods/enterprise/enterprise.php | 37 +++++++++++++++++-- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/workflow/engine/classes/PmLicenseManager.php b/workflow/engine/classes/PmLicenseManager.php index b03b128c1..89ef88d99 100644 --- a/workflow/engine/classes/PmLicenseManager.php +++ b/workflow/engine/classes/PmLicenseManager.php @@ -166,8 +166,14 @@ class PmLicenseManager } } - if (file_exists(PATH_DATA_SITE . "ee")) { - $aPlugins = unserialize(trim(file_get_contents(PATH_DATA_SITE . 'ee'))); + $eeData = Cache::get(config('system.workspace') . 'enterprise.ee', function () { + if (file_exists(PATH_DATA_SITE . 'ee')) { + return trim(file_get_contents(PATH_DATA_SITE . 'ee')); + } + return null; + }); + if ($eeData) { + $aPlugins = unserialize($eeData); $aDenied = []; foreach ($aPlugins as $aPlugin) { $sClassName = substr($aPlugin ['sFilename'], 0, strpos($aPlugin ['sFilename'], '-')); @@ -210,8 +216,14 @@ class PmLicenseManager $oPluginRegistry->savePlugin($oDetails->getNamespace()); } - if (file_exists(PATH_DATA_SITE . 'ee')) { - $aPlugins = unserialize(trim(file_get_contents(PATH_DATA_SITE . 'ee'))); + $eeData = Cache::get(config('system.workspace') . 'enterprise.ee', function () { + if (file_exists(PATH_DATA_SITE . 'ee')) { + return trim(file_get_contents(PATH_DATA_SITE . 'ee')); + } + return null; + }); + if ($eeData) { + $aPlugins = unserialize($eeData); foreach ($aPlugins as $aPlugin) { $sClassName = substr($aPlugin ['sFilename'], 0, strpos($aPlugin ['sFilename'], '-')); diff --git a/workflow/engine/classes/model/AddonsStore.php b/workflow/engine/classes/model/AddonsStore.php index 6434164fa..643945e85 100644 --- a/workflow/engine/classes/model/AddonsStore.php +++ b/workflow/engine/classes/model/AddonsStore.php @@ -354,8 +354,14 @@ class AddonsStore extends BaseAddonsStore $oPluginRegistry = PluginRegistry::loadSingleton(); $aPluginsPP = array(); - if (file_exists(PATH_DATA_SITE . 'ee')) { - $aPluginsPP = unserialize(trim(file_get_contents(PATH_DATA_SITE . 'ee'))); + $eeData = Cache::get(config('system.workspace') . 'enterprise.ee', function () { + if (file_exists(PATH_DATA_SITE . 'ee')) { + return trim(file_get_contents(PATH_DATA_SITE . 'ee')); + } + return null; + }); + if ($eeData) { + $aPluginsPP = unserialize($eeData); } $pmLicenseManagerO = PmLicenseManager::getSingleton(); diff --git a/workflow/engine/controllers/adminProxy.php b/workflow/engine/controllers/adminProxy.php index 65d1fafdc..067db1ff3 100644 --- a/workflow/engine/controllers/adminProxy.php +++ b/workflow/engine/controllers/adminProxy.php @@ -1500,8 +1500,14 @@ class adminProxy extends HttpProxyController //Installed Plugins (license info?) $arrayAddon = array(); - if (file_exists(PATH_DATA_SITE . "ee")) { - $arrayAddon = unserialize(trim(file_get_contents(PATH_DATA_SITE . "ee"))); + $eeData = Cache::get(config('system.workspace') . 'enterprise.ee', function () { + if (file_exists(PATH_DATA_SITE . 'ee')) { + return trim(file_get_contents(PATH_DATA_SITE . 'ee')); + } + return null; + }); + if ($eeData) { + $arrayAddon = unserialize($eeData); } $plugins = array(); diff --git a/workflow/engine/methods/enterprise/enterprise.php b/workflow/engine/methods/enterprise/enterprise.php index a943b6e99..b291e204c 100644 --- a/workflow/engine/methods/enterprise/enterprise.php +++ b/workflow/engine/methods/enterprise/enterprise.php @@ -1,5 +1,6 @@ systemAvailable = unserialize(trim(file_get_contents(PATH_DATA_SITE . "ee"))); + $cacheKey = config('system.workspace') . 'enterprise.ee'; + // Fetch the value from cache. If not present, fetch from the filesystem. + $value = Cache::get($cacheKey, function () { + if (file_exists(PATH_DATA_SITE . "ee")) { + return trim(file_get_contents(PATH_DATA_SITE . "ee")); + } else { + return null; + } + }); + if ($value) { + $this->systemAvailable = unserialize($value); + } else { + // Handle potential no value + $this->systemAvailable = []; } - $this->systemAvailable[$pluginFile]["sFilename"] = $pluginFile . "-" . $pluginVersion . ".tar"; - file_put_contents(PATH_DATA_SITE . "ee", serialize($this->systemAvailable)); + $filename = $pluginFile . '-' . $pluginVersion . '.tar'; + // Check to see if update is required + if ( + !isset($this->systemAvailable[$pluginFile]) || + !isset($this->systemAvailable[$pluginFile]['sFilename']) || + $this->systemAvailable[$pluginFile]['sFilename'] != $filename + ) { + // Update required + $this->systemAvailable[$pluginFile]["sFilename"] = $filename; + file_put_contents(PATH_DATA_SITE . "ee", serialize($this->systemAvailable)); + // Put in cache as well + Cache::forever($cacheKey, serialize($this->systemAvailable)); + } return true; }