Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ddev/docker-compose.phpmyadmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
- HTTPS_EXPOSE=8037:80
healthcheck:
test: ["CMD-SHELL", "true"]
interval: 120s
interval: 5s
timeout: 2s
retries: 1
depends_on:
Expand Down
47 changes: 44 additions & 3 deletions src/Command/SyncPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just talked with josbeir and he said I could just add a --quiet option to the command in cron. I am fine with that as well

$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 (
Expand All @@ -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;
}

Expand All @@ -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,
));
}

/**
Expand Down
6 changes: 2 additions & 4 deletions templates/element/navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
</div>
</div>
</li>
<li role="separator" class="p-0"><hr class="divider my-0" /></li>
<li>
<li class="border-t border-base-300 pt-1">
<?= $this->Html->link('Sign out', [
'controller' => 'Users',
'action' => 'logout',
Expand Down Expand Up @@ -92,8 +91,7 @@
<li><?= $this->Html->link('Docs', 'https://book.cakephp.org/', ['target' => '_blank', 'rel' => 'noopener']) ?></li>
<li><?= $this->Html->link('API', 'https://api.cakephp.org/', ['target' => '_blank', 'rel' => 'noopener']) ?></li>
<?php if (!$this->Identity->isLoggedIn()) : ?>
<li role="separator" class="p-0"><hr class="divider my-0" /></li>
<li>
<li class="border-t border-base-300 pt-1">
<?= $this->Form->postLink(
'Sign in with GitHub',
[
Expand Down
Loading