upgrade-functions.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 checkForConfigKeyAddToArray($keys)
  79. {
  80. $updateItems = [];
  81. foreach ($keys as $new => $old) {
  82. if (isset($this->config[$old])) {
  83. if ($this->config[$old] !== '') {
  84. $updateItemsNew = [$new => $this->config[$old]];
  85. $updateItems = array_merge($updateItems, $updateItemsNew);
  86. }
  87. }
  88. }
  89. return $updateItems;
  90. }
  91. public function removeOldCustomHTML()
  92. {
  93. $backup = $this->backupOrganizr();
  94. if ($backup) {
  95. $keys = [
  96. 'homepageCustomHTML01Enabled' => 'homepageCustomHTMLoneEnabled',
  97. 'homepageCustomHTML01Auth' => 'homepageCustomHTMLoneAuth',
  98. 'customHTML01' => 'customHTMLone',
  99. 'homepageCustomHTML02Enabled' => 'homepageCustomHTMLtwoEnabled',
  100. 'homepageCustomHTML02Auth' => 'homepageCustomHTMLtwoAuth',
  101. 'customHTML02' => 'customHTMLtwo',
  102. ];
  103. $updateItems = $this->checkForConfigKeyAddToArray($keys);
  104. $updateComplete = false;
  105. if (!empty($updateItems)) {
  106. $updateComplete = $this->updateConfig($updateItems);
  107. }
  108. if ($updateComplete) {
  109. $removeConfigItems = $this->removeConfigItem(['homepagCustomHTMLoneAuth', 'homepagCustomHTMLoneEnabled', 'homepagCustomHTMLtwoAuth', 'homepagCustomHTMLtwoEnabled', 'homepageOrdercustomhtml', 'homepageOrdercustomhtmlTwo', 'homepageCustomHTMLoneEnabled', 'homepageCustomHTMLoneAuth', 'customHTMLone', 'homepageCustomHTMLtwoEnabled', 'homepageCustomHTMLtwoAuth', 'customHTMLtwo']);
  110. if ($removeConfigItems) {
  111. return true;
  112. }
  113. }
  114. }
  115. return false;
  116. }
  117. }