Skip to content

Commit

Permalink
Merge pull request #2225 from Leantime/clearTemplatePathCache
Browse files Browse the repository at this point in the history
Update Plugins.php
  • Loading branch information
marcelfolaron authored Jan 18, 2024
2 parents cebaa0a + 46499b0 commit c93766d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions app/Domain/Plugins/Services/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function isPluginEnabled($pluginFolder): bool
*/
public function getEnabledPlugins(): mixed
{
unset($_SESSION['enabledPlugins']);

if (isset($_SESSION['enabledPlugins'])) {
$enabledPlugins = static::dispatch_filter("beforeReturnCachedPlugins", $_SESSION['enabledPlugins'], array("enabledOnly" => true));
return $enabledPlugins;
Expand All @@ -171,6 +171,9 @@ public function getEnabledPlugins(): mixed
*/
public function discoverNewPlugins(): array
{

$this->clearCache();

$installedPluginNames = array_map(fn ($plugin) => $plugin->foldername, $this->getAllPlugins());
$scanned_directory = array_diff(scandir($this->pluginDirectory), ['..', '.']);

Expand Down Expand Up @@ -226,6 +229,9 @@ public function createPluginFromComposer(string $pluginFolder, string $license_k
*/
public function installPlugin($pluginFolder): false|string
{

$this->clearCache();

$pluginFolder = Str::studly($pluginFolder);

try {
Expand Down Expand Up @@ -256,7 +262,7 @@ public function installPlugin($pluginFolder): false|string
*/
public function enablePlugin(int $id): bool
{
unset($_SESSION['enabledPlugins']);
$this->clearCache();

$pluginModel = $this->pluginRepository->getPlugin($id);

Expand Down Expand Up @@ -292,7 +298,7 @@ public function enablePlugin(int $id): bool
*/
public function disablePlugin(int $id): bool
{
unset($_SESSION['enabledPlugins']);
$this->clearCache();

$pluginModel = $this->pluginRepository->getPlugin($id);

Expand Down Expand Up @@ -329,7 +335,7 @@ public function disablePlugin(int $id): bool
*/
public function removePlugin(int $id): bool
{
unset($_SESSION['enabledPlugins']);
$this->clearCache();
/** @var PluginModel|false $plugin */
$plugin = $this->pluginRepository->getPlugin($id);

Expand Down Expand Up @@ -450,6 +456,9 @@ public function getMarketplacePlugin(string $identifier): MarketplacePlugin|fals
*/
public function installMarketplacePlugin(MarketplacePlugin $plugin, string $version): void
{

$this->clearCache();

$response = Http::withoutVerifying()->withHeaders([
'X-License-Key' => $plugin->license,
'X-Instance-Id' => $this->settingsService->getCompanyId(),
Expand Down Expand Up @@ -514,7 +523,6 @@ public function installMarketplacePlugin(MarketplacePlugin $plugin, string $vers
throw new \Exception(__('notification_cant_add_to_db'));
}

unset($_SESSION['enabledPlugins']);
}

public function canActivate(InstalledPlugin $plugin): bool
Expand All @@ -541,5 +549,11 @@ public function canActivate(InstalledPlugin $plugin): bool

return true;
}

public function clearCache() {

unset($_SESSION['commands']['plugins'], $_SESSION['enabledPlugins'], $_SESSION['template_paths'], $_SESSION['composers']);

}
}
}

0 comments on commit c93766d

Please sign in to comment.