/ansel/migration/9_ansel_upgrade_sqlng.php

https://github.com/ewandor/horde · PHP · 198 lines · 159 code · 14 blank · 25 comment · 0 complexity · 840d2fc8dea2329b346c8898af4182ad MD5 · raw file

  1. <?php
  2. /**
  3. * @author Michael J Rubinsky <mrubinsk@horde.org>
  4. * @category Horde
  5. * @license http://www.horde.org/licenses/gpl GPL
  6. * @package Ansel
  7. */
  8. /**
  9. * Adds tables for the Sqlng share driver.
  10. *
  11. * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
  12. *
  13. * See the enclosed file COPYING for license information (GPL). If you
  14. * did not receive this file, see http://www.horde.org/licenses/gpl.
  15. *
  16. * @author Michael J Rubinsky <mrubinsk@horde.org>
  17. * @category Horde
  18. * @license http://www.horde.org/licenses/gpl GPL
  19. * @package Ansel
  20. */
  21. class AnselUpgradeSqlng extends Horde_Db_Migration_Base
  22. {
  23. /**
  24. * Upgrade.
  25. */
  26. public function up()
  27. {
  28. $t = $this->createTable('ansel_sharesng', array('autoincrementKey' => 'share_id'));
  29. $t->column('share_name', 'string', array('limit' => 255, 'null' => false));
  30. $t->column('share_owner', 'string', array('limit' => 255));
  31. $t->column('share_flags', 'integer', array('default' => 0, 'null' => false));
  32. $t->column('share_parents', 'text');
  33. $t->column('perm_creator_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  34. $t->column('perm_creator_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  35. $t->column('perm_creator_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  36. $t->column('perm_creator_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  37. $t->column('perm_default_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  38. $t->column('perm_default_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  39. $t->column('perm_default_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  40. $t->column('perm_default_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  41. $t->column('perm_guest_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  42. $t->column('perm_guest_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  43. $t->column('perm_guest_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  44. $t->column('perm_guest_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  45. $t->column('attribute_name', 'string', array('limit' => 255, 'null' => false));
  46. $t->column('attribute_desc', 'string', array('limit' => 255));
  47. $t->column('attribute_default', 'integer');
  48. $t->column('attribute_default_type', 'string', array('limit' => 6));
  49. $t->column('attribute_default_prettythumb', 'text');
  50. $t->column('attribute_style', 'text');
  51. $t->column('attribute_last_modified', 'integer');
  52. $t->column('attribute_date_created', 'integer');
  53. $t->column('attribute_images', 'integer', array('null' => false, 'default' => 0));
  54. $t->column('attribute_has_subgalleries', 'integer', array('null' => false, 'default' => 0));
  55. $t->column('attribute_slug', 'string', array('limit' => 255));
  56. $t->column('attribute_age', 'integer', array('null' => false, 'default' => 0));
  57. $t->column('attribute_download', 'string', array('limit' => 255));
  58. $t->column('attribute_passwd', 'string', array('limit' => 255));
  59. $t->column('attribute_faces', 'integer', array('null' => false, 'default' => 0));
  60. $t->column('attribute_view_mode', 'string', array('limit' => 255, 'default' => 'Normal', 'null' => false));
  61. $t->end();
  62. $this->addIndex('ansel_sharesng', array('share_name'));
  63. $this->addIndex('ansel_sharesng', array('share_owner'));
  64. $this->addIndex('ansel_sharesng', array('perm_creator_' . Horde_Perms::SHOW));
  65. $this->addIndex('ansel_sharesng', array('perm_creator_' . Horde_Perms::READ));
  66. $this->addIndex('ansel_sharesng', array('perm_creator_' . Horde_Perms::EDIT));
  67. $this->addIndex('ansel_sharesng', array('perm_creator_' . Horde_Perms::DELETE));
  68. $this->addIndex('ansel_sharesng', array('perm_default_' . Horde_Perms::SHOW));
  69. $this->addIndex('ansel_sharesng', array('perm_default_' . Horde_Perms::READ));
  70. $this->addIndex('ansel_sharesng', array('perm_default_' . Horde_Perms::EDIT));
  71. $this->addIndex('ansel_sharesng', array('perm_default_' . Horde_Perms::DELETE));
  72. $this->addIndex('ansel_sharesng', array('perm_guest_' . Horde_Perms::SHOW));
  73. $this->addIndex('ansel_sharesng', array('perm_guest_' . Horde_Perms::READ));
  74. $this->addIndex('ansel_sharesng', array('perm_guest_' . Horde_Perms::EDIT));
  75. $this->addIndex('ansel_sharesng', array('perm_guest_' . Horde_Perms::DELETE));
  76. $t = $this->createTable('ansel_sharesng_groups', array('autoincrementKey' => false));
  77. $t->column('share_id', 'integer', array('null' => false));
  78. $t->column('group_uid', 'string', array('limit' => 255, 'null' => false));
  79. $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  80. $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  81. $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  82. $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  83. $t->end();
  84. $this->addIndex('ansel_sharesng_groups', array('share_id'));
  85. $this->addIndex('ansel_sharesng_groups', array('group_uid'));
  86. $this->addIndex('ansel_sharesng_groups', array('perm_' . Horde_Perms::SHOW));
  87. $this->addIndex('ansel_sharesng_groups', array('perm_' . Horde_Perms::READ));
  88. $this->addIndex('ansel_sharesng_groups', array('perm_' . Horde_Perms::EDIT));
  89. $this->addIndex('ansel_sharesng_groups', array('perm_' . Horde_Perms::DELETE));
  90. $t = $this->createTable('ansel_sharesng_users', array('autoincrementKey' => false));
  91. $t->column('share_id', 'integer', array('null' => false));
  92. $t->column('user_uid', 'string', array('limit' => 255, 'null' => false));
  93. $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  94. $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  95. $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  96. $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  97. $t->end();
  98. $this->addIndex('ansel_sharesng_users', array('share_id'));
  99. $this->addIndex('ansel_sharesng_users', array('user_uid'));
  100. $this->addIndex('ansel_sharesng_users', array('perm_' . Horde_Perms::SHOW));
  101. $this->addIndex('ansel_sharesng_users', array('perm_' . Horde_Perms::READ));
  102. $this->addIndex('ansel_sharesng_users', array('perm_' . Horde_Perms::EDIT));
  103. $this->addIndex('ansel_sharesng_users', array('perm_' . Horde_Perms::DELETE));
  104. $this->dataUp();
  105. }
  106. /**
  107. * Downgrade
  108. */
  109. public function down()
  110. {
  111. $this->dropTable('ansel_sharesng');
  112. $this->dropTable('ansel_sharesng_groups');
  113. $this->dropTable('ansel_sharesng_users');
  114. }
  115. public function dataUp()
  116. {
  117. $whos = array('creator', 'default', 'guest');
  118. $perms = array(Horde_Perms::SHOW,
  119. Horde_Perms::READ,
  120. Horde_Perms::EDIT,
  121. Horde_Perms::DELETE);
  122. $sql = 'INSERT INTO ansel_sharesng (share_id, share_owner, share_parents, share_name, '
  123. . 'share_flags, attribute_name, attribute_desc, attribute_default, '
  124. . 'attribute_default_type, attribute_default_prettythumb, attribute_style, '
  125. . 'attribute_last_modified, attribute_date_created, attribute_images, '
  126. . 'attribute_has_subgalleries, attribute_slug, attribute_age, '
  127. . 'attribute_download, attribute_passwd, attribute_faces, attribute_view_mode';
  128. $count = 0;
  129. foreach ($whos as $who) {
  130. foreach ($perms as $perm) {
  131. $sql .= ', perm_' . $who . '_' . $perm;
  132. $count++;
  133. }
  134. }
  135. $sql .= ') VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?' . str_repeat(', ?', $count) . ')';
  136. foreach ($this->select('SELECT * FROM ansel_shares') as $share) {
  137. $values = array($share['share_id'],
  138. $share['share_owner'],
  139. $share['share_parents'],
  140. $share['share_name'],
  141. $share['share_flags'],
  142. $share['attribute_name'],
  143. $share['attribute_desc'],
  144. $share['attribute_default'],
  145. $share['attribute_default_type'],
  146. $share['attribute_default_prettythumb'],
  147. $share['attribute_style'],
  148. $share['attribute_last_modified'],
  149. $share['attribute_date_created'],
  150. $share['attribute_images'],
  151. $share['attribute_has_subgalleries'],
  152. $share['attribute_slug'],
  153. $share['attribute_age'],
  154. $share['attribute_download'],
  155. $share['attribute_passwd'],
  156. $share['attribute_faces'],
  157. $share['attribute_view_mode']
  158. );
  159. foreach ($whos as $who) {
  160. foreach ($perms as $perm) {
  161. $values[] = (bool)($share['perm_' . $who] & $perm);
  162. }
  163. }
  164. $this->insert($sql, $values, null, 'share_id', $share['share_id']);
  165. }
  166. foreach (array('user', 'group') as $what) {
  167. $sql = 'INSERT INTO ansel_sharesng_' . $what . 's (share_id, ' . $what . '_uid';
  168. $count = 0;
  169. foreach ($perms as $perm) {
  170. $sql .= ', perm_' . $perm;
  171. $count++;
  172. }
  173. $sql .= ') VALUES (?, ?' . str_repeat(', ?', $count) . ')';
  174. foreach ($this->select('SELECT * FROM ansel_shares_' . $what . 's') as $share) {
  175. $values = array($share['share_id'],
  176. $share[$what . '_uid']);
  177. foreach ($perms as $perm) {
  178. $values[] = (bool)($share['perm'] & $perm);
  179. }
  180. $this->insert($sql, $values);
  181. }
  182. }
  183. }
  184. }