1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiouPiou\RibsAdminBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
6
|
|
|
use Exception; |
7
|
|
|
use PiouPiou\RibsAdminBundle\Entity\Package; |
8
|
|
|
use PiouPiou\RibsAdminBundle\Service\Version; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
10
|
|
|
use Symfony\Component\Console\Application; |
11
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
12
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
13
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
14
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
15
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
16
|
|
|
|
17
|
|
|
class PackagesDistController extends AbstractController |
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]); |
30
|
|
|
|
31
|
|
|
if ($package) { |
32
|
|
|
$version->setPackageEntity($package); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return new JsonResponse([ |
36
|
|
|
"package" => $version->getPackage(), |
37
|
|
|
"package_date" => $version->getVersionDate() |
38
|
|
|
]); |
39
|
|
|
} |
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'); |
48
|
|
|
|
49
|
|
|
if ($composer_lock) { |
50
|
|
|
$composer_lock = json_decode($composer_lock); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return new JsonResponse($composer_lock); |
54
|
|
|
} |
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
|
|
|
} |
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); |
79
|
|
|
|
80
|
|
|
$input = new ArrayInput([ |
|
|
|
|
81
|
|
|
'command' => 'ribsadmin:change-package-version', |
82
|
|
|
'package-name' => $package_name, |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
$output = new BufferedOutput(); |
86
|
|
|
$application->run($input, $output); |
87
|
|
|
$content = $output->fetch(); |
88
|
|
|
|
89
|
|
|
return new JsonResponse($content); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|