Skip to content

Commit 88633b4

Browse files
committed
Discover plugins compatible with upcoming CakePHP versions
1 parent 09fcbdc commit 88633b4

24 files changed

Lines changed: 700 additions & 49 deletions

‎Procfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
web: frankenphp run --config /etc/frankenphp/Caddyfile --adapter caddyfile
2-
release: sh -c 'bin/cake migrations migrate --no-lock -p Tags && bin/cake migrations migrate --no-lock && bin/cake migrations migrate --no-lock -p ADmad/SocialAuth'
2+
release: sh -c 'bin/cake migrations migrate --no-lock -p Tags && bin/cake migrations migrate --no-lock && bin/cake migrations migrate --no-lock -p ADmad/SocialAuth && bin/cake schema_cache clear'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Migrations\BaseMigration;
5+
6+
class AddDevelopmentCompatibility extends BaseMigration
7+
{
8+
/**
9+
* Indexed tags filter development support; JSON retains its source release metadata.
10+
*/
11+
public function change(): void
12+
{
13+
$this->table('packages')
14+
->addColumn('development_compatibility', 'json', ['null' => true, 'default' => null])
15+
->update();
16+
}
17+
}

‎config/app.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@
103103
],
104104

105105
'Packages' => [
106+
// Minor releases per stable major; null marks an upcoming development major.
107+
// Promote a major by replacing null with its released minors, e.g. 6 => [0].
108+
'cakephpVersions' => [
109+
3 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
110+
4 => [0, 1, 2, 3, 4, 5, 6],
111+
5 => [0, 1, 2, 3, 4],
112+
6 => null,
113+
],
106114
// Resolve moved or ambiguous Awesome-list repositories to an exact Composer package name.
107115
'awesomeAliases' => [],
108116
],

‎playwright.config.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default defineConfig({
1818
CACHE_DEFAULT_URL: 'array://',
1919
CACHE_CATALOGUE_URL: `file://${fileURLToPath(new URL('./tmp/browser-catalogue/', import.meta.url))}`,
2020
CACHE_GITHUB_PROFILES_URL: `file://${fileURLToPath(new URL('./tmp/browser-github-profiles/', import.meta.url))}`,
21-
CACHE_MODEL_URL: 'array://',
22-
CACHE_PERSISTENT_URL: 'array://',
21+
CACHE_CAKEMODEL_URL: 'array://',
22+
CACHE_CAKECORE_URL: 'array://',
2323
},
2424
},
2525
})

‎resources/css/style.css‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ body::before {
329329
@apply flex min-w-0 items-center p-1 [scrollbar-width:thin]
330330
[scrollbar-color:var(--color-control)_transparent];
331331
}
332+
.version-development {
333+
@apply border-dashed;
334+
}
332335
.version-pill {
333336
@apply h-auto min-h-6 shrink-0 rounded-full border-base-300 bg-transparent px-1.75 py-0.5 text-xs leading-tight
334337
font-medium whitespace-nowrap text-muted no-underline hover:border-primary hover:text-primary

‎src/Island/CatalogueIsland.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use App\Model\Table\CategoriesTable;
77
use App\Model\Table\PackagesTable;
8+
use App\Utility\CakephpVersion;
89
use Cake\Http\Exception\BadRequestException;
910
use Interact\Attribute\Action;
1011
use Interact\Attribute\Pagination;
@@ -167,7 +168,8 @@ public function viewData(): array
167168
throw new BadRequestException('Search query is too long.');
168169
}
169170
$options = $this->packages->filterOptions();
170-
$categoryOptions = $this->fetchTable(CategoriesTable::class)->unhydratedFind('catalogueOptions', namespace: $this->namespace)->all()->toArray();
171+
$includeDevelopment = array_any($this->cakephpSlugs, static fn(mixed $slug): bool => is_string($slug) && CakephpVersion::isDevelopmentSlug($slug));
172+
$categoryOptions = $this->fetchTable(CategoriesTable::class)->unhydratedFind('catalogueOptions', namespace: $this->namespace, includeDevelopment: $includeDevelopment)->all()->toArray();
171173
if (!array_key_exists($this->category, $categoryOptions)) {
172174
$this->category = '';
173175
}

‎src/Island/PublishersIsland.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace App\Island;
55

66
use App\Model\Table\PackagesTable;
7+
use App\Utility\CakephpVersion;
78
use Cake\Http\Exception\BadRequestException;
89
use Interact\Attribute\Action;
910
use Interact\Attribute\Pagination;
@@ -89,6 +90,12 @@ public function viewData(): array
8990
}
9091
}
9192
$versionOptions['all'] = __('All versions');
93+
foreach (CakephpVersion::developmentMajors() as $developmentMajor) {
94+
if (isset($packages->filterOptions()['cakephp'][CakephpVersion::developmentSlug($developmentMajor)])) {
95+
$label = CakephpVersion::developmentLabel($developmentMajor);
96+
$versionOptions[$label] = $label;
97+
}
98+
}
9299
if (!isset($versionOptions[$this->cakephp])) {
93100
$this->cakephp = $current !== null ? 'current' : 'all';
94101
}

‎src/Model/Entity/Package.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/**
1111
* Package Entity
1212
*
13+
* @phpstan-type DevelopmentRelease array{version: string, stability: string, cakephp_constraint: string, php_constraint: string|null}
14+
* @property array<int, array{version: string, stability: string, cakephp_constraint: string, php_constraint: string|null}>|null $development_compatibility
1315
* @property int $id
1416
* @property string $package
1517
* @property string $namespace

‎src/Model/Table/CategoriesTable.php‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,20 @@ public function initialize(array $config): void
4242
* @param \Cake\ORM\Query\SelectQuery<array<string, mixed>> $query Category query.
4343
* @return \Cake\ORM\Query\SelectQuery<array<string, mixed>>
4444
*/
45-
public function findCatalogueOptions(SelectQuery $query, ?string $namespace = null): SelectQuery
45+
public function findCatalogueOptions(SelectQuery $query, ?string $namespace = null, bool $includeDevelopment = false): SelectQuery
4646
{
47-
$query->select(['Categories.slug', 'Categories.name', 'package_count' => $query->func()->count('CategoryMemberships.package_id')])
47+
$packageJoin = ['CataloguePackages.id = CategoryMemberships.package_id'];
48+
if (!$includeDevelopment) {
49+
$packageJoin['CataloguePackages.latest_stable_version IS NOT'] = null;
50+
$packageJoin['CataloguePackages.downloads >='] = 10;
51+
}
52+
$query->select(['Categories.slug', 'Categories.name', 'package_count' => $query->func()->count('CataloguePackages.id')])
4853
->leftJoin(['CategoryMemberships' => 'categories_packages'], ['CategoryMemberships.category_id = Categories.id'])
54+
->leftJoin(['CataloguePackages' => 'packages'], $packageJoin)
4955
->groupBy(['Categories.id', 'Categories.slug', 'Categories.name'])
5056
->orderByAsc('Categories.name');
5157
if ($namespace !== null) {
52-
$query->innerJoin(['CataloguePackages' => 'packages'], ['CataloguePackages.id = CategoryMemberships.package_id'])
53-
->where(['CataloguePackages.namespace' => $namespace]);
58+
$query->where(['CataloguePackages.namespace' => $namespace]);
5459
}
5560
$query->formatResults(static fn(CollectionInterface $results): CollectionInterface => $results->combine(
5661
'slug',

‎src/Model/Table/PackagesTable.php‎

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
namespace App\Model\Table;
55

66
use App\Model\Filter\PackagesCollection;
7+
use App\Utility\CakephpVersion;
78
use ArrayObject;
89
use Cake\Cache\Cache;
910
use Cake\Collection\Collection;
1011
use Cake\Collection\CollectionInterface;
1112
use Cake\Database\Expression\FunctionExpression;
1213
use Cake\Database\Expression\QueryExpression;
14+
use Cake\Database\Schema\TableSchemaInterface;
1315
use Cake\Datasource\EntityInterface;
1416
use Cake\Event\EventInterface;
1517
use Cake\ORM\Query\SelectQuery;
1618
use Cake\ORM\Table;
1719
use Cake\Validation\Validator;
20+
use Override;
1821

1922
/**
2023
* Packages Model
@@ -72,6 +75,20 @@ public function initialize(array $config): void
7275
]);
7376
}
7477

78+
/**
79+
* MariaDB reflects JSON as LONGTEXT; keep Cake's JSON conversion on every driver.
80+
*/
81+
#[Override]
82+
public function getSchema(): TableSchemaInterface
83+
{
84+
$schema = parent::getSchema();
85+
if ($schema->hasColumn('development_compatibility')) {
86+
$schema->setColumnType('development_compatibility', 'json');
87+
}
88+
89+
return $schema;
90+
}
91+
7592
/**
7693
* Default validation rules.
7794
*
@@ -150,6 +167,11 @@ public function findCatalogue(SelectQuery $query, array $filters, ?string $names
150167
if ($namespace !== null) {
151168
$query->find('namespace', namespace: $namespace);
152169
}
170+
$versions = $filters['cakephp_slugs'] ?? [];
171+
$development = is_array($versions) && array_any($versions, static fn(mixed $slug): bool => is_string($slug) && CakephpVersion::isDevelopmentSlug($slug));
172+
if (!$development) {
173+
$query->find('released');
174+
}
153175
$query->find('search', search: $filters)
154176
->contain(['CommunityPicks', 'Categories', 'Tags' => static fn(SelectQuery $tags) => $tags->orderByDesc('Tags.label')]);
155177
if (!empty($filters['featured'])) {
@@ -170,6 +192,21 @@ public function findCatalogue(SelectQuery $query, array $filters, ?string $names
170192
return $this->cachePublicQuery($query, 'catalogue', count: true);
171193
}
172194

195+
/**
196+
* Preserve the normal directory's published-release and download eligibility.
197+
*
198+
* @template TSubject of \Cake\Datasource\EntityInterface|array
199+
* @param \Cake\ORM\Query\SelectQuery<TSubject> $query Package query.
200+
* @return \Cake\ORM\Query\SelectQuery<TSubject>
201+
*/
202+
public function findReleased(SelectQuery $query): SelectQuery
203+
{
204+
return $query->where([
205+
$this->aliasField('latest_stable_version') . ' IS NOT' => null,
206+
$this->aliasField('downloads') . ' >=' => 10,
207+
]);
208+
}
209+
173210
/**
174211
* Match the indexed Composer namespace exactly.
175212
*
@@ -210,6 +247,8 @@ public function findPublishers(SelectQuery $query, string $search = '', string $
210247

211248
if ($major !== null) {
212249
$query->find('cakephpCompatible', major: $major);
250+
} else {
251+
$query->find('released');
213252
}
214253

215254
$search = mb_strtolower(trim($search));
@@ -247,7 +286,7 @@ public function findPublisherDetails(SelectQuery $query, array $namespaces, stri
247286
'stars', 'downloads' => $sort,
248287
default => 'monthly_downloads',
249288
};
250-
$query->select(['id', 'namespace', 'package', 'repo_url'])
289+
$query->select(['id', 'namespace', 'package', 'repo_url', 'latest_stable_version', 'downloads'])
251290
->where($namespaces === [] ? ['1 = 0'] : ['namespace IN' => $namespaces])
252291
->orderBy([
253292
$this->aliasField($metric) => 'DESC',
@@ -264,7 +303,9 @@ public function findPublisherDetails(SelectQuery $query, array $namespaces, stri
264303

265304
return [
266305
'githubUrl' => count($owners) === 1 ? 'https://github.com/' . $owners[0] : null,
267-
'plugins' => $packages->filter(static fn(array|EntityInterface $row): bool => $major === null || (bool)$row['publisher_compatible'])
306+
'plugins' => $packages->filter(static fn(array|EntityInterface $row): bool => (CakephpVersion::isDevelopmentLabel($major ?? '')
307+
|| ($row['latest_stable_version'] !== null && $row['downloads'] >= 10))
308+
&& ($major === null || (bool)$row['publisher_compatible']))
268309
->take(2)->map(static fn(array|EntityInterface $row): array => [
269310
'id' => $row['id'],
270311
'package' => $row['package'],
@@ -289,6 +330,10 @@ public function findPublisherDetails(SelectQuery $query, array $namespaces, stri
289330
*/
290331
public function findCakephpCompatible(SelectQuery $query, string $major): SelectQuery
291332
{
333+
if (!CakephpVersion::isDevelopmentLabel($major)) {
334+
$query->find('released');
335+
}
336+
292337
return $query->where($query->expr()->exists($this->publisherCompatibility($major)));
293338
}
294339

@@ -306,7 +351,9 @@ private function publisherCompatibility(string $major): SelectQuery
306351
->innerJoin(['PublisherVersion' => $this->Tags->getTarget()->getTable()], ['PublisherVersion.id = ' . $alias . '.tag_id'])
307352
->where([
308353
$alias . '.fk_model' => $this->getAlias(),
309-
'PublisherVersion.slug LIKE' => 'cakephp-' . $major . '-%',
354+
'PublisherVersion.slug LIKE' => CakephpVersion::isDevelopmentLabel($major)
355+
? CakephpVersion::developmentSlug((int)$major)
356+
: 'cakephp-' . $major . '-%',
310357
])
311358
->where(static fn(QueryExpression $exp) => $exp->equalFields($alias . '.fk_id', 'Packages.id'));
312359
}
@@ -372,6 +419,8 @@ public function findSitemap(SelectQuery $query): SelectQuery
372419
*/
373420
public function findEcosystemTotals(SelectQuery $query): SelectQuery
374421
{
422+
$query->find('released');
423+
375424
return $query->select([
376425
'plugins' => $query->func()->count('*'),
377426
'monthly_downloads' => $query->func()->sum('Packages.monthly_downloads'),
@@ -401,9 +450,9 @@ public function findNamespaces(SelectQuery $query): SelectQuery
401450
*/
402451
public function ecosystemStats(): array
403452
{
404-
return Cache::remember('ecosystem_stats_v2', function (): array {
453+
return Cache::remember('ecosystem_stats_v3', function (): array {
405454
$totals = $this->unhydratedFind('ecosystemTotals')->firstOrFail();
406-
$publishers = $this->find('namespaces')->count();
455+
$publishers = $this->find('released')->find('namespaces')->count();
407456
$major = $this->publisherMajors()[0] ?? null;
408457
$currentSupport = null;
409458
if ($major !== null) {
@@ -495,9 +544,13 @@ public function filterOptions(): array
495544
return Cache::remember('package_filter_tags_v1', function (): array {
496545
$options = [];
497546
foreach (['cakephp' => 'CakePHP', 'php' => 'PHP'] as $key => $label) {
547+
$query = $this->Tags->find('list', keyField: 'slug', valueField: 'label')
548+
->where(['slug LIKE' => $key . '-%']);
549+
if ($key === 'cakephp') {
550+
$query->where(['slug IN' => CakephpVersion::slugs()]);
551+
}
498552
/** @var array<string, string> $tags Scalar list results, keyed by version slug. */
499-
$tags = $this->Tags->find('list', keyField: 'slug', valueField: 'label')
500-
->where(['slug LIKE' => $key . '-%'])->toArray();
553+
$tags = $query->toArray();
501554
$pattern = '/^' . preg_quote($label, '/') . ':\\s*/';
502555
uasort($tags, static fn(string $a, string $b): int => version_compare(
503556
preg_replace($pattern, '', $b) ?? $b,

0 commit comments

Comments
 (0)