Changeset 12966
- Timestamp:
- 10/22/07 14:23:21 (1 year ago)
- Files:
-
- trunk/midgard/data/midgard_admin_sitewizard.php (modified) (3 diffs)
- trunk/midgard/data/midgard_admin_sitewizard_creator.php (modified) (3 diffs)
- trunk/midgard/data/midgard_admin_sitewizard_creator_host.php (modified) (6 diffs)
- trunk/midgard/data/midgard_admin_sitewizard_creator_sitegroup.php (modified) (2 diffs)
- trunk/midgard/data/midgard_admin_sitewizard_creator_structure.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midgard/data/midgard_admin_sitewizard.php
r12012 r12966 13 13 class midgard_admin_sitewizard 14 14 { 15 p rivate $current_state;15 public static $current_state = null; 16 16 17 17 private $verbose; … … 19 19 public function __construct() 20 20 { 21 $this->verbose = false; 22 $this->current_state = null; 21 $this->verbose = false; 23 22 } 24 23 … … 96 95 public function get_current_state() 97 96 { 98 return $this->current_state;97 return self::current_state; 99 98 } 99 100 100 101 101 102 } trunk/midgard/data/midgard_admin_sitewizard_creator.php
r12012 r12966 31 31 32 32 abstract protected function initialize($guid); 33 34 //abstract protected function read_config($path);35 33 36 34 abstract protected function execute(); … … 40 38 abstract protected function previous_link(); 41 39 40 /* 42 41 protected function set_parent_link($parent_link) 43 42 { … … 49 48 return $this->parent_link; 50 49 } 50 */ 51 51 52 52 protected function start_chain($start) trunk/midgard/data/midgard_admin_sitewizard_creator_host.php
r12720 r12966 28 28 29 29 private $host_style_id = null; 30 31 private $page_title = ''; 30 32 31 33 … … 71 73 { 72 74 $this->host->style = $this->host_style_id; 75 76 $qb = new MidgardQueryBuilder('midgard_style'); 77 $qb->add_constraint('up', '=', 0); 78 $qb->add_constraint('id', '=', $this->host_style_id); 79 $styles = $qb->execute(); 80 81 if (count($styles) > 0) 82 { 83 $extend_style = new midgard_style(); 84 $extend_style->up = $this->host_style_id; 85 $extend_style->sitegroup = $this->sitegroup->id; 86 $extend_style->name = sprintf('%s for %s', $styles[0]->name, 87 $this->host_url . str_replace('/', ':', $this->host_prefix)); 88 89 if (!$extend_style->create()) 90 { 91 throw new midgard_admin_sitewizard_exception("Failed to create extend style for host GUID: " 92 . $this->host->guid); 93 } 94 else 95 { 96 $this->host->style = $extend_style->id; 97 } 98 } 73 99 } 74 100 … … 102 128 $this->root_page->up = 0; 103 129 $this->root_page->name = $this->host->name . $this->host->prefix . " root"; 104 $this->root_page->title = $this->sitegroup->name; 130 131 if ($this->page_title == '') 132 { 133 $this->root_page->title = $this->sitegroup->name; 134 } 135 else 136 { 137 $this->root_page->title = $this->page_title; 138 } 105 139 106 140 if (!$this->root_page->create()) … … 157 191 } 158 192 193 public function set_page_title($page_title) 194 { 195 $this->page_title = $page_title; 196 } 197 159 198 public function cleanup() 160 199 { … … 171 210 $this->verbose('Initializing next link in the creation chain.'); 172 211 $this->next_link = new midgard_admin_sitewizard_creator_structure($this); 212 midgard_admin_sitewizard::$current_state = $this->next_link; 173 213 174 214 return $this->next_link; … … 179 219 $this->verbose('Returning previous link in the creation chain.'); 180 220 221 midgard_admin_sitewizard::$current_state = $this->parent_link; 181 222 return $this->parent_link; 182 223 } trunk/midgard/data/midgard_admin_sitewizard_creator_sitegroup.php
r12581 r12966 228 228 $this->verbose("Initializing next link in the creation chain."); 229 229 $this->next_link = new midgard_admin_sitewizard_creator_host($this); 230 midgard_admin_sitewizard::$current_state = $this->next_link; 230 231 231 232 return $this->next_link; … … 235 236 { 236 237 $this->verbose("There is no parent link. Returning null"); 238 239 midgard_admin_sitewizard::$current_state = $this; 237 240 238 241 return null; trunk/midgard/data/midgard_admin_sitewizard_creator_structure.php
r12720 r12966 31 31 32 32 private $created_groups = array(); 33 34 private $schemadb = null; 35 36 private $schemavalues = array(); 33 37 34 38 public function __construct($parent_link = null) … … 92 96 } 93 97 } 98 99 public function get_schemadb() 100 { 101 return $this->schemadb; 102 } 94 103 95 104 public function read_config($path) 96 105 { 97 $this->config = $this->get_structure_config_filesystem($path); 106 $this->config = $this->get_structure_config_filesystem($path); 107 108 $values = each($this->config); 109 110 if (isset($values['value']['schemadb'])) 111 { 112 $this->schemadb = $values['value']['schemadb']; 113 } 98 114 } 99 115 … … 123 139 public function next_link() 124 140 { 125 $this->execute(); 141 $this->next_link = $this; 142 midgard_admin_sitewizard::$current_state = $this->next_link; 126 143 } 127 144 128 145 public function previous_link() 129 146 { 147 $this->verbose('Returning previous link in the creation chain.'); 148 149 midgard_admin_sitewizard::$current_state = $this->parent_link; 130 150 return $this->parent_link; 131 151 } … … 191 211 $this->verbose("Creating a root group for group structure creation under group GUID: " . $owner_guid); 192 212 193 $owner_group = new midgard_group($owner_guid); 194 213 if ($owner_guid != 0) 214 { 215 $owner_group = new midgard_group($owner_guid); 216 $owner_id = $owner_group->id; 217 } 218 else 219 { 220 $owner_id = 0; 221 } 222 195 223 $qb = new midgard_query_builder('midgard_group'); 196 224 $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 197 $qb->add_constraint('owner', '=', $owner_ group->id);225 $qb->add_constraint('owner', '=', $owner_id); 198 226 $qb->add_constraint('name', '=', $group_name); 199 227 … … 212 240 { 213 241 $this->creation_root_group = new midgard_group(); 214 $this->creation_root_group->owner = $owner_group->id;242 $this->creation_root_group->owner = $owner_id; 215 243 $this->creation_root_group->sitegroup = $this->sitegroup->id; 216 244 $this->creation_root_group->name = $group_name; … … 273 301 } 274 302 275 $this->verbose("Created root topic for structure creation GUID: " . $this->creation_root_topic->guid); 303 $this->verbose("Created root topic for structure creation GUID: " 304 . $this->creation_root_topic->guid); 276 305 277 306 // Setting additional parameters … … 291 320 } 292 321 } 322 323 public function set_schema_values($schemavalues) 324 { 325 $this->schemavalues = $schemavalues; 326 } 293 327 294 328 private function replace($string) … … 296 330 $result = str_replace('__HOSTNAME__', $this->host->name, $string); 297 331 $result = str_replace('__HOSTTITLE__', $this->root_page->title, $result); 298 332 333 foreach ($this->created_groups as $name => $group) 334 { 335 // Change __GROUPGUID_groupname strings to GUIDs of the actual created groups 336 $result = str_replace("__GROUPGUID_{$name}", $group->guid, $result); 337 } 338 339 foreach ($this->schemavalues as $field => $inputted_value) 340 { 341 // Change all __SCHEMA_fieldname strings to values inputted in the DM2 editor 342 $result = str_replace("__SCHEMA_{$field}", $inputted_value, $result); 343 } 344 299 345 return $result; 300 346 } … … 368 414 foreach ($parameter as $name => $value) 369 415 { 370 $this->verbose("Setting parameter (" . $domain . "," . $name . "," . $value .") for object GUID: " 416 $value = $this->replace($value); 417 $this->verbose("Setting parameter (" . $domain . "," . $name . "," . $value .") for object GUID: " 371 418 . $object->guid); 372 419 … … 538 585 foreach ($this->config as $structure) 539 586 { 540 foreach ($structure['groups'] as $ candidate_group_name)541 { 542 543 $this->verbose("Checking if group \"" . $candidate_group _name. "\" already exists");587 foreach ($structure['groups'] as $key => $candidate_group) 588 { 589 590 $this->verbose("Checking if group \"" . $candidate_group['name'] . "\" already exists"); 544 591 545 592 $group_match = 0; … … 547 594 foreach ($groups as $group) 548 595 { 549 if ($group->name == $candidate_group _name)596 if ($group->name == $candidate_group['name']) 550 597 { 551 598 $this->created_groups[$group->name] = $group; … … 556 603 if ($group_match > 0) 557 604 { 558 $this->verbose("Group \"" . $candidate_group _name. "\" already exists! No need to create");605 $this->verbose("Group \"" . $candidate_group['name'] . "\" already exists! No need to create"); 559 606 } 560 607 elseif (count($groups) > 0) 561 608 { 562 $this->verbose("Group \"" . $candidate_group _name. "\" does not exist! Creating now");609 $this->verbose("Group \"" . $candidate_group['name'] . "\" does not exist! Creating now"); 563 610 564 611 $new_group = new midgard_group(); 565 612 $new_group->owner = $group_owner_id; 566 613 $new_group->sitegroup = $this->sitegroup->id; 567 $new_group->name = $ candidate_group_name;614 $new_group->name = $this->replace($candidate_group['name']); 568 615 569 616 if (!$new_group->create()) 570 617 { 571 throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group _name618 throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group['name'] 572 619 . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); 573 620 } … … 575 622 { 576 623 $this->created_groups[$new_group->name] = $new_group; 624 625 if (array_key_exists('subgroups', $candidate_group)) 626 { 627 foreach($candidate_group['subgroups'] as $subgroup) 628 { 629 $new_subgroup = new midgard_group(); 630 $new_subgroup->owner = $new_group->id; 631 $new_subgroup->sitegroup = $this->sitegroup->id; 632 $new_subgroup->name = $this->replace($subgroup['name']); 633 634 if (!$new_subgroup->create()) 635 { 636 throw new midgard_admin_sitewizard("Failed to create subgroup \"" . $subgroup['name'] 637 . "\" GUID: " . $new_subgroup->guid . " Reason: " . mgd_errstr()); 638 } 639 else 640 { 641 $this->verbose("Subgroup \"" . $subgroup['name'] 642 . "\" does not exist! Creating now"); 643 $this->created_groups[$new_subgroup->name] = $new_subgroup; 644 } 645 } 646 } 647 577 648 return true; 578 649 } … … 586 657 foreach ($this->config as $structure) 587 658 { 588 foreach ($structure['groups'] as $candidate_group _name)589 { 590 $this->verbose("Group \"" . $candidate_group _name. "\" does not exist! Creating now");659 foreach ($structure['groups'] as $candidate_group['name']) 660 { 661 $this->verbose("Group \"" . $candidate_group['name'] . "\" does not exist! Creating now"); 591 662 592 663 $new_group = new midgard_group(); 593 $new_group->name = $candidate_group _name;664 $new_group->name = $candidate_group['name']; 594 665 $new_group->sitegroup = $this->sitegroup->id; 595 666 $new_group->owner = $group_owner_id; … … 597 668 if (!$new_group->create()) 598 669 { 599 throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group _name670 throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group['name'] 600 671 . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr()); 601 672 } 602 673 else 603 674 { 675 $this->created_groups[$new_group->name] = $new_group; 676 677 if (array_key_exists('subgroups', $candidate_group)) 678 { 679 foreach($candidate_group['subgroups'] as $subgroup) 680 { 681 $new_subgroup = new midgard_group(); 682 $new_subgroup->owner = $new_group->id; 683 $new_subgroup->sitegroup = $this->sitegroup->id; 684 $new_subgroup->name = $this->replace($subgroup['name']); 685 686 if (!$new_subgroup->create()) 687 { 688 throw new midgard_admin_sitewizard("Failed to create subgroup \"" . $subgroup['name'] 689 . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); 690 } 691 else 692 { 693 $this->verbose("Subgroup \"" . $subgroup['name'] 694 . "\" does not exist! Creating now"); 695 $this->created_groups[$new_subgroup->name] = $new_subgroup; 696 } 697 } 698 } 699 604 700 return true; 605 701 } … … 608 704 } 609 705 } 706 707 public function get_host() 708 { 709 return $this->host; 710 } 711 712 public function get_root_page() 713 { 714 return $this->root_page; 715 } 716 717 public function get_creation_root_topic() 718 { 719 return $this->creation_root_topic; 720 } 721 722 public function get_creation_root_group() 723 { 724 return $this->creation_root_group; 725 } 610 726 611 727 public function execute()
