This commit is contained in:
Richard Dern
2022-01-12 00:35:37 +01:00
commit 400e3d01f1
1363 changed files with 57778 additions and 0 deletions

View 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);
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}