mirror of
https://github.com/flarum/core.git
synced 2025-08-17 13:54:18 +02:00
Include task scheduler in core
This commit is contained in:
committed by
Alexander Skvortsov
parent
d29495203b
commit
8dd57ffed2
@@ -14,6 +14,9 @@ use Flarum\Database\Console\ResetCommand;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Foundation\Console\CacheClearCommand;
|
||||
use Flarum\Foundation\Console\InfoCommand;
|
||||
use Illuminate\Console\Scheduling\Schedule as LaravelSchedule;
|
||||
use Illuminate\Console\Scheduling\ScheduleListCommand;
|
||||
use Illuminate\Console\Scheduling\ScheduleRunCommand;
|
||||
|
||||
class ConsoleServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
@@ -22,13 +25,42 @@ class ConsoleServiceProvider extends AbstractServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Used by Laravel to proxy artisan commands to its binary.
|
||||
// Flarum uses a similar binary, but it's called flarum.
|
||||
if (! defined('ARTISAN_BINARY')) {
|
||||
define('ARTISAN_BINARY', 'flarum');
|
||||
}
|
||||
|
||||
$this->container->singleton(LaravelSchedule::class, function () {
|
||||
return $this->container->make(Schedule::class);
|
||||
});
|
||||
|
||||
$this->container->singleton('flarum.console.commands', function () {
|
||||
return [
|
||||
CacheClearCommand::class,
|
||||
InfoCommand::class,
|
||||
MigrateCommand::class,
|
||||
ResetCommand::class,
|
||||
ScheduleListCommand::class,
|
||||
ScheduleRunCommand::class
|
||||
];
|
||||
});
|
||||
|
||||
$this->container->singleton('flarum.console.scheduled', function () {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$schedule = $this->container->make(LaravelSchedule::class);
|
||||
|
||||
foreach ($this->container->make('flarum.console.scheduled') as $scheduled) {
|
||||
$event = $schedule->command($scheduled['command'], $scheduled['args']);
|
||||
$scheduled['callback']($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
src/Console/Schedule.php
Normal file
40
src/Console/Schedule.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Console;
|
||||
|
||||
use Flarum\Foundation\Config;
|
||||
use Illuminate\Console\Scheduling\Schedule as LaravelSchedule;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Schedule extends LaravelSchedule
|
||||
{
|
||||
public function dueEvents($container)
|
||||
{
|
||||
return (new Collection($this->events))->filter->isDue(new FakeApp($container));
|
||||
}
|
||||
}
|
||||
|
||||
class FakeApp
|
||||
{
|
||||
public function __construct($container)
|
||||
{
|
||||
$this->config = $container->make(Config::class);
|
||||
}
|
||||
|
||||
public function isDownForMaintenance()
|
||||
{
|
||||
return $this->config->inMaintenanceMode();
|
||||
}
|
||||
|
||||
public function environment()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user