@@ -12,6 +12,8 @@ class QueueUpdates extends Command
1212{
1313 use RequestTargetVersion;
1414 protected int $ totalPushed = 0 ;
15+ protected int $ updateLimit ;
16+ protected string $ targetVersion ;
1517
1618 /**
1719 * The name and signature of the console command.
@@ -32,40 +34,53 @@ class QueueUpdates extends Command
3234 */
3335 public function handle (): int
3436 {
35- $ targetVersion = $ this ->queryTargetVersion ();
37+ $ this -> targetVersion = $ this ->queryTargetVersion ();
3638
37- if (!$ this ->confirm ("Are you sure you would like to push the updates for " . $ targetVersion )) {
39+ if (!$ this ->confirm ("Are you sure you would like to push the updates for " . $ this -> targetVersion )) {
3840 return Command::FAILURE ;
3941 }
4042
4143 $ this ->output ->writeln ('Pushing update jobs ' );
4244
45+ // Get update-ready sites in correct major branch that are not yet on the target version
4346 $ sites = Site::query ()
4447 ->where (
4548 'cms_version ' ,
4649 'like ' ,
47- $ targetVersion [0 ] . '% '
50+ $ this ->targetVersion [0 ] . '% '
51+ )
52+ ->where (
53+ 'update_requirement_state ' ,
54+ '= ' ,
55+ 1
56+ )
57+ ->where (
58+ 'cms_version ' ,
59+ '!= ' ,
60+ $ this ->targetVersion
4861 );
4962
5063 // Query the amount of sites to be updated
5164 // @phpstan-ignore-next-line
52- $ updateCount = (int ) $ this ->ask ('How many updates will be pushed? - Use 0 for "ALL" ' , "100 " );
53-
54- if ($ updateCount > 0 ) {
55- $ sites ->limit ($ updateCount );
56- }
65+ $ this ->updateLimit = (int ) $ this ->ask ('How many updates will be pushed? - Use 0 for "ALL" ' , "100 " );
5766
5867 // Chunk and push to queue
5968 $ sites ->chunkById (
6069 100 ,
61- function (Collection $ chunk ) use ( $ targetVersion ) {
70+ function (Collection $ chunk ) {
6271 // Show progress
6372 $ this ->output ->write ('. ' );
6473
65- $ this ->totalPushed += $ chunk ->count ();
66-
6774 // Push each site check to queue
68- $ chunk ->each (fn ($ site ) => UpdateSite::dispatch ($ site , $ targetVersion )->onQueue ('updates ' ));
75+ $ chunk ->each (function (Site $ site ) {
76+ if ($ this ->updateLimit > 0 && $ this ->totalPushed >= $ this ->updateLimit ) {
77+ return ;
78+ }
79+
80+ $ this ->totalPushed ++;
81+
82+ UpdateSite::dispatch ($ site , $ this ->targetVersion )->onQueue ('updates ' );
83+ });
6984 }
7085 );
7186
0 commit comments