22
33namespace App \Console \Commands ;
44
5- use App \Jobs \RefreshFeedJob ;
6- use App \Models \Feed ;
5+ use App \Config \ConfiguredFeedProvider ;
76use Illuminate \Console \Command ;
8- use Illuminate \Database \Eloquent \Builder ;
9- use Illuminate \Database \Eloquent \Collection ;
107
118class UpdateFeedsCommand extends Command
129{
@@ -15,40 +12,24 @@ class UpdateFeedsCommand extends Command
1512 *
1613 * @var string
1714 */
18- protected $ signature = 'rss:update-outdated-feeds
19- {--all : Also update dormant feeds}
20- {--outdated-time=24 : Age (in hours) that \'s considered as outdated} ' ;
15+ protected $ signature = 'rss:update-outdated-feeds ' ;
2116
2217 /**
2318 * The console command description.
2419 *
2520 * @var string
2621 */
27- protected $ description = 'Trigger the processing of outdated feeds ' ;
22+ protected $ description = 'Trigger the update of outdated feeds ' ;
2823
2924 /**
3025 * Execute the console command.
3126 *
3227 * @return int
3328 */
34- public function handle ()
29+ public function handle (ConfiguredFeedProvider $ feedProvider )
3530 {
36- $ queryDormant = $ this ->hasOption ('all ' );
37- $ dormantTime = time () - (86400 * 90 ); // 90 days
38- $ outdatedTime = time () - ceil (floatval ($ this ->option ('outdated-time ' )) * 3600 );
39- $ dormantQuery = function (Builder $ query ) use ($ dormantTime ) {
40- $ query ->where ('last_accessed_at ' , '> ' , $ dormantTime );
41- };
42-
43- Feed::query ()
44- ->when (!$ queryDormant , $ dormantQuery )
45- ->where ('last_fetched_at ' , '< ' , $ outdatedTime )
46- ->chunk (100 , function (Collection $ feeds ) {
47- /** @var Feed $feed */
48- foreach ($ feeds as $ feed ) {
49- dispatch (new RefreshFeedJob ($ feed ));
50- }
51- });
31+ $ feeds = $ feedProvider ->getAll ();
32+ $ feeds ->reloadOutdatedFeeds ();
5233
5334 return 0 ;
5435 }
0 commit comments