Skip to content

Commit 4c5fd00

Browse files
committed
duplicates on rebuild fix
Signed-off-by: Jurj-Bogdan <jurj@dotkernel.com>
1 parent d94141a commit 4c5fd00

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

data/ecosystem/ecosystem-packages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
{
6363
"packagistUrl": "https://packagist.org/packages/roave/psr-container-doctrine",
64-
"keywords": ["middleware", "doctrine", "psr"],
64+
"keywords": ["intentional-duplicate"],
6565
"homepage": "",
6666
"category": "integration"
6767
},

src/Ecosystem/Console/CreateEcosystemDatabase.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use function filter_var;
3030
use function getcwd;
3131
use function implode;
32+
use function in_array;
3233
use function is_array;
3334
use function is_string;
3435
use function json_decode;
@@ -53,9 +54,8 @@ class CreateEcosystemDatabase extends Command
5354

5455
private CurlHandle $curl;
5556
private CurlHandle $githubCurl;
56-
private ?string $ghToken = null;
57-
private bool $forceRebuild = false;
58-
private array $validPackages = [];
57+
private ?string $ghToken = null;
58+
private bool $forceRebuild = false;
5959
public PdoMapper $mapper;
6060

6161
/** @var string[] */
@@ -218,8 +218,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int
218218
$pdo = $this->createDatabase($dbFile);
219219
$this->initCurl();
220220

221+
$validPackages = [];
221222
/** @var array{packagistUrl: string, keywords: array<string>, homepage: string, category: string} $userData */
222223
foreach ($userDataArray as $userData) {
224+
$urlComponents = [];
225+
preg_match('/packagist.org\/packages\/((?>\w-?)+\/(?>\w-?)+)/i', $userData['packagistUrl'], $urlComponents);
226+
227+
if (in_array($urlComponents[1], $validPackages)) {
228+
continue;
229+
}
230+
231+
$validPackages[] = $urlComponents[1];
232+
233+
if (! $this->forceRebuild) {
234+
$existingPackage = $this->mapper->searchPackage($urlComponents[1]);
235+
if ($existingPackage !== null && $existingPackage !== []) {
236+
continue;
237+
}
238+
}
239+
240+
$userData['packagistUrl'] = $urlComponents[1];
241+
223242
$curlResult = $this->getPackageData($userData);
224243
if ($curlResult === null) {
225244
continue;
@@ -235,7 +254,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
235254

236255
if (! $this->forceRebuild) {
237256
$currentPackages = $this->mapper->getPackagesTitles();
238-
$removedPackages = array_diff($currentPackages, $this->validPackages);
257+
$removedPackages = array_diff($currentPackages, $validPackages);
239258
/** @var string $package */
240259
foreach ($removedPackages as $package) {
241260
$this->mapper->deletePackageByName($package);
@@ -285,20 +304,9 @@ public function createDatabase(string $path): PDO
285304
*/
286305
private function getPackageData(array $userData): ?array
287306
{
288-
$urlComponents = [];
289-
preg_match('/packagist.org\/packages\/((?>\w-?)+\/(?>\w-?)+)/i', $userData['packagistUrl'], $urlComponents);
290-
291-
if (! $this->forceRebuild) {
292-
$this->validPackages[] = $urlComponents[1];
293-
$existingPackage = $this->mapper->searchPackage($urlComponents[1]);
294-
if ($existingPackage !== null && $existingPackage !== []) {
295-
return null;
296-
}
297-
}
298-
299307
$packagistUrl = sprintf(
300308
'https://packagist.org/packages/%s.json',
301-
$urlComponents[1]
309+
$userData['packagistUrl']
302310
);
303311
curl_setopt($this->curl, CURLOPT_URL, $packagistUrl);
304312
$rawResult = curl_exec($this->curl);

src/Ecosystem/Console/SeedEcosystemDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
152152
private function getPackageData(array $package): array
153153
{
154154
$packagistUrl = sprintf(
155-
'https://repo.packagist.org/packages/%s.json',
155+
'https://packagist.org/packages/%s.json',
156156
$package['name'],
157157
);
158158
curl_setopt($this->curl, CURLOPT_URL, $packagistUrl);

0 commit comments

Comments
 (0)