@@ -16,228 +16,228 @@ |
||
16 | 16 | |
17 | 17 | class Version |
18 | 18 | { |
19 | - /** |
|
20 | - * @var EntityManagerInterface |
|
21 | - */ |
|
22 | - private $em; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var HttpClientInterface |
|
26 | - */ |
|
27 | - private $client; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var ParameterBagInterface |
|
31 | - */ |
|
32 | - private $parameter; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var PackagistApi |
|
36 | - */ |
|
37 | - private $packagist; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var mixed |
|
41 | - */ |
|
42 | - private $local_token; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var Package |
|
46 | - */ |
|
47 | - private $package; |
|
48 | - |
|
49 | - private $messages = []; |
|
50 | - |
|
51 | - /** |
|
52 | - * Version constructor. |
|
53 | - * @param EntityManagerInterface $em |
|
54 | - * @param HttpClientInterface $client |
|
55 | - * @param ParameterBagInterface $parameter |
|
56 | - * @param PackagistApi $packagist |
|
57 | - */ |
|
58 | - public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter, PackagistApi $packagist) |
|
59 | - { |
|
60 | - $this->em = $em; |
|
61 | - $this->client = $client; |
|
62 | - $this->parameter = $parameter; |
|
63 | - $this->packagist = $packagist; |
|
64 | - $this->local_token = $parameter->get("ribs_admin.packages_token"); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function getMessages(): array |
|
71 | - { |
|
72 | - return $this->messages; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param Package $package |
|
77 | - */ |
|
78 | - public function setPackageEntity(Package $package) |
|
79 | - { |
|
80 | - $this->package = $package; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return mixed|null |
|
85 | - * @throws ClientExceptionInterface |
|
86 | - * @throws RedirectionExceptionInterface |
|
87 | - * @throws ServerExceptionInterface |
|
88 | - * @throws TransportExceptionInterface |
|
89 | - */ |
|
90 | - private function getToken() |
|
91 | - { |
|
92 | - $token = null; |
|
93 | - $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/dist/send-token/"); |
|
94 | - $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
95 | - |
|
96 | - if ($datas) { |
|
97 | - $token = json_decode($datas, true)["token"]; |
|
98 | - } |
|
99 | - |
|
100 | - return $token; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @return mixed|null |
|
105 | - * @throws ClientExceptionInterface |
|
106 | - * @throws RedirectionExceptionInterface |
|
107 | - * @throws ServerExceptionInterface |
|
108 | - * @throws TransportExceptionInterface |
|
109 | - */ |
|
110 | - private function getComposerLockJson() |
|
111 | - { |
|
112 | - if ($this->package && !$this->package->isIsLocal()) { |
|
113 | - $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
114 | - $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
115 | - } else { |
|
116 | - $composer_lock = file_get_contents('../composer.lock'); |
|
117 | - } |
|
118 | - |
|
119 | - if ($composer_lock) { |
|
120 | - return json_decode($composer_lock, true); |
|
121 | - } |
|
122 | - |
|
123 | - return null; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return mixed|null |
|
128 | - * @throws ClientExceptionInterface |
|
129 | - * @throws RedirectionExceptionInterface |
|
130 | - * @throws ServerExceptionInterface |
|
131 | - * @throws TransportExceptionInterface |
|
132 | - */ |
|
133 | - public function getPackage() |
|
134 | - { |
|
135 | - $composer_lock = $this->getComposerLockJson(); |
|
136 | - if ($composer_lock) { |
|
137 | - $packages = $composer_lock["packages"]; |
|
138 | - $key = array_search($this->package->getPackageName(), array_column($packages, 'name')); |
|
139 | - |
|
140 | - if ($key) { |
|
141 | - return $packages[$key]; |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - $this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl(); |
|
146 | - |
|
147 | - return null; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return mixed|null |
|
152 | - * @throws ClientExceptionInterface |
|
153 | - * @throws RedirectionExceptionInterface |
|
154 | - * @throws ServerExceptionInterface |
|
155 | - * @throws TransportExceptionInterface |
|
156 | - */ |
|
157 | - public function getVersion() |
|
158 | - { |
|
159 | - return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @return DateTime|null |
|
164 | - * @throws Exception |
|
165 | - */ |
|
166 | - public function getVersionDate(): ?DateTime |
|
167 | - { |
|
168 | - $string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null; |
|
169 | - $version_date = null; |
|
170 | - |
|
171 | - if ($string_date) { |
|
172 | - $version_date = new DateTime($string_date); |
|
173 | - } |
|
174 | - |
|
175 | - return $version_date; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @param string $guid |
|
180 | - * @param string $version |
|
181 | - * @return string|void|null |
|
182 | - * @throws ClientExceptionInterface |
|
183 | - * @throws RedirectionExceptionInterface |
|
184 | - * @throws ServerExceptionInterface |
|
185 | - * @throws TransportExceptionInterface |
|
186 | - */ |
|
187 | - public function updatePackage(string $guid, string $version) |
|
188 | - { |
|
189 | - $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
190 | - |
|
191 | - if ($package) { |
|
192 | - $this->setPackageEntity($package); |
|
193 | - |
|
194 | - if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
195 | - $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
196 | - return; |
|
197 | - } |
|
198 | - |
|
199 | - $form_data = new FormDataPart([ |
|
200 | - "package_name" => $package->getPackageName(), |
|
201 | - "version" => $version, |
|
202 | - ]); |
|
203 | - |
|
204 | - $response = $this->client->request("POST", $this->package->getProjectUrl().'ribs-admin/packages/dist/change-version/', [ |
|
205 | - "headers" => $form_data->getPreparedHeaders()->toArray(), |
|
206 | - "body" => $form_data->bodyToIterable() |
|
207 | - ]); |
|
208 | - |
|
209 | - $this->save($guid); |
|
210 | - |
|
211 | - return $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @param string $package_guid |
|
217 | - * @throws ClientExceptionInterface |
|
218 | - * @throws RedirectionExceptionInterface |
|
219 | - * @throws ServerExceptionInterface |
|
220 | - * @throws TransportExceptionInterface |
|
221 | - */ |
|
222 | - public function save(string $package_guid) |
|
223 | - { |
|
224 | - $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]); |
|
225 | - |
|
226 | - if ($package) { |
|
227 | - $this->setPackageEntity($package); |
|
228 | - |
|
229 | - if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
230 | - $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
231 | - return; |
|
232 | - } |
|
233 | - |
|
234 | - $package->setVersion($this->getVersion()); |
|
235 | - $package->setVersionDate($this->getVersionDate()); |
|
236 | - $package->setLastPackagistVersion($this->packagist->getLastPackagistVersion($package->getPackageName())); |
|
237 | - $package->setLastCheck(new DateTime()); |
|
238 | - |
|
239 | - $this->em->persist($package); |
|
240 | - $this->em->flush(); |
|
241 | - } |
|
242 | - } |
|
19 | + /** |
|
20 | + * @var EntityManagerInterface |
|
21 | + */ |
|
22 | + private $em; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var HttpClientInterface |
|
26 | + */ |
|
27 | + private $client; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var ParameterBagInterface |
|
31 | + */ |
|
32 | + private $parameter; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var PackagistApi |
|
36 | + */ |
|
37 | + private $packagist; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var mixed |
|
41 | + */ |
|
42 | + private $local_token; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var Package |
|
46 | + */ |
|
47 | + private $package; |
|
48 | + |
|
49 | + private $messages = []; |
|
50 | + |
|
51 | + /** |
|
52 | + * Version constructor. |
|
53 | + * @param EntityManagerInterface $em |
|
54 | + * @param HttpClientInterface $client |
|
55 | + * @param ParameterBagInterface $parameter |
|
56 | + * @param PackagistApi $packagist |
|
57 | + */ |
|
58 | + public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter, PackagistApi $packagist) |
|
59 | + { |
|
60 | + $this->em = $em; |
|
61 | + $this->client = $client; |
|
62 | + $this->parameter = $parameter; |
|
63 | + $this->packagist = $packagist; |
|
64 | + $this->local_token = $parameter->get("ribs_admin.packages_token"); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function getMessages(): array |
|
71 | + { |
|
72 | + return $this->messages; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param Package $package |
|
77 | + */ |
|
78 | + public function setPackageEntity(Package $package) |
|
79 | + { |
|
80 | + $this->package = $package; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return mixed|null |
|
85 | + * @throws ClientExceptionInterface |
|
86 | + * @throws RedirectionExceptionInterface |
|
87 | + * @throws ServerExceptionInterface |
|
88 | + * @throws TransportExceptionInterface |
|
89 | + */ |
|
90 | + private function getToken() |
|
91 | + { |
|
92 | + $token = null; |
|
93 | + $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/dist/send-token/"); |
|
94 | + $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
95 | + |
|
96 | + if ($datas) { |
|
97 | + $token = json_decode($datas, true)["token"]; |
|
98 | + } |
|
99 | + |
|
100 | + return $token; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @return mixed|null |
|
105 | + * @throws ClientExceptionInterface |
|
106 | + * @throws RedirectionExceptionInterface |
|
107 | + * @throws ServerExceptionInterface |
|
108 | + * @throws TransportExceptionInterface |
|
109 | + */ |
|
110 | + private function getComposerLockJson() |
|
111 | + { |
|
112 | + if ($this->package && !$this->package->isIsLocal()) { |
|
113 | + $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
114 | + $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
115 | + } else { |
|
116 | + $composer_lock = file_get_contents('../composer.lock'); |
|
117 | + } |
|
118 | + |
|
119 | + if ($composer_lock) { |
|
120 | + return json_decode($composer_lock, true); |
|
121 | + } |
|
122 | + |
|
123 | + return null; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return mixed|null |
|
128 | + * @throws ClientExceptionInterface |
|
129 | + * @throws RedirectionExceptionInterface |
|
130 | + * @throws ServerExceptionInterface |
|
131 | + * @throws TransportExceptionInterface |
|
132 | + */ |
|
133 | + public function getPackage() |
|
134 | + { |
|
135 | + $composer_lock = $this->getComposerLockJson(); |
|
136 | + if ($composer_lock) { |
|
137 | + $packages = $composer_lock["packages"]; |
|
138 | + $key = array_search($this->package->getPackageName(), array_column($packages, 'name')); |
|
139 | + |
|
140 | + if ($key) { |
|
141 | + return $packages[$key]; |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + $this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl(); |
|
146 | + |
|
147 | + return null; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return mixed|null |
|
152 | + * @throws ClientExceptionInterface |
|
153 | + * @throws RedirectionExceptionInterface |
|
154 | + * @throws ServerExceptionInterface |
|
155 | + * @throws TransportExceptionInterface |
|
156 | + */ |
|
157 | + public function getVersion() |
|
158 | + { |
|
159 | + return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @return DateTime|null |
|
164 | + * @throws Exception |
|
165 | + */ |
|
166 | + public function getVersionDate(): ?DateTime |
|
167 | + { |
|
168 | + $string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null; |
|
169 | + $version_date = null; |
|
170 | + |
|
171 | + if ($string_date) { |
|
172 | + $version_date = new DateTime($string_date); |
|
173 | + } |
|
174 | + |
|
175 | + return $version_date; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @param string $guid |
|
180 | + * @param string $version |
|
181 | + * @return string|void|null |
|
182 | + * @throws ClientExceptionInterface |
|
183 | + * @throws RedirectionExceptionInterface |
|
184 | + * @throws ServerExceptionInterface |
|
185 | + * @throws TransportExceptionInterface |
|
186 | + */ |
|
187 | + public function updatePackage(string $guid, string $version) |
|
188 | + { |
|
189 | + $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
190 | + |
|
191 | + if ($package) { |
|
192 | + $this->setPackageEntity($package); |
|
193 | + |
|
194 | + if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
195 | + $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
196 | + return; |
|
197 | + } |
|
198 | + |
|
199 | + $form_data = new FormDataPart([ |
|
200 | + "package_name" => $package->getPackageName(), |
|
201 | + "version" => $version, |
|
202 | + ]); |
|
203 | + |
|
204 | + $response = $this->client->request("POST", $this->package->getProjectUrl().'ribs-admin/packages/dist/change-version/', [ |
|
205 | + "headers" => $form_data->getPreparedHeaders()->toArray(), |
|
206 | + "body" => $form_data->bodyToIterable() |
|
207 | + ]); |
|
208 | + |
|
209 | + $this->save($guid); |
|
210 | + |
|
211 | + return $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @param string $package_guid |
|
217 | + * @throws ClientExceptionInterface |
|
218 | + * @throws RedirectionExceptionInterface |
|
219 | + * @throws ServerExceptionInterface |
|
220 | + * @throws TransportExceptionInterface |
|
221 | + */ |
|
222 | + public function save(string $package_guid) |
|
223 | + { |
|
224 | + $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]); |
|
225 | + |
|
226 | + if ($package) { |
|
227 | + $this->setPackageEntity($package); |
|
228 | + |
|
229 | + if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
230 | + $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
231 | + return; |
|
232 | + } |
|
233 | + |
|
234 | + $package->setVersion($this->getVersion()); |
|
235 | + $package->setVersionDate($this->getVersionDate()); |
|
236 | + $package->setLastPackagistVersion($this->packagist->getLastPackagistVersion($package->getPackageName())); |
|
237 | + $package->setLastCheck(new DateTime()); |
|
238 | + |
|
239 | + $this->em->persist($package); |
|
240 | + $this->em->flush(); |
|
241 | + } |
|
242 | + } |
|
243 | 243 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | private function getToken() |
91 | 91 | { |
92 | 92 | $token = null; |
93 | - $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/dist/send-token/"); |
|
93 | + $response = $this->client->request("GET", $this->package->getProjectUrl() . "ribs-admin/packages/dist/send-token/"); |
|
94 | 94 | $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
95 | 95 | |
96 | 96 | if ($datas) { |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | private function getComposerLockJson() |
111 | 111 | { |
112 | 112 | if ($this->package && !$this->package->isIsLocal()) { |
113 | - $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
113 | + $response = $this->client->request("GET", $this->package->getProjectUrl() . $this->package->getComposerLockUrl()); |
|
114 | 114 | $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
115 | 115 | } else { |
116 | 116 | $composer_lock = file_get_contents('../composer.lock'); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | "version" => $version, |
202 | 202 | ]); |
203 | 203 | |
204 | - $response = $this->client->request("POST", $this->package->getProjectUrl().'ribs-admin/packages/dist/change-version/', [ |
|
204 | + $response = $this->client->request("POST", $this->package->getProjectUrl() . 'ribs-admin/packages/dist/change-version/', [ |
|
205 | 205 | "headers" => $form_data->getPreparedHeaders()->toArray(), |
206 | 206 | "body" => $form_data->bodyToIterable() |
207 | 207 | ]); |
@@ -21,111 +21,111 @@ |
||
21 | 21 | |
22 | 22 | class PackagesDistController extends AbstractController |
23 | 23 | { |
24 | - /** |
|
25 | - * @Route("/packages/dist/send-package/{package_name}", name="ribsadmin_packages_dist_send", requirements={"package_name"=".+"}) |
|
26 | - * @param EntityManagerInterface $em |
|
27 | - * @param Version $version |
|
28 | - * @param string $package_name |
|
29 | - * @return mixed|null |
|
30 | - * @throws Exception |
|
31 | - */ |
|
32 | - public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
33 | - { |
|
34 | - $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
35 | - |
|
36 | - if ($package) { |
|
37 | - $version->setPackageEntity($package); |
|
38 | - } |
|
39 | - |
|
40 | - return new JsonResponse([ |
|
41 | - "package" => $version->getPackage(), |
|
42 | - "package_date" => $version->getVersionDate() |
|
43 | - ]); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @Route("/packages/dist/send-composer-lock/", name="ribsadmin_packages_dist_send_composer_lock") |
|
48 | - * @return JsonResponse |
|
49 | - */ |
|
50 | - public function sendComposerJson(): JsonResponse |
|
51 | - { |
|
52 | - $composer_lock = file_get_contents('../composer.lock'); |
|
53 | - |
|
54 | - if ($composer_lock) { |
|
55 | - $composer_lock = json_decode($composer_lock); |
|
56 | - } |
|
57 | - |
|
58 | - return new JsonResponse($composer_lock); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @Route("/packages/dist/send-token/", name="ribsadmin_packages_dist_send_token") |
|
63 | - * @param ParameterBagInterface $parameter |
|
64 | - * @return JsonResponse |
|
65 | - */ |
|
66 | - public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
67 | - { |
|
68 | - return new JsonResponse([ |
|
69 | - "token" => $parameter->get("ribs_admin.packages_token") |
|
70 | - ]); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param $file |
|
75 | - * @param $folder |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - private function uploadConfigFile($file, $folder) |
|
79 | - { |
|
80 | - $success = true; |
|
81 | - if ($file) { |
|
82 | - try { |
|
83 | - $file->move('../config/'.$folder, $file->getClientOriginalName()); |
|
84 | - } catch (FileException $exception) { |
|
85 | - $success = false; |
|
86 | - } |
|
87 | - } |
|
88 | - return $success; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @Route("/packages/dist/change-version/", name="ribsadmin_packages_dist_change_version", requirements={"package_name"=".+"}, methods={"POST"}) |
|
93 | - * @param KernelInterface $kernel |
|
94 | - * @param Request $request |
|
95 | - * @return JsonResponse |
|
96 | - * @throws Exception |
|
97 | - */ |
|
98 | - public function changePackageVersion(KernelInterface $kernel, Request $request): JsonResponse |
|
99 | - { |
|
100 | - $application = new Application($kernel); |
|
101 | - $application->setAutoExit(false); |
|
102 | - |
|
103 | - $package_name = $request->get("package_name"); |
|
104 | - $version = $request->get("version"); |
|
105 | - |
|
106 | - if (!$this->uploadConfigFile($request->files->get('package_routes'), "routes")) { |
|
107 | - return new JsonResponse([ |
|
108 | - "error_message" => "Routes file move is impossible" |
|
109 | - ]); |
|
110 | - } |
|
111 | - |
|
112 | - if (!$this->uploadConfigFile($request->files->get('package_config'), "packages")) { |
|
113 | - return new JsonResponse([ |
|
114 | - "error_message" => "Package file move is impossible" |
|
115 | - ]); |
|
116 | - } |
|
117 | - |
|
118 | - $input = new ArrayInput([ |
|
119 | - 'command' => 'ribsadmin:change-package-version', |
|
120 | - 'package-name' => $package_name.":".$version, |
|
121 | - ]); |
|
122 | - |
|
123 | - $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); |
|
124 | - $application->run($input, $output); |
|
125 | - |
|
126 | - $converter = new AnsiToHtmlConverter(); |
|
127 | - $content = $output->fetch(); |
|
128 | - |
|
129 | - return new JsonResponse($converter->convert($content)); |
|
130 | - } |
|
24 | + /** |
|
25 | + * @Route("/packages/dist/send-package/{package_name}", name="ribsadmin_packages_dist_send", requirements={"package_name"=".+"}) |
|
26 | + * @param EntityManagerInterface $em |
|
27 | + * @param Version $version |
|
28 | + * @param string $package_name |
|
29 | + * @return mixed|null |
|
30 | + * @throws Exception |
|
31 | + */ |
|
32 | + public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
33 | + { |
|
34 | + $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
35 | + |
|
36 | + if ($package) { |
|
37 | + $version->setPackageEntity($package); |
|
38 | + } |
|
39 | + |
|
40 | + return new JsonResponse([ |
|
41 | + "package" => $version->getPackage(), |
|
42 | + "package_date" => $version->getVersionDate() |
|
43 | + ]); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @Route("/packages/dist/send-composer-lock/", name="ribsadmin_packages_dist_send_composer_lock") |
|
48 | + * @return JsonResponse |
|
49 | + */ |
|
50 | + public function sendComposerJson(): JsonResponse |
|
51 | + { |
|
52 | + $composer_lock = file_get_contents('../composer.lock'); |
|
53 | + |
|
54 | + if ($composer_lock) { |
|
55 | + $composer_lock = json_decode($composer_lock); |
|
56 | + } |
|
57 | + |
|
58 | + return new JsonResponse($composer_lock); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @Route("/packages/dist/send-token/", name="ribsadmin_packages_dist_send_token") |
|
63 | + * @param ParameterBagInterface $parameter |
|
64 | + * @return JsonResponse |
|
65 | + */ |
|
66 | + public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
67 | + { |
|
68 | + return new JsonResponse([ |
|
69 | + "token" => $parameter->get("ribs_admin.packages_token") |
|
70 | + ]); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param $file |
|
75 | + * @param $folder |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + private function uploadConfigFile($file, $folder) |
|
79 | + { |
|
80 | + $success = true; |
|
81 | + if ($file) { |
|
82 | + try { |
|
83 | + $file->move('../config/'.$folder, $file->getClientOriginalName()); |
|
84 | + } catch (FileException $exception) { |
|
85 | + $success = false; |
|
86 | + } |
|
87 | + } |
|
88 | + return $success; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @Route("/packages/dist/change-version/", name="ribsadmin_packages_dist_change_version", requirements={"package_name"=".+"}, methods={"POST"}) |
|
93 | + * @param KernelInterface $kernel |
|
94 | + * @param Request $request |
|
95 | + * @return JsonResponse |
|
96 | + * @throws Exception |
|
97 | + */ |
|
98 | + public function changePackageVersion(KernelInterface $kernel, Request $request): JsonResponse |
|
99 | + { |
|
100 | + $application = new Application($kernel); |
|
101 | + $application->setAutoExit(false); |
|
102 | + |
|
103 | + $package_name = $request->get("package_name"); |
|
104 | + $version = $request->get("version"); |
|
105 | + |
|
106 | + if (!$this->uploadConfigFile($request->files->get('package_routes'), "routes")) { |
|
107 | + return new JsonResponse([ |
|
108 | + "error_message" => "Routes file move is impossible" |
|
109 | + ]); |
|
110 | + } |
|
111 | + |
|
112 | + if (!$this->uploadConfigFile($request->files->get('package_config'), "packages")) { |
|
113 | + return new JsonResponse([ |
|
114 | + "error_message" => "Package file move is impossible" |
|
115 | + ]); |
|
116 | + } |
|
117 | + |
|
118 | + $input = new ArrayInput([ |
|
119 | + 'command' => 'ribsadmin:change-package-version', |
|
120 | + 'package-name' => $package_name.":".$version, |
|
121 | + ]); |
|
122 | + |
|
123 | + $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); |
|
124 | + $application->run($input, $output); |
|
125 | + |
|
126 | + $converter = new AnsiToHtmlConverter(); |
|
127 | + $content = $output->fetch(); |
|
128 | + |
|
129 | + return new JsonResponse($converter->convert($content)); |
|
130 | + } |
|
131 | 131 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $success = true; |
81 | 81 | if ($file) { |
82 | 82 | try { |
83 | - $file->move('../config/'.$folder, $file->getClientOriginalName()); |
|
83 | + $file->move('../config/' . $folder, $file->getClientOriginalName()); |
|
84 | 84 | } catch (FileException $exception) { |
85 | 85 | $success = false; |
86 | 86 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | $input = new ArrayInput([ |
119 | 119 | 'command' => 'ribsadmin:change-package-version', |
120 | - 'package-name' => $package_name.":".$version, |
|
120 | + 'package-name' => $package_name . ":" . $version, |
|
121 | 121 | ]); |
122 | 122 | |
123 | 123 | $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); |
@@ -19,140 +19,140 @@ |
||
19 | 19 | |
20 | 20 | class PackageController extends AbstractController |
21 | 21 | { |
22 | - /** |
|
23 | - * @Route("/packages/", name="ribsadmin_packages") |
|
24 | - * @param EntityManagerInterface $em |
|
25 | - * @return Response |
|
26 | - */ |
|
27 | - public function index(EntityManagerInterface $em): Response |
|
28 | - { |
|
29 | - $packages = $em->getRepository(Package::class)->findAll(); |
|
22 | + /** |
|
23 | + * @Route("/packages/", name="ribsadmin_packages") |
|
24 | + * @param EntityManagerInterface $em |
|
25 | + * @return Response |
|
26 | + */ |
|
27 | + public function index(EntityManagerInterface $em): Response |
|
28 | + { |
|
29 | + $packages = $em->getRepository(Package::class)->findAll(); |
|
30 | 30 | |
31 | - return $this->render("@RibsAdmin/packages/list.html.twig", ["packages" => $packages]); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @Route("/packages/create/", name="ribsadmin_packages_create") |
|
36 | - * @Route("/packages/show/{guid}", name="ribsadmin_packages_show") |
|
37 | - * @Route("/packages/edit/{guid}", name="ribsadmin_packages_edit") |
|
38 | - * @param Request $request |
|
39 | - * @param EntityManagerInterface $em |
|
40 | - * @param PackagistApi $packagist |
|
41 | - * @param string|null $guid |
|
42 | - * @return Response |
|
43 | - * @throws ClientExceptionInterface |
|
44 | - * @throws RedirectionExceptionInterface |
|
45 | - * @throws ServerExceptionInterface |
|
46 | - * @throws TransportExceptionInterface |
|
47 | - */ |
|
48 | - public function edit(Request $request, EntityManagerInterface $em, PackagistApi $packagist, string $guid = null): Response |
|
49 | - { |
|
50 | - $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
51 | - if (!$guid) { |
|
52 | - $package = new Package(); |
|
53 | - $text = "created"; |
|
54 | - } else { |
|
55 | - $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
56 | - $text = "edited"; |
|
57 | - } |
|
58 | - |
|
59 | - $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Package::class, $package, ["disabled" => $disabled_form]); |
|
60 | - $form->handleRequest($request); |
|
61 | - |
|
62 | - if ($form->isSubmitted() && $form->isValid()) { |
|
63 | - /** @var Package $data */ |
|
64 | - $data = $form->getData(); |
|
65 | - $em->persist($data); |
|
66 | - $em->flush(); |
|
67 | - $this->addFlash("success-flash", "Package " . $data->getProjectName() . " was " . $text); |
|
68 | - |
|
69 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
70 | - } |
|
71 | - |
|
72 | - return $this->render("@RibsAdmin/packages/edit.html.twig", [ |
|
73 | - "disabled_form" => $disabled_form, |
|
74 | - "form" => $form->createView(), |
|
75 | - "form_errors" => $form->getErrors(), |
|
76 | - "package" => $package, |
|
77 | - "versions" => $packagist->getAllPackagistVersions($package->getPackageName()) |
|
78 | - ]); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @Route("/packages/delete/{guid}", name="ribsadmin_packages_delete") |
|
83 | - * @param EntityManagerInterface $em |
|
84 | - * @param string $guid |
|
85 | - * @return RedirectResponse |
|
86 | - */ |
|
87 | - public function delete(EntityManagerInterface $em, string $guid): RedirectResponse |
|
88 | - { |
|
89 | - $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
90 | - |
|
91 | - if ($package) { |
|
92 | - $em->remove($package); |
|
93 | - $em->flush(); |
|
94 | - $this->addFlash("success-flash", "The project package was deleted"); |
|
95 | - } else { |
|
96 | - $this->addFlash("error-flash", "The project package was not found"); |
|
97 | - } |
|
98 | - |
|
99 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @Route("/packages/update/{guid}", name="ribsadmin_packages_update") |
|
104 | - * @param Version $version |
|
105 | - * @param string $guid |
|
106 | - * @return RedirectResponse |
|
107 | - * @throws ClientExceptionInterface |
|
108 | - * @throws RedirectionExceptionInterface |
|
109 | - * @throws ServerExceptionInterface |
|
110 | - * @throws TransportExceptionInterface |
|
111 | - */ |
|
112 | - public function updatePackage(Version $version, string $guid): RedirectResponse |
|
113 | - { |
|
114 | - if ($guid) { |
|
115 | - $version->save($guid); |
|
116 | - |
|
117 | - if ($version->getMessages()) { |
|
118 | - $message = "<ul>"; |
|
119 | - $message .= "<li>The project package was not well updated</li>"; |
|
120 | - foreach ($version->getMessages() as $version_message) { |
|
121 | - $message .= "<li>".$version_message."</li>"; |
|
122 | - } |
|
123 | - $message .= "</ul>"; |
|
124 | - |
|
125 | - $this->addFlash("info-flash", $message); |
|
126 | - } else { |
|
127 | - $this->addFlash("success-flash", "The project package was updated"); |
|
128 | - } |
|
129 | - } else { |
|
130 | - $this->addFlash("error-flash", "The project package was not found"); |
|
131 | - } |
|
132 | - |
|
133 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @Route("/packages/update-version/{guid}/{install_version}", name="ribsadmin_packages_update_version") |
|
138 | - * @param Version $version |
|
139 | - * @param string $guid |
|
140 | - * @param string $install_version |
|
141 | - * @return RedirectResponse|Response |
|
142 | - * @throws ClientExceptionInterface |
|
143 | - * @throws RedirectionExceptionInterface |
|
144 | - * @throws ServerExceptionInterface |
|
145 | - * @throws TransportExceptionInterface |
|
146 | - */ |
|
147 | - public function changePackageVersion(Version $version, string $guid, string $install_version) |
|
148 | - { |
|
149 | - $response = $version->updatePackage($guid, $install_version); |
|
150 | - |
|
151 | - if ($response) { |
|
152 | - $response = str_replace("\n", "<br>", $response); |
|
153 | - return $this->render("@RibsAdmin/packages/show-update-version.html.twig", ["logs" => $response]); |
|
154 | - } |
|
155 | - |
|
156 | - return $this->redirectToRoute("ribsadmin_packages_update", ["guid" => $guid]); |
|
157 | - } |
|
31 | + return $this->render("@RibsAdmin/packages/list.html.twig", ["packages" => $packages]); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @Route("/packages/create/", name="ribsadmin_packages_create") |
|
36 | + * @Route("/packages/show/{guid}", name="ribsadmin_packages_show") |
|
37 | + * @Route("/packages/edit/{guid}", name="ribsadmin_packages_edit") |
|
38 | + * @param Request $request |
|
39 | + * @param EntityManagerInterface $em |
|
40 | + * @param PackagistApi $packagist |
|
41 | + * @param string|null $guid |
|
42 | + * @return Response |
|
43 | + * @throws ClientExceptionInterface |
|
44 | + * @throws RedirectionExceptionInterface |
|
45 | + * @throws ServerExceptionInterface |
|
46 | + * @throws TransportExceptionInterface |
|
47 | + */ |
|
48 | + public function edit(Request $request, EntityManagerInterface $em, PackagistApi $packagist, string $guid = null): Response |
|
49 | + { |
|
50 | + $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
51 | + if (!$guid) { |
|
52 | + $package = new Package(); |
|
53 | + $text = "created"; |
|
54 | + } else { |
|
55 | + $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
56 | + $text = "edited"; |
|
57 | + } |
|
58 | + |
|
59 | + $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Package::class, $package, ["disabled" => $disabled_form]); |
|
60 | + $form->handleRequest($request); |
|
61 | + |
|
62 | + if ($form->isSubmitted() && $form->isValid()) { |
|
63 | + /** @var Package $data */ |
|
64 | + $data = $form->getData(); |
|
65 | + $em->persist($data); |
|
66 | + $em->flush(); |
|
67 | + $this->addFlash("success-flash", "Package " . $data->getProjectName() . " was " . $text); |
|
68 | + |
|
69 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
70 | + } |
|
71 | + |
|
72 | + return $this->render("@RibsAdmin/packages/edit.html.twig", [ |
|
73 | + "disabled_form" => $disabled_form, |
|
74 | + "form" => $form->createView(), |
|
75 | + "form_errors" => $form->getErrors(), |
|
76 | + "package" => $package, |
|
77 | + "versions" => $packagist->getAllPackagistVersions($package->getPackageName()) |
|
78 | + ]); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @Route("/packages/delete/{guid}", name="ribsadmin_packages_delete") |
|
83 | + * @param EntityManagerInterface $em |
|
84 | + * @param string $guid |
|
85 | + * @return RedirectResponse |
|
86 | + */ |
|
87 | + public function delete(EntityManagerInterface $em, string $guid): RedirectResponse |
|
88 | + { |
|
89 | + $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
90 | + |
|
91 | + if ($package) { |
|
92 | + $em->remove($package); |
|
93 | + $em->flush(); |
|
94 | + $this->addFlash("success-flash", "The project package was deleted"); |
|
95 | + } else { |
|
96 | + $this->addFlash("error-flash", "The project package was not found"); |
|
97 | + } |
|
98 | + |
|
99 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @Route("/packages/update/{guid}", name="ribsadmin_packages_update") |
|
104 | + * @param Version $version |
|
105 | + * @param string $guid |
|
106 | + * @return RedirectResponse |
|
107 | + * @throws ClientExceptionInterface |
|
108 | + * @throws RedirectionExceptionInterface |
|
109 | + * @throws ServerExceptionInterface |
|
110 | + * @throws TransportExceptionInterface |
|
111 | + */ |
|
112 | + public function updatePackage(Version $version, string $guid): RedirectResponse |
|
113 | + { |
|
114 | + if ($guid) { |
|
115 | + $version->save($guid); |
|
116 | + |
|
117 | + if ($version->getMessages()) { |
|
118 | + $message = "<ul>"; |
|
119 | + $message .= "<li>The project package was not well updated</li>"; |
|
120 | + foreach ($version->getMessages() as $version_message) { |
|
121 | + $message .= "<li>".$version_message."</li>"; |
|
122 | + } |
|
123 | + $message .= "</ul>"; |
|
124 | + |
|
125 | + $this->addFlash("info-flash", $message); |
|
126 | + } else { |
|
127 | + $this->addFlash("success-flash", "The project package was updated"); |
|
128 | + } |
|
129 | + } else { |
|
130 | + $this->addFlash("error-flash", "The project package was not found"); |
|
131 | + } |
|
132 | + |
|
133 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @Route("/packages/update-version/{guid}/{install_version}", name="ribsadmin_packages_update_version") |
|
138 | + * @param Version $version |
|
139 | + * @param string $guid |
|
140 | + * @param string $install_version |
|
141 | + * @return RedirectResponse|Response |
|
142 | + * @throws ClientExceptionInterface |
|
143 | + * @throws RedirectionExceptionInterface |
|
144 | + * @throws ServerExceptionInterface |
|
145 | + * @throws TransportExceptionInterface |
|
146 | + */ |
|
147 | + public function changePackageVersion(Version $version, string $guid, string $install_version) |
|
148 | + { |
|
149 | + $response = $version->updatePackage($guid, $install_version); |
|
150 | + |
|
151 | + if ($response) { |
|
152 | + $response = str_replace("\n", "<br>", $response); |
|
153 | + return $this->render("@RibsAdmin/packages/show-update-version.html.twig", ["logs" => $response]); |
|
154 | + } |
|
155 | + |
|
156 | + return $this->redirectToRoute("ribsadmin_packages_update", ["guid" => $guid]); |
|
157 | + } |
|
158 | 158 | } |