0010080: caldav client / import caldav tasks/task lists via CLI
[tine20] / tine20 / Tasks / Import / CalDav / Client.php
1 <?php
2 //./tine20.php --username unittest --method Tasks.importCalDav url="https://ical.metaways.de:8443" caldavuserfile=caldavuserfile.csv
3
4 /**
5  * Tine 2.0
6  * 
7  * @package     Tasks
8  * @subpackage  Import
9  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
10  * @author      Philipp Schüle <p.schuele@metaways.de>
11  * @copyright   Copyright (c) 2014 Metaways Infosystems GmbH (http://www.metaways.de)
12  */
13
14 /**
15  * Tasks_Import_CalDAV
16  * 
17  * @package     Tasks
18  * @subpackage  Import
19  * 
20  * @todo        move generic parts from Calendar_Import_CalDav_Client to Tinebase and extend Tinebase_Import_CalDav_Client
21  * @todo        finish update
22  */
23 class Tasks_Import_CalDav_Client extends Calendar_Import_CalDav_Client
24 {
25     protected $component = 'VTODO';
26     protected $skipComonent = 'VEVENT';
27     protected $modelName = 'Tasks_Model_Task';
28     protected $appName = 'Tasks';
29     protected $webdavFrontend = 'Tasks_Frontend_WebDAV_Task';
30     
31     /**
32      * 
33      * @param string $onlyCurrentUserOrganizer
34      * @return boolean
35      * 
36      * @todo generalize
37      * @todo implement for tasks
38      */
39     public function updateAllCalendarData($onlyCurrentUserOrganizer = false)
40     {
41 //         if (count($this->calendarICSs) < 1 && ! $this->findAllCalendarICSs()) {
42 //             if (Tinebase_Core::isLogLevel(Zend_Log::INFO))
43 //                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' no calendars found for: ' . $this->userName);
44 //             return false;
45 //         }
46         
47 //         $newICSs = array();
48 //         $calendarEventBackend = Tasks_Controller_Task::getInstance()->getBackend();
49         
50 //         foreach ($this->calendarICSs as $calUri => $calICSs) {
51 //             $start = 0;
52 //             $max = count($calICSs);
53 //             $etags = array();
54 //             do {
55 //                 $requestEnd = '';
56 //                 for ($i = $start; $i < $max && $i < ($this->maxBulkRequest+$start); ++$i) {
57 //                     $requestEnd .= '  <a:href>' . $calICSs[$i] . "</a:href>\n";
58 //                 }
59 //                 $start = $i;
60 //                 $requestEnd .= '</b:calendar-multiget>';
61 //                 $result = $this->calDavRequest('REPORT', $calUri, self::getEventETagsRequest . $requestEnd, 1);
62                 
63 //                 foreach ($result as $key => $value) {
64 //                     if (isset($value['{DAV:}getetag'])) {
65 //                         $name = explode('/', $key);
66 //                         $name = end($name);
67 //                         $id = $this->_getEventIdFromName($name);
68 //                         $etags[$key] = array( 'id' => $id, 'etag' => $value['{DAV:}getetag']);
69 //                     }
70 //                 }
71 //             } while($start < $max);
72             
73 //             //check etags
74 //             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' '
75 //                 . ' Got ' . count($etags) . ' etags');
76 //             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' '
77 //                 . ' etags: ' . print_r($etags, true));
78             
79 //             // @todo find out deleted events
80 //             foreach ($etags as $ics => $data) {
81 //                 try {
82 //                     $etagCheck = $calendarEventBackend->checkETag($data['id'], $data['etag']);
83 //                     if ($etagCheck) {
84 //                         continue; // same
85 //                     } else {
86 //                         $eventExists = true; // different
87 //                     }
88 //                 } catch (Tinebase_Exception_NotFound $tenf) {
89 //                     $eventExists = false;
90 //                 }
91                 
92 //                 if (!isset($newICSs[$calUri])) {
93 //                     $newICSs[$calUri] = array();
94 //                     $this->existingRecordIds[$calUri] = array();
95 //                 }
96 //                 $newICSs[$calUri][] = $ics;
97 //                 if ($eventExists) {
98 //                     $this->existingRecordIds[$calUri][] = $data['id'];
99 //                 }
100 //             }
101 //         }
102         
103 //         if (($count = count($newICSs)) > 0) {
104 //             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' 
105 //                     . $count . ' calendar(s) changed for: ' . $this->userName);
106 //             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' 
107 //                     . ' events changed: ' . print_r($newICSs, true));
108 //             $this->calendarICSs = $newICSs;
109 //             $this->importAllCalendarData($onlyCurrentUserOrganizer, /* $update = */ true);
110 //         } else {
111 //             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE))
112 //                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' no changes found for: ' . $this->userName);
113 //         }
114     }
115     
116     /**
117      * (non-PHPdoc)
118      * @see Calendar_Import_CalDav_Client::_setEtags()
119      * 
120      * @todo implement
121      */
122     protected function _setEtags($etags)
123     {
124 //         $calendarEventBackend = Tinebase_Core::getApplicationInstance($this->appName, $this->modelName)->getBackend();
125 //         $calendarEventBackend->setETags($etags);
126     }
127
128     protected function _getAllGrants()
129     {
130         return array(
131             Tinebase_Model_Grants::GRANT_READ => true,
132             Tinebase_Model_Grants::GRANT_ADD=> true,
133             Tinebase_Model_Grants::GRANT_EDIT=> true,
134             Tinebase_Model_Grants::GRANT_DELETE=> true,
135             Tinebase_Model_Grants::GRANT_EXPORT=> true,
136             Tinebase_Model_Grants::GRANT_SYNC=> true,
137             Tinebase_Model_Grants::GRANT_ADMIN=> true,
138         );
139     }
140     
141     protected function _getFreeBusyGrants()
142     {
143         return array(
144         );
145     }
146     
147     protected function _getReadGrants()
148     {
149         return array(
150             Tinebase_Model_Grants::GRANT_READ=> true,
151             Tinebase_Model_Grants::GRANT_EXPORT=> true,
152             Tinebase_Model_Grants::GRANT_SYNC=> true,
153         );
154     }
155 }