Completed
Push — master ( bc4e81...14a953 )
by claudio
04:04
created
app/Console/Commands/SyncCaldav/Sync.php 3 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: Claudio Cardinale <[email protected]>
5
- * Date: 03/12/15
6
- * Time: 2.33
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; either version 2
10
- * of the License, or (at your option) any later version.
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
- */
3
+     * Created by PhpStorm.
4
+     * User: Claudio Cardinale <[email protected]>
5
+     * Date: 03/12/15
6
+     * Time: 2.33
7
+     * This program is free software; you can redistribute it and/or
8
+     * modify it under the terms of the GNU General Public License
9
+     * as published by the Free Software Foundation; either version 2
10
+     * of the License, or (at your option) any later version.
11
+     * This program is distributed in the hope that it will be useful,
12
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+     * GNU General Public License for more details.
15
+     * You should have received a copy of the GNU General Public License
16
+     * along with this program; if not, write to the Free Software
17
+     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
+     */
19 19
 
20 20
 namespace plunner\Console\Commands\SyncCaldav;
21 21
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
         $caldavClient = new SimpleCaldavAdapter();
74 74
         $caldavClient->connect($this->calendar->url, $this->calendar->username, \Crypt::decrypt($this->calendar->password));
75 75
         $calendars = $caldavClient->findCalendars();
76
-        $caldavClient->setCalendar($calendars[$this->calendar->calendar_name]);
76
+        $caldavClient->setCalendar($calendars[ $this->calendar->calendar_name ]);
77 77
         /**
78 78
          * 26 hours before to avoid tiemezone problems and dst problems
79 79
          * 30 days after
80 80
          */
81
-        return $caldavClient->getEvents(date('Ymd\THis\Z', time()-93600), date('Ymd\THis\Z', time()+2592000));
81
+        return $caldavClient->getEvents(date('Ymd\THis\Z', time() - 93600), date('Ymd\THis\Z', time() + 2592000));
82 82
     }
83 83
 
84 84
     /**
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
         try
90 90
         {
91 91
             $events = $this->getEvents();
92
-        }catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
92
+        } catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
93 93
         {
94 94
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
95
-            return ;
96
-        }catch(\Illuminate\Contracts\Encryption\DecryptException $e){
95
+            return;
96
+        } catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
97 97
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
98
-            return ;
98
+            return;
99 99
         }
100 100
 
101 101
         /**
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 
106 106
         //remove old timeslots
107 107
         $calendarMain->timeslots()->delete();
108
-        foreach($events as $event){
109
-            if(!($event = $this->parseEvent($event)))
108
+        foreach ($events as $event) {
109
+            if (!($event = $this->parseEvent($event)))
110 110
                 \Event::fire(new CaldavErrorEvent($this->calendar, 'problem during the parsing an event'));
111 111
             $calendarMain->timeslots()->create($event);
112 112
         }
@@ -119,16 +119,16 @@  discard block
 block discarded – undo
119 119
     private function parseEvent(EventInterface $event)
120 120
     {
121 121
         $pattern = "/^((DTSTART;)|(DTEND;))(.*)\$/m";
122
-        if(preg_match_all($pattern, $event->getData(), $matches)){
123
-            if(!isset($matches[4]) || count($matches[4]) != 2)
122
+        if (preg_match_all($pattern, $event->getData(), $matches)) {
123
+            if (!isset($matches[ 4 ]) || count($matches[ 4 ]) != 2)
124 124
                 return null;
125
-            $ret = [];
126
-            if($tmp = $this->parseDate($matches[4][0]))
127
-                $ret['time_start'] = $tmp;
125
+            $ret = [ ];
126
+            if ($tmp = $this->parseDate($matches[ 4 ][ 0 ]))
127
+                $ret[ 'time_start' ] = $tmp;
128 128
             else
129 129
                 return null;
130
-            if($tmp = $this->parseDate($matches[4][1]))
131
-                $ret['time_end'] = $tmp;
130
+            if ($tmp = $this->parseDate($matches[ 4 ][ 1 ]))
131
+                $ret[ 'time_end' ] = $tmp;
132 132
             else
133 133
                 return null;
134 134
             return $ret;
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
     private function parseDate($date)
144 144
     {
145 145
         $pattern = "/^((TZID=)|(VALUE=))(.*):(.*)\$/m";
146
-        if(preg_match_all($pattern, $date, $matches)){
147
-            if($matches[1][0] == 'TZID=')
146
+        if (preg_match_all($pattern, $date, $matches)) {
147
+            if ($matches[ 1 ][ 0 ] == 'TZID=')
148 148
             {
149
-                return \DateTime::createFromFormat('Ymd\THis', $matches[5][0], new \DateTimeZone($matches[4][0]));
150
-            }else if($matches[1][0] == 'VALUE=' && $matches[4][0] == 'DATE')
149
+                return \DateTime::createFromFormat('Ymd\THis', $matches[ 5 ][ 0 ], new \DateTimeZone($matches[ 4 ][ 0 ]));
150
+            } else if ($matches[ 1 ][ 0 ] == 'VALUE=' && $matches[ 4 ][ 0 ] == 'DATE')
151 151
             {
152
-                return \DateTime::createFromFormat('Ymd\THis', $matches[5][0].'T000000');
152
+                return \DateTime::createFromFormat('Ymd\THis', $matches[ 5 ][ 0 ].'T000000');
153 153
             }
154 154
         }
155 155
         return null;
Please login to merge, or discard this patch.
Braces   +21 added lines, -17 removed lines patch added patch discarded remove patch
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
         try
90 90
         {
91 91
             $events = $this->getEvents();
92
-        }catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
92
+        } catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
93 93
         {
94 94
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
95 95
             return ;
96
-        }catch(\Illuminate\Contracts\Encryption\DecryptException $e){
96
+        } catch(\Illuminate\Contracts\Encryption\DecryptException $e){
97 97
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
98 98
             return ;
99 99
         }
@@ -106,10 +106,11 @@  discard block
 block discarded – undo
106 106
         //remove old timeslots
107 107
         $calendarMain->timeslots()->delete();
108 108
         foreach($events as $event){
109
-            if(!($event = $this->parseEvent($event)))
110
-                \Event::fire(new CaldavErrorEvent($this->calendar, 'problem during the parsing an event'));
111
-            else
112
-                $calendarMain->timeslots()->create($event);
109
+            if(!($event = $this->parseEvent($event))) {
110
+                            \Event::fire(new CaldavErrorEvent($this->calendar, 'problem during the parsing an event'));
111
+            } else {
112
+                            $calendarMain->timeslots()->create($event);
113
+            }
113 114
         }
114 115
     }
115 116
 
@@ -121,17 +122,20 @@  discard block
 block discarded – undo
121 122
     {
122 123
         $pattern = "/^((DTSTART;)|(DTEND;))(.*)\$/m";
123 124
         if(preg_match_all($pattern, $event->getData(), $matches)){
124
-            if(!isset($matches[4]) || count($matches[4]) != 2)
125
-                return null;
125
+            if(!isset($matches[4]) || count($matches[4]) != 2) {
126
+                            return null;
127
+            }
126 128
             $ret = [];
127
-            if($tmp = $this->parseDate($matches[4][0]))
128
-                $ret['time_start'] = $tmp;
129
-            else
130
-                return null;
131
-            if($tmp = $this->parseDate($matches[4][1]))
132
-                $ret['time_end'] = $tmp;
133
-            else
134
-                return null;
129
+            if($tmp = $this->parseDate($matches[4][0])) {
130
+                            $ret['time_start'] = $tmp;
131
+            } else {
132
+                            return null;
133
+            }
134
+            if($tmp = $this->parseDate($matches[4][1])) {
135
+                            $ret['time_end'] = $tmp;
136
+            } else {
137
+                            return null;
138
+            }
135 139
             return $ret;
136 140
         }
137 141
         return null;
@@ -148,7 +152,7 @@  discard block
 block discarded – undo
148 152
             if($matches[1][0] == 'TZID=')
149 153
             {
150 154
                 return \DateTime::createFromFormat('Ymd\THis', $matches[5][0], new \DateTimeZone($matches[4][0]));
151
-            }else if($matches[1][0] == 'VALUE=' && $matches[4][0] == 'DATE')
155
+            } else if($matches[1][0] == 'VALUE=' && $matches[4][0] == 'DATE')
152 156
             {
153 157
                 return \DateTime::createFromFormat('Ymd\THis', $matches[5][0].'T000000');
154 158
             }
Please login to merge, or discard this patch.
app/Console/Commands/SyncCaldav/SyncCaldav.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
     {
83 83
         $event = $this->schedule->command('sync:caldav '.$calendar->calendar_id)->withoutOverlapping();
84 84
         if($event->isDue($this->laravel))
85
-             $event->run($this->laravel);
85
+                $event->run($this->laravel);
86 86
     }
87 87
 
88 88
     /**
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     {
54 54
         //
55 55
         $calendarId = $this->argument('calendarId');
56
-        if(is_numeric($calendarId))
56
+        if (is_numeric($calendarId))
57 57
             $this->makeForeground(Caldav::findOrFail($calendarId));
58 58
         else
59 59
             $this->syncAll();
@@ -62,15 +62,15 @@  discard block
 block discarded – undo
62 62
     private function syncAll()
63 63
     {
64 64
         $calendars = Caldav::all();
65
-        if($this->option('background')) {
65
+        if ($this->option('background')) {
66 66
             \Log::debug(self::BACKGROUND_MOD_MEX);
67 67
             $this->info(self::BACKGROUND_MOD_MEX);
68 68
             foreach ($calendars as $calendar)
69 69
                 $this->makeBackground($calendar);
70 70
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
71 71
             $this->info(self::BACKGROUND_COMPLETED_MEX);
72
-        }else
73
-            foreach($calendars as $calendar)
72
+        } else
73
+            foreach ($calendars as $calendar)
74 74
                 $this->makeForeground($calendar);
75 75
     }
76 76
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     private function makeBackground(Caldav $calendar)
82 82
     {
83 83
         $event = $this->schedule->command('sync:caldav '.$calendar->calendar_id)->withoutOverlapping();
84
-        if($event->isDue($this->laravel))
84
+        if ($event->isDue($this->laravel))
85 85
              $event->run($this->laravel);
86 86
     }
87 87
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function makeForeground(Caldav $calendar)
93 93
     {
94
-        $this->info('Sync calendar '. $calendar->calendar_id.' started');
94
+        $this->info('Sync calendar '.$calendar->calendar_id.' started');
95 95
         (new Sync($calendar))->sync();
96
-        $this->info('Sync calendar '. $calendar->calendar_id.' completed');
96
+        $this->info('Sync calendar '.$calendar->calendar_id.' completed');
97 97
     }
98 98
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -53,10 +53,11 @@  discard block
 block discarded – undo
53 53
     {
54 54
         //
55 55
         $calendarId = $this->argument('calendarId');
56
-        if(is_numeric($calendarId))
57
-            $this->makeForeground(Caldav::findOrFail($calendarId));
58
-        else
59
-            $this->syncAll();
56
+        if(is_numeric($calendarId)) {
57
+                    $this->makeForeground(Caldav::findOrFail($calendarId));
58
+        } else {
59
+                    $this->syncAll();
60
+        }
60 61
     }
61 62
 
62 63
     private function syncAll()
@@ -65,13 +66,15 @@  discard block
 block discarded – undo
65 66
         if($this->option('background')) {
66 67
             \Log::debug(self::BACKGROUND_MOD_MEX);
67 68
             $this->info(self::BACKGROUND_MOD_MEX);
68
-            foreach ($calendars as $calendar)
69
-                $this->makeBackground($calendar);
69
+            foreach ($calendars as $calendar) {
70
+                            $this->makeBackground($calendar);
71
+            }
70 72
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
71 73
             $this->info(self::BACKGROUND_COMPLETED_MEX);
72
-        }else
73
-            foreach($calendars as $calendar)
74
+        } else {
75
+                    foreach($calendars as $calendar)
74 76
                 $this->makeForeground($calendar);
77
+        }
75 78
     }
76 79
 
77 80
     /**
@@ -81,8 +84,9 @@  discard block
 block discarded – undo
81 84
     private function makeBackground(Caldav $calendar)
82 85
     {
83 86
         $event = $this->schedule->command('sync:caldav '.$calendar->calendar_id)->withoutOverlapping();
84
-        if($event->isDue($this->laravel))
85
-             $event->run($this->laravel);
87
+        if($event->isDue($this->laravel)) {
88
+                     $event->run($this->laravel);
89
+        }
86 90
     }
87 91
 
88 92
     /**
Please login to merge, or discard this patch.