22
33namespace App \Console \Commands ;
44
5+ use App \Jobs \SyncGameSaveForUser ;
56use App \Models \GamejoltAccount ;
6- use App \Models \GameSave ;
7- use Harrk \GameJoltApi \Exceptions \TimeOutException ;
8- use Harrk \GameJoltApi \GamejoltApi ;
9- use Harrk \GameJoltApi \GamejoltConfig ;
107use Illuminate \Console \Command ;
11- use Schema ;
128
139class SyncGameSave extends Command
1410{
@@ -26,43 +22,6 @@ class SyncGameSave extends Command
2622 */
2723 protected $ description = 'Sync a game save from the GameJolt API ' ;
2824
29- private function handleGameSave ($ gamejolt_user_id , $ api )
30- {
31- $ gja = GamejoltAccount::firstWhere ('id ' , $ gamejolt_user_id );
32- $ new_game_save = new GameSave ;
33- $ columns = Schema::getColumnListing ($ new_game_save ->getTable ());
34- $ result = [];
35- try {
36- foreach ($ columns as $ column ) {
37- if ($ column == 'uuid ' or $ column == 'created_at ' or $ column == 'updated_at ' or $ column == 'user_id ' ) {
38- continue ;
39- }
40- $ key = 'saveStorageV1| ' .$ gamejolt_user_id .'| ' .$ column ;
41- $ this ->info ('Getting " ' .$ key .'" from datastore ' );
42- $ ds_result = $ api ->dataStore ()->fetch ($ key , $ gja ->username , $ gja ->token );
43- $ success = $ ds_result ['response ' ]['success ' ];
44- if (filter_var ($ success , FILTER_VALIDATE_BOOLEAN )) {
45- $ result [$ column ] = $ ds_result ['response ' ]['data ' ];
46- } else {
47- $ message = $ ds_result ['response ' ]['message ' ];
48- $ this ->error ($ message );
49- break ;
50- }
51- }
52- } catch (TimeOutException $ e ) {
53- $ this ->error ('Error: ' .$ e ->getMessage ());
54-
55- return Command::FAILURE ;
56- }
57- $ game_save = GameSave::where (['user_id ' => $ gja ->user_id ])->first ();
58- if ($ game_save ) {
59- $ game_save ->update ($ result );
60- } else {
61- $ result ['user_id ' ] = $ gja ->user_id ;
62- GameSave::create ($ result );
63- }
64- }
65-
6625 /**
6726 * Execute the console command.
6827 *
@@ -77,7 +36,6 @@ public function handle()
7736
7837 return Command::FAILURE ;
7938 }
80- $ api = new GamejoltApi (new GamejoltConfig ($ game_id , $ private_key ));
8139 $ gamejolt_user_id = $ this ->argument ('gamejolt_user_id ' );
8240 if ($ gamejolt_user_id != 'all ' ) {
8341 if (! is_numeric ($ gamejolt_user_id ) || $ gamejolt_user_id < 1 ) {
@@ -90,10 +48,11 @@ public function handle()
9048 if ($ gamejolt_user_id == 'all ' ) {
9149 $ gamejolt_accounts = GamejoltAccount::all ();
9250 foreach ($ gamejolt_accounts as $ gamejolt_account ) {
93- $ this -> handleGameSave ($ gamejolt_account ->id , $ api );
51+ SyncGameSaveForUser:: dispatch ($ gamejolt_account ->user );
9452 }
9553 } else {
96- $ this ->handleGameSave ($ gamejolt_user_id , $ api );
54+ $ gamejolt_account = GamejoltAccount::firstWhere ('gamejolt_user_id ' , $ gamejolt_user_id );
55+ SyncGameSaveForUser::dispatch ($ gamejolt_account ->user );
9756 }
9857
9958 $ this ->info ('Done. ' );
0 commit comments