ImportPlugin.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the import plugins
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Plugins;
  10. use PhpMyAdmin\Import;
  11. use PhpMyAdmin\Properties\Plugins\ImportPluginProperties;
  12. /**
  13. * Provides a common interface that will have to be implemented by all of the
  14. * import plugins.
  15. *
  16. * @package PhpMyAdmin
  17. */
  18. abstract class ImportPlugin
  19. {
  20. /**
  21. * ImportPluginProperties object containing the import plugin properties
  22. *
  23. * @var ImportPluginProperties
  24. */
  25. protected $properties;
  26. /**
  27. * @var Import
  28. */
  29. protected $import;
  30. /**
  31. * ImportPlugin constructor.
  32. */
  33. public function __construct()
  34. {
  35. $this->import = new Import();
  36. }
  37. /**
  38. * Handles the whole import logic
  39. *
  40. * @param array $sql_data 2-element array with sql data
  41. *
  42. * @return void
  43. */
  44. abstract public function doImport(array &$sql_data = []);
  45. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  46. /**
  47. * Gets the import specific format plugin properties
  48. *
  49. * @return ImportPluginProperties
  50. */
  51. public function getProperties()
  52. {
  53. return $this->properties;
  54. }
  55. /**
  56. * Sets the export plugins properties and is implemented by each import
  57. * plugin
  58. *
  59. * @return void
  60. */
  61. abstract protected function setProperties();
  62. /**
  63. * Define DB name and options
  64. *
  65. * @param string $currentDb DB
  66. * @param string $defaultDb Default DB name
  67. *
  68. * @return array DB name and options (an associative array of options)
  69. */
  70. protected function getDbnameAndOptions($currentDb, $defaultDb)
  71. {
  72. if (strlen((string) $currentDb) > 0) {
  73. $db_name = $currentDb;
  74. $options = ['create_db' => false];
  75. } else {
  76. $db_name = $defaultDb;
  77. $options = null;
  78. }
  79. return [
  80. $db_name,
  81. $options,
  82. ];
  83. }
  84. }