/nag/migration/6_nag_upgrade_sqlng.php

https://github.com/ewandor/horde · PHP · 156 lines · 125 code · 12 blank · 19 comment · 0 complexity · e2138d09242137d3f2b255bbffbfa24b MD5 · raw file

  1. <?php
  2. /**
  3. * Adds tables for the Sqlng share driver.
  4. *
  5. * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
  6. *
  7. * See the enclosed file COPYING for license information (GPL). If you
  8. * did not receive this file, see http://www.horde.org/licenses/gpl.
  9. *
  10. * @author Jan Schneider <jan@horde.org>
  11. * @category Horde
  12. * @license http://www.horde.org/licenses/gpl GPL
  13. * @package Nag
  14. */
  15. class NagUpgradeSqlng extends Horde_Db_Migration_Base
  16. {
  17. /**
  18. * Upgrade.
  19. */
  20. public function up()
  21. {
  22. $t = $this->createTable('nag_sharesng', array('autoincrementKey' => 'share_id'));
  23. $t->column('share_name', 'string', array('limit' => 255, 'null' => false));
  24. $t->column('share_owner', 'string', array('limit' => 255));
  25. $t->column('share_flags', 'integer', array('default' => 0, 'null' => false));
  26. $t->column('perm_creator_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  27. $t->column('perm_creator_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  28. $t->column('perm_creator_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  29. $t->column('perm_creator_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  30. $t->column('perm_default_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  31. $t->column('perm_default_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  32. $t->column('perm_default_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  33. $t->column('perm_default_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  34. $t->column('perm_guest_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  35. $t->column('perm_guest_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  36. $t->column('perm_guest_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  37. $t->column('perm_guest_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  38. $t->column('attribute_name', 'string', array('limit' => 255, 'null' => false));
  39. $t->column('attribute_desc', 'string', array('limit' => 255));
  40. $t->column('attribute_color', 'string', array('limit' => 7));
  41. $t->end();
  42. $this->addIndex('nag_sharesng', array('share_name'));
  43. $this->addIndex('nag_sharesng', array('share_owner'));
  44. $this->addIndex('nag_sharesng', array('perm_creator_' . Horde_Perms::SHOW));
  45. $this->addIndex('nag_sharesng', array('perm_creator_' . Horde_Perms::READ));
  46. $this->addIndex('nag_sharesng', array('perm_creator_' . Horde_Perms::EDIT));
  47. $this->addIndex('nag_sharesng', array('perm_creator_' . Horde_Perms::DELETE));
  48. $this->addIndex('nag_sharesng', array('perm_default_' . Horde_Perms::SHOW));
  49. $this->addIndex('nag_sharesng', array('perm_default_' . Horde_Perms::READ));
  50. $this->addIndex('nag_sharesng', array('perm_default_' . Horde_Perms::EDIT));
  51. $this->addIndex('nag_sharesng', array('perm_default_' . Horde_Perms::DELETE));
  52. $this->addIndex('nag_sharesng', array('perm_guest_' . Horde_Perms::SHOW));
  53. $this->addIndex('nag_sharesng', array('perm_guest_' . Horde_Perms::READ));
  54. $this->addIndex('nag_sharesng', array('perm_guest_' . Horde_Perms::EDIT));
  55. $this->addIndex('nag_sharesng', array('perm_guest_' . Horde_Perms::DELETE));
  56. $t = $this->createTable('nag_sharesng_groups', array('autoincrementKey' => false));
  57. $t->column('share_id', 'integer', array('null' => false));
  58. $t->column('group_uid', 'string', array('limit' => 255, 'null' => false));
  59. $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  60. $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  61. $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  62. $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  63. $t->end();
  64. $this->addIndex('nag_sharesng_groups', array('share_id'));
  65. $this->addIndex('nag_sharesng_groups', array('group_uid'));
  66. $this->addIndex('nag_sharesng_groups', array('perm_' . Horde_Perms::SHOW));
  67. $this->addIndex('nag_sharesng_groups', array('perm_' . Horde_Perms::READ));
  68. $this->addIndex('nag_sharesng_groups', array('perm_' . Horde_Perms::EDIT));
  69. $this->addIndex('nag_sharesng_groups', array('perm_' . Horde_Perms::DELETE));
  70. $t = $this->createTable('nag_sharesng_users', array('autoincrementKey' => false));
  71. $t->column('share_id', 'integer', array('null' => false));
  72. $t->column('user_uid', 'string', array('limit' => 255, 'null' => false));
  73. $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
  74. $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
  75. $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
  76. $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
  77. $t->end();
  78. $this->addIndex('nag_sharesng_users', array('share_id'));
  79. $this->addIndex('nag_sharesng_users', array('user_uid'));
  80. $this->addIndex('nag_sharesng_users', array('perm_' . Horde_Perms::SHOW));
  81. $this->addIndex('nag_sharesng_users', array('perm_' . Horde_Perms::READ));
  82. $this->addIndex('nag_sharesng_users', array('perm_' . Horde_Perms::EDIT));
  83. $this->addIndex('nag_sharesng_users', array('perm_' . Horde_Perms::DELETE));
  84. $this->dataUp();
  85. }
  86. /**
  87. * Downgrade
  88. */
  89. public function down()
  90. {
  91. $this->dropTable('nag_sharesng');
  92. $this->dropTable('nag_sharesng_groups');
  93. $this->dropTable('nag_sharesng_users');
  94. }
  95. public function dataUp()
  96. {
  97. $whos = array('creator', 'default', 'guest');
  98. $perms = array(Horde_Perms::SHOW,
  99. Horde_Perms::READ,
  100. Horde_Perms::EDIT,
  101. Horde_Perms::DELETE);
  102. $sql = 'INSERT INTO nag_sharesng (share_id, share_name, share_owner, share_flags, attribute_name, attribute_desc, attribute_color';
  103. $count = 0;
  104. foreach ($whos as $who) {
  105. foreach ($perms as $perm) {
  106. $sql .= ', perm_' . $who . '_' . $perm;
  107. $count++;
  108. }
  109. }
  110. $sql .= ') VALUES (?, ?, ?, ?, ?, ?, ?' . str_repeat(', ?', $count) . ')';
  111. foreach ($this->select('SELECT * FROM nag_shares') as $share) {
  112. $values = array($share['share_id'],
  113. $share['share_name'],
  114. $share['share_owner'],
  115. $share['share_flags'],
  116. $share['attribute_name'],
  117. $share['attribute_desc'],
  118. $share['attribute_color']);
  119. foreach ($whos as $who) {
  120. foreach ($perms as $perm) {
  121. $values[] = (bool)($share['perm_' . $who] & $perm);
  122. }
  123. }
  124. $this->insert($sql, $values, null, 'share_id', $share['share_id']);
  125. }
  126. foreach (array('user', 'group') as $what) {
  127. $sql = 'INSERT INTO nag_sharesng_' . $what . 's (share_id, ' . $what . '_uid';
  128. $count = 0;
  129. foreach ($perms as $perm) {
  130. $sql .= ', perm_' . $perm;
  131. $count++;
  132. }
  133. $sql .= ') VALUES (?, ?' . str_repeat(', ?', $count) . ')';
  134. foreach ($this->select('SELECT * FROM nag_shares_' . $what . 's') as $share) {
  135. $values = array($share['share_id'],
  136. $share[$what . '_uid']);
  137. foreach ($perms as $perm) {
  138. $values[] = (bool)($share['perm'] & $perm);
  139. }
  140. $this->insert($sql, $values);
  141. }
  142. }
  143. }
  144. }