Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- mdb2_schema tool moved from "bin" to "scripts" folder. now installs…
… to pear_bin dir - introducing www/mdb2_schematool that is a rewrite of docs/examples/example.php and should be installed to web root - package.xml reflects new files changes git-svn-id: http://svn.php.net/repository/pear/packages/MDB2_Schema/trunk@268111 c90b9560-bf6c-de11-be94-00142212c4b1
- Loading branch information
Showing
7 changed files
with
717 additions
and
427 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/env php | ||
#!@php_bin@ | ||
<?php | ||
require_once 'MDB2/Schema/Tool.php'; | ||
MDB2_Schema_Tool::run(); | ||
?> | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
<?php | ||
// +----------------------------------------------------------------------+ | ||
// | PHP versions 4 and 5 | | ||
// +----------------------------------------------------------------------+ | ||
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, | | ||
// | Stig. S. Bakken, Lukas Smith, Igor Feghali | | ||
// | All rights reserved. | | ||
// +----------------------------------------------------------------------+ | ||
// | MDB2_Schema enables users to maintain RDBMS independant schema files | | ||
// | in XML that can be used to manipulate both data and database schemas | | ||
// | This LICENSE is in the BSD license style. | | ||
// | | | ||
// | Redistribution and use in source and binary forms, with or without | | ||
// | modification, are permitted provided that the following conditions | | ||
// | are met: | | ||
// | | | ||
// | Redistributions of source code must retain the above copyright | | ||
// | notice, this list of conditions and the following disclaimer. | | ||
// | | | ||
// | Redistributions in binary form must reproduce the above copyright | | ||
// | notice, this list of conditions and the following disclaimer in the | | ||
// | documentation and/or other materials provided with the distribution. | | ||
// | | | ||
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | | ||
// | Lukas Smith, Igor Feghali nor the names of his contributors may be | | ||
// | used to endorse or promote products derived from this software | | ||
// | without specific prior written permission. | | ||
// | | | ||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | | ||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | | ||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | | ||
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | | ||
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | | ||
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | ||
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| | ||
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | ||
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | ||
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| | ||
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | ||
// | POSSIBILITY OF SUCH DAMAGE. | | ||
// +----------------------------------------------------------------------+ | ||
// | Author: Lukas Smith <smith@pooteeweet.org> | | ||
// | Author: Igor Feghali <ifeghali@php.net> | | ||
// +----------------------------------------------------------------------+ | ||
// | ||
// $Id$ | ||
// | ||
|
||
/** | ||
* This is all rather ugly code, thats probably very much XSS exploitable etc. | ||
* However the idea was to keep the magic and dependencies low, to just | ||
* illustrate the MDB2_Schema API a bit. | ||
*/ | ||
|
||
require_once 'MDB2/Schema.php'; | ||
require_once 'class.inc.php'; | ||
|
||
$data =& MDB2_Schema_Example::factory($_GET); | ||
if (PEAR::isError($data)) { | ||
setcookie('error', $data->getMessage()); | ||
header('location: index.php'); | ||
exit; | ||
} | ||
|
||
$schema =& MDB2_Schema::factory($data->dsn, $data->options); | ||
if (PEAR::isError($schema)) { | ||
$error = $schema->getMessage() . ' ' . $schema->getUserInfo(); | ||
setcookie('error', $error); | ||
header('location: index.php'); | ||
exit; | ||
} | ||
|
||
switch ($data->action) { | ||
/* DUMP DATABASE */ | ||
case 'dump': | ||
switch ($data->dumptype) { | ||
case 'structure': | ||
$dump_what = MDB2_SCHEMA_DUMP_STRUCTURE; | ||
break; | ||
case 'content': | ||
$dump_what = MDB2_SCHEMA_DUMP_CONTENT; | ||
break; | ||
default: | ||
$dump_what = MDB2_SCHEMA_DUMP_ALL; | ||
break; | ||
} | ||
$dump_config = array( | ||
'output_mode' => 'file', | ||
'output' => $data->file | ||
); | ||
|
||
$definition = $schema->getDefinitionFromDatabase(); | ||
if (PEAR::isError($definition)) { | ||
$error = $definition->getMessage() . ' ' . $definition->getUserInfo(); | ||
} else { | ||
$operation = $schema->dumpDatabase($definition, $dump_config, $dump_what); | ||
if (PEAR::isError($operation)) { | ||
$error = $operation->getMessage() . ' ' . $operation->getUserInfo(); | ||
} | ||
} | ||
break; | ||
|
||
/* UPDATE DATABASE */ | ||
case 'update': | ||
if ($data->disable_query) { | ||
$debug_tmp = $schema->db->getOption('debug'); | ||
$schema->db->setOption('debug', true); | ||
$debug_handler_tmp = $schema->db->getOption('debug_handler'); | ||
$schema->db->setOption('debug_handler', 'printQueries'); | ||
} | ||
|
||
$dump_config = array( | ||
'output_mode' => 'file', | ||
'output' => $data->file.'.old' | ||
); | ||
$definition = $schema->getDefinitionFromDatabase(); | ||
if (PEAR::isError($definition)) { | ||
$error = $definition->getMessage() . ' ' . $definition->getUserInfo(); | ||
} else { | ||
$operation = $schema->dumpDatabase($definition, $dump_config, MDB2_SCHEMA_DUMP_ALL); | ||
if (PEAR::isError($operation)) { | ||
$error = $operation->getMessage() . ' ' . $operation->getUserInfo(); | ||
} else { | ||
$operation = $schema->updateDatabase($data->file | ||
, $data->file.'.old', array(), $data->disable_query | ||
); | ||
if (PEAR::isError($operation)) { | ||
$error = $operation->getMessage() . ' ' . $operation->getUserInfo(); | ||
} | ||
} | ||
} | ||
|
||
if ($data->disable_query) { | ||
$schema->db->setOption('debug', $debug_tmp); | ||
$schema->db->setOption('debug_handler', $debug_handler_tmp); | ||
} | ||
break; | ||
|
||
/* CREATE DATABASE */ | ||
case 'create': | ||
if ($data->disable_query) { | ||
$debug_tmp = $schema->db->getOption('debug'); | ||
$schema->db->setOption('debug', true); | ||
$debug_handler_tmp = $schema->db->getOption('debug_handler'); | ||
$schema->db->setOption('debug_handler', 'printQueries'); | ||
} | ||
|
||
$definition = $schema->parseDatabaseDefinition( | ||
$data->file, false, array(), $schema->options['fail_on_invalid_names'] | ||
); | ||
if (PEAR::isError($definition)) { | ||
$error = $definition->getMessage() . ' ' . $definition->getUserInfo(); | ||
} else { | ||
$schema->db->setOption('disable_query', $data->disable_query); | ||
$operation = $schema->createDatabase($definition); | ||
$schema->db->setOption('disable_query', false); | ||
|
||
if (PEAR::isError($operation)) { | ||
$error = $operation->getMessage() . ' ' . $operation->getUserInfo(); | ||
} | ||
} | ||
|
||
if ($data->disable_query) { | ||
$schema->db->setOption('debug', $debug_tmp); | ||
$schema->db->setOption('debug_handler', $debug_handler_tmp); | ||
} | ||
break; | ||
|
||
/* INITIALIZE DATABASE */ | ||
case 'initialize': | ||
if ($data->disable_query) { | ||
$debug_tmp = $schema->db->getOption('debug'); | ||
$schema->db->setOption('debug', true); | ||
$debug_handler_tmp = $schema->db->getOption('debug_handler'); | ||
$schema->db->setOption('debug_handler', 'printQueries'); | ||
} | ||
|
||
$definition = $schema->parseDatabaseDefinition( | ||
$data->file, false, array(), $schema->options['fail_on_invalid_names'] | ||
); | ||
if (PEAR::isError($definition)) { | ||
$error = $definition->getMessage() . ' ' . $definition->getUserInfo(); | ||
} else { | ||
$schema->db->setOption('disable_query', $data->disable_query); | ||
if (isset($definition['tables']) | ||
&& is_array($definition['tables']) | ||
) { | ||
foreach ($definition['tables'] as $table_name => $table) { | ||
$operation = $schema->initializeTable($table_name, $table); | ||
if (PEAR::isError($operation)) { | ||
$error = $operation->getMessage() . ' ' . $operation->getUserInfo(); | ||
} | ||
} | ||
} | ||
$schema->db->setOption('disable_query', false); | ||
} | ||
|
||
if ($data->disable_query) { | ||
$schema->db->setOption('debug', $debug_tmp); | ||
$schema->db->setOption('debug_handler', $debug_handler_tmp); | ||
} | ||
break; | ||
} | ||
|
||
include 'result.php'; | ||
$schema->disconnect(); | ||
?> |
Oops, something went wrong.