51042e22fd10c814080b7e9e6bbd7791bd7442dc
[tine20] / tine20 / Timetracker / Setup / Update / Release10.php
1 <?php
2 /**
3  * Tine 2.0
4  *
5  * @package     Timetracker
6  * @subpackage  Setup
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
8  * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
9  * @author      Michael Spahn <m.spahn@metaways.de>
10  */
11 class Timetracker_Setup_Update_Release10 extends Setup_Update_Abstract
12 {
13     /**
14      * update to 10.1
15      *
16      * Add fulltext index to field description of timesheet
17      */
18     public function update_0()
19     {
20         if ($this->getTableVersion('timetracker_timesheet') < 6) {
21             $declaration = new Setup_Backend_Schema_Index_Xml('
22                 <index>
23                     <name>description</name>
24                     <fulltext>true</fulltext>
25                     <field>
26                         <name>description</name>
27                     </field>
28                 </index>
29             ');
30
31             try {
32                 $this->_backend->addIndex('timetracker_timesheet', $declaration);
33             } catch (Exception $e) {
34                 Tinebase_Exception::log($e);
35             }
36
37             $this->setTableVersion('timetracker_timesheet', '6');
38         }
39         $this->setApplicationVersion('Timetracker', '10.1');
40     }
41
42     /**
43      * update to 10.2
44      *
45      * Add fulltext index to field description of timeaccount
46      */
47     public function update_1()
48     {
49         if ($this->getTableVersion('timetracker_timesheet') < 11) {
50             $declaration = new Setup_Backend_Schema_Index_Xml('
51                 <index>
52                     <name>description</name>
53                     <fulltext>true</fulltext>
54                     <field>
55                         <name>description</name>
56                     </field>
57                 </index>
58             ');
59
60             try {
61                 $this->_backend->addIndex('timetracker_timeaccount', $declaration);
62             } catch (Exception $e) {
63                 Tinebase_Exception::log($e);
64             }
65             $this->setTableVersion('timetracker_timeaccount', '11');
66         }
67         $this->setApplicationVersion('Timetracker', '10.2');
68     }
69
70     public function update_2()
71     {
72         $this->setApplicationVersion('Timetracker', '10.3');
73     }
74
75     /**
76      * update to 10.4
77      *
78      * @return void
79      */
80     public function update_3()
81     {
82         if (! $this->_backend->tableExists('timetracker_timeaccount_fav')) {
83             $declaration = new Setup_Backend_Schema_Table_Xml('<table>
84                 <name>timetracker_timeaccount_fav</name>
85                 <version>1</version>
86                 <declaration>
87                     <field>
88                         <name>id</name>
89                         <type>text</type>
90                         <length>40</length>
91                         <notnull>true</notnull>
92                     </field>
93                     <field>
94                         <name>account_id</name>
95                         <type>text</type>
96                         <length>40</length>
97                         <notnull>true</notnull>
98                     </field>
99                     <field>
100                         <name>timeaccount_id</name>
101                         <type>text</type>
102                         <length>40</length>
103                         <notnull>false</notnull>
104                     </field>
105                     <field>
106                         <name>created_by</name>
107                         <type>text</type>
108                         <length>40</length>
109                     </field>
110                     <field>
111                         <name>creation_time</name>
112                         <type>datetime</type>
113                     </field>
114                     <field>
115                         <name>last_modified_by</name>
116                         <type>text</type>
117                         <length>40</length>
118                     </field>
119                     <field>
120                         <name>last_modified_time</name>
121                         <type>datetime</type>
122                     </field>
123                     <field>
124                         <name>is_deleted</name>
125                         <type>boolean</type>
126                         <default>false</default>
127                     </field>
128                     <field>
129                         <name>deleted_by</name>
130                         <type>text</type>
131                         <length>40</length>
132                     </field>
133                     <field>
134                         <name>deleted_time</name>
135                         <type>datetime</type>
136                     </field>
137                     <index>
138                         <name>id</name>
139                         <primary>true</primary>
140                         <field>
141                             <name>id</name>
142                         </field>
143                     </index>
144                     <index>
145                         <name>timesheet_favorites--timesheet_id::id</name>
146                         <field>
147                             <name>timeaccount_id</name>
148                         </field>
149                         <foreign>true</foreign>
150                         <reference>
151                             <table>timetracker_timeaccount</table>
152                             <field>id</field>
153                         </reference>
154                     </index>
155                     <index>
156                         <name>timesheet_favorites--account_id::id</name>
157                         <field>
158                             <name>account_id</name>
159                         </field>
160                         <foreign>true</foreign>
161                         <reference>
162                             <table>accounts</table>
163                             <field>id</field>
164                             <ondelete>CASCADE</ondelete>
165                         </reference>
166                     </index>
167                 </declaration>
168             </table>');
169
170             $this->_backend->createTable($declaration, 'Timetracker', 'timetracker_timeaccount_fav');
171             $this->setTableVersion('timetracker_timeaccount_fav', 1);
172         }
173         $this->setApplicationVersion('Timetracker', '10.4');
174     }
175
176     /**
177      * 0012470: Don't shorten description in export
178      */
179     public function update_4()
180     {
181         Setup_Controller::getInstance()->createImportExportDefinitions(Tinebase_Application::getInstance()->getApplicationByName('Timetracker'));
182         $this->setApplicationVersion('Timetracker', '10.5');
183     }
184
185     /**
186      * update to 10.6
187      *
188      * Add fulltext index to field description of timesheet
189      * - re-run update 0 + 1 because 2017.02 added update 2 + 3
190      */
191     public function update_5()
192     {
193         $this->update_0();
194         $this->update_1();
195         $this->setApplicationVersion('Timetracker', '10.6');
196     }
197 }