Changeset 12559
- Timestamp:
- 09/28/07 00:57:43 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midgard/data/midgard_admin_sitewizard_creator_structure.php
r12558 r12559 25 25 26 26 private $sitegroup = null; 27 27 28 28 private $config = null; 29 29 30 30 private $structure = null; 31 31 … … 54 54 55 55 if ($this->host_creator == null) 56 {56 { 57 57 if (!$this->host = new midgard_host($host_guid)) 58 {59 throw new midgard_admin_sitewizard_exception("Sitewizard couldn't initialize host60 object. Reason: " . mgd_errstr());61 62 return false;58 { 59 throw new midgard_admin_sitewizard_exception("Sitewizard couldn't initialize host 60 object. Reason: " . mgd_errstr()); 61 62 return false; 63 63 } 64 64 else 65 65 { 66 $this->verbose("Getting sitegroup of host GUID: " . $this->host->guid);66 $this->verbose("Getting sitegroup of host GUID: " . $this->host->guid); 67 67 $sitegroup_id = $this->host->sitegroup; 68 68 /* 69 $this->sitegroup = new midgard_sitegroup();70 $this->sitegroup->get_by_id($sitegroup_id);69 $this->sitegroup = new midgard_sitegroup(); 70 $this->sitegroup->get_by_id($sitegroup_id); 71 71 */ 72 72 $this->sitegroup = mgd_get_sitegroup($sitegroup_id); 73 73 74 $this->verbose("Getting root page of host GUID: " . $this->host->guid);75 $this->root_page = new midgard_page();76 $this->root_page->get_by_id($this->host->root);74 $this->verbose("Getting root page of host GUID: " . $this->host->guid); 75 $this->root_page = new midgard_page(); 76 $this->root_page->get_by_id($this->host->root); 77 77 78 78 $root_topic_guid = $this->root_page->parameter('midgard', 'midcom_root_topic_guid'); 79 79 80 if (empty($root_topic_guid))81 {80 if (empty($root_topic_guid)) 81 { 82 82 throw new midgard_admin_sitewizard_exception("Failed to get valid root topic 83 83 guid from root page parameter GUID: " . $root_topic_guid . " Reason: " . mgd_errstr()); 84 84 85 return false;86 }87 else88 {89 $this->verbose("Getting root topic of page GUID: " . $this->root_page->guid);90 $this->root_topic = new midgard_topic($root_topic_guid);91 } 92 93 return true;94 }95 } 96 } 97 85 return false; 86 } 87 else 88 { 89 $this->verbose("Getting root topic of page GUID: " . $this->root_page->guid); 90 $this->root_topic = new midgard_topic($root_topic_guid); 91 } 92 93 return true; 94 } 95 } 96 } 97 98 98 public function read_config($path) 99 99 { 100 $this->config = $this->get_structure_config_filesystem($path); 100 $this->config = $this->get_structure_config_filesystem($path); 101 101 } 102 102 … … 121 121 } 122 122 } 123 123 124 124 /** 125 125 * There is no next link in the chain … … 130 130 $this->execute(); 131 131 } 132 132 133 133 public function previous_link() 134 134 { … … 148 148 { 149 149 throw new midgard_admin_sitewizard_exception("Failed to create index article GUID: " 150 . $article->guid . " Reason: " . mgd_errstr());150 . $article->guid . " Reason: " . mgd_errstr()); 151 151 } 152 152 else … … 161 161 { 162 162 if (!$this->creation_root_group = new midgard_group($group_guid)) 163 {163 { 164 164 throw new midgard_admin_sitewizard_exception("Failed to set root group for structure creation GUID: " 165 . $group_guid . " Reason: " . mgd_errstr());166 167 return true;168 }169 else170 {165 . $group_guid . " Reason: " . mgd_errstr()); 166 167 return true; 168 } 169 else 170 { 171 171 $this->verbose("Setting group for structure creation GUID: " . $group_guid); 172 172 173 return true;174 }173 return true; 174 } 175 175 } 176 176 … … 178 178 { 179 179 if (!$this->creation_root_topic = new midgard_topic($topic_guid)) 180 {180 { 181 181 throw new midgard_admin_sitewizard_exception("Failed to set root topic for structure creation GUID: " 182 . $topic_guid . " Reason: " . mgd_errstr());183 184 return true;185 }186 else187 {182 . $topic_guid . " Reason: " . mgd_errstr()); 183 184 return true; 185 } 186 else 187 { 188 188 $this->verbose("Setting topic for structure creation GUID: " . $topic_guid); 189 189 190 return true;191 }190 return true; 191 } 192 192 } 193 193 … … 198 198 $owner_group = new midgard_group($owner_guid); 199 199 200 $qb = new midgard_query_builder('midgard_group');201 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id);202 $qb->add_constraint('owner', '=', $owner_group->id);203 $qb->add_constraint('name', '=', $group_name);204 205 $groups = $qb->execute();206 207 if (count($groups) > 0)208 {200 $qb = new midgard_query_builder('midgard_group'); 201 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 202 $qb->add_constraint('owner', '=', $owner_group->id); 203 $qb->add_constraint('name', '=', $group_name); 204 205 $groups = $qb->execute(); 206 207 if (count($groups) > 0) 208 { 209 209 $this->verbose("Group \"" . $group_name . "\" GUID: " . $groups[0]->guid 210 . " already exists. Setting as root group for structure creation.");211 212 $this->creation_root_group = $groups[0];213 214 return true;215 }216 else217 {218 $this->creation_root_group = new midgard_group();219 $this->creation_root_group->owner = $owner_group->id;220 $this->creation_root_group->sitegroup = $this->sitegroup->id;221 $this->creation_root_group->name = $group_name;210 . " already exists. Setting as root group for structure creation."); 211 212 $this->creation_root_group = $groups[0]; 213 214 return true; 215 } 216 else 217 { 218 $this->creation_root_group = new midgard_group(); 219 $this->creation_root_group->owner = $owner_group->id; 220 $this->creation_root_group->sitegroup = $this->sitegroup->id; 221 $this->creation_root_group->name = $group_name; 222 222 223 223 if (!$this->creation_root_group->create()) 224 {224 { 225 225 throw new midgard_admin_sitewizard_exception("Failed to create root group for group 226 226 structure creation under group GUID: " . $this->creation_root_group->guid); 227 }228 else229 {227 } 228 else 229 { 230 230 return true; 231 }231 } 232 232 } 233 233 } … … 252 252 else 253 253 { 254 $this->creation_root_topic = new midgard_topic();255 $this->creation_root_topic->extra = $topic_title;256 $this->creation_root_topic->name = $topic_name;257 $this->creation_root_topic->sitegroup = $this->sitegroup->id;258 $this->creation_root_topic->component = $component;259 $this->creation_root_topic->up = $topic->id;260 261 if (!empty($style))262 {263 $this->verbose("Setting style for topic" . $topic_name . ": (" . $style . ")");264 $this->creation_root_topic->style = $style;265 }254 $this->creation_root_topic = new midgard_topic(); 255 $this->creation_root_topic->extra = $topic_title; 256 $this->creation_root_topic->name = $topic_name; 257 $this->creation_root_topic->sitegroup = $this->sitegroup->id; 258 $this->creation_root_topic->component = $component; 259 $this->creation_root_topic->up = $topic->id; 260 261 if (!empty($style)) 262 { 263 $this->verbose("Setting style for topic" . $topic_name . ": (" . $style . ")"); 264 $this->creation_root_topic->style = $style; 265 } 266 266 267 267 if (!$this->creation_root_topic->create()) 268 {268 { 269 269 throw new midgard_admin_sitewizard_exception("Failed to create root topic for structure creation GUID: " 270 . $this->creation_root_topic->guid . " Reason: " . mdg_errstr());271 }272 else273 {274 // Setting style parameter275 if (!empty($style))276 {277 $this->creation_root_topic->parameter('midcom', 'style', $style);278 }279 270 . $this->creation_root_topic->guid . " Reason: " . mdg_errstr()); 271 } 272 else 273 { 274 // Setting style parameter 275 if (!empty($style)) 276 { 277 $this->creation_root_topic->parameter('midcom', 'style', $style); 278 } 279 280 280 $this->verbose("Created root topic for structure creation GUID: " . $this->creation_root_topic->guid); 281 282 // Setting additional parameters281 282 // Setting additional parameters 283 283 foreach ($parameters as $domain => $parameter) 284 {284 { 285 285 foreach ($parameter as $name => $value) 286 {286 { 287 287 $this->creation_root_topic->parameter($domain, $name, $value); 288 }289 }290 291 if ($create_index == true)292 {293 $this->create_index_article($this->creation_root_topic->id, $topic_title);294 }295 }296 }288 } 289 } 290 291 if ($create_index == true) 292 { 293 $this->create_index_article($this->creation_root_topic->id, $topic_title); 294 } 295 } 296 } 297 297 } 298 298 … … 307 307 private function create_topic_structure_recursive($nodes, $parent_node) 308 308 { 309 foreach ($nodes as $node)310 {309 foreach ($nodes as $node) 310 { 311 311 $this->verbose("Creating topic \"" . $this->replace($node['title']) . "\" under parent topic GUID: " 312 . $parent_node->guid);313 314 $topic = new midgard_topic();315 $topic->up = $parent_node->id;312 . $parent_node->guid); 313 314 $topic = new midgard_topic(); 315 $topic->up = $parent_node->id; 316 316 $topic->name = $this->replace($node['name']); 317 $topic->extra = $this->replace($node['title']);318 $topic->sitegroup = $this->sitegroup->id;319 $topic->component = $node['component'];320 321 if (isset($node['style']) && !empty($node['style']))322 {323 $this->verbose("Setting style for topic " . $node['name'] . ": (" . $node['style'] . ")");324 $topic->style = $node['style'];325 }326 327 if (!$topic->create())328 {317 $topic->extra = $this->replace($node['title']); 318 $topic->sitegroup = $this->sitegroup->id; 319 $topic->component = $node['component']; 320 321 if (isset($node['style']) && !empty($node['style'])) 322 { 323 $this->verbose("Setting style for topic " . $node['name'] . ": (" . $node['style'] . ")"); 324 $topic->style = $node['style']; 325 } 326 327 if (!$topic->create()) 328 { 329 329 throw new midagard_admin_sitewizard_exception("Failed to create topic \"" 330 330 . $topic->extra . "\" under parent GUID: " . $parent_node->guid); 331 }332 else333 {334 // Setting style parameter335 if (isset($node['style']) && !empty($node['style']))336 {337 $topic->parameter('midcom', 'style', $node['style']);338 }339 340 // Setting additional parameters341 if (isset($node['parameters']) && count($node['parameters']) > 0)331 } 332 else 333 { 334 // Setting style parameter 335 if (isset($node['style']) && !empty($node['style'])) 336 { 337 $topic->parameter('midcom', 'style', $node['style']); 338 } 339 340 // Setting additional parameters 341 if (isset($node['parameters']) && count($node['parameters']) > 0) 342 342 { 343 343 $this->verbose("Starting to set additional parameters for topic GUID: " . $topic->guid); 344 344 345 345 $this->set_parameters($node, $topic); 346 }347 348 // Setting midcom acl privileges346 } 347 348 // Setting midcom acl privileges 349 349 if (isset($node['acl']) && count($node['acl']) > 0) 350 {350 { 351 351 $this->verbose("Starting to set midcom acl privileges for topic GUID: " . $topic->guid); 352 352 353 353 $this->set_privileges($node, $this->creation_root_topic); 354 }355 356 if (isset($node['create_index']) && $node['create_index'] == true)357 {358 $this->create_index_article($topic->id, $this->replace($node['title']));359 }360 }361 362 if (isset($node['nodes']) && count($node['nodes']) > 0)363 {354 } 355 356 if (isset($node['create_index']) && $node['create_index'] == true) 357 { 358 $this->create_index_article($topic->id, $this->replace($node['title'])); 359 } 360 } 361 362 if (isset($node['nodes']) && count($node['nodes']) > 0) 363 { 364 364 $this->create_topic_structure_recursive($node['nodes']); 365 }366 }365 } 366 } 367 367 } 368 368 … … 370 370 { 371 371 foreach ($config_node['parameters'] as $domain => $parameter) 372 {373 foreach ($parameter as $name => $value)374 {372 { 373 foreach ($parameter as $name => $value) 374 { 375 375 $this->verbose("Setting parameter (" . $domain . "," . $name . "," . $value .") for object GUID: " 376 376 . $object->guid); 377 378 $object->parameter($domain, $name, $value);379 }380 } 381 return true;377 378 $object->parameter($domain, $name, $value); 379 } 380 } 381 return true; 382 382 } 383 383 … … 385 385 { 386 386 foreach($config_node['acl'] as $identifier => $privilege) 387 {387 { 388 388 $assignee = null 389 389 if (array_key_exists($assignee, $this->created_groups)) … … 402 402 } 403 403 404 foreach($privilege as $name => $value)405 {404 foreach($privilege as $name => $value) 405 { 406 406 $acl = new midcom_core_privilege_db(); 407 407 $acl->objectguid = $object->guid; … … 422 422 return true; 423 423 } 424 }424 } 425 425 } 426 426 } … … 428 428 public function create_topic_structure() 429 429 { 430 $this->verbose("Starting to create topic structure under topic GUID: " . $this->creation_root_topic->guid); 431 432 foreach ($this->config as $structure) 433 { 434 $this->structure = $structure; 435 } 430 $this->verbose("Starting to create topic structure"); 431 432 if (!is_null($this->creation_root_topic)) 433 { 434 $this->verbose("under topic GUID: " . $this->creation_root_topic->guid); 435 } 436 437 foreach ($this->config as $structure) 438 { 439 $this->structure = $structure; 440 } 436 441 437 442 // Creating root topic from configuration if it hasn't been set already 438 443 if ($this->creation_root_topic == null) 439 {444 { 440 445 $this->verbose('Creating root topic from configuration'); 441 446 442 $this->creation_root_topic = midgard_topic();443 $this->creation_root_topic->up = 0;444 $this->creation_root_topic->sitegroup = $this->sitegroup->id;445 $this->creation_root_topic->extra = $this->structure['root']['title'];446 $this->creation_root_topic->name = $this->structure['root']['name'];447 448 if (isset($node['root']['style']) && !empty($node['root']['style']))449 {450 $this->verbose("Setting style for topic " . $this->structure['root']['name']451 . "(" . $node['root']['style'] . ")");452 $this->creation_root_topic->style = $node['root']['style'];453 }454 455 if (!$this->creation_root_topic->create())456 {447 $this->creation_root_topic = midgard_topic(); 448 $this->creation_root_topic->up = 0; 449 $this->creation_root_topic->sitegroup = $this->sitegroup->id; 450 $this->creation_root_topic->extra = $this->structure['root']['title']; 451 $this->creation_root_topic->name = $this->structure['root']['name']; 452 453 if (isset($node['root']['style']) && !empty($node['root']['style'])) 454 { 455 $this->verbose("Setting style for topic " . $this->structure['root']['name'] 456 . "(" . $node['root']['style'] . ")"); 457 $this->creation_root_topic->style = $node['root']['style']; 458 } 459 460 if (!$this->creation_root_topic->create()) 461 { 457 462 throw new midgard_admin_sitewizard_exception("Failed to create root topic \"" 458 463 . $this->structure['root']['name'] . "\" for structure creation"); 459 464 460 return false;461 }462 else463 {464 // Setting style parameter465 if (isset($node['root']['style']) && !empty($node['root']['style']))466 {467 $this->creation_root_topic->parameter('midcom', 'style', $node['root']['style']);468 }469 470 // Setting additional parameters471 if (isset($this->structure['root']['parameters']) && count($this->structure['root']['parameters']) > 0)472 {473 $this->set_parameters($this->structure['root'], $this->creation_root_topic);465 return false; 466 } 467 else 468 { 469 // Setting style parameter 470 if (isset($node['root']['style']) && !empty($node['root']['style'])) 471 { 472 $this->creation_root_topic->parameter('midcom', 'style', $node['root']['style']); 473 } 474 475 // Setting additional parameters 476 if (isset($this->structure['root']['parameters']) && count($this->structure['root']['parameters']) > 0) 477 { 478 $this->set_parameters($this->structure['root'], $this->creation_root_topic); 474 479 } 475 480 476 481 // Setting midcom acl privileges 477 482 if (isset($this->structure['root']['acl']) && count($this->structure['root']['acl']) > 0) 478 {483 { 479 484 $this->set_privileges($this->structure['root'], $this->creation_root_topic); 480 }481 482 if (isset($this->structure['root']['create_index']) && $this->structure['root']['create_index'] == true)483 {484 $this->create_index_article($this->creation_root_topic->id, $this->replace($node['root']['title']));485 }486 }485 } 486 487 if (isset($this->structure['root']['create_index']) && $this->structure['root']['create_index'] == true) 488 { 489 $this->create_index_article($this->creation_root_topic->id, $this->replace($node['root']['title'])); 490 } 491 } 487 492 } 488 493 489 494 // Making sure the topic is empty before creating a structure 490 $qb = new midgard_query_builder('midgard_topic');491 $qb->add_constraint('up', '=', $this->creation_root_topic->id);492 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id);495 $qb = new midgard_query_builder('midgard_topic'); 496 $qb->add_constraint('up', '=', $this->creation_root_topic->id); 497 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 493 498 $topics = $qb->execute(); 494 495 if (count($topics) !=0)496 {497 throw new midgard_admin_sitewizard_exception('Creation root topic is not empty!');498 }499 else500 {499 500 if (count($topics) > 0) 501 { 502 throw new midgard_admin_sitewizard_exception('Creation root topic is not empty!'); 503 } 504 else 505 { 501 506 try 502 {503 $this->create_topic_structure_recursive($this->structure['root']['nodes'], $this->creation_root_topic);504 }505 catch (midgard_admin_sitewizard_exception $e)506 {507 { 508 $this->create_topic_structure_recursive($this->structure['root']['nodes'], $this->creation_root_topic); 509 } 510 catch (midgard_admin_sitewizard_exception $e) 511 { 507 512 $e->error(); 508 513 509 514 throw new midgard_admin_sitewizard_exception("Failed to create topic structure under topic GUID: " 510 . $this->creation_root_topic->guid . "Reason: " . mgd_errstr());511 512 }513 }515 . $this->creation_root_topic->guid . "Reason: " . mgd_errstr()); 516 517 } 518 } 514 519 } 515 520 … … 517 522 { 518 523 if ($this->creation_root_group != null) 519 {524 { 520 525 $group_owner_id = $this->creation_root_group->id; 521 }522 else523 {524 $group_owner_id = $this->sitegroup->admingroup;525 }526 } 527 else 528 { 529 $group_owner_id = $this->sitegroup->admingroup; 530 } 526 531 527 532 $this->verbose("Starting to create groups under group ID: " . $group_owner_id); 528 533 529 534 $qb = new midgard_query_builder('midgard_group'); 530 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id);531 $qb->add_constraint('owner', '=', $group_owner_id);532 $groups = $qb->execute();533 534 if (count($groups) != 0)535 {535 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 536 $qb->add_constraint('owner', '=', $group_owner_id); 537 $groups = $qb->execute(); 538 539 if (count($groups) != 0) 540 { 536 541 // Ok, let's first check if a group already exists 537 foreach ($this->config as $structure)538 {542 foreach ($this->config as $structure) 543 { 539 544 foreach ($structure['groups'] as $candidate_group_name) 540 {541 542 $this->verbose("Checking if group \"" . $candidate_group_name . "\" already exists");545 { 546 547 $this->verbose("Checking if group \"" . $candidate_group_name . "\" already exists"); 543 548 544 549 $group_match = 0; 545 550 546 foreach ($groups as $group)547 {551 foreach ($groups as $group) 552 { 548 553 if ($group->name == $candidate_group_name) 549 {554 { 550 555 $this->created_groups[$group->name] = $group; 551 $group_match++;552 }553 }554 555 if ($group_match > 0)556 {557 $this->verbose("Group \"" . $candidate_group_name . "\" already exists! No need to create");558 }559 elseif (count($groups) > 0)560 {556 $group_match++; 557 } 558 } 559 560 if ($group_match > 0) 561 { 562 $this->verbose("Group \"" . $candidate_group_name . "\" already exists! No need to create"); 563 } 564 elseif (count($groups) > 0) 565 { 561 566 $this->verbose("Group \"" . $candidate_group_name . "\" does not exist! Creating now"); 562 567 563 568 $new_group = new midgard_group(); 564 $new_group->owner = $group_owner_id;565 $new_group->sitegroup = $this->sitegroup->id;566 $new_group->name = $candidate_group_name;569 $new_group->owner = $group_owner_id; 570 $new_group->sitegroup = $this->sitegroup->id; 571 $new_group->name = $candidate_group_name; 567 572 568 if (!$new_group->create())569 {573 if (!$new_group->create()) 574 { 570 575 throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name 571 . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr());572 }573 else574 {575 $this->created_groups[$new_group->name] = $new_group;576 return true;577 }576 . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); 577 } 578 else 579 { 580 $this->created_groups[$new_group->name] = $new_group; 581 return true; 582 } 578 583 } 579 }580 }581 }582 else583 {584 // There are no groups so we can just create the groups from config file585 foreach ($this->config as $structure)586 {584 } 585 } 586 } 587 else 588 { 589 // There are no groups so we can just create the groups from config file 590 foreach ($this->config as $structure) 591 { 587 592 foreach ($structure['groups'] as $candidate_group_name) 588 {593 { 589 594 $this->verbose("Group \"" . $candidate_group_name . "\" does not exist! Creating now"); 590 595 591 596 $new_group = new midgard_group(); 592 $new_group->name = $candidate_group_name;597 $new_group->name = $candidate_group_name; 593 598 $new_group->sitegroup = $this->sitegroup->id; 594 $new_group->owner = $group_owner_id;599 $new_group->owner = $group_owner_id; 595 600 596 601 if (!$new_group->create()) 597 {602 { 598 603 throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name 599 . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr());600 }601 else602 {603 return true;604 }605 }606 }604 . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr()); 605 } 606 else 607 { 608 return true; 609 } 610 } 611 } 607 612 } 608 613 } … … 614 619 if ($this->parent_link != null) 615 620 { 616 $this->verbose('Executing parent');617 618 try619 {620 $this->parent_link->execute(); 621 }622 catch (midgard_admin_sitewizard_exception $e)623 {621 $this->verbose('Executing parent'); 622 623 try 624 { 625 $this->parent_link->execute(); 626 } 627 catch (midgard_admin_sitewizard_exception $e) 628 { 624 629 $e->error(); 625 630 626 631 throw new midgard_admin_sitewizard_exception("Failed to execute parent creator"); 627 }632 } 628 633 } 629 634 630 635 try 631 {632 $this->create_group_structure();633 $this->create_topic_structure();634 635 $this->verbose("Sitewizard created website structure successfully. Now cleaning up...");636 637 $this->cleanup();638 639 return $this->creation_root_topic->guid;640 } 641 catch(midgard_admin_sitewizard_exception $e)642 {643 $e->error();636 { 637 $this->create_group_structure(); 638 $this->create_topic_structure(); 639 640 $this->verbose("Sitewizard created website structure successfully. Now cleaning up..."); 641 642 $this->cleanup(); 643 644 return $this->creation_root_topic->guid; 645 } 646 catch(midgard_admin_sitewizard_exception $e) 647 { 648 $e->error(); 644 649 $this->cleanup(); 645 650 646 throw new midgard_admin_sitewizard_exception("Failed to create structure");&nb
