diff --git a/application/Espo/Classes/AppInfo/Jobs.php b/application/Espo/Classes/AppInfo/Jobs.php index cb1d04eecf..4cdb93462b 100644 --- a/application/Espo/Classes/AppInfo/Jobs.php +++ b/application/Espo/Classes/AppInfo/Jobs.php @@ -31,14 +31,18 @@ namespace Espo\Classes\AppInfo; use Espo\Core\Console\Params; use Espo\Core\Utils\ClassFinder; +use Espo\Core\Job\MetadataProvider; class Jobs { private $classFinder; - public function __construct(ClassFinder $classFinder) + private $metadataProvider; + + public function __construct(ClassFinder $classFinder, MetadataProvider $metadataProvider) { $this->classFinder = $classFinder; + $this->metadataProvider = $metadataProvider; } public function process(Params $params): string @@ -47,9 +51,14 @@ class Jobs $list = array_map( function ($item) { - return ' '. $item; + return ' ' . $item; }, - array_keys($this->classFinder->getMap('Jobs')) + array_unique( + array_merge( + array_keys($this->classFinder->getMap('Jobs')), + $this->metadataProvider->getScheduledJobNameList() + ) + ) ); asort($list); diff --git a/application/Espo/Jobs/AuthTokenControl.php b/application/Espo/Classes/Jobs/AuthTokenControl.php similarity index 99% rename from application/Espo/Jobs/AuthTokenControl.php rename to application/Espo/Classes/Jobs/AuthTokenControl.php index b6d2cd1458..fb98d69896 100644 --- a/application/Espo/Jobs/AuthTokenControl.php +++ b/application/Espo/Classes/Jobs/AuthTokenControl.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; use Espo\Core\{ Utils\Config, diff --git a/application/Espo/Jobs/CheckEmailAccounts.php b/application/Espo/Classes/Jobs/CheckEmailAccounts.php similarity index 98% rename from application/Espo/Jobs/CheckEmailAccounts.php rename to application/Espo/Classes/Jobs/CheckEmailAccounts.php index 7bce4df6fd..f7fb3daadb 100644 --- a/application/Espo/Jobs/CheckEmailAccounts.php +++ b/application/Espo/Classes/Jobs/CheckEmailAccounts.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; use Espo\Core\Exceptions\Error; diff --git a/application/Espo/Jobs/CheckInboundEmails.php b/application/Espo/Classes/Jobs/CheckInboundEmails.php similarity index 98% rename from application/Espo/Jobs/CheckInboundEmails.php rename to application/Espo/Classes/Jobs/CheckInboundEmails.php index 76dd30e2f5..fcdb60d6fb 100644 --- a/application/Espo/Jobs/CheckInboundEmails.php +++ b/application/Espo/Classes/Jobs/CheckInboundEmails.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; use Espo\Core\Exceptions\Error; diff --git a/application/Espo/Jobs/CheckNewExtensionVersion.php b/application/Espo/Classes/Jobs/CheckNewExtensionVersion.php similarity index 98% rename from application/Espo/Jobs/CheckNewExtensionVersion.php rename to application/Espo/Classes/Jobs/CheckNewExtensionVersion.php index a1a9925369..3327df0da2 100644 --- a/application/Espo/Jobs/CheckNewExtensionVersion.php +++ b/application/Espo/Classes/Jobs/CheckNewExtensionVersion.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; class CheckNewExtensionVersion extends CheckNewVersion { @@ -50,4 +50,4 @@ class CheckNewExtensionVersion extends CheckNewVersion $this->entityManager->saveEntity($job); } -} \ No newline at end of file +} diff --git a/application/Espo/Jobs/CheckNewVersion.php b/application/Espo/Classes/Jobs/CheckNewVersion.php similarity index 99% rename from application/Espo/Jobs/CheckNewVersion.php rename to application/Espo/Classes/Jobs/CheckNewVersion.php index cc699a6f78..dedc98049e 100644 --- a/application/Espo/Jobs/CheckNewVersion.php +++ b/application/Espo/Classes/Jobs/CheckNewVersion.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; use Espo\Core\{ Utils\Config, diff --git a/application/Espo/Jobs/Cleanup.php b/application/Espo/Classes/Jobs/Cleanup.php similarity index 99% rename from application/Espo/Jobs/Cleanup.php rename to application/Espo/Classes/Jobs/Cleanup.php index 488ddfb4d6..7354c23b07 100644 --- a/application/Espo/Jobs/Cleanup.php +++ b/application/Espo/Classes/Jobs/Cleanup.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; use Espo\Core\Record\ServiceContainer; diff --git a/application/Espo/Jobs/Dummy.php b/application/Espo/Classes/Jobs/Dummy.php similarity index 93% rename from application/Espo/Jobs/Dummy.php rename to application/Espo/Classes/Jobs/Dummy.php index 1c6b55ac97..abfdb428a0 100644 --- a/application/Espo/Jobs/Dummy.php +++ b/application/Espo/Classes/Jobs/Dummy.php @@ -27,15 +27,11 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; -use Espo\Core\{ - Job\JobDataLess, -}; +use Espo\Core\Job\JobDataLess; class Dummy implements JobDataLess { - public function run(): void - { - } + public function run(): void {} } diff --git a/application/Espo/Jobs/ProcessWebhookQueue.php b/application/Espo/Classes/Jobs/ProcessWebhookQueue.php similarity index 98% rename from application/Espo/Jobs/ProcessWebhookQueue.php rename to application/Espo/Classes/Jobs/ProcessWebhookQueue.php index 10c272c7e6..33388834c9 100644 --- a/application/Espo/Jobs/ProcessWebhookQueue.php +++ b/application/Espo/Classes/Jobs/ProcessWebhookQueue.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; use Espo\Core\{ Job\JobDataLess, diff --git a/application/Espo/Jobs/SendEmailNotifications.php b/application/Espo/Classes/Jobs/SendEmailNotifications.php similarity index 98% rename from application/Espo/Jobs/SendEmailNotifications.php rename to application/Espo/Classes/Jobs/SendEmailNotifications.php index 215a4379cb..9c59e26342 100644 --- a/application/Espo/Jobs/SendEmailNotifications.php +++ b/application/Espo/Classes/Jobs/SendEmailNotifications.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Classes\Jobs; use Espo\Core\Job\JobDataLess; diff --git a/application/Espo/Core/Job/Job/Jobs/AbstractGroupJob.php b/application/Espo/Core/Job/Job/Jobs/ProcessJobGroup.php similarity index 97% rename from application/Espo/Core/Job/Job/Jobs/AbstractGroupJob.php rename to application/Espo/Core/Job/Job/Jobs/ProcessJobGroup.php index 842008df90..b142a40a65 100644 --- a/application/Espo/Core/Job/Job/Jobs/AbstractGroupJob.php +++ b/application/Espo/Core/Job/Job/Jobs/ProcessJobGroup.php @@ -34,7 +34,7 @@ use Espo\Core\Job\Job; use Espo\Core\Job\Job\Data; use Espo\Core\Job\JobManager; -abstract class AbstractGroupJob implements Job +class ProcessJobGroup implements Job { private const PORTION_NUMBER = 100; diff --git a/application/Espo/Jobs/ProcessJobQueueE0.php b/application/Espo/Core/Job/Job/Jobs/ProcessJobQueueE0.php similarity index 97% rename from application/Espo/Jobs/ProcessJobQueueE0.php rename to application/Espo/Core/Job/Job/Jobs/ProcessJobQueueE0.php index 888ef19a0f..3280bc5d66 100644 --- a/application/Espo/Jobs/ProcessJobQueueE0.php +++ b/application/Espo/Core/Job/Job/Jobs/ProcessJobQueueE0.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Core\Job\Job\Jobs; use Espo\Core\{ Job\QueueName, diff --git a/application/Espo/Jobs/ProcessJobQueueQ0.php b/application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ0.php similarity index 97% rename from application/Espo/Jobs/ProcessJobQueueQ0.php rename to application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ0.php index 4411ab3788..3ece14c47b 100644 --- a/application/Espo/Jobs/ProcessJobQueueQ0.php +++ b/application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ0.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Core\Job\Job\Jobs; use Espo\Core\{ Job\QueueName, diff --git a/application/Espo/Jobs/ProcessJobQueueQ1.php b/application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ1.php similarity index 97% rename from application/Espo/Jobs/ProcessJobQueueQ1.php rename to application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ1.php index f0ec088d35..e89bdb8d22 100644 --- a/application/Espo/Jobs/ProcessJobQueueQ1.php +++ b/application/Espo/Core/Job/Job/Jobs/ProcessJobQueueQ1.php @@ -27,7 +27,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Jobs; +namespace Espo\Core\Job\Job\Jobs; use Espo\Core\{ Job\QueueName, diff --git a/application/Espo/Core/Job/JobFactory.php b/application/Espo/Core/Job/JobFactory.php index 4f90d2dc83..1db95f8818 100644 --- a/application/Espo/Core/Job/JobFactory.php +++ b/application/Espo/Core/Job/JobFactory.php @@ -29,6 +29,8 @@ namespace Espo\Core\Job; +use Espo\Core\Job\MetadataProvider; + use Espo\Core\{ Exceptions\Error, Utils\ClassFinder, @@ -41,14 +43,20 @@ class JobFactory private $injectableFactory; - public function __construct(ClassFinder $classFinder, InjectableFactory $injectableFactory) - { + private $metadataProvider; + + public function __construct( + ClassFinder $classFinder, + InjectableFactory $injectableFactory, + MetadataProvider $metadataProvider + ) { $this->classFinder = $classFinder; $this->injectableFactory = $injectableFactory; + $this->metadataProvider = $metadataProvider; } /** - * Create a job. + * Create a job by a scheduled job name. * * @return Job|JobDataLess * @throws Error @@ -65,7 +73,7 @@ class JobFactory } /** - * Create a job by class name. + * Create a job by a class name. * @return Job|JobDataLess */ @@ -78,6 +86,12 @@ class JobFactory private function getClassName(string $name): ?string { + $className = $this->metadataProvider->getJobClassName($name); + + if ($className) { + return $className; + } + return $this->classFinder->find('Jobs', ucfirst($name)); } } \ No newline at end of file diff --git a/application/Espo/Core/Job/MetadataProvider.php b/application/Espo/Core/Job/MetadataProvider.php index 999f5e32a0..802d5178ef 100644 --- a/application/Espo/Core/Job/MetadataProvider.php +++ b/application/Espo/Core/Job/MetadataProvider.php @@ -50,7 +50,7 @@ class MetadataProvider $items = $this->metadata->get(['app', 'scheduledJobs']) ?? []; foreach ($items as $name => $item) { - $isPreparable = $item['isPreparable'] ?? false; + $isPreparable = (bool) ($item['preparatorClassName'] ?? null); if ($isPreparable) { $list[] = $name; @@ -60,13 +60,40 @@ class MetadataProvider return $list; } + public function isJobSystem(string $name): bool + { + return (bool) $this->metadata->get(['app', 'scheduledJobs', $name, 'isSystem']); + } + public function isJobPreparable(string $name): bool { - return (bool) $this->metadata->get(['app', 'scheduledJobs', $name, 'isPreparable']); + return (bool) $this->metadata->get(['app', 'scheduledJobs', $name, 'preparatorClassName']); } public function getPreparatorClassName(string $name): ?string { return $this->metadata->get(['app', 'scheduledJobs', $name, 'preparatorClassName']); } + + public function getJobClassName(string $name): ?string + { + return $this->metadata->get(['app', 'scheduledJobs', $name, 'jobClassName']); + } + + public function getScheduledJobNameList(): array + { + return array_keys($this->metadata->get(['app', 'scheduledJobs']) ?? []); + } + + public function getNonSystemScheduledJobNameList(): array + { + return array_filter( + $this->getScheduledJobNameList(), + function (string $item) { + $isSystem = (bool) $this->metadata->get(['app', 'scheduledJobs', $item, 'isSystem']); + + return !$isSystem; + } + ); + } } diff --git a/application/Espo/Core/Job/Preparator/Preparators/GroupPreparator.php b/application/Espo/Core/Job/Preparator/Preparators/ProcessJobGroupPreparator.php similarity index 98% rename from application/Espo/Core/Job/Preparator/Preparators/GroupPreparator.php rename to application/Espo/Core/Job/Preparator/Preparators/ProcessJobGroupPreparator.php index d290481d56..3e795fbdc0 100644 --- a/application/Espo/Core/Job/Preparator/Preparators/GroupPreparator.php +++ b/application/Espo/Core/Job/Preparator/Preparators/ProcessJobGroupPreparator.php @@ -40,7 +40,7 @@ use Espo\Entities\Job as JobEntity; use DateTimeImmutable; -class GroupPreparator implements Preparator +class ProcessJobGroupPreparator implements Preparator { private $entityManager; diff --git a/application/Espo/Core/Utils/ScheduledJob.php b/application/Espo/Core/Utils/ScheduledJob.php index bd51038422..f9d877b9fd 100644 --- a/application/Espo/Core/Utils/ScheduledJob.php +++ b/application/Espo/Core/Utils/ScheduledJob.php @@ -29,6 +29,8 @@ namespace Espo\Core\Utils; +use Espo\Core\Job\MetadataProvider; + use Espo\Core\{ Utils\ClassFinder, Utils\Language, @@ -59,28 +61,45 @@ class ScheduledJob 'default' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BINARY} -f {CRON-FILE} > /dev/null 2>&1', ]; - protected $classFinder; + private $classFinder; - protected $language; + private $language; - protected $entityManager; + private $entityManager; - public function __construct(ClassFinder $classFinder, EntityManager $entityManager, Language $language) - { + private $metadataProvider; + + public function __construct( + ClassFinder $classFinder, + EntityManager $entityManager, + Language $language, + MetadataProvider $metadataProvider + ) { $this->classFinder = $classFinder; $this->entityManager = $entityManager; $this->language = $language; + $this->metadataProvider = $metadataProvider; $this->systemUtil = new System(); } public function getAvailableList(): array { - $map = $this->classFinder->getMap('Jobs'); + $list = array_filter( + array_merge( + $this->metadataProvider->getNonSystemScheduledJobNameList(), + array_keys( + $this->classFinder->getMap('Jobs') + ) + ), + function (string $item) { + return !$this->metadataProvider->isJobSystem($item); + } + ); - $list = array_keys($map); + asort($list); - return $list; + return array_values($list); } public function getSetupMessage(): array diff --git a/application/Espo/Jobs/ProcessJobGroup.php b/application/Espo/Jobs/ProcessJobGroup.php deleted file mode 100644 index ad07ab9727..0000000000 --- a/application/Espo/Jobs/ProcessJobGroup.php +++ /dev/null @@ -1,34 +0,0 @@ -