Skip to content

Commit 51c0ad4

Browse files
committed
Add a way to unfreeze packages from the cli
1 parent f2070c2 commit 51c0ad4

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of Packagist.
5+
*
6+
* (c) Jordi Boggiano <[email protected]>
7+
* Nils Adermann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace App\Command;
14+
15+
use App\Service\Scheduler;
16+
use Doctrine\Persistence\ManagerRegistry;
17+
use App\Entity\Package;
18+
use App\Model\ProviderManager;
19+
use Symfony\Component\Console\Command\Command;
20+
use Symfony\Component\Console\Input\InputArgument;
21+
use Symfony\Component\Console\Input\InputInterface;
22+
use Symfony\Component\Console\Output\OutputInterface;
23+
24+
class UnfreezePackageCommand extends Command
25+
{
26+
use \App\Util\DoctrineTrait;
27+
28+
private ProviderManager $providerManager;
29+
private ManagerRegistry $doctrine;
30+
private Scheduler $scheduler;
31+
32+
public function __construct(ProviderManager $providerManager, ManagerRegistry $doctrine, Scheduler $scheduler)
33+
{
34+
$this->providerManager = $providerManager;
35+
$this->doctrine = $doctrine;
36+
parent::__construct();
37+
$this->scheduler = $scheduler;
38+
}
39+
40+
protected function configure(): void
41+
{
42+
$this
43+
->setName('packagist:unfreeze')
44+
->setDefinition([
45+
new InputArgument('package', InputArgument::REQUIRED, 'Package name to unfreeze'),
46+
])
47+
->setDescription('Unfreezes a package, marks it for update and clears frozen status')
48+
;
49+
}
50+
51+
protected function execute(InputInterface $input, OutputInterface $output): int
52+
{
53+
$name = $input->getArgument('package');
54+
55+
$package = $this->getEM()->getRepository(Package::class)->findOneBy(['name' => $name]);
56+
if ($package === null) {
57+
$output->writeln('<error>Package '.$name.' not found</error>');
58+
return 1;
59+
}
60+
61+
$this->providerManager->insertPackage($package);
62+
$package->setCrawledAt(null);
63+
$package->setUpdatedAt(new \DateTimeImmutable());
64+
$package->unfreeze();
65+
66+
$this->getEM()->flush();
67+
68+
$this->scheduler->scheduleUpdate($package, 'unfreeze cmd', forceDump: true);
69+
70+
$output->writeln('<info>Package '.$name.' has been unfrozen and marked for update</info>');
71+
72+
return 0;
73+
}
74+
}

0 commit comments

Comments
 (0)