17 import(
'lib.pkp.classes.db.DBDataXMLParser');
39 parent::__construct(
$argv);
41 if (isset($this->argv[0]) && in_array($this->argv[0], array(
'-schema',
'-data'))) {
42 $this->type = substr($this->argv[0], 1);
45 $this->type =
'schema';
49 if (!isset($this->argv[$argOffset]) || !in_array($this->argv[$argOffset], array(
'print',
'save',
'print_upgrade',
'save_upgrade',
'execute'))) {
54 $this->command = $this->argv[$argOffset];
56 $file = isset($this->argv[$argOffset+1]) ? $this->argv[$argOffset+1] : DATABASE_XML_FILE;
58 if (!file_exists($file) && !file_exists(($file2 = PWD .
'/' . $file))) {
59 printf(
"Input file \"%s\" does not exist!\n", $file);
63 $this->inputFile = isset($file2) ? $file2 : $file;
65 $this->outputFile = isset($this->argv[$argOffset+2]) ? PWD .
'/' . $this->argv[$argOffset+2] :
null;
66 if (in_array($this->command, array(
'save',
'save_upgrade')) && ($this->outputFile ==
null || (file_exists($this->outputFile) && (is_dir($this->outputFile) || !is_writeable($this->outputFile))) || !is_writable(dirname($this->outputFile)))) {
67 printf(
"Invalid output file \"%s\"!\n", $this->outputFile);
76 echo
"Script to convert and execute XML-formatted database schema and data files\n"
77 .
"Usage: {$this->scriptName} [-data|-schema] command [input_file] [output_file]\n"
78 .
"Supported commands:\n"
79 .
" print - print SQL statements\n"
80 .
" save - save SQL statements to output_file\n"
81 .
" print_upgrade - print upgrade SQL statements for current database\n"
82 .
" save_upgrade - save upgrade SQL statements to output_file\n"
83 .
" execute - execute SQL statements on current database\n";
91 require_once(
'./lib/pkp/lib/vendor/adodb/adodb-php/adodb-xmlschema.inc.php');
93 if (in_array($this->command, array(
'print',
'save'))) {
104 $dbconn = $conn->getDBConn();
111 $schema =
new adoSchema($dbconn);
112 $dict =& $schema->dict;
114 if ($this->type ==
'schema') {
116 $sql = $schema->parseSchema($this->inputFile);
118 switch ($this->command) {
120 $schema->ExecuteSchema();
124 $schema->SaveSQL($this->outputFile);
127 case 'print_upgrade':
129 echo @$schema->PrintSQL(
'TEXT') .
"\n";
133 }
else if ($this->type ==
'data') {
136 $dataXMLParser->setDBConn($dbconn);
137 $sql = $dataXMLParser->parseData($this->inputFile);
139 switch ($this->command) {
141 $schema->addSQL($sql);
142 $schema->ExecuteSchema();
146 $schema->addSQL($sql);
147 $schema->SaveSQL($this->outputFile);
150 case 'print_upgrade':
152 $schema->addSQL($sql);
153 echo @$schema->PrintSQL(
'TEXT') .
"\n";