update.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="update",
  5. * description="Organizr Update"
  6. * )
  7. */
  8. $app->get('/update', function ($request, $response, $args) {
  9. /**
  10. * @OA\Get(
  11. * security={{ "api_key":{} }},
  12. * tags={"update"},
  13. * path="/api/v2/update",
  14. * summary="Update Organizr install using update script",
  15. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  16. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  17. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  18. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  19. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  20. * )
  21. */
  22. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  23. if ($Organizr->qualifyRequest(1, true)) {
  24. $Organizr->updateOrganizr();
  25. }
  26. $response->getBody()->write(jsonE($GLOBALS['api']));
  27. return $response
  28. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  29. ->withStatus($GLOBALS['responseCode']);
  30. });
  31. $app->get('/update/download/{branch}', function ($request, $response, $args) {
  32. /**
  33. * @OA\Get(
  34. * security={{ "api_key":{} }},
  35. * tags={"update"},
  36. * path="/api/v2/update/download/{branch}",
  37. * summary="Download Organizr Update Files",
  38. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  39. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  40. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  41. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  42. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  43. * )
  44. */
  45. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  46. if ($Organizr->qualifyRequest(1, true)) {
  47. $Organizr->upgradeInstall($args['branch'], '1');
  48. }
  49. $response->getBody()->write(jsonE($GLOBALS['api']));
  50. return $response
  51. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  52. ->withStatus($GLOBALS['responseCode']);
  53. });
  54. $app->get('/update/unzip/{branch}', function ($request, $response, $args) {
  55. /**
  56. * @OA\Get(
  57. * security={{ "api_key":{} }},
  58. * tags={"update"},
  59. * path="/api/v2/update/unzip/{branch}",
  60. * summary="Unzip Organizr Update Files",
  61. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  62. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  63. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  64. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  65. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  66. * )
  67. */
  68. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  69. if ($Organizr->qualifyRequest(1, true)) {
  70. $Organizr->upgradeInstall($args['branch'], '2');
  71. }
  72. $response->getBody()->write(jsonE($GLOBALS['api']));
  73. return $response
  74. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  75. ->withStatus($GLOBALS['responseCode']);
  76. });
  77. $app->get('/update/move/{branch}', function ($request, $response, $args) {
  78. /**
  79. * @OA\Get(
  80. * security={{ "api_key":{} }},
  81. * tags={"update"},
  82. * path="/api/v2/update/move/{branch}",
  83. * summary="Move Organizr Update Files",
  84. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  85. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  86. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  87. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  88. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  89. * )
  90. */
  91. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  92. if ($Organizr->qualifyRequest(1, true)) {
  93. $Organizr->upgradeInstall($args['branch'], '3');
  94. }
  95. $response->getBody()->write(jsonE($GLOBALS['api']));
  96. return $response
  97. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  98. ->withStatus($GLOBALS['responseCode']);
  99. });
  100. $app->get('/update/cleanup/{branch}', function ($request, $response, $args) {
  101. /**
  102. * @OA\Get(
  103. * security={{ "api_key":{} }},
  104. * tags={"update"},
  105. * path="/api/v2/update/cleanup/{branch}",
  106. * summary="Cleanup Organizr Update Files",
  107. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  108. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  109. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  110. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  111. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  112. * )
  113. */
  114. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  115. if ($Organizr->qualifyRequest(1, true)) {
  116. $Organizr->upgradeInstall($args['branch'], '4');
  117. }
  118. $response->getBody()->write(jsonE($GLOBALS['api']));
  119. return $response
  120. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  121. ->withStatus($GLOBALS['responseCode']);
  122. });
  123. $app->get('/update/docker', function ($request, $response, $args) {
  124. /**
  125. * @OA\Get(
  126. * security={{ "api_key":{} }},
  127. * tags={"update"},
  128. * path="/api/v2/update/docker",
  129. * summary="Update Organizr install using Docker Container script",
  130. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  131. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  132. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  133. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  134. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  135. * )
  136. */
  137. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  138. if ($Organizr->qualifyRequest(1, true)) {
  139. $Organizr->dockerUpdate();
  140. }
  141. $response->getBody()->write(jsonE($GLOBALS['api']));
  142. return $response
  143. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  144. ->withStatus($GLOBALS['responseCode']);
  145. });
  146. $app->get('/update/windows', function ($request, $response, $args) {
  147. /**
  148. * @OA\Get(
  149. * security={{ "api_key":{} }},
  150. * tags={"update"},
  151. * path="/api/v2/update/windows",
  152. * summary="Update Organizr install using Windows script",
  153. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  154. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  155. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  156. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  157. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  158. * )
  159. */
  160. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  161. if ($Organizr->qualifyRequest(1, true)) {
  162. $Organizr->windowsUpdate();
  163. }
  164. $response->getBody()->write(jsonE($GLOBALS['api']));
  165. return $response
  166. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  167. ->withStatus($GLOBALS['responseCode']);
  168. });
  169. $app->get('/update/linux', function ($request, $response, $args) {
  170. /**
  171. * @OA\Get(
  172. * security={{ "api_key":{} }},
  173. * tags={"update"},
  174. * path="/api/v2/update/linux",
  175. * summary="Update Organizr install using Linux script",
  176. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  177. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  178. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  179. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  180. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  181. * )
  182. */
  183. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  184. if ($Organizr->qualifyRequest(1, true)) {
  185. $Organizr->linuxUpdate();
  186. }
  187. $response->getBody()->write(jsonE($GLOBALS['api']));
  188. return $response
  189. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  190. ->withStatus($GLOBALS['responseCode']);
  191. });
  192. $app->get('/update/migrate/{version}', function ($request, $response, $args) {
  193. /**
  194. * @OA\Get(
  195. * security={{ "api_key":{} }},
  196. * tags={"update"},
  197. * path="/api/v2/update/migrate/{version}",
  198. * summary="Run Organizr Version Mirgation for specific version",
  199. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  200. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  201. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  202. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  203. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  204. * )
  205. */
  206. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  207. if ($Organizr->qualifyRequest(1, true)) {
  208. $Organizr->upgradeToVersion($args['version']);
  209. }
  210. $response->getBody()->write(jsonE($GLOBALS['api']));
  211. return $response
  212. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  213. ->withStatus($GLOBALS['responseCode']);
  214. });
  215. $app->get('/update/reset/{feature}', function ($request, $response, $args) {
  216. /**
  217. * @OA\Get(
  218. * security={{ "api_key":{} }},
  219. * tags={"update"},
  220. * path="/api/v2/update/reset/{feature}",
  221. * summary="Reset an Organizr feature back to default values",
  222. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  223. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  224. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  225. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  226. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  227. * )
  228. */
  229. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  230. if ($Organizr->qualifyRequest(1, true)) {
  231. $Organizr->resetUpdateFeature($args['feature']);
  232. }
  233. $response->getBody()->write(jsonE($GLOBALS['api']));
  234. return $response
  235. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  236. ->withStatus($GLOBALS['responseCode']);
  237. });