README 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. This directory holds import plugins for phpMyAdmin. Any new plugin should
  2. basically follow the structure presented here. The messages must use our
  3. gettext mechanism, see https://wiki.phpmyadmin.net/pma/Gettext_for_developers.
  4. <?php
  5. /* vim: set expandtab sw=4 ts=4 sts=4: */
  6. /**
  7. * [Name] import plugin for phpMyAdmin
  8. *
  9. * @package PhpMyAdmin-Import
  10. * @subpackage [Name]
  11. */
  12. namespace PhpMyAdmin\Plugins\Import;
  13. use PhpMyAdmin\Import;
  14. use PhpMyAdmin\Plugins\ImportPlugin;
  15. /**
  16. * Handles the import for the [Name] format
  17. *
  18. * @package PhpMyAdmin-Import
  19. */
  20. class Import[Name] extends ImportPlugin
  21. {
  22. /**
  23. * optional - declare variables and descriptions
  24. *
  25. * @var type
  26. */
  27. private $_myOptionalVariable;
  28. /**
  29. * Constructor
  30. */
  31. public function __construct()
  32. {
  33. $this->setProperties();
  34. }
  35. /**
  36. * Sets the import plugin properties.
  37. * Called in the constructor.
  38. *
  39. * @return void
  40. */
  41. protected function setProperties()
  42. {
  43. $importPluginProperties = new PhpMyAdmin\Properties\Plugins\ImportPluginProperties();
  44. $importPluginProperties->setText('[name]'); // the name of your plug-in
  45. $importPluginProperties->setExtension('[ext]'); // extension this plug-in can handle
  46. $importPluginProperties->setOptionsText(__('Options'));
  47. // create the root group that will be the options field for
  48. // $importPluginProperties
  49. // this will be shown as "Format specific options"
  50. $importSpecificOptions = new
  51. PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup(
  52. "Format Specific Options"
  53. );
  54. // general options main group
  55. $generalOptions = new PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup(
  56. "general_opts"
  57. );
  58. // optional :
  59. // create primary items and add them to the group
  60. // type - one of the classes listed in libraries/properties/options/items/
  61. // name - form element name
  62. // text - description in GUI
  63. // size - size of text element
  64. // len - maximal size of input
  65. // values - possible values of the item
  66. $leaf = new PhpMyAdmin\Properties\Options\Items\RadioPropertyItem(
  67. "structure_or_data"
  68. );
  69. $leaf->setValues(
  70. array(
  71. 'structure' => __('structure'),
  72. 'data' => __('data'),
  73. 'structure_and_data' => __('structure and data')
  74. )
  75. );
  76. $generalOptions->addProperty($leaf);
  77. // add the main group to the root group
  78. $importSpecificOptions->addProperty($generalOptions);
  79. // set the options for the import plugin property item
  80. $importPluginProperties->setOptions($importSpecificOptions);
  81. $this->properties = $importPluginProperties;
  82. }
  83. /**
  84. * Handles the whole import logic
  85. *
  86. * @param array &$sql_data 2-element array with sql data
  87. *
  88. * @return void
  89. */
  90. public function doImport(&$sql_data = array())
  91. {
  92. // get globals (others are optional)
  93. global $error, $timeout_passed, $finished;
  94. $buffer = '';
  95. while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
  96. $data = Import::getNextChunk();
  97. if ($data === false) {
  98. // subtract data we didn't handle yet and stop processing
  99. $GLOBALS['offset'] -= strlen($buffer);
  100. break;
  101. } elseif ($data === true) {
  102. // Handle rest of buffer
  103. } else {
  104. // Append new data to buffer
  105. $buffer .= $data;
  106. }
  107. // PARSE $buffer here, post sql queries using:
  108. Import::runQuery($sql, $verbose_sql_with_comments, $sql_data);
  109. } // End of import loop
  110. // Commit any possible data in buffers
  111. Import::runQuery('', '', $sql_data);
  112. }
  113. // optional:
  114. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  115. /**
  116. * Getter description
  117. *
  118. * @return type
  119. */
  120. private function _getMyOptionalVariable()
  121. {
  122. return $this->_myOptionalVariable;
  123. }
  124. /**
  125. * Setter description
  126. *
  127. * @param type $my_optional_variable description
  128. *
  129. * @return void
  130. */
  131. private function _setMyOptionalVariable($my_optional_variable)
  132. {
  133. $this->_myOptionalVariable = $my_optional_variable;
  134. }
  135. }
  136. ?>