PageRenderTime 28ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tine20/Addressbook/Setup/Update/Release0.php

https://github.com/testruby/Tine-2.0-Open-Source-Groupware-and-CRM
PHP | 381 lines | 282 code | 41 blank | 58 comment | 0 complexity | 6ceb409de8c9bb421559f5939beefbb4 MD5 | raw file
  1. <?php
  2. /**
  3. * Tine 2.0
  4. *
  5. * @package Addressbook
  6. * @license http://www.gnu.org/licenses/agpl.html AGPL3
  7. * @copyright Copyright (c) 2008 Metaways Infosystems GmbH (http://www.metaways.de)
  8. * @author Lars Kneschke <l.kneschke@metaways.de>
  9. */
  10. class Addressbook_Setup_Update_Release0 extends Setup_Update_Abstract
  11. {
  12. /**
  13. * this function does nothing. It's from the dark ages without setup being functional
  14. */
  15. public function update_1()
  16. {
  17. $this->validateTableVersion('addressbook', '1');
  18. $this->setApplicationVersion('Addressbook', '0.2');
  19. }
  20. /**
  21. * updates what???
  22. *
  23. * @todo add changed fields
  24. */
  25. public function update_2()
  26. {
  27. $this->validateTableVersion('addressbook', '1');
  28. $this->setTableVersion('addressbook', '2');
  29. $this->setApplicationVersion('Addressbook', '0.3');
  30. }
  31. /**
  32. * correct modlog field definitions
  33. */
  34. public function update_3()
  35. {
  36. $declaration = new Setup_Backend_Schema_Field_Xml('
  37. <field>
  38. <name>created_by</name>
  39. <type>integer</type>
  40. </field>');
  41. $this->_backend->alterCol('addressbook', $declaration);
  42. $declaration = new Setup_Backend_Schema_Field_Xml('
  43. <field>
  44. <name>creation_time</name>
  45. <type>datetime</type>
  46. </field>');
  47. $this->_backend->alterCol('addressbook', $declaration);
  48. $declaration = new Setup_Backend_Schema_Field_Xml('
  49. <field>
  50. <name>last_modified_by</name>
  51. <type>integer</type>
  52. </field>');
  53. $this->_backend->alterCol('addressbook', $declaration);
  54. $declaration = new Setup_Backend_Schema_Field_Xml('
  55. <field>
  56. <name>last_modified_time</name>
  57. <type>datetime</type>
  58. </field>');
  59. $this->_backend->alterCol('addressbook', $declaration);
  60. $declaration = new Setup_Backend_Schema_Field_Xml('
  61. <field>
  62. <name>is_deleted</name>
  63. <type>boolean</type>
  64. <default>false</default>
  65. </field>');
  66. $this->_backend->alterCol('addressbook', $declaration);
  67. $declaration = new Setup_Backend_Schema_Field_Xml('
  68. <field>
  69. <name>deleted_by</name>
  70. <type>integer</type>
  71. </field>');
  72. $this->_backend->alterCol('addressbook', $declaration);
  73. $declaration = new Setup_Backend_Schema_Field_Xml('
  74. <field>
  75. <name>deleted_time</name>
  76. <type>datetime</type>
  77. </field>');
  78. $this->_backend->alterCol('addressbook', $declaration);
  79. $this->setApplicationVersion('Addressbook', '0.4');
  80. }
  81. /**
  82. * add salutation_id field and table
  83. *
  84. */
  85. public function update_4()
  86. {
  87. $declaration = new Setup_Backend_Schema_Field_Xml('
  88. <field>
  89. <name>salutation_id</name>
  90. <type>text</type>
  91. <length>64</length>
  92. <notnull>false</notnull>
  93. </field>');
  94. try {
  95. $this->_backend->addCol('addressbook', $declaration);
  96. } catch (Exception $e) {
  97. echo "salutation_id already exists.\n";
  98. }
  99. $tableDefinition = ('
  100. <table>
  101. <name>addressbook_salutations</name>
  102. <version>1</version>
  103. <declaration>
  104. <field>
  105. <name>id</name>
  106. <type>text</type>
  107. <length>40</length>
  108. <notnull>true</notnull>
  109. </field>
  110. <field>
  111. <name>name</name>
  112. <type>text</type>
  113. <length>32</length>
  114. <notnull>true</notnull>
  115. </field>
  116. <field>
  117. <name>gender</name>
  118. <type>enum</type>
  119. <value>male</value>
  120. <value>female</value>
  121. <value>other</value>
  122. <notnull>true</notnull>
  123. </field>
  124. <index>
  125. <name>id</name>
  126. <primary>true</primary>
  127. <unique>true</unique>
  128. <field>
  129. <name>id</name>
  130. </field>
  131. </index>
  132. </declaration>
  133. </table>
  134. ');
  135. $table = Setup_Backend_Schema_Table_Factory::factory('String', $tableDefinition);
  136. try {
  137. $this->_backend->createTable($table);
  138. } catch (Exception $e) {
  139. echo "salutation table already exists.\n";
  140. }
  141. // add initial values
  142. $backend = new Addressbook_Backend_Salutation();
  143. $maleSalutation = new Addressbook_Model_Salutation(array(
  144. 'id' => 1,
  145. 'name' => 'Mr',
  146. 'gender' => Addressbook_Model_Salutation::GENDER_MALE
  147. ));
  148. $backend->create($maleSalutation);
  149. $femaleSalutation = new Addressbook_Model_Salutation(array(
  150. 'id' => 2,
  151. 'name' => 'Ms',
  152. 'gender' => Addressbook_Model_Salutation::GENDER_FEMALE
  153. ));
  154. $backend->create($femaleSalutation);
  155. $companySalutation = new Addressbook_Model_Salutation(array(
  156. 'id' => 3,
  157. 'name' => 'Company',
  158. 'gender' => Addressbook_Model_Salutation::GENDER_OTHER
  159. ));
  160. $backend->create($companySalutation);
  161. $this->setApplicationVersion('Addressbook', '0.5');
  162. }
  163. /**
  164. * rename column owner to container_id in addressbook table
  165. *
  166. */
  167. public function update_5()
  168. {
  169. try {
  170. $this->_backend->dropForeignKey('addressbook', 'addressbook_container_id');
  171. } catch (Exception $e) {
  172. echo " Foreign key 'addressbook_container_id' didn't exist.\n";
  173. }
  174. try {
  175. $this->_backend->dropIndex('addressbook', 'owner');
  176. } catch (Exception $e) {
  177. echo " Index 'owner' didn't exist.\n";
  178. }
  179. $declaration = new Setup_Backend_Schema_Field_Xml('
  180. <field>
  181. <name>container_id</name>
  182. <type>integer</type>
  183. <notnull>false</notnull>
  184. </field>');
  185. $this->_backend->alterCol('addressbook', $declaration, 'owner');
  186. $declaration = new Setup_Backend_Schema_Index_Xml('
  187. <index>
  188. <name>container_id</name>
  189. <field>
  190. <name>container_id</name>
  191. </field>
  192. </index>
  193. ');
  194. $this->_backend->addIndex('addressbook', $declaration);
  195. $declaration = new Setup_Backend_Schema_Index_Xml('
  196. <index>
  197. <name>addressbook::container_id--container::id</name>
  198. <field>
  199. <name>container_id</name>
  200. </field>
  201. <foreign>true</foreign>
  202. <reference>
  203. <table>container</table>
  204. <field>id</field>
  205. </reference>
  206. </index>
  207. ');
  208. $this->_backend->addForeignKey('addressbook', $declaration);
  209. $this->setTableVersion('addressbook', '4');
  210. $this->setApplicationVersion('Addressbook', '0.6');
  211. }
  212. /**
  213. * rename column owner to container_id in addressbook table
  214. *
  215. */
  216. public function update_6()
  217. {
  218. $declaration = new Setup_Backend_Schema_Field_Xml('
  219. <field>
  220. <name>account_id</name>
  221. <type>text</type>
  222. <length>64</length>
  223. <notnull>false</notnull>
  224. </field>');
  225. $this->_backend->alterCol('addressbook', $declaration, 'account_id');
  226. $this->setTableVersion('addressbook', '5');
  227. $this->setApplicationVersion('Addressbook', '0.7');
  228. }
  229. /**
  230. * the formeer update had the wrong field length
  231. * added foreign key to accounts table
  232. *
  233. */
  234. public function update_7()
  235. {
  236. $declaration = new Setup_Backend_Schema_Field_Xml('
  237. <field>
  238. <name>account_id</name>
  239. <type>text</type>
  240. <length>40</length>
  241. <notnull>false</notnull>
  242. </field>');
  243. $this->_backend->alterCol('addressbook', $declaration, 'account_id');
  244. $declaration = new Setup_Backend_Schema_Index_Xml('
  245. <index>
  246. <name>addressbook::account_id--accounts::id</name>
  247. <field>
  248. <name>account_id</name>
  249. </field>
  250. <foreign>true</foreign>
  251. <reference>
  252. <table>accounts</table>
  253. <field>id</field>
  254. </reference>
  255. <onupdate>cascade</onupdate>
  256. <ondelete>cascade</ondelete>
  257. </index>
  258. ');
  259. $this->_backend->addForeignKey('addressbook', $declaration);
  260. $this->setTableVersion('addressbook', '6');
  261. $this->setApplicationVersion('Addressbook', '0.8');
  262. }
  263. /**
  264. * change all fields which store account ids from integer to string
  265. *
  266. */
  267. public function update_8()
  268. {
  269. $declaration = new Setup_Backend_Schema_Field_Xml('
  270. <field>
  271. <name>created_by</name>
  272. <type>text</type>
  273. <length>40</length>
  274. </field>');
  275. $this->_backend->alterCol('addressbook', $declaration, 'created_by');
  276. $declaration = new Setup_Backend_Schema_Field_Xml('
  277. <field>
  278. <name>last_modified_by</name>
  279. <type>text</type>
  280. <length>40</length>
  281. </field>');
  282. $this->_backend->alterCol('addressbook', $declaration, 'last_modified_by');
  283. $declaration = new Setup_Backend_Schema_Field_Xml('
  284. <field>
  285. <name>deleted_by</name>
  286. <type>text</type>
  287. <length>40</length>
  288. </field>');
  289. $this->_backend->alterCol('addressbook', $declaration, 'deleted_by');
  290. $this->setApplicationVersion('Addressbook', '0.9');
  291. }
  292. /**
  293. * change all fields which store account ids from integer to string
  294. *
  295. */
  296. public function update_9()
  297. {
  298. $this->_backend->dropForeignKey('addressbook', 'addressbook::account_id--accounts::id');
  299. $declaration = new Setup_Backend_Schema_Index_Xml('
  300. <index>
  301. <name>addressbook::account_id--accounts::id</name>
  302. <field>
  303. <name>account_id</name>
  304. </field>
  305. <foreign>true</foreign>
  306. <reference>
  307. <table>accounts</table>
  308. <field>id</field>
  309. <onupdate>cascade</onupdate>
  310. <ondelete>cascade</ondelete>
  311. </reference>
  312. </index>
  313. ');
  314. $this->_backend->addForeignKey('addressbook', $declaration);
  315. $this->setTableVersion('addressbook', '7');
  316. $this->setApplicationVersion('Addressbook', '0.10');
  317. }
  318. /**
  319. * give anyone GRANT_READ to internal addressbook
  320. *
  321. * @todo remove that
  322. */
  323. public function update_10()
  324. {
  325. // $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_INTERNAL);
  326. // Tinebase_Container::getInstance()->addGrants($internalAddressbook, Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE, '0', array(
  327. // Tinebase_Model_Grants::GRANT_READ
  328. // ), TRUE);
  329. $this->setApplicationVersion('Addressbook', '0.11');
  330. }
  331. /**
  332. * update to 2.0
  333. * @return void
  334. */
  335. public function update_11()
  336. {
  337. $this->setApplicationVersion('Addressbook', '2.0');
  338. }
  339. }