1: <?php
2:
3:
4: if(!isset($config)) {
5: require_once '../util/AlphaConfig.inc';
6: $config = AlphaConfig::getInstance();
7:
8: require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
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: class TagManager extends AlphaController implements AlphaControllerInterface {
57: 58: 59: 60: 61: 62:
63: private static $logger = null;
64:
65: 66: 67: 68: 69:
70: public function __construct() {
71: self::$logger = new Logger('TagManager');
72: self::$logger->debug('>>__construct()');
73:
74: global $config;
75:
76:
77: parent::__construct('Admin');
78:
79: $this->setTitle('Tag Manager');
80:
81: self::$logger->debug('<<__construct');
82: }
83:
84: 85: 86: 87: 88: 89:
90: public function doGET($params) {
91: self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
92:
93: global $config;
94:
95: echo AlphaView::displayPageHead($this);
96:
97: echo '<h2>Listing business objects which are tagged</h2>';
98:
99: $BOs = AlphaDAO::getBOClassNames();
100:
101: foreach ($BOs as $BO) {
102: AlphaDAO::loadClassDef($BO);
103: $temp = new $BO;
104: if($temp->isTagged()) {
105: $tag = new TagObject();
106: $count = count($tag->loadAllByAttribute('taggedClass', $BO));
107: echo '<h3>'.$temp->getFriendlyClassName().' object is tagged ('.$count.' tags found)</h3>';
108:
109: $js = "$('#dialogDiv').text('Are you sure you want to delete all tags attached to the ".$temp->getFriendlyClassName().
110: " class, and have them re-created?');
111: $('#dialogDiv').dialog({
112: buttons: {
113: 'OK': function(event, ui) {
114: $('#clearTaggedClass').attr('value', '".$BO."');
115: $('#clearForm').submit();
116: },
117: 'Cancel': function(event, ui) {
118: $(this).dialog('close');
119: }
120: }
121: })
122: $('#dialogDiv').dialog('open');
123: return false;";
124: $button = new Button($js, "Re-create tags", "clearBut".$BO);
125:
126: echo $button->render();
127: }
128: }
129:
130: AlphaDAO::disconnect();
131:
132: echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="clearForm">';
133: echo '<input type="hidden" name="clearTaggedClass" id="clearTaggedClass"/>';
134: echo AlphaView::renderSecurityFields();
135: echo '</form>';
136:
137: echo AlphaView::displayPageFoot($this);
138:
139: self::$logger->debug('<<doGET');
140: }
141:
142: 143: 144: 145: 146: 147: 148:
149: public function doPOST($params) {
150: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
151:
152: try {
153:
154: if(!$this->checkSecurityFields())
155: throw new SecurityException('This page cannot accept post data from remote servers!');
156:
157: if (isset($params['clearTaggedClass']) && $params['clearTaggedClass'] != '') {
158: try {
159: self::$logger->info('About to start rebuilding the tags for the class ['.$params['clearTaggedClass'].']');
160: $startTime = microtime(true);
161:
162: AlphaDAO::loadClassDef($params['clearTaggedClass']);
163: $temp = new $params['clearTaggedClass'];
164: $BOs = $temp->loadAll();
165:
166: self::$logger->info('Loaded all of the BOs (elapsed time ['.round(microtime(true)-$startTime, 5).'] seconds)');
167:
168: AlphaDAO::begin();
169:
170: $tag = new TagObject();
171: $tag->deleteAllByAttribute('taggedClass', $params['clearTaggedClass']);
172:
173: self::$logger->info('Deleted all of the old tags (elapsed time ['.round(microtime(true)-$startTime, 5).'] seconds)');
174:
175: $this->regenerateTagsOnBOs($BOs);
176:
177: self::$logger->info('Saved all of the new tags (elapsed time ['.round(microtime(true)-$startTime, 5).'] seconds)');
178:
179: self::$logger->action('Tags recreated on the ['.$params['clearTaggedClass'].'] class');
180:
181: AlphaDAO::commit();
182: $this->setStatusMessage(AlphaView::displayUpdateMessage('Tags recreated on the '.$temp->getFriendlyClassName().' class.'));
183:
184: self::$logger->info('Tags recreated on the ['.$params['clearTaggedClass'].'] class (time taken ['.round(microtime(true)-$startTime, 5).'] seconds).');
185: }catch (AlphaException $e) {
186: self::$logger->error($e->getMessage());
187: AlphaDAO::rollback();
188: }
189:
190: AlphaDAO::disconnect();
191: }
192:
193: $this->doGET($params);
194: }catch(SecurityException $e) {
195: self::$logger->warn($e->getMessage());
196: throw new ResourceNotAllowedException($e->getMessage());
197: }catch(IllegalArguementException $e) {
198: self::$logger->error($e->getMessage());
199: throw new ResourceNotFoundException($e->getMessage());
200: }
201:
202: echo AlphaView::displayPageFoot($this);
203: self::$logger->debug('<<doPOST');
204: }
205:
206: 207: 208: 209: 210: 211:
212: private function regenerateTagsOnBOs($BOs) {
213: foreach ($BOs as $BO) {
214: foreach($BO->get('taggedAttributes') as $tagged) {
215:
216: $tags = TagObject::tokenize($BO->get($tagged), get_class($BO), $BO->getOID());
217:
218: foreach($tags as $tag) {
219: try {
220: $tag->save();
221: }catch(ValidationException $e){
222: 223: 224: 225:
226: }
227: }
228: }
229: }
230: }
231:
232: 233: 234: 235: 236:
237: public function after_displayPageHead_callback() {
238: $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
239:
240: return $menu;
241: }
242: }
243:
244:
245: if ('TagManager.php' == basename($_SERVER['PHP_SELF'])) {
246: $controller = new TagManager();
247:
248: if(!empty($_POST)) {
249: $controller->doPOST($_REQUEST);
250: }else{
251: $controller->doGET($_GET);
252: }
253: }
254:
255: ?>