PHP Class adoSchema, pkp-lib

This class is used to load and parse the XML file, to create an array of SQL statements that can be used to build a database, and to build the database using the SQL array.
Show file Open project: pkp/pkp-lib Class Usage Examples

Public Properties

Property Type Description
$continueOnError Continue SQL execution if errors occur
$currentElement Current XML element
$db ADOdb connection object
$debug System debug
$dict ADOdb Data Dictionary
$executeInline Execute SQL inline as it is generated
$mgq Original Magic Quotes Runtime value
$objectPrefix Optional object prefix
$schemaVersion Current schema version
$sqlArray Array containing SQL queries to generate all objects
$success Success of last Schema execution
$upgrade If set (to 'ALTER' or 'REPLACE'), upgrade an existing database
$versionRegex Regular expression to find schema version

Public Methods

Method Description
ContinueOnError ( boolean $mode = NULL ) : boolean Enables/disables SQL continue on error.
ConvertSchemaFile ( string $filename, string $newVersion = NULL, string $newFile = NULL ) : string Converts an XML schema file to the specified DTD version.
ConvertSchemaString ( string $schema, string $newVersion = NULL, string $newFile = NULL ) : string Converts an XML schema string to the specified DTD version.
Destroy ( ) Destroys an adoSchema object.
ExecuteInline ( boolean $mode = NULL ) : boolean Enables/disables inline SQL execution.
ExecuteSchema ( array $sqlArray = NULL, boolean $continueOnErr = NULL ) Applies the current XML schema to the database (post execution).
ExtractSchema ( boolean $data = FALSE ) : string Extracts an XML schema from an existing database.
ParseSchema ( $filename, boolean $returnSchema = FALSE ) : array Loads an XML schema from a file and converts it to SQL.
ParseSchemaFile ( $filename, boolean $returnSchema = FALSE ) : array Loads an XML schema from a file and converts it to SQL.
ParseSchemaString ( string $xmlstring, boolean $returnSchema = FALSE ) : array Converts an XML schema string to SQL.
PrintSQL ( string $format = 'NONE' ) : array Returns the current SQL array.
RemoveSchema ( $filename, boolean $returnSchema = FALSE ) : array Loads an XML schema from a file and converts it to uninstallation SQL.
RemoveSchemaString ( string $schema, boolean $returnSchema = FALSE ) : array Converts an XML schema string to uninstallation SQL.
SaveSQL ( string $filename = './schema.sql' ) : boolean Saves the current SQL array to the local filesystem as a list of SQL queries.
SchemaFileVersion ( string $filename ) : string Returns the AXMLS Schema Version of the requested XML schema file.
SchemaStringVersion ( string $xmlstring ) : string Returns the AXMLS Schema Version of the provided XML schema string.
SetPrefix ( string $prefix = '', boolean $underscore = TRUE ) : boolean Sets a prefix for database objects
SetUpgradeMethod ( string $method = '' ) Sets the method to be used for upgrading an existing database
TransformSchema ( $schema, $xsl, $schematype = 'string' )
_file_get_contents ( $path ) compat for pre-4.3 - jlim
_tag_cdata ( &$parser, $cdata ) XML Callback to process CDATA elements
_tag_close ( &$parser, $tag ) XML Callback to process end elements
_tag_open ( &$parser, $tag, $attributes ) XML Callback to process start elements
addSQL ( mixed $sql = NULL ) : boolean Adds SQL into the SQL array.
adoSchema ( object $db ) Creates an adoSchema object
clearSQL ( ) Clears the array of generated SQL.
create_parser ( ) : object Create an xml parser
getSQL ( string $format = NULL, $sqlArray = NULL ) : mixed Gets the SQL array in the specified format.
prefix ( string $name = '' ) : string Returns an object name with the current prefix prepended.
supportedPlatform ( string $platform = NULL ) Checks if element references a specific platform
xslt_error_handler ( object $parser, integer $errno, integer $level, array $fields ) Processes XSLT transformation errors

Method Details

ContinueOnError() public method

Call this method to enable or disable continuation of SQL execution if an error occurs. If the mode is set to TRUE (continue), AXMLS will continue to apply SQL to the database, even if an error occurs. If the mode is set to FALSE (halt), AXMLS will halt execution of generated sql if an error occurs, though parsing of the schema will continue.
public ContinueOnError ( boolean $mode = NULL ) : boolean
$mode boolean execute
return boolean current continueOnError mode

ConvertSchemaFile() public method

Call this method to convert the specified XML schema file to a different AXMLS DTD version. For instance, to convert a schema created for an pre-1.0 version for AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version parameter is specified, the schema will be converted to the current DTD version. If the newFile parameter is provided, the converted schema will be written to the specified file.
See also: ConvertSchemaString()
public ConvertSchemaFile ( string $filename, string $newVersion = NULL, string $newFile = NULL ) : string
$filename string Name of XML schema file that will be converted.
$newVersion string DTD version to convert to.
$newFile string File name of (converted) output file.
return string Converted XML schema or FALSE if an error occurs.

ConvertSchemaString() public method

Call this method to convert a string containing an XML schema to a different AXMLS DTD version. For instance, to convert a schema created for an pre-1.0 version for AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version parameter is specified, the schema will be converted to the current DTD version. If the newFile parameter is provided, the converted schema will be written to the specified file.
See also: ConvertSchemaFile()
public ConvertSchemaString ( string $schema, string $newVersion = NULL, string $newFile = NULL ) : string
$schema string String containing XML schema that will be converted.
$newVersion string DTD version to convert to.
$newFile string File name of (converted) output file.
return string Converted XML schema or FALSE if an error occurs.

Destroy() public method

Call this method to clean up after an adoSchema object that is no longer in use.
Deprecation: adoSchema now cleans up automatically.
public Destroy ( )

ExecuteInline() public method

Call this method to enable or disable inline execution of the schema. If the mode is set to TRUE (inline execution), AXMLS applies the SQL to the database immediately as each schema entity is parsed. If the mode is set to FALSE (post execution), AXMLS parses the entire schema and you will need to call adoSchema::ExecuteSchema() to apply the schema to the database.
public ExecuteInline ( boolean $mode = NULL ) : boolean
$mode boolean execute
return boolean current execution mode

ExecuteSchema() public method

Call this method to apply the current schema (generally created by calling ParseSchema() or ParseSchemaString() ) to the database (creating the tables, indexes, and executing other SQL specified in the schema) after parsing.
public ExecuteSchema ( array $sqlArray = NULL, boolean $continueOnErr = NULL )
$sqlArray array Array of SQL statements that will be applied rather than the current schema.
$continueOnErr boolean Continue to apply the schema even if an error occurs.

ExtractSchema() public method

Call this method to create an XML schema string from an existing database. If the data parameter is set to TRUE, AXMLS will include the data from the database in the schema.
public ExtractSchema ( boolean $data = FALSE ) : string
$data boolean Include data in schema dump
return string Generated XML schema

ParseSchema() public method

Call this method to load the specified schema (see the DTD for the proper format) from the filesystem and generate the SQL necessary to create the database described.
See also: ParseSchemaString()
public ParseSchema ( $filename, boolean $returnSchema = FALSE ) : array
$returnSchema boolean Return schema rather than parsing.
return array Array of SQL queries, ready to execute

ParseSchemaFile() public method

Call this method to load the specified schema from a file (see the DTD for the proper format) and generate the SQL necessary to create the database described by the schema.
Deprecation: Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString()
public ParseSchemaFile ( $filename, boolean $returnSchema = FALSE ) : array
$returnSchema boolean Return schema rather than parsing.
return array Array of SQL queries, ready to execute.

ParseSchemaString() public method

Call this method to parse a string containing an XML schema (see the DTD for the proper format) and generate the SQL necessary to create the database described by the schema.
See also: ParseSchema()
public ParseSchemaString ( string $xmlstring, boolean $returnSchema = FALSE ) : array
$xmlstring string XML schema string.
$returnSchema boolean Return schema rather than parsing.
return array Array of SQL queries, ready to execute.

PrintSQL() public method

Call this method to fetch the array of SQL queries resulting from ParseSchema() or ParseSchemaString().
public PrintSQL ( string $format = 'NONE' ) : array
$format string Format: HTML, TEXT, or NONE (PHP array)
return array Array of SQL statements or FALSE if an error occurs

RemoveSchema() public method

Call this method to load the specified schema (see the DTD for the proper format) from the filesystem and generate the SQL necessary to remove the database described.
See also: RemoveSchemaString()
public RemoveSchema ( $filename, boolean $returnSchema = FALSE ) : array
$returnSchema boolean Return schema rather than parsing.
return array Array of SQL queries, ready to execute

RemoveSchemaString() public method

Call this method to parse a string containing an XML schema (see the DTD for the proper format) and generate the SQL necessary to uninstall the database described by the schema.
See also: RemoveSchema()
public RemoveSchemaString ( string $schema, boolean $returnSchema = FALSE ) : array
$schema string XML schema string.
$returnSchema boolean Return schema rather than parsing.
return array Array of SQL queries, ready to execute.

SaveSQL() public method

Call this method to save the array of SQL queries (generally resulting from a parsed XML schema) to the filesystem.
public SaveSQL ( string $filename = './schema.sql' ) : boolean
$filename string Path and name where the file should be saved.
return boolean TRUE if save is successful, else FALSE.

SchemaFileVersion() public method

Call this method to obtain the AXMLS DTD version of the requested XML schema file.
See also: SchemaStringVersion()
public SchemaFileVersion ( string $filename ) : string
$filename string AXMLS schema file
return string Schema version number or FALSE on error

SchemaStringVersion() public method

Call this method to obtain the AXMLS DTD version of the provided XML schema string.
See also: SchemaFileVersion()
public SchemaStringVersion ( string $xmlstring ) : string
$xmlstring string XML schema string
return string Schema version number or FALSE on error

SetPrefix() public method

Call this method to set a standard prefix that will be prepended to all database tables and indices when the schema is parsed. Calling setPrefix with no arguments clears the prefix.
public SetPrefix ( string $prefix = '', boolean $underscore = TRUE ) : boolean
$prefix string Prefix that will be prepended.
$underscore boolean If TRUE, automatically append an underscore character to the prefix.
return boolean TRUE if successful, else FALSE

SetUpgradeMethod() public method

Use this method to specify how existing database objects should be upgraded. The method option can be set to ALTER, REPLACE, BEST, or NONE. ALTER attempts to alter each database object directly, REPLACE attempts to rebuild each object from scratch, BEST attempts to determine the best upgrade method for each object, and NONE disables upgrading. This method is not yet used by AXMLS, but exists for backward compatibility. The ALTER method is automatically assumed when the adoSchema object is instantiated; other upgrade methods are not currently supported.
public SetUpgradeMethod ( string $method = '' )
$method string Upgrade method (ALTER|REPLACE|BEST|NONE)

TransformSchema() public method

public TransformSchema ( $schema, $xsl, $schematype = 'string' )

_file_get_contents() public method

compat for pre-4.3 - jlim
public _file_get_contents ( $path )

_tag_cdata() public method

XML Callback to process CDATA elements
public _tag_cdata ( &$parser, $cdata )

_tag_close() public method

XML Callback to process end elements
public _tag_close ( &$parser, $tag )

_tag_open() public method

XML Callback to process start elements
public _tag_open ( &$parser, $tag, $attributes )

addSQL() public method

Adds SQL into the SQL array.
public addSQL ( mixed $sql = NULL ) : boolean
$sql mixed SQL to Add
return boolean TRUE if successful, else FALSE.

adoSchema() public method

Creating an adoSchema object is the first step in processing an XML schema. The only parameter is an ADOdb database connection object, which must already have been created.
public adoSchema ( object $db )
$db object ADOdb database connection object.

clearSQL() public method

Clears the array of generated SQL.
public clearSQL ( )

create_parser() public method

Create an xml parser
public create_parser ( ) : object
return object PHP XML parser object

getSQL() public method

Gets the SQL array in the specified format.
public getSQL ( string $format = NULL, $sqlArray = NULL ) : mixed
$format string Format
return mixed SQL

prefix() public method

Returns an object name with the current prefix prepended.
public prefix ( string $name = '' ) : string
$name string Name
return string Prefixed name

supportedPlatform() public method

Checks if element references a specific platform
public supportedPlatform ( string $platform = NULL )
$platform string Requested platform

xslt_error_handler() public method

Processes XSLT transformation errors
public xslt_error_handler ( object $parser, integer $errno, integer $level, array $fields )
$parser object XML parser object
$errno integer Error number
$level integer Error level
$fields array Error information fields

Property Details

$continueOnError public property

Continue SQL execution if errors occur
public $continueOnError

$currentElement public property

Current XML element
public $currentElement

$db public property

ADOdb connection object
public $db

$debug public property

System debug
public $debug

$dict public property

ADOdb Data Dictionary
public $dict

$executeInline public property

Execute SQL inline as it is generated
public $executeInline

$mgq public property

Original Magic Quotes Runtime value
public $mgq

$objectPrefix public property

Optional object prefix
public $objectPrefix

$schemaVersion public property

Current schema version
public $schemaVersion

$sqlArray public property

Array containing SQL queries to generate all objects
public $sqlArray

$success public property

Success of last Schema execution
public $success

$upgrade public property

If set (to 'ALTER' or 'REPLACE'), upgrade an existing database
public $upgrade

$versionRegex public property

Regular expression to find schema version
public $versionRegex