0013288: Calendar update fails with "no permission"
[tine20] / tine20 / Calendar / Setup / Update / Release10.php
1 <?php
2 /**
3  * Tine 2.0
4  *
5  * @package     Calendar
6  * @subpackage  Setup
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
8  * @copyright   Copyright (c) 2015-2016 Metaways Infosystems GmbH (http://www.metaways.de)
9  * @author      Philipp Schüle <p.schuele@metaways.de>
10  */
11 class Calendar_Setup_Update_Release10 extends Setup_Update_Abstract
12 {
13     /**
14      * update to 10.1
15      * - Update Calendar Import Export definitions
16      */
17     public function update_0()
18     {
19         $release9 = new Calendar_Setup_Update_Release9($this->_backend);
20         $release9->update_7();
21         $this->setApplicationVersion('Calendar', '10.1');
22     }
23
24     /**
25      * fix displaycontainer in organizers attendee records
26      */
27     public function update_1()
28     {
29         $release9 = new Calendar_Setup_Update_Release9($this->_backend);
30         $release9->update_8();
31         $this->setApplicationVersion('Calendar', '10.2');
32     }
33
34     /**
35      * add type and max_number_of_people columns to resources
36      */
37     public function update_2()
38     {
39
40         $declaration = new Setup_Backend_Schema_Field_Xml('
41             <field>
42                 <name>max_number_of_people</name>
43                 <type>integer</type>
44                 <notnull>false</notnull>
45                 <default>null</default>
46             </field>');
47         $this->_backend->addCol('cal_resources', $declaration);
48
49         $declaration = new Setup_Backend_Schema_Field_Xml('
50             <field>
51                 <name>type</name>
52                 <type>text</type>
53                 <length>32</length>
54                 <default>RESOURCE</default>
55                 <notnull>true</notnull>
56             </field>');
57         $this->_backend->addCol('cal_resources', $declaration);
58
59         $resourceController = Calendar_Controller_Resource::getInstance();
60         $user = Setup_Update_Abstract::getSetupFromConfigOrCreateOnTheFly();
61         if ($user) {
62             Tinebase_Core::set(Tinebase_Core::USER, $user);
63
64             $resources = $resourceController->getAll();
65             foreach ($resources as $resource) {
66                 if ($resource->is_location) {
67                     $resource->type = 'ROOM';
68
69                     try {
70                         $resourceController->update($resource);
71                     } catch (Tinebase_Exception_AccessDenied $tead) {
72                         Tinebase_Exception::log($tead);
73                     }
74                 }
75             }
76         }
77
78         $this->setTableVersion('cal_resources', 5);
79         $this->setApplicationVersion('Calendar', '10.3');
80     }
81
82     /**
83      * add resource xprops to container
84      */
85     public function update_3()
86     {
87         $be = new Tinebase_Backend_Sql(array(
88             'modelName' => 'Calendar_Model_Resource',
89             'tableName' => 'cal_resources'
90         ));
91
92         $persistentObserver = Tinebase_Record_PersistentObserver::getInstance();
93
94         foreach($be->getAll() as $resource) {
95             try {
96                 $container = Tinebase_Container::getInstance()->get($resource->container_id);
97                 $container->xprops()['Calendar']['Resource']['resource_id'] = $resource->getId();
98
99                 Tinebase_Container::getInstance()->update($container);
100
101                 $updateObserver = new Tinebase_Model_PersistentObserver(array(
102                     'observable_model'      => 'Tinebase_Model_Container',
103                     'observable_identifier' => $resource->container_id,
104                     'observer_model'        => $this->_modelName,
105                     'observer_identifier'   => $resource->getId(),
106                     'observed_event'        => 'Tinebase_Event_Record_Update'
107                 ));
108                 $persistentObserver->addObserver($updateObserver);
109
110                 $deleteObserver = new Tinebase_Model_PersistentObserver(array(
111                     'observable_model'      => 'Tinebase_Model_Container',
112                     'observable_identifier' => $resource->container_id,
113                     'observer_model'        => $this->_modelName,
114                     'observer_identifier'   => $resource->getId(),
115                     'observed_event'        => 'Tinebase_Event_Record_Delete'
116                 ));
117                 $persistentObserver->addObserver($deleteObserver);
118
119             } catch (Exception $e) {
120                 Tinebase_Exception::log($e, /* suppress trace */ false);
121             }
122         }
123
124         $this->setApplicationVersion('Calendar', '10.4');
125     }
126
127     /**
128      * update to 10.5
129      *
130      * Add fulltext index for description field
131      */
132     public function update_4()
133     {
134         $declaration = new Setup_Backend_Schema_Index_Xml('
135             <index>
136                 <name>description</name>
137                 <fulltext>true</fulltext>
138                 <field>
139                     <name>description</name>
140                 </field>
141             </index>
142         ');
143
144         $this->_backend->addIndex('cal_events', $declaration);
145
146         $this->setTableVersion('cal_events', 13);
147         $this->setApplicationVersion('Calendar', '10.5');
148     }
149
150     /**
151      * update to 10.6
152      *
153      * import export definitions
154      */
155     public function update_5()
156     {
157         $addressbookApplication = Tinebase_Application::getInstance()->getApplicationByName('Calendar');
158         $definitionDirectory = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Export' . DIRECTORY_SEPARATOR . 'definitions' . DIRECTORY_SEPARATOR;
159
160         $dir = new DirectoryIterator($definitionDirectory);
161         foreach ($dir as $fileinfo) {
162             if ($fileinfo->isFile()) {
163                 Tinebase_ImportExportDefinition::getInstance()->updateOrCreateFromFilename(
164                     $fileinfo->getPath() . '/' . $fileinfo->getFilename(),
165                     $addressbookApplication
166                 );
167             }
168         }
169
170         $this->setApplicationVersion('Calendar', '10.6');
171     }
172
173     /**
174      * update to 10.7
175      *
176      * import export definitions
177      */
178     public function update_6()
179     {
180         $scheduler = Tinebase_Core::getScheduler();
181         Calendar_Scheduler_Task::addTentativeNotificationTask($scheduler);
182
183         $this->setApplicationVersion('Calendar', '10.7');
184     }
185
186     public function update_7()
187     {}
188 }