EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Skip cron in maintenance mode, cron:run command
Yurii35e8ab39c6ff
diff --git a/application/Espo/Classes/ConsoleCommands/CronRun.php b/application/Espo/Classes/ConsoleCommands/CronRun.phpnew file mode 100644index 0000000000..67f51ca51f--- /dev/null+++ b/application/Espo/Classes/ConsoleCommands/CronRun.php@@ -0,0 +1,70 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 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\Classes\ConsoleCommands;++use Espo\Core\Console\Command;+use Espo\Core\Console\Command\Params;+use Espo\Core\Console\IO;+use Espo\Core\Job\Exceptions\TooFrequentRun;+use Espo\Core\Job\JobManager;+use Espo\Core\Job\PrepareProcessor;+use Espo\Core\Utils\Config\SystemConfig;+use RuntimeException;++/**+ * @noinspection PhpUnused+ */+class CronRun implements Command+{+ public function __construct(+ private PrepareProcessor $prepareProcessor,+ private JobManager $jobManager,+ private SystemConfig $config,+ ) {}++ public function run(Params $params, IO $io): void+ {+ if (!$this->config->isCronEnabled()) {+ throw new RuntimeException("Cron cannot be run as 'cronDisabled' is set to true in the config.");+ }++ if (!$params->hasFlag('force') && $this->config->isMaintenanceMode()) {+ throw new RuntimeException("Cron cannot be run in maintenance mode. You can use --force flag.");+ }++ try {+ $this->prepareProcessor->process();+ } catch (TooFrequentRun $e) {+ throw new RuntimeException('Too frequent run.', previous: $e);+ }++ $this->jobManager->processMainQueue();+ }+}diff --git a/application/Espo/Core/ApplicationRunners/Cron.php b/application/Espo/Core/ApplicationRunners/Cron.phpindex ce855bb6d9..a074e54c64 100644--- a/application/Espo/Core/ApplicationRunners/Cron.php+++ b/application/Espo/Core/ApplicationRunners/Cron.php@@ -55,7 +55,13 @@ class Cron implements Runnerpublic function run(): void{if (!$this->config->isCronEnabled()) {- $this->log->warning("Cron is not run because it's disabled with 'cronDisabled' param.");+ $this->log->warning("Cron is skipped as 'cronDisabled' is set to true in the config.");++ return;+ }++ if ($this->config->isMaintenanceMode()) {+ $this->log->warning("Cron run is skipped in maintenance mode.");return;}diff --git a/application/Espo/Core/Authentication/ConfigDataProvider.php b/application/Espo/Core/Authentication/ConfigDataProvider.phpindex d38960a817..c3fa8bf68b 100644--- a/application/Espo/Core/Authentication/ConfigDataProvider.php+++ b/application/Espo/Core/Authentication/ConfigDataProvider.php@@ -43,8 +43,11 @@ class ConfigDataProviderprivate const string USERNAME_FAILED_ATTEMPTS_PERIOD = '60 seconds';private const int USERNAME_FAILED_ATTEMPT_DELAY = 2;- public function __construct(private Config $config, private Metadata $metadata)- {}+ public function __construct(+ private Config $config,+ private Metadata $metadata,+ private Config\SystemConfig $systemConfig,+ ) {}/*** A period for max failed attempts checking.@@ -106,7 +109,7 @@ class ConfigDataProvider*/public function isMaintenanceMode(): bool{- return (bool) $this->config->get('maintenanceMode');+ return $this->systemConfig->isMaintenanceMode();}/**diff --git a/application/Espo/Core/Upgrades/Actions/Base.php b/application/Espo/Core/Upgrades/Actions/Base.phpindex f84a436469..5cafa8e67f 100644--- a/application/Espo/Core/Upgrades/Actions/Base.php+++ b/application/Espo/Core/Upgrades/Actions/Base.php@@ -83,7 +83,7 @@ abstract class Basepublic function __construct(private Container $container,- private ActionManager $actionManager+ private ActionManager $actionManager,) {$this->params = $actionManager->getParams();@@ -1007,9 +1007,8 @@ abstract class Base}$actualParams = [- 'maintenanceMode' => $config->get('maintenanceMode'),- 'cronDisabled' => $config->get('cronDisabled'),- 'useCache' => $config->get('useCache'),+ 'maintenanceMode' => $this->getSystemConfig()->isMaintenanceMode(),+ 'useCache' => $this->getSystemConfig()->useCache(),];if ($configParamName) {@@ -1025,12 +1024,6 @@ abstract class Base$save = true;}- if (!$actualParams['cronDisabled']) {- $configWriter->set('cronDisabled', true);-- $save = true;- }-if ($actualParams['useCache']) {$configWriter->set('useCache', false);diff --git a/application/Espo/Core/Utils/Config/SystemConfig.php b/application/Espo/Core/Utils/Config/SystemConfig.phpindex d77cd671d0..f99e4a2fb3 100644--- a/application/Espo/Core/Utils/Config/SystemConfig.php+++ b/application/Espo/Core/Utils/Config/SystemConfig.php@@ -68,4 +68,14 @@ class SystemConfig{return !$this->config->get('cronDisabled');}++ /**+ * A maintenance mode. Only admin can log in.+ *+ * @since 10.1.0+ */+ public function isMaintenanceMode(): bool+ {+ return (bool) $this->config->get('maintenanceMode');+ }}diff --git a/application/Espo/Resources/metadata/app/consoleCommands.json b/application/Espo/Resources/metadata/app/consoleCommands.jsonindex 2558ed1e6e..c0eee85511 100644--- a/application/Espo/Resources/metadata/app/consoleCommands.json+++ b/application/Espo/Resources/metadata/app/consoleCommands.json@@ -107,6 +107,14 @@"listed": false,"noSystemUser": true},+ "cron:run": {+ "className": "Espo\\Classes\\ConsoleCommands\\CronRun",+ "listed": true,+ "allowedFlags": [+ "force"+ ],+ "allowedOptions": []+ },"job:prepare": {"className": "Espo\\Classes\\ConsoleCommands\\JobPrepare","listed": false,