PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/web/system/PermissionsModule/Installer.php

https://github.com/390/core
PHP | 152 lines | 82 code | 15 blank | 55 comment | 1 complexity | bab6dc60c4ba70d5737dfc75366584af MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright Zikula Foundation 2009 - Zikula Application Framework
  4. *
  5. * This work is contributed to the Zikula Foundation under one or more
  6. * Contributor Agreements and licensed to You under the following license:
  7. *
  8. * @license GNU/LGPLv3 (or at your option, any later version).
  9. * @package Zikula
  10. *
  11. * Please see the NOTICE file distributed with this source code for further
  12. * information regarding copyright and licensing.
  13. */
  14. namespace PermissionsModule;
  15. use PermissionsModule\Entity\Permission;
  16. class Installer extends \Zikula\Framework\AbstractInstaller
  17. {
  18. /**
  19. * initialise the permissions module
  20. *
  21. * This function is only ever called once during the lifetime of a particular
  22. * module instance.
  23. * This function MUST exist in the pninit file for a module
  24. *
  25. * @return bool true on success, false otherwise
  26. */
  27. public function install()
  28. {
  29. // create the table
  30. try {
  31. \DoctrineHelper::createSchema($this->entityManager, array('Permission'));
  32. } catch (\Exception $e) {
  33. return false;
  34. }
  35. // Create any default for this module
  36. $this->defaultdata();
  37. // Initialisation successful
  38. return true;
  39. }
  40. /**
  41. * upgrade the permissions module from an old version
  42. *
  43. * This function must consider all the released versions of the module!
  44. * If the upgrade fails at some point, it returns the last upgraded version.
  45. *
  46. * @param string $oldVersion version number string to upgrade from
  47. * @return mixed true on success, last valid version string or false if fails
  48. */
  49. public function upgrade($oldversion)
  50. {
  51. // Upgrade dependent on old version number
  52. switch ($oldversion) {
  53. case '1.1':
  54. // future upgrade routines
  55. }
  56. // Update successful
  57. return true;
  58. }
  59. /**
  60. * delete the permissions module
  61. *
  62. * This function is only ever called once during the lifetime of a particular
  63. * module instance
  64. *
  65. * Since the permissions module should never be deleted we'all always return false here
  66. *
  67. * @return bool false
  68. */
  69. public function uninstall()
  70. {
  71. // Deletion not allowed
  72. return false;
  73. }
  74. /**
  75. * create the default data for the permissions module
  76. *
  77. * This function is only ever called once during the lifetime of a particular
  78. * module instance
  79. *
  80. * @return bool false
  81. */
  82. public function defaultdata()
  83. {
  84. $record = new Permission;
  85. $record['gid'] = 2;
  86. $record['sequence'] = 1;
  87. $record['realm'] = 0;
  88. $record['component'] = '.*';
  89. $record['instance'] = '.*';
  90. $record['level'] = 800;
  91. $record['bond'] = 0;
  92. $this->entityManager->persist($record);
  93. $record = new Permission;
  94. $record['gid'] = -1;
  95. $record['sequence'] = 2;
  96. $record['realm'] = 0;
  97. $record['component'] = 'ExtendedMenublock::';
  98. $record['instance'] = '1:1:';
  99. $record['level'] = 0;
  100. $record['bond'] = 0;
  101. $this->entityManager->persist($record);
  102. $record = new Permission;
  103. $record['gid'] = 1;
  104. $record['sequence'] = 3;
  105. $record['realm'] = 0;
  106. $record['component'] = '.*';
  107. $record['instance'] = '.*';
  108. $record['level'] = 300;
  109. $record['bond'] = 0;
  110. $this->entityManager->persist($record);
  111. $record = new Permission;
  112. $record['gid'] = 0;
  113. $record['sequence'] = 4;
  114. $record['realm'] = 0;
  115. $record['component'] = 'ExtendedMenublock::';
  116. $record['instance'] = '1:(1|2|3):';
  117. $record['level'] = 0;
  118. $record['bond'] = 0;
  119. $this->entityManager->persist($record);
  120. $record = new Permission;
  121. $record['gid'] = 0;
  122. $record['sequence'] = 5;
  123. $record['realm'] = 0;
  124. $record['component'] = '.*';
  125. $record['instance'] = '.*';
  126. $record['level'] = 200;
  127. $record['bond'] = 0;
  128. $this->entityManager->persist($record);
  129. $this->entityManager->flush();
  130. $this->setVar('filter', 1);
  131. $this->setVar('warnbar', 1);
  132. $this->setVar('rowview', 20);
  133. $this->setVar('rowedit', 20);
  134. $this->setVar('lockadmin', 1);
  135. $this->setVar('adminid', 1);
  136. }
  137. }