1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 23:47:32 +02:00

Fix onOneServer, withoutOverlapping console scheduling options

Flarum doesn't fully use Laravel's cache system, but rather
creates and binds a single cache store.
See \Flarum\Foundation\InstalledSite::registerCache
Since certain config options (e.g. withoutOverlapping, onOneServer)
need the cache, we must override the cache factory we give to the scheduling
mutexes so it returns our single custom cache.
This commit is contained in:
Alexander Skvortsov
2021-05-18 03:08:32 -04:00
parent 09615f1a85
commit 2042eed99f
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace Flarum\Console\Cache;
use Illuminate\Contracts\Cache\Factory as FactoryContract;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Container\Container;
class Factory implements FactoryContract
{
/**
* @var Container
*/
private $container;
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Get a cache store instance by name.
*
* @param string|null $name
* @return Repository
*/
public function store($name = null)
{
return $this->container['cache.store'];
}
}

View File

@@ -9,15 +9,20 @@
namespace Flarum\Console;
use Flarum\Console\Cache\Factory;
use Flarum\Database\Console\MigrateCommand;
use Flarum\Database\Console\ResetCommand;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Console\AssetsPublishCommand;
use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Foundation\Console\InfoCommand;
use Illuminate\Console\Scheduling\CacheEventMutex;
use Illuminate\Console\Scheduling\CacheSchedulingMutex;
use Illuminate\Console\Scheduling\EventMutex;
use Illuminate\Console\Scheduling\Schedule as LaravelSchedule;
use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Console\Scheduling\SchedulingMutex;
use Illuminate\Contracts\Container\Container;
class ConsoleServiceProvider extends AbstractServiceProvider
@@ -33,6 +38,19 @@ class ConsoleServiceProvider extends AbstractServiceProvider
define('ARTISAN_BINARY', 'flarum');
}
// Flarum doesn't fully use Laravel's cache system, but rather
// creates and binds a single cache store.
// See \Flarum\Foundation\InstalledSite::registerCache
// Since certain config options (e.g. withoutOverlapping, onOneServer)
// need the cache, we must override the cache factory we give to the scheduling
// mutexes so it returns our single custom cache.
$this->container->bind(EventMutex::class, function ($container) {
return new CacheEventMutex($container->make(Factory::class));
});
$this->container->bind(SchedulingMutex::class, function ($container) {
return new CacheSchedulingMutex($container->make(Factory::class));
});
$this->container->singleton(LaravelSchedule::class, function (Container $container) {
return $container->make(Schedule::class);
});