Skip to content

Commit 6ad008e

Browse files
committed
adjust sync packages command to use other api endpoint
1 parent 2dc7bc0 commit 6ad008e

5 files changed

Lines changed: 21 additions & 31 deletions

File tree

config/Migrations/20250921094317_Initial.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public function change(): void
1919
->addColumn('package', 'string')
2020
->addColumn('description', 'text')
2121
->addColumn('repo_url', 'string')
22-
->addColumn('packagist_url', 'string')
2322
->addColumn('downloads', 'integer')
2423
->addColumn('stars', 'integer')
2524
->create();
-1.9 KB
Binary file not shown.

src/Command/SyncPackagesCommand.php

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,11 @@ public function execute(Arguments $args, ConsoleIo $io)
6666
{
6767
$packagesTable = $this->fetchTable('Packages');
6868

69-
/** @var \Packagist\Api\Result\Result $package */
70-
foreach ($this->client->search('', ['type' => 'cakephp-plugin']) as $package) {
71-
$tags = $this->getTagsForPackage($package->getName());
72-
$data = [
73-
'package' => $package->getName(),
74-
'description' => $package->getDescription(),
75-
'repo_url' => $package->getRepository(),
76-
'packagist_url' => $package->getUrl(),
77-
'downloads' => $package->getDownloads(),
78-
'stars' => $package->getFavers(),
79-
'tag_list' => $tags,
80-
];
81-
82-
$entity = $packagesTable->find()->where(['package' => $package->getName()])->first();
69+
$data = $this->client->all(['type' => 'cakephp-plugin']);
70+
foreach ($data as $package) {
71+
$data = $this->getDataForPackage($package);
72+
73+
$entity = $packagesTable->find()->where(['package' => $package])->first();
8374
if (!$entity) {
8475
$entity = $packagesTable->newEmptyEntity();
8576
}
@@ -98,21 +89,19 @@ public function execute(Arguments $args, ConsoleIo $io)
9889
* @param string $packageName
9990
* @return array
10091
*/
101-
private function getTagsForPackage(string $packageName): array
92+
private function getDataForPackage(string $packageName): array
10293
{
103-
$metaDetails = $this->client->getComposer($packageName);
104-
10594
/** @var \Packagist\Api\Result\Package $metaDetails */
106-
$metaDetails = $metaDetails[$packageName];
95+
$metaDetails = $this->client->get($packageName);
10796
$versions = $metaDetails->getVersions();
10897

10998
$meta = [];
11099
// Check each version
111100
foreach ($versions as $versionMeta) {
112-
$phpRequire = $versionMeta->getRequire()['php'] ?? null;
113-
if ($phpRequire) {
114-
$meta = $this->checkPHPVersion($meta, $phpRequire);
115-
}
101+
// $phpRequire = $versionMeta->getRequire()['php'] ?? null;
102+
// if ($phpRequire) {
103+
// $meta = $this->checkPHPVersion($meta, $phpRequire);
104+
// }
116105

117106
$cakephpRequire = $versionMeta->getRequire()['cakephp/cakephp'] ?? null;
118107
if ($cakephpRequire) {
@@ -144,7 +133,16 @@ private function getTagsForPackage(string $packageName): array
144133
}
145134
}
146135

147-
return $meta;
136+
$data = [
137+
'package' => $packageName,
138+
'description' => $metaDetails->getDescription(),
139+
'repo_url' => $metaDetails->getRepository(),
140+
'downloads' => $metaDetails->getDownloads()->getTotal(),
141+
'stars' => $metaDetails->getGithubStars(),
142+
'tag_list' => $meta,
143+
];
144+
145+
return $data;
148146
}
149147

150148
/**

src/Model/Entity/Package.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @property string $package
1313
* @property string $description
1414
* @property string $repo_url
15-
* @property string $packagist_url
1615
* @property int $downloads
1716
* @property int $stars
1817
*/

src/Model/Table/PackagesTable.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ public function validationDefault(Validator $validator): Validator
7070
->requirePresence('repo_url', 'create')
7171
->notEmptyString('repo_url');
7272

73-
$validator
74-
->scalar('packagist_url')
75-
->maxLength('packagist_url', 255)
76-
->requirePresence('packagist_url', 'create')
77-
->notEmptyString('packagist_url');
78-
7973
$validator
8074
->integer('downloads')
8175
->requirePresence('downloads', 'create')

0 commit comments

Comments
 (0)