From a8cbf0d735e6b242af48fdb1b748d8740b3a2bd4 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 27 Nov 2023 16:21:16 +0200 Subject: [PATCH] fix script --- dev/SetConfigParams.php | 85 --------------------------------------- dev/set-config-params.php | 52 +++++++++++++++++++++++- 2 files changed, 51 insertions(+), 86 deletions(-) delete mode 100644 dev/SetConfigParams.php diff --git a/dev/SetConfigParams.php b/dev/SetConfigParams.php deleted file mode 100644 index 95d6f50af6..0000000000 --- a/dev/SetConfigParams.php +++ /dev/null @@ -1,85 +0,0 @@ -getContents('package.json') - ); - - $version = $packageData->version ?? null; - - if (!$version) { - return; - } - - $configPath = 'data/config.php'; - - $configWriterFileManager = new ConfigWriterFileManager(); - - if (!$configWriterFileManager->isFile($configPath)) { - $configWriterFileManager->putPhpContents($configPath, []); - } - - $app = new Application(); - - $injectableFactory = $app->getContainer()->getByClass(InjectableFactory::class); - $config = $app->getContainer()->getByClass(Config::class); - - if ($config->get('version') === $version) { - return; - } - - $configWriter = $injectableFactory->create(ConfigWriter::class); - - $configWriter->set('version', $version); - $configWriter->save(); - } -} diff --git a/dev/set-config-params.php b/dev/set-config-params.php index 2119fee194..2215b1aa84 100644 --- a/dev/set-config-params.php +++ b/dev/set-config-params.php @@ -27,6 +27,56 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ +/** + * Creates the config file if it does not exist. Sets the 'version' from the `package.json` in the config. + */ + include "bootstrap.php"; -(new EspoDev\SetConfigParams())->process(); +use Espo\Core\Application; +use Espo\Core\InjectableFactory; +use Espo\Core\Utils\Config; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Config\ConfigWriterFileManager; +use Espo\Core\Utils\Config\ConfigWriter; +use Espo\Core\Utils\Json; + +if (!str_starts_with(php_sapi_name(), 'cli')) { + return; +} + +$fileManager = new FileManager(); + +$packageData = Json::decode( + $fileManager->getContents('package.json') +); + +$version = $packageData->version ?? null; + +if (!$version) { + return; +} + +$configPath = 'data/config.php'; + +$configWriterFileManager = new ConfigWriterFileManager(); + +if (!$configWriterFileManager->isFile($configPath)) { + $configWriterFileManager->putPhpContents($configPath, []); +} + +$app = new Application(); + +$injectableFactory = $app->getContainer()->getByClass(InjectableFactory::class); +$config = $app->getContainer()->getByClass(Config::class); + +if ($config->get('version') === $version) { + return; +} + +$configWriter = $injectableFactory->create(ConfigWriter::class); + +$configWriter->set('version', $version); +$configWriter->save(); + +