midgard.admin.wizards
midgard.admin.wizards is a site creation and configuration tool in MidCOM which is designed to run custom made site wizard plugins.
Installation
Midgard Wizards may be installed from PEAR packages. Midgard Wizards is currently available only in Midcom 2.8. To get it running, generate a website for it using the following command:
# php /usr/share/php/midcom/lib/midgard/admin/sitegroup/bin/create-host.php -u admin -p password --sitegroup_id 0 --topic_midcom midgard.admin.wizards --hostname www.example.net --host_prefix /wizards --extend_style template_Simplegray --topic_name "Midgard Wizards"
After this Midgard Wizards should be available in http://www.example.net/wizards/.
Default site wizard usage
Default site wizard is not implemented yet...only some custom ones...
Custom wizards
Midgard Wizards component is based on a plugin architecture. Custom site wizards are implemented as plugins that are configured in a plugin group. You can create as many plugins and as many plugin groups (site wizards) you might need. This is very flexible compared to the Midgard Site Wizard.
Implementing plugins
To do this you need to be familiar with authoring Midcom components.
- Create a new file "myplugin.php" in the components plugins folder
- Implement a class myplugin that extends midcom_baseclasses_components_handler
Implement get_plugin_handlers() function:
function get_plugin_handlers() { return array ( 'sitewizard' => array ( 'handler' => array('myplugin', 'create_website'), ), ); }Implement a handler function:
function _handler_create_website() { // Do something }Implement a show function:
function _show_create_website() { midcom_show_style('my_style'); }Implement _on_initialize() function
function _on_initialize() { if ( isset($this->_request_data['plugin_config']['sitewizard_path']) && !empty($this->_request_data['plugin_config']['sitewizard_path'])) { require_once($this->_request_data['plugin_config']['sitewizard_path']); } else { $_MIDCOM->uimessages->add( $this->_l10n->get('midcom.admin.wizards'), $this->_l10n->get('sitewizard was not found') ); $_MIDCOM->relocate(''); } parent::_on_initialize(); }
Tips:
Relocating to next plugin:
$_MIDCOM->relocate($this->_request_data'next_plugin_full_path');
Accessing plugin config:
$my_config_option = $this->_request_data['plugin_config']['my_config_option'];
Using midgard_admin_sitewizard classes to do the hard work
These classes are located in Midgard svn trunk (trunk/midgard/data):
- midgard_admin_sitewizard.php
- midgard_admin_sitewizard_creator.php
- midgard_admin_sitewizard_creator_host.php
- midgard_admin_sitewizard_creator_sitegroup.php
- midgard_admin_sitewizard_creator_structure.php
- midgard_admin_sitewizard_creator_exception.php
- midgard_admin_sitewizard_cli.php
Example of usage:
try
{
$sitewizard = new midgard_admin_sitewizard();
$sitewizard->set_verbose(true);
$sitegroup_creator = $sitewizard->initialize_sitegroup_creation();
$sitegroup_creator->set_sitegroup_name("Test");
$sitegroup_creator->set_sitegroup_admin_username("user");
$sitegroup_creator->set_sitegroup_admin_password("pass");
$host_creator = $sitegroup_creator->next_link();
$host_creator->set_verbose(false);
$host_creator->set_host_url('http://www.test.com');
$host_creator->set_host_prefix('/test');
$structure_creator = $host_creator->next_link();
$structure_creator->set_verbose(false);
$structure_creator->read_config('structure_config.inc');
$structure_creator->execute();
}
catch (midgard_admin_sitewizard_exception $e)
{
$e->error();
}
Calling execute() will execute the whole site wizard chain from the beginning. Creator classes can also be initialized and executed separately.
try
{
$sitewizard = new midgard_admin_sitewizard();
$sitewizard->set_verbose(true);
$host_guid = '983e66725acd11db845a197adaa843af43af';
$structure_creator = $sitewizard->initialize_structure_creation($host_guid);
$structure_creator->set_verbose(false);
$structure_creator->read_config('structure_config.inc');
$structure_creator->execute();
}
catch (midgard_admin_sitewizard_exception $e)
{
$e->error();
}
Configuring
Custom site wizards are configured in the components config. Plugins may have their own configuration options but a basic configuration looks like this:
'plugin_groups' => array
(
'my_sitewizard' => array
(
'title' => 'My Sitewizard',
'description' => 'My Sitewizard',
'plugins' => array
(
'create_my_sitegroup' => array
(
'class' => 'create_my_sitegroup',
'src' => 'file:/midgard/admin/wizards/plugins/create_my_sitegroup.php',
'name' => 'My Sitegroup creation',
'config' => array
(
'sitewizard_path' => '/usr/share/php/midcom/static/data/midgard_admin_sitewizard.php',
),
),
'create_my_host' => array
(
'class' => 'create_host_host',
'src' => 'file:/midgard/admin/wizards/plugins/create_my_host.php',
'name' => 'My Host Creation',
'config' => array
(
'sitewizard_path' => '/usr/share/php/midcom/static/data/midgard_admin_sitewizard.php',
),
),
),
),
),
The plugins are executed in the same order they appear in a configuration.
Structure templates
Structure templates are used to define topic and user group structures that can be automatically created with a site wizard plugin. Structure templates are usually located in the components config/templates folder.
DM2 Schema
This is a DM2 schema which is used for generating a template configuration form. Form values can be used in the structure template by assigning __SCHEMA_name (ie. __SCHEMA_mailto) as a value.
// DM2 schema
'schemadb' => array
(
'settings' => array
(
'description' => 'settings',
'fields' => array
(
'mailto' => Array
(
'title' => 'Mailto',
'storage' => 'null',
'type' => 'text',
'widget' => 'text',
),
),
),
),
Groups
Group guid can also be used in the structure template by assigning __GRUOPGUID_name as a value.
// Groups that should be created / used for this site template
'groups' => array
(
'administrators' => array
(
'name' => '__HOSTTITLE__ administrators',
'subgroups' => array
(
'authors' => array
(
'name' => 'authors',
),
),
),
),
Topics
Topic structure is created starting from root node definition.
// Root node definition
'root' => array
(
'name' => '__HOSTNAME__',
'title' => '__HOSTTITLE__',
'component' => 'net.nehmer.static',
'create_index' => true,
'acl' => array
(
'authors' => array
(
'midgard:owner' => MIDCOM_PRIVILEGE_ALLOW,
),
),
'parameters' => array
(
'net.nehmer.blog' => array
(
),
),
'metadata' => array
(
'description' => 'test',
'score' => 3,
),
// Child node definitions
'nodes' => array
(
'fi' => array
(
'name' => 'fi',
'title' => 'Fi',
'component' => 'net.nehmer.static',
'create_index' => true,
'acl' => array
(
),
'parameters' => array
(
),
),
),
),
Symlinking
Symlinks can also be configured in the structure template. This is done by using symlink_source_id and symlink_target_id configuration options.
// Child node definitions
'nodes' => array
(
'fi' => array
(
'name' => 'fi',
'title' => 'Fi',
'component' => 'net.nehmer.static',
'create_index' => true,
'acl' => array
(
),
'parameters' => array
(
),
'nodes' => array
(
'ajankohtaista' => array
(
'name' => 'ajankohtaista',
'title' => 'Ajankohtaista',
'component' => 'net.nehmer.blog',
'symlink_source_id' => 'news_fi',
'acl' => array
(
'authors' => array
(
'midgard:delete' => MIDCOM_PRIVILEGE_ALLOW,
),
),
'parameters' => array
(
'net.nehmer.comments' => array
(
'allow_anonymous' => '__SCHEMA_anonymous',
),
),
),
'uutisia' => array
(
'name' => 'uutisia',
'title' => 'Uutisia',
'component' => 'net.nehmer.plog',
'symlink_target_id' => 'news_fi',
'acl' => array
(
),
'parameters' => array
(
),
),
),
),
),
Other str replaces
__HOSTTITLE__
__HOSTNAME__
