@@ -15,197 +15,197 @@ |
||
15 | 15 | |
16 | 16 | class Version |
17 | 17 | { |
18 | - /** |
|
19 | - * @var EntityManagerInterface |
|
20 | - */ |
|
21 | - private $em; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var HttpClientInterface |
|
25 | - */ |
|
26 | - private $client; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var ParameterBagInterface |
|
30 | - */ |
|
31 | - private $parameter; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var mixed |
|
35 | - */ |
|
36 | - private $local_token; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var Package |
|
40 | - */ |
|
41 | - private $package; |
|
42 | - |
|
43 | - private $messages = []; |
|
44 | - |
|
45 | - /** |
|
46 | - * Version constructor. |
|
47 | - * @param EntityManagerInterface $em |
|
48 | - * @param HttpClientInterface $client |
|
49 | - * @param ParameterBagInterface $parameter |
|
50 | - */ |
|
51 | - public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter) |
|
52 | - { |
|
53 | - $this->em = $em; |
|
54 | - $this->client = $client; |
|
55 | - $this->parameter = $parameter; |
|
56 | - $this->local_token = $parameter->get("ribs_admin.packages_token"); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function getMessages(): array |
|
63 | - { |
|
64 | - return $this->messages; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @param Package $package |
|
69 | - */ |
|
70 | - public function setPackageEntity(Package $package) { |
|
71 | - $this->package = $package; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return mixed|null |
|
76 | - */ |
|
77 | - private function getToken() |
|
78 | - { |
|
79 | - $token = null; |
|
80 | - $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/send-token/"); |
|
81 | - $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
82 | - |
|
83 | - if ($datas) { |
|
84 | - $token = json_decode($datas, true)["token"]; |
|
85 | - } |
|
86 | - |
|
87 | - return $token; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @return mixed|null |
|
92 | - * @throws ClientExceptionInterface |
|
93 | - * @throws RedirectionExceptionInterface |
|
94 | - * @throws ServerExceptionInterface |
|
95 | - * @throws TransportExceptionInterface |
|
96 | - */ |
|
97 | - private function getComposerLockJson() |
|
98 | - { |
|
99 | - if ($this->package && !$this->package->isIsLocal()) { |
|
100 | - $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
101 | - $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
102 | - } else { |
|
103 | - $composer_lock = file_get_contents('../composer.lock'); |
|
104 | - } |
|
105 | - |
|
106 | - if ($composer_lock) { |
|
107 | - return json_decode($composer_lock, true); |
|
108 | - } |
|
109 | - |
|
110 | - return null; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @return mixed|null |
|
115 | - * @throws ClientExceptionInterface |
|
116 | - * @throws RedirectionExceptionInterface |
|
117 | - * @throws ServerExceptionInterface |
|
118 | - * @throws TransportExceptionInterface |
|
119 | - */ |
|
120 | - public function getPackage() |
|
121 | - { |
|
122 | - $composer_lock = $this->getComposerLockJson(); |
|
123 | - if ($composer_lock) { |
|
124 | - $packages = $composer_lock["packages"]; |
|
125 | - $key = array_search($this->package->getPackageName(), array_column($packages, 'name')); |
|
126 | - |
|
127 | - if ($key) { |
|
128 | - return $packages[$key]; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - $this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl(); |
|
133 | - |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return mixed|null |
|
139 | - */ |
|
140 | - public function getVersion() |
|
141 | - { |
|
142 | - return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return DateTime|null |
|
147 | - * @throws Exception |
|
148 | - */ |
|
149 | - public function getVersionDate(): ?DateTime |
|
150 | - { |
|
151 | - $string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null; |
|
152 | - $version_date = null; |
|
153 | - |
|
154 | - if ($string_date) { |
|
155 | - $version_date = new DateTime($string_date); |
|
156 | - } |
|
157 | - |
|
158 | - return $version_date; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @return false|int|string|null |
|
163 | - * @throws ClientExceptionInterface |
|
164 | - * @throws RedirectionExceptionInterface |
|
165 | - * @throws ServerExceptionInterface |
|
166 | - * @throws TransportExceptionInterface |
|
167 | - */ |
|
168 | - public function getLastPackagistVersion() |
|
169 | - { |
|
170 | - if (!strpos($this->package->getPackageName(), "/")) { |
|
171 | - return false; |
|
172 | - } |
|
173 | - |
|
174 | - $packgist_url = "https://repo.packagist.org/p/".$this->package->getPackageName().".json"; |
|
175 | - |
|
176 | - $response = $this->client->request("GET", $packgist_url); |
|
177 | - |
|
178 | - if ($response->getStatusCode() == 200) { |
|
179 | - $content = json_decode($response->getContent(), true); |
|
180 | - if (is_array($content) && $content["packages"] && $content["packages"][$this->package->getPackageName()]) { |
|
181 | - return array_key_first($content["packages"][$this->package->getPackageName()]); |
|
182 | - } |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param $package_guid |
|
188 | - * @throws Exception |
|
189 | - */ |
|
190 | - public function save($package_guid) |
|
191 | - { |
|
192 | - $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]); |
|
193 | - |
|
194 | - if ($package) { |
|
195 | - $this->setPackageEntity($package); |
|
196 | - |
|
197 | - if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
198 | - $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
199 | - return; |
|
200 | - } |
|
201 | - |
|
202 | - $package->setVersion($this->getVersion()); |
|
203 | - $package->setVersionDate($this->getVersionDate()); |
|
204 | - $package->setLastPackagistVersion($this->getLastPackagistVersion()); |
|
205 | - $package->setLastCheck(new DateTime()); |
|
206 | - |
|
207 | - $this->em->persist($package); |
|
208 | - $this->em->flush(); |
|
209 | - } |
|
210 | - } |
|
18 | + /** |
|
19 | + * @var EntityManagerInterface |
|
20 | + */ |
|
21 | + private $em; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var HttpClientInterface |
|
25 | + */ |
|
26 | + private $client; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var ParameterBagInterface |
|
30 | + */ |
|
31 | + private $parameter; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var mixed |
|
35 | + */ |
|
36 | + private $local_token; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var Package |
|
40 | + */ |
|
41 | + private $package; |
|
42 | + |
|
43 | + private $messages = []; |
|
44 | + |
|
45 | + /** |
|
46 | + * Version constructor. |
|
47 | + * @param EntityManagerInterface $em |
|
48 | + * @param HttpClientInterface $client |
|
49 | + * @param ParameterBagInterface $parameter |
|
50 | + */ |
|
51 | + public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter) |
|
52 | + { |
|
53 | + $this->em = $em; |
|
54 | + $this->client = $client; |
|
55 | + $this->parameter = $parameter; |
|
56 | + $this->local_token = $parameter->get("ribs_admin.packages_token"); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function getMessages(): array |
|
63 | + { |
|
64 | + return $this->messages; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @param Package $package |
|
69 | + */ |
|
70 | + public function setPackageEntity(Package $package) { |
|
71 | + $this->package = $package; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return mixed|null |
|
76 | + */ |
|
77 | + private function getToken() |
|
78 | + { |
|
79 | + $token = null; |
|
80 | + $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/send-token/"); |
|
81 | + $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
82 | + |
|
83 | + if ($datas) { |
|
84 | + $token = json_decode($datas, true)["token"]; |
|
85 | + } |
|
86 | + |
|
87 | + return $token; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @return mixed|null |
|
92 | + * @throws ClientExceptionInterface |
|
93 | + * @throws RedirectionExceptionInterface |
|
94 | + * @throws ServerExceptionInterface |
|
95 | + * @throws TransportExceptionInterface |
|
96 | + */ |
|
97 | + private function getComposerLockJson() |
|
98 | + { |
|
99 | + if ($this->package && !$this->package->isIsLocal()) { |
|
100 | + $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
101 | + $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
102 | + } else { |
|
103 | + $composer_lock = file_get_contents('../composer.lock'); |
|
104 | + } |
|
105 | + |
|
106 | + if ($composer_lock) { |
|
107 | + return json_decode($composer_lock, true); |
|
108 | + } |
|
109 | + |
|
110 | + return null; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @return mixed|null |
|
115 | + * @throws ClientExceptionInterface |
|
116 | + * @throws RedirectionExceptionInterface |
|
117 | + * @throws ServerExceptionInterface |
|
118 | + * @throws TransportExceptionInterface |
|
119 | + */ |
|
120 | + public function getPackage() |
|
121 | + { |
|
122 | + $composer_lock = $this->getComposerLockJson(); |
|
123 | + if ($composer_lock) { |
|
124 | + $packages = $composer_lock["packages"]; |
|
125 | + $key = array_search($this->package->getPackageName(), array_column($packages, 'name')); |
|
126 | + |
|
127 | + if ($key) { |
|
128 | + return $packages[$key]; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + $this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl(); |
|
133 | + |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return mixed|null |
|
139 | + */ |
|
140 | + public function getVersion() |
|
141 | + { |
|
142 | + return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return DateTime|null |
|
147 | + * @throws Exception |
|
148 | + */ |
|
149 | + public function getVersionDate(): ?DateTime |
|
150 | + { |
|
151 | + $string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null; |
|
152 | + $version_date = null; |
|
153 | + |
|
154 | + if ($string_date) { |
|
155 | + $version_date = new DateTime($string_date); |
|
156 | + } |
|
157 | + |
|
158 | + return $version_date; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @return false|int|string|null |
|
163 | + * @throws ClientExceptionInterface |
|
164 | + * @throws RedirectionExceptionInterface |
|
165 | + * @throws ServerExceptionInterface |
|
166 | + * @throws TransportExceptionInterface |
|
167 | + */ |
|
168 | + public function getLastPackagistVersion() |
|
169 | + { |
|
170 | + if (!strpos($this->package->getPackageName(), "/")) { |
|
171 | + return false; |
|
172 | + } |
|
173 | + |
|
174 | + $packgist_url = "https://repo.packagist.org/p/".$this->package->getPackageName().".json"; |
|
175 | + |
|
176 | + $response = $this->client->request("GET", $packgist_url); |
|
177 | + |
|
178 | + if ($response->getStatusCode() == 200) { |
|
179 | + $content = json_decode($response->getContent(), true); |
|
180 | + if (is_array($content) && $content["packages"] && $content["packages"][$this->package->getPackageName()]) { |
|
181 | + return array_key_first($content["packages"][$this->package->getPackageName()]); |
|
182 | + } |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @param $package_guid |
|
188 | + * @throws Exception |
|
189 | + */ |
|
190 | + public function save($package_guid) |
|
191 | + { |
|
192 | + $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]); |
|
193 | + |
|
194 | + if ($package) { |
|
195 | + $this->setPackageEntity($package); |
|
196 | + |
|
197 | + if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
198 | + $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
199 | + return; |
|
200 | + } |
|
201 | + |
|
202 | + $package->setVersion($this->getVersion()); |
|
203 | + $package->setVersionDate($this->getVersionDate()); |
|
204 | + $package->setLastPackagistVersion($this->getLastPackagistVersion()); |
|
205 | + $package->setLastCheck(new DateTime()); |
|
206 | + |
|
207 | + $this->em->persist($package); |
|
208 | + $this->em->flush(); |
|
209 | + } |
|
210 | + } |
|
211 | 211 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | private function getToken() |
78 | 78 | { |
79 | 79 | $token = null; |
80 | - $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/send-token/"); |
|
80 | + $response = $this->client->request("GET", $this->package->getProjectUrl() . "ribs-admin/packages/send-token/"); |
|
81 | 81 | $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
82 | 82 | |
83 | 83 | if ($datas) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | private function getComposerLockJson() |
98 | 98 | { |
99 | 99 | if ($this->package && !$this->package->isIsLocal()) { |
100 | - $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
100 | + $response = $this->client->request("GET", $this->package->getProjectUrl() . $this->package->getComposerLockUrl()); |
|
101 | 101 | $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
102 | 102 | } else { |
103 | 103 | $composer_lock = file_get_contents('../composer.lock'); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | return false; |
172 | 172 | } |
173 | 173 | |
174 | - $packgist_url = "https://repo.packagist.org/p/".$this->package->getPackageName().".json"; |
|
174 | + $packgist_url = "https://repo.packagist.org/p/" . $this->package->getPackageName() . ".json"; |
|
175 | 175 | |
176 | 176 | $response = $this->client->request("GET", $packgist_url); |
177 | 177 |
@@ -16,156 +16,156 @@ |
||
16 | 16 | |
17 | 17 | class PackageController extends AbstractController |
18 | 18 | { |
19 | - /** |
|
20 | - * @Route("/packages/", name="ribsadmin_packages") |
|
21 | - * @param EntityManagerInterface $em |
|
22 | - * @return Response |
|
23 | - */ |
|
24 | - public function index(EntityManagerInterface $em): Response |
|
25 | - { |
|
26 | - $packages = $em->getRepository(Package::class)->findAll(); |
|
19 | + /** |
|
20 | + * @Route("/packages/", name="ribsadmin_packages") |
|
21 | + * @param EntityManagerInterface $em |
|
22 | + * @return Response |
|
23 | + */ |
|
24 | + public function index(EntityManagerInterface $em): Response |
|
25 | + { |
|
26 | + $packages = $em->getRepository(Package::class)->findAll(); |
|
27 | 27 | |
28 | - return $this->render("@RibsAdmin/packages/list.html.twig", ["packages" => $packages]); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @Route("/packages/create/", name="ribsadmin_packages_create") |
|
33 | - * @Route("/packages/show/{guid}", name="ribsadmin_packages_show") |
|
34 | - * @Route("/packages/edit/{guid}", name="ribsadmin_packages_edit") |
|
35 | - * @param Request $request |
|
36 | - * @param EntityManagerInterface $em |
|
37 | - * @param string|null $guid |
|
38 | - * @return Response |
|
39 | - */ |
|
40 | - public function edit(Request $request, EntityManagerInterface $em, string $guid = null): Response |
|
41 | - { |
|
42 | - $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
43 | - if (!$guid) { |
|
44 | - $package = new Package(); |
|
45 | - $text = "created"; |
|
46 | - } else { |
|
47 | - $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
48 | - $text = "edited"; |
|
49 | - } |
|
50 | - |
|
51 | - $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Package::class, $package, ["disabled" => $disabled_form]); |
|
52 | - $form->handleRequest($request); |
|
53 | - |
|
54 | - if ($form->isSubmitted() && $form->isValid()) { |
|
55 | - /** @var Package $data */ |
|
56 | - $data = $form->getData(); |
|
57 | - $em->persist($data); |
|
58 | - $em->flush(); |
|
59 | - $this->addFlash("success-flash", "Package " . $data->getProjectName() . " was " . $text); |
|
60 | - |
|
61 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
62 | - } |
|
63 | - |
|
64 | - return $this->render("@RibsAdmin/packages/edit.html.twig", [ |
|
65 | - "form" => $form->createView(), |
|
66 | - "form_errors" => $form->getErrors(), |
|
67 | - "package" => $package |
|
68 | - ]); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @Route("/packages/delete/{guid}", name="ribsadmin_packages_delete") |
|
73 | - * @param EntityManagerInterface $em |
|
74 | - * @param string $guid |
|
75 | - * @return RedirectResponse |
|
76 | - */ |
|
77 | - public function delete(EntityManagerInterface $em, string $guid): RedirectResponse |
|
78 | - { |
|
79 | - $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
80 | - |
|
81 | - if ($package) { |
|
82 | - $em->remove($package); |
|
83 | - $em->flush(); |
|
84 | - $this->addFlash("success-flash", "The project package was deleted"); |
|
85 | - } else { |
|
86 | - $this->addFlash("error-flash", "The project package was not found"); |
|
87 | - } |
|
88 | - |
|
89 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @Route("/packages/update/{guid}", name="ribsadmin_packages_update") |
|
94 | - * @param Version $version |
|
95 | - * @param string $guid |
|
96 | - * @return RedirectResponse |
|
97 | - * @throws Exception |
|
98 | - */ |
|
99 | - public function updatePackage(Version $version, string $guid): RedirectResponse |
|
100 | - { |
|
101 | - if ($guid) { |
|
102 | - $version->save($guid); |
|
103 | - |
|
104 | - if ($version->getMessages()) { |
|
105 | - $message = "<ul>"; |
|
106 | - $message .= "<li>The project package was not well updated</li>"; |
|
107 | - foreach ($version->getMessages() as $version_message) { |
|
108 | - $message .= "<li>".$version_message."</li>"; |
|
109 | - } |
|
110 | - $message .= "</ul>"; |
|
111 | - |
|
112 | - $this->addFlash("info-flash", $message); |
|
113 | - } |
|
114 | - |
|
115 | - $this->addFlash("success-flash", "The project package was updated"); |
|
116 | - } else { |
|
117 | - $this->addFlash("error-flash", "The project package was not found"); |
|
118 | - } |
|
119 | - |
|
120 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @Route("/packages/send-package/{package_name}", name="ribsadmin_packages_send", requirements={"package_name"=".+"}) |
|
125 | - * @param EntityManagerInterface $em |
|
126 | - * @param Version $version |
|
127 | - * @param string $package_name |
|
128 | - * @return mixed|null |
|
129 | - * @throws Exception |
|
130 | - */ |
|
131 | - public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
132 | - { |
|
133 | - $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
134 | - |
|
135 | - if ($package) { |
|
136 | - $version->setPackageEntity($package); |
|
137 | - } |
|
138 | - |
|
139 | - return new JsonResponse([ |
|
140 | - "package" => $version->getPackage(), |
|
141 | - "package_date" => $version->getVersionDate() |
|
142 | - ]); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @Route("/packages/send-composer-lock/", name="ribsadmin_packages_send_composer_lock") |
|
147 | - * @return JsonResponse |
|
148 | - */ |
|
149 | - public function sendComposerJson(): JsonResponse |
|
150 | - { |
|
151 | - $composer_lock = file_get_contents('../composer.lock'); |
|
152 | - |
|
153 | - if ($composer_lock) { |
|
154 | - $composer_lock = json_decode($composer_lock); |
|
155 | - } |
|
156 | - |
|
157 | - return new JsonResponse($composer_lock); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @Route("/packages/send-token/", name="ribsadmin_packages_send_token") |
|
162 | - * @param ParameterBagInterface $parameter |
|
163 | - * @return JsonResponse |
|
164 | - */ |
|
165 | - public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
166 | - { |
|
167 | - return new JsonResponse([ |
|
168 | - "token" => $parameter->get("ribs_admin.packages_token") |
|
169 | - ]); |
|
170 | - } |
|
28 | + return $this->render("@RibsAdmin/packages/list.html.twig", ["packages" => $packages]); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @Route("/packages/create/", name="ribsadmin_packages_create") |
|
33 | + * @Route("/packages/show/{guid}", name="ribsadmin_packages_show") |
|
34 | + * @Route("/packages/edit/{guid}", name="ribsadmin_packages_edit") |
|
35 | + * @param Request $request |
|
36 | + * @param EntityManagerInterface $em |
|
37 | + * @param string|null $guid |
|
38 | + * @return Response |
|
39 | + */ |
|
40 | + public function edit(Request $request, EntityManagerInterface $em, string $guid = null): Response |
|
41 | + { |
|
42 | + $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
43 | + if (!$guid) { |
|
44 | + $package = new Package(); |
|
45 | + $text = "created"; |
|
46 | + } else { |
|
47 | + $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
48 | + $text = "edited"; |
|
49 | + } |
|
50 | + |
|
51 | + $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Package::class, $package, ["disabled" => $disabled_form]); |
|
52 | + $form->handleRequest($request); |
|
53 | + |
|
54 | + if ($form->isSubmitted() && $form->isValid()) { |
|
55 | + /** @var Package $data */ |
|
56 | + $data = $form->getData(); |
|
57 | + $em->persist($data); |
|
58 | + $em->flush(); |
|
59 | + $this->addFlash("success-flash", "Package " . $data->getProjectName() . " was " . $text); |
|
60 | + |
|
61 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
62 | + } |
|
63 | + |
|
64 | + return $this->render("@RibsAdmin/packages/edit.html.twig", [ |
|
65 | + "form" => $form->createView(), |
|
66 | + "form_errors" => $form->getErrors(), |
|
67 | + "package" => $package |
|
68 | + ]); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @Route("/packages/delete/{guid}", name="ribsadmin_packages_delete") |
|
73 | + * @param EntityManagerInterface $em |
|
74 | + * @param string $guid |
|
75 | + * @return RedirectResponse |
|
76 | + */ |
|
77 | + public function delete(EntityManagerInterface $em, string $guid): RedirectResponse |
|
78 | + { |
|
79 | + $package = $em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
80 | + |
|
81 | + if ($package) { |
|
82 | + $em->remove($package); |
|
83 | + $em->flush(); |
|
84 | + $this->addFlash("success-flash", "The project package was deleted"); |
|
85 | + } else { |
|
86 | + $this->addFlash("error-flash", "The project package was not found"); |
|
87 | + } |
|
88 | + |
|
89 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @Route("/packages/update/{guid}", name="ribsadmin_packages_update") |
|
94 | + * @param Version $version |
|
95 | + * @param string $guid |
|
96 | + * @return RedirectResponse |
|
97 | + * @throws Exception |
|
98 | + */ |
|
99 | + public function updatePackage(Version $version, string $guid): RedirectResponse |
|
100 | + { |
|
101 | + if ($guid) { |
|
102 | + $version->save($guid); |
|
103 | + |
|
104 | + if ($version->getMessages()) { |
|
105 | + $message = "<ul>"; |
|
106 | + $message .= "<li>The project package was not well updated</li>"; |
|
107 | + foreach ($version->getMessages() as $version_message) { |
|
108 | + $message .= "<li>".$version_message."</li>"; |
|
109 | + } |
|
110 | + $message .= "</ul>"; |
|
111 | + |
|
112 | + $this->addFlash("info-flash", $message); |
|
113 | + } |
|
114 | + |
|
115 | + $this->addFlash("success-flash", "The project package was updated"); |
|
116 | + } else { |
|
117 | + $this->addFlash("error-flash", "The project package was not found"); |
|
118 | + } |
|
119 | + |
|
120 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @Route("/packages/send-package/{package_name}", name="ribsadmin_packages_send", requirements={"package_name"=".+"}) |
|
125 | + * @param EntityManagerInterface $em |
|
126 | + * @param Version $version |
|
127 | + * @param string $package_name |
|
128 | + * @return mixed|null |
|
129 | + * @throws Exception |
|
130 | + */ |
|
131 | + public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
132 | + { |
|
133 | + $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
134 | + |
|
135 | + if ($package) { |
|
136 | + $version->setPackageEntity($package); |
|
137 | + } |
|
138 | + |
|
139 | + return new JsonResponse([ |
|
140 | + "package" => $version->getPackage(), |
|
141 | + "package_date" => $version->getVersionDate() |
|
142 | + ]); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @Route("/packages/send-composer-lock/", name="ribsadmin_packages_send_composer_lock") |
|
147 | + * @return JsonResponse |
|
148 | + */ |
|
149 | + public function sendComposerJson(): JsonResponse |
|
150 | + { |
|
151 | + $composer_lock = file_get_contents('../composer.lock'); |
|
152 | + |
|
153 | + if ($composer_lock) { |
|
154 | + $composer_lock = json_decode($composer_lock); |
|
155 | + } |
|
156 | + |
|
157 | + return new JsonResponse($composer_lock); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @Route("/packages/send-token/", name="ribsadmin_packages_send_token") |
|
162 | + * @param ParameterBagInterface $parameter |
|
163 | + * @return JsonResponse |
|
164 | + */ |
|
165 | + public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
166 | + { |
|
167 | + return new JsonResponse([ |
|
168 | + "token" => $parameter->get("ribs_admin.packages_token") |
|
169 | + ]); |
|
170 | + } |
|
171 | 171 | } |