1 | <?php |
||
16 | class SyncCaldav extends Command |
||
17 | { |
||
18 | const BACKGROUND_MOD_MEX = 'background mode'; |
||
19 | const BACKGROUND_COMPLETED_MEX = 'All background tasks started'; |
||
20 | |||
21 | /** |
||
22 | * The name and signature of the console command. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $signature = 'sync:caldav {calendarId?} {--background}'; |
||
27 | |||
28 | /** |
||
29 | * The console command description. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $description = 'Sync caldav accounts'; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * @var Schedule laravel schedule object needed to perform command in background |
||
38 | */ |
||
39 | private $schedule; |
||
40 | |||
41 | |||
42 | /** |
||
43 | * Create a new command instance. |
||
44 | * @param Schedule $schedule |
||
45 | * |
||
46 | */ |
||
47 | 15 | public function __construct(Schedule $schedule) |
|
48 | { |
||
49 | 15 | parent::__construct(); |
|
50 | 15 | $this->schedule = $schedule; |
|
51 | 15 | } |
|
52 | |||
53 | /** |
||
54 | * Execute the console command. |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | 9 | public function handle() |
|
59 | { |
||
60 | // |
||
61 | 9 | $calendarId = $this->argument('calendarId'); |
|
62 | 9 | if (is_numeric($calendarId)) |
|
63 | 6 | $this->makeForeground(Caldav::findOrFail($calendarId)); |
|
64 | else |
||
65 | 9 | $this->syncAll(); |
|
66 | 9 | } |
|
67 | |||
68 | /** |
||
69 | * sync calendars foreground |
||
70 | * @param Caldav $calendar |
||
71 | */ |
||
72 | 6 | private function makeForeground(Caldav $calendar) |
|
73 | { |
||
74 | 6 | $this->info('Sync calendar ' . $calendar->calendar_id . ' started'); |
|
75 | 6 | (new Sync($calendar))->sync(); |
|
76 | //TODO show errors as warning |
||
77 | 6 | $this->info('Sync calendar ' . $calendar->calendar_id . ' completed'); |
|
78 | 6 | } |
|
79 | |||
80 | 9 | private function syncAll() |
|
95 | |||
96 | /** |
||
97 | * sync calendars via exec command |
||
98 | * @param Caldav $calendar |
||
99 | */ |
||
100 | 3 | private function makeBackground(Caldav $calendar) |
|
106 | } |
||
107 |