PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Acl/Console/Command/ExtrasShell.php

https://github.com/kareypowell/croogo
PHP | 173 lines | 109 code | 10 blank | 54 comment | 1 complexity | bf4c781d5751abd997f15ae9c3541820 MD5 | raw file
  1. <?php
  2. /**
  3. * Acl Extras Shell.
  4. *
  5. * Enhances the existing Acl Shell with a few handy functions
  6. *
  7. * Copyright 2008, Mark Story.
  8. * 694B The Queensway
  9. * toronto, ontario M8Y 1K9
  10. *
  11. * Licensed under The MIT License
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright 2008-2010, Mark Story.
  15. * @link http://mark-story.com
  16. * @author Mark Story <mark@mark-story.com>
  17. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  18. */
  19. App::uses('AclExtras', 'Acl.Lib');
  20. /**
  21. * Shell for ACO extras
  22. *
  23. * @package Croogo.Acl.Console.Command
  24. */
  25. class ExtrasShell extends Shell {
  26. /**
  27. * Contains arguments parsed from the command line.
  28. *
  29. * @var array
  30. * @access public
  31. */
  32. public $args;
  33. /**
  34. * AclExtras instance
  35. */
  36. public $AclExtras;
  37. /**
  38. * Constructor
  39. */
  40. public function __construct($stdout = null, $stderr = null, $stdin = null) {
  41. parent::__construct($stdout, $stderr, $stdin);
  42. $this->AclExtras = new AclExtras();
  43. }
  44. /**
  45. * Start up And load Acl Component / Aco model
  46. *
  47. * @return void
  48. **/
  49. public function startup() {
  50. parent::startup();
  51. $this->AclExtras->startup();
  52. $this->AclExtras->Shell = $this;
  53. }
  54. /**
  55. * Sync the ACO table
  56. *
  57. * @return void
  58. **/
  59. public function aco_sync() {
  60. $this->AclExtras->aco_sync($this->params);
  61. }
  62. /**
  63. * Sync the ACO table for contents
  64. *
  65. * @return void
  66. */
  67. public function aco_sync_contents() {
  68. $this->AclExtras->args = $this->args;
  69. $this->AclExtras->aco_update_contents($this->params);
  70. }
  71. /**
  72. * Updates the Aco Tree with new controller actions.
  73. *
  74. * @return void
  75. **/
  76. public function aco_update() {
  77. $this->AclExtras->aco_update($this->params);
  78. return true;
  79. }
  80. public function getOptionParser() {
  81. $plugin = array(
  82. 'short' => 'p',
  83. 'help' => __d('croogo', 'Plugin to process'),
  84. );
  85. return parent::getOptionParser()
  86. ->description(__d('croogo', "Better manage, and easily synchronize you application's ACO tree"))
  87. ->addSubcommand('aco_update', array(
  88. 'parser' => array(
  89. 'options' => compact('plugin'),
  90. ),
  91. 'help' => __d('croogo', 'Add new ACOs for new controllers and actions. Does not remove nodes from the ACO table.')
  92. ))
  93. ->addSubcommand('aco_sync', array(
  94. 'parser' => array(
  95. 'options' => compact('plugin'),
  96. ),
  97. 'help' => __d('croogo', 'Perform a full sync on the ACO table.' .
  98. 'Will create new ACOs or missing controllers and actions.' .
  99. 'Will also remove orphaned entries that no longer have a matching controller/action')
  100. ))
  101. ->addSubcommand('aco_sync_contents', array(
  102. 'help' => __d('croogo', 'Perform a full content sync on the ACO table.' .
  103. 'Will create new ACOs or missing contents.' .
  104. 'Will also remove orphaned entries that no longer have a matching contents'),
  105. 'parser' => array(
  106. 'arguments' => array(
  107. 'model' => array(
  108. 'required' => true,
  109. 'help' => __d('croogo', 'The content model name '),
  110. )
  111. ),
  112. ),
  113. ))
  114. ->addSubcommand('verify', array(
  115. 'help' => __d('croogo', 'Verify the tree structure of either your Aco or Aro Trees'),
  116. 'parser' => array(
  117. 'arguments' => array(
  118. 'type' => array(
  119. 'required' => true,
  120. 'help' => __d('croogo', 'The type of tree to verify'),
  121. 'choices' => array('aco', 'aro')
  122. )
  123. )
  124. )
  125. ))
  126. ->addSubcommand('recover', array(
  127. 'help' => __d('croogo', 'Recover a corrupted Tree'),
  128. 'parser' => array(
  129. 'arguments' => array(
  130. 'type' => array(
  131. 'required' => true,
  132. 'help' => __d('croogo', 'The type of tree to recover'),
  133. 'choices' => array('aco', 'aro')
  134. )
  135. )
  136. )
  137. ));
  138. }
  139. /**
  140. * Verify a Acl Tree
  141. *
  142. * @param string $type The type of Acl Node to verify
  143. * @access public
  144. * @return void
  145. */
  146. public function verify() {
  147. $this->AclExtras->args = $this->args;
  148. return $this->AclExtras->verify();
  149. }
  150. /**
  151. * Recover an Acl Tree
  152. *
  153. * @param string $type The Type of Acl Node to recover
  154. * @access public
  155. * @return void
  156. */
  157. public function recover() {
  158. $this->AclExtras->args = $this->args;
  159. $this->AclExtras->recover();
  160. }
  161. }