c6a95eede1b42c496f5b854dd23192d436f75a44
[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      * fix displaycontainer in organizers attendee records
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         Tinebase_Core::set(Tinebase_Core::USER, $user);
62
63         $resources = $resourceController->getAll();
64         foreach ($resources as $resource) {
65             if ($resource->is_location) {
66                 $resource->type = 'ROOM';
67
68                 $resourceController->update($resource);
69             }
70         }
71
72         $this->setTableVersion('cal_resources', 5);
73         $this->setApplicationVersion('Calendar', '10.3');
74     }
75
76     /**
77      * add resource xprops to container
78      */
79     public function update_3()
80     {
81         $be = new Tinebase_Backend_Sql(array(
82             'modelName' => 'Calendar_Model_Resource',
83             'tableName' => 'cal_resources'
84         ));
85
86         $persistentObserver = Tinebase_Record_PersistentObserver::getInstance();
87
88         foreach($be->getAll() as $resource) {
89             try {
90                 $container = Tinebase_Container::getInstance()->get($resource->container_id);
91                 $container->xprops()['Calendar']['Resource']['resource_id'] = $resource->getId();
92
93                 Tinebase_Container::getInstance()->update($container);
94
95                 $updateObserver = new Tinebase_Model_PersistentObserver(array(
96                     'observable_model'      => 'Tinebase_Model_Container',
97                     'observable_identifier' => $resource->container_id,
98                     'observer_model'        => $this->_modelName,
99                     'observer_identifier'   => $resource->getId(),
100                     'observed_event'        => 'Tinebase_Event_Record_Update'
101                 ));
102                 $persistentObserver->addObserver($updateObserver);
103
104                 $deleteObserver = new Tinebase_Model_PersistentObserver(array(
105                     'observable_model'      => 'Tinebase_Model_Container',
106                     'observable_identifier' => $resource->container_id,
107                     'observer_model'        => $this->_modelName,
108                     'observer_identifier'   => $resource->getId(),
109                     'observed_event'        => 'Tinebase_Event_Record_Delete'
110                 ));
111                 $persistentObserver->addObserver($deleteObserver);
112
113             } catch (Exception $e) {
114                 Tinebase_Exception::log($e, /* suppress trace */ false);
115             }
116         }
117
118         $this->setApplicationVersion('Calendar', '10.4');
119     }
120
121     /**
122      * update to 10.5
123      *
124      * Add fulltext index for description field
125      */
126     public function update_4()
127     {
128         $declaration = new Setup_Backend_Schema_Index_Xml('
129             <index>
130                 <name>description</name>
131                 <fulltext>true</fulltext>
132                 <field>
133                     <name>description</name>
134                 </field>
135             </index>
136         ');
137
138         $this->_backend->addIndex('cal_events', $declaration);
139
140         $this->setTableVersion('cal_events', 13);
141         $this->setApplicationVersion('Calendar', '10.5');
142     }
143
144     /**
145      * update to 10.6
146      *
147      * import export definitions
148      */
149     public function update_5()
150     {
151         $addressbookApplication = Tinebase_Application::getInstance()->getApplicationByName('Calendar');
152         $definitionDirectory = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Export' . DIRECTORY_SEPARATOR . 'definitions' . DIRECTORY_SEPARATOR;
153
154         $dir = new DirectoryIterator($definitionDirectory);
155         foreach ($dir as $fileinfo) {
156             if ($fileinfo->isFile()) {
157                 Tinebase_ImportExportDefinition::getInstance()->updateOrCreateFromFilename(
158                     $fileinfo->getPath() . '/' . $fileinfo->getFilename(),
159                     $addressbookApplication
160                 );
161             }
162         }
163
164         $this->setApplicationVersion('Calendar', '10.6');
165     }
166
167     /**
168      * update to 10.7
169      *
170      * import export definitions
171      */
172     public function update_6()
173     {
174         $scheduler = Tinebase_Core::getScheduler();
175         Calendar_Scheduler_Task::addTentativeNotificationTask($scheduler);
176
177         $this->setApplicationVersion('Calendar', '10.7');
178     }
179
180     public function update_7()
181     {}
182 }