Refresh
This commit is contained in:
74
app/Console/Commands/GenerateRoutes.php
Executable file
74
app/Console/Commands/GenerateRoutes.php
Executable file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
class GenerateRoutes extends Command
|
||||
{
|
||||
protected $router;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'route:generate';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates a json file containing routes made available to frontend';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct(Router $router)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$routes = $this->buildRoutesArray();
|
||||
$json = $routes->toJson();
|
||||
|
||||
file_put_contents(config('routes.target'), $json);
|
||||
|
||||
$this->info(sprintf('Routes successfully generated in %s', config('routes.target')));
|
||||
$this->comment("Don't forget to rebuild assets using npm run dev or npm run prod !");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of whitelisted routes as a Laravel Collection.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected function buildRoutesArray()
|
||||
{
|
||||
$routes = [];
|
||||
$whitelist = config('routes.whitelist');
|
||||
|
||||
foreach ($this->router->getRoutes() as $route) {
|
||||
if (!in_array($route->getName(), $whitelist)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$routes[$route->getName()] = $route->uri();
|
||||
}
|
||||
|
||||
return collect($routes);
|
||||
}
|
||||
}
|
||||
51
app/Console/Commands/PurgeReadFeedItems.php
Executable file
51
app/Console/Commands/PurgeReadFeedItems.php
Executable file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\FeedItem;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class PurgeReadFeedItems extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'feeditems:purgeread';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Purge old read feed items from the database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$oldest = now()->subDays(config('cyca.maxOrphanAge.feeditems'));
|
||||
$oldFeedItems = FeedItem::allRead()->olderThan($oldest)->get();
|
||||
|
||||
// We need to do this individually to take advantage of the
|
||||
// FeedItemObserver and automatically delete associated files that may
|
||||
// have been locally stored
|
||||
foreach ($oldFeedItems as $item) {
|
||||
$item->delete();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
49
app/Console/Commands/UpdateDocuments.php
Executable file
49
app/Console/Commands/UpdateDocuments.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\EnqueueDocumentUpdate;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UpdateDocuments extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'document:update';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Enqueue documents that need update';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$oldest = now()->subMinute(config('cyca.maxAge.document'));
|
||||
$documents = Document::needingUpdate($oldest)->get();
|
||||
|
||||
foreach ($documents as $document) {
|
||||
EnqueueDocumentUpdate::dispatch($document);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
49
app/Console/Commands/UpdateFeeds.php
Executable file
49
app/Console/Commands/UpdateFeeds.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\EnqueueFeedUpdate;
|
||||
use App\Models\Feed;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UpdateFeeds extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'feed:update';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Enqueue feeds that need update';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$oldest = now()->subMinute(config('cyca.maxAge.feed'));
|
||||
$feeds = Feed::needingUpdate($oldest)->get();
|
||||
|
||||
foreach ($feeds as $feed) {
|
||||
EnqueueFeedUpdate::dispatch($feed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
37
app/Console/Kernel.php
Executable file
37
app/Console/Kernel.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->command('document:update')->everyFifteenMinutes()->withoutOverlapping();
|
||||
$schedule->command('feed:update')->everyFifteenMinutes()->withoutOverlapping();
|
||||
$schedule->command('feeditems:purgeread')->daily();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user