Skip to content

Commit

Permalink
Upgrade to Laravel 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
phanan committed Sep 26, 2016
1 parent 365d333 commit b0f5b3d
Show file tree
Hide file tree
Showing 23 changed files with 835 additions and 487 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ ALLOW_DOWNLOAD=true

# The variables below are Laravel-specific.
# You can change them if you know what you're doing. Otherwise, just leave them as-is.

APP_LOG_LEVEL=debug
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
Expand All @@ -96,3 +97,7 @@ MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
18 changes: 18 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Exceptions;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
Expand Down Expand Up @@ -52,4 +53,21 @@ public function render($request, Exception $e)

return parent::render($request, $e);
}

/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
*
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}

return redirect()->guest('login');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function index()

return response()->json([
'artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(),
'settings' => auth()->user()->is_admin ? Setting::lists('value', 'key')->all() : [],
'settings' => auth()->user()->is_admin ? Setting::pluck('value', 'key')->all() : [],
'playlists' => $playlists,
'interactions' => Interaction::byCurrentUser()->get(),
'users' => auth()->user()->is_admin ? User::all() : [],
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function update(UserUpdateRequest $request, User $user)
*/
public function destroy(User $user)
{
$this->authorize($user);
$this->authorize('destroy', $user);

return response()->json($user->delete());
}
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\GetUserFromToken;
use App\Http\Middleware\ObjectStorageAuthenticate;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Routing\Middleware\ThrottleRequests;

class Kernel extends HttpKernel
{
Expand All @@ -19,6 +22,21 @@ class Kernel extends HttpKernel
CheckForMaintenanceMode::class,
];

/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
// Koel doesn't use any default Laravel middleware for web.
],
'api' => [
'throttle:60,1',
'bindings',
],
];

/**
* The application's route middleware.
*
Expand All @@ -28,5 +46,8 @@ class Kernel extends HttpKernel
'auth' => Authenticate::class,
'jwt.auth' => GetUserFromToken::class,
'os.auth' => ObjectStorageAuthenticate::class,
'bindings' => SubstituteBindings::class,
'can' => Authorize::class,
'throttle' => ThrottleRequests::class
];
}
3 changes: 3 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

/**
* @property array preferences
Expand All @@ -12,6 +13,8 @@
*/
class User extends Authenticatable
{
use Notifiable;

/**
* The database table used by the model.
*
Expand Down
3 changes: 0 additions & 3 deletions app/Policies/PlaylistPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

use App\Models\Playlist;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class PlaylistPolicy
{
use HandlesAuthorization;

public function owner(User $user, Playlist $playlist)
{
return $user->id === $playlist->user_id;
Expand Down
3 changes: 0 additions & 3 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace App\Policies;

use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class UserPolicy
{
use HandlesAuthorization;

public function destroy(User $currentUser, User $userToDestroy)
{
return $currentUser->is_admin && $currentUser->id !== $userToDestroy->id;
Expand Down
9 changes: 2 additions & 7 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\User;
use App\Policies\PlaylistPolicy;
use App\Policies\UserPolicy;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
Expand All @@ -23,14 +22,10 @@ class AuthServiceProvider extends ServiceProvider

/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
*
* @return void
*/
public function boot(GateContract $gate)
public function boot()
{
$this->registerPolicies($gate);
$this->registerPolicies();

//
}
Expand Down
26 changes: 26 additions & 0 deletions app/Providers/BroadcastServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;

class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();

/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
}
}
6 changes: 2 additions & 4 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ class EventServiceProvider extends ServiceProvider

/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function boot(DispatcherContract $events)
public function boot()
{
parent::boot($events);
parent::boot();

// Generate a unique hash for a song from its path to be the ID
Song::creating(function ($song) {
Expand Down
51 changes: 38 additions & 13 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
Expand All @@ -19,29 +19,54 @@ class RouteServiceProvider extends ServiceProvider
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
*
* @return void
*/
public function boot(Router $router)
public function boot()
{
parent::boot($router);

$router->model('playlist', 'App\Models\Playlist');
$router->model('user', 'App\Models\User');
parent::boot();
}

/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
public function map(Router $router)
protected function mapApiRoutes()
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
Route::group([
'middleware' => 'api',
'namespace' => $this->namespace,
'prefix' => 'api',
], function ($router) {
require base_path('routes/api.php');
});
}
}
6 changes: 3 additions & 3 deletions app/Services/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ public function getHash($path)
*/
public function tidy()
{
$inUseAlbums = Song::select('album_id')->groupBy('album_id')->get()->lists('album_id')->toArray();
$inUseAlbums = Song::select('album_id')->groupBy('album_id')->get()->pluck('album_id')->toArray();
$inUseAlbums[] = Album::UNKNOWN_ID;
Album::whereNotIn('id', $inUseAlbums)->delete();

$inUseArtists = Album::select('artist_id')->groupBy('artist_id')->get()->lists('artist_id')->toArray();
$inUseArtists = Album::select('artist_id')->groupBy('artist_id')->get()->pluck('artist_id')->toArray();

$contributingArtists = Song::distinct()
->select('contributing_artist_id')
->groupBy('contributing_artist_id')
->get()
->lists('contributing_artist_id')
->pluck('contributing_artist_id')
->toArray();

$inUseArtists = array_merge($inUseArtists, $contributingArtists);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"james-heinrich/getid3": "^1.9",
"barryvdh/laravel-ide-helper": "^2.1",
"guzzlehttp/guzzle": "^6.1",
Expand Down
Loading

0 comments on commit b0f5b3d

Please sign in to comment.