README 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 http://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. if (! defined('PHPMYADMIN')) {
  13. exit;
  14. }
  15. /* Get the import interface */
  16. require_once 'libraries/plugins/ImportPlugin.class.php';
  17. /**
  18. * Handles the import for the [Name] format
  19. *
  20. * @package PhpMyAdmin-Import
  21. */
  22. class Import[Name] extends ImportPlugin
  23. {
  24. /**
  25. * optional - declare variables and descriptions
  26. *
  27. * @var type
  28. */
  29. private $_myOptionalVariable;
  30. /**
  31. * Constructor
  32. */
  33. public function __construct()
  34. {
  35. $this->setProperties();
  36. }
  37. /**
  38. * Sets the import plugin properties.
  39. * Called in the constructor.
  40. *
  41. * @return void
  42. */
  43. protected function setProperties()
  44. {
  45. // set properties
  46. $props = 'libraries/properties/';
  47. // include the main class for properties for the import plug-ins
  48. include_once "$props/plugins/ImportPluginProperties.class.php";
  49. // include the group properties classes
  50. include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
  51. include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
  52. // include the needed single property items
  53. include_once "$props/options/items/RadioPropertyItem.class.php";
  54. $importPluginProperties = new ImportPluginProperties();
  55. $importPluginProperties->setText('[name]'); // the name of your plug-in
  56. $importPluginProperties->setExtension('[ext]'); // extension this plug-in can handle
  57. $importPluginProperties->setOptionsText(__('Options'));
  58. // create the root group that will be the options field for
  59. // $importPluginProperties
  60. // this will be shown as "Format specific options"
  61. $importSpecificOptions = new OptionsPropertyRootGroup();
  62. $importSpecificOptions->setName("Format Specific Options");
  63. // general options main group
  64. $generalOptions = new OptionsPropertyMainGroup();
  65. $generalOptions->setName("general_opts");
  66. // optional :
  67. // create primary items and add them to the group
  68. // type - one of the classes listed in libraries/properties/options/items/
  69. // name - form element name
  70. // text - description in GUI
  71. // size - size of text element
  72. // len - maximal size of input
  73. // values - possible values of the item
  74. $leaf = new RadioPropertyItem();
  75. $leaf->setName("structure_or_data");
  76. $leaf->setValues(
  77. array(
  78. 'structure' => __('structure'),
  79. 'data' => __('data'),
  80. 'structure_and_data' => __('structure and data')
  81. )
  82. );
  83. $generalOptions->addProperty($leaf);
  84. // add the main group to the root group
  85. $importSpecificOptions->addProperty($generalOptions);
  86. // set the options for the import plugin property item
  87. $importPluginProperties->setOptions($importSpecificOptions);
  88. $this->properties = $importPluginProperties;
  89. }
  90. /**
  91. * This method is called when any PluginManager to which the observer
  92. * is attached calls PluginManager::notify()
  93. *
  94. * @param SplSubject $subject The PluginManager notifying the observer
  95. * of an update.
  96. *
  97. * @return void
  98. */
  99. public function update (SplSubject $subject)
  100. {
  101. }
  102. /**
  103. * Handles the whole import logic
  104. *
  105. * @return void
  106. */
  107. public function doImport()
  108. {
  109. // get globals (others are optional)
  110. global $error, $timeout_passed, $finished;
  111. $buffer = '';
  112. while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
  113. $data = PMA_importGetNextChunk();
  114. if ($data === false) {
  115. // subtract data we didn't handle yet and stop processing
  116. $GLOBALS['offset'] -= strlen($buffer);
  117. break;
  118. } elseif ($data === true) {
  119. // Handle rest of buffer
  120. } else {
  121. // Append new data to buffer
  122. $buffer .= $data;
  123. }
  124. // PARSE $buffer here, post sql queries using:
  125. PMA_importRunQuery($sql, $verbose_sql_with_comments);
  126. } // End of import loop
  127. // Commit any possible data in buffers
  128. PMA_importRunQuery();
  129. }
  130. // optional:
  131. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  132. /**
  133. * Getter description
  134. *
  135. * @return type
  136. */
  137. private function _getMyOptionalVariable()
  138. {
  139. return $this->_myOptionalVariable;
  140. }
  141. /**
  142. * Setter description
  143. *
  144. * @param type $my_optional_variable description
  145. *
  146. * @return void
  147. */
  148. private function _setMyOptionalVariable($my_optional_variable)
  149. {
  150. $this->_myOptionalVariable = $my_optional_variable;
  151. }
  152. }
  153. ?>