Initial commit
This commit is contained in:
173
application/Espo/Core/Console/Commands/AclCheck.php
Normal file
173
application/Espo/Core/Console/Commands/AclCheck.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Core\AclManager;
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Container;
|
||||
use Espo\Core\Portal\Application as PortalApplication;
|
||||
use Espo\Core\Acl\Table;
|
||||
|
||||
/**
|
||||
* Checks access for websocket topic subscription. Prints `true` if access allowed.
|
||||
*
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class AclCheck implements Command
|
||||
{
|
||||
public function __construct(private Container $container)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$userId = $params->getOption('userId');
|
||||
$scope = $params->getOption('scope');
|
||||
$id = $params->getOption('id');
|
||||
/** @var Table::ACTION_*|null $action */
|
||||
$action = $params->getOption('action');
|
||||
|
||||
$io->setExitStatus(1);
|
||||
|
||||
if (!$userId || !$scope) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($params->hasOption('id') && !$id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entityManager = $this->container->getByClass(EntityManager::class);
|
||||
|
||||
$user = $entityManager->getRDBRepositoryByClass(User::class)->getById($userId);
|
||||
|
||||
if (!$user) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user->isPortal()) {
|
||||
$this->processPortal(
|
||||
io: $io,
|
||||
userId: $userId,
|
||||
scope: $scope,
|
||||
action: $action,
|
||||
id: $id,
|
||||
user: $user,
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->check($user, $scope, $id, $action, $this->container)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$io->setExitStatus(0);
|
||||
$io->write('true');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Table::ACTION_*|null $action
|
||||
* @noinspection PhpDocSignatureInspection
|
||||
*/
|
||||
private function check(
|
||||
User $user,
|
||||
string $scope,
|
||||
?string $id,
|
||||
?string $action,
|
||||
Container $container
|
||||
): bool {
|
||||
|
||||
if (!$id) {
|
||||
$aclManager = $container->getByClass(AclManager::class);
|
||||
|
||||
return $aclManager->check($user, $scope, $action);
|
||||
}
|
||||
|
||||
$entityManager = $container->getByClass(EntityManager::class);
|
||||
|
||||
$entity = $entityManager->getEntityById($scope, $id);
|
||||
|
||||
if (!$entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$aclManager = $container->getByClass(AclManager::class);
|
||||
|
||||
return $aclManager->check($user, $entity, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Table::ACTION_*|null $action
|
||||
* @noinspection PhpDocSignatureInspection
|
||||
*/
|
||||
private function processPortal(
|
||||
IO $io,
|
||||
string $userId,
|
||||
string $scope,
|
||||
?string $action,
|
||||
?string $id,
|
||||
User $user,
|
||||
): void {
|
||||
|
||||
$portalIds = $user->getLinkMultipleIdList('portals');
|
||||
|
||||
foreach ($portalIds as $portalId) {
|
||||
try {
|
||||
$application = new PortalApplication($portalId);
|
||||
} catch (Forbidden|NotFound) {
|
||||
return;
|
||||
}
|
||||
|
||||
$containerPortal = $application->getContainer();
|
||||
$entityManager = $containerPortal->getByClass(EntityManager::class);
|
||||
|
||||
$user = $entityManager->getRDBRepositoryByClass(User::class)->getById($userId);
|
||||
|
||||
if (!$user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->check($user, $scope, $id, $action, $containerPortal);
|
||||
|
||||
if (!$result) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$io->setExitStatus(0);
|
||||
$io->write('true');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
100
application/Espo/Core/Console/Commands/AppInfo.php
Normal file
100
application/Espo/Core/Console/Commands/AppInfo.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class AppInfo implements Command
|
||||
{
|
||||
public function __construct(private InjectableFactory $injectableFactory, private FileManager $fileManager)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
/** @var string[] $fileList */
|
||||
$fileList = $this->fileManager->getFileList('application/Espo/Classes/AppInfo');
|
||||
|
||||
$typeList = array_map(
|
||||
function ($item): string {
|
||||
return lcfirst(substr($item, 0, -4));
|
||||
},
|
||||
$fileList
|
||||
);
|
||||
|
||||
foreach ($typeList as $type) {
|
||||
if ($params->hasFlag(Util::camelCaseToHyphen($type))) {
|
||||
$this->processType($io, $type, $params);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($params->getFlagList()) === 0) {
|
||||
$io->writeLine("");
|
||||
$io->writeLine("Available flags:");
|
||||
$io->writeLine("");
|
||||
|
||||
foreach ($typeList as $type) {
|
||||
$io->writeLine(' --' . Util::camelCaseToHyphen($type));
|
||||
}
|
||||
|
||||
$io->writeLine("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("Not supported flag specified.");
|
||||
}
|
||||
|
||||
protected function processType(IO $io, string $type, Params $params): void
|
||||
{
|
||||
/** @var class-string $className */
|
||||
$className = 'Espo\\Classes\\AppInfo\\' . ucfirst($type);
|
||||
|
||||
$obj = $this->injectableFactory->create($className);
|
||||
|
||||
// @todo Use inteface.
|
||||
assert(method_exists($obj, 'process'));
|
||||
|
||||
$result = $obj->process($params);
|
||||
|
||||
$io->writeLine('');
|
||||
$io->write($result);
|
||||
$io->writeLine("");
|
||||
}
|
||||
}
|
||||
93
application/Espo/Core/Console/Commands/AuthTokenCheck.php
Normal file
93
application/Espo/Core/Console/Commands/AuthTokenCheck.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Entities\User;
|
||||
use Espo\Core\Authentication\AuthToken\Manager as AuthTokenManager;
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class AuthTokenCheck implements Command
|
||||
{
|
||||
public function __construct(private EntityManager $entityManager, private AuthTokenManager $authTokenManager)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$io->setExitStatus(1);
|
||||
|
||||
$token = $params->getArgument(0);
|
||||
$userId = $params->getArgument(1);
|
||||
|
||||
if (!$token) {
|
||||
return;
|
||||
}
|
||||
|
||||
$authToken = $this->authTokenManager->get($token);
|
||||
|
||||
if (!$authToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$authToken->isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$authToken->getUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($userId && $authToken->getUserId() !== $userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $this->entityManager
|
||||
->getRDBRepositoryByClass(User::class)
|
||||
->select(Attribute::ID)
|
||||
->where([
|
||||
Attribute::ID => $authToken->getUserId(),
|
||||
User::ATTR_IS_ACTIVE => true,
|
||||
])
|
||||
->findOne();
|
||||
|
||||
if (!$user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$io->write($user->getId());
|
||||
$io->setExitStatus(0);
|
||||
}
|
||||
}
|
||||
51
application/Espo/Core/Console/Commands/Base.php
Normal file
51
application/Espo/Core/Console/Commands/Base.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Container;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @todo Remove in v10.0.
|
||||
*/
|
||||
abstract class Base
|
||||
{
|
||||
private Container $container;
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getContainer(): Container
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
}
|
||||
55
application/Espo/Core/Console/Commands/ClearCache.php
Normal file
55
application/Espo/Core/Console/Commands/ClearCache.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class ClearCache implements Command
|
||||
{
|
||||
public function __construct(private DataManager $dataManager)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$this->dataManager->clearCache();
|
||||
|
||||
$io->writeLine("Cache has been cleared.");
|
||||
}
|
||||
}
|
||||
36
application/Espo/Core/Console/Commands/Command.php
Normal file
36
application/Espo/Core/Console/Commands/Command.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
interface Command
|
||||
{}
|
||||
152
application/Espo/Core/Console/Commands/EntityUtil.php
Normal file
152
application/Espo/Core/Console/Commands/EntityUtil.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
|
||||
use Espo\Tools\EntityManager\Rename\Renamer;
|
||||
use Espo\Tools\EntityManager\Rename\FailReason as RenameFailReason;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class EntityUtil implements Command
|
||||
{
|
||||
public function __construct(private Renamer $renamer)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$subCommand = $params->getArgument(0);
|
||||
|
||||
if (!$subCommand) {
|
||||
$io->writeLine("No sub-command specified.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($subCommand === 'rename') {
|
||||
$this->runRename($params, $io);
|
||||
}
|
||||
}
|
||||
|
||||
private function runRename(Params $params, IO $io): void
|
||||
{
|
||||
$entityType = $params->getOption('entityType');
|
||||
$newName = $params->getOption('newName');
|
||||
|
||||
if (!$entityType) {
|
||||
$io->writeLine("No --entity-type option specified.");
|
||||
}
|
||||
|
||||
if (!$newName) {
|
||||
$io->writeLine("No --new-name option specified.");
|
||||
}
|
||||
|
||||
if (!$entityType || !$newName) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->renamer->process($entityType, $newName, $io);
|
||||
|
||||
$io->writeLine("");
|
||||
|
||||
if (!$result->isFail()) {
|
||||
$io->writeLine("Finished.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->setExitStatus(1);
|
||||
$io->write("Failed. ");
|
||||
|
||||
$failReason = $result->getFailReason();
|
||||
|
||||
if ($failReason === RenameFailReason::NAME_BAD) {
|
||||
$io->writeLine("Name is bad.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::NAME_NOT_ALLOWED) {
|
||||
$io->writeLine("Name is not allowed.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::NAME_TOO_LONG) {
|
||||
$io->writeLine("Name is too long.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::NAME_TOO_SHORT) {
|
||||
$io->writeLine("Name is too short.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::NAME_USED) {
|
||||
$io->writeLine("Name is already used.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::DOES_NOT_EXIST) {
|
||||
$io->writeLine("Entity type `$entityType` does not exist.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::NOT_CUSTOM) {
|
||||
$io->writeLine("Entity type `$entityType` is not custom, hence can't be renamed.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::ENV_NOT_SUPPORTED) {
|
||||
$io->writeLine("Environment is not supported.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::TABLE_EXISTS) {
|
||||
$io->writeLine("Table already exists.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($failReason === RenameFailReason::ERROR) {
|
||||
$io->writeLine("Error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
285
application/Espo/Core/Console/Commands/Extension.php
Normal file
285
application/Espo/Core/Console/Commands/Extension.php
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Entities\Extension as ExtensionEntity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Core\Upgrades\ExtensionManager;
|
||||
use Espo\Core\Container;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class Extension implements Command
|
||||
{
|
||||
public function __construct(
|
||||
private Container $container,
|
||||
private EntityManager $entityManager,
|
||||
private FileManager $fileManager
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
if ($params->hasFlag('l') || $params->hasFlag('list')) {
|
||||
$this->printList($io);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($params->hasFlag('u')) {
|
||||
$name = $params->getOption('name');
|
||||
$id = $params->getOption('id');
|
||||
|
||||
if (!$name && !$id) {
|
||||
$io->writeLine("Can't uninstall. Specify --name=\"Extension Name\".");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->runUninstall($params, $io);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$file = $params->getOption('file');
|
||||
|
||||
if (!$file) {
|
||||
$io->writeLine("");
|
||||
$io->writeLine("Install extension:");
|
||||
$io->writeLine("");
|
||||
$io->writeLine(" bin/command extension --file=\"path/to/package.zip\"");
|
||||
$io->writeLine("");
|
||||
|
||||
$io->writeLine("Uninstall extension:");
|
||||
$io->writeLine("");
|
||||
$io->writeLine(" bin/command extension -u --name=\"Extension Name\"");
|
||||
$io->writeLine("");
|
||||
|
||||
$io->writeLine("List all extensions:");
|
||||
$io->writeLine("");
|
||||
$io->writeLine(" bin/command extension --list");
|
||||
$io->writeLine("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->runInstall($file, $io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function runInstall(string $file, IO $io): void
|
||||
{
|
||||
$manager = $this->createExtensionManager();
|
||||
|
||||
if (!$this->fileManager->isFile($file)) {
|
||||
$io->writeLine("File does not exist.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fileData = $this->fileManager->getContents($file);
|
||||
|
||||
$fileDataEncoded = 'data:application/zip;base64,' . base64_encode($fileData);
|
||||
|
||||
try {
|
||||
$id = $manager->upload($fileDataEncoded);
|
||||
} catch (Throwable $e) {
|
||||
$io->writeLine($e->getMessage());
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$manifest = $manager->getManifestById($id);
|
||||
|
||||
$name = $manifest['name'] ?? null;
|
||||
$version = $manifest['version'] ?? null;
|
||||
|
||||
if (!$name) {
|
||||
$io->writeLine("Can't install. Bad manifest.json file.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->write("Installing... Do not close the terminal. This may take a while...");
|
||||
|
||||
try {
|
||||
$manager->install(['id' => $id]);
|
||||
} catch (Throwable $e) {
|
||||
$io->writeLine("");
|
||||
$io->writeLine($e->getMessage());
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("");
|
||||
$io->writeLine("Extension '$name' v$version is installed.\nExtension ID: '$id'.");
|
||||
}
|
||||
|
||||
protected function runUninstall(Params $params, IO $io): void
|
||||
{
|
||||
$id = $params->getOption('id');
|
||||
$name = $params->getOption('name');
|
||||
$toKeep = $params->hasFlag('k');
|
||||
|
||||
if ($id) {
|
||||
$record = $this->entityManager
|
||||
->getRDBRepository(ExtensionEntity::ENTITY_TYPE)
|
||||
->where([
|
||||
Attribute::ID => $id,
|
||||
'isInstalled' => true,
|
||||
])
|
||||
->findOne();
|
||||
|
||||
if (!$record) {
|
||||
$io->writeLine("Extension with ID '$id' is not installed.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $record->get(Field::NAME);
|
||||
} else {
|
||||
if (!$name) {
|
||||
$io->writeLine("Can't uninstall. No --name or --id specified.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$record = $this->entityManager
|
||||
->getRDBRepository(ExtensionEntity::ENTITY_TYPE)
|
||||
->where([
|
||||
'name' => $name,
|
||||
'isInstalled' => true,
|
||||
])
|
||||
->findOne();
|
||||
|
||||
if (!$record) {
|
||||
$io->writeLine("Extension '$name' is not installed.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $record->getId();
|
||||
}
|
||||
|
||||
$manager = $this->createExtensionManager();
|
||||
|
||||
$io->write("Uninstalling... Do not close the terminal. This may take a while...");
|
||||
|
||||
try {
|
||||
$manager->uninstall(['id' => $id]);
|
||||
} catch (Throwable $e) {
|
||||
$io->writeLine("");
|
||||
$io->writeLine($e->getMessage());
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("");
|
||||
|
||||
if ($toKeep) {
|
||||
$io->writeLine("Extension '$name' is uninstalled.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$manager->delete(['id' => $id]);
|
||||
} catch (Throwable $e) {
|
||||
$io->writeLine($e->getMessage());
|
||||
$io->writeLine("Extension '$name' is uninstalled but could not be deleted.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("Extension '$name' is uninstalled and deleted.");
|
||||
}
|
||||
|
||||
private function printList(IO $io): void
|
||||
{
|
||||
$collection = $this->entityManager
|
||||
->getRDBRepositoryByClass(ExtensionEntity::class)
|
||||
->find();
|
||||
|
||||
$count = count($collection);
|
||||
|
||||
/** @noinspection PhpIfWithCommonPartsInspection */
|
||||
if ($count === 0) {
|
||||
$io->writeLine("");
|
||||
$io->writeLine("No extensions.");
|
||||
$io->writeLine("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("");
|
||||
$io->writeLine("Extensions:");
|
||||
$io->writeLine("");
|
||||
|
||||
foreach ($collection as $extension) {
|
||||
$isInstalled = $extension->isInstalled();
|
||||
|
||||
$io->writeLine(' Name: ' . $extension->getName());
|
||||
$io->writeLine(' ID: ' . $extension->getId());
|
||||
$io->writeLine(' Version: ' . $extension->getVersion());
|
||||
$io->writeLine(' Installed: ' . ($isInstalled ? 'yes' : 'no'));
|
||||
|
||||
$io->writeLine("");
|
||||
}
|
||||
}
|
||||
|
||||
private function createExtensionManager(): ExtensionManager
|
||||
{
|
||||
return new ExtensionManager($this->container);
|
||||
}
|
||||
}
|
||||
83
application/Espo/Core/Console/Commands/Help.php
Normal file
83
application/Espo/Core/Console/Commands/Help.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class Help implements Command
|
||||
{
|
||||
public function __construct(private Metadata $metadata)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
/** @var string[] $fullCommandList */
|
||||
$fullCommandList = array_keys($this->metadata->get(['app', 'consoleCommands']) ?? []);
|
||||
|
||||
$commandList = array_filter(
|
||||
$fullCommandList,
|
||||
function ($item): bool {
|
||||
return (bool) $this->metadata->get(['app', 'consoleCommands', $item, 'listed']);
|
||||
}
|
||||
);
|
||||
|
||||
sort($commandList);
|
||||
|
||||
$io->writeLine("");
|
||||
$io->writeLine("Available commands:");
|
||||
$io->writeLine("");
|
||||
|
||||
foreach ($commandList as $item) {
|
||||
$io->writeLine(
|
||||
' ' . Util::camelCaseToHyphen($item)
|
||||
);
|
||||
}
|
||||
|
||||
$io->writeLine("");
|
||||
|
||||
$io->writeLine("Usage:");
|
||||
$io->writeLine("");
|
||||
$io->writeLine(" bin/command [command-name] [some-argument] [--some-option=value] [--some-flag]");
|
||||
|
||||
$io->writeLine("");
|
||||
|
||||
$io->writeLine("Documentation: https://docs.espocrm.com/administration/commands/");
|
||||
|
||||
$io->writeLine("");
|
||||
}
|
||||
}
|
||||
54
application/Espo/Core/Console/Commands/Migrate.php
Normal file
54
application/Espo/Core/Console/Commands/Migrate.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Upgrades\Migration\Runner;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class Migrate implements Command
|
||||
{
|
||||
public function __construct(
|
||||
private Runner $runner
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$this->runner->run($io);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Upgrades\Migration\AfterUpgradeRunner;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class MigrationVersionStep implements Command
|
||||
{
|
||||
public function __construct(
|
||||
private AfterUpgradeRunner $afterUpgradeRunner
|
||||
) {}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$step = $params->getOption('step');
|
||||
|
||||
if (!$step) {
|
||||
throw new RuntimeException("No step parameter.");
|
||||
}
|
||||
|
||||
$this->afterUpgradeRunner->run($step);
|
||||
|
||||
$io->writeLine("Done.");
|
||||
$io->setExitStatus(0);
|
||||
}
|
||||
}
|
||||
74
application/Espo/Core/Console/Commands/Rebuild.php
Normal file
74
application/Espo/Core/Console/Commands/Rebuild.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\Database\Schema\RebuildMode;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class Rebuild implements Command
|
||||
{
|
||||
public function __construct(private DataManager $dataManager)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$this->dataManager->rebuild();
|
||||
|
||||
if ($params->hasFlag('hard')) {
|
||||
if (!$params->hasFlag('y')) {
|
||||
$message =
|
||||
"Are you sure you want to run a hard DB rebuild? It will drop unused columns, " .
|
||||
"decrease exceeding column lengths. It may take some time to process.\nType [Y] to proceed.";
|
||||
|
||||
$io->writeLine($message);
|
||||
|
||||
$input = $io->readLine();
|
||||
|
||||
if (strtolower($input) !== 'y') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->dataManager->rebuildDatabase(null, RebuildMode::HARD);
|
||||
}
|
||||
|
||||
$io->writeLine("Rebuild has been done.");
|
||||
}
|
||||
}
|
||||
111
application/Espo/Core/Console/Commands/RunJob.php
Normal file
111
application/Espo/Core/Console/Commands/RunJob.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Job\JobManager;
|
||||
use Espo\Core\Job\Job\Status;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Entities\Job;
|
||||
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class RunJob implements Command
|
||||
{
|
||||
public function __construct(private JobManager $jobManager, private EntityManager $entityManager)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$options = $params->getOptions();
|
||||
$argumentList = $params->getArgumentList();
|
||||
|
||||
$jobName = $options['job'] ?? null;
|
||||
$targetId = $options['targetId'] ?? null;
|
||||
$targetType = $options['targetType'] ?? null;
|
||||
|
||||
if (!$jobName && count($argumentList)) {
|
||||
$jobName = $argumentList[0];
|
||||
}
|
||||
|
||||
if (!$jobName) {
|
||||
$io->writeLine("");
|
||||
$io->writeLine("A job name must be specified:");
|
||||
$io->writeLine("");
|
||||
|
||||
$io->writeLine(" bin/command run-job [JobName]");
|
||||
$io->writeLine("");
|
||||
|
||||
$io->writeLine("To print all available jobs, run:");
|
||||
$io->writeLine("");
|
||||
$io->writeLine(" bin/command app-info --jobs");
|
||||
$io->writeLine("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$jobName = ucfirst(Util::hyphenToCamelCase($jobName));
|
||||
|
||||
$entityManager = $this->entityManager;
|
||||
|
||||
/** @var Job $job */
|
||||
$job = $entityManager->createEntity(Job::ENTITY_TYPE, [
|
||||
'name' => $jobName,
|
||||
'job' => $jobName,
|
||||
'targetType' => $targetType,
|
||||
'targetId' => $targetId,
|
||||
'attempts' => 0,
|
||||
'status' => Status::READY,
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->jobManager->runJob($job);
|
||||
} catch (Throwable $e) {
|
||||
$message = "Error: Job '$jobName' failed to execute.";
|
||||
|
||||
if ($e->getMessage()) {
|
||||
$message .= ' ' . $e->getMessage();
|
||||
}
|
||||
|
||||
$io->writeLine($message);
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("Job '$jobName' has been executed.");
|
||||
}
|
||||
}
|
||||
104
application/Espo/Core/Console/Commands/SetPassword.php
Normal file
104
application/Espo/Core/Console/Commands/SetPassword.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Entities\User;
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\Core\Utils\PasswordHash;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class SetPassword implements Command
|
||||
{
|
||||
public function __construct(private EntityManager $entityManager, private PasswordHash $passwordHash)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$userName = $params->getArgument(0);
|
||||
|
||||
if (!$userName) {
|
||||
$io->writeLine("Username must be specified as the first argument.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$em = $this->entityManager;
|
||||
|
||||
$user = $em->getRDBRepositoryByClass(User::class)
|
||||
->where(['userName' => $userName])
|
||||
->findOne();
|
||||
|
||||
if (!$user) {
|
||||
$io->writeLine("User '$userName' not found.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$userType = $user->getType();
|
||||
|
||||
$allowedTypes = [
|
||||
User::TYPE_ADMIN,
|
||||
User::TYPE_SUPER_ADMIN,
|
||||
User::TYPE_PORTAL,
|
||||
User::TYPE_REGULAR,
|
||||
];
|
||||
|
||||
if (!in_array($userType, $allowedTypes)) {
|
||||
$io->writeLine("Can't set password for a user of the type '$userType'.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("Enter a new password:");
|
||||
|
||||
$password = $io->readSecretLine();
|
||||
|
||||
if (!$password) {
|
||||
$io->writeLine("Password cannot be empty.");
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$user->set('password', $this->passwordHash->hash($password));
|
||||
|
||||
$em->saveEntity($user);
|
||||
|
||||
$io->writeLine("Password for user '$userName' has been changed.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\DataManager;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class UpdateAppTimestamp implements Command
|
||||
{
|
||||
public function __construct(private DataManager $dataManager)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$this->dataManager->updateAppTimestamp();
|
||||
|
||||
$io->writeLine("App timestamp is updated.");
|
||||
}
|
||||
}
|
||||
533
application/Espo/Core/Console/Commands/Upgrade.php
Normal file
533
application/Espo/Core/Console/Commands/Upgrade.php
Normal file
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Application;
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Upgrades\UpgradeManager;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use stdClass;
|
||||
|
||||
use const CURLOPT_FILE;
|
||||
use const CURLOPT_RETURNTRANSFER;
|
||||
use const CURLOPT_SSL_VERIFYPEER;
|
||||
use const CURLOPT_TIMEOUT;
|
||||
use const CURLOPT_URL;
|
||||
use const FILTER_VALIDATE_URL;
|
||||
use const STDOUT;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class Upgrade implements Command
|
||||
{
|
||||
private ?UpgradeManager $upgradeManager = null;
|
||||
|
||||
/** @var string[] */
|
||||
private $upgradeStepList = [
|
||||
'copyBefore',
|
||||
'rebuild',
|
||||
'beforeUpgradeScript',
|
||||
'rebuild',
|
||||
'copy',
|
||||
'rebuild',
|
||||
'copyAfter',
|
||||
'rebuild',
|
||||
'afterUpgradeScript',
|
||||
'rebuild',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
private $upgradeStepLabels = [
|
||||
'init' => 'Initialization',
|
||||
'copyBefore' => 'Copying before upgrade files',
|
||||
'rebuild' => 'Rebuilding',
|
||||
'beforeUpgradeScript' => 'Before upgrade script execution',
|
||||
'copy' => 'Copying files',
|
||||
'copyAfter' => 'Copying after upgrade files',
|
||||
'afterUpgradeScript' => 'After upgrade script execution',
|
||||
'finalize' => 'Finalization',
|
||||
'revert' => 'Reverting',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private FileManager $fileManager,
|
||||
private Config $config,
|
||||
private Log $log
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$options = $params->getOptions();
|
||||
$flagList = $params->getFlagList();
|
||||
$argumentList = $params->getArgumentList();
|
||||
|
||||
$upgradeParams = $this->normalizeParams($options, $flagList, $argumentList);
|
||||
|
||||
$fromVersion = $this->config->get('version');
|
||||
$toVersion = $upgradeParams->toVersion ?? null;
|
||||
|
||||
$versionInfo = $this->getVersionInfo($toVersion);
|
||||
|
||||
$nextVersion = $versionInfo->nextVersion ?? null;
|
||||
$lastVersion = $versionInfo->lastVersion ?? null;
|
||||
|
||||
$packageFile = $this->getPackageFile($upgradeParams, $versionInfo);
|
||||
|
||||
if (!$packageFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($upgradeParams->localMode) {
|
||||
$upgradeId = $this->upload($packageFile);
|
||||
|
||||
$manifest = $this->getUpgradeManager()->getManifestById($upgradeId);
|
||||
|
||||
$nextVersion = $manifest['version'];
|
||||
}
|
||||
|
||||
fwrite(STDOUT, "Current version is $fromVersion.\n");
|
||||
|
||||
if (!$upgradeParams->skipConfirmation) {
|
||||
fwrite(STDOUT, "EspoCRM will be upgraded to version $nextVersion now. Enter [Y] to continue.\n");
|
||||
|
||||
if (!$this->confirm()) {
|
||||
echo "Upgrade canceled.\n";
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(STDOUT, "This may take a while. Do not close the terminal.\n");
|
||||
|
||||
if (filter_var($packageFile, FILTER_VALIDATE_URL)) {
|
||||
fwrite(STDOUT, "Downloading...");
|
||||
|
||||
$packageFile = $this->downloadFile($packageFile);
|
||||
|
||||
fwrite(STDOUT, "\n");
|
||||
|
||||
if (!$packageFile) {
|
||||
fwrite(STDOUT, "Error: Unable to download upgrade package.\n");
|
||||
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$upgradeId = $upgradeId ?? $this->upload($packageFile);
|
||||
|
||||
fwrite(STDOUT, "Upgrading...");
|
||||
|
||||
try {
|
||||
$this->runUpgradeProcess($upgradeId, $upgradeParams);
|
||||
} catch (Throwable $e) {
|
||||
$this->displayStep('revert');
|
||||
$errorMessage = $e->getMessage();
|
||||
}
|
||||
|
||||
fwrite(STDOUT, "\n");
|
||||
|
||||
if (!$upgradeParams->keepPackageFile) {
|
||||
$this->fileManager->unlink($packageFile);
|
||||
}
|
||||
|
||||
if (isset($errorMessage)) {
|
||||
$errorMessage = !empty($errorMessage) ? $errorMessage : "Error: An unexpected error occurred.";
|
||||
|
||||
fwrite(STDOUT, $errorMessage . "\n");
|
||||
|
||||
$io->setExitStatus(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$currentVersion = $this->getCurrentVersion();
|
||||
|
||||
fwrite(STDOUT, "Upgrade is complete. Current version is $currentVersion.\n");
|
||||
|
||||
if ($lastVersion && $lastVersion !== $currentVersion && $fromVersion !== $currentVersion) {
|
||||
fwrite(STDOUT, "Newer version is available. Run command again to upgrade.\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($lastVersion && $lastVersion === $currentVersion) {
|
||||
fwrite(STDOUT, "You have the latest version.\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize params. Permitted options and flags and $arguments:
|
||||
* -y - without confirmation
|
||||
* -s - single process
|
||||
* --file="EspoCRM-upgrade.zip"
|
||||
* --step="beforeUpgradeScript"
|
||||
*
|
||||
* @param array<string, string> $options
|
||||
* @param string[] $flagList
|
||||
* @param string[] $argumentList
|
||||
* @return stdClass
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
*/
|
||||
private function normalizeParams(array $options, array $flagList, array $argumentList): object
|
||||
{
|
||||
$params = (object) [
|
||||
'localMode' => false,
|
||||
'skipConfirmation' => false,
|
||||
'singleProcess' => false,
|
||||
'keepPackageFile' => false,
|
||||
];
|
||||
|
||||
if (!empty($options['file'])) {
|
||||
$params->localMode = true;
|
||||
$params->file = $options['file'];
|
||||
$params->keepPackageFile = true;
|
||||
}
|
||||
|
||||
if (in_array('y', $flagList)) {
|
||||
$params->skipConfirmation = true;
|
||||
}
|
||||
|
||||
if (in_array('s', $flagList)) {
|
||||
$params->singleProcess = true;
|
||||
}
|
||||
|
||||
if (in_array('patch', $flagList)) {
|
||||
$currentVersion = $this->config->get('version');
|
||||
|
||||
if (preg_match('/^(.*)\.(.*)\..*$/', $currentVersion, $match)) {
|
||||
$options['toVersion'] = $match[1] . '.' . $match[2];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($options['step'])) {
|
||||
$params->step = $options['step'];
|
||||
}
|
||||
|
||||
if (!empty($options['toVersion'])) {
|
||||
$params->toVersion = $options['toVersion'];
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
private function getPackageFile(stdClass $params, ?stdClass $versionInfo): ?string
|
||||
{
|
||||
$packageFile = $params->file ?? null;
|
||||
|
||||
if (!$params->localMode) {
|
||||
if (empty($versionInfo)) {
|
||||
fwrite(STDOUT, "Error: Upgrade server is currently unavailable. Please try again later.\n");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($versionInfo->nextVersion)) {
|
||||
fwrite(STDOUT, "There are no available upgrades.\n");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($versionInfo->nextPackage)) {
|
||||
fwrite(STDOUT, "Error: Upgrade package is not found.\n");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $versionInfo->nextPackage;
|
||||
}
|
||||
|
||||
if (!$packageFile || !file_exists($packageFile)) {
|
||||
fwrite(STDOUT, "Error: Upgrade package is not found.\n");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $packageFile;
|
||||
}
|
||||
|
||||
private function upload(string $filePath): string
|
||||
{
|
||||
try {
|
||||
/** @var string $fileData */
|
||||
$fileData = file_get_contents($filePath);
|
||||
$fileData = 'data:application/zip;base64,' . base64_encode($fileData);
|
||||
|
||||
$upgradeId = $this->getUpgradeManager()->upload($fileData);
|
||||
} catch (Exception $e) {
|
||||
die("Error: " . $e->getMessage() . "\n");
|
||||
}
|
||||
|
||||
return $upgradeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function runUpgradeProcess(string $upgradeId, ?stdClass $params = null): void
|
||||
{
|
||||
$params = $params ?? (object) [];
|
||||
|
||||
$useSingleProcess = property_exists($params, 'singleProcess') ? $params->singleProcess : false;
|
||||
|
||||
$stepList = !empty($params->step) ? [$params->step] : $this->upgradeStepList;
|
||||
|
||||
array_unshift($stepList, 'init');
|
||||
$stepList[] = 'finalize';
|
||||
|
||||
if (!$useSingleProcess && $this->isShellEnabled()) {
|
||||
$this->runSteps($upgradeId, $stepList);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->runStepsInSingleProcess($upgradeId, $stepList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $stepList
|
||||
* @throws Error
|
||||
*/
|
||||
private function runStepsInSingleProcess(string $upgradeId, array $stepList): void
|
||||
{
|
||||
$this->log->debug('Installation process ['.$upgradeId.']: Single process mode.');
|
||||
|
||||
try {
|
||||
foreach ($stepList as $stepName) {
|
||||
$this->displayStep($stepName);
|
||||
|
||||
$upgradeManager = $this->getUpgradeManager(true);
|
||||
|
||||
$upgradeManager->runInstallStep($stepName, ['id' => $upgradeId]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
try {
|
||||
$this->log->error('Upgrade Error: ' . $e->getMessage());
|
||||
} catch (Throwable) {}
|
||||
|
||||
throw new Error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $stepList
|
||||
* @throws Error
|
||||
*/
|
||||
private function runSteps(string $upgradeId, array $stepList): void
|
||||
{
|
||||
$phpExecutablePath = $this->getPhpExecutablePath();
|
||||
|
||||
foreach ($stepList as $stepName) {
|
||||
$this->displayStep($stepName);
|
||||
|
||||
$command = $phpExecutablePath . " command.php upgrade-step --step=" . ucfirst($stepName) .
|
||||
" --id=" . $upgradeId;
|
||||
|
||||
/** @var string $shellResult */
|
||||
$shellResult = shell_exec($command);
|
||||
|
||||
if ($shellResult !== 'true') {
|
||||
try {
|
||||
$this->log->error('Upgrade Error: ' . $shellResult);
|
||||
} catch (Throwable) {}
|
||||
|
||||
throw new Error($shellResult ?: 'Unknown error on shell_exec.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function displayStep(string $stepName): void
|
||||
{
|
||||
$stepLabel = $this->upgradeStepLabels[$stepName] ?? "";
|
||||
|
||||
fwrite(STDOUT, "\n $stepLabel...");
|
||||
}
|
||||
|
||||
private function confirm(): bool
|
||||
{
|
||||
/** @var resource $fh */
|
||||
$fh = fopen('php://stdin', 'r');
|
||||
|
||||
$inputLine = trim(fgets($fh)); /** @phpstan-ignore-line */
|
||||
|
||||
fclose($fh);
|
||||
|
||||
if (strtolower($inputLine) !== 'y'){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getUpgradeManager(bool $reload = false): UpgradeManager
|
||||
{
|
||||
if (!$this->upgradeManager || $reload) {
|
||||
$app = new Application();
|
||||
|
||||
$app->setupSystemUser();
|
||||
|
||||
$this->upgradeManager = new UpgradeManager($app->getContainer());
|
||||
}
|
||||
|
||||
return $this->upgradeManager;
|
||||
}
|
||||
|
||||
private function getPhpExecutablePath(): string
|
||||
{
|
||||
$phpExecutablePath = $this->config->get('phpExecutablePath');
|
||||
|
||||
if (!$phpExecutablePath) {
|
||||
$phpExecutablePath = (new PhpExecutableFinder)->find();
|
||||
}
|
||||
|
||||
return $phpExecutablePath;
|
||||
}
|
||||
|
||||
private function getVersionInfo(?string $toVersion = null): ?stdClass
|
||||
{
|
||||
$url = 'https://s.espocrm.com/upgrade/next/';
|
||||
$url = $this->config->get('upgradeNextVersionUrl', $url);
|
||||
$url .= '?fromVersion=' . $this->config->get('version');
|
||||
|
||||
if ($toVersion) {
|
||||
$url .= '&toVersion=' . $toVersion;
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
try {
|
||||
$data = json_decode($result); /** @phpstan-ignore-line */
|
||||
} catch (Exception) { /** @phpstan-ignore-line */
|
||||
echo "Could not parse info about next version.\n";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
echo "Could not get info about next version.\n";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function downloadFile(string $url): ?string
|
||||
{
|
||||
$localFilePath = 'data/upload/upgrades/' . Util::generateId() . '.zip';
|
||||
|
||||
$this->fileManager->putContents($localFilePath, '');
|
||||
|
||||
if (is_file($url)) {
|
||||
copy($url, $localFilePath);
|
||||
} else {
|
||||
$options = [
|
||||
CURLOPT_FILE => fopen($localFilePath, 'w'),
|
||||
CURLOPT_TIMEOUT => 3600,
|
||||
CURLOPT_URL => $url,
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt_array($ch, $options);
|
||||
|
||||
curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
if (!$this->fileManager->isFile($localFilePath)) {
|
||||
echo "\nCould not download upgrade file.\n";
|
||||
|
||||
$this->fileManager->unlink($localFilePath);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = realpath($localFilePath);
|
||||
|
||||
assert($path !== false);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function isShellEnabled(): bool
|
||||
{
|
||||
if (
|
||||
!function_exists('exec') ||
|
||||
!is_callable('shell_exec') /** @phpstan-ignore-line */
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = shell_exec("echo test");
|
||||
|
||||
if (empty($result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getCurrentVersion(): ?string
|
||||
{
|
||||
$configData = include "data/config.php"; /** @phpstan-ignore-line */
|
||||
|
||||
if (!$configData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $configData['version'] ?? null;
|
||||
}
|
||||
}
|
||||
88
application/Espo/Core/Console/Commands/UpgradeStep.php
Normal file
88
application/Espo/Core/Console/Commands/UpgradeStep.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Application;
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Upgrades\UpgradeManager;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class UpgradeStep implements Command
|
||||
{
|
||||
public function __construct() {}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$options = $params->getOptions();
|
||||
|
||||
if (empty($options['step'])) {
|
||||
echo "Step is not specified.\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($options['id'])) {
|
||||
echo "Upgrade ID is not specified.\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$stepName = $options['step'];
|
||||
$upgradeId = $options['id'];
|
||||
|
||||
$this->runUpgradeStep($stepName, ['id' => $upgradeId]);
|
||||
|
||||
echo "true";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
private function runUpgradeStep(string $stepName, array $params): void
|
||||
{
|
||||
$app = new Application();
|
||||
|
||||
$app->setupSystemUser();
|
||||
|
||||
$upgradeManager = new UpgradeManager($app->getContainer());
|
||||
|
||||
try {
|
||||
$upgradeManager->runInstallStep($stepName, $params);
|
||||
} catch (Exception $e) {
|
||||
die("Error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
48
application/Espo/Core/Console/Commands/Version.php
Normal file
48
application/Espo/Core/Console/Commands/Version.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\Console\Command;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
class Version implements Command
|
||||
{
|
||||
public function __construct(private Config\SystemConfig $config)
|
||||
{}
|
||||
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$version = $this->config->getVersion();
|
||||
|
||||
$io->writeLine($version);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user