Skip to content

Commit

Permalink
oop: export codegen; camel caps export naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
amarin15 committed Jun 8, 2012
1 parent 54098d0 commit 683d767
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 372 deletions.
35 changes: 16 additions & 19 deletions export.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@
PMA_fatalError(__('Bad parameters!'));
}

// Get the functions specific to the export type
require 'libraries/export/' . PMA_securePath($type) . '.php';

/**
* Increase time limit for script execution and initializes some variables
*/
Expand Down Expand Up @@ -499,11 +496,11 @@ function PMA_exportOutputHandler($line)
if (! $export_plugin->exportDBCreate($current_db)) {
break 2;
}
if (function_exists('PMA_exportRoutines')
if (function_exists('$export_plugin->exportRoutines')
&& strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
&& isset($GLOBALS['sql_procedure_function'])
) {
PMA_exportRoutines($current_db);
$export_plugin->exportRoutines($current_db);
}

$tables = PMA_DBI_get_tables($current_db);
Expand All @@ -520,7 +517,7 @@ function PMA_exportOutputHandler($line)
) {
// for a view, export a stand-in definition of the table
// to resolve view dependencies
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$current_db, $table, $crlf, $err_url,
$is_view ? 'stand_in' : 'create_table', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand All @@ -544,7 +541,7 @@ function PMA_exportOutputHandler($line)
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
) {
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$current_db, $table, $crlf, $err_url,
'triggers', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand All @@ -558,7 +555,7 @@ function PMA_exportOutputHandler($line)
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
) {
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$current_db, $view, $crlf, $err_url,
'create_view', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand All @@ -567,21 +564,21 @@ function PMA_exportOutputHandler($line)
}
}
}
if (! PMA_exportDBFooter($current_db)) {
if (! $export_plugin->exportDBFooter($current_db)) {
break 2;
}
}
}
} elseif ($export_type == 'database') {
if (! PMA_exportDBHeader($db)) {
if (! $export_plugin->exportDBHeader($db)) {
break;
}

if (function_exists('PMA_exportRoutines')
if (function_exists('$export_plugin->exportRoutines')
&& strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
&& isset($GLOBALS['sql_procedure_function'])
) {
PMA_exportRoutines($db);
$export_plugin->exportRoutines($db);
}

$i = 0;
Expand All @@ -599,7 +596,7 @@ function PMA_exportOutputHandler($line)
) {
// for a view, export a stand-in definition of the table
// to resolve view dependencies
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$db, $table, $crlf, $err_url,
$is_view ? 'stand_in' : 'create_table', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand All @@ -621,7 +618,7 @@ function PMA_exportOutputHandler($line)
// now export the triggers (needs to be done after the data because
// triggers can modify already imported tables)
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$db, $table, $crlf, $err_url,
'triggers', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand All @@ -633,7 +630,7 @@ function PMA_exportOutputHandler($line)
foreach ($views as $view) {
// no data export for a view
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$db, $view, $crlf, $err_url,
'create_view', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand All @@ -643,11 +640,11 @@ function PMA_exportOutputHandler($line)
}
}

if (!PMA_exportDBFooter($db)) {
if (! $export_plugin->exportDBFooter($db)) {
break;
}
} else {
if (!PMA_exportDBHeader($db)) {
if (! $export_plugin->exportDBHeader($db)) {
break;
}
// We export just one table
Expand All @@ -662,7 +659,7 @@ function PMA_exportOutputHandler($line)

$is_view = PMA_Table::isView($db, $table);
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$db, $table, $crlf, $err_url,
$is_view ? 'create_view' : 'create_table', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand Down Expand Up @@ -692,7 +689,7 @@ function PMA_exportOutputHandler($line)
// now export the triggers (needs to be done after the data because
// triggers can modify already imported tables)
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (! PMA_exportStructure(
if (! $export_plugin->exportStructure(
$db, $table, $crlf, $err_url,
'triggers', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
Expand Down
4 changes: 3 additions & 1 deletion libraries/plugin_interface.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function PMA_getPlugin($plugin_type, $plugin_format, $plugins_dir, $plugin_param
// todo replace strtoupper with CamelCaps (ex: HtmlWord)
$class_name = strtoupper($plugin_type[0])
. strtolower(substr($plugin_type, 1))
. strtoupper($plugin_format);
. strtoupper($plugin_format[0])
. strtolower(substr($plugin_format, 1));
$file = $class_name . ".class.php";
if (is_file($plugins_dir . $file)) {
include_once $plugins_dir . $file;
Expand All @@ -31,6 +32,7 @@ function PMA_getPlugin($plugin_type, $plugin_format, $plugins_dir, $plugin_param

return null;
}

/**
* Reads all plugin information from directory $plugins_dir
*
Expand Down
64 changes: 63 additions & 1 deletion libraries/plugins/ExportPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ abstract class ExportPlugin extends PluginObserver
*/
private $_db;


/**
* Common methods, must be overwritten by all export plugins
*/


/**
* Outputs export header
*
Expand Down Expand Up @@ -104,14 +110,70 @@ abstract public function exportDBCreate($db);
*/
abstract public function exportData ($db, $table, $crlf, $error_url, $sql_query);


/**
* The following methods are used in export.php, but they are not
* implemented by all export plugins
*/


/**
* Exports routines (procedures and functions)
*
* @param string $db Database
*
* @return bool Whether it succeeded
*/
public function exportRoutines($db)
{
;
}

/**
* Outputs table's structure
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $export_mode 'create_table','triggers','create_view',
* 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param bool $relation whether to include relation comments
* @param bool $comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls exportStructure() also for other export
* types which use this parameter
* @param bool $mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
*
* @return bool Whether it succeeded
*/
public function exportStructure(
$db,
$table,
$crlf,
$error_url,
$export_mode,
$export_type,
$relation = false,
$comments = false,
$mime = false,
$dates = false
) {
;
}


/**
* Initializes the local variables with the global values.
* These are variables that are used by all of the export plugins.
*
* @global String $crlf type of the newline character
* @global array $cfg array with configuration settings
* @global String $db database name
*
*
* @return void
*/
protected function initExportCommonVariables()
Expand Down
Loading

0 comments on commit 683d767

Please sign in to comment.