@@ -34,91 +34,91 @@ |
||
| 34 | 34 | |
| 35 | 35 | class BuildCalendarSearchIndexBackgroundJob extends QueuedJob { |
| 36 | 36 | |
| 37 | - /** @var IDBConnection */ |
|
| 38 | - private $db; |
|
| 39 | - |
|
| 40 | - /** @var CalDavBackend */ |
|
| 41 | - private $calDavBackend; |
|
| 42 | - |
|
| 43 | - /** @var ILogger */ |
|
| 44 | - private $logger; |
|
| 45 | - |
|
| 46 | - /** @var IJobList */ |
|
| 47 | - private $jobList; |
|
| 48 | - |
|
| 49 | - /** @var ITimeFactory */ |
|
| 50 | - private $timeFactory; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param IDBConnection $db |
|
| 54 | - * @param CalDavBackend $calDavBackend |
|
| 55 | - * @param ILogger $logger |
|
| 56 | - * @param IJobList $jobList |
|
| 57 | - * @param ITimeFactory $timeFactory |
|
| 58 | - */ |
|
| 59 | - public function __construct(IDBConnection $db, |
|
| 60 | - CalDavBackend $calDavBackend, |
|
| 61 | - ILogger $logger, |
|
| 62 | - IJobList $jobList, |
|
| 63 | - ITimeFactory $timeFactory) { |
|
| 64 | - $this->db = $db; |
|
| 65 | - $this->calDavBackend = $calDavBackend; |
|
| 66 | - $this->logger = $logger; |
|
| 67 | - $this->jobList = $jobList; |
|
| 68 | - $this->timeFactory = $timeFactory; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function run($arguments) { |
|
| 72 | - $offset = (int) $arguments['offset']; |
|
| 73 | - $stopAt = (int) $arguments['stopAt']; |
|
| 74 | - |
|
| 75 | - $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 76 | - |
|
| 77 | - $startTime = $this->timeFactory->getTime(); |
|
| 78 | - while (($this->timeFactory->getTime() - $startTime) < 15) { |
|
| 79 | - $offset = $this->buildIndex($offset, $stopAt); |
|
| 80 | - if ($offset >= $stopAt) { |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if ($offset >= $stopAt) { |
|
| 86 | - $this->logger->info('Building calendar index done'); |
|
| 87 | - } else { |
|
| 88 | - $this->jobList->add(self::class, [ |
|
| 89 | - 'offset' => $offset, |
|
| 90 | - 'stopAt' => $stopAt |
|
| 91 | - ]); |
|
| 92 | - $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param int $offset |
|
| 98 | - * @param int $stopAt |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - private function buildIndex(int $offset, int $stopAt): int { |
|
| 102 | - $query = $this->db->getQueryBuilder(); |
|
| 103 | - $query->select(['id', 'calendarid', 'uri', 'calendardata']) |
|
| 104 | - ->from('calendarobjects') |
|
| 105 | - ->where($query->expr()->lte('id', $query->createNamedParameter($stopAt))) |
|
| 106 | - ->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset))) |
|
| 107 | - ->orderBy('id', 'ASC') |
|
| 108 | - ->setMaxResults(500); |
|
| 109 | - |
|
| 110 | - $result = $query->execute(); |
|
| 111 | - while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { |
|
| 112 | - $offset = $row['id']; |
|
| 113 | - |
|
| 114 | - $calendarData = $row['calendardata']; |
|
| 115 | - if (is_resource($calendarData)) { |
|
| 116 | - $calendarData = stream_get_contents($calendarData); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $offset; |
|
| 123 | - } |
|
| 37 | + /** @var IDBConnection */ |
|
| 38 | + private $db; |
|
| 39 | + |
|
| 40 | + /** @var CalDavBackend */ |
|
| 41 | + private $calDavBackend; |
|
| 42 | + |
|
| 43 | + /** @var ILogger */ |
|
| 44 | + private $logger; |
|
| 45 | + |
|
| 46 | + /** @var IJobList */ |
|
| 47 | + private $jobList; |
|
| 48 | + |
|
| 49 | + /** @var ITimeFactory */ |
|
| 50 | + private $timeFactory; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param IDBConnection $db |
|
| 54 | + * @param CalDavBackend $calDavBackend |
|
| 55 | + * @param ILogger $logger |
|
| 56 | + * @param IJobList $jobList |
|
| 57 | + * @param ITimeFactory $timeFactory |
|
| 58 | + */ |
|
| 59 | + public function __construct(IDBConnection $db, |
|
| 60 | + CalDavBackend $calDavBackend, |
|
| 61 | + ILogger $logger, |
|
| 62 | + IJobList $jobList, |
|
| 63 | + ITimeFactory $timeFactory) { |
|
| 64 | + $this->db = $db; |
|
| 65 | + $this->calDavBackend = $calDavBackend; |
|
| 66 | + $this->logger = $logger; |
|
| 67 | + $this->jobList = $jobList; |
|
| 68 | + $this->timeFactory = $timeFactory; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function run($arguments) { |
|
| 72 | + $offset = (int) $arguments['offset']; |
|
| 73 | + $stopAt = (int) $arguments['stopAt']; |
|
| 74 | + |
|
| 75 | + $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 76 | + |
|
| 77 | + $startTime = $this->timeFactory->getTime(); |
|
| 78 | + while (($this->timeFactory->getTime() - $startTime) < 15) { |
|
| 79 | + $offset = $this->buildIndex($offset, $stopAt); |
|
| 80 | + if ($offset >= $stopAt) { |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if ($offset >= $stopAt) { |
|
| 86 | + $this->logger->info('Building calendar index done'); |
|
| 87 | + } else { |
|
| 88 | + $this->jobList->add(self::class, [ |
|
| 89 | + 'offset' => $offset, |
|
| 90 | + 'stopAt' => $stopAt |
|
| 91 | + ]); |
|
| 92 | + $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param int $offset |
|
| 98 | + * @param int $stopAt |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + private function buildIndex(int $offset, int $stopAt): int { |
|
| 102 | + $query = $this->db->getQueryBuilder(); |
|
| 103 | + $query->select(['id', 'calendarid', 'uri', 'calendardata']) |
|
| 104 | + ->from('calendarobjects') |
|
| 105 | + ->where($query->expr()->lte('id', $query->createNamedParameter($stopAt))) |
|
| 106 | + ->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset))) |
|
| 107 | + ->orderBy('id', 'ASC') |
|
| 108 | + ->setMaxResults(500); |
|
| 109 | + |
|
| 110 | + $result = $query->execute(); |
|
| 111 | + while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { |
|
| 112 | + $offset = $row['id']; |
|
| 113 | + |
|
| 114 | + $calendarData = $row['calendardata']; |
|
| 115 | + if (is_resource($calendarData)) { |
|
| 116 | + $calendarData = stream_get_contents($calendarData); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $offset; |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $offset = (int) $arguments['offset']; |
| 73 | 73 | $stopAt = (int) $arguments['stopAt']; |
| 74 | 74 | |
| 75 | - $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 75 | + $this->logger->info('Building calendar index ('.$offset.'/'.$stopAt.')'); |
|
| 76 | 76 | |
| 77 | 77 | $startTime = $this->timeFactory->getTime(); |
| 78 | 78 | while (($this->timeFactory->getTime() - $startTime) < 15) { |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | 'offset' => $offset, |
| 90 | 90 | 'stopAt' => $stopAt |
| 91 | 91 | ]); |
| 92 | - $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 92 | + $this->logger->info('New building calendar index job scheduled with offset '.$offset); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |