[zi-cvs] packages/com.zzoss.zic.plugin.repository InstallerDb.php,NONE,1.1 install.php,NONE,1.1 package.xml,NONE,1.1 remove.php,NONE,1.1 repository2xsd.xsl,NONE,1.1
Christian Zonsius <[email protected]> Tue, 18 May 2004 00:52:51 +0000
| Newsgroups | gmane.comp.php.zzoss.installer.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/zzossinstaller/packages/com.zzoss.zic.plugin.repository
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15865
Added Files:
InstallerDb.php install.php package.xml remove.php
repository2xsd.xsl
Log Message:
initial commit
--- NEW FILE: remove.php ---
<?php
// TODO
?>
--- NEW FILE: repository2xsd.xsl ---
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2001-2003 ZZOSS GbR, http://www.zzoss.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
$Id: repository2xsd.xsl,v 1.1 2004/05/18 00:52:48 czonsius Exp $
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:repository="http://www.zzoss.com/software/namespaces/repository"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="/*">
<schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:copy-of select="xsd:attribute" />
<xsl:apply-templates select="xsd:complexType"/>
</schema>
</xsl:template>
<!-- add the _ddo reference to each complex type -->
<xsl:template match="xsd:sequence">
<xsd:complexType name="{../@name}">
<xsd:sequence>
<xsl:choose>
<xsl:when test="../@name = 'item'"><xsl:call-template name="item-fields"/></xsl:when>
<xsl:otherwise><xsd:element ref="_ddo"/></xsl:otherwise>
</xsl:choose>
<xsl:copy-of select="xsd:element"/>
<xsl:apply-templates select="xsd:complexType"/>
</xsd:sequence>
</xsd:complexType>
</xsl:template>
<xsl:template name="item-fields">
<xsd:element name="_ddo" minOccurs="1" maxOccurs="1" default="" nillable="false">
<xsd:restriction base='xsd:string'>
<xsd:maxLength value='255'/>
<xsd:minLength value='10'/>
</xsd:restriction>
</xsd:element>
<xsd:element name="_id" minOccurs="1" maxOccurs="1" default="0" nillable="false">
<xsd:restriction base='xsd:positiveInteger'>
<xsd:totalDigits value='10'/>
</xsd:restriction>
</xsd:element>
<xsd:element name="_network" minOccurs="1" maxOccurs="1" default="0" nillable="false">
<xsd:restriction base='xsd:positiveInteger'>
<xsd:totalDigits value='10'/>
</xsd:restriction>
</xsd:element>
<xsd:element name="_community" minOccurs="1" maxOccurs="1" default="0" nillable="false">
<xsd:restriction base='xsd:positiveInteger'>
<xsd:totalDigits value='10'/>
</xsd:restriction>
</xsd:element>
<xsd:element name="_repository" minOccurs="1" maxOccurs="1" default="0" nillable="false">
<xsd:restriction base='xsd:positiveInteger'>
<xsd:totalDigits value='10'/>
</xsd:restriction>
</xsd:element>
<xsd:element name="_created" minOccurs="1" maxOccurs="1" default="0000-00-00 00:00:00" nillable="false">
<xsd:restriction base="xsd:dateTime" />
</xsd:element>
<xsd:element name="_modified" minOccurs="1" maxOccurs="1" default="0000-00-00 00:00:00" nillable="false">
<xsd:restriction base="xsd:dateTime" />
</xsd:element>
<xsd:element name="_deleted" minOccurs="1" maxOccurs="1" default="0000-00-00 00:00:00" nillable="true">
<xsd:restriction base="xsd:dateTime" />
</xsd:element>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: InstallerDb.php ---
<?php
/*
Copyright (C) 2001-2003 ZZOSS GbR, http://www.zzoss.com
----------------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
----------------------------------------------------------------------
$Id: InstallerDb.php,v 1.1 2004/05/18 00:52:48 czonsius Exp $
*/
require_once 'DB.php';
class ZZOSS_InstallerDb
{
function db( &$db )
{
$this->db = $db;
$this->db_name = $this->db->dsn['database'];
// define tables for DOM
if(isset($this->db->tables)&&count($this->db->tables)){
$this->tbl_name = $this->db->tables;
}
//print_r($this->tbl_name);
}
function setReplacements($replacements)
{
$this->replacements = $replacements;
}
function sqlDumpFromString( $sql_query )
{
$sql_query = trim($sql_query);
// check if we should replace characters of the query
if(isset($this->replacements)&&is_array($this->replacements) && count($this->replacements)){
// extract the key as the needle that we replace in the haystack
$search = array();
$replace = array();
foreach($this->replacements as $key => $value){
array_push($search, "'{".$key."}'si");
array_push($replace, $value);
}
$sql_query = preg_replace ($search, $replace, $sql_query);
}
$pieces = array();
$this->_split_sql_file($pieces, $sql_query);
$pieces_count = count($pieces);
for ($i = 0; $i < $pieces_count; $i++) {
//echo $a_sql_query.'<br>';
$this->query($pieces[$i]);
} // end for
unset($pieces);
return true;
}
function sqlDump( $sql_file )
{
// Gets the query from a file
if (file_exists($sql_file)) {
$sql_query = fread(fopen($sql_file, 'r'), filesize($sql_file));
if (get_magic_quotes_runtime() == 1) {
$sql_query = stripslashes($sql_query);
}
} else {
return false;
}
return $this->sqlDumpFromString($sql_query);
}
function &query( $query )
{
//$query = $this->_replaceTableNames( $query );
//echo "---\n";
//echo $query."\n";
return $this->db->query( $query );
}
/*
function _replaceTableNames( $query )
{
// replace hard coded table names with table aliases
if(count($this->tbl_name)){
foreach($this->tbl_name as $tbl_name => $tbl_alias){
// TODO: use regular expressions
// replace table names
$query = str_replace(' '.$tbl_name.' ',' '.$this->db_name.'.'.$tbl_alias.' ', $query);
// replace table names with backticks
$query = str_replace(' `'.$tbl_name.'` ',' `'.$this->db_name.'`.`'.$tbl_alias.'` ', $query);
// replace table names at end of query string
$query = str_replace(' '.$tbl_name,' '.$this->db_name.'.'.$tbl_alias, $query);
// replace table names in column definition
$query = str_replace(' '.$tbl_name.'.', ' '.$tbl_alias.'.', $query);
// replace sequence tables
$query = str_replace(' '.$tbl_name.'_seq ',' '.$this->db_name.'.'.$tbl_alias.'_seq ', $query);
// replace sequence tables at end of query string
$query = str_replace(' '.$tbl_name.'_seq',' '.$this->db_name.'.'.$tbl_alias.'_seq', $query);
}
} else {
return false;
}
return $query;
}
*/
/**
* Taken from phpMyAdmin ./read_dump.php
*
* Removes comment lines and splits up large sql files into individual queries
*
* Last revision: September 23, 2001 - gandon
*
* @param array the splitted sql commands
* @param string the sql commands
* @param integer the MySQL release number (because certains php3 versions
* can't get the value of a constant from within a function)
*
* @return boolean always true
*
* @access public
*/
function _split_sql_file(&$ret, $sql, $release = 32300)
{
$sql = trim($sql);
$sql_len = strlen($sql);
$char = '';
$string_start = '';
$in_string = FALSE;
for ($i = 0; $i < $sql_len; ++$i) {
$char = $sql[$i];
// We are in a string, check for not escaped end of strings except for
// backquotes that can't be escaped
if ($in_string) {
for (;;) {
$i = strpos($sql, $string_start, $i);
// No end of string found -> add the current substring to the
// returned array
if (!$i) {
$ret[] = $sql;
return TRUE;
}
// Backquotes or no backslashes before quotes: it's indeed the
// end of the string -> exit the loop
else if ($string_start == '`' || $sql[$i-1] != '\\') {
$string_start = '';
$in_string = FALSE;
break;
}
// one or more Backslashes before the presumed end of string...
else {
// ... first checks for escaped backslashes
$j = 2;
$escaped_backslash = FALSE;
while ($i-$j > 0 && $sql[$i-$j] == '\\') {
$escaped_backslash = !$escaped_backslash;
$j++;
}
// ... if escaped backslashes: it's really the end of the
// string -> exit the loop
if ($escaped_backslash) {
$string_start = '';
$in_string = FALSE;
break;
}
// ... else loop
else {
$i++;
}
} // end if...elseif...else
} // end for
} // end if (in string)
// We are not in a string, first check for delimiter...
else if ($char == ';') {
// if delimiter found, add the parsed part to the returned array
$ret[] = substr($sql, 0, $i);
$sql = ltrim(substr($sql, min($i + 1, $sql_len)));
$sql_len = strlen($sql);
if ($sql_len) {
$i = -1;
} else {
// The submited statement(s) end(s) here
return TRUE;
}
} // end else if (is delimiter)
// ... then check for start of a string,...
else if (($char == '"') || ($char == '\'') || ($char == '`')) {
$in_string = TRUE;
$string_start = $char;
} // end else if (is start of string)
// ... for start of a comment (and remove this comment if found)...
else if ($char == '#'
|| ($char == ' ' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '--')) {
// starting position of the comment depends on the comment type
$start_of_comment = (($sql[$i] == '#') ? $i : $i-2);
// if no "\n" exits in the remaining string, checks for "\r"
// (Mac eol style)
$end_of_comment = (strpos(' ' . $sql, "\012", $i+2))
? strpos(' ' . $sql, "\012", $i+2)
: strpos(' ' . $sql, "\015", $i+2);
if (!$end_of_comment) {
// no eol found after '#', add the parsed part to the returned
// array and exit
$ret[] = trim(substr($sql, 0, $i-1));
return TRUE;
} else {
$sql = substr($sql, 0, $start_of_comment)
. ltrim(substr($sql, $end_of_comment));
$sql_len = strlen($sql);
$i--;
} // end if...else
} // end else if (is comment)
// ... and finally disactivate the "/*!...*/" syntax if MySQL < 3.22.07
else if ($release < 32270
&& ($char == '!' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '/*')) {
$sql[$i] = ' ';
} // end else if
} // end for
// add any rest to the returned array
if (!empty($sql) && ereg('[^[:space:]]+', $sql)) {
$ret[] = $sql;
}
return TRUE;
} // end of the 'split_sql_file()' function
}
?>
--- NEW FILE: install.php ---
<?php
/*
Copyright (C) 2001-2003 ZZOSS GbR, http://www.zzoss.com
----------------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
----------------------------------------------------------------------
$Id: install.php,v 1.1 2004/05/18 00:52:48 czonsius Exp $
*/
// set include path
$old_include_path = ini_get("include_path");
ini_set( "include_path",
ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['application_data_dir'].'plugins_re/lib').
DIRECTORY_SEPARATOR.
$old_include_path
);
if($GLOBALS['ZI']['plugin_mode'] == 'post'){
$GLOBALS['ZI']['plugin_log'] .= "Processing input.\n";
$xsd_file = ZZOSS_InstallerUtils::fixPath(
$GLOBALS['ZI']['build_dir'].'new/structure.xsd'
);
$xsd2mysql_file = ZZOSS_InstallerUtils::fixPath(
$GLOBALS['ZI']['application_data_dir'].'plugins_re/lib/xsd2db/xsd2mysql.xsl'
);
$repository2xsd_file = ZZOSS_InstallerUtils::fixPath(
$GLOBALS['ZI']['application_data_dir'].'plugins_re/com.zzoss.zic.plugin.repository/repository2xsd.xsl'
);
// parse config.xml file of com.zzoss.repository.build package
$config_file = $GLOBALS['ZI']['application_data_dir'].'data'.DIRECTORY_SEPARATOR.'package'.DIRECTORY_SEPARATOR.'com.zzoss.repository.build'.DIRECTORY_SEPARATOR.'config.xml';
if(file_exists($config_file)) {
require_once 'ZZOSS_Config/Config.php';
$config = new ZZOSS_Config;
$config->setFile($config_file);
$GLOBALS['ZI']['plugin_log'] .=
"Reading config.xml from '$config_file'"."\n";
$config_repository = $config->query('/zzoss_config');
}
// parse config.xml file of current package
$config_file_package = $GLOBALS['ZI']['application_data_dir'].'data'.DIRECTORY_SEPARATOR.'package'.DIRECTORY_SEPARATOR.$GLOBALS['ZI']['package_name'].DIRECTORY_SEPARATOR.'config.xml';
if(file_exists($config_file_package)) {
require_once 'ZZOSS_Config/Config.php';
$config = new ZZOSS_Config;
$config->setFile($config_file_package);
$GLOBALS['ZI']['plugin_log'] .=
"Reading config.xml from '$config_file_package'"."\n";
$config_package = $config->query('/zzoss_config');
}
// set xsl params
$xslparams = array("tbl.prefix" => $config_package['component']['repository']['@']['name'].'_');
// read XML file
$fd = fopen( $xsd_file, "r" );
$xml = fread( $fd, filesize( $xsd_file ) );
fclose( $fd );
// read XSD2MYSQL XSLT file
$fd = fopen( $xsd2mysql_file, "r" );
$xsl_xsd2mysql = fread( $fd, filesize( $xsd2mysql_file ) );
fclose( $fd );
// read REPOSITORY2XSD XSLT file
$fd = fopen( $repository2xsd_file, "r" );
$xsl_repository2xsd = fread( $fd, filesize( $repository2xsd_file ) );
fclose( $fd );
// convert repository to xsd
$xslproc = xslt_create();
xslt_set_encoding($xslproc, "iso-8859-1");
$xslargs = array("_xml" => $xml, "_xsl" => $xsl_repository2xsd);
$xsd = xslt_process($xslproc, "arg:/_xml", "arg:/_xsl", NULL, $xslargs);
// convert xsd to mysql
$xslproc = xslt_create();
xslt_set_encoding($xslproc, "iso-8859-1");
$xslargs = array("_xml" => $xsd, "_xsl" => $xsl_xsd2mysql);
$sql = xslt_process($xslproc, "arg:/_xml", "arg:/_xsl", NULL, $xslargs, $xslparams);
// parse config params
if(is_array($config_repository['component']['params']['param'])) {
foreach($config_repository['component']['params']['param'] as $param) {
if($param['@']['name']!='') {
$config_params[$param['@']['name']] = $param['#'];
}
}
}
// get installer connector
if(is_array($config_package['component']['connector'])) {
foreach($config_package['component']['connector'] as $connector) {
if($connector['@']['name']=='installer') {
$connector_install = $connector;
}
}
}
// create db object
require_once 'InstallerDb.php';
$db = DB::connect($connector_install['dsn'], true);
if (DB::isError($db)) {
die ($db->getMessage());
}
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$installer = new ZZOSS_InstallerDb;
$installer->db( $db );
// execute table sql
$installer->sqlDumpFromString($sql);
// create new repository entry
$repositories_table = $config_repository['component']['repository']['@']['name'].'_item';
$_id = $db->nextID( $repositories_table );
$_ddo = 'ddo:'.
$config_params['network'].
'.'.
$config_params['community'].
'.'.
'1'. // repository (1 = repository table itself)
// better way is to retrieve this with db
'/'.
$_id;
$sql_2 = 'INSERT INTO '.$repositories_table.' (_id, _ddo, _network, _community, _repository, _created, name, label, description, created) VALUES ('
.'"'.$_id.'", '
.'"'.$_ddo.'", '
.'"'.$config_params['network'].'", '
.'"'.$config_params['community'].'", '
.'"1", ' // see above
.'"'.gmdate('Y-m-d H:i:s').'", '
.'"'.$config_package['component']['repository']['@']['name'].'", '
.'"'.$config_package['component']['repository']['label'].'", '
.'"'.$config_package['component']['repository']['description'].'", '
.'"'.gmdate('Y-m-d H:i:s').'"'
.')';
$installer->sqlDumpFromString($sql_2);
}
// restore include path
ini_set( "include_path", $old_include_path );
/*
// we have to set this global, otherwise ZZOSS_Framework::conf()
// would not work
$_SERVER['ZZOSS_PATH_TRANSLATED'] = $GLOBALS['ZI']['root'];
require_once 'ZZOSS_Framework/Framework.php';
require_once 'ZZOSS_Framework/Parser.php';
require_once "lib/ZZOSS_Installer/Utils.php";
require_once "lib/ZZOSS_Installer/Db.php";
if($GLOBALS['ZI']['plugin_mode'] == 'post'){
$GLOBALS['ZI']['plugin_log'] .= "Processing input.\n";
// include class file
require_once 'install_inc.php';
$debug = true;
$plugin = new ZZOSS_RepositoriesPluginInstall($debug);
$plugin->setName($GLOBALS['ZI']['plugin_params']['schema']);
$plugin->setRepository(ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_build_dir'].'new/structure.xsd'));
$plugin->setXslt('repository2xsd', $GLOBALS['ZI']['plugin_root'].'repository2xsd.xsl');
$plugin->setXslt('xsd2db', $GLOBALS['ZI']['root'].'utils/xsd2db/xsd2mysql.xsl');
$plugin->setXslt('xsd2template', $GLOBALS['ZI']['root'].'utils/xsd2template/xsd2itx_template.xsl');
$plugin->setXslt('xsd2xforms', $GLOBALS['ZI']['root'].'utils/xsd2xforms/xsd2xforms.xsl');
$plugin->setXslt('xsd2xml2mysql', $GLOBALS['ZI']['root'].'utils/xsd2db/xsd2xml2mysql.xsl');
$plugin->exec();
if($GLOBALS['ZI']['demo']){
$GLOBALS['ZI']['plugin_log'] .= 'com.zzoss.installer.plugin.repository: Trying to find '.ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_build_dir'].'new/demo.xml')."\n";
if(file_exists(ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_build_dir'].'new/demo.xml'))){
$plugin->demo(ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_build_dir'].'new/demo.xml'));
}
}
}*/
?>
--- NEW FILE: package.xml ---
<?xml version="1.0" encoding="ISO-8859-1" ?>
<package version="1.0"
xmlns="http://www.zzoss.com/NS/installer/package/">
<name>com.zzoss.zic.plugin.repository</name>
<summary>ZZ/OSS Installer Repository Plugin</summary>
<description>Plugin to install build files.</description>
<maintainers>
<maintainer>
<user>czonsius</user>
<name>Christian Zonsius</name>
<email>[email protected]</email>
<role>developer</role>
</maintainer>
<maintainer>
<user>ordnas</user>
<name>Sandro Zic</name>
<email>[email protected]</email>
<role>developer</role>
</maintainer>
</maintainers>
<release>
<version>0.1.0</version>
<date>2004-03-19</date>
<license url="http://www.gnu.org/licenses/gpl.txt" version="2">GPL</license>
<state>beta</state>
<notes>Initial release.</notes>
<copyright>
<holder year="2004" url="http://www.zzoss.com">ZZ/OSS Information Networking GbR</holder>
</copyright>
<filelist>
<file baseinstalldir="com.zzoss.zic.plugin.repository" name="install.php"/>
<file baseinstalldir="com.zzoss.zic.plugin.repository" name="remove.php"/>
<file baseinstalldir="com.zzoss.zic.plugin.repository" name="repository2xsd.xsl"/>
<file baseinstalldir="lib" name="InstallerDb.php"/>
</filelist>
<plugin>
<filelist>
<file role="install" name="install.php"/>
<file role="remove" name="remove.php"/>
</filelist>
</plugin>
<deps>
<dep type="pkg" rel="ge" version="1.4.0">DB</dep>
</deps>
</release>
</package>
-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click