CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.
This commit is contained in:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'builder/util/Pluralizer.php';
|
||||
|
||||
/**
|
||||
* The default Enlglish pluralizer class.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1612 $
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
class DefaultEnglishPluralizer implements Pluralizer
|
||||
{
|
||||
|
||||
/**
|
||||
* Generate a plural name based on the passed in root.
|
||||
* @param string $root The root that needs to be pluralized (e.g. Author)
|
||||
* @return string The plural form of $root (e.g. Authors).
|
||||
*/
|
||||
public function getPluralForm($root)
|
||||
{
|
||||
return $root . 's';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* The generic interface to create a plural form of a name.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1612 $
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
interface Pluralizer
|
||||
{
|
||||
|
||||
/**
|
||||
* Generate a plural name based on the passed in root.
|
||||
* @param string $root The root that needs to be pluralized (e.g. Author)
|
||||
* @return string The plural form of $root.
|
||||
*/
|
||||
public function getPluralForm($root);
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
include_once 'phing/system/io/Reader.php';
|
||||
|
||||
/**
|
||||
* Overrides Phing's StringReader to allow inclusin inside a BufferedReader
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Revision: 1785 $
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
class PropelStringReader extends Reader
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_string;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $mark = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $currPos = 0;
|
||||
|
||||
public function __construct($string)
|
||||
{
|
||||
$this->_string = $string;
|
||||
}
|
||||
|
||||
public function skip($n)
|
||||
{
|
||||
$this->currPos = $this->currPos + $n;
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return $this->currPos == strlen($this->_string);
|
||||
}
|
||||
|
||||
public function read($len = null)
|
||||
{
|
||||
if ($len === null) {
|
||||
return $this->_string;
|
||||
} else {
|
||||
if ($this->currPos >= strlen($this->_string)) {
|
||||
return -1;
|
||||
}
|
||||
$out = substr($this->_string, $this->currPos, $len);
|
||||
$this->currPos += $len;
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
public function mark()
|
||||
{
|
||||
$this->mark = $this->currPos;
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->currPos = $this->mark;
|
||||
}
|
||||
|
||||
public function close() {}
|
||||
|
||||
public function open() {}
|
||||
|
||||
public function ready() {}
|
||||
|
||||
public function markSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getResource()
|
||||
{
|
||||
return '(string) "'.$this->_string . '"';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple templating system to ease behavior writing
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Revision: 1784 $
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
class PropelTemplate
|
||||
{
|
||||
protected $template, $templateFile;
|
||||
|
||||
/**
|
||||
* Set a string as a template.
|
||||
* The string doesn't need closing php tags.
|
||||
*
|
||||
* <code>
|
||||
* $template->setTemplate('This is <?php echo $name ?>');
|
||||
* </code>
|
||||
*
|
||||
* @param string $template the template string
|
||||
*/
|
||||
public function setTemplate($template)
|
||||
{
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a file as a template. The file can be any regular PHP file.
|
||||
*
|
||||
* <code>
|
||||
* $template->setTemplateFile(dirname(__FILE__) . '/template/foo.php');
|
||||
* </code>
|
||||
*
|
||||
* @param string $filePath The (absolute or relative to the include path) file path
|
||||
*/
|
||||
public function setTemplateFile($filePath)
|
||||
{
|
||||
$this->templateFile = $filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the template using the variable provided as arguments.
|
||||
*
|
||||
* <code>
|
||||
* $template = new PropelTemplate();
|
||||
* $template->setTemplate('This is <?php echo $name ?>');
|
||||
* echo $template->render(array('name' => 'Mike'));
|
||||
* // This is Mike
|
||||
* </code>
|
||||
*
|
||||
* @param array $vars An associative array of argumens to be rendered
|
||||
*
|
||||
* @return string The rendered template
|
||||
*/
|
||||
public function render($vars = array())
|
||||
{
|
||||
if (null === $this->templateFile && null === $this->template) {
|
||||
throw new InvalidArgumentException('You must set a template or a template file before rendering');
|
||||
}
|
||||
|
||||
extract($vars);
|
||||
ob_start();
|
||||
ob_implicit_flush(0);
|
||||
|
||||
try
|
||||
{
|
||||
if (null !== $this->templateFile) {
|
||||
require($this->templateFile);
|
||||
} else {
|
||||
eval('?>' . $this->template . '<?php ');
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// need to end output buffering before throwing the exception #7596
|
||||
ob_end_clean();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,417 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'model/AppData.php';
|
||||
|
||||
// Phing dependencies
|
||||
require_once 'phing/parser/AbstractHandler.php';
|
||||
|
||||
require_once 'builder/util/PropelStringReader.php';
|
||||
|
||||
/**
|
||||
* A class that is used to parse an input xml schema file and creates an AppData
|
||||
* PHP object.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Propel)
|
||||
* @author Leon Messerschmidt <leon@opticode.co.za> (Torque)
|
||||
* @author Jason van Zyl <jvanzyl@apache.org> (Torque)
|
||||
* @author Martin Poeschl <mpoeschl@marmot.at> (Torque)
|
||||
* @author Daniel Rall <dlr@collab.net> (Torque)
|
||||
* @version $Revision: 1764 $
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
class XmlToAppData extends AbstractHandler
|
||||
{
|
||||
|
||||
/** enables debug output */
|
||||
const DEBUG = false;
|
||||
|
||||
private $app;
|
||||
private $platform;
|
||||
private $currDB;
|
||||
private $currTable;
|
||||
private $currColumn;
|
||||
private $currFK;
|
||||
private $currIndex;
|
||||
private $currUnique;
|
||||
private $currValidator;
|
||||
private $currBehavior;
|
||||
private $currVendorObject;
|
||||
|
||||
private $isForReferenceOnly;
|
||||
private $currentPackage;
|
||||
private $currentXmlFile;
|
||||
private $defaultPackage;
|
||||
|
||||
private $encoding;
|
||||
|
||||
/** two-dimensional array,
|
||||
first dimension is for schemas(key is the path to the schema file),
|
||||
second is for tags within the schema */
|
||||
private $schemasTagsStack = array();
|
||||
|
||||
public $parser;
|
||||
|
||||
/**
|
||||
* Creates a new instance for the specified database type.
|
||||
*
|
||||
* @param Platform $platform The type of database for the application.
|
||||
* @param string $defaultPackage the default PHP package used for the om
|
||||
* @param string $encoding The database encoding.
|
||||
*/
|
||||
public function __construct(Platform $platform, $defaultPackage, $encoding = 'iso-8859-1')
|
||||
{
|
||||
$this->app = new AppData($platform);
|
||||
$this->platform = $platform;
|
||||
$this->defaultPackage = $defaultPackage;
|
||||
$this->firstPass = true;
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a XML input file and returns a newly created and
|
||||
* populated AppData structure.
|
||||
*
|
||||
* @param string $xmlFile The input file to parse.
|
||||
* @return AppData populated by <code>xmlFile</code>.
|
||||
*/
|
||||
public function parseFile($xmlFile)
|
||||
{
|
||||
// we don't want infinite recursion
|
||||
if ($this->isAlreadyParsed($xmlFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$f = new PhingFile($xmlFile);
|
||||
|
||||
return $this->parseString($f->contents(), $xmlFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a XML input string and returns a newly created and
|
||||
* populated AppData structure.
|
||||
*
|
||||
* @param string $xmlString The input string to parse.
|
||||
* @param string $xmlFile The input file name.
|
||||
* @return AppData populated by <code>xmlFile</code>.
|
||||
*/
|
||||
public function parseString($xmlString, $xmlFile)
|
||||
{
|
||||
// we don't want infinite recursion
|
||||
if ($this->isAlreadyParsed($xmlFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// store current schema file path
|
||||
$this->schemasTagsStack[$xmlFile] = array();
|
||||
|
||||
$this->currentXmlFile = $xmlFile;
|
||||
|
||||
try {
|
||||
$sr = new PropelStringReader($xmlString);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$f = new PhingFile($xmlFile);
|
||||
throw new Exception("XML File not found: " . $f->getAbsolutePath());
|
||||
}
|
||||
|
||||
$br = new BufferedReader($sr);
|
||||
|
||||
$this->parser = new ExpatParser($br);
|
||||
$this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
|
||||
$this->parser->setHandler($this);
|
||||
|
||||
try {
|
||||
$this->parser->parse();
|
||||
} catch (Exception $e) {
|
||||
$br->close();
|
||||
throw $e;
|
||||
}
|
||||
$br->close();
|
||||
|
||||
array_pop($this->schemasTagsStack);
|
||||
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles opening elements of the xml file.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param string $localName The local name (without prefix), or the empty string if
|
||||
* Namespace processing is not being performed.
|
||||
* @param string $rawName The qualified name (with prefix), or the empty string if
|
||||
* qualified names are not available.
|
||||
* @param string $attributes The specified or defaulted attributes
|
||||
*/
|
||||
public function startElement($name, $attributes) {
|
||||
|
||||
try {
|
||||
|
||||
$parentTag = $this->peekCurrentSchemaTag();
|
||||
|
||||
if ($parentTag === false) {
|
||||
|
||||
switch($name) {
|
||||
case "database":
|
||||
if ($this->isExternalSchema()) {
|
||||
$this->currentPackage = @$attributes["package"];
|
||||
if ($this->currentPackage === null) {
|
||||
$this->currentPackage = $this->defaultPackage;
|
||||
}
|
||||
} else {
|
||||
$this->currDB = $this->app->addDatabase($attributes);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
} elseif ($parentTag == "database") {
|
||||
|
||||
switch($name) {
|
||||
|
||||
case "external-schema":
|
||||
$xmlFile = @$attributes["filename"];
|
||||
|
||||
//"referenceOnly" attribute is valid in the main schema XML file only,
|
||||
//and it's ingnored in the nested external-schemas
|
||||
if (!$this->isExternalSchema()) {
|
||||
$isForRefOnly = @$attributes["referenceOnly"];
|
||||
$this->isForReferenceOnly = ($isForRefOnly !== null ? (strtolower($isForRefOnly) === "true") : true); // defaults to TRUE
|
||||
}
|
||||
|
||||
if ($xmlFile{0} != '/') {
|
||||
$f = new PhingFile($this->currentXmlFile);
|
||||
$xf = new PhingFile($f->getParent(), $xmlFile);
|
||||
$xmlFile = $xf->getPath();
|
||||
}
|
||||
|
||||
$this->parseFile($xmlFile);
|
||||
break;
|
||||
|
||||
case "domain":
|
||||
$this->currDB->addDomain($attributes);
|
||||
break;
|
||||
|
||||
case "table":
|
||||
$this->currTable = $this->currDB->addTable($attributes);
|
||||
if ($this->isExternalSchema()) {
|
||||
$this->currTable->setForReferenceOnly($this->isForReferenceOnly);
|
||||
$this->currTable->setPackage($this->currentPackage);
|
||||
}
|
||||
break;
|
||||
|
||||
case "vendor":
|
||||
$this->currVendorObject = $this->currDB->addVendorInfo($attributes);
|
||||
break;
|
||||
|
||||
case "behavior":
|
||||
$this->currBehavior = $this->currDB->addBehavior($attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
} elseif ($parentTag == "table") {
|
||||
|
||||
switch($name) {
|
||||
case "column":
|
||||
$this->currColumn = $this->currTable->addColumn($attributes);
|
||||
break;
|
||||
|
||||
case "foreign-key":
|
||||
$this->currFK = $this->currTable->addForeignKey($attributes);
|
||||
break;
|
||||
|
||||
case "index":
|
||||
$this->currIndex = $this->currTable->addIndex($attributes);
|
||||
break;
|
||||
|
||||
case "unique":
|
||||
$this->currUnique = $this->currTable->addUnique($attributes);
|
||||
break;
|
||||
|
||||
case "vendor":
|
||||
$this->currVendorObject = $this->currTable->addVendorInfo($attributes);
|
||||
break;
|
||||
|
||||
case "validator":
|
||||
$this->currValidator = $this->currTable->addValidator($attributes);
|
||||
break;
|
||||
|
||||
case "id-method-parameter":
|
||||
$this->currTable->addIdMethodParameter($attributes);
|
||||
break;
|
||||
|
||||
case "behavior":
|
||||
$this->currBehavior = $this->currTable->addBehavior($attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
} elseif ($parentTag == "column") {
|
||||
|
||||
switch($name) {
|
||||
case "inheritance":
|
||||
$this->currColumn->addInheritance($attributes);
|
||||
break;
|
||||
|
||||
case "vendor":
|
||||
$this->currVendorObject = $this->currColumn->addVendorInfo($attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
} elseif ($parentTag == "foreign-key") {
|
||||
|
||||
switch($name) {
|
||||
case "reference":
|
||||
$this->currFK->addReference($attributes);
|
||||
break;
|
||||
|
||||
case "vendor":
|
||||
$this->currVendorObject = $this->currUnique->addVendorInfo($attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
} elseif ($parentTag == "index") {
|
||||
|
||||
switch($name) {
|
||||
case "index-column":
|
||||
$this->currIndex->addColumn($attributes);
|
||||
break;
|
||||
|
||||
case "vendor":
|
||||
$this->currVendorObject = $this->currIndex->addVendorInfo($attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
} elseif ($parentTag == "unique") {
|
||||
|
||||
switch($name) {
|
||||
case "unique-column":
|
||||
$this->currUnique->addColumn($attributes);
|
||||
break;
|
||||
|
||||
case "vendor":
|
||||
$this->currVendorObject = $this->currUnique->addVendorInfo($attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
} elseif ($parentTag == "behavior") {
|
||||
|
||||
switch($name) {
|
||||
case "parameter":
|
||||
$this->currBehavior->addParameter($attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
} elseif ($parentTag == "validator") {
|
||||
switch($name) {
|
||||
case "rule":
|
||||
$this->currValidator->addRule($attributes);
|
||||
break;
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
} elseif ($parentTag == "vendor") {
|
||||
|
||||
switch($name) {
|
||||
case "parameter":
|
||||
$this->currVendorObject->addParameter($attributes);
|
||||
break;
|
||||
default:
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
} else {
|
||||
// it must be an invalid tag
|
||||
$this->_throwInvalidTagException($name);
|
||||
}
|
||||
|
||||
$this->pushCurrentSchemaTag($name);
|
||||
|
||||
} catch (BuildException $e) {
|
||||
throw $e;
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
echo "\n";
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
function _throwInvalidTagException($tag_name)
|
||||
{
|
||||
throw new BuildException("Unexpected tag <" . $tag_name . ">", $this->parser->getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles closing elements of the xml file.
|
||||
*
|
||||
* @param uri
|
||||
* @param localName The local name (without prefix), or the empty string if
|
||||
* Namespace processing is not being performed.
|
||||
* @param rawName The qualified name (with prefix), or the empty string if
|
||||
* qualified names are not available.
|
||||
*/
|
||||
public function endElement($name)
|
||||
{
|
||||
if (self::DEBUG) {
|
||||
print("endElement(" . $name . ") called\n");
|
||||
}
|
||||
|
||||
$this->popCurrentSchemaTag();
|
||||
}
|
||||
|
||||
protected function peekCurrentSchemaTag()
|
||||
{
|
||||
$keys = array_keys($this->schemasTagsStack);
|
||||
return end($this->schemasTagsStack[end($keys)]);
|
||||
}
|
||||
|
||||
protected function popCurrentSchemaTag()
|
||||
{
|
||||
$keys = array_keys($this->schemasTagsStack);
|
||||
array_pop($this->schemasTagsStack[end($keys)]);
|
||||
}
|
||||
|
||||
protected function pushCurrentSchemaTag($tag)
|
||||
{
|
||||
$keys = array_keys($this->schemasTagsStack);
|
||||
$this->schemasTagsStack[end($keys)][] = $tag;
|
||||
}
|
||||
|
||||
protected function isExternalSchema()
|
||||
{
|
||||
return count($this->schemasTagsStack) > 1;
|
||||
}
|
||||
|
||||
protected function isAlreadyParsed($filePath)
|
||||
{
|
||||
return isset($this->schemasTagsStack[$filePath]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'phing/parser/AbstractHandler.php';
|
||||
|
||||
/**
|
||||
* A Class that is used to parse an data dump XML file and create SQL using a DataSQLBuilder class.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Propel)
|
||||
* @version $Revision: 1612 $
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
class XmlToDataSQL extends AbstractHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* The GeneratorConfig associated with the build.
|
||||
*
|
||||
* @var GeneratorConfig
|
||||
*/
|
||||
private $generatorConfig;
|
||||
|
||||
/**
|
||||
* The database.
|
||||
*
|
||||
* @var Database
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* The output writer for the SQL file.
|
||||
*
|
||||
* @var Writer
|
||||
*/
|
||||
private $sqlWriter;
|
||||
|
||||
/**
|
||||
* The database (and output SQL file) encoding.
|
||||
*
|
||||
* Values will be converted to this encoding in the output file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $encoding;
|
||||
|
||||
/**
|
||||
* The classname of the static class that will perform the building.
|
||||
*
|
||||
* This is needed because there are some pre/post methods that get called
|
||||
* on the static class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $builderClazz;
|
||||
|
||||
/**
|
||||
* The name of the current table being processed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $currTableName;
|
||||
|
||||
/**
|
||||
* The DataSQLBuilder for the current table.
|
||||
*
|
||||
* @var DataSQLBuilder
|
||||
*/
|
||||
private $currBuilder;
|
||||
|
||||
/**
|
||||
* Expat Parser.
|
||||
*
|
||||
* @var ExpatParser
|
||||
*/
|
||||
public $parser;
|
||||
|
||||
/**
|
||||
* Flag for enabing debug output to aid in parser tracing.
|
||||
*/
|
||||
const DEBUG = false;
|
||||
|
||||
/**
|
||||
* Construct new XmlToDataSQL class.
|
||||
*
|
||||
* This class is passed the Database object so that it knows what to expect from
|
||||
* the XML file.
|
||||
*
|
||||
* @param Database $database
|
||||
* @param GeneratorConfig $config
|
||||
* @param string $encoding Database encoding
|
||||
*/
|
||||
public function __construct(Database $database, GeneratorConfig $config, $encoding = 'iso-8859-1')
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->generatorConfig = $config;
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the data dump input file into SQL and writes it to the output stream.
|
||||
*
|
||||
* @param PhingFile $xmlFile
|
||||
* @param Writer $out
|
||||
*/
|
||||
public function transform(PhingFile $xmlFile, Writer $out)
|
||||
{
|
||||
$this->sqlWriter = $out;
|
||||
|
||||
// Reset some vars just in case this is being run multiple times.
|
||||
$this->currTableName = $this->currBuilder = null;
|
||||
|
||||
$this->builderClazz = $this->generatorConfig->getBuilderClassname('datasql');
|
||||
|
||||
try {
|
||||
$fr = new FileReader($xmlFile);
|
||||
} catch (Exception $e) {
|
||||
throw new BuildException("XML File not found: " . $xmlFile->getAbsolutePath());
|
||||
}
|
||||
|
||||
$br = new BufferedReader($fr);
|
||||
|
||||
$this->parser = new ExpatParser($br);
|
||||
$this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
|
||||
$this->parser->setHandler($this);
|
||||
|
||||
try {
|
||||
$this->parser->parse();
|
||||
} catch (Exception $e) {
|
||||
print $e->getMessage() . "\n";
|
||||
$br->close();
|
||||
}
|
||||
$br->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles opening elements of the xml file.
|
||||
*/
|
||||
public function startElement($name, $attributes)
|
||||
{
|
||||
try {
|
||||
if ($name == "dataset") {
|
||||
// Clear any start/end DLL
|
||||
call_user_func(array($this->builderClazz, 'reset'));
|
||||
$this->sqlWriter->write(call_user_func(array($this->builderClazz, 'getDatabaseStartSql')));
|
||||
} else {
|
||||
|
||||
// we're processing a row of data
|
||||
// where tag name is phpName e.g. <BookReader .... />
|
||||
|
||||
$table = $this->database->getTableByPhpName($name);
|
||||
|
||||
$columnValues = array();
|
||||
foreach ($attributes as $name => $value) {
|
||||
$col = $table->getColumnByPhpName($name);
|
||||
$columnValues[] = new ColumnValue($col, iconv('utf-8',$this->encoding, $value));
|
||||
}
|
||||
|
||||
$data = new DataRow($table, $columnValues);
|
||||
|
||||
if ($this->currTableName !== $table->getName()) {
|
||||
// new table encountered
|
||||
|
||||
if ($this->currBuilder !== null) {
|
||||
$this->sqlWriter->write($this->currBuilder->getTableEndSql());
|
||||
}
|
||||
|
||||
$this->currTableName = $table->getName();
|
||||
$this->currBuilder = $this->generatorConfig->getConfiguredBuilder($table, 'datasql');
|
||||
|
||||
$this->sqlWriter->write($this->currBuilder->getTableStartSql());
|
||||
}
|
||||
|
||||
// Write the SQL
|
||||
$this->sqlWriter->write($this->currBuilder->buildRowSql($data));
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
// Exceptions have traditionally not bubbled up nicely from the expat parser,
|
||||
// so we also print the stack trace here.
|
||||
print $e;
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles closing elements of the xml file.
|
||||
*
|
||||
* @param $name The local name (without prefix), or the empty string if
|
||||
* Namespace processing is not being performed.
|
||||
*/
|
||||
public function endElement($name)
|
||||
{
|
||||
if (self::DEBUG) {
|
||||
print("endElement(" . $name . ") called\n");
|
||||
}
|
||||
if ($name == "dataset") {
|
||||
if ($this->currBuilder !== null) {
|
||||
$this->sqlWriter->write($this->currBuilder->getTableEndSql());
|
||||
}
|
||||
$this->sqlWriter->write(call_user_func(array($this->builderClazz, 'getDatabaseEndSql')));
|
||||
}
|
||||
}
|
||||
|
||||
} // XmlToData
|
||||
|
||||
/**
|
||||
* "inner class"
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
class DataRow
|
||||
{
|
||||
private $table;
|
||||
private $columnValues;
|
||||
|
||||
public function __construct(Table $table, $columnValues)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->columnValues = $columnValues;
|
||||
}
|
||||
|
||||
public function getTable()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getColumnValues()
|
||||
{
|
||||
return $this->columnValues;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "inner" class
|
||||
* @package propel.generator.builder.util
|
||||
*/
|
||||
class ColumnValue {
|
||||
|
||||
private $col;
|
||||
private $val;
|
||||
|
||||
public function __construct(Column $col, $val)
|
||||
{
|
||||
$this->col = $col;
|
||||
$this->val = $val;
|
||||
}
|
||||
|
||||
public function getColumn()
|
||||
{
|
||||
return $this->col;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->val;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue