You've already forked phpmyadmin
mirror of
https://github.com/phpmyadmin/phpmyadmin.git
synced 2026-10-28 07:41:55 +03:00
Minimize code duplication by pushing most of the common code to abstract parent class's setProperties() method
This commit is contained in:
@@ -22,16 +22,33 @@ require_once 'libraries/plugins/ImportPlugin.class.php';
|
||||
abstract class AbstractImportCsv extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Populates the passed OptionsPropertyMainGroup object with options common to
|
||||
* CSV type imports.
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @param object $generalOptions main group of format specific options
|
||||
*
|
||||
* @return object main group of format specific options populated
|
||||
* with common options
|
||||
* @return object OptionsPropertyMainGroup object of the plugin
|
||||
*/
|
||||
protected function populateCommonOptions($generalOptions)
|
||||
protected function setProperties()
|
||||
{
|
||||
$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";
|
||||
|
||||
$importPluginProperties = new ImportPluginProperties();
|
||||
$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 common items and add them to the group
|
||||
$leaf = new BoolPropertyItem();
|
||||
$leaf->setName("replace");
|
||||
@@ -61,6 +78,13 @@ abstract class AbstractImportCsv extends ImportPlugin
|
||||
$leaf->setSize(2);
|
||||
$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;
|
||||
|
||||
return $generalOptions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,28 +51,9 @@ class ImportCsv extends AbstractImportCsv
|
||||
$this->_setAnalyze(true);
|
||||
}
|
||||
|
||||
$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";
|
||||
|
||||
$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");
|
||||
$generalOptions = $this->populateCommonOptions($generalOptions);
|
||||
$generalOptions = parent::setProperties();
|
||||
$this->properties->setText('CSV');
|
||||
$this->properties->setExtension('csv');
|
||||
|
||||
if ($GLOBALS['plugin_param'] !== 'table') {
|
||||
$leaf = new BoolPropertyItem();
|
||||
@@ -102,13 +83,6 @@ class ImportCsv extends AbstractImportCsv
|
||||
);
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,51 +57,24 @@ class ImportLdi extends AbstractImportCsv
|
||||
unset($result);
|
||||
}
|
||||
|
||||
$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";
|
||||
|
||||
$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");
|
||||
|
||||
$leaf = new BoolPropertyItem();
|
||||
$leaf->setName("ignore");
|
||||
$leaf->setText(__('Do not abort on INSERT error'));
|
||||
$generalOptions->addProperty($leaf);
|
||||
|
||||
$generalOptions = $this->populateCommonOptions($generalOptions);
|
||||
$generalOptions = parent::setProperties();
|
||||
$this->properties->setText('CSV using LOAD DATA');
|
||||
$this->properties->setExtension('ldi');
|
||||
|
||||
$leaf = new TextPropertyItem();
|
||||
$leaf->setName("columns");
|
||||
$leaf->setText(__('Column names: '));
|
||||
$generalOptions->addProperty($leaf);
|
||||
|
||||
$leaf = new BoolPropertyItem();
|
||||
$leaf->setName("ignore");
|
||||
$leaf->setText(__('Do not abort on INSERT error'));
|
||||
$generalOptions->addProperty($leaf);
|
||||
|
||||
$leaf = new BoolPropertyItem();
|
||||
$leaf->setName("local_option");
|
||||
$leaf->setText(__('Use LOCAL keyword'));
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user