From 02c37994c11679900a2d16d05fde7982fd160bc1 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 14:25:04 +0300 Subject: [PATCH 01/12] oop: properties for ImportCsv --- libraries/plugins/import/ImportCsv.class.php | 140 +++++++++--------- .../ImportDocsql.class.php | 0 .../{ => todo_refactor}/ImportLdi.class.php | 0 .../ImportMediawiki.class.php | 0 .../{ => todo_refactor}/ImportOds.class.php | 0 .../{ => todo_refactor}/ImportShp.class.php | 0 .../{ => todo_refactor}/ImportSql.class.php | 0 .../{ => todo_refactor}/ImportXml.class.php | 0 8 files changed, 73 insertions(+), 67 deletions(-) rename libraries/plugins/import/{ => todo_refactor}/ImportDocsql.class.php (100%) rename libraries/plugins/import/{ => todo_refactor}/ImportLdi.class.php (100%) rename libraries/plugins/import/{ => todo_refactor}/ImportMediawiki.class.php (100%) rename libraries/plugins/import/{ => todo_refactor}/ImportOds.class.php (100%) rename libraries/plugins/import/{ => todo_refactor}/ImportShp.class.php (100%) rename libraries/plugins/import/{ => todo_refactor}/ImportSql.class.php (100%) rename libraries/plugins/import/{ => todo_refactor}/ImportXml.class.php (100%) diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index b0cf2e8f67..2817409508 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -27,7 +27,7 @@ class ImportCsv extends ImportPlugin * @var bool */ private $_analyze; - + /** * Constructor */ @@ -50,67 +50,67 @@ class ImportCsv extends ImportPlugin $this->_setAnalyze(true); } - $this->properties = array( - 'text' => __('CSV'), - 'extension' => 'csv', - 'options' => array(), - 'options_text' => __('Options') - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + include_once "$props/options/items/TextPropertyItem.class.php"; - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'bool', - 'name' => 'replace', - 'text' => __('Replace table data with file') - ), - array( - 'type' => 'bool', - 'name' => 'ignore', - 'text' => __('Do not abort on INSERT error') - ), - array( - 'type' => 'text', - 'name' => 'terminated', - 'text' => __('Columns separated with:'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'enclosed', - 'text' => __('Columns enclosed with:'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'escaped', - 'text' => __('Columns escaped with:'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'new_line', - 'text' => __('Lines terminated with:'), - 'size' => 2 - ) - ); + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('CSV'); + $importPluginProperties->setExtension('csv'); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new BoolPropertyItem(); + $leaf->setName("replace"); + $leaf->setText(__('Replace table data with file')); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("terminated"); + $leaf->setText(__('Columns separated with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("enclosed"); + $leaf->setText(__('Columns enclosed with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("escaped"); + $leaf->setText(__('Columns escaped with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("new_line"); + $leaf->setText(__('Lines terminated with:')); + $leaf->setSize(2); + $generalOptions->addProperty($leaf); if ($GLOBALS['plugin_param'] !== 'table') { - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'col_names', - 'text' => __( - 'The first line of the file contains the table column names ' - . '(if this is unchecked, the first line will become part of the' - . ' data)' + $leaf = new BoolPropertyItem(); + $leaf->setName("col_names"); + $leaf->setText( + __( + 'The first line of the file contains the table column names' + . ' (if this is unchecked, the first line will become part' + . ' of the data)' ) ); + $generalOptions->addProperty($leaf); } else { $hint = new PMA_Message( __( @@ -120,15 +120,21 @@ class ImportCsv extends ImportPlugin . ' and not enclosed in quotations.' ) ); - $this->properties['options'][] = array( - 'type' => 'text', - 'name' => 'columns', - 'text' => __('Column names: ') - . PMA_CommonFunctions::getInstance()->showHint($hint) + $leaf = new TextPropertyItem(); + $leaf->setName("columns"); + $leaf->setText( + __('Column names: ') + . PMA_CommonFunctions::getInstance()->showHint($hint) ); + $generalOptions->addProperty($leaf); } - $this->properties['options'][] = array('type' => 'end_group'); + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** @@ -146,7 +152,7 @@ class ImportCsv extends ImportPlugin /** * Handles the whole import logic - * + * * @return void */ public function doImport() @@ -499,7 +505,7 @@ class ImportCsv extends ImportPlugin $sql .= ')'; /** - * @todo maybe we could add original line to verbose + * @todo maybe we could add original line to verbose * SQL in comment */ PMA_importRunQuery($sql, $sql); @@ -597,11 +603,11 @@ class ImportCsv extends ImportPlugin $error = true; } } - + /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ - + /** * Returns true if the table should be analyzed, false otherwise * diff --git a/libraries/plugins/import/ImportDocsql.class.php b/libraries/plugins/import/todo_refactor/ImportDocsql.class.php similarity index 100% rename from libraries/plugins/import/ImportDocsql.class.php rename to libraries/plugins/import/todo_refactor/ImportDocsql.class.php diff --git a/libraries/plugins/import/ImportLdi.class.php b/libraries/plugins/import/todo_refactor/ImportLdi.class.php similarity index 100% rename from libraries/plugins/import/ImportLdi.class.php rename to libraries/plugins/import/todo_refactor/ImportLdi.class.php diff --git a/libraries/plugins/import/ImportMediawiki.class.php b/libraries/plugins/import/todo_refactor/ImportMediawiki.class.php similarity index 100% rename from libraries/plugins/import/ImportMediawiki.class.php rename to libraries/plugins/import/todo_refactor/ImportMediawiki.class.php diff --git a/libraries/plugins/import/ImportOds.class.php b/libraries/plugins/import/todo_refactor/ImportOds.class.php similarity index 100% rename from libraries/plugins/import/ImportOds.class.php rename to libraries/plugins/import/todo_refactor/ImportOds.class.php diff --git a/libraries/plugins/import/ImportShp.class.php b/libraries/plugins/import/todo_refactor/ImportShp.class.php similarity index 100% rename from libraries/plugins/import/ImportShp.class.php rename to libraries/plugins/import/todo_refactor/ImportShp.class.php diff --git a/libraries/plugins/import/ImportSql.class.php b/libraries/plugins/import/todo_refactor/ImportSql.class.php similarity index 100% rename from libraries/plugins/import/ImportSql.class.php rename to libraries/plugins/import/todo_refactor/ImportSql.class.php diff --git a/libraries/plugins/import/ImportXml.class.php b/libraries/plugins/import/todo_refactor/ImportXml.class.php similarity index 100% rename from libraries/plugins/import/ImportXml.class.php rename to libraries/plugins/import/todo_refactor/ImportXml.class.php From 55c27dd333943612bc0417c432e4a8608bb66d36 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 14:27:14 +0300 Subject: [PATCH 02/12] oop: fix undefined method bug for import plug-ins --- libraries/plugin_interface.lib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/plugin_interface.lib.php b/libraries/plugin_interface.lib.php index f4b9888f32..77a82c7d1b 100644 --- a/libraries/plugin_interface.lib.php +++ b/libraries/plugin_interface.lib.php @@ -199,13 +199,16 @@ function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null) $plugin_name = strtolower(substr(get_class($plugin), strlen($section))); $ret .= ''. "\n"; } + return $ret; } From c91058d0d61f64cdcdf8fb02ffd89f0adbd5e3da Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 14:30:55 +0300 Subject: [PATCH 03/12] oop: properties for ImportDocSQL --- .../ImportDocsql.class.php | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) rename libraries/plugins/import/{todo_refactor => }/ImportDocsql.class.php (79%) diff --git a/libraries/plugins/import/todo_refactor/ImportDocsql.class.php b/libraries/plugins/import/ImportDocsql.class.php similarity index 79% rename from libraries/plugins/import/todo_refactor/ImportDocsql.class.php rename to libraries/plugins/import/ImportDocsql.class.php index 17d8288842..e0f440653b 100644 --- a/libraries/plugins/import/todo_refactor/ImportDocsql.class.php +++ b/libraries/plugins/import/ImportDocsql.class.php @@ -18,7 +18,7 @@ if ($GLOBALS['plugin_param'] !== 'database') { $GLOBALS['skip_import'] = true; return; } - + /** * Handles the import for the DocSQL format * @@ -58,27 +58,38 @@ class ImportDocsql extends ImportPlugin return; } - $this->properties = array( - 'text' => __('DocSQL'), - 'extension' => '', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/TextPropertyItem.class.php"; - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'text', - 'name' => 'table', - 'text' => __('Table name') - ), - array( - 'type' => 'end_group' - ) - ); + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('DocSQL'); + $importPluginProperties->setExtension(''); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new TextPropertyItem(); + $leaf->setName("table"); + $leaf->setText(__('Table name')); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** @@ -104,7 +115,7 @@ class ImportDocsql extends ImportPlugin global $error, $timeout_passed, $finished; $cfgRelation = $this->_getCfgRelation(); $common_functions = PMA_CommonFunctions::getInstance(); - + $tab = $_POST['docsql_table']; $buffer = ''; From 912ad23d411c3e97fa348068aad79de94a512a77 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 14:44:31 +0300 Subject: [PATCH 04/12] oop: properties for ImportLdi --- .../{todo_refactor => }/ImportLdi.class.php | 100 ++++++------------ 1 file changed, 34 insertions(+), 66 deletions(-) rename libraries/plugins/import/{todo_refactor => }/ImportLdi.class.php (68%) diff --git a/libraries/plugins/import/todo_refactor/ImportLdi.class.php b/libraries/plugins/import/ImportLdi.class.php similarity index 68% rename from libraries/plugins/import/todo_refactor/ImportLdi.class.php rename to libraries/plugins/import/ImportLdi.class.php index 09eab78a12..aef57a82bf 100644 --- a/libraries/plugins/import/todo_refactor/ImportLdi.class.php +++ b/libraries/plugins/import/ImportLdi.class.php @@ -56,71 +56,39 @@ class ImportLdi extends ImportPlugin unset($result); } - $this->properties = array( - 'text' => __('CSV using LOAD DATA'), - // Following is nonsense, however we want to default to our - // parser for csv - 'extension' => 'ldi', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + include_once "$props/options/items/TextPropertyItem.class.php"; - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'bool', - 'name' => 'replace', - 'text' => __('Replace table data with file') - ), - array( - 'type' => 'bool', - 'name' => 'ignore', - 'text' => __('Do not abort on INSERT error') - ), - array( - 'type' => 'text', - 'name' => 'terminated', - 'text' => __('Columns terminated by'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'enclosed', - 'text' => __('Columns enclosed by'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'escaped', - 'text' => __('Columns escaped by'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'new_line', - 'text' => __('Lines terminated by'), - 'size' => 2 - ), - array( - 'type' => 'text', - 'name' => 'columns', - 'text' => __('Column names') - ), - array( - 'type' => 'bool', - 'name' => 'local_option', - 'text' => __('Use LOCAL keyword') - ), - array( - 'type' => 'end_group' - ) - ); + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('CSV using LOAD DATA'); + $importPluginProperties->setExtension('ldi'); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new BoolPropertyItem(); + $leaf->setName("replacxe"); + $leaf->setText(__('Replace table data with file')); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** @@ -146,9 +114,9 @@ class ImportLdi extends ImportPlugin global $finished, $error, $import_file, $compression, $charset_conversion; global $ldi_local_option, $ldi_replace, $ldi_terminated, $ldi_enclosed, $ldi_escaped, $ldi_new_line, $skip_queries, $ldi_columns; - + $common_functions = PMA_CommonFunctions::getInstance(); - + if ($import_file == 'none' || $compression != 'none' || $charset_conversion From 01ba929c94c227803f95fda43987651bf178ef78 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 14:51:31 +0300 Subject: [PATCH 05/12] oop: properties for ImportMediawiki --- .../ImportMediawiki.class.php | 18 +++++++----- .../plugins/ExportPluginProperties.class.php | 1 - .../plugins/ImportPluginProperties.class.php | 29 +++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) rename libraries/plugins/import/{todo_refactor => }/ImportMediawiki.class.php (97%) diff --git a/libraries/plugins/import/todo_refactor/ImportMediawiki.class.php b/libraries/plugins/import/ImportMediawiki.class.php similarity index 97% rename from libraries/plugins/import/todo_refactor/ImportMediawiki.class.php rename to libraries/plugins/import/ImportMediawiki.class.php index 8ed5e52be7..e6ce2e0e96 100644 --- a/libraries/plugins/import/todo_refactor/ImportMediawiki.class.php +++ b/libraries/plugins/import/ImportMediawiki.class.php @@ -48,13 +48,17 @@ class ImportMediawiki extends ImportPlugin $this->_setAnalyze(true); } - $this->properties = array( - 'text' => __('MediaWiki Table'), - 'extension' => 'txt', - 'mime_type' => 'text/plain', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText(__('MediaWiki Table')); + $importPluginProperties->setExtension('txt'); + $importPluginProperties->setMimeType('text/plain'); + $importPluginProperties->setOptions(array()); + $importPluginProperties->setOptionsText(__('Options')); + + $this->properties = $importPluginProperties; } /** diff --git a/libraries/properties/plugins/ExportPluginProperties.class.php b/libraries/properties/plugins/ExportPluginProperties.class.php index b8f8465da8..51f9d7da79 100644 --- a/libraries/properties/plugins/ExportPluginProperties.class.php +++ b/libraries/properties/plugins/ExportPluginProperties.class.php @@ -55,7 +55,6 @@ class ExportPluginProperties extends PluginPropertyItem */ private $_mimeType; - /** * Whether to force or not * diff --git a/libraries/properties/plugins/ImportPluginProperties.class.php b/libraries/properties/plugins/ImportPluginProperties.class.php index 24ff567d61..e377fc7b0d 100644 --- a/libraries/properties/plugins/ImportPluginProperties.class.php +++ b/libraries/properties/plugins/ImportPluginProperties.class.php @@ -48,6 +48,13 @@ class ImportPluginProperties extends PluginPropertyItem */ private $_optionsText; + /** + * MIME Type + * + * @var string + */ + private $_mimeType; + /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ @@ -152,5 +159,27 @@ public function getItemType() { $this->_optionsText = $optionsText; } + + /** + * Gets the MIME type + * + * @return string + */ + public function getMimeType() + { + return $this->_mimeType; + } + + /** + * Sets the MIME type + * + * @param string $mimeType MIME type + * + * @return void + */ + public function setMimeType($mimeType) + { + $this->_mimeType = $mimeType; + } } ?> \ No newline at end of file From d83fc57c51e9fd93128ece34d8aa2c2f5b2f58c7 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 14:57:57 +0300 Subject: [PATCH 06/12] oop: properties for ImportOds --- libraries/plugins/import/ImportLdi.class.php | 2 +- .../{todo_refactor => }/ImportOds.class.php | 83 ++++++++++++------- 2 files changed, 52 insertions(+), 33 deletions(-) rename libraries/plugins/import/{todo_refactor => }/ImportOds.class.php (83%) diff --git a/libraries/plugins/import/ImportLdi.class.php b/libraries/plugins/import/ImportLdi.class.php index aef57a82bf..3780a21e8d 100644 --- a/libraries/plugins/import/ImportLdi.class.php +++ b/libraries/plugins/import/ImportLdi.class.php @@ -79,7 +79,7 @@ class ImportLdi extends ImportPlugin $generalOptions->setName("general_opts"); // create primary items and add them to the group $leaf = new BoolPropertyItem(); - $leaf->setName("replacxe"); + $leaf->setName("replace"); $leaf->setText(__('Replace table data with file')); $generalOptions->addProperty($leaf); diff --git a/libraries/plugins/import/todo_refactor/ImportOds.class.php b/libraries/plugins/import/ImportOds.class.php similarity index 83% rename from libraries/plugins/import/todo_refactor/ImportOds.class.php rename to libraries/plugins/import/ImportOds.class.php index c275de6491..d1879ef0b6 100644 --- a/libraries/plugins/import/todo_refactor/ImportOds.class.php +++ b/libraries/plugins/import/ImportOds.class.php @@ -45,40 +45,59 @@ class ImportOds extends ImportPlugin */ protected function setProperties() { - $this->properties = array( - 'text' => __('Open Document Spreadsheet'), - 'extension' => 'ods', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'bool', - 'name' => 'col_names', - 'text' => __('The first line of the file contains the table column names (if this is unchecked, the first line will become part of the data)') - ), - array( - 'type' => 'bool', - 'name' => 'empty_rows', - 'text' => __('Do not import empty rows') - ), - array( - 'type' => 'bool', - 'name' => 'recognize_percentages', - 'text' => __('Import percentages as proper decimals (ex. 12.00% to .12)') - ), - array( - 'type' => 'bool', - 'name' => 'recognize_currency', - 'text' => __('Import currencies (ex. $5.00 to 5.00)') - ), - array('type' => 'end_group') + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('Open Document Spreadsheet'); + $importPluginProperties->setExtension('ods'); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new BoolPropertyItem(); + $leaf->setName("col_names"); + $leaf->setText( + __('The first line of the file contains the table column names' + . ' (if this is unchecked, the first line will become part' + . ' of the data)' + ) ); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("empty_rows"); + $leaf->setText(__('Do not import empty rows')); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("recognize_percentages"); + $leaf->setText( + __( + 'Import percentages as proper decimals (ex. 12.00% to .12)' + ) + ); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("recognize_currency"); + $leaf->setText(__('Import currencies (ex. $5.00 to 5.00)')); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** From 7411cd39894e8b1b437598595c1b3c2e3f05ec48 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 15:03:11 +0300 Subject: [PATCH 07/12] oop: properties for ImportShp --- .../{todo_refactor => }/ImportShp.class.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) rename libraries/plugins/import/{todo_refactor => }/ImportShp.class.php (95%) diff --git a/libraries/plugins/import/todo_refactor/ImportShp.class.php b/libraries/plugins/import/ImportShp.class.php similarity index 95% rename from libraries/plugins/import/todo_refactor/ImportShp.class.php rename to libraries/plugins/import/ImportShp.class.php index 7f35135e03..e05d368464 100644 --- a/libraries/plugins/import/todo_refactor/ImportShp.class.php +++ b/libraries/plugins/import/ImportShp.class.php @@ -45,12 +45,16 @@ class ImportShp extends ImportPlugin */ protected function setProperties() { - $this->properties = array( - 'text' => __('ESRI Shape File'), - 'extension' => 'shp', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText(__('ESRI Shape File')); + $importPluginProperties->setExtension('shp'); + $importPluginProperties->setOptions(array()); + $importPluginProperties->setOptionsText(__('Options')); + + $this->properties = $importPluginProperties; } /** @@ -312,7 +316,7 @@ class ImportShp extends ImportPlugin * Sets $eof when $GLOBALS['finished'] is set and the buffer falls short. * * @param int $length number of bytes - * + * * @return string */ public static function readFromBuffer($length) From 45d6e21148aa5aaa198042325a72ead830d26d29 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 15:18:48 +0300 Subject: [PATCH 08/12] oop: properties for ImportSql --- .../{todo_refactor => }/ImportSql.class.php | 83 ++++++++++++------- 1 file changed, 52 insertions(+), 31 deletions(-) rename libraries/plugins/import/{todo_refactor => }/ImportSql.class.php (85%) diff --git a/libraries/plugins/import/todo_refactor/ImportSql.class.php b/libraries/plugins/import/ImportSql.class.php similarity index 85% rename from libraries/plugins/import/todo_refactor/ImportSql.class.php rename to libraries/plugins/import/ImportSql.class.php index d25c71139a..5f0f1e0b48 100644 --- a/libraries/plugins/import/todo_refactor/ImportSql.class.php +++ b/libraries/plugins/import/ImportSql.class.php @@ -36,12 +36,17 @@ class ImportSql extends ImportPlugin */ protected function setProperties() { - $this->properties = array( - 'text' => __('SQL'), - 'extension' => 'sql', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/SelectPropertyItem.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('SQL'); + $importPluginProperties->setExtension('sql'); + $importPluginProperties->setOptionsText(__('Options')); $compats = PMA_DBI_getCompatibilities(); if (count($compats) > 0) { @@ -49,33 +54,49 @@ class ImportSql extends ImportPlugin foreach ($compats as $val) { $values[$val] = $val; } - $this->properties['options'] = array( - array('type' => 'begin_group', 'name' => 'general_opts'), + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new SelectPropertyItem(); + $leaf->setName("compatibility"); + $leaf->setText(__('SQL compatibility mode:')); + $leaf->setValues($values); + $leaf->setDoc( array( - 'type' => 'select', - 'name' => 'compatibility', - 'text' => __('SQL compatibility mode:'), - 'values' => $values, - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'Server_SQL_mode', - ), - ), - array( - 'type' => 'bool', - 'name' => 'no_auto_value_on_zero', - 'text' => __( - 'Do not use AUTO_INCREMENT for zero values' - ), - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'Server_SQL_mode', - 'sqlmode_no_auto_value_on_zero' - ), - ), - array('type' => 'end_group'), + 'manual_MySQL_Database_Administration', + 'Server_SQL_mode', + ) ); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("no_auto_value_on_zero"); + $leaf->setText( + __('Do not use AUTO_INCREMENT for zero values') + ); + $leaf->setDoc( + array( + 'manual_MySQL_Database_Administration', + 'Server_SQL_mode', + 'sqlmode_no_auto_value_on_zero' + ) + ); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); } + + $this->properties = $importPluginProperties; } /** @@ -93,7 +114,7 @@ class ImportSql extends ImportPlugin /** * Handles the whole import logic - * + * * @param &$sql_data array 2-element array with sql data * * @return void From e16f13b0bdcb9f44563ae65503154df024eb18f9 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 15:21:16 +0300 Subject: [PATCH 09/12] oop: properties for ImportXml --- .../{todo_refactor => }/ImportXml.class.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) rename libraries/plugins/import/{todo_refactor => }/ImportXml.class.php (95%) diff --git a/libraries/plugins/import/todo_refactor/ImportXml.class.php b/libraries/plugins/import/ImportXml.class.php similarity index 95% rename from libraries/plugins/import/todo_refactor/ImportXml.class.php rename to libraries/plugins/import/ImportXml.class.php index 496a4ddc4f..7d84dd2bc4 100644 --- a/libraries/plugins/import/todo_refactor/ImportXml.class.php +++ b/libraries/plugins/import/ImportXml.class.php @@ -45,13 +45,17 @@ class ImportXml extends ImportPlugin */ protected function setProperties() { - $this->properties = array( - 'text' => __('XML'), - 'extension' => 'xml', - 'mime_type' => 'text/xml', - 'options' => array(), - 'options_text' => __('Options') - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText(__('XML')); + $importPluginProperties->setExtension('xml'); + $importPluginProperties->setMimeType('text/xml'); + $importPluginProperties->setOptions(array()); + $importPluginProperties->setOptionsText(__('Options')); + + $this->properties = $importPluginProperties; } /** From d82e1e2e9e93c8df10faac601d4da8b96d6f88ea Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 15:25:37 +0300 Subject: [PATCH 10/12] oop: properties - show "This format has no options" message --- libraries/plugin_interface.lib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/plugin_interface.lib.php b/libraries/plugin_interface.lib.php index 77a82c7d1b..2a83cf0a67 100644 --- a/libraries/plugin_interface.lib.php +++ b/libraries/plugin_interface.lib.php @@ -442,6 +442,7 @@ function PMA_pluginGetOptions($section, &$list) $ret .= '

' . PMA_getString($plugin->getProperties()->getText()) . '

'; + $no_options = true; if ($plugin->getProperties()->getOptions() != null && count($plugin->getProperties()->getOptions()) > 0 ) { From 59ba476e439af93b07bb3edbba096217578672f1 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 18:44:50 +0300 Subject: [PATCH 11/12] oop: update export readme with new properties --- libraries/plugins/export/README | 60 +++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/libraries/plugins/export/README b/libraries/plugins/export/README index 3d69bc1bd7..47d0c4fd4f 100644 --- a/libraries/plugins/export/README +++ b/libraries/plugins/export/README @@ -70,32 +70,56 @@ class Export[Name] extends ExportPlugin */ protected function setProperties() { - // optional - get globals - // set properties - $this->properties = array( // set name of your plugin - 'text' => __('[Name]'), // text to be displayed as choice - 'extension' => '[ext]', // extension this plugin can handle - 'options' => array(), // array of options - 'options_text' => __('Options') - ); + $props = 'libraries/properties/'; + // include the main class for properties for the export plug-ins + include_once "$props/plugins/ExportPluginProperties.class.php"; + // include the group properties classes + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + // include the needed single property items + include_once "$props/options/items/RadioPropertyItem.class.php"; + + $exportPluginProperties = new ExportPluginProperties(); + $exportPluginProperties->setText('[name]'); // the name of your plug-in + $exportPluginProperties->setExtension('[ext]'); // extension this plug-in can handle + $exportPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $exportPluginProperties + // this will be shown as "Format specific options" + $exportSpecificOptions = new OptionsPropertyRootGroup(); + $exportSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); // optional : - // type - bool or text, or begin/end group_subgroup + // create primary items and add them to the group + // type - one of the classes listed in libraries/properties/options/items/ // name - form element name // text - description in GUI - // size - size of text element (optional) - // len - maximal size of input (optional) - $this->properties['options'] = array( + // size - size of text element + // len - maximal size of input + // values - possible values of the item + $leaf = new RadioPropertyItem(); + $leaf->setName("structure_or_data"); + $leaf->setValues( array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - [..], - array( - 'type' => 'end_group' + 'structure' => __('structure'), + 'data' => __('data'), + 'structure_and_data' => __('structure and data') ) ); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $exportSpecificOptions->addProperty($generalOptions); + + // set the options for the export plugin property item + $exportPluginProperties->setOptions($exportSpecificOptions); + $this->properties = $exportPluginProperties; } /** From b5ec05f7c900b92714867d41340165258746f1e0 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Mon, 30 Jul 2012 18:50:56 +0300 Subject: [PATCH 12/12] oop: update import readme with new properties --- libraries/plugins/import/README | 60 +++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/libraries/plugins/import/README b/libraries/plugins/import/README index 8e840658a1..fae847f064 100644 --- a/libraries/plugins/import/README +++ b/libraries/plugins/import/README @@ -48,32 +48,56 @@ class Import[Name] extends ImportPlugin */ protected function setProperties() { - // optional - get globals - // set properties - $this->properties = array( // set name of your plugin - 'text' => __('[Name]'), // text to be displayed as choice - 'extension' => '[ext]', // extension this plugin can handle - 'options' => array(), // array of options - 'options_text' => __('Options') - ); + $props = 'libraries/properties/'; + // include the main class for properties for the import plug-ins + include_once "$props/plugins/ImportPluginProperties.class.php"; + // include the group properties classes + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + // include the needed single property items + include_once "$props/options/items/RadioPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('[name]'); // the name of your plug-in + $importPluginProperties->setExtension('[ext]'); // extension this plug-in can handle + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); // optional : - // type - bool or text, or begin/end group_subgroup + // create primary items and add them to the group + // type - one of the classes listed in libraries/properties/options/items/ // name - form element name // text - description in GUI - // size - size of text element (optional) - // len - maximal size of input (optional) - $this->properties['options'] = array( + // size - size of text element + // len - maximal size of input + // values - possible values of the item + $leaf = new RadioPropertyItem(); + $leaf->setName("structure_or_data"); + $leaf->setValues( array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - [..], - array( - 'type' => 'end_group' + 'structure' => __('structure'), + 'data' => __('data'), + 'structure_and_data' => __('structure and data') ) ); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /**