Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| PullDavSyncTask | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| run | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Dav\Task; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use PDO; |
| 12 | |
| 13 | /** |
| 14 | * Inbound DAV Pull Delta-Sync Worker CRON Task. |
| 15 | * |
| 16 | * Implements CronTaskInterface to periodically pull modified events and contacts |
| 17 | * from SOGo server into local CRM modules. |
| 18 | * |
| 19 | * @package App\Modules\Dav\Task |
| 20 | */ |
| 21 | final readonly class PullDavSyncTask extends AbstractDavTask |
| 22 | { |
| 23 | /** |
| 24 | * {@inheritdoc} |
| 25 | */ |
| 26 | public function run(): string |
| 27 | { |
| 28 | $pdo = $this->resolvePdo(); |
| 29 | $calendarSync = $this->resolveCalendarSync($pdo); |
| 30 | $contactSync = $this->resolveContactSync($pdo); |
| 31 | $accountResolver = $this->resolveAccountResolver($pdo); |
| 32 | |
| 33 | $accounts = $accountResolver->listActiveAccounts(); |
| 34 | if (empty($accounts)) { |
| 35 | return 'DAV pull sync: No active users with DAV accounts configured.'; |
| 36 | } |
| 37 | |
| 38 | $calCreated = 0; |
| 39 | $calUpdated = 0; |
| 40 | $conCreated = 0; |
| 41 | $conUpdated = 0; |
| 42 | $errors = []; |
| 43 | |
| 44 | foreach ($accounts as $account) { |
| 45 | $calRes = $calendarSync->pullUserCalendar($account); |
| 46 | $calCreated += $calRes->createdCount; |
| 47 | $calUpdated += $calRes->updatedCount; |
| 48 | $errors = array_merge($errors, $calRes->errors); |
| 49 | |
| 50 | $conRes = $contactSync->pullUserContacts($account); |
| 51 | $conCreated += $conRes->createdCount; |
| 52 | $conUpdated += $conRes->updatedCount; |
| 53 | $errors = array_merge($errors, $conRes->errors); |
| 54 | } |
| 55 | |
| 56 | return sprintf( |
| 57 | 'DAV pull sync completed for %d accounts. Calendar: (+%d, ~%d), Contacts: (+%d, ~%d). Errors: %d.', |
| 58 | count($accounts), |
| 59 | $calCreated, |
| 60 | $calUpdated, |
| 61 | $conCreated, |
| 62 | $conUpdated, |
| 63 | count($errors) |
| 64 | ); |
| 65 | } |
| 66 | } |
| 67 |