1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
# Import plugin creation
This directory holds import plugins for phpMyAdmin. Any new plugin should
basically follow the structure presented here. The messages must use our
gettext mechanism, see https://wiki.phpmyadmin.net/pma/Gettext_for_developers.
```php
<?php
/**
* [Name] import plugin for phpMyAdmin
*/
declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Import;
use PhpMyAdmin\Plugins\ImportPlugin;
use function strlen;
/**
* Handles the import for the [Name] format
*/
class Import[Name] extends ImportPlugin
{
/**
* optional - declare variables and descriptions
*
* @var type
*/
private $myOptionalVariable;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->setProperties();
}
/**
* Sets the import plugin properties.
* Called in the constructor.
*
* @return void
*/
protected function setProperties()
{
$importPluginProperties = new PhpMyAdmin\Properties\Plugins\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 PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup(
'Format Specific Options'
);
// general options main group
$generalOptions = new PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup(
'general_opts'
);
// optional :
// 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
// len - maximal size of input
// values - possible values of the item
$leaf = new PhpMyAdmin\Properties\Options\Items\RadioPropertyItem(
'structure_or_data'
);
$leaf->setValues(
[
'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;
}
/**
* Handles the whole import logic
*
* @param array &$sql_data 2-element array with sql data
*
* @return void
*/
public function doImport(&$sql_data = [])
{
// get globals (others are optional)
global $error, $timeout_passed, $finished;
$buffer = '';
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
$data = $this->import->getNextChunk();
if ($data === false) {
// subtract data we didn't handle yet and stop processing
$GLOBALS['offset'] -= strlen($buffer);
break;
}
if ($data === true) {
// Handle rest of buffer
} else {
// Append new data to buffer
$buffer .= $data;
}
// PARSE $buffer here, post sql queries using:
$this->import->runQuery($sql, $verbose_sql_with_comments, $sql_data);
} // End of import loop
// Commit any possible data in buffers
$this->import->runQuery('', '', $sql_data);
}
/* optional: */
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
/**
* Getter description
*
* @return type
*/
private function getMyOptionalVariable(): type
{
return $this->myOptionalVariable;
}
/**
* Setter description
*
* @param type $myOptionalVariable description
*
* @return void
*/
private function _setMyOptionalVariable(type $myOptionalVariable): void
{
$this->myOptionalVariable = $myOptionalVariable;
}
}
```
|