#12: Added a new table to hold the redirects, and implemented the controller to check this table if an album is not found
This commit is contained in:
parent
2f1cbfc16c
commit
b7a8222ecf
25
app/AlbumRedirect.php
Normal file
25
app/AlbumRedirect.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class AlbumRedirect extends Model
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['album_id', 'source_url'];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [];
|
||||
}
|
@ -72,6 +72,11 @@ class DbHelper
|
||||
->withCount('photos');
|
||||
}
|
||||
|
||||
public static function getAlbumById($albumID)
|
||||
{
|
||||
return Album::where('id', $albumID)->first();
|
||||
}
|
||||
|
||||
public static function getAlbumByPath($urlPath)
|
||||
{
|
||||
return Album::where('url_path', $urlPath)->first();
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Gallery;
|
||||
|
||||
use App\Album;
|
||||
use App\AlbumRedirect;
|
||||
use App\Facade\Theme;
|
||||
use App\Facade\UserConfig;
|
||||
use App\Helpers\ConfigHelper;
|
||||
@ -21,10 +22,20 @@ class AlbumController extends Controller
|
||||
$album = DbHelper::getAlbumByPath($albumUrlAlias);
|
||||
if (is_null($album))
|
||||
{
|
||||
// Check redirects
|
||||
$redirect = AlbumRedirect::where(DB::raw('\'/a\' + source_url'), $request->path())->first();
|
||||
|
||||
if (is_null($redirect))
|
||||
{
|
||||
// No redirect found either - bail out
|
||||
App::abort(404);
|
||||
return null;
|
||||
}
|
||||
|
||||
$album = DbHelper::getAlbumById($redirect->album_id);
|
||||
return redirect($album->url());
|
||||
}
|
||||
|
||||
$this->authorizeForUser($this->getUser(), 'view', $album);
|
||||
|
||||
$validViews = UserConfig::allowedAlbumViews();
|
||||
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateAlbumRedirectsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('album_redirects', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('album_id');
|
||||
$table->string('source_url');
|
||||
|
||||
$table->foreign('album_id')
|
||||
->references('id')->on('albums')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('album_redirects');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user