diff --git a/app/AlbumRedirect.php b/app/AlbumRedirect.php new file mode 100644 index 0000000..7227ddf --- /dev/null +++ b/app/AlbumRedirect.php @@ -0,0 +1,25 @@ +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(); diff --git a/app/Http/Controllers/Gallery/AlbumController.php b/app/Http/Controllers/Gallery/AlbumController.php index 68e6b01..b705e1a 100644 --- a/app/Http/Controllers/Gallery/AlbumController.php +++ b/app/Http/Controllers/Gallery/AlbumController.php @@ -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,8 +22,18 @@ class AlbumController extends Controller $album = DbHelper::getAlbumByPath($albumUrlAlias); if (is_null($album)) { - App::abort(404); - return null; + // 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); diff --git a/database/migrations/2017_09_03_084118_create_album_redirects_table.php b/database/migrations/2017_09_03_084118_create_album_redirects_table.php new file mode 100644 index 0000000..e0f1d54 --- /dev/null +++ b/database/migrations/2017_09_03_084118_create_album_redirects_table.php @@ -0,0 +1,38 @@ +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'); + } +}