33namespace App \Jobs ;
44
55use App \Wiki ;
6+ use App \User ;
67use Illuminate \Database \DatabaseManager ;
78use PDO ;
89use Carbon \Carbon ;
@@ -39,21 +40,33 @@ private function isNullOrEmpty( $value ): bool {
3940 return is_null ($ value ) || intVal ($ value ) === 0 ;
4041 }
4142
42- public function prepareStats ( array $ allStats , $ wikis ): array {
43+ public function prepareStats ( array $ allStats , array $ wikis, array $ users ): array {
4344
4445 $ deletedWikis = [];
4546 $ activeWikis = [];
4647 $ inactive = [];
4748 $ emptyWikis = [];
49+ $ nonDeletedStats = [];
4850 $ createdWikis = [];
51+ $ createdUsers = [];
4952 foreach ($ this ->creationRanges as $ range ) {
5053 $ createdWikis [$ range ] = [];
54+ $ createdUsers [$ range ] = [];
5155 }
52- $ nonDeletedStats = [];
5356
5457 $ now = Carbon::now ();
5558 $ currentTime = $ now ->timestamp ;
5659
60+ foreach ( $ users as $ user ) {
61+ $ createdAt = new Carbon ($ user ->created_at );
62+ foreach ($ createdUsers as $ range =>$ matches ) {
63+ $ lookback = new \DateInterval ($ range );
64+ if ($ createdAt >= $ now ->clone ()->sub ($ lookback )) {
65+ $ createdUsers [$ range ][] = $ user ;
66+ }
67+ }
68+ }
69+
5770 foreach ( $ wikis as $ wiki ) {
5871
5972 if ( !is_null ($ wiki ->deleted_at ) ) {
@@ -129,12 +142,17 @@ public function prepareStats( array $allStats, $wikis ): array {
129142 $ result ['wikis_created_ ' .$ range ] = count ($ items );
130143 }
131144
145+ foreach ($ createdUsers as $ range =>$ items ) {
146+ $ result ['users_created_ ' .$ range ] = count ($ items );
147+ }
148+
132149 return $ result ;
133150 }
134151
135152 public function handle ( DatabaseManager $ manager ): void
136153 {
137154 $ wikis = Wiki::withTrashed ()->with ('wikidb ' )->get ();
155+ $ users = User::all ();
138156
139157 $ manager ->purge ('mw ' );
140158 $ manager ->purge ('mysql ' );
@@ -161,7 +179,7 @@ public function handle( DatabaseManager $manager ): void
161179
162180 // use mw PDO to talk to mediawiki dbs
163181 $ allStats = $ mediawikiPdo ->query ($ query )->fetchAll (PDO ::FETCH_ASSOC );
164- $ summary = $ this ->prepareStats ( $ allStats , $ wikis );
182+ $ summary = $ this ->prepareStats ( $ allStats , $ wikis, $ users );
165183
166184 $ manager ->purge ('mw ' );
167185 $ manager ->purge ('mysql ' );
0 commit comments