Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New version 0.2.0 :-) #14

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
12 changes: 0 additions & 12 deletions FAQ

This file was deleted.

147 changes: 16 additions & 131 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eZ XML Installer extension 0.0.1 README
eZ XML Installer extension 0.2.0 README


What is the eZ XML Installer extension?
Expand All @@ -17,18 +17,18 @@ What is the eZ XML Installer extension?

eZ XML Installer version
========================

The current version of eZ XML Installer is 0.0.1.
You can find details about changes for this version in
doc/changelogs/
The current version of eZ XML Installer is 0.2.0.
You can find details about changes for this version in
doc/changelogs/


License
=======

This software is licensed under the GNU General Public License. The complete
license agreement is included in the LICENSE file. For more information
or questions please contact info@ez.no
This software is licensed under the GNU General Public License. The complete
license agreement is included in the LICENSE file. For more information
or questions please contact info@ez.no

Requirements
============
Expand All @@ -37,7 +37,7 @@ The following requirements exists for using eZ XML Installer extension:

o eZ Publish version:

Make sure you use eZ Publish version 3.9 or higher.
Make sure you use eZ Publish version 4.5 or higher.

o PHP version:

Expand All @@ -47,133 +47,18 @@ o PHP version:
Installation
============

Please read the INSTALL file for installation instructions.


Creating a custom proccess XML file
===================================
A proccess XML files will be defined with a enclosing <eZXMLImporter> tag.
This tag contains a set of proccess definitions.
Here is an example:
<eZXMLImporter>
<ProccessInformation comment="Content in media sections" />
<MyCustomAction>
<DoThis value1="foo" value2="bar" />
<DoThat myvalue="lorem" myothervalue="ipsum" />
</MyCustomAction>
</eZXMLImporter>

The XML structure of each action is defined by the handler.
The proccess definition will be executed step by step downwards from top.

The eZXMLImporter tag may contain some attributes which will be called "settings".
This can be global settings. E.g. where are some binary files located.

Internal / External references
------------------------------
The XML can contain internal or external referneces.
Currently are only "node_id" and "object_id" as external references are supported.
References can be only used by actions where the handler supports references.
* Internal reference definition
References will be defined inside the action definition.
Example:
<SetReference attribute="object_id" value="CONTENT_MANAGER_GROUP" />
The "attribute" attribute will define which variable of the current action will be defined as reference.
The "value" attribute will name the variable the reference can be used with.
* External reference definition
External references can be used without defintion.
It is important to only use values which will exist in the installation.
Otherwise this can cause errors and data inconsistencies.
* Usage of internal references
Internal references can be used with the "internal:" prefix.
References are not supported everywhere. Please consult the handler documentation where references can be used.
Example:
<RoleAssignment roleID="8" assignTo="internal:CONTENT_MANAGER_GROUP" />
In this example role with id 8 will be assigned to the newly created group with reference "CONTENT_MANAGER_GROUP".
* Usage of external references
Internal references can be used with the "node_id:" or "object_id:" prefix.
References are not supported everywhere. Please consult the handler documentation where references can be used.

Default XML Installer handler
-----------------------------
Here is a short introduction in the hanlder shipped with this extension
* ProccessInformation
This simple action will only display the given comment and increase the internal step counter.
* AssignRoles
This action can be used to assign existing roles to user or user groups.
* CreateContent
This action is used to create content objects based on existing content classes.
Please note that currently not all datatypes are supported.
* SetSettings
This action can create new or modify existing setting files.
Please note that the standard eZ Publish mechanism is used.
This may cause a loss of comments or unsupported ini usage.


Creating a custom proccess template file
========================================
The template based proccess definition is an extended version of the file based definition.
The XML structure must be defined as described.
The template must be located under templates/xmlinstaller in a valid design.
But it is possible to define a set of variables which will be requested and can be used in the xml.
Futhermore it is possible to use standard template functionallity.

Defing the XML structure
------------------------
The XML must be defined in a variable block with the name "xml_data".
Example:
{set-block variable='xml_data'}
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<eZXMLImporter>
[...]
</eZXMLImporter>
{/set-block}

Defining and using template variables
-------------------------------------
To request custom input before processing the "tpl_info" variable can be defined in the template.
E.g.
{set $tpl_info=hash(
'var1', hash( 'info', 'Number of objects',
'type', 'int' ),
'var2', hash( 'info', 'URL to siteaccess',
'type', 'string',
'default', 'http://mmc.ez' ))}
This will request two variables. "var1" and "var2"
The hash of each variable defines the additional information.
* info: The info text for the request.
* type: The type of the variable (int or string)
* default: The default value (used when input is empty).

The variabled will be rquested before proccessing and can thus be used in the template as named.
E.g. {$var1} and {$var2}.


Proccessing the XML
===================
The xmlinstaller.php script will proccess the XML.

The script is located in extension/ezxmlinstaller/bin/php/.

It can be used in two ways:
* Proccessing a template:
php extension/ezxmlinstaller/bin/php/xmlinstaller.php --template=demo/mynewsiteaccess
In this case the name of the template (without .tpl, but with additional directories)
must be given as "template" parameter.
* Proccessing a xml file:
php extension/ezxmlinstaller/bin/php/xmlinstaller.php --file=path/to/my/xml/demo.xml
In this case the relative or absolute path to a valid xml file must be given as "file" parameter.


Creating a custom handler
=========================
possible, but not documented yet.
Please read the INSTALL file for installation instructions.


Usage
=====
Please read the dos/HOWTO file for usage instructions.


Where to get more help
======================

eZ Publish forums: http://ez.no/community/forum
eZ Publish forums: http://ez.no/community/forum


Troubleshooting
Expand Down
23 changes: 15 additions & 8 deletions bin/php/xmlinstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
// MA 02110-1301, USA.
//
//

require_once( 'autoload.php' );
require 'autoload.php';

function changeSiteAccessSetting( $siteaccess )
{
Expand Down Expand Up @@ -74,10 +73,11 @@ function isExtensionSiteaccess( $siteaccessName )

$script->startup();

$options = $script->getOptions( "[file:][template:]",
$options = $script->getOptions( "[file:][template:][user:]",
"",
array( 'file' => 'file with xml definition',
'template' => 'name of template to use' ),
array( 'file' => 'File with the xml definition to proceed',
'template' => 'Location of the template to use',
'user' => 'name of the user to use' ),
false,
array( 'user' => true ));

Expand All @@ -97,9 +97,16 @@ function isExtensionSiteaccess( $siteaccessName )
$script->shutdown( 0 );
}

$cli->output( "Checking requirements..." );
$cli->output( $cli->stylize( "yellow", "Checking requirements...") );
if ( isset( $options['user'] ) && $options['user'] )
{
$user = eZUser::fetch( $options['user'] );
}
else
{
$user = eZUser::fetchByName( 'admin' );
}

$user = eZUser::fetchByName( 'admin' );
if ( $user )
{
eZUser::setCurrentlyLoggedInUser( $user, $user->attribute( 'contentobject_id' ) );
Expand All @@ -124,7 +131,7 @@ function isExtensionSiteaccess( $siteaccessName )
$cli->error( "Need at least one argument." );
$script->shutdown( 1 );
}
$cli->output( "Trying to install data from XML ..." );
$cli->output( $cli->stylize( "yellow", "Trying to install data from XML ...") );

if ( $xml == '' )
{
Expand Down
61 changes: 51 additions & 10 deletions classes/ezpreparexml.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
//
//

require_once( 'autoload.php' );

if ( !function_exists( 'readline' ) )
{
function readline( $prompt = '' )
Expand All @@ -37,23 +35,23 @@ function readline( $prompt = '' )
class eZPrepareXML
{

function eZPrepareXML( )
private function __construct()
{
}

function prepareXMLFromTemplate( $templateName, $cli = false )
{
$template = 'design:' . $templateName . '.tpl';
$template = 'design:' . $templateName;
$tpl = eZTemplate::factory();

$tpl->setVariable( 'tpl_info', false );
$tpl->setVariable( 'xmlinstaller_feature_list', false );

$content = $tpl->fetch( $template );
$tplInfo = false;

if ( $tpl->variable( "tpl_info" ) !== false )
if ( $tpl->variable( "xmlinstaller_feature_list" ) !== false )
{
$tplInfo = $tpl->variable( "tpl_info" );
$tplInfo = $tpl->variable( "xmlinstaller_feature_list" );
}
if ( is_array( $tplInfo ) )
{
Expand All @@ -72,7 +70,51 @@ function prepareXMLFromTemplate( $templateName, $cli = false )
{
$default = $info['default'];
}
$value = eZPrepareXML::getUserInput( "Please enter \"" . $query . "\" (" . $default . "): ", $default );
$value = "";
$question = "Please enter \"" . $query . "\"";
if ($default)
{
$question .= " (" . $default . ")";
}
switch($info['type'])
{
case "string":
{
$question .= ": ";
$value = eZPrepareXML::getUserInput( $question, $default );
} break;
case "selection":
{
$question .= " [";
$optionList = array();
foreach ($info['vars'] as $k => $v)
{
$optionList[] = $k;
$question .= " $k($v), ";
}
$question .= "]: ";
$value = eZPrepareXML::getUserInput( $question, $default );
} break;
case "boolean":
{
$optionList = array('yes', 'no', 'y', 'n');
$question .= " [" . implode(', ', $optionList) . "]: ";
$value = eZPrepareXML::getUserInput( $question, $default, $optionList );
if ($value == 'y' || $value == 'yes')
{
$value = true;
}
else
{
$value = false;
}
} break;
default:
{
$question .= ": ";
$value = eZPrepareXML::getUserInput( $question, $default );
}
}
$tpl->setVariable( $var, $value );
}
}
Expand Down Expand Up @@ -105,8 +147,7 @@ function getUserInput( $query, $defaultValue = false, $acceptValues = false )
while ( !$validInput )
{
$input = readline( $query );
if ( $acceptValues === false ||
in_array( $input, $acceptValues ) )
if ( $acceptValues === false || in_array( $input, $acceptValues ) || $defaultValue != false )
{
$validInput = true;
}
Expand Down
9 changes: 2 additions & 7 deletions classes/ezxmlinstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@
//
//

include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentclass.php' );
include_once( "lib/ezlocale/classes/ezdatetime.php" );
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );

class eZXMLInstaller
{
function eZXMLInstaller( $domDocument )
function __construct( $domDocument )
{
$this->rootDomNode = $domDocument->documentElement;
$this->cli = eZCLI::instance();
Expand All @@ -42,7 +37,7 @@ function proccessXML( )
$installerHandlerManager->initialize();
if ( $this->rootDomNode &&
$this->rootDomNode->nodeType == XML_ELEMENT_NODE &&
$this->rootDomNode->nodeName == 'eZXMLImporter' )
$this->rootDomNode->nodeName == 'eZXMLInstaller' )
{
if ( $this->rootDomNode->hasAttributes() )
{
Expand Down
6 changes: 3 additions & 3 deletions classes/ezxmlinstallerhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class eZXMLInstallerHandler
{

function eZXMLInstallerHandler()
function __construct()
{
}

Expand All @@ -47,10 +47,10 @@ static public function handlerInfo()
return array( 'XMLName' => '', 'Info' => '' );
}

function writeMessage( $message, $type = 'notice' )
function writeMessage( $message, $type = 'notice', $color = false )
{
$handlerManager = eZXMLInstallerHandlerManager::instance();
$handlerManager->writeMessage( $message, $type = 'notice' );
$handlerManager->writeMessage( $message, $type, $color );
}

function addReference( $refInfo )
Expand Down