@@ -12,59 +12,59 @@ |
||
| 12 | 12 | |
| 13 | 13 | class ChangePackageVersionCommand extends Command |
| 14 | 14 | { |
| 15 | - protected function configure() |
|
| 16 | - { |
|
| 17 | - $this |
|
| 18 | - ->setName('ribsadmin:change-package-version') |
|
| 19 | - ->setDescription('Change a package version') |
|
| 20 | - ->addArgument( |
|
| 21 | - 'package-name', |
|
| 22 | - InputArgument::REQUIRED, |
|
| 23 | - 'Name of composer package to import with version (example : piou/piou/test-bundle:1.0.0)' |
|
| 24 | - ) |
|
| 25 | - ; |
|
| 26 | - } |
|
| 15 | + protected function configure() |
|
| 16 | + { |
|
| 17 | + $this |
|
| 18 | + ->setName('ribsadmin:change-package-version') |
|
| 19 | + ->setDescription('Change a package version') |
|
| 20 | + ->addArgument( |
|
| 21 | + 'package-name', |
|
| 22 | + InputArgument::REQUIRED, |
|
| 23 | + 'Name of composer package to import with version (example : piou/piou/test-bundle:1.0.0)' |
|
| 24 | + ) |
|
| 25 | + ; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
| 29 | - { |
|
| 30 | - $fs = new Filesystem(); |
|
| 31 | - $cd = ""; |
|
| 28 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
| 29 | + { |
|
| 30 | + $fs = new Filesystem(); |
|
| 31 | + $cd = ""; |
|
| 32 | 32 | |
| 33 | - if (!$fs->exists("composer.json") && $fs->exists("index.php")) { |
|
| 34 | - $cd = "cd .. && "; |
|
| 35 | - } |
|
| 33 | + if (!$fs->exists("composer.json") && $fs->exists("index.php")) { |
|
| 34 | + $cd = "cd .. && "; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - $package_name = $input->getArgument('package-name'); |
|
| 37 | + $package_name = $input->getArgument('package-name'); |
|
| 38 | 38 | |
| 39 | - $process = Process::fromShellCommandline("echo Start composer require " . $package_name); |
|
| 40 | - $process->run(function ($type, $buffer) { |
|
| 41 | - echo $buffer; |
|
| 42 | - }); |
|
| 39 | + $process = Process::fromShellCommandline("echo Start composer require " . $package_name); |
|
| 40 | + $process->run(function ($type, $buffer) { |
|
| 41 | + echo $buffer; |
|
| 42 | + }); |
|
| 43 | 43 | |
| 44 | - $process = Process::fromShellCommandline($cd . "chmod 777 composer.json"); |
|
| 45 | - $process->run(function ($type, $buffer) { |
|
| 46 | - echo $buffer; |
|
| 47 | - }); |
|
| 44 | + $process = Process::fromShellCommandline($cd . "chmod 777 composer.json"); |
|
| 45 | + $process->run(function ($type, $buffer) { |
|
| 46 | + echo $buffer; |
|
| 47 | + }); |
|
| 48 | 48 | |
| 49 | - $process = Process::fromShellCommandline($cd . "composer require " . $package_name); |
|
| 50 | - $process->run(function ($type, $buffer) { |
|
| 51 | - echo $buffer; |
|
| 52 | - }); |
|
| 49 | + $process = Process::fromShellCommandline($cd . "composer require " . $package_name); |
|
| 50 | + $process->run(function ($type, $buffer) { |
|
| 51 | + echo $buffer; |
|
| 52 | + }); |
|
| 53 | 53 | |
| 54 | - if (!$process->isSuccessful()) { |
|
| 55 | - throw new ProcessFailedException($process); |
|
| 56 | - } |
|
| 54 | + if (!$process->isSuccessful()) { |
|
| 55 | + throw new ProcessFailedException($process); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $process = Process::fromShellCommandline($cd . "chmod 644 composer.json"); |
|
| 59 | - $process->run(function ($type, $buffer) { |
|
| 60 | - echo $buffer; |
|
| 61 | - }); |
|
| 58 | + $process = Process::fromShellCommandline($cd . "chmod 644 composer.json"); |
|
| 59 | + $process->run(function ($type, $buffer) { |
|
| 60 | + echo $buffer; |
|
| 61 | + }); |
|
| 62 | 62 | |
| 63 | - $process = Process::fromShellCommandline("echo Change version of " . $package_name . " is finished."); |
|
| 64 | - $process->run(function ($type, $buffer) { |
|
| 65 | - echo $buffer; |
|
| 66 | - }); |
|
| 63 | + $process = Process::fromShellCommandline("echo Change version of " . $package_name . " is finished."); |
|
| 64 | + $process->run(function ($type, $buffer) { |
|
| 65 | + echo $buffer; |
|
| 66 | + }); |
|
| 67 | 67 | |
| 68 | - return 0; |
|
| 69 | - } |
|
| 68 | + return 0; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -37,17 +37,17 @@ discard block |
||
| 37 | 37 | $package_name = $input->getArgument('package-name'); |
| 38 | 38 | |
| 39 | 39 | $process = Process::fromShellCommandline("echo Start composer require " . $package_name); |
| 40 | - $process->run(function ($type, $buffer) { |
|
| 40 | + $process->run(function($type, $buffer) { |
|
| 41 | 41 | echo $buffer; |
| 42 | 42 | }); |
| 43 | 43 | |
| 44 | 44 | $process = Process::fromShellCommandline($cd . "chmod 777 composer.json"); |
| 45 | - $process->run(function ($type, $buffer) { |
|
| 45 | + $process->run(function($type, $buffer) { |
|
| 46 | 46 | echo $buffer; |
| 47 | 47 | }); |
| 48 | 48 | |
| 49 | 49 | $process = Process::fromShellCommandline($cd . "composer require " . $package_name); |
| 50 | - $process->run(function ($type, $buffer) { |
|
| 50 | + $process->run(function($type, $buffer) { |
|
| 51 | 51 | echo $buffer; |
| 52 | 52 | }); |
| 53 | 53 | |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $process = Process::fromShellCommandline($cd . "chmod 644 composer.json"); |
| 59 | - $process->run(function ($type, $buffer) { |
|
| 59 | + $process->run(function($type, $buffer) { |
|
| 60 | 60 | echo $buffer; |
| 61 | 61 | }); |
| 62 | 62 | |
| 63 | 63 | $process = Process::fromShellCommandline("echo Change version of " . $package_name . " is finished."); |
| 64 | - $process->run(function ($type, $buffer) { |
|
| 64 | + $process->run(function($type, $buffer) { |
|
| 65 | 65 | echo $buffer; |
| 66 | 66 | }); |
| 67 | 67 | |
@@ -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); |