Skip to content

Commit

Permalink
- mdb2_schema tool moved from "bin" to "scripts" folder. now installs…
Browse files Browse the repository at this point in the history
… 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
ifeghali committed Nov 1, 2008
1 parent aa0864a commit 8edb9c2
Show file tree
Hide file tree
Showing 7 changed files with 717 additions and 427 deletions.
419 changes: 0 additions & 419 deletions docs/examples/example.php

This file was deleted.

20 changes: 14 additions & 6 deletions package.xml
Expand Up @@ -92,14 +92,22 @@ open todo items:
- Fulltext index support</notes>
<contents>
<dir baseinstalldir="/" name="/">
<dir name="bin">
<file name="mdb2_schematool" role="data" />
</dir> <!-- /bin -->
<dir name="www">
<dir name="mdb2_schematool">
<file name="action.php" role="www" />
<file name="class.inc.php" role="www" />
<file name="index.php" role="www" />
<file name="result.php" role="www" />
</dir>
</dir> <!-- /www -->
<dir name="scripts">
<file name="mdb2_schematool" role="script">
<tasks:replace from="@php_bin@" to="php_bin" type="pear-config" />
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
</dir> <!-- /scripts -->
<dir name="docs">
<dir name="examples">
<file name="example.php" role="doc">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
<file name="parse.php" role="doc">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
Expand Down
4 changes: 2 additions & 2 deletions bin/mdb2_schematool → scripts/mdb2_schematool
@@ -1,5 +1,5 @@
#!/bin/env php
#!@php_bin@
<?php
require_once 'MDB2/Schema/Tool.php';
MDB2_Schema_Tool::run();
?>
?>
207 changes: 207 additions & 0 deletions www/mdb2_schematool/action.php
@@ -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();
?>

0 comments on commit 8edb9c2

Please sign in to comment.