Changeset 11641
- Timestamp:
- 08/20/07 16:39:59 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midgard/data/midgard_admin_sitewizard_cli.php
r11619 r11641 19 19 $structure_creator = $sitewizard->initialize_structure_creation('983e66725acd11db845a197adaa843af43af'); 20 20 $structure_creator->read_config('structure_config.inc'); 21 $structure_creator->set_creation_root_topic('6d3af3384be911dcb7b0b3bf4b275d0d5d0d'); 21 //$structure_creator->set_creation_root_topic('6d3af3384be911dcb7b0b3bf4b275d0d5d0d'); 22 $structure_creator->create_creation_root_topic('6d3af3384be911dcb7b0b3bf4b275d0d5d0d', "test", "Test", "net.nehmer.static", array("koe", "koe", "koe")); 23 //$structure_creator->set_creation_root_group('94f058364f0f11dc93f803ebc4b67c0c7c0c'); 24 $structure_creator->create_creation_root_group('94f058364f0f11dc93f803ebc4b67c0c7c0c', "testgroup8"); 22 25 $structure_creator->execute(); 23 26 } trunk/midgard/data/midgard_admin_sitewizard_creator.php
r11619 r11641 9 9 abstract class midgard_admin_sitewizard_creator 10 10 { 11 protected $varbose ;11 protected $varbose = false; 12 12 13 protected $parent_link; 14 15 public function __construct() 13 protected $parent_link = null; 14 15 protected $next_link = null; 16 17 protected $start_chain = true; 18 19 public function __construct($parent_link = null) 16 20 { 17 $this->verbose = false; 18 $this->parent_link = null; 21 $this->parent_link = $parent_link; 19 22 } 20 23 … … 22 25 { 23 26 unset($this->parent_link); 27 unset($this->next_link); 24 28 } 25 29 26 //abstract protected function shutdown();30 abstract protected function cleanup(); 27 31 28 32 abstract protected function read_config($path); … … 39 43 } 40 44 45 protected function start_chain($start) 46 { 47 $this->start_chain = $start; 48 } 49 41 50 protected function get_parent_link() 42 51 { trunk/midgard/data/midgard_admin_sitewizard_creator_structure.php
r11619 r11641 12 12 class midgard_admin_sitewizard_creator_structure extends midgard_admin_sitewizard_creator 13 13 { 14 private $host; 15 16 private $host_creator; 17 18 private $root_topic; 19 20 private $root_page; 21 22 private $creation_root_topic; 23 24 private $sitegroup; 14 private $host = null; 15 16 private $host_creator = null; 17 18 private $root_topic = null; 19 20 private $root_page = null; 21 22 private $creation_root_topic = null; 23 24 private $creation_root_group = null; 25 26 private $sitegroup = null; 25 27 26 private $config ;28 private $config = null; 27 29 28 private $start_chain; 29 30 30 private $structure = null; 31 32 private $created_groups = array(); 33 31 34 public function __construct($host_creator = null) 32 35 { 33 36 // Always a good idea to run parent constructor 34 parent::__construct(); 35 $this->parent_link = $host_creator; 36 $this->start_chain = true; 37 $this->config = null; 37 parent::__construct($host_creator); 38 38 } 39 39 … … 41 41 { 42 42 parent::__destruct(); 43 } 44 45 protected function cleanup() 46 { 47 $this->verbose('Cleaning up!'); 48 43 49 } 44 50 … … 89 95 } 90 96 91 public function disable_start_chain()92 {93 $this->start_chain = false;94 }95 96 97 public function read_config($path) 97 98 { … … 113 114 } 114 115 115 public function set_midcom_privilege() 116 { 117 116 public function set_creation_root_group($group_guid) 117 { 118 if (!$this->creation_root_group = new midgard_group($group_guid)) 119 { 120 throw new midgard_admin_sitewizard_exception("Failed to set root group for structure creation GUID: " 121 . $group_guid . " Reason: " . mgd_errstr()); 122 123 return true; 124 } 125 else 126 { 127 $this->verbose("Setting group for structure creation GUID: " . $group_guid); 128 129 return true; 130 } 118 131 } 119 132 … … 135 148 } 136 149 137 // TODO 138 public function create_creation_root_topic($topic_guid, $topic_title = "", $component = "", $parameters = array()) 150 public function create_creation_root_group($owner_guid, $group_name) 151 { 152 $this->verbose("Creating a root group for group structure creation under group GUID: " . $owner_guid); 153 154 $owner_group = new midgard_group($owner_guid); 155 156 $qb = new midgard_query_builder('midgard_group'); 157 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 158 $qb->add_constraint('owner', '=', $owner_group->id); 159 $qb->add_constraint('name', '=', $group_name); 160 161 $groups = $qb->execute(); 162 163 if (count($groups) > 0) 164 { 165 $this->verbose("Group \"" . $group_name . "\" GUID: " . $groups[0]->guid 166 . " already exists. Setting as root group for structure creation."); 167 168 $this->creation_root_group = $groups[0]; 169 170 return true; 171 } 172 else 173 { 174 $this->creation_root_group = new midgard_group(); 175 $this->creation_root_group->owner = $owner_group->id; 176 $this->creation_root_group->sitegroup = $this->sitegroup->id; 177 $this->creation_root_group->name = $group_name; 178 179 if (!$this->creation_root_group->create()) 180 { 181 throw new midgard_admin_sitewizard_exception("Failed to create root group for group structure creation under group GUID: " 182 . $this->creation_root_group->guid); 183 } 184 else 185 { 186 187 return true; 188 } 189 } 190 } 191 192 public function create_creation_root_topic($topic_guid, $topic_name = "", $topic_title = "", $component = "", $parameters = array()) 139 193 { 140 194 $this->verbose('Creating a root topic for structure creation'); … … 143 197 144 198 $this->creation_root_topic = new midgard_topic(); 145 $this->creation_root_topic->title = "Koe";146 $this->creation_root_topic->name = "koe";199 $this->creation_root_topic->title = $topic_title; 200 $this->creation_root_topic->name = $topic_name; 147 201 $this->creation_root_topic->sitegroup = $this->sitegroup->id; 202 $this->creation_root_topic->component = $component; 203 $this->creation_root_topic->up = $topic->id; 148 204 149 205 if (!$this->creation_root_topic->create()) … … 155 211 { 156 212 $this->verbose("Created root topic for structure creation GUID: " . $this->ceration_root_topic->guid); 157 } 213 214 // Setting additional parameters 215 foreach ($parameters as $domain => $parameter) 216 { 217 foreach ($parameter as $name => $value) 218 { 219 $this->creation_root_topic->parameter($domain, $name, $value); 220 } 221 } 222 } 223 } 224 225 private function replace($string) 226 { 227 $result = str_replace('__HOSTNAME__', $this->host->name, $string); 228 $result = str_replace('__HOSTTITLE__', $this->root_page->title, $result); 229 230 return $result; 231 } 232 233 private function create_topic_structure_recursive($nodes, $parent_node) 234 { 235 foreach ($nodes as $node) 236 { 237 $this->verbose("Creating topic \"" . $this->replace($node['title']) . "\" under parent topic GUID: " 238 . $parent_node->guid); 239 240 $topic = new midgard_topic(); 241 $topic->up = $parent_node->id; 242 $topic->name = $this->replace($node['name']); 243 $topic->title = $this->replace($node['title']); 244 $topic->sitegroup = $this->sitegroup->id; 245 $topic->component = $node['component']; 246 247 if (!$topic->create()) 248 { 249 throw new midagard_admin_sitewizard_exception("Failed to create topic \"" . $topic->title . "\" under parent GUID: " 250 . $parent_node->guid); 251 } 252 else 253 { 254 // Setting additional parameters 255 if (isset($node['parameters']) && count($node['parameters']) > 0) 256 { 257 $this->verbose("Starting to set additional parameters for topic GUID: " . $topic->guid); 258 259 $this->set_parameters($node, $topic); 260 } 261 262 // Setting midcom acl privileges 263 if (isset($node['acl']) && count($node['acl']) > 0) 264 { 265 $this->verbose("Starting to set midcom acl privileges for topic GUID: " . $topic->guid); 266 267 $this->set_privileges($node, $this->creation_root_topic); 268 } 269 } 270 271 if (isset($node['nodes']) && count($node['nodes']) > 0) 272 { 273 $this->create_topic_structure_recursive($node['nodes']); 274 } 275 } 276 } 277 278 private function set_parameters($config_node, $object) 279 { 280 foreach ($config_node['parameters'] as $domain => $parameter) 281 { 282 foreach ($parameter as $name => $value) 283 { 284 $this->verbose("Setting parameter (" . $domain . "," . $name . "," . $value .") for object GUID: " 285 . $object->guid); 286 287 $object->parameter($domain, $name, $value); 288 } 289 } 290 return true; 291 } 292 293 private function set_privileges($config_node, $object) 294 { 295 foreach($config_node['acl'] as $group_name => $privilege) 296 { 297 foreach($privilege as $name => $value) 298 { 299 if (array_key_exists($group_name, $this->created_groups)) 300 { 301 $acl = new midcom_core_privilege_db(); 302 $acl->objectguid = $object->guid; 303 $acl->name = $name; 304 $acl->sitegroup = $this->sitegroup->id; 305 $acl->assignee = "group:" . $this->created_groups[$group_name]->guid; 306 $acl->value = $value; 307 308 if (!$acl->create()) 309 { 310 throw new midgard_admin_sitewizard_exception(); 311 } 312 else 313 { 314 $this->verbose("ACL (" . $acl->name . "," . $acl->assignee . "," . $acl->value . " set for object GUID: " 315 . $object->guid); 316 317 return true; 318 } 319 } 320 } 321 } 158 322 } 159 323 160 324 public function create_topic_structure() 161 325 { 162 $this->verbose("Starting to create topic structure under topic GUID: " . $creation_root_topic->guid); 326 $this->verbose("Starting to create topic structure under topic GUID: " . $this->creation_root_topic->guid); 327 328 foreach ($this->config as $structure) 329 { 330 $this->structure = $structure; 331 } 332 333 // Creating root topic from configuration if it hasn't been set already 334 if ($this->creation_root_topic == null) 335 { 336 $this->verbose('Creating root topic from configuration'); 337 338 $this->creation_root_topic = midgard_topic(); 339 $this->creation_root_topic->up = 0; 340 $this->creation_root_topic->sitegroup = $this->sitegroup->id; 341 $this->creation_root_topic->title = $this->structure['root']['title']; 342 $this->creation_root_topic->name = $this->structure['root']['name']; 343 344 if (!$this->creation_root_topic->create()) 345 { 346 throw new midgard_admin_sitewizard_exception("Failed to create root topic \"" . $this->structure['root']['name'] 347 . "\" for structure creation"); 348 349 return false; 350 } 351 else 352 { 353 // Setting additional parameters 354 if (isset($this->structure['root']['parameters']) && count($this->structure['root']['parameters']) > 0) 355 { 356 $this->set_parameters($this->structure['root'], $this->creation_root_topic); 357 } 358 359 // Setting midcom acl privileges 360 if (isset($this->structure['root']['acl']) && count($this->structure['root']['acl']) > 0) 361 { 362 $this->set_privileges($this->structure['root'], $this->creation_root_topic); 363 } 364 } 365 } 163 366 164 367 // Making sure the topic is empty before creating a structure 165 368 $qb = new midgard_query_builder('midgard_topic'); 166 369 $qb->add_constraint('up', '=', $this->creation_root_topic->id); 370 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 167 371 $topics = $qb->execute(); 168 372 169 373 if (count($topics) != 0) 170 374 { 171 throw new midgard_admin_sitewizard_exception("Creation root topic is not empty!"); 172 } 173 else 174 { 175 //TODO: create structure 176 177 foreach ($this->config as $structure) 178 { 179 // TODO: create root topic 375 throw new midgard_admin_sitewizard_exception('Creation root topic is not empty!'); 376 } 377 else 378 { 379 try 380 { 381 $this->create_topic_structure_recursive($this->structure['root']['nodes'], $this->creation_root_topic); 382 } 383 catch (midgard_admin_sitewizard_exception $e) 384 { 385 $e->error(); 386 387 throw new midgard_admin_sitewizard_exception("Failed to create topic structure under topic GUID: " 388 . $this->creation_root_topic->guid . "Reason: " . mgd_errstr()); 180 389 181 foreach ($structure['root']['nodes'] as $node)182 {183 //echo $node['name'] . "\n";184 }185 186 390 } 187 391 } … … 190 394 public function create_group_structure() 191 395 { 192 $this->verbose("Starting to create groups under admingroup ID: " . $this->sitegroup->admingroup); 396 if ($this->creation_root_group != null) 397 { 398 $group_owner_id = $this->creation_root_group->id; 399 } 400 else 401 { 402 $group_owner_id = $this->sitegroup->admingroup; 403 } 404 405 $this->verbose("Starting to create groups under group ID: " . $group_owner_id); 193 406 194 407 $qb = new midgard_query_builder('midgard_group'); 195 408 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 196 $qb->add_constraint('owner', '=', $ this->sitegroup->admingroup);409 $qb->add_constraint('owner', '=', $group_owner_id); 197 410 $groups = $qb->execute(); 198 411 … … 213 426 if ($group->name == $candidate_group_name) 214 427 { 428 $this->created_groups[$group->name] = $group; 215 429 $group_match++; 216 430 } … … 226 440 227 441 $new_group = new midgard_group(); 442 $new_group->owner = $group_owner_id; 443 $new_group->sitegroup = $this->sitegroup->id; 228 444 $new_group->name = $candidate_group_name; 229 $new_group->sitegroup = $this->sitegroup->id; 230 $new_group->owner = $this->sitegroup->admingroup; 231 232 if (!$new_group->create()) 445 446 if (!$new_group->create()) 233 447 { 234 448 throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name … … 237 451 else 238 452 { 453 $this->created_groups[$new_group->name] = $new_group; 239 454 return true; 240 455 } … … 256 471 $new_group->name = $candidate_group_name; 257 472 $new_group->sitegroup = $this->sitegroup->id; 258 $new_group->owner = $ this->sitegroup->admingroup;473 $new_group->owner = $group_owner_id; 259 474 260 475 if (!$new_group->create()) … … 286 501 catch (midgard_admin_sitewizard_exception $e) 287 502 { 503 $e->error(); 504 288 505 throw new midgard_admin_sitewizard_exception("Failed to execute parent creator"); 289 506 } … … 294 511 $this->create_group_structure(); 295 512 $this->create_topic_structure(); 513 514 $this->verbose("Sitewizard created website structure successfully. Now cleaning up..."); 515 516 $this->cleanup(); 296 517 } 297 518 catch(midgard_admin_sitewizard_exception $e) 298 519 { 299 520 $e->error(); 300 // TODO: Shutdown 521 522 $this->cleanup(); 523 301 524 throw new midgard_admin_sitewizard_exception("Failed to create structure"); 525 526 return false; 302 527 } 303 528 }
