44namespace App \Model \Table ;
55
66use App \Model \Filter \PackagesCollection ;
7+ use App \Utility \CakephpVersion ;
78use ArrayObject ;
89use Cake \Cache \Cache ;
910use Cake \Collection \Collection ;
1011use Cake \Collection \CollectionInterface ;
1112use Cake \Database \Expression \FunctionExpression ;
1213use Cake \Database \Expression \QueryExpression ;
14+ use Cake \Database \Schema \TableSchemaInterface ;
1315use Cake \Datasource \EntityInterface ;
1416use Cake \Event \EventInterface ;
1517use Cake \ORM \Query \SelectQuery ;
1618use Cake \ORM \Table ;
1719use 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