1 This directory holds import plugins for phpMyAdmin. Any new plugin should
2 basically follow the structure presented here. Official plugins need to
3 have str* messages with their definition in language files, but if you build
4 some plugins for your use, you can directly use texts in plugin.
7 /* vim: set expandtab sw=4 ts=4 sts=4: */
9 * [Name] import plugin for phpMyAdmin
11 * @package PhpMyAdmin-Import
14 if (! defined('PHPMYADMIN')) {
18 /* Get the import interface */
19 require_once 'libraries/plugins/ImportPlugin.class.php';
22 * Handles the import for the [Name] format
24 * @package PhpMyAdmin-Import
26 class Import[Name] extends ImportPlugin
29 * optional - declare variables and descriptions
33 private $_myOptionalVariable;
38 public function __construct()
40 $this->setProperties();
44 * Sets the import plugin properties.
45 * Called in the constructor.
49 protected function setProperties()
52 $props = 'libraries/properties/';
53 // include the main class for properties for the import plug-ins
54 include_once "$props/plugins/ImportPluginProperties.class.php";
55 // include the group properties classes
56 include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
57 include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
58 // include the needed single property items
59 include_once "$props/options/items/RadioPropertyItem.class.php";
61 $importPluginProperties = new ImportPluginProperties();
62 $importPluginProperties->setText('[name]'); // the name of your plug-in
63 $importPluginProperties->setExtension('[ext]'); // extension this plug-in can handle
64 $importPluginProperties->setOptionsText(__('Options'));
66 // create the root group that will be the options field for
67 // $importPluginProperties
68 // this will be shown as "Format specific options"
69 $importSpecificOptions = new OptionsPropertyRootGroup();
70 $importSpecificOptions->setName("Format Specific Options");
72 // general options main group
73 $generalOptions = new OptionsPropertyMainGroup();
74 $generalOptions->setName("general_opts");
77 // create primary items and add them to the group
78 // type - one of the classes listed in libraries/properties/options/items/
79 // name - form element name
80 // text - description in GUI
81 // size - size of text element
82 // len - maximal size of input
83 // values - possible values of the item
84 $leaf = new RadioPropertyItem();
85 $leaf->setName("structure_or_data");
88 'structure' => __('structure'),
90 'structure_and_data' => __('structure and data')
93 $generalOptions->addProperty($leaf);
95 // add the main group to the root group
96 $importSpecificOptions->addProperty($generalOptions);
98 // set the options for the import plugin property item
99 $importPluginProperties->setOptions($importSpecificOptions);
100 $this->properties = $importPluginProperties;
104 * This method is called when any PluginManager to which the observer
105 * is attached calls PluginManager::notify()
107 * @param SplSubject $subject The PluginManager notifying the observer
112 public function update (SplSubject $subject)
117 * Handles the whole import logic
121 public function doImport()
123 // get globals (others are optional)
124 global $error, $timeout_passed, $finished;
127 while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
128 $data = PMA_importGetNextChunk();
129 if ($data === false) {
130 // subtract data we didn't handle yet and stop processing
131 $offset -= strlen($buffer);
133 } elseif ($data === true) {
134 // Handle rest of buffer
136 // Append new data to buffer
139 // PARSE $buffer here, post sql queries using:
140 PMA_importRunQuery($sql, $verbose_sql_with_comments);
141 } // End of import loop
142 // Commit any possible data in buffers
143 PMA_importRunQuery();
148 /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
156 private function _getMyOptionalVariable()
158 return $this->_myOptionalVariable;
164 * @param type $my_optional_variable description
168 private function _setMyOptionalVariable($my_optional_variable)
170 $this->_myOptionalVariable = $my_optional_variable;