upgrade-functions.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. default:
  13. $this->setAPIResponse('success', 'Ran update function for version: ' . $version, 200);
  14. return true;
  15. }
  16. }
  17. public function upgradeSettingsTabURL()
  18. {
  19. $response = [
  20. array(
  21. 'function' => 'query',
  22. 'query' => array(
  23. 'UPDATE tabs SET',
  24. ['url' => 'api/v2/page/settings'],
  25. 'WHERE url = ?',
  26. 'api/?v1/settings/page'
  27. )
  28. ),
  29. ];
  30. return $this->processQueries($response);
  31. }
  32. public function upgradeHomepageTabURL()
  33. {
  34. $response = [
  35. array(
  36. 'function' => 'query',
  37. 'query' => array(
  38. 'UPDATE tabs SET',
  39. ['url' => 'api/v2/page/homepage'],
  40. 'WHERE url = ?',
  41. 'api/?v1/homepage/page'
  42. )
  43. ),
  44. ];
  45. return $this->processQueries($response);
  46. }
  47. public function removeOldPluginDirectoriesAndFiles()
  48. {
  49. $folders = [
  50. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'api',
  51. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'config',
  52. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css',
  53. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'js',
  54. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'misc',
  55. ];
  56. $files = [
  57. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'bookmark.php',
  58. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'chat.php',
  59. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'healthChecks.php',
  60. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'invites.php',
  61. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'php-mailer.php',
  62. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'speedTest.php',
  63. ];
  64. foreach ($files as $file) {
  65. if (file_exists($file)) {
  66. @unlink($file);
  67. }
  68. }
  69. foreach ($folders as $folder) {
  70. if (file_exists($folder)) {
  71. @$this->rrmdir($folder);
  72. }
  73. }
  74. return true;
  75. }
  76. }