01-plugin_updater.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace cx_newsletter;
  3. class plugin_updater
  4. extends plugin_worker
  5. implements plugin_worker_interface {
  6. public function update() : void {
  7. $init_settings = !(
  8. $this
  9. ->get_settings()
  10. ->is_initializated()
  11. );
  12. $init_database = !(
  13. $this
  14. ->get_versions()
  15. ->is_installed()
  16. );
  17. if ($init_settings or $init_database) {
  18. $this
  19. ->install();
  20. }
  21. $this
  22. ->get_installer()
  23. ->update();
  24. }
  25. public function install() : void {
  26. $this
  27. ->remove();
  28. $this
  29. ->get_settings()
  30. ->init();
  31. $this
  32. ->get_installer()
  33. ->init()
  34. ->update();
  35. }
  36. public function remove() : void {
  37. $this
  38. ->get_settings()
  39. ->clean();
  40. $this
  41. ->get_installer()
  42. ->clean();
  43. }
  44. private function get_installer() : database_installer {
  45. if ($this->installer !== null) {
  46. return $this->installer;
  47. }
  48. $this->installer = new database_installer(
  49. $this->get_database(),
  50. $this->get_tables(),
  51. $this->get_versions()
  52. );
  53. return $this->get_installer();
  54. }
  55. private ?database_installer $installer = null;
  56. }