Changeset 12559

Show
Ignore:
Timestamp:
09/28/07 00:57:43 (1 year ago)
Author:
bergie
Message:

Fix some notices

Files:

Legend:

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

    r12558 r12559  
    2525 
    2626    private $sitegroup = null; 
    27         
     27      
    2828    private $config = null; 
    29         
     29      
    3030    private $structure = null; 
    3131 
     
    5454 
    5555        if ($this->host_creator == null) 
    56            { 
     56         { 
    5757            if (!$this->host = new midgard_host($host_guid)) 
    58                { 
    59                        throw new midgard_admin_sitewizard_exception("Sitewizard couldn't initialize host  
    60                            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; 
    6363            } 
    6464            else 
    6565            { 
    66                    $this->verbose("Getting sitegroup of host GUID: " . $this->host->guid); 
     66                $this->verbose("Getting sitegroup of host GUID: " . $this->host->guid); 
    6767                $sitegroup_id = $this->host->sitegroup; 
    6868/* 
    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); 
    7171*/ 
    7272                $this->sitegroup = mgd_get_sitegroup($sitegroup_id); 
    7373 
    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); 
    7777 
    7878                $root_topic_guid = $this->root_page->parameter('midgard', 'midcom_root_topic_guid'); 
    7979 
    80                        if (empty($root_topic_guid)) 
    81                        { 
     80                if (empty($root_topic_guid)) 
     81                { 
    8282                    throw new midgard_admin_sitewizard_exception("Failed to get valid root topic  
    8383                        guid from root page parameter GUID: " . $root_topic_guid . " Reason: " . mgd_errstr()); 
    8484 
    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         
     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      
    9898    public function read_config($path) 
    9999    { 
    100         $this->config = $this->get_structure_config_filesystem($path);  
     100        $this->config = $this->get_structure_config_filesystem($path);     
    101101    } 
    102102     
     
    121121        } 
    122122    } 
    123         
     123      
    124124   /** 
    125125    * There is no next link in the chain  
     
    130130        $this->execute(); 
    131131    } 
    132         
     132      
    133133    public function previous_link() 
    134134    { 
     
    148148        { 
    149149            throw new midgard_admin_sitewizard_exception("Failed to create index article GUID: "  
    150                    . $article->guid . " Reason: " . mgd_errstr());              
     150                . $article->guid . " Reason: " . mgd_errstr());              
    151151        } 
    152152        else 
     
    161161    { 
    162162        if (!$this->creation_root_group = new midgard_group($group_guid)) 
    163            { 
     163        { 
    164164            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            else 
    170            { 
     165            . $group_guid . " Reason: " . mgd_errstr());  
     166     
     167            return true; 
     168        } 
     169        else 
     170        { 
    171171            $this->verbose("Setting group for structure creation GUID: " . $group_guid); 
    172172 
    173                return true; 
    174            } 
     173            return true; 
     174        } 
    175175    } 
    176176 
     
    178178    { 
    179179        if (!$this->creation_root_topic = new midgard_topic($topic_guid)) 
    180            { 
     180        { 
    181181            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            else 
    187            { 
     182            . $topic_guid . " Reason: " . mgd_errstr());  
     183     
     184            return true; 
     185        } 
     186        else 
     187        { 
    188188            $this->verbose("Setting topic for structure creation GUID: " . $topic_guid); 
    189189 
    190                return true; 
    191            } 
     190            return true; 
     191        } 
    192192    } 
    193193 
     
    198198        $owner_group = new midgard_group($owner_guid); 
    199199 
    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        { 
    209209            $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            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; 
     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; 
    222222 
    223223            if (!$this->creation_root_group->create()) 
    224                { 
     224            { 
    225225                throw new midgard_admin_sitewizard_exception("Failed to create root group for group  
    226226                    structure creation under group GUID: " . $this->creation_root_group->guid); 
    227                } 
    228                else 
    229                { 
     227            } 
     228            else 
     229            { 
    230230                return true; 
    231                } 
     231            } 
    232232        } 
    233233    } 
     
    252252        else 
    253253        { 
    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            } 
    266266 
    267267            if (!$this->creation_root_topic->create()) 
    268                { 
     268            { 
    269269                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                else 
    273                { 
    274                    // Setting style parameter 
    275                    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                 
    280280                $this->verbose("Created root topic for structure creation GUID: " . $this->creation_root_topic->guid); 
    281             
    282                    // Setting additional parameters 
     281         
     282                // Setting additional parameters 
    283283                foreach ($parameters as $domain => $parameter) 
    284                    { 
     284                { 
    285285                    foreach ($parameter as $name => $value) 
    286                            { 
     286                    { 
    287287                        $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        } 
    297297    } 
    298298 
     
    307307    private function create_topic_structure_recursive($nodes, $parent_node) 
    308308    { 
    309            foreach ($nodes as $node) 
    310            { 
     309        foreach ($nodes as $node) 
     310        { 
    311311            $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; 
    316316            $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            { 
    329329                throw new midagard_admin_sitewizard_exception("Failed to create topic \""  
    330330                    . $topic->extra . "\" under parent GUID: " . $parent_node->guid); 
    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) 
     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) 
    342342                { 
    343343                    $this->verbose("Starting to set additional parameters for topic GUID: " . $topic->guid); 
    344344                     
    345345                    $this->set_parameters($node, $topic); 
    346                        } 
    347  
    348                        // Setting midcom acl privileges 
     346                } 
     347 
     348                // Setting midcom acl privileges 
    349349                if (isset($node['acl']) && count($node['acl']) > 0) 
    350                    { 
     350                { 
    351351                    $this->verbose("Starting to set midcom acl privileges for topic GUID: " . $topic->guid); 
    352352 
    353353                    $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            { 
    364364                $this->create_topic_structure_recursive($node['nodes']); 
    365                } 
    366            } 
     365            } 
     366        } 
    367367    } 
    368368 
     
    370370    { 
    371371        foreach ($config_node['parameters'] as $domain => $parameter) 
    372            { 
    373                foreach ($parameter as $name => $value) 
    374                { 
     372        { 
     373            foreach ($parameter as $name => $value) 
     374            { 
    375375                $this->verbose("Setting parameter (" . $domain . "," . $name . "," . $value .") for object GUID: "  
    376376                    . $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; 
    382382    } 
    383383 
     
    385385    { 
    386386        foreach($config_node['acl'] as $identifier => $privilege) 
    387            { 
     387        { 
    388388            $assignee = null 
    389389            if (array_key_exists($assignee, $this->created_groups)) 
     
    402402            } 
    403403             
    404                foreach($privilege as $name => $value) 
    405                { 
     404            foreach($privilege as $name => $value) 
     405            { 
    406406                $acl = new midcom_core_privilege_db();  
    407407                $acl->objectguid = $object->guid; 
     
    422422                    return true; 
    423423                } 
    424                }  
     424            }  
    425425        } 
    426426    } 
     
    428428    public function create_topic_structure() 
    429429    { 
    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        } 
    436441 
    437442        // Creating root topic from configuration if it hasn't been set already 
    438443        if ($this->creation_root_topic == null) 
    439            { 
     444        { 
    440445            $this->verbose('Creating root topic from configuration'); 
    441446 
    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            { 
    457462                throw new midgard_admin_sitewizard_exception("Failed to create root topic \""  
    458463                    . $this->structure['root']['name'] . "\" for structure creation"); 
    459464 
    460                        return false;     
    461                } 
    462                else 
    463                { 
    464                    // Setting style parameter 
    465                    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 parameters 
    471                        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); 
    474479                } 
    475480 
    476481                // Setting midcom acl privileges 
    477482                if (isset($this->structure['root']['acl']) && count($this->structure['root']['acl']) > 0) 
    478                    { 
     483                { 
    479484                    $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            } 
    487492        } 
    488493 
    489494        // 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); 
    493498       $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           else 
    500           { 
     499     
     500       if (count($topics) > 0) 
     501       { 
     502           throw new midgard_admin_sitewizard_exception('Creation root topic is not empty!'); 
     503       } 
     504       else 
     505       { 
    501506           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           { 
    507512                $e->error(); 
    508513 
    509514                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        } 
    514519    } 
    515520 
     
    517522    { 
    518523        if ($this->creation_root_group != null) 
    519            {    
     524        {    
    520525            $group_owner_id = $this->creation_root_group->id; 
    521            } 
    522            else 
    523            { 
    524                 $group_owner_id = $this->sitegroup->admingroup; 
    525            } 
     526        } 
     527        else 
     528        { 
     529             $group_owner_id = $this->sitegroup->admingroup; 
     530        } 
    526531 
    527532        $this->verbose("Starting to create groups under group ID: " . $group_owner_id); 
    528533 
    529534        $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        { 
    536541            // Ok, let's first check if a group already exists           
    537                foreach ($this->config as $structure) 
    538                { 
     542            foreach ($this->config as $structure) 
     543            { 
    539544                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"); 
    543548 
    544549                    $group_match = 0; 
    545550 
    546                            foreach ($groups as $group) 
    547                            { 
     551                    foreach ($groups as $group) 
     552                    { 
    548553                        if ($group->name == $candidate_group_name) 
    549                                    { 
     554                        { 
    550555                            $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                    { 
    561566                        $this->verbose("Group \"" . $candidate_group_name . "\" does not exist! Creating now"); 
    562                    
     567            
    563568                        $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; 
    567572                         
    568                                    if (!$new_group->create()) 
    569                                    { 
     573                        if (!$new_group->create()) 
     574                        { 
    570575                            throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name  
    571                                            . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); 
    572                                    } 
    573                                    else 
    574                                    { 
    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                        } 
    578583                    } 
    579                        } 
    580                } 
    581            } 
    582            else 
    583            { 
    584                // There are no groups so we can just create the groups from config file          
    585                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            {         
    587592                foreach ($structure['groups'] as $candidate_group_name) 
    588                        { 
     593                { 
    589594                    $this->verbose("Group \"" . $candidate_group_name . "\" does not exist! Creating now"); 
    590                     
     595             
    591596                    $new_group = new midgard_group(); 
    592                            $new_group->name = $candidate_group_name; 
     597                    $new_group->name = $candidate_group_name; 
    593598                    $new_group->sitegroup = $this->sitegroup->id; 
    594                            $new_group->owner = $group_owner_id; 
     599                    $new_group->owner = $group_owner_id; 
    595600 
    596601                    if (!$new_group->create()) 
    597                            { 
     602                    { 
    598603                        throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name  
    599                                        . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr()); 
    600                            } 
    601                            else 
    602                        { 
    603                             return true; 
    604                            } 
    605                        } 
    606                }             
     604                            . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr()); 
     605                    } 
     606                    else 
     607                    { 
     608                         return true; 
     609                    } 
     610                } 
     611            }             
    607612        } 
    608613    } 
     
    614619        if ($this->parent_link != null) 
    615620        { 
    616                $this->verbose('Executing parent'); 
    617  
    618                try 
    619                { 
    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            { 
    624629                $e->error(); 
    625630 
    626631                throw new midgard_admin_sitewizard_exception("Failed to execute parent creator"); 
    627                } 
     632            } 
    628633        } 
    629634 
    630635        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();       
    644649            $this->cleanup(); 
    645650   
    646                throw new midgard_admin_sitewizard_exception("Failed to create structure");&nb