installer libs

This commit is contained in:
Yuri Kuznetsov
2021-06-24 11:34:13 +03:00
parent b37a458a1d
commit 2dc0a6bc95
5 changed files with 138 additions and 51 deletions

View File

@@ -0,0 +1,91 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2021 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
use Espo\Core\{
Utils\File\Manager as FileManager,
};
/**
* @internal Also used by the installer w/o DI.
*/
class DevModeJsFileListProvider
{
private $fileManager;
private const LIBS_FILE = 'frontend/libs.json';
public function __construct(FileManager $fileManager)
{
$this->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;
}
}

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -6,14 +6,22 @@
<meta content="utf-8" http-equiv="encoding">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
{if $isBuild}
<script type="text/javascript" src="../client/espo.min.js"></script>
{else}
{foreach from=$libFileList item=file}
<script type="text/javascript" src="../{$file}"></script>
{/foreach}
{/if}
<script type="text/javascript" src="js/install.js"></script>
<link href="../client/css/espo/hazyblue.css" rel="stylesheet">
<link href="css/install.css" rel="stylesheet">
<link rel="shortcut icon" href="../client/img/favicon.ico" type="image/x-icon">
</head>
<body class='install-body'>
<a href="index.tpl"></a>
<header id="header"></header>
<div class="container content">
<div class="col-md-offset-1 col-md-10">
@@ -23,6 +31,7 @@
</div>
</div>
</div>
<footer class="container">{include file="footer.tpl"}</footer>
</body>
</html>

View File

@@ -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');
}