AbstractPatch.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\Core\Configuration\Addon\Update\Patch;
  3. use ModulesGarden\Servers\ZimbraEmail\Core\Helper\DatabaseHelper;
  4. use ModulesGarden\Servers\ZimbraEmail\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)
  40. ?false
  41. :true;
  42. }
  43. /**
  44. * @return bool
  45. */
  46. protected function runData()
  47. {
  48. return ($this->databaseHelper->performQueryFromFile($this->path . DS . $this->versionName . DS . 'data.sql') === true)
  49. ?false
  50. :true;
  51. }
  52. public function setVersion($version = null)
  53. {
  54. $this->version = $version;
  55. return $this;
  56. }
  57. public function getVersion()
  58. {
  59. return $this->version;
  60. }
  61. public function execute()
  62. {
  63. }
  64. }