-
Notifications
You must be signed in to change notification settings - Fork 30
Introduces various improvements (wip) #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,8 +96,24 @@ public function execute(Arguments $args, ConsoleIo $io): void | |
| $packagesTable = $this->fetchTable('Packages'); | ||
| $touchedIds = []; | ||
|
|
||
| $data = $this->client->all(['type' => 'cakephp-plugin']); | ||
| foreach ($data as $package) { | ||
| $io->out('Fetching package list from Packagist...'); | ||
| $packages = $this->client->all(['type' => 'cakephp-plugin']); | ||
| $total = count($packages); | ||
| $io->out(sprintf('Found <info>%d</info> packages. Processing...', $total)); | ||
|
|
||
| $saved = 0; | ||
| $skipped = 0; | ||
| $failed = 0; | ||
| $i = 0; | ||
|
|
||
| $progress = $io->helper('Progress'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to have sync commands like this not output anything at all when the sync is executed. Otherwise the containers stdout log would get bloated with this kind of stuff. We can keep this with a optional verbose or progress options though
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just talked with josbeir and he said I could just add a |
||
| $progress->init(['total' => $total, 'width' => 60]); | ||
| $io->out('', 0); | ||
|
|
||
| foreach ($packages as $package) { | ||
| $i++; | ||
| $io->out(sprintf('[%d/%d] %s', $i, $total, $package), 1, ConsoleIo::VERBOSE); | ||
|
|
||
| $data = $this->getDataForPackage($package); | ||
|
|
||
| if ( | ||
|
|
@@ -106,6 +122,8 @@ public function execute(Arguments $args, ConsoleIo $io): void | |
| $data['downloads'] < 10 || | ||
| !$this->hasExplicitCakePhpDependency($data['tag_list']) | ||
| ) { | ||
| $skipped++; | ||
| $progress->increment()->draw(); | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -116,26 +134,49 @@ public function execute(Arguments $args, ConsoleIo $io): void | |
|
|
||
| $entity = $packagesTable->patchEntity($entity, $data); | ||
| if (!$packagesTable->save($entity)) { | ||
| $failed++; | ||
| Log::warning('Unable to save package', [ | ||
| 'package' => $package->getName(), | ||
| 'package' => $package, | ||
| 'errors' => $entity->getErrors(), | ||
| ]); | ||
| } else { | ||
| $saved++; | ||
| } | ||
| $touchedIds[] = $entity->id; | ||
| $progress->increment()->draw(); | ||
| } | ||
|
|
||
| $io->out(''); | ||
| $io->out(sprintf( | ||
| 'Sync complete. Saved: <info>%d</info>, Skipped: <comment>%d</comment>, Failed: <error>%d</error>', | ||
| $saved, | ||
| $skipped, | ||
| $failed, | ||
| )); | ||
|
|
||
| // Remove packages that were not touched | ||
| $io->out('Removing stale packages...'); | ||
| $deleted = 0; | ||
| $deleteFailed = 0; | ||
| /** @var \Cake\ORM\ResultSet<array-key, \App\Model\Entity\Package> $toDeletePackages */ | ||
| $toDeletePackages = $packagesTable->find()->where(['id NOT IN' => $touchedIds])->all(); | ||
| foreach ($toDeletePackages as $package) { | ||
| if (!$packagesTable->delete($package)) { | ||
| $deleteFailed++; | ||
| Log::warning('Unable to delete package', [ | ||
| 'package' => $package->package, | ||
| 'id' => $package->id, | ||
| 'errors' => $package->getErrors(), | ||
| ]); | ||
| } else { | ||
| $deleted++; | ||
| } | ||
| } | ||
| $io->out(sprintf( | ||
| 'Cleanup complete. Deleted: <info>%d</info>, Failed: <error>%d</error>', | ||
| $deleted, | ||
| $deleteFailed, | ||
| )); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.