Changeset 22748

Show
Ignore:
Timestamp:
06/30/09 17:13:39 (1 year ago)
Author:
piotras
Message:

Refs #1204.
midgard_admin_sitewizard_nnn: get(set)_sitegroup moved to abstract class.
sitewizard_creator_structure can set root topic name explicitly.
midgard_setup_app sets structure creator's sitegroup.
midgard_setup_app configures sitegroup.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/ragnaroek/midgard/data/midgard/setup/php/midgard_admin_sitewizard_creator.php

    r17512 r22748  
    2121    protected $links = array(); 
    2222 
     23    protected $sitegroup = null; 
     24 
     25    protected $sitegroup_name = null; 
     26 
    2327    public function __construct(midgard_setup_config &$config, $parent_link = null) 
    2428    { 
     
    4246    } 
    4347 
    44     final function add_link($object) 
     48    final public function add_link($object) 
    4549    { 
    4650        $this->links[] = $object; 
    4751    } 
    4852 
    49     final function cleanup_links() 
     53    final public function cleanup_links() 
    5054    { 
    5155        if(empty($this->links)) 
     
    5660            $link->cleanup(); 
    5761        } 
     62    } 
     63 
     64    final public function set_sitegroup($identifier) 
     65    { 
     66        if($identifier == MIDGARD_SITEGROUP_0) 
     67        { 
     68            $this->sitegroup = new midgard_sitegroup(); 
     69            $this->sitegroup->name = null; 
     70 
     71            $this->sitegroup_name = null; 
     72 
     73            return; 
     74        } 
     75 
     76        if($this->sitegroup == null) 
     77        { 
     78            try 
     79            { 
     80                $this->sitegroup = new midgard_sitegroup($identifier); 
     81            } 
     82            catch (midgard_error_exception $e) { 
     83 
     84                $this->sitegroup = new midgard_sitegroup(); 
     85                $this->sitegroup_name = $this->sitegroup->name; 
     86            } 
     87        } 
     88    } 
     89 
     90    final public function get_sitegroup() 
     91    { 
     92        return $this->sitegroup; 
    5893    } 
    5994 
  • branches/ragnaroek/midgard/data/midgard/setup/php/midgard_admin_sitewizard_creator_host.php

    r20751 r22748  
    1414 
    1515final class midgard_admin_sitewizard_creator_host extends midgard_admin_sitewizard_creator 
    16 
    17     private $sitegroup = null; 
    18      
     16{    
    1917    private $host = null; 
    2018     
     
    257255        if(!$created) 
    258256        { 
    259             $this->setup_config->ui->warning(_("Failed to create root topic")); 
     257            $this->setup_config->ui->warning(_("Failed to create root topic") . " " . midgard_connection::get_error_string()); 
    260258            return FALSE; 
    261259        } 
     
    505503        return $this->host; 
    506504    } 
    507      
    508     public function get_sitegroup() 
    509     { 
    510         return $this->sitegroup; 
    511     } 
    512      
    513     public function set_sitegroup(midgard_sitegroup $sitegroup) 
    514     { 
    515         $this->sitegroup = $sitegroup; 
    516     } 
    517  
     505      
    518506    public function get_root_page() 
    519507    { 
  • branches/ragnaroek/midgard/data/midgard/setup/php/midgard_admin_sitewizard_creator_sitegroup.php

    r21945 r22748  
    1313 
    1414class midgard_admin_sitewizard_creator_sitegroup extends midgard_admin_sitewizard_creator 
    15 
    16     private $sitegroup = null; 
    17      
    18     private $sitegroup_name = 'midgard-project.org'; 
    19      
     15{    
    2016    private $sitegroup_admin_username = 'admin'; 
    2117     
     
    3935        // Do nothing 
    4036    } 
    41      
    42     public function set_sitegroup_name($sitegroup_name) 
    43     { 
    44         $this->verbose("Setting new sitegroup name \"" . $sitegroup_name . "\""); 
    45         $this->sitegroup_name = $sitegroup_name; 
    46  
    47         if($sitegroup_name == MIDGARD_SITEGROUP_0)  
    48         { 
    49             $this->sitegroup = new midgard_sitegroup(); 
    50             $this->sitegroup->name = null; 
    51  
    52             $this->sitegroup_name = null; 
    53  
    54             return; 
    55         } 
    56  
    57         if($this->sitegroup == null) 
    58         { 
    59             try  
    60             { 
    61                 $sg = new midgard_sitegroup($sitegroup_name); 
    62             } 
    63             catch (midgard_error_exception $e) { 
    64                  
    65                 /* We're in creation mode (probably). */ 
    66                 $sg = new midgard_sitegroup(); 
    67                 $sg->name = $sitegroup_name; 
    68             } 
    69  
    70             $this->sitegroup = $sg; 
    71         } 
    72     } 
    73      
     37         
    7438    public function set_sitegroup_admin_username($admin_name) 
    7539    { 
     
    186150        } 
    187151    } 
    188      
    189     public function get_sitegroup() 
    190     { 
    191         return $this->sitegroup; 
    192     } 
    193      
     152         
    194153    /** 
    195154     * Check if the user is in sitegroup zero. 
  • branches/ragnaroek/midgard/data/midgard/setup/php/midgard_admin_sitewizard_creator_structure.php

    r22737 r22748  
    2424    private $host_creator = null; 
    2525 
     26    private $root_topic_name = null; 
     27 
    2628    private $root_topic = null; 
    2729 
     
    3133 
    3234    private $creation_root_group = null; 
    33  
    34     private $sitegroup = null; 
    3535      
    3636    private $config = null; 
     
    110110        } 
    111111    } 
    112     
     112 
     113    public function set_root_topic_name($name) 
     114    { 
     115        /* Should be null special,  not allowed case */ 
     116        $this->root_topic_name = $name; 
     117    } 
     118 
     119    public function get_root_topic_name() 
     120    { 
     121        if ($this->root_topic_name != null) 
     122        { 
     123            return $this->root_topic_name; 
     124        } 
     125 
     126        return $this->replace($this->structure['root']['name']) . $this->get_host_prefix(); 
     127    } 
     128 
     129    private function get_host_name() 
     130    { 
     131        if (is_object($this->host)) 
     132        { 
     133            return $this->host->name; 
     134        } 
     135 
     136        return exec('hostname'); 
     137    }   
     138  
     139    private function get_host_prefix() 
     140    { 
     141        if (is_object($this->host)) 
     142        { 
     143            return $this->host->prefix; 
     144        } 
     145 
     146        return ""; 
     147    }   
     148 
     149    private function get_host_style() 
     150    { 
     151        if (is_object($this->host)) 
     152        { 
     153            return $this->host->style; 
     154        } 
     155 
     156        return 0; 
     157    }   
     158 
    113159    public function set_sitegroup_creator($object) 
    114160    { 
     
    370416            $this->creation_root_topic = new midgard_topic(); 
    371417            $this->creation_root_topic->extra = $topic_title; 
    372             $this->creation_root_topic->name = $topic_name
     418            $this->creation_root_topic->name = $this->get_root_topic_name()
    373419            $this->creation_root_topic->sitegroup = $this->sitegroup->id; 
    374420            $this->creation_root_topic->component = $component; 
     
    421467    private function replace($string) 
    422468    { 
    423         $result = str_replace('__HOSTNAME__', $this->host->name, $string); 
     469        $result = str_replace('__HOSTNAME__', $this->get_host_name(), $string); 
    424470        /* $result = str_replace('__HOSTTITLE__', $this->root_page->title, $result); */ 
    425471         
     
    448494            $topic = new midgard_topic(); 
    449495            $topic->up = $parent_node->id; 
    450             $topic->name = $this->replace($node['name']); 
     496            $topic->name = $this->get_root_topic_name(); 
    451497            $topic->extra = $this->replace($node['title']); 
    452498            $topic->sitegroup = $this->sitegroup->id; 
     
    643689            $this->creation_root_topic->sitegroup = $this->sitegroup->id; 
    644690            $this->creation_root_topic->extra = $this->replace($this->structure['root']['title']);  
    645             $this->creation_root_topic->name = $this->replace($this->structure['root']['name']) . $this->host->prefix
     691            $this->creation_root_topic->name = $this->get_root_topic_name()
    646692            $this->creation_root_topic->component = $this->structure['root']['component']; 
    647693             
     
    654700            else 
    655701            { 
    656                 $this->verbose("Setting style for topic " . $this->structure['root']['name'] . ": (" . $this->host->style . ")"); 
     702                $this->verbose("Setting style for topic " . $this->structure['root']['name'] . ": (" . $this->get_host_style() . ")"); 
    657703                 
    658704                if (isset($this->structure['root']['use_inherited_style']) && $this->structure['root']['use_inherited_style'] == false) 
     
    662708                else 
    663709                { 
    664                     $this->creation_root_topic->style = "/" . $this->get_host_style_name($this->host->style); 
     710                    $this->creation_root_topic->style = "/" . $this->get_host_style_name($this->get_host_style()); 
    665711                } 
    666712            } 
     
    674720            { 
    675721                throw new midgard_admin_sitewizard_exception("Failed to create root topic \""  
    676                     . $this->structure['root']['name'] . "\" for structure creation"); 
     722                    . $this->structure['root']['name'] . "\" for structure creation" . ". " . midgard_connection::get_error_string()); 
    677723 
    678724                return false;     
     
    693739                    else 
    694740                    { 
    695                         $this->creation_root_topic->parameter('midcom', 'style', "/" . $this->get_host_style_name($this->host->style)); 
     741                        $this->creation_root_topic->parameter('midcom', 'style', "/" . $this->get_host_style_name($this->get_host_style())); 
    696742                    } 
    697743                } 
     
    10281074        catch(midgard_admin_sitewizard_exception $e) 
    10291075        { 
    1030             $e->error();      
    10311076            //$this->parent_link->cleanup()  
    10321077            $this->cleanup(); 
    1033    
    1034             throw new midgard_admin_sitewizard_exception("Failed to create structure"); 
     1078  
     1079            $this->setup_config->ui->error(_("Failed to create structure") . $e->error());  
    10351080     
    10361081            return false; 
  • branches/ragnaroek/midgard/data/midgard/setup/php/midgard_setup_app.php

    r22734 r22748  
    1010    private $_apps = array(); 
    1111    private $_setup_config = null; 
     12    private $_app = null; 
     13    private $_app_name; 
     14    private $_sitegroup_name; 
    1215 
    1316    public function __construct(midgard_setup_config $config) 
     
    3942    } 
    4043 
    41     public function install($name = null) 
     44    private function configure_sitegroup() 
     45    { 
     46        $this->_setup_config->ui->message(_("Configure target Midgard domain (sitegroup) ")); 
     47 
     48        $sg_names = ''; 
     49        $i = 0; 
     50 
     51        $sg_array = midgard_sitegroup::list_names(); 
     52 
     53        if (!empty($sg_array)) 
     54        { 
     55            foreach ($sg_array as $name) 
     56            { 
     57                if ($i >= 1) 
     58                { 
     59                    $sg_names .= ", "; 
     60                } 
     61 
     62                $sg_names .= $name; 
     63                $i++; 
     64            } 
     65        } 
     66 
     67        if ($i == 0) 
     68        { 
     69            $sg_names .= 'none'; 
     70        } 
     71 
     72        $this->_sitegroup_name = $this->_setup_config->ui->get_text(_("Target Midgard domain (sitegroup) name ?"), "", $sg_names); 
     73 
     74        if ($this->_sitegroup_name === "") 
     75        { 
     76            $this->_setup_config->ui->message(_("Target Midgard domain (sitegroup) not selected")); 
     77            $this->configure_sitegroup(); 
     78        }  
     79    } 
     80 
     81    final public function install($name = null) 
    4282    { 
    4383        if ($name == null 
    4484            || $name === "")  
    4585        { 
    46             midgard_setup_ui_cli::warning(_("Expected Midgard application name to be installed.")); 
     86            $this->_setup_config->ui->warning(_("Expected Midgard application name to be installed.")); 
    4787            return; 
    4888        } 
     
    5090        if (!array_key_exists($name, $this->_apps)) 
    5191        { 
    52             midgard_setup_ui_cli::warning(_("Can not install {$name}. It is not registered as Midgard application.")); 
     92            $this->_setup_config->ui->warning(_("Can not install {$name}. It is not registered as Midgard application.")); 
    5393            return;           
    5494        } 
    5595 
    56         $app = $this->_apps[$name]; 
     96        $this->_app = $this->_apps[$name]; 
     97        $this->_app_name = $name; 
    5798 
     99        $this->install_pear_packages(); 
     100        $this->configure_sitegroup(); 
     101        $this->install_structure(); 
     102    } 
     103 
     104    private function install_pear_packages() 
     105    { 
    58106        $msp = new midgard_setup_pear(); 
    59107        $msp->prepare_pear(); 
     
    61109   
    62110        /* Install required packages from PEAR*/  
    63         if (!empty($app['packages'])) 
     111        if (!empty($this->_app['packages'])) 
    64112        { 
    65             foreach ($app['packages'] as $key => $name)  
     113            foreach ($this->_app['packages'] as $key => $name)  
    66114            { 
    67115                if (!$msp->install_midcom_package($name)) 
     
    76124        if (!empty($app['templates'])) 
    77125        { 
    78             foreach ($app['templates'] as $key => $name)  
     126            foreach ($this->_app['templates'] as $key => $name)  
    79127            { 
    80128                if (!$msp->install_midcom_package($name, true)) 
     
    85133            } 
    86134        } 
     135    } 
     136     
     137    private function install_structure() 
     138    { 
     139        if ($this->_app == null) 
     140        { 
     141            $this->_setup_config->ui->error(_("Can not install application structure. No application selected.")); 
     142            return;           
     143        } 
    87144 
    88145        $sc = new midgard_admin_sitewizard_creator_structure($this->_setup_config); 
    89         $sc->read_config(MIDGARD_SETUP_ROOT_DIR . "/" . $app['structure']); 
     146        $sc->set_sitegroup($this->_sitegroup_name); 
     147        $sc->set_root_topic_name($this->_app_name . " root topic"); 
     148        $sc->read_config(MIDGARD_SETUP_ROOT_DIR . "/" . $this->_app['structure']); 
    90149        $sc->execute();  
     150 
     151        $this->_setup_config->ui->message($this->_app_name . _(" successfully installed")); 
    91152    } 
    92153} 
  • branches/ragnaroek/midgard/data/midgard/setup/php/midgard_setup_wizard.php

    r22729 r22748  
    118118            $this->midgard_password = $this->setup_config->midgard_config->midgardpassword; 
    119119             
    120             $this->sitegroup_creator->set_sitegroup_name(MIDGARD_SITEGROUP_0); 
     120            $this->sitegroup_creator->set_sitegroup(MIDGARD_SITEGROUP_0); 
    121121            $this->sitegroup_creator->set_sitegroup_admin_username($this->midgard_username); 
    122122            $this->sitegroup_creator->set_sitegroup_admin_password($this->midgard_password);