From 2dc0a6bc9595b4aa910d13dc40e110443f7fa9a2 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 24 Jun 2021 11:34:13 +0300 Subject: [PATCH] installer libs --- .../Client/DevModeJsFileListProvider.php | 91 +++++++++++++++++++ application/Espo/Core/Utils/ClientManager.php | 42 ++------- install/core/Utils.php | 6 +- install/core/tpl/index.tpl | 9 ++ install/index.php | 41 ++++++--- 5 files changed, 138 insertions(+), 51 deletions(-) create mode 100644 application/Espo/Core/Utils/Client/DevModeJsFileListProvider.php diff --git a/application/Espo/Core/Utils/Client/DevModeJsFileListProvider.php b/application/Espo/Core/Utils/Client/DevModeJsFileListProvider.php new file mode 100644 index 0000000000..f383177875 --- /dev/null +++ b/application/Espo/Core/Utils/Client/DevModeJsFileListProvider.php @@ -0,0 +1,91 @@ +fileManager = $fileManager; + } + + /** + * @return string[] + */ + public function get(): array + { + $list = []; + + $items = json_decode($this->fileManager->getContents(self::LIBS_FILE)); + + foreach ($items as $item) { + if (!($item->bundle ?? false)) { + continue; + } + + $files = $item->files ?? null; + + if ($files !== null) { + $list = array_merge( + $list, + $this->getLibFileListFromItems($files) + ); + + continue; + } + + $list[] = $item->src; + } + + return $list; + } + + private function getLibFileListFromItems(array $items): array + { + $list = []; + + foreach ($items as $item) { + $list[] = $item->src; + } + + return $list; + } +} diff --git a/application/Espo/Core/Utils/ClientManager.php b/application/Espo/Core/Utils/ClientManager.php index acef1a9706..65fecce178 100644 --- a/application/Espo/Core/Utils/ClientManager.php +++ b/application/Espo/Core/Utils/ClientManager.php @@ -31,6 +31,7 @@ namespace Espo\Core\Utils; use Espo\Core\{ Utils\File\Manager as FileManager, + Utils\Client\DevModeJsFileListProvider, }; /** @@ -52,20 +53,22 @@ class ClientManager private $basePath = ''; - private const LIBS_FILE = 'frontend/libs.json'; - private $libsConfigPath = 'client/cfg/libs.json'; + private $devModeJsFileListProvider; + public function __construct( Config $config, ThemeManager $themeManager, Metadata $metadata, - FileManager $fileManager + FileManager $fileManager, + DevModeJsFileListProvider $devModeJsFileListProvider ) { $this->config = $config; $this->themeManager = $themeManager; $this->metadata = $metadata; $this->fileManager = $fileManager; + $this->devModeJsFileListProvider = $devModeJsFileListProvider; } public function setBasePath(string $basePath): void @@ -220,37 +223,6 @@ class ClientManager */ private function getDeveloperModeBundleLibFileList(): array { - $list = []; - - $items = json_decode($this->fileManager->getContents(self::LIBS_FILE)); - - foreach ($items as $item) { - if (!($item->bundle ?? false)) { - continue; - } - - $files = $item->files ?? null; - - if ($files !== null) { - $list = array_merge($list, $this->getLibFileListFromItems($files)); - - continue; - } - - $list[] = $item->src; - } - - return $list; - } - - private function getLibFileListFromItems(array $items): array - { - $list = []; - - foreach ($items as $item) { - $list[] = $item->src; - } - - return $list; + return $this->devModeJsFileListProvider->get(); } } diff --git a/install/core/Utils.php b/install/core/Utils.php index 7dac7e94aa..2f2f831770 100644 --- a/install/core/Utils.php +++ b/install/core/Utils.php @@ -31,7 +31,7 @@ class Utils { static public $actionPath = 'install/core/actions'; - static public function checkActionExists($actionName) + static public function checkActionExists(string $actionName): bool { return in_array($actionName, [ 'saveSettings', @@ -49,9 +49,7 @@ class Utils 'step2', 'step3', 'step4', - 'step5' + 'step5', ]); - - return false; } } diff --git a/install/core/tpl/index.tpl b/install/core/tpl/index.tpl index be00b24cf4..1a9cbb09ca 100644 --- a/install/core/tpl/index.tpl +++ b/install/core/tpl/index.tpl @@ -6,14 +6,22 @@ + {if $isBuild} + {else} + {foreach from=$libFileList item=file} + + {/foreach} + {/if} + +
@@ -23,6 +31,7 @@
+ diff --git a/install/index.php b/install/index.php index 45ca59f7b5..b858cd48d9 100644 --- a/install/index.php +++ b/install/index.php @@ -31,9 +31,11 @@ if (session_status() !== \PHP_SESSION_ACTIVE) { session_start(); } -if (file_exists('../bootstrap.php')) { - require_once('../bootstrap.php'); -} +require_once('../bootstrap.php'); + +use Espo\Core\Utils\Util; +use Espo\Core\Utils\Client\DevModeJsFileListProvider; +use Espo\Core\Utils\File\Manager as FileManager; if (!isset($postData)) { require_once('core/PostData.php'); @@ -43,7 +45,7 @@ if (!isset($postData)) { $allPostData = $postData->getAll(); -//action +// action $action = (!empty($allPostData['action']))? $allPostData['action'] : 'main'; require_once('core/Utils.php'); @@ -53,12 +55,19 @@ if (!Utils::checkActionExists($action)) { } // temp save all settings -$ignoredFields = array('installProcess', 'dbName', 'hostName', 'dbUserName', 'dbUserPass', 'dbDriver'); +$ignoredFields = [ + 'installProcess', + 'dbName', + 'hostName', + 'dbUserName', + 'dbUserPass', + 'dbDriver', +]; if (!empty($allPostData)) { foreach ($allPostData as $key => $val) { if (!in_array($key, $ignoredFields)) { - $_SESSION['install'][$key] = trim($val); + $_SESSION['install'][$key] = trim($val); } } } @@ -69,8 +78,10 @@ $userLang = (!empty($_SESSION['install']['user-lang']))? $_SESSION['install']['u require_once 'core/Language.php'; $language = new Language(); + $langs = $language->get($userLang); -$sanitizedLangs = \Espo\Core\Utils\Util::sanitizeHtml($langs); + +$sanitizedLangs = Util::sanitizeHtml($langs); //END: get user selected language $config = include('core/config.php'); @@ -99,8 +110,8 @@ if (!$systemHelper->initWritable()) { $message = $sanitizedLangs['messages']['Bad init Permission']; $message = str_replace('{*}', $dir, $message); - $message = str_replace('{C}', $systemHelper->getPermissionCommands(array($dir, ''), '775'), $message); - $message = str_replace('{CSU}', $systemHelper->getPermissionCommands(array($dir, ''), '775', true), $message); + $message = str_replace('{C}', $systemHelper->getPermissionCommands([$dir, ''], '775'), $message); + $message = str_replace('{CSU}', $systemHelper->getPermissionCommands([$dir, ''], '775', true), $message); die($message . "\n"); } @@ -116,7 +127,7 @@ $installer = new Installer(); // check if app was installed if ($installer->isInstalled() && !isset($_SESSION['install']['installProcess'])) { if (isset($_SESSION['install']['redirected']) && $_SESSION['install']['redirected']) { - die('The installation is disabled. It can be enabled in config files.'); + die('The installation is disabled. It can be enabled in config files.'); } $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; @@ -183,14 +194,20 @@ $smarty->assign('config', $config); $smarty->assign('installerConfig', $installer->getInstallerConfigData()); if (Utils::checkActionExists($action)) { - include $actionFile; + include $actionFile; } if (!empty($actionFile) && file_exists('install/core/tpl/' . $tplName)) { /* check if EspoCRM is built */ $isBuilt = file_exists('client/espo.min.js'); - $smarty->assign('isBuilt', $isBuilt); + $smarty->assign('isBuilt', true); + + if (!$isBuilt) { + $libListProvider = new DevModeJsFileListProvider(new FileManager()); + + $smarty->assign('libFileList', $libListProvider->get()); + } $smarty->display('index.tpl'); }