AbstractPatch.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\Configuration\Addon\Update\Patch;
  3. use ModulesGarden\ProxmoxAddon\Core\Helper\DatabaseHelper;
  4. use ModulesGarden\ProxmoxAddon\Core\ModuleConstants;
  5. /**
  6. * Description of AbstractPatch
  7. *
  8. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  9. */
  10. class AbstractPatch
  11. {
  12. /**
  13. * @var DatabaseHelper
  14. */
  15. protected $databaseHelper;
  16. /**
  17. * @var string
  18. */
  19. private $path;
  20. /**
  21. * @var string
  22. */
  23. private $versionName;
  24. protected $version;
  25. /**
  26. * @param DatabaseHelper $databaseHelper
  27. */
  28. public function __construct(DatabaseHelper $databaseHelper)
  29. {
  30. $this->databaseHelper = $databaseHelper;
  31. $this->path = ModuleConstants::getModuleRootDir() . DS . 'app' . DS . 'Database';
  32. $this->versionName = end(explode("\\", get_called_class()));
  33. }
  34. /**
  35. * @return bool
  36. */
  37. protected function runSchema()
  38. {
  39. return ($this->databaseHelper->performQueryFromFile($this->path . DS . $this->versionName . DS . 'schema.sql') === true) ? false : true;
  40. }
  41. /**
  42. * @return bool
  43. */
  44. protected function runData()
  45. {
  46. return ($this->databaseHelper->performQueryFromFile($this->path . DS . $this->versionName . DS . 'data.sql') === true) ? false : true;
  47. }
  48. public function setVersion($version = null)
  49. {
  50. $this->version = $version;
  51. return $this;
  52. }
  53. public function getVersion()
  54. {
  55. return $this->version;
  56. }
  57. public function execute()
  58. {
  59. }
  60. }