Changeset 11954

Show
Ignore:
Timestamp:
08/31/07 17:49:04 (1 year ago)
Author:
juhana
Message:

Implemented index article creation

Files:

Legend:

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

    r11768 r11954  
    5353        $this->verbose('Initializing structure creation'); 
    5454 
    55        if ($this->host_creator == null) 
    56        
     55        if ($this->host_creator == null) 
     56           
    5757            if (!$this->host = new midgard_host($host_guid)) 
    58             { 
    59                 throw new midgard_admin_sitewizard_exception("Sitewizard couldn't initialize host object. Reason: " . mgd_errstr()); 
    60  
    61                 return false; 
     58                { 
     59                        throw new midgard_admin_sitewizard_exception("Sitewizard couldn't initialize host object. Reason: "  
     60                            . mgd_errstr()); 
     61 
     62                    return false; 
    6263            } 
    6364            else 
    6465            { 
    65                 $this->verbose("Getting sitegroup of host GUID: " . $this->host->guid); 
     66                    $this->verbose("Getting sitegroup of host GUID: " . $this->host->guid); 
    6667                $sitegroup_id = $this->host->sitegroup; 
    6768/* 
     
    7172                $this->sitegroup = mgd_get_sitegroup($sitegroup_id); 
    7273 
    73                 $this->verbose("Getting root page of host GUID: " . $this->host->guid); 
    74                 $this->root_page = new midgard_page(); 
    75                 $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); 
    7677 
    7778                $root_topic_guid = $this->root_page->parameter('midgard', 'midcom_root_topic_guid'); 
    7879 
    79                 if (!mgd_is_guid($root_topic_guid)) 
    80                
    81                     throw new midgard_admin_sitewizard_exception("Failed to get valid root topic guid from root page parameter GUID: "  
    82                       . $root_topic_guid . " Reason: " . mgd_errstr()); 
    83  
    84                     return false; 
    85                
    86                 else 
    87                
    88                     $this->verbose("Getting root topic of page GUID: " . $this->root_page->guid); 
    89                     $this->root_topic = new midgard_topic($root_topic_guid); 
     80                        if (!mgd_is_guid($root_topic_guid)) 
     81                       
     82                    throw new midgard_admin_sitewizard_exception("Failed to get valid root topic  
     83                        guid from root page parameter GUID: " . $root_topic_guid . " Reason: " . mgd_errstr()); 
     84 
     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); 
    9091                } 
    9192 
    92                 return true; 
    93            
     93                    return true; 
     94               
    9495        } 
    9596    } 
     
    113114        return $this->parent_link; 
    114115    } 
     116     
     117    public function create_index_article($topic_id, $title = '') 
     118    { 
     119        $this->verbose("Creating index article for topic ID: " . $topic_id . " Title: " . $title); 
     120     
     121        $article = new midgard_article(); 
     122        $article->topic = $topic_id; 
     123        $article->title = $title; 
     124        $article->name = 'index'; 
     125         
     126        if (!$article->create()) 
     127        { 
     128            throw new midgard_admin_sitewizard_exception("Failed to create index article GUID: "  
     129                    . $article->guid . " Reason: " . mgd_errstr());              
     130        } 
     131        else 
     132        { 
     133            return true; 
     134        } 
     135         
     136        return false;       
     137    } 
    115138 
    116139    public function set_creation_root_group($group_guid) 
    117140    { 
    118141        if (!$this->creation_root_group = new midgard_group($group_guid)) 
    119        
     142           
    120143            throw new midgard_admin_sitewizard_exception("Failed to set root group for structure creation GUID: "  
    121144                . $group_guid . " Reason: " . mgd_errstr());  
    122145         
    123             return true; 
    124        
    125         else 
    126        
     146                return true; 
     147           
     148            else 
     149           
    127150            $this->verbose("Setting group for structure creation GUID: " . $group_guid); 
    128151 
    129             return true; 
    130        
     152                return true; 
     153           
    131154    } 
    132155 
     
    134157    { 
    135158        if (!$this->creation_root_topic = new midgard_topic($topic_guid)) 
    136        
     159           
    137160            throw new midgard_admin_sitewizard_exception("Failed to set root topic for structure creation GUID: "  
    138161                . $topic_guid . " Reason: " . mgd_errstr());  
    139162         
    140             return true; 
    141        
    142         else 
    143        
     163                return true; 
     164           
     165            else 
     166           
    144167            $this->verbose("Setting topic for structure creation GUID: " . $topic_guid); 
    145168 
    146             return true; 
    147        
     169                return true; 
     170           
    148171    } 
    149172 
     
    154177        $owner_group = new midgard_group($owner_guid); 
    155178 
    156         $qb = new midgard_query_builder('midgard_group'); 
    157         $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 
    158         $qb->add_constraint('owner', '=', $owner_group->id); 
    159         $qb->add_constraint('name', '=', $group_name); 
    160  
    161         $groups = $qb->execute(); 
    162  
    163         if (count($groups) > 0) 
    164        
     179            $qb = new midgard_query_builder('midgard_group'); 
     180            $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 
     181            $qb->add_constraint('owner', '=', $owner_group->id); 
     182            $qb->add_constraint('name', '=', $group_name); 
     183 
     184            $groups = $qb->execute(); 
     185 
     186            if (count($groups) > 0) 
     187           
    165188            $this->verbose("Group \"" . $group_name . "\" GUID: " . $groups[0]->guid  
    166189                . " already exists. Setting as root group for structure creation."); 
    167190 
    168             $this->creation_root_group = $groups[0]; 
    169  
    170             return true; 
    171        
    172         else 
    173        
    174             $this->creation_root_group = new midgard_group(); 
    175             $this->creation_root_group->owner = $owner_group->id; 
    176             $this->creation_root_group->sitegroup = $this->sitegroup->id; 
    177             $this->creation_root_group->name = $group_name; 
     191                $this->creation_root_group = $groups[0]; 
     192 
     193                return true; 
     194           
     195            else 
     196           
     197                $this->creation_root_group = new midgard_group(); 
     198                $this->creation_root_group->owner = $owner_group->id; 
     199                $this->creation_root_group->sitegroup = $this->sitegroup->id; 
     200                $this->creation_root_group->name = $group_name; 
    178201 
    179202            if (!$this->creation_root_group->create()) 
    180             { 
    181                 throw new midgard_admin_sitewizard_exception("Failed to create root group for group structure creation under group GUID: "  
    182                     . $this->creation_root_group->guid); 
    183             } 
    184             else 
    185             { 
     203                { 
     204                throw new midgard_admin_sitewizard_exception("Failed to create root group for group  
     205                    structure creation under group GUID: " . $this->creation_root_group->guid); 
     206                } 
     207                else 
     208                { 
     209                return true; 
     210                } 
     211        } 
     212    } 
     213 
     214    public function create_creation_root_topic($topic_guid, $topic_name = '', $topic_title = '',  
     215        $component = '', $parameters = array(), $style = '', $create_index = false) 
     216    { 
     217        $this->verbose('Creating a root topic for structure creation'); 
     218 
     219        $topic = new midgard_topic($topic_guid); 
     220         
     221        $mc = new midgard_collector('midgard_topic', 'up', $topic->id); 
     222        $mc->add_constraint('name', '=', $topic_name); 
     223        $mc->set_key_property('id'); 
     224        $mc->execute(); 
     225        $keys = $mc->list_keys(); 
     226         
     227        if (count($keys) > 0) 
     228        { 
     229            throw new midgard_admin_sitewizard_exception("Can't create root topic! Reason: name already exists."); 
     230        } 
     231        else 
     232        { 
     233                $this->creation_root_topic = new midgard_topic(); 
     234                $this->creation_root_topic->extra = $topic_title; 
     235                $this->creation_root_topic->name = $topic_name; 
     236                $this->creation_root_topic->sitegroup = $this->sitegroup->id; 
     237                $this->creation_root_topic->component = $component; 
     238                $this->creation_root_topic->up = $topic->id; 
     239                 
     240                if (!empty($style)) 
     241                { 
     242                    $this->verbose("Setting style for topic" . $topic_name . ": (" . $style . ")"); 
     243                    $this->creation_root_topic->style = $style; 
     244                } 
     245 
     246            if (!$this->creation_root_topic->create()) 
     247                { 
     248                throw new midgard_admin_sitewizard_exception("Failed to create root topic for structure creation GUID: "  
     249                        . $this->creation_root_topic->guid . " Reason: " . mdg_errstr()); 
     250                } 
     251                else 
     252                { 
     253                    // Setting style parameter 
     254                    if (!empty($style)) 
     255                    { 
     256                        $this->creation_root_topic->parameter('midcom', 'style', $style); 
     257                    } 
     258                     
     259                $this->verbose("Created root topic for structure creation GUID: " . $this->creation_root_topic->guid); 
    186260             
    187                 return true; 
    188             } 
    189         } 
    190     } 
    191  
    192     public function create_creation_root_topic($topic_guid, $topic_name = "", $topic_title = "", $component = "", $parameters = array()) 
    193     { 
    194         $this->verbose('Creating a root topic for structure creation'); 
    195  
    196         $topic = new midgard_topic($topic_guid); 
    197  
    198         $this->creation_root_topic = new midgard_topic(); 
    199         $this->creation_root_topic->title = $topic_title; 
    200         $this->creation_root_topic->name = $topic_name; 
    201         $this->creation_root_topic->sitegroup = $this->sitegroup->id; 
    202         $this->creation_root_topic->component = $component; 
    203         $this->creation_root_topic->up = $topic->id; 
    204  
    205         if (!$this->creation_root_topic->create()) 
    206         { 
    207             throw new midgard_admin_sitewizard_exception("Failed to create root topic for structure creation GUID: "  
    208                 . $this->creation_root_topic->guid . " Reason: " . mdg_errstr()); 
    209         } 
    210         else 
    211         { 
    212             $this->verbose("Created root topic for structure creation GUID: " . $this->creation_root_topic->guid); 
    213              
    214             // Setting additional parameters 
    215             foreach ($parameters as $domain => $parameter) 
    216             { 
    217                 foreach ($parameter as $name => $value) 
    218                 { 
    219                     $this->creation_root_topic->parameter($domain, $name, $value); 
    220                 } 
    221             } 
    222         } 
     261                    // Setting additional parameters 
     262                foreach ($parameters as $domain => $parameter) 
     263                    { 
     264                    foreach ($parameter as $name => $value) 
     265                            { 
     266                        $this->creation_root_topic->parameter($domain, $name, $value); 
     267                            } 
     268                    } 
     269                     
     270                    if ($create_index == true) 
     271                    { 
     272                        $this->create_index_article($this->creation_root_topic->id, $topic_title); 
     273                    } 
     274                } 
     275            } 
    223276    } 
    224277 
     
    233286    private function create_topic_structure_recursive($nodes, $parent_node) 
    234287    { 
    235         foreach ($nodes as $node) 
    236        
     288            foreach ($nodes as $node) 
     289           
    237290            $this->verbose("Creating topic \"" . $this->replace($node['title']) . "\" under parent topic GUID: "  
    238291                . $parent_node->guid); 
    239292 
    240             $topic = new midgard_topic(); 
    241             $topic->up = $parent_node->id; 
     293                $topic = new midgard_topic(); 
     294                $topic->up = $parent_node->id; 
    242295            $topic->name = $this->replace($node['name']); 
    243             $topic->title = $this->replace($node['title']); 
    244             $topic->sitegroup = $this->sitegroup->id; 
    245             $topic->component = $node['component']; 
    246  
    247             if (!$topic->create()) 
    248             { 
    249                 throw new midagard_admin_sitewizard_exception("Failed to create topic \"" . $topic->title . "\" under parent GUID: "  
    250                     . $parent_node->guid); 
    251             } 
    252             else 
    253             { 
    254                 // Setting additional parameters 
    255                 if (isset($node['parameters']) && count($node['parameters']) > 0) 
     296                $topic->extra = $this->replace($node['title']); 
     297                $topic->sitegroup = $this->sitegroup->id; 
     298                $topic->component = $node['component']; 
     299                 
     300                if (isset($node['style']) && !empty($node['style'])) 
     301                { 
     302                    $this->verbose("Setting style for topic " . $node['name'] . ": (" . $node['style'] . ")"); 
     303                    $topic->style = $node['style']; 
     304                } 
     305 
     306                if (!$topic->create()) 
     307                { 
     308                throw new midagard_admin_sitewizard_exception("Failed to create topic \""  
     309                    . $topic->extra . "\" under parent GUID: " . $parent_node->guid); 
     310                } 
     311                else 
     312                { 
     313                    // Setting style parameter 
     314                    if (isset($node['style']) && !empty($node['style'])) 
     315                    { 
     316                        $topic->parameter('midcom', 'style', $node['style']); 
     317                    } 
     318                     
     319                    // Setting additional parameters 
     320                    if (isset($node['parameters']) && count($node['parameters']) > 0) 
    256321                { 
    257322                    $this->verbose("Starting to set additional parameters for topic GUID: " . $topic->guid); 
    258323                     
    259324                    $this->set_parameters($node, $topic); 
    260                 } 
    261  
    262                 // Setting midcom acl privileges 
    263                if (isset($node['acl']) && count($node['acl']) > 0) 
    264                { 
    265                    $this->verbose("Starting to set midcom acl privileges for topic GUID: " . $topic->guid); 
    266  
    267                    $this->set_privileges($node, $this->creation_root_topic); 
    268                } 
    269             } 
    270  
    271             if (isset($node['nodes']) && count($node['nodes']) > 0) 
    272             { 
     325                        } 
     326 
     327                        // Setting midcom acl privileges 
     328                if (isset($node['acl']) && count($node['acl']) > 0) 
     329                    { 
     330                    $this->verbose("Starting to set midcom acl privileges for topic GUID: " . $topic->guid); 
     331 
     332                    $this->set_privileges($node, $this->creation_root_topic); 
     333                    } 
     334                     
     335                    if (isset($node['create_index']) && $node['create_index'] == true) 
     336                    { 
     337                        $this->create_index_article($topic->id, $this->replace($node['title'])); 
     338                    } 
     339                } 
     340 
     341                if (isset($node['nodes']) && count($node['nodes']) > 0) 
     342                { 
    273343                $this->create_topic_structure_recursive($node['nodes']); 
    274            
    275        
     344               
     345           
    276346    } 
    277347 
     
    279349    { 
    280350        foreach ($config_node['parameters'] as $domain => $parameter) 
    281        
    282             foreach ($parameter as $name => $value) 
    283            
     351           
     352                foreach ($parameter as $name => $value) 
     353               
    284354                $this->verbose("Setting parameter (" . $domain . "," . $name . "," . $value .") for object GUID: "  
    285355                    . $object->guid); 
    286356                 
    287                 $object->parameter($domain, $name, $value); 
    288            
    289         } 
    290         return true; 
     357                        $object->parameter($domain, $name, $value); 
     358               
     359        } 
     360            return true; 
    291361    } 
    292362 
     
    294364    { 
    295365        foreach($config_node['acl'] as $group_name => $privilege) 
    296        
    297             foreach($privilege as $name => $value) 
    298            
    299                 if (array_key_exists($group_name, $this->created_groups)) 
    300                
     366           
     367                foreach($privilege as $name => $value) 
     368               
     369                    if (array_key_exists($group_name, $this->created_groups)) 
     370                       
    301371                    $acl = new midcom_core_privilege_db();  
    302                     $acl->objectguid = $object->guid; 
    303                     $acl->name = $name; 
    304                     $acl->sitegroup = $this->sitegroup->id; 
    305                     $acl->assignee = "group:" . $this->created_groups[$group_name]->guid; 
    306                     $acl->value = $value; 
     372                            $acl->objectguid = $object->guid; 
     373                            $acl->name = $name; 
     374                            $acl->sitegroup = $this->sitegroup->id; 
     375                            $acl->assignee = "group:" . $this->created_groups[$group_name]->guid; 
     376                            $acl->value = $value; 
    307377                 
    308                     if (!$acl->create()) 
    309                    
     378                            if (!$acl->create()) 
     379                           
    310380                        throw new midgard_admin_sitewizard_exception(); 
    311                    
    312                     else 
    313                    
    314                         $this->verbose("ACL (" . $acl->name . "," . $acl->assignee . "," . $acl->value . " set for object GUID: "  
    315                           . $object->guid); 
     381                           
     382                            else 
     383                           
     384                        $this->verbose("ACL (" . $acl->name . "," . $acl->assignee . ","  
     385                            . $acl->value . " set for object GUID: " . $object->guid); 
    316386                         
    317                         return true; 
    318                    
    319                
    320             }  
     387                                    return true; 
     388                           
     389                       
     390                }  
    321391        } 
    322392    } 
     
    326396        $this->verbose("Starting to create topic structure under topic GUID: " . $this->creation_root_topic->guid); 
    327397 
    328         foreach ($this->config as $structure) 
    329        
    330              $this->structure = $structure; 
    331        
     398            foreach ($this->config as $structure) 
     399           
     400                $this->structure = $structure; 
     401           
    332402 
    333403        // Creating root topic from configuration if it hasn't been set already 
    334404        if ($this->creation_root_topic == null) 
    335        
     405           
    336406            $this->verbose('Creating root topic from configuration'); 
    337407 
    338             $this->creation_root_topic = midgard_topic(); 
    339             $this->creation_root_topic->up = 0; 
    340             $this->creation_root_topic->sitegroup = $this->sitegroup->id; 
    341             $this->creation_root_topic->title = $this->structure['root']['title'];  
    342             $this->creation_root_topic->name = $this->structure['root']['name']; 
    343  
    344             if (!$this->creation_root_topic->create()) 
    345             { 
    346                 throw new midgard_admin_sitewizard_exception("Failed to create root topic \"" . $this->structure['root']['name']  
    347                     . "\" for structure creation"); 
    348  
    349                 return false;     
    350             } 
    351             else 
    352             { 
    353                 // Setting additional parameters 
    354                 if (isset($this->structure['root']['parameters']) && count($this->structure['root']['parameters']) > 0) 
    355                 { 
    356                     $this->set_parameters($this->structure['root'], $this->creation_root_topic); 
     408                $this->creation_root_topic = midgard_topic(); 
     409                $this->creation_root_topic->up = 0; 
     410                $this->creation_root_topic->sitegroup = $this->sitegroup->id; 
     411                $this->creation_root_topic->extra = $this->structure['root']['title'];  
     412                $this->creation_root_topic->name = $this->structure['root']['name']; 
     413                 
     414                if (isset($node['root']['style']) && !empty($node['root']['style'])) 
     415                { 
     416                    $this->verbose("Setting style for topic " . $this->structure['root']['name']  
     417                        . "(" . $node['root']['style'] . ")"); 
     418                    $this->creation_root_topic->style = $node['root']['style']; 
     419                } 
     420 
     421                if (!$this->creation_root_topic->create()) 
     422                { 
     423                throw new midgard_admin_sitewizard_exception("Failed to create root topic \""  
     424                    . $this->structure['root']['name'] . "\" for structure creation"); 
     425 
     426                        return false;     
     427                } 
     428                else 
     429                { 
     430                    // Setting style parameter 
     431                    if (isset($node['root']['style']) && !empty($node['root']['style'])) 
     432                    { 
     433                         $this->creation_root_topic->parameter('midcom', 'style', $node['root']['style']); 
     434                    } 
     435                 
     436                    // Setting additional parameters 
     437                        if (isset($this->structure['root']['parameters']) && count($this->structure['root']['parameters']) > 0) 
     438                        { 
     439                            $this->set_parameters($this->structure['root'], $this->creation_root_topic); 
    357440                } 
    358441 
    359442                // Setting midcom acl privileges 
    360443                if (isset($this->structure['root']['acl']) && count($this->structure['root']['acl']) > 0) 
    361                
     444                   
    362445                    $this->set_privileges($this->structure['root'], $this->creation_root_topic); 
    363                 } 
    364             } 
     446                        } 
     447                         
     448                        if (isset($this->structure['root']['create_index']) && $this->structure['root']['create_index'] == true) 
     449                        { 
     450                        $this->create_index_article($this->creation_root_topic->id, $this->replace($node['root']['title'])); 
     451                        } 
     452                } 
    365453        } 
    366454 
    367455        // Making sure the topic is empty before creating a structure 
    368         $qb = new midgard_query_builder('midgard_topic'); 
    369         $qb->add_constraint('up', '=', $this->creation_root_topic->id); 
    370         $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 
    371         $topics = $qb->execute(); 
     456           $qb = new midgard_query_builder('midgard_topic'); 
     457           $qb->add_constraint('up', '=', $this->creation_root_topic->id); 
     458           $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 
     459       $topics = $qb->execute(); 
    372460         
    373         if (count($topics) != 0) 
    374        
    375             throw new midgard_admin_sitewizard_exception('Creation root topic is not empty!'); 
    376        
    377         else 
    378        
    379             try 
    380            
    381                 $this->create_topic_structure_recursive($this->structure['root']['nodes'], $this->creation_root_topic); 
    382            
    383             catch (midgard_admin_sitewizard_exception $e) 
    384            
     461           if (count($topics) != 0) 
     462           
     463               throw new midgard_admin_sitewizard_exception('Creation root topic is not empty!'); 
     464           
     465           else 
     466           
     467           try 
     468               
     469                   $this->create_topic_structure_recursive($this->structure['root']['nodes'], $this->creation_root_topic); 
     470               
     471               catch (midgard_admin_sitewizard_exception $e) 
     472               
    385473                $e->error(); 
    386474 
    387475                throw new midgard_admin_sitewizard_exception("Failed to create topic structure under topic GUID: "  
    388                     . $this->creation_root_topic->guid . "Reason: " . mgd_errstr()); 
     476                            . $this->creation_root_topic->guid . "Reason: " . mgd_errstr()); 
    389477             
    390            
    391        
     478               
     479           
    392480    } 
    393481 
     
    395483    { 
    396484        if ($this->creation_root_group != null) 
    397         {    
     485            {    
    398486            $group_owner_id = $this->creation_root_group->id; 
    399        
    400         else 
    401        
    402             $group_owner_id = $this->sitegroup->admingroup; 
    403        
     487           
     488            else 
     489           
     490                 $group_owner_id = $this->sitegroup->admingroup; 
     491           
    404492 
    405493        $this->verbose("Starting to create groups under group ID: " . $group_owner_id); 
    406494 
    407495        $qb = new midgard_query_builder('midgard_group'); 
    408         $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 
    409         $qb->add_constraint('owner', '=', $group_owner_id); 
    410         $groups = $qb->execute(); 
    411  
    412         if (count($groups) != 0) 
    413         { 
    414             // Ok, let's first check if a group already exists 
    415              
    416             foreach ($this->config as $structure) 
    417             { 
     496            $qb->add_constraint('sitegroup', '=', $this->sitegroup->id); 
     497            $qb->add_constraint('owner', '=', $group_owner_id); 
     498            $groups = $qb->execute(); 
     499 
     500            if (count($groups) != 0) 
     501            { 
     502            // Ok, let's first check if a group already exists           
     503                foreach ($this->config as $structure) 
     504                { 
    418505                foreach ($structure['groups'] as $candidate_group_name) 
    419                 { 
    420                     $this->verbose("Checking if group \"" . $candidate_group_name . "\" already exists"); 
     506                        { 
     507                     
     508                            $this->verbose("Checking if group \"" . $candidate_group_name . "\" already exists"); 
    421509 
    422510                    $group_match = 0; 
    423511 
    424                     foreach ($groups as $group) 
    425                    
     512                            foreach ($groups as $group) 
     513                           
    426514                        if ($group->name == $candidate_group_name) 
    427                        
     515                                   
    428516                            $this->created_groups[$group->name] = $group; 
    429                             $group_match++;  
    430                        
    431                    
    432  
    433                     if ($group_match > 0) 
    434                    
    435                         $this->verbose("Group \"" . $candidate_group_name . "\" already exists! No need to create");    
    436                    
    437                     else 
    438                    
     517                                        $group_match++;  
     518                                   
     519                           
     520 
     521                            if ($group_match > 0) 
     522                           
     523                                $this->verbose("Group \"" . $candidate_group_name . "\" already exists! No need to create");    
     524                           
     525                            elseif (count($groups) > 0) 
     526                           
    439527                        $this->verbose("Group \"" . $candidate_group_name . "\" does not exist! Creating now"); 
    440528                    
    441529                        $new_group = new midgard_group(); 
    442                         $new_group->owner = $group_owner_id; 
    443                         $new_group->sitegroup = $this->sitegroup->id; 
    444                         $new_group->name = $candidate_group_name; 
     530                                    $new_group->owner = $group_owner_id; 
     531                                    $new_group->sitegroup = $this->sitegroup->id; 
     532                                    $new_group->name = $candidate_group_name; 
    445533                         
    446                         if (!$new_group->create()) 
    447                        
     534                                    if (!$new_group->create()) 
     535                                   
    448536                            throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name  
    449                                 . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); 
    450                         } 
    451                         else 
    452                         { 
    453                             $this->created_groups[$new_group->name] = $new_group;  
    454                             return true; 
    455                         } 
    456                     } 
    457                 } 
    458             } 
    459         } 
    460         else 
    461         { 
    462             // There are no groups so we can just create the groups from config file 
    463              
    464             foreach ($this->config as $structure) 
    465             {        
     537                                            . "\" GUID: " . $new_group->guid . " Reason: " . mgd_errstr()); 
     538                                    } 
     539                                    else 
     540                                    { 
     541                                        $this->created_groups[$new_group->name] = $new_group;  
     542                                        return true; 
     543                                    } 
     544                    } 
     545                        } 
     546                } 
     547            } 
     548            else 
     549            { 
     550                // There are no groups so we can just create the groups from config file          
     551                foreach ($this->config as $structure) 
     552                {            
    466553                foreach ($structure['groups'] as $candidate_group_name) 
    467                
     554                       
    468555                    $this->verbose("Group \"" . $candidate_group_name . "\" does not exist! Creating now"); 
    469556                     
    470557                    $new_group = new midgard_group(); 
    471                     $new_group->name = $candidate_group_name; 
     558                            $new_group->name = $candidate_group_name; 
    472559                    $new_group->sitegroup = $this->sitegroup->id; 
    473                     $new_group->owner = $group_owner_id; 
     560                            $new_group->owner = $group_owner_id; 
    474561 
    475562                    if (!$new_group->create()) 
    476                    
     563                           
    477564                        throw new midgard_admin_sitewizard("Failed to create group \"" . $candidate_group_name  
    478                             . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr()); 
    479                    
    480                     else 
    481                    
    482                         return true; 
    483                    
    484                
    485             }             
    486        
     565                                        . "\" GUID: " . $new_group->guid . " Reason: " . meg_errstr()); 
     566                           
     567                            else 
     568                       
     569                             return true; 
     570                           
     571                       
     572                }             
     573       
    487574    } 
    488575 
     
    493580        if ($this->parent_link != null) 
    494581        { 
    495             $this->verbose('Executing parent'); 
    496  
    497             try 
    498            
     582                $this->verbose('Executing parent'); 
     583 
     584                try 
     585               
    499586                $this->parent_link->execute();           
    500            
    501             catch (midgard_admin_sitewizard_exception $e) 
    502            
     587               
     588                catch (midgard_admin_sitewizard_exception $e) 
     589               
    503590                $e->error(); 
    504591 
    505592                throw new midgard_admin_sitewizard_exception("Failed to execute parent creator"); 
    506            
     593               
    507594        } 
    508595 
    509596        try  
    510         { 
    511             $this->create_group_structure(); 
    512             $this->create_topic_structure(); 
    513  
    514             $this->verbose("Sitewizard created website structure successfully. Now cleaning up..."); 
    515  
    516             $this->cleanup(); 
    517         } 
    518         catch(midgard_admin_sitewizard_exception $e) 
    519         { 
    520             $e->error(); 
     597            { 
     598                $this->create_group_structure(); 
     599                $this->create_topic_structure(); 
     600 
     601                $this->verbose("Sitewizard created website structure successfully. Now cleaning up..."); 
     602 
     603                $this->cleanup(); 
     604                 
     605                return $this->creation_root_topic->guid; 
     606        } 
     607            catch(midgard_admin_sitewizard_exception $e) 
     608            { 
     609                $e->error(); 
    521610             
    522611            $this->cleanup(); 
    523  
    524             throw new midgard_admin_sitewizard_exception("Failed to create structure"); 
     612   
     613                throw new midgard_admin_sitewizard_exception("Failed to create structure"); 
    525614         
    526             return false; 
    527        
     615                return false; 
     616           
    528617    } 
    529618}