|
@@ -8,7 +8,7 @@ use Composer\InstalledVersions;
|
|
|
use Composer\Json\JsonFile;
|
|
use Composer\Json\JsonFile;
|
|
|
use ReflectionException;
|
|
use ReflectionException;
|
|
|
use Seld\JsonLint\ParsingException;
|
|
use Seld\JsonLint\ParsingException;
|
|
|
-use SixShop\Core\Command\GenerateInstalledSixShopCommand;
|
|
|
|
|
|
|
+use SixShop\Core\Command\ClearExtensionCacheCommand;
|
|
|
use SixShop\Core\Exception\ExceptionHandle;
|
|
use SixShop\Core\Exception\ExceptionHandle;
|
|
|
use SixShop\Core\Plugin;
|
|
use SixShop\Core\Plugin;
|
|
|
use SixShop\Core\Request;
|
|
use SixShop\Core\Request;
|
|
@@ -67,22 +67,40 @@ class CoreService extends Service
|
|
|
self::$extensionComposerMap = require $extensionComposerFile;
|
|
self::$extensionComposerMap = require $extensionComposerFile;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- $files = array_diff(scandir($runtimePath), ['.', '..']);
|
|
|
|
|
- foreach ($files as $file) {
|
|
|
|
|
- if (str_starts_with($file, 'extension_') && str_ends_with($file, '.php')) {
|
|
|
|
|
- unlink($runtimePath . $file);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ foreach (glob($runtimePath . 'extension_*.php') ?: [] as $file) {
|
|
|
|
|
+ unlink($runtimePath . basename($file));
|
|
|
}
|
|
}
|
|
|
|
|
+ self::$extensionComposerMap = self::buildExtensionComposerMap();
|
|
|
|
|
+ $header = '// This file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL;
|
|
|
|
|
+ $content = '<?php ' . PHP_EOL . $header . "return " . var_export(self::$extensionComposerMap, true) . ';';
|
|
|
|
|
+ file_put_contents($extensionComposerFile, $content);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @throws ParsingException
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function buildExtensionComposerMap(): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $map = [];
|
|
|
foreach (InstalledVersions::getInstalledPackagesByType(Plugin::EXTENSION_TYPE) as $item) {
|
|
foreach (InstalledVersions::getInstalledPackagesByType(Plugin::EXTENSION_TYPE) as $item) {
|
|
|
$installPath = InstalledVersions::getInstallPath($item);
|
|
$installPath = InstalledVersions::getInstallPath($item);
|
|
|
$composerJson = new JsonFile($installPath . '/composer.json');
|
|
$composerJson = new JsonFile($installPath . '/composer.json');
|
|
|
$composer = $composerJson->read();
|
|
$composer = $composerJson->read();
|
|
|
$extensionID = $composer['extra']['sixshop']['id'] ?? $composer['name'];
|
|
$extensionID = $composer['extra']['sixshop']['id'] ?? $composer['name'];
|
|
|
- self::$extensionComposerMap[$extensionID] = $composer;
|
|
|
|
|
|
|
+ $map[$extensionID] = $composer;
|
|
|
}
|
|
}
|
|
|
- $header = '// This file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL;
|
|
|
|
|
- $content = '<?php ' . PHP_EOL . $header . "return " . var_export(self::$extensionComposerMap, true) . ';';
|
|
|
|
|
- file_put_contents($extensionComposerFile, $content);
|
|
|
|
|
|
|
+ return $map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function clearExtensionCache(): int
|
|
|
|
|
+ {
|
|
|
|
|
+ $count = 0;
|
|
|
|
|
+ foreach (glob(dirname(self::$extensionPath) . '/runtime/extension_*.php') ?: [] as $file) {
|
|
|
|
|
+ unlink($file);
|
|
|
|
|
+ $count++;
|
|
|
|
|
+ }
|
|
|
|
|
+ self::$extensionComposerMap = [];
|
|
|
|
|
+ return $count;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -111,7 +129,7 @@ class CoreService extends Service
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
$this->commands([
|
|
$this->commands([
|
|
|
- GenerateInstalledSixShopCommand::class,
|
|
|
|
|
|
|
+ ClearExtensionCacheCommand::class,
|
|
|
]);
|
|
]);
|
|
|
$this->app->make(CommandService::class)->init(function ($commands) {
|
|
$this->app->make(CommandService::class)->init(function ($commands) {
|
|
|
$this->commands($commands);
|
|
$this->commands($commands);
|