Changeset 12966

Show
Ignore:
Timestamp:
10/22/07 14:23:21 (1 year ago)
Author:
juhana
Message:

Some fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midgard/data/midgard_admin_sitewizard.php

    r12012 r12966  
    1313class midgard_admin_sitewizard 
    1414{ 
    15     private $current_state
     15    public static $current_state = null
    1616         
    1717    private $verbose; 
     
    1919    public function __construct() 
    2020    {            
    21         $this->verbose = false; 
    22             $this->current_state = null;         
     21        $this->verbose = false;  
    2322    } 
    2423 
     
    9695    public function get_current_state() 
    9796    { 
    98         return $this->current_state; 
     97        return self::current_state; 
    9998    } 
     99     
     100     
    100101         
    101102} 
  • trunk/midgard/data/midgard_admin_sitewizard_creator.php

    r12012 r12966  
    3131         
    3232        abstract protected function initialize($guid); 
    33  
    34         //abstract protected function read_config($path); 
    3533         
    3634        abstract protected function execute(); 
     
    4038        abstract protected function previous_link(); 
    4139         
     40        /* 
    4241        protected function set_parent_link($parent_link) 
    4342        { 
     
    4948                return $this->parent_link; 
    5049        } 
     50        */ 
    5151         
    5252    protected function start_chain($start) 
  • trunk/midgard/data/midgard_admin_sitewizard_creator_host.php

    r12720 r12966  
    2828     
    2929    private $host_style_id = null; 
     30     
     31    private $page_title = ''; 
    3032       
    3133 
     
    7173        { 
    7274            $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            } 
    7399        } 
    74100 
     
    102128        $this->root_page->up = 0; 
    103129        $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        } 
    105139         
    106140        if (!$this->root_page->create()) 
     
    157191    } 
    158192     
     193    public function set_page_title($page_title) 
     194    { 
     195        $this->page_title = $page_title; 
     196    } 
     197     
    159198    public function cleanup() 
    160199    { 
     
    171210        $this->verbose('Initializing next link in the creation chain.'); 
    172211        $this->next_link = new midgard_admin_sitewizard_creator_structure($this); 
     212        midgard_admin_sitewizard::$current_state = $this->next_link; 
    173213         
    174214        return $this->next_link; 
     
    179219        $this->verbose('Returning previous link in the creation chain.'); 
    180220     
     221        midgard_admin_sitewizard::$current_state = $this->parent_link; 
    181222        return $this->parent_link; 
    182223    } 
  • trunk/midgard/data/midgard_admin_sitewizard_creator_sitegroup.php

    r12581 r12966  
    228228        $this->verbose("Initializing next link in the creation chain."); 
    229229        $this->next_link = new midgard_admin_sitewizard_creator_host($this); 
     230        midgard_admin_sitewizard::$current_state = $this->next_link; 
    230231         
    231232        return $this->next_link; 
     
    235236    { 
    236237        $this->verbose("There is no parent link. Returning null"); 
     238         
     239        midgard_admin_sitewizard::$current_state = $this; 
    237240         
    238241        return null; 
  • trunk/midgard/data/midgard_admin_sitewizard_creator_structure.php

    r12720 r12966  
    3131 
    3232    private $created_groups = array(); 
     33     
     34    private $schemadb = null; 
     35     
     36    private $schemavalues = array(); 
    3337 
    3438    public function __construct($parent_link = null) 
     
    9296        } 
    9397    } 
     98     
     99    public function get_schemadb() 
     100    { 
     101        return $this->schemadb; 
     102    } 
    94103      
    95104    public function read_config($path) 
    96105    { 
    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        }  
    98114    } 
    99115     
     
    123139    public function next_link() 
    124140    { 
    125         $this->execute(); 
     141        $this->next_link = $this; 
     142        midgard_admin_sitewizard::$current_state = $this->next_link; 
    126143    } 
    127144      
    128145    public function previous_link() 
    129146    { 
     147        $this->verbose('Returning previous link in the creation chain.'); 
     148     
     149        midgard_admin_sitewizard::$current_state = $this->parent_link; 
    130150        return $this->parent_link; 
    131151    } 
     
    191211        $this->verbose("Creating a root group for group structure creation under group GUID: " .  $owner_guid); 
    192212 
    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         
    195223        $qb = new midgard_query_builder('midgard_group'); 
    196224        $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 
    197         $qb->add_constraint('owner', '=', $owner_group->id); 
     225        $qb->add_constraint('owner', '=', $owner_id); 
    198226        $qb->add_constraint('name', '=', $group_name); 
    199227 
     
    212240        { 
    213241            $this->creation_root_group = new midgard_group(); 
    214               $this->creation_root_group->owner = $owner_group->id; 
     242            $this->creation_root_group->owner = $owner_id; 
    215243            $this->creation_root_group->sitegroup = $this->sitegroup->id; 
    216244            $this->creation_root_group->name = $group_name; 
     
    273301                } 
    274302                 
    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); 
    276305         
    277306                // Setting additional parameters 
     
    291320        } 
    292321    } 
     322     
     323    public function set_schema_values($schemavalues) 
     324    {        
     325        $this->schemavalues = $schemavalues;       
     326    } 
    293327 
    294328    private function replace($string) 
     
    296330        $result = str_replace('__HOSTNAME__', $this->host->name, $string); 
    297331        $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             
    299345        return $result; 
    300346    } 
     
    368414            foreach ($parameter as $name => $value) 
    369415            { 
    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: " 
    371418                    . $object->guid); 
    372419             
     
    538585            foreach ($this->config as $structure) 
    539586            { 
    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"); 
    544591 
    545592                    $group_match = 0; 
     
    547594                    foreach ($groups as $group) 
    548595                    { 
    549                         if ($group->name == $candidate_group_name
     596                        if ($group->name == $candidate_group['name']
    550597                        { 
    551598                            $this->created_groups[$group->name] = $group; 
     
    556603                    if ($group_match > 0) 
    557604                    { 
    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");    
    559606                    } 
    560607                    elseif (count($groups) > 0) 
    561608                    { 
    562                         $this->verbose("Group \"" . $candidate_group_name . "\" does not exist! Creating now"); 
     609                        $this->verbose("Group \"" . $candidate_group['name'] . "\" does not exist! Creating now"); 
    563610            
    564611                        $new_group = new midgard_group(); 
    565612                        $new_group->owner = $group_owner_id; 
    566613                        $new_group->sitegroup = $this->sitegroup->id; 
    567                         $new_group->name = $candidate_group_name
     614                        $new_group->name = $this->replace($candidate_group['name'])
    568615                         
    569616                        if (!$new_group->create()) 
    570617                        { 
    571                             throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name  
     618                            throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group['name']  
    572619                                . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); 
    573620                        } 
     
    575622                        { 
    576623                            $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                             
    577648                            return true; 
    578649                        } 
     
    586657            foreach ($this->config as $structure) 
    587658            {         
    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"); 
    591662             
    592663                    $new_group = new midgard_group(); 
    593                     $new_group->name = $candidate_group_name
     664                    $new_group->name = $candidate_group['name']
    594665                    $new_group->sitegroup = $this->sitegroup->id; 
    595666                    $new_group->owner = $group_owner_id; 
     
    597668                    if (!$new_group->create()) 
    598669                    { 
    599                         throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name  
     670                        throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group['name']  
    600671                            . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr()); 
    601672                    } 
    602673                    else 
    603674                    { 
     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                             
    604700                         return true; 
    605701                    } 
     
    608704        } 
    609705    } 
     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    }    
    610726 
    611727    public function execute()