@@ -43,39 +43,16 @@ public function perform(): void
4343 // happen if a previous request failed.
4444 $ users = models \User::listBy (['subscription_account_id ' => null ]);
4545 foreach ($ users as $ user ) {
46- if (!$ user ->validated_at ) {
46+ if (!$ user ->isValidated () ) {
4747 continue ;
4848 }
4949
50- $ account = $ subscriptions_service ->account ($ user ->email );
51- if ($ account ) {
52- $ user ->subscription_account_id = $ account ['id ' ];
53- $ user ->subscription_expired_at = $ account ['expired_at ' ];
54- $ user ->save ();
55- }
50+ $ subscriptions_service ->initAccount ($ user );
51+ $ user ->save ();
5652 }
5753
5854 // Then, synchronize expiration dates.
5955 $ users = models \User::listAll ();
60- $ account_ids_to_users = array_column ($ users , null , 'subscription_account_id ' );
61- $ account_ids = array_keys ($ account_ids_to_users );
62-
63- $ result = $ subscriptions_service ->sync ($ account_ids );
64- if ($ result === null ) {
65- return ;
66- }
67-
68- foreach ($ result as $ account_id => $ expired_at ) {
69- if (!isset ($ account_ids_to_users [$ account_id ])) {
70- \Minz \Log::error ("Subscription account {$ account_id } does not exist. " );
71- continue ;
72- }
73-
74- $ user = $ account_ids_to_users [$ account_id ];
75- if ($ user ->subscription_expired_at != $ expired_at ) {
76- $ user ->subscription_expired_at = $ expired_at ;
77- $ user ->save ();
78- }
79- }
56+ $ subscriptions_service ->sync ($ users );
8057 }
8158}
0 commit comments