mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 08:43:42 +08:00
Remove last remaining usage of DB facade
This commit is contained in:
parent
2a713ccb67
commit
d1cd4b174b
|
@ -34,7 +34,7 @@ class CreatePostsTable extends Migration
|
||||||
$table->engine = 'MyISAM';
|
$table->engine = 'MyISAM';
|
||||||
});
|
});
|
||||||
|
|
||||||
DB::statement('ALTER TABLE posts ADD FULLTEXT content (content)');
|
app('db')->statement('ALTER TABLE posts ADD FULLTEXT content (content)');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,7 +6,6 @@ use Flarum\Support\Actor;
|
||||||
use Flarum\Support\HtmlAction;
|
use Flarum\Support\HtmlAction;
|
||||||
use Session;
|
use Session;
|
||||||
use Config;
|
use Config;
|
||||||
use DB;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
class IndexAction extends HtmlAction
|
class IndexAction extends HtmlAction
|
||||||
|
@ -23,7 +22,7 @@ class IndexAction extends HtmlAction
|
||||||
|
|
||||||
protected function render(Request $request, $routeParams = [])
|
protected function render(Request $request, $routeParams = [])
|
||||||
{
|
{
|
||||||
$config = DB::table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
|
$config = app('db')->table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
|
||||||
$data = [];
|
$data = [];
|
||||||
$session = [];
|
$session = [];
|
||||||
$alert = Session::get('alert');
|
$alert = Session::get('alert');
|
||||||
|
|
169
src/Core/Application.php
Normal file
169
src/Core/Application.php
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Flarum\Core;
|
||||||
|
|
||||||
|
use Illuminate\Container\Container;
|
||||||
|
use Illuminate\Contracts\Foundation\Application as LaravelApplication;
|
||||||
|
|
||||||
|
class Application extends Container implements LaravelApplication
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $basePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $serviceProviders = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $bootingListeners = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $bootedListeners = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the application instance.
|
||||||
|
*
|
||||||
|
* @param $basePath
|
||||||
|
*/
|
||||||
|
public function __construct($basePath)
|
||||||
|
{
|
||||||
|
$this->basePath = $basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the version number of the application.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function version()
|
||||||
|
{
|
||||||
|
return '1.0.dev';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the base path of the Laravel installation.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function basePath()
|
||||||
|
{
|
||||||
|
return $this->basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get or check the current application environment.
|
||||||
|
*
|
||||||
|
* @param mixed
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function environment()
|
||||||
|
{
|
||||||
|
return 'production';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the application is currently down for maintenance.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDownForMaintenance()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register all of the configured providers.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function registerConfiguredProviders()
|
||||||
|
{
|
||||||
|
foreach ($this->serviceProviders as $provider) {
|
||||||
|
$provider->register();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a service provider with the application.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Support\ServiceProvider|string $provider
|
||||||
|
* @param array $options
|
||||||
|
* @param bool $force
|
||||||
|
* @return \Illuminate\Support\ServiceProvider
|
||||||
|
*/
|
||||||
|
public function register($provider, $options = array(), $force = false)
|
||||||
|
{
|
||||||
|
$this->serviceProviders[] = $provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a deferred provider and service.
|
||||||
|
*
|
||||||
|
* @param string $provider
|
||||||
|
* @param string $service
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function registerDeferredProvider($provider, $service = null)
|
||||||
|
{
|
||||||
|
$this->register($provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boot the application's service providers.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->fireListeners($this->bootingListeners);
|
||||||
|
|
||||||
|
foreach ($this->serviceProviders as $provider) {
|
||||||
|
$this->call([$provider, 'boot']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->fireListeners($this->bootedListeners);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new boot listener.
|
||||||
|
*
|
||||||
|
* @param mixed $callback
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function booting($callback)
|
||||||
|
{
|
||||||
|
$this->bootingListeners[] = $callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new "booted" listener.
|
||||||
|
*
|
||||||
|
* @param mixed $callback
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function booted($callback)
|
||||||
|
{
|
||||||
|
$this->bootedListeners[] = $callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fire the given array of listener callbacks.
|
||||||
|
*
|
||||||
|
* @param array $listeners
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function fireListeners(array $listeners)
|
||||||
|
{
|
||||||
|
foreach ($listeners as $listener)
|
||||||
|
{
|
||||||
|
$listener($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,13 +2,12 @@
|
||||||
|
|
||||||
use Flarum\Core\Models\Notification;
|
use Flarum\Core\Models\Notification;
|
||||||
use Flarum\Core\Models\User;
|
use Flarum\Core\Models\User;
|
||||||
use DB;
|
|
||||||
|
|
||||||
class EloquentNotificationRepository implements NotificationRepositoryInterface
|
class EloquentNotificationRepository implements NotificationRepositoryInterface
|
||||||
{
|
{
|
||||||
public function findByUser(User $user, $limit = null, $offset = 0)
|
public function findByUser(User $user, $limit = null, $offset = 0)
|
||||||
{
|
{
|
||||||
$primaries = Notification::select(DB::raw('MAX(id) AS id'), DB::raw('SUM(is_read = 0) AS unread_count'))
|
$primaries = Notification::select(app('db')->raw('MAX(id) AS id'), app('db')->raw('SUM(is_read = 0) AS unread_count'))
|
||||||
->where('user_id', $user->id)
|
->where('user_id', $user->id)
|
||||||
->whereIn('type', array_filter(array_keys(Notification::getTypes()), [$user, 'shouldAlert']))
|
->whereIn('type', array_filter(array_keys(Notification::getTypes()), [$user, 'shouldAlert']))
|
||||||
->where('is_deleted', false)
|
->where('is_deleted', false)
|
||||||
|
@ -20,7 +19,7 @@ class EloquentNotificationRepository implements NotificationRepositoryInterface
|
||||||
return Notification::with('subject')
|
return Notification::with('subject')
|
||||||
->select('notifications.*', 'p.unread_count')
|
->select('notifications.*', 'p.unread_count')
|
||||||
->mergeBindings($primaries->getQuery())
|
->mergeBindings($primaries->getQuery())
|
||||||
->join(DB::raw('('.$primaries->toSql().') p'), 'notifications.id', '=', 'p.id')
|
->join(app('db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', 'p.id')
|
||||||
->orderBy('time', 'desc')
|
->orderBy('time', 'desc')
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php namespace Flarum\Core\Seeders;
|
<?php namespace Flarum\Core\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use DB;
|
|
||||||
|
|
||||||
class ConfigTableSeeder extends Seeder
|
class ConfigTableSeeder extends Seeder
|
||||||
{
|
{
|
||||||
|
@ -26,7 +25,7 @@ class ConfigTableSeeder extends Seeder
|
||||||
'theme_colored_header' => false,
|
'theme_colored_header' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
DB::table('config')->insert(array_map(function ($key, $value) {
|
app('db')->table('config')->insert(array_map(function ($key, $value) {
|
||||||
return compact('key', 'value');
|
return compact('key', 'value');
|
||||||
}, array_keys($config), $config));
|
}, array_keys($config), $config));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,5 @@ foreach ($permissions as &$permission) {
|
||||||
'permission' => $permission[2]
|
'permission' => $permission[2]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
\DB::table('permissions')->truncate();
|
app('db')->table('permissions')->truncate();
|
||||||
\DB::table('permissions')->insert($permissions);
|
app('db')->table('permissions')->insert($permissions);
|
Loading…
Reference in New Issue
Block a user