@@ -16,76 +16,76 @@ |
||
16 | 16 | |
17 | 17 | class PackagesDistController extends AbstractController |
18 | 18 | { |
19 | - /** |
|
20 | - * @Route("/packages/dist/send-package/{package_name}", name="ribsadmin_packages_dist_send", requirements={"package_name"=".+"}) |
|
21 | - * @param EntityManagerInterface $em |
|
22 | - * @param Version $version |
|
23 | - * @param string $package_name |
|
24 | - * @return mixed|null |
|
25 | - * @throws Exception |
|
26 | - */ |
|
27 | - public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
28 | - { |
|
29 | - $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
19 | + /** |
|
20 | + * @Route("/packages/dist/send-package/{package_name}", name="ribsadmin_packages_dist_send", requirements={"package_name"=".+"}) |
|
21 | + * @param EntityManagerInterface $em |
|
22 | + * @param Version $version |
|
23 | + * @param string $package_name |
|
24 | + * @return mixed|null |
|
25 | + * @throws Exception |
|
26 | + */ |
|
27 | + public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse |
|
28 | + { |
|
29 | + $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]); |
|
30 | 30 | |
31 | - if ($package) { |
|
32 | - $version->setPackageEntity($package); |
|
33 | - } |
|
31 | + if ($package) { |
|
32 | + $version->setPackageEntity($package); |
|
33 | + } |
|
34 | 34 | |
35 | - return new JsonResponse([ |
|
36 | - "package" => $version->getPackage(), |
|
37 | - "package_date" => $version->getVersionDate() |
|
38 | - ]); |
|
39 | - } |
|
35 | + return new JsonResponse([ |
|
36 | + "package" => $version->getPackage(), |
|
37 | + "package_date" => $version->getVersionDate() |
|
38 | + ]); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @Route("/packages/dist/send-composer-lock/", name="ribsadmin_packages_dist_send_composer_lock") |
|
43 | - * @return JsonResponse |
|
44 | - */ |
|
45 | - public function sendComposerJson(): JsonResponse |
|
46 | - { |
|
47 | - $composer_lock = file_get_contents('../composer.lock'); |
|
41 | + /** |
|
42 | + * @Route("/packages/dist/send-composer-lock/", name="ribsadmin_packages_dist_send_composer_lock") |
|
43 | + * @return JsonResponse |
|
44 | + */ |
|
45 | + public function sendComposerJson(): JsonResponse |
|
46 | + { |
|
47 | + $composer_lock = file_get_contents('../composer.lock'); |
|
48 | 48 | |
49 | - if ($composer_lock) { |
|
50 | - $composer_lock = json_decode($composer_lock); |
|
51 | - } |
|
49 | + if ($composer_lock) { |
|
50 | + $composer_lock = json_decode($composer_lock); |
|
51 | + } |
|
52 | 52 | |
53 | - return new JsonResponse($composer_lock); |
|
54 | - } |
|
53 | + return new JsonResponse($composer_lock); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @Route("/packages/dist/send-token/", name="ribsadmin_packages_dist_send_token") |
|
58 | - * @param ParameterBagInterface $parameter |
|
59 | - * @return JsonResponse |
|
60 | - */ |
|
61 | - public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
62 | - { |
|
63 | - return new JsonResponse([ |
|
64 | - "token" => $parameter->get("ribs_admin.packages_token") |
|
65 | - ]); |
|
66 | - } |
|
56 | + /** |
|
57 | + * @Route("/packages/dist/send-token/", name="ribsadmin_packages_dist_send_token") |
|
58 | + * @param ParameterBagInterface $parameter |
|
59 | + * @return JsonResponse |
|
60 | + */ |
|
61 | + public function sendToken(ParameterBagInterface $parameter): JsonResponse |
|
62 | + { |
|
63 | + return new JsonResponse([ |
|
64 | + "token" => $parameter->get("ribs_admin.packages_token") |
|
65 | + ]); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @Route("/packages/dist/change-version/{package_name}", name="ribsadmin_packages_dist_change_version", requirements={"package_name"=".+"}) |
|
70 | - * @param KernelInterface $kernel |
|
71 | - * @param string $package_name |
|
72 | - * @return JsonResponse |
|
73 | - * @throws Exception |
|
74 | - */ |
|
75 | - public function changePackageVersion(KernelInterface $kernel, string $package_name): JsonResponse |
|
76 | - { |
|
77 | - $application = new Application($kernel); |
|
78 | - $application->setAutoExit(false); |
|
68 | + /** |
|
69 | + * @Route("/packages/dist/change-version/{package_name}", name="ribsadmin_packages_dist_change_version", requirements={"package_name"=".+"}) |
|
70 | + * @param KernelInterface $kernel |
|
71 | + * @param string $package_name |
|
72 | + * @return JsonResponse |
|
73 | + * @throws Exception |
|
74 | + */ |
|
75 | + public function changePackageVersion(KernelInterface $kernel, string $package_name): JsonResponse |
|
76 | + { |
|
77 | + $application = new Application($kernel); |
|
78 | + $application->setAutoExit(false); |
|
79 | 79 | |
80 | - $input = new ArrayInput([ |
|
81 | - 'command' => 'ribsadmin:change-package-version', |
|
82 | - 'package-name' => $package_name, |
|
83 | - ]); |
|
80 | + $input = new ArrayInput([ |
|
81 | + 'command' => 'ribsadmin:change-package-version', |
|
82 | + 'package-name' => $package_name, |
|
83 | + ]); |
|
84 | 84 | |
85 | - $output = new BufferedOutput(); |
|
86 | - $application->run($input, $output); |
|
87 | - $content = $output->fetch(); |
|
85 | + $output = new BufferedOutput(); |
|
86 | + $application->run($input, $output); |
|
87 | + $content = $output->fetch(); |
|
88 | 88 | |
89 | - return new JsonResponse($content); |
|
90 | - } |
|
89 | + return new JsonResponse($content); |
|
90 | + } |
|
91 | 91 | } |
@@ -19,128 +19,128 @@ |
||
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 Exception |
|
108 | - */ |
|
109 | - public function updatePackage(Version $version, string $guid): RedirectResponse |
|
110 | - { |
|
111 | - if ($guid) { |
|
112 | - $version->save($guid); |
|
113 | - |
|
114 | - if ($version->getMessages()) { |
|
115 | - $message = "<ul>"; |
|
116 | - $message .= "<li>The project package was not well updated</li>"; |
|
117 | - foreach ($version->getMessages() as $version_message) { |
|
118 | - $message .= "<li>".$version_message."</li>"; |
|
119 | - } |
|
120 | - $message .= "</ul>"; |
|
121 | - |
|
122 | - $this->addFlash("info-flash", $message); |
|
123 | - } else { |
|
124 | - $this->addFlash("success-flash", "The project package was updated"); |
|
125 | - } |
|
126 | - } else { |
|
127 | - $this->addFlash("error-flash", "The project package was not found"); |
|
128 | - } |
|
129 | - |
|
130 | - return $this->redirectToRoute("ribsadmin_packages"); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @Route("/packages/update-version/{guid}/{install_version}", name="ribsadmin_packages_update_version") |
|
135 | - * @param Version $version |
|
136 | - * @param string $guid |
|
137 | - * @param string $install_version |
|
138 | - * @return RedirectResponse |
|
139 | - */ |
|
140 | - public function changePackageVersion(Version $version, string $guid, string $install_version): RedirectResponse |
|
141 | - { |
|
142 | - $version->updatePackage($guid, $install_version); |
|
143 | - |
|
144 | - return $this->redirectToRoute("ribsadmin_packages_update", ["guid" => $guid]); |
|
145 | - } |
|
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 Exception |
|
108 | + */ |
|
109 | + public function updatePackage(Version $version, string $guid): RedirectResponse |
|
110 | + { |
|
111 | + if ($guid) { |
|
112 | + $version->save($guid); |
|
113 | + |
|
114 | + if ($version->getMessages()) { |
|
115 | + $message = "<ul>"; |
|
116 | + $message .= "<li>The project package was not well updated</li>"; |
|
117 | + foreach ($version->getMessages() as $version_message) { |
|
118 | + $message .= "<li>".$version_message."</li>"; |
|
119 | + } |
|
120 | + $message .= "</ul>"; |
|
121 | + |
|
122 | + $this->addFlash("info-flash", $message); |
|
123 | + } else { |
|
124 | + $this->addFlash("success-flash", "The project package was updated"); |
|
125 | + } |
|
126 | + } else { |
|
127 | + $this->addFlash("error-flash", "The project package was not found"); |
|
128 | + } |
|
129 | + |
|
130 | + return $this->redirectToRoute("ribsadmin_packages"); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @Route("/packages/update-version/{guid}/{install_version}", name="ribsadmin_packages_update_version") |
|
135 | + * @param Version $version |
|
136 | + * @param string $guid |
|
137 | + * @param string $install_version |
|
138 | + * @return RedirectResponse |
|
139 | + */ |
|
140 | + public function changePackageVersion(Version $version, string $guid, string $install_version): RedirectResponse |
|
141 | + { |
|
142 | + $version->updatePackage($guid, $install_version); |
|
143 | + |
|
144 | + return $this->redirectToRoute("ribsadmin_packages_update", ["guid" => $guid]); |
|
145 | + } |
|
146 | 146 | } |
@@ -15,210 +15,210 @@ |
||
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 PackagistApi |
|
35 | - */ |
|
36 | - private $packagist; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var mixed |
|
40 | - */ |
|
41 | - private $local_token; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var Package |
|
45 | - */ |
|
46 | - private $package; |
|
47 | - |
|
48 | - private $messages = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * Version constructor. |
|
52 | - * @param EntityManagerInterface $em |
|
53 | - * @param HttpClientInterface $client |
|
54 | - * @param ParameterBagInterface $parameter |
|
55 | - * @param PackagistApi $packagist |
|
56 | - */ |
|
57 | - public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter, PackagistApi $packagist) |
|
58 | - { |
|
59 | - $this->em = $em; |
|
60 | - $this->client = $client; |
|
61 | - $this->parameter = $parameter; |
|
62 | - $this->packagist = $packagist; |
|
63 | - $this->local_token = $parameter->get("ribs_admin.packages_token"); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getMessages(): array |
|
70 | - { |
|
71 | - return $this->messages; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param Package $package |
|
76 | - */ |
|
77 | - public function setPackageEntity(Package $package) |
|
78 | - { |
|
79 | - $this->package = $package; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @return mixed|null |
|
84 | - * @throws ClientExceptionInterface |
|
85 | - * @throws RedirectionExceptionInterface |
|
86 | - * @throws ServerExceptionInterface |
|
87 | - * @throws TransportExceptionInterface |
|
88 | - */ |
|
89 | - private function getToken() |
|
90 | - { |
|
91 | - $token = null; |
|
92 | - $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/dist/send-token/"); |
|
93 | - $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
94 | - |
|
95 | - if ($datas) { |
|
96 | - $token = json_decode($datas, true)["token"]; |
|
97 | - } |
|
98 | - |
|
99 | - return $token; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return mixed|null |
|
104 | - * @throws ClientExceptionInterface |
|
105 | - * @throws RedirectionExceptionInterface |
|
106 | - * @throws ServerExceptionInterface |
|
107 | - * @throws TransportExceptionInterface |
|
108 | - */ |
|
109 | - private function getComposerLockJson() |
|
110 | - { |
|
111 | - if ($this->package && !$this->package->isIsLocal()) { |
|
112 | - $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
113 | - $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
114 | - } else { |
|
115 | - $composer_lock = file_get_contents('../composer.lock'); |
|
116 | - } |
|
117 | - |
|
118 | - if ($composer_lock) { |
|
119 | - return json_decode($composer_lock, true); |
|
120 | - } |
|
121 | - |
|
122 | - return null; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return mixed|null |
|
127 | - * @throws ClientExceptionInterface |
|
128 | - * @throws RedirectionExceptionInterface |
|
129 | - * @throws ServerExceptionInterface |
|
130 | - * @throws TransportExceptionInterface |
|
131 | - */ |
|
132 | - public function getPackage() |
|
133 | - { |
|
134 | - $composer_lock = $this->getComposerLockJson(); |
|
135 | - if ($composer_lock) { |
|
136 | - $packages = $composer_lock["packages"]; |
|
137 | - $key = array_search($this->package->getPackageName(), array_column($packages, 'name')); |
|
138 | - |
|
139 | - if ($key) { |
|
140 | - return $packages[$key]; |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - $this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl(); |
|
145 | - |
|
146 | - return null; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return mixed|null |
|
151 | - * @throws ClientExceptionInterface |
|
152 | - * @throws RedirectionExceptionInterface |
|
153 | - * @throws ServerExceptionInterface |
|
154 | - * @throws TransportExceptionInterface |
|
155 | - */ |
|
156 | - public function getVersion() |
|
157 | - { |
|
158 | - return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @return DateTime|null |
|
163 | - * @throws Exception |
|
164 | - */ |
|
165 | - public function getVersionDate(): ?DateTime |
|
166 | - { |
|
167 | - $string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null; |
|
168 | - $version_date = null; |
|
169 | - |
|
170 | - if ($string_date) { |
|
171 | - $version_date = new DateTime($string_date); |
|
172 | - } |
|
173 | - |
|
174 | - return $version_date; |
|
175 | - } |
|
176 | - |
|
177 | - public function updatePackage(string $guid, string $version) |
|
178 | - { |
|
179 | - $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
180 | - |
|
181 | - if ($package) { |
|
182 | - $this->setPackageEntity($package); |
|
183 | - |
|
184 | - if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
185 | - $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
186 | - return; |
|
187 | - } |
|
188 | - |
|
189 | - $this->client->request("GET", $this->package->getProjectUrl().'ribs-admin/packages/dist/change-version/'.$package->getPackageName().':'.$version); |
|
190 | - //$composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
191 | - |
|
192 | - $this->save($guid); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param string $package_guid |
|
198 | - * @throws ClientExceptionInterface |
|
199 | - * @throws RedirectionExceptionInterface |
|
200 | - * @throws ServerExceptionInterface |
|
201 | - * @throws TransportExceptionInterface |
|
202 | - */ |
|
203 | - public function save(string $package_guid) |
|
204 | - { |
|
205 | - $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]); |
|
206 | - |
|
207 | - if ($package) { |
|
208 | - $this->setPackageEntity($package); |
|
209 | - |
|
210 | - if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
211 | - $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
212 | - return; |
|
213 | - } |
|
214 | - |
|
215 | - $package->setVersion($this->getVersion()); |
|
216 | - $package->setVersionDate($this->getVersionDate()); |
|
217 | - $package->setLastPackagistVersion($this->packagist->getLastPackagistVersion($package->getPackageName())); |
|
218 | - $package->setLastCheck(new DateTime()); |
|
219 | - |
|
220 | - $this->em->persist($package); |
|
221 | - $this->em->flush(); |
|
222 | - } |
|
223 | - } |
|
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 PackagistApi |
|
35 | + */ |
|
36 | + private $packagist; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var mixed |
|
40 | + */ |
|
41 | + private $local_token; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var Package |
|
45 | + */ |
|
46 | + private $package; |
|
47 | + |
|
48 | + private $messages = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * Version constructor. |
|
52 | + * @param EntityManagerInterface $em |
|
53 | + * @param HttpClientInterface $client |
|
54 | + * @param ParameterBagInterface $parameter |
|
55 | + * @param PackagistApi $packagist |
|
56 | + */ |
|
57 | + public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter, PackagistApi $packagist) |
|
58 | + { |
|
59 | + $this->em = $em; |
|
60 | + $this->client = $client; |
|
61 | + $this->parameter = $parameter; |
|
62 | + $this->packagist = $packagist; |
|
63 | + $this->local_token = $parameter->get("ribs_admin.packages_token"); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getMessages(): array |
|
70 | + { |
|
71 | + return $this->messages; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param Package $package |
|
76 | + */ |
|
77 | + public function setPackageEntity(Package $package) |
|
78 | + { |
|
79 | + $this->package = $package; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @return mixed|null |
|
84 | + * @throws ClientExceptionInterface |
|
85 | + * @throws RedirectionExceptionInterface |
|
86 | + * @throws ServerExceptionInterface |
|
87 | + * @throws TransportExceptionInterface |
|
88 | + */ |
|
89 | + private function getToken() |
|
90 | + { |
|
91 | + $token = null; |
|
92 | + $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/dist/send-token/"); |
|
93 | + $datas = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
94 | + |
|
95 | + if ($datas) { |
|
96 | + $token = json_decode($datas, true)["token"]; |
|
97 | + } |
|
98 | + |
|
99 | + return $token; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return mixed|null |
|
104 | + * @throws ClientExceptionInterface |
|
105 | + * @throws RedirectionExceptionInterface |
|
106 | + * @throws ServerExceptionInterface |
|
107 | + * @throws TransportExceptionInterface |
|
108 | + */ |
|
109 | + private function getComposerLockJson() |
|
110 | + { |
|
111 | + if ($this->package && !$this->package->isIsLocal()) { |
|
112 | + $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl()); |
|
113 | + $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
114 | + } else { |
|
115 | + $composer_lock = file_get_contents('../composer.lock'); |
|
116 | + } |
|
117 | + |
|
118 | + if ($composer_lock) { |
|
119 | + return json_decode($composer_lock, true); |
|
120 | + } |
|
121 | + |
|
122 | + return null; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return mixed|null |
|
127 | + * @throws ClientExceptionInterface |
|
128 | + * @throws RedirectionExceptionInterface |
|
129 | + * @throws ServerExceptionInterface |
|
130 | + * @throws TransportExceptionInterface |
|
131 | + */ |
|
132 | + public function getPackage() |
|
133 | + { |
|
134 | + $composer_lock = $this->getComposerLockJson(); |
|
135 | + if ($composer_lock) { |
|
136 | + $packages = $composer_lock["packages"]; |
|
137 | + $key = array_search($this->package->getPackageName(), array_column($packages, 'name')); |
|
138 | + |
|
139 | + if ($key) { |
|
140 | + return $packages[$key]; |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + $this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl(); |
|
145 | + |
|
146 | + return null; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return mixed|null |
|
151 | + * @throws ClientExceptionInterface |
|
152 | + * @throws RedirectionExceptionInterface |
|
153 | + * @throws ServerExceptionInterface |
|
154 | + * @throws TransportExceptionInterface |
|
155 | + */ |
|
156 | + public function getVersion() |
|
157 | + { |
|
158 | + return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @return DateTime|null |
|
163 | + * @throws Exception |
|
164 | + */ |
|
165 | + public function getVersionDate(): ?DateTime |
|
166 | + { |
|
167 | + $string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null; |
|
168 | + $version_date = null; |
|
169 | + |
|
170 | + if ($string_date) { |
|
171 | + $version_date = new DateTime($string_date); |
|
172 | + } |
|
173 | + |
|
174 | + return $version_date; |
|
175 | + } |
|
176 | + |
|
177 | + public function updatePackage(string $guid, string $version) |
|
178 | + { |
|
179 | + $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $guid]); |
|
180 | + |
|
181 | + if ($package) { |
|
182 | + $this->setPackageEntity($package); |
|
183 | + |
|
184 | + if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
185 | + $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
186 | + return; |
|
187 | + } |
|
188 | + |
|
189 | + $this->client->request("GET", $this->package->getProjectUrl().'ribs-admin/packages/dist/change-version/'.$package->getPackageName().':'.$version); |
|
190 | + //$composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null; |
|
191 | + |
|
192 | + $this->save($guid); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param string $package_guid |
|
198 | + * @throws ClientExceptionInterface |
|
199 | + * @throws RedirectionExceptionInterface |
|
200 | + * @throws ServerExceptionInterface |
|
201 | + * @throws TransportExceptionInterface |
|
202 | + */ |
|
203 | + public function save(string $package_guid) |
|
204 | + { |
|
205 | + $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]); |
|
206 | + |
|
207 | + if ($package) { |
|
208 | + $this->setPackageEntity($package); |
|
209 | + |
|
210 | + if (!$this->getToken() || $this->getToken() !== $this->local_token) { |
|
211 | + $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl(); |
|
212 | + return; |
|
213 | + } |
|
214 | + |
|
215 | + $package->setVersion($this->getVersion()); |
|
216 | + $package->setVersionDate($this->getVersionDate()); |
|
217 | + $package->setLastPackagistVersion($this->packagist->getLastPackagistVersion($package->getPackageName())); |
|
218 | + $package->setLastCheck(new DateTime()); |
|
219 | + |
|
220 | + $this->em->persist($package); |
|
221 | + $this->em->flush(); |
|
222 | + } |
|
223 | + } |
|
224 | 224 | } |