config = $config; $this->entityManager = $entityManager; } public function run(): void { if ( !$this->config->get('adminNotifications') || !$this->config->get('adminNotificationsNewVersion') ) { return; } $className = \Espo\Tools\AdminNotifications\Jobs\CheckNewVersion::class; /** @todo Job scheduler is not used for bc reasons. */ $this->entityManager->createEntity(Job::ENTITY_TYPE, [ 'name' => $className, 'className' => $className, 'executeTime' => $this->getRunTime(), ]); } protected function getRunTime(): string { $hour = rand(0, 4); $minute = rand(0, 59); $nextDay = new DateTime('+ 1 day'); $time = $nextDay->format(DateTimeUtil::SYSTEM_DATE_FORMAT) . ' ' . $hour . ':' . $minute . ':00'; $timeZone = $this->config->get('timeZone'); if (empty($timeZone)) { $timeZone = 'UTC'; } $datetime = new DateTime($time, new DateTimeZone($timeZone)); return $datetime ->setTimezone(new DateTimeZone('UTC')) ->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT); } /** * For backward compatibility. * @deprecated */ protected function getEntityManager() /** @phpstan-ignore-line */ { return $this->entityManager; } }