croogo /Acl/Console/Command/ExtrasShell.php

Language PHP Lines 174
MD5 Hash bf4c781d5751abd997f15ae9c3541820
Repository https://github.com/kareypowell/croogo.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
 * Acl Extras Shell.
 *
 * Enhances the existing Acl Shell with a few handy functions
 *
 * Copyright 2008, Mark Story.
 * 694B The Queensway
 * toronto, ontario M8Y 1K9
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright 2008-2010, Mark Story.
 * @link http://mark-story.com
 * @author Mark Story <mark@mark-story.com>
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 */

App::uses('AclExtras', 'Acl.Lib');

/**
 * Shell for ACO extras
 *
 * @package     Croogo.Acl.Console.Command
 */
class ExtrasShell extends Shell {

/**
 * Contains arguments parsed from the command line.
 *
 * @var array
 * @access public
 */
	public $args;

/**
 * AclExtras instance
 */
	public $AclExtras;

/**
 * Constructor
 */
	public function __construct($stdout = null, $stderr = null, $stdin = null) {
		parent::__construct($stdout, $stderr, $stdin);
		$this->AclExtras = new AclExtras();
	}

/**
 * Start up And load Acl Component / Aco model
 *
 * @return void
 **/
	public function startup() {
		parent::startup();
		$this->AclExtras->startup();
		$this->AclExtras->Shell = $this;
	}

/**
 * Sync the ACO table
 *
 * @return void
 **/
	public function aco_sync() {
		$this->AclExtras->aco_sync($this->params);
	}

/**
 * Sync the ACO table for contents
 *
 * @return void
 */
	public function aco_sync_contents() {
		$this->AclExtras->args = $this->args;
		$this->AclExtras->aco_update_contents($this->params);
	}

/**
 * Updates the Aco Tree with new controller actions.
 *
 * @return void
 **/
	public function aco_update() {
		$this->AclExtras->aco_update($this->params);
		return true;
	}

	public function getOptionParser() {
		$plugin = array(
			'short' => 'p',
			'help' => __d('croogo', 'Plugin to process'),
		);
		return parent::getOptionParser()
			->description(__d('croogo', "Better manage, and easily synchronize you application's ACO tree"))
			->addSubcommand('aco_update', array(
				'parser' => array(
					'options' => compact('plugin'),
				),
				'help' => __d('croogo', 'Add new ACOs for new controllers and actions. Does not remove nodes from the ACO table.')
			))
			->addSubcommand('aco_sync', array(
				'parser' => array(
					'options' => compact('plugin'),
				),
				'help' => __d('croogo', 'Perform a full sync on the ACO table.' .
					'Will create new ACOs or missing controllers and actions.' .
					'Will also remove orphaned entries that no longer have a matching controller/action')
			))
			->addSubcommand('aco_sync_contents', array(
				'help' => __d('croogo', 'Perform a full content sync on the ACO table.' .
					'Will create new ACOs or missing contents.' .
					'Will also remove orphaned entries that no longer have a matching contents'),
				'parser' => array(
					'arguments' => array(
						'model' => array(
							'required' => true,
							'help' => __d('croogo', 'The content model name '),
						)
					),
				),
			))
			->addSubcommand('verify', array(
				'help' => __d('croogo', 'Verify the tree structure of either your Aco or Aro Trees'),
				'parser' => array(
					'arguments' => array(
						'type' => array(
							'required' => true,
							'help' => __d('croogo', 'The type of tree to verify'),
							'choices' => array('aco', 'aro')
						)
					)
				)
			))
			->addSubcommand('recover', array(
				'help' => __d('croogo', 'Recover a corrupted Tree'),
				'parser' => array(
					'arguments' => array(
						'type' => array(
							'required' => true,
							'help' => __d('croogo', 'The type of tree to recover'),
							'choices' => array('aco', 'aro')
						)
					)
				)
			));
	}

/**
 * Verify a Acl Tree
 *
 * @param string $type The type of Acl Node to verify
 * @access public
 * @return void
 */
	public function verify() {
		$this->AclExtras->args = $this->args;
		return $this->AclExtras->verify();
	}
/**
 * Recover an Acl Tree
 *
 * @param string $type The Type of Acl Node to recover
 * @access public
 * @return void
 */
	public function recover() {
		$this->AclExtras->args = $this->args;
		$this->AclExtras->recover();
	}

}
Back to Top