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: AlphaDAO::commit();
180: $this->setStatusMessage(AlphaView::displayUpdateMessage('Tags recreated on the '.$temp->getFriendlyClassName().' class.'));
181:
182: self::$logger->info('Tags recreated on the ['.$params['clearTaggedClass'].'] class (time taken ['.round(microtime(true)-$startTime, 5).'] seconds).');
183: }catch (AlphaException $e) {
184: self::$logger->error($e->getMessage());
185: AlphaDAO::rollback();
186: }
187:
188: AlphaDAO::disconnect();
189: }
190:
191: $this->doGET($params);
192: }catch(SecurityException $e) {
193: self::$logger->warn($e->getMessage());
194: throw new ResourceNotAllowedException($e->getMessage());
195: }catch(IllegalArguementException $e) {
196: self::$logger->error($e->getMessage());
197: throw new ResourceNotFoundException($e->getMessage());
198: }
199:
200: echo AlphaView::displayPageFoot($this);
201: self::$logger->debug('<<doPOST');
202: }
203:
204: 205: 206: 207: 208: 209:
210: private function regenerateTagsOnBOs($BOs) {
211: foreach ($BOs as $BO) {
212: foreach($BO->get('taggedAttributes') as $tagged) {
213:
214: $tags = TagObject::tokenize($BO->get($tagged), get_class($BO), $BO->getOID());
215:
216: foreach($tags as $tag) {
217: try {
218: $tag->save();
219: }catch(ValidationException $e){
220: 221: 222: 223:
224: }
225: }
226: }
227: }
228: }
229:
230: 231: 232: 233: 234:
235: public function after_displayPageHead_callback() {
236: $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
237:
238: return $menu;
239: }
240: }
241:
242:
243: if ('TagManager.php' == basename($_SERVER['PHP_SELF'])) {
244: $controller = new TagManager();
245:
246: if(!empty($_POST)) {
247: $controller->doPOST($_REQUEST);
248: }else{
249: $controller->doGET($_GET);
250: }
251: }
252:
253: ?>