Initial commit
This commit is contained in:
47
application/Espo/Core/ApplicationRunners/Api.php
Normal file
47
application/Espo/Core/ApplicationRunners/Api.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\Api\Starter;
|
||||
|
||||
/**
|
||||
* Runs API request processing.
|
||||
*/
|
||||
class Api implements Runner
|
||||
{
|
||||
public function __construct(private Starter $starter)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$this->starter->start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
|
||||
/**
|
||||
* @deprecated For backward compatibility.
|
||||
*/
|
||||
interface ApplicationRunner extends Runner
|
||||
{
|
||||
}
|
||||
53
application/Espo/Core/ApplicationRunners/ClearCache.php
Normal file
53
application/Espo/Core/ApplicationRunners/ClearCache.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
/**
|
||||
* Clears an application cache.
|
||||
*/
|
||||
class ClearCache implements Runner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
public function __construct(private DataManager $dataManager)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->dataManager->clearCache();
|
||||
}
|
||||
}
|
||||
38
application/Espo/Core/ApplicationRunners/Cli.php
Normal file
38
application/Espo/Core/ApplicationRunners/Cli.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
/**
|
||||
* Can be run only via CLI.
|
||||
*/
|
||||
trait Cli
|
||||
{
|
||||
public static bool $cli = true;
|
||||
}
|
||||
54
application/Espo/Core/ApplicationRunners/Client.php
Normal file
54
application/Espo/Core/ApplicationRunners/Client.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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\Utils\ClientManager;
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
/**
|
||||
* Displays the main HTML page.
|
||||
*/
|
||||
class Client implements Runner
|
||||
{
|
||||
public function __construct(private ClientManager $clientManager, private Config $config)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
if (!$this->config->get('isInstalled')) {
|
||||
header("Location: install/");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->clientManager->display();
|
||||
}
|
||||
}
|
||||
59
application/Espo/Core/ApplicationRunners/Command.php
Normal file
59
application/Espo/Core/ApplicationRunners/Command.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\Console\CommandManager as ConsoleCommandManager;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Runs a console command.
|
||||
*/
|
||||
class Command implements Runner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
public function __construct(private ConsoleCommandManager $commandManager)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
try {
|
||||
$exitStatus = $this->commandManager->run($_SERVER['argv']);
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
exit($exitStatus);
|
||||
}
|
||||
}
|
||||
58
application/Espo/Core/ApplicationRunners/Cron.php
Normal file
58
application/Espo/Core/ApplicationRunners/Cron.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\Job\JobManager;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Log;
|
||||
|
||||
/**
|
||||
* Runs Cron.
|
||||
*/
|
||||
class Cron implements Runner
|
||||
{
|
||||
use Cli;
|
||||
use SetupSystemUser;
|
||||
|
||||
public function __construct(private JobManager $jobManager, private Config $config, private Log $log)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
if ($this->config->get('cronDisabled')) {
|
||||
$this->log->warning("Cron is not run because it's disabled with 'cronDisabled' param.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->jobManager->process();
|
||||
}
|
||||
}
|
||||
100
application/Espo/Core/ApplicationRunners/Daemon.php
Normal file
100
application/Espo/Core/ApplicationRunners/Daemon.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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Log;
|
||||
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Runs daemon. The daemon runs the cron more often than once a minute.
|
||||
*/
|
||||
class Daemon implements Runner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
public function __construct(private Config $config, private Log $log)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$maxProcessNumber = $this->config->get('daemonMaxProcessNumber');
|
||||
$interval = $this->config->get('daemonInterval');
|
||||
$timeout = $this->config->get('daemonProcessTimeout');
|
||||
|
||||
$phpExecutablePath = $this->config->get('phpExecutablePath');
|
||||
|
||||
if (!$phpExecutablePath) {
|
||||
$phpExecutablePath = (new PhpExecutableFinder)->find();
|
||||
}
|
||||
|
||||
if (!$maxProcessNumber || !$interval) {
|
||||
$this->log->error("Daemon config params are not set.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$processList = [];
|
||||
|
||||
while (true) { /** @phpstan-ignore-line */
|
||||
$toSkip = false;
|
||||
$runningCount = 0;
|
||||
|
||||
foreach ($processList as $i => $process) {
|
||||
if ($process->isRunning()) {
|
||||
$runningCount++;
|
||||
} else {
|
||||
unset($processList[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$processList = array_values($processList);
|
||||
|
||||
if ($runningCount >= $maxProcessNumber) {
|
||||
$toSkip = true;
|
||||
}
|
||||
|
||||
if (!$toSkip) {
|
||||
$process = new Process([$phpExecutablePath, 'cron.php']);
|
||||
|
||||
$process->setTimeout($timeout);
|
||||
|
||||
$process->start();
|
||||
|
||||
$processList[] = $process;
|
||||
}
|
||||
|
||||
sleep($interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
51
application/Espo/Core/ApplicationRunners/EntryPoint.php
Normal file
51
application/Espo/Core/ApplicationRunners/EntryPoint.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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\RunnerParameterized;
|
||||
use Espo\Core\Application\Runner\Params;
|
||||
use Espo\Core\EntryPoint\Starter;
|
||||
|
||||
/**
|
||||
* Runs an entry point.
|
||||
*/
|
||||
class EntryPoint implements RunnerParameterized
|
||||
{
|
||||
public function __construct(private Starter $starter)
|
||||
{}
|
||||
|
||||
public function run(Params $params): void
|
||||
{
|
||||
$this->starter->start(
|
||||
$params->get('entryPoint'),
|
||||
$params->get('final') ?? false
|
||||
);
|
||||
}
|
||||
}
|
||||
53
application/Espo/Core/ApplicationRunners/Job.php
Normal file
53
application/Espo/Core/ApplicationRunners/Job.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner\Params;
|
||||
use Espo\Core\Application\RunnerParameterized;
|
||||
use Espo\Core\Job\JobManager;
|
||||
|
||||
/**
|
||||
* Runs a job by ID. A job record should exist in database.
|
||||
*/
|
||||
class Job implements RunnerParameterized
|
||||
{
|
||||
use Cli;
|
||||
use SetupSystemUser;
|
||||
|
||||
public function __construct(private JobManager $jobManager)
|
||||
{}
|
||||
|
||||
public function run(Params $params): void
|
||||
{
|
||||
$id = $params->get('id');
|
||||
|
||||
$this->jobManager->runJobById($id);
|
||||
}
|
||||
}
|
||||
107
application/Espo/Core/ApplicationRunners/PortalClient.php
Normal file
107
application/Espo/Core/ApplicationRunners/PortalClient.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Api\ErrorOutput;
|
||||
use Espo\Core\Api\RequestWrapper;
|
||||
use Espo\Core\Api\ResponseWrapper;
|
||||
use Espo\Core\Application\Runner\Params;
|
||||
use Espo\Core\Application\RunnerParameterized;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Portal\Application as PortalApplication;
|
||||
use Espo\Core\Portal\ApplicationRunners\Client as PortalPortalClient;
|
||||
use Espo\Core\Portal\Utils\Url;
|
||||
use Espo\Core\Utils\ClientManager;
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
use Slim\Factory\ServerRequestCreatorFactory;
|
||||
use Slim\Psr7\Response;
|
||||
use Slim\ResponseEmitter;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Runs a portal client.
|
||||
*/
|
||||
class PortalClient implements RunnerParameterized
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private ClientManager $clientManager,
|
||||
private Config $config,
|
||||
private ErrorOutput $errorOutput
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
public function run(Params $params): void
|
||||
{
|
||||
$id = $params->get('id') ??
|
||||
Url::detectPortalId() ??
|
||||
$this->config->get('defaultPortalId');
|
||||
|
||||
$basePath = $params->get('basePath') ?? $this->clientManager->getBasePath();
|
||||
|
||||
$requestWrapped = new RequestWrapper(
|
||||
ServerRequestCreatorFactory::create()->createServerRequestFromGlobals()
|
||||
);
|
||||
|
||||
$responseWrapped = new ResponseWrapper(new Response());
|
||||
|
||||
if ($requestWrapped->getMethod() !== 'GET') {
|
||||
throw new BadRequest("Only GET request is allowed.");
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$id) {
|
||||
throw new NotFound("Portal ID not detected.");
|
||||
}
|
||||
|
||||
$application = new PortalApplication($id);
|
||||
} catch (Exception $e) {
|
||||
$this->processError($requestWrapped, $responseWrapped, $e);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$application->setClientBasePath($basePath);
|
||||
|
||||
$application->run(PortalPortalClient::class);
|
||||
}
|
||||
|
||||
private function processError(RequestWrapper $request, ResponseWrapper $response, Exception $exception): void
|
||||
{
|
||||
$this->errorOutput->processWithBodyPrinting($request, $response, $exception);
|
||||
|
||||
(new ResponseEmitter())->emit($response->toPsr7());
|
||||
}
|
||||
}
|
||||
85
application/Espo/Core/ApplicationRunners/Preload.php
Normal file
85
application/Espo/Core/ApplicationRunners/Preload.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\Utils\Preload as PreloadUtil;
|
||||
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Runs a preload.
|
||||
*
|
||||
* @see https://www.php.net/manual/en/opcache.preloading.php
|
||||
*/
|
||||
class Preload implements Runner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$preload = new PreloadUtil();
|
||||
|
||||
try {
|
||||
$preload->process();
|
||||
} catch (Throwable $e) {
|
||||
$this->processException($e);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$count = $preload->getCount();
|
||||
|
||||
echo "Success." . PHP_EOL;
|
||||
echo "Files loaded: " . $count . "." . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function processException(Throwable $e): void
|
||||
{
|
||||
echo "Error occurred." . PHP_EOL;
|
||||
|
||||
$msg = $e->getMessage();
|
||||
|
||||
if ($msg) {
|
||||
echo "Message: $msg" . PHP_EOL;
|
||||
}
|
||||
|
||||
$file = $e->getFile();
|
||||
|
||||
if ($file) {
|
||||
echo "File: $file" . PHP_EOL;
|
||||
}
|
||||
|
||||
echo "Line: " . $e->getLine() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
62
application/Espo/Core/ApplicationRunners/Rebuild.php
Normal file
62
application/Espo/Core/ApplicationRunners/Rebuild.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Rebuilds an application.
|
||||
*/
|
||||
class Rebuild implements Runner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
public function __construct(private DataManager $dataManager, private Log $log)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
try {
|
||||
$this->dataManager->rebuild();
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
|
||||
$this->log->error('Rebuild: ' . $e->getMessage(), [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
application/Espo/Core/ApplicationRunners/SetupSystemUser.php
Normal file
38
application/Espo/Core/ApplicationRunners/SetupSystemUser.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
/**
|
||||
* System user will be set up for an application.
|
||||
*/
|
||||
trait SetupSystemUser
|
||||
{
|
||||
public static bool $setupSystemUser = true;
|
||||
}
|
||||
49
application/Espo/Core/ApplicationRunners/WebSocket.php
Normal file
49
application/Espo/Core/ApplicationRunners/WebSocket.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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\ApplicationRunners;
|
||||
|
||||
use Espo\Core\Application\Runner;
|
||||
use Espo\Core\WebSocket\ServerStarter;
|
||||
|
||||
/**
|
||||
* Runs WebSocket.
|
||||
*/
|
||||
class WebSocket implements Runner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
public function __construct(private ServerStarter $serverStarter)
|
||||
{}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$this->serverStarter->start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user