Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
job.php
1<?php
2
4
8
9final class Job extends Main\Engine\Controller
10{
11 public function addAction(int $sitemapId): AjaxJson
12 {
13 try {
14 $job = Sitemap\Job::addJob($sitemapId);
15
16 return $job
17 ? self::createSuccess($job->getData())
18 : self::createError("Can't add job {$sitemapId}")
19 ;
20 }
21 catch (Main\SystemException $e)
22 {
23 return self::createError($e->getMessage() . " Sitemap id: {$sitemapId}");
24 }
25 }
26
27 public function doAction(int $sitemapId): AjaxJson
28 {
29 try
30 {
31 $job = Sitemap\Job::findJob($sitemapId);
32 if (!$job)
33 {
34 $job = Sitemap\Job::addJob($sitemapId);
35 }
36
37 $res = $job->doStep();
38 if ($res->isSuccess())
39 {
40 return self::createSuccess($job->getData());
41 }
42
43 return self::createError(implode('; ', $res->getErrors()));
44 }
45 catch (Main\SystemException $e)
46 {
47 return self::createError($e->getMessage() . " Sitemap id: {$sitemapId}");
48 }
49 }
50
51 protected static function createSuccess(mixed $data): AjaxJson
52 {
53 return AjaxJson::createSuccess($data);
54 }
55
56 protected static function createError(string $message): AjaxJson
57 {
59 $errorCollection[] = new Main\Error($message);
60
61 return AjaxJson::createError($errorCollection);
62 }
63}
doAction(int $sitemapId)
Definition job.php:27
static createError(string $message)
Definition job.php:56
addAction(int $sitemapId)
Definition job.php:11
static createSuccess(mixed $data)
Definition job.php:51