Skip to content

Commit db858dc

Browse files
committed
Avoid dumping root repeatedly
1 parent 7170ae5 commit db858dc

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

src/Command/DumpPackagesV2Command.php

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9898

9999
$iterations = $force ? 1 : 120;
100100
try {
101+
$this->dumper->dumpRoot($verbose);
102+
101103
while ($iterations--) {
102104
if ($force) {
103105
$ids = $this->getEM()->getConnection()->fetchFirstColumn('SELECT id FROM package WHERE frozen IS NULL ORDER BY id ASC');

src/Package/V2Dumper.php

+34-31
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,10 @@ public function __construct(
6161
$this->webDir = $webDir;
6262
}
6363

64-
/**
65-
* Dump a set of packages to the web root
66-
*
67-
* @param list<int> $packageIds
68-
*/
69-
public function dump(array $packageIds, bool $force = false, bool $verbose = false): void
64+
public function dumpRoot(bool $verbose = false): void
7065
{
71-
// prepare build dir
72-
$webDir = $this->webDir;
73-
74-
$buildDirV2 = $this->buildDir.'/p2';
75-
76-
// initialize
77-
$initialRun = false;
78-
if (!is_dir($buildDirV2)) {
79-
$initialRun = true;
80-
$this->filesystem->mkdir($buildDirV2);
81-
}
82-
$buildDirV2 = realpath($buildDirV2);
83-
Assert::string($buildDirV2);
84-
85-
// copy existing stuff for smooth BC transition
86-
if ($initialRun && !$force) {
87-
throw new \RuntimeException('Run this again with --force the first time around to make sure it dumps all packages');
88-
}
89-
90-
if ($verbose) {
91-
echo 'Web dir is '.$webDir.'/p2 ('.realpath($webDir.'/p2').')'.PHP_EOL;
92-
echo 'Build v2 dir is '.$buildDirV2.PHP_EOL;
93-
}
94-
9566
// prepare root file
96-
$rootFile = $webDir.'/packages.json';
67+
$rootFile = $this->webDir.'/packages.json';
9768
$rootFileContents = [
9869
'packages' => []
9970
];
@@ -138,6 +109,38 @@ public function dump(array $packageIds, bool $force = false, bool $verbose = fal
138109
echo 'Dumping root'.PHP_EOL;
139110
}
140111
$this->dumpRootFile($rootFile, json_encode($rootFileContents, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
112+
}
113+
114+
/**
115+
* Dump a set of packages to the web root
116+
*
117+
* @param list<int> $packageIds
118+
*/
119+
public function dump(array $packageIds, bool $force = false, bool $verbose = false): void
120+
{
121+
// prepare build dir
122+
$webDir = $this->webDir;
123+
124+
$buildDirV2 = $this->buildDir.'/p2';
125+
126+
// initialize
127+
$initialRun = false;
128+
if (!is_dir($buildDirV2)) {
129+
$initialRun = true;
130+
$this->filesystem->mkdir($buildDirV2);
131+
}
132+
$buildDirV2 = realpath($buildDirV2);
133+
Assert::string($buildDirV2);
134+
135+
// copy existing stuff for smooth BC transition
136+
if ($initialRun && !$force) {
137+
throw new \RuntimeException('Run this again with --force the first time around to make sure it dumps all packages');
138+
}
139+
140+
if ($verbose) {
141+
echo 'Web dir is '.$webDir.'/p2 ('.realpath($webDir.'/p2').')'.PHP_EOL;
142+
echo 'Build v2 dir is '.$buildDirV2.PHP_EOL;
143+
}
141144

142145
$dumpTimeUpdates = [];
143146

0 commit comments

Comments
 (0)