upgrade-functions.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. trait UpgradeFunctions
  3. {
  4. public function upgradeToVersion($version = '2.1.0')
  5. {
  6. switch ($version) {
  7. case '2.1.0':
  8. $this->upgradeSettingsTabURL();
  9. $this->upgradeHomepageTabURL();
  10. case '2.1.400':
  11. $this->removeOldPluginDirectoriesAndFiles();
  12. case '2.1.525':
  13. $this->removeOldCustomHTML();
  14. default:
  15. $this->setAPIResponse('success', 'Ran update function for version: ' . $version, 200);
  16. return true;
  17. }
  18. }
  19. public function upgradeSettingsTabURL()
  20. {
  21. $response = [
  22. array(
  23. 'function' => 'query',
  24. 'query' => array(
  25. 'UPDATE tabs SET',
  26. ['url' => 'api/v2/page/settings'],
  27. 'WHERE url = ?',
  28. 'api/?v1/settings/page'
  29. )
  30. ),
  31. ];
  32. return $this->processQueries($response);
  33. }
  34. public function upgradeHomepageTabURL()
  35. {
  36. $response = [
  37. array(
  38. 'function' => 'query',
  39. 'query' => array(
  40. 'UPDATE tabs SET',
  41. ['url' => 'api/v2/page/homepage'],
  42. 'WHERE url = ?',
  43. 'api/?v1/homepage/page'
  44. )
  45. ),
  46. ];
  47. return $this->processQueries($response);
  48. }
  49. public function removeOldPluginDirectoriesAndFiles()
  50. {
  51. $folders = [
  52. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'api',
  53. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'config',
  54. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css',
  55. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'js',
  56. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'misc',
  57. ];
  58. $files = [
  59. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'bookmark.php',
  60. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'chat.php',
  61. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'healthChecks.php',
  62. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'invites.php',
  63. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'php-mailer.php',
  64. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'speedTest.php',
  65. ];
  66. foreach ($files as $file) {
  67. if (file_exists($file)) {
  68. @unlink($file);
  69. }
  70. }
  71. foreach ($folders as $folder) {
  72. if (file_exists($folder)) {
  73. @$this->rrmdir($folder);
  74. }
  75. }
  76. return true;
  77. }
  78. public function removeOldCustomHTML()
  79. {
  80. $updateItems = [];
  81. if ($this->config['homepageCustomHTMLoneEnabled']) {
  82. if ($this->config['homepageCustomHTMLoneEnabled'] !== '') {
  83. $updateItemsNew = ['homepageCustomHTML01Enabled' => $this->config['homepageCustomHTMLoneEnabled']];
  84. $updateItems = array_merge($updateItems, $updateItemsNew);
  85. }
  86. }
  87. if ($this->config['homepageCustomHTMLoneAuth']) {
  88. if ($this->config['homepageCustomHTMLoneAuth'] !== '') {
  89. $updateItemsNew = ['homepageCustomHTML01Auth' => $this->config['homepageCustomHTMLoneAuth']];
  90. $updateItems = array_merge($updateItems, $updateItemsNew);
  91. }
  92. }
  93. if ($this->config['customHTMLone']) {
  94. if ($this->config['customHTMLone'] !== '') {
  95. $updateItemsNew = ['customHTML01' => $this->config['customHTMLone']];
  96. $updateItems = array_merge($updateItems, $updateItemsNew);
  97. }
  98. }
  99. if ($this->config['homepageCustomHTMLtwoEnabled']) {
  100. if ($this->config['homepageCustomHTMLtwoEnabled'] !== '') {
  101. $updateItemsNew = ['homepageCustomHTML02Enabled' => $this->config['homepageCustomHTMLtwoEnabled']];
  102. $updateItems = array_merge($updateItems, $updateItemsNew);
  103. }
  104. }
  105. if ($this->config['homepageCustomHTMLtwoAuth']) {
  106. if ($this->config['homepageCustomHTMLtwoAuth'] !== '') {
  107. $updateItemsNew = ['homepageCustomHTML02Auth' => $this->config['homepageCustomHTMLtwoAuth']];
  108. $updateItems = array_merge($updateItems, $updateItemsNew);
  109. }
  110. }
  111. if ($this->config['customHTMLtwo']) {
  112. if ($this->config['customHTMLtwo'] !== '') {
  113. $updateItemsNew = ['customHTML02' => $this->config['customHTMLtwo']];
  114. $updateItems = array_merge($updateItems, $updateItemsNew);
  115. }
  116. }
  117. if (!empty($updateItems)) {
  118. $this->updateConfig($updateItems);
  119. }
  120. $this->removeConfigItem(['homepageOrdercustomhtml', 'homepageOrdercustomhtmlTwo', 'homepageCustomHTMLoneEnabled', 'homepageCustomHTMLoneAuth', 'customHTMLone', 'homepageCustomHTMLtwoEnabled', 'homepageCustomHTMLtwoAuth', 'customHTMLtwo']);
  121. return true;
  122. }
  123. }