From 3583e1b34177d21655cf96132911bb0049e6541b Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Fri, 2 Feb 2018 15:09:29 +0000 Subject: [PATCH] Apply fixes from StyleCI --- app/Collection.php | 3 +- app/Console/Commands/DBDown.php | 110 +++--- app/Console/Commands/DBUp.php | 111 +++---- app/Console/Kernel.php | 5 +- app/Credit.php | 7 +- app/Event.php | 21 +- app/Exceptions/Handler.php | 17 +- .../TooManyRequestsHttpException.php | 9 +- app/Genre.php | 5 +- app/Helpers/Helper.php | 313 +++++++++--------- app/Helpers/HelperFunctions.php | 22 +- app/Helpers/IMDBAPI.php | 114 +++---- app/Helpers/MappingsCache.php | 180 +++++----- .../Controllers/API/DiscoverController.php | 250 +++++++------- app/Http/Controllers/API/IMDBController.php | 73 ++-- app/Http/Controllers/API/JSONController.php | 53 +-- .../Controllers/API/MappingsController.php | 193 +++++------ app/Http/Controllers/API/MovieController.php | 8 +- app/Http/Controllers/API/PersonController.php | 19 +- app/Http/Controllers/API/SearchController.php | 90 +++-- .../Controllers/API/TestJSONController.php | 22 +- .../Controllers/Auth/RegisterController.php | 18 +- app/Http/Controllers/Controller.php | 4 +- .../Controllers/DBMaintenanceController.php | 12 +- app/Http/Controllers/HomeController.php | 2 - app/Http/Kernel.php | 10 +- app/Http/Middleware/CheckDBMaint.php | 22 +- app/Http/Middleware/CheckDBMaintAPI.php | 6 +- .../Middleware/RedirectIfAuthenticated.php | 7 +- .../Middleware/ThrottleRequestsException.php | 10 +- app/Http/Requests/IMDBListRequest.php | 13 +- app/Http/Requests/JSONRequest.php | 35 +- app/Http/Requests/MappingRequests.php | 96 +++--- app/Keyword.php | 5 +- app/Mapping.php | 73 ++-- app/MappingMovie.php | 10 +- app/Movie.php | 117 ++++--- app/Person.php | 35 +- app/Providers/AuthServiceProvider.php | 1 - app/Providers/BroadcastServiceProvider.php | 2 +- app/Providers/EventServiceProvider.php | 2 +- app/Providers/RouteServiceProvider.php | 4 +- app/Searchable.php | 2 +- app/StevenLuMovie.php | 4 +- app/User.php | 2 +- config/app.php | 72 ++-- config/auth.php | 12 +- config/broadcasting.php | 10 +- config/cache.php | 16 +- config/database.php | 116 +++---- config/debugbar.php | 16 +- config/filesystems.php | 10 +- config/mail.php | 2 +- config/queue.php | 24 +- config/services.php | 8 +- database/factories/ModelFactory.php | 6 +- .../2014_10_12_000000_create_users_table.php | 4 +- ...12_100000_create_password_resets_table.php | 4 +- .../2017_06_08_114302_create_events_table.php | 53 ++- ..._06_08_114302_create_ip_adresses_table.php | 51 ++- ...017_06_08_114302_create_mappings_table.php | 61 ++-- ..._08_114302_create_title_mappings_table.php | 51 ++- ...6_08_114302_create_year_mappings_table.php | 49 ++- ...14304_add_foreign_keys_to_events_table.php | 52 ++- ..._add_foreign_keys_to_ip_adresses_table.php | 52 ++- public/index.php | 3 +- resources/lang/en/auth.php | 2 +- resources/lang/en/pagination.php | 2 +- resources/lang/en/passwords.php | 8 +- routes/api.php | 54 ++- routes/web.php | 4 +- server.php | 4 +- tests/Feature/ExampleTest.php | 3 - tests/Unit/ExampleTest.php | 2 - 74 files changed, 1363 insertions(+), 1505 deletions(-) diff --git a/app/Collection.php b/app/Collection.php index bf4b0d3..9859f1d 100644 --- a/app/Collection.php +++ b/app/Collection.php @@ -8,7 +8,8 @@ class Collection extends Model { //protected $with = []; - public function movies() { + public function movies() + { return $this->hasMany("App\Movie"); } } diff --git a/app/Console/Commands/DBDown.php b/app/Console/Commands/DBDown.php index b3cd106..fba0279 100644 --- a/app/Console/Commands/DBDown.php +++ b/app/Console/Commands/DBDown.php @@ -3,9 +3,9 @@ namespace App\Console\Commands; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\Config; class DBDown extends Command { @@ -42,34 +42,30 @@ public function handle() { // $info = $this->get_maintenance_info(); - if ($info === false) - { - $this->info("Starting maintenance mode!"); + if ($info === false) { + $this->info('Starting maintenance mode!'); $config = $this->argument('maintenance_to_use'); - if ($config == "") - { - $config = "maintenance"; + if ($config == '') { + $config = 'maintenance'; } $this->start_maintenance_mode($config); - } - else - { + } else { $this->error("Maintenance mode already on the way. Currently on stage: {$info['stage_name']}"); } } protected function get_maintenance_info() { - if (Storage::disk()->exists("db.down")) - { - $contents = Storage::get("db.down"); + if (Storage::disk()->exists('db.down')) { + $contents = Storage::get('db.down'); + return json_decode($contents, true); } return false; } - protected function start_maintenance_mode($config = "tmdb_maintenance") + protected function start_maintenance_mode($config = 'tmdb_maintenance') { $this->replicate_tables($config); @@ -78,21 +74,21 @@ protected function start_maintenance_mode($config = "tmdb_maintenance") protected function replicate_tables($config) { - $info = array( - "stage" => "db.replication", - "stage_name" => "Database Replication", - "progress" => 0.0 - ); + $info = [ + 'stage' => 'db.replication', + 'stage_name' => 'Database Replication', + 'progress' => 0.0, + ]; $this->set_maintenance_info($info); //Replicating database $from_db = Config::get("database.$config.from_database"); $to_db = Config::get("database.$config.to_database"); $connection = Config::get("database.$config.db_connection"); - if ($from_db == "" || $to_db == "") - { - $this->error("Please check your configuration!"); + if ($from_db == '' || $to_db == '') { + $this->error('Please check your configuration!'); $this->free_maintenance_info(); + return; } @@ -100,25 +96,23 @@ protected function replicate_tables($config) $conf_tables = Config::get("database.$config.tables"); $tables = $conf_tables; - if ($conf_tables == "all" || $conf_tables == "") - { - $tables = DB::select("SHOW TABLES FROM $from_db"); - $real_tables = array(); - foreach ($tables as $dict) { - foreach ($dict as $key => $value) { - $real_tables[] = $value; - } - } - $tables = $real_tables; + if ($conf_tables == 'all' || $conf_tables == '') { + $tables = DB::select("SHOW TABLES FROM $from_db"); + $real_tables = []; + foreach ($tables as $dict) { + foreach ($dict as $key => $value) { + $real_tables[] = $value; + } + } + $tables = $real_tables; } - $this->info("Replicating tables ".join(", ", $tables)); + $this->info('Replicating tables '.implode(', ', $tables)); $first_tables = Config::get("database.$config.tables_before"); - if (is_array($first_tables) && count($first_tables) > 0) - { - $this->info("Starting with table(s) ".join(",", $first_tables)); + if (is_array($first_tables) && count($first_tables) > 0) { + $this->info('Starting with table(s) '.implode(',', $first_tables)); foreach ($first_tables as $value) { if (($key = array_search($value, $tables)) !== false) { @@ -130,13 +124,13 @@ protected function replicate_tables($config) array_unshift($tables, $value); } - $this->info("Order of replication: ".join(", ", $tables)); + $this->info('Order of replication: '.implode(', ', $tables)); } $current = 0; $total = count($tables); - DB::connection($connection)->statement("SET foreign_key_checks = 0;"); + DB::connection($connection)->statement('SET foreign_key_checks = 0;'); foreach ($tables as $value) { try { DB::connection($connection)->statement("DROP TABLE $to_db.$value"); @@ -145,16 +139,14 @@ protected function replicate_tables($config) } $create_syntax = DB::select("SHOW CREATE TABLE $from_db.$value"); - $actual_syntax = ""; + $actual_syntax = ''; foreach ($create_syntax as $syntax) { //dd($syntax); foreach ($syntax as $key => $val) { - if ($key == "Create Table") - { + if ($key == 'Create Table') { $actual_syntax = $val; } } - } $actual_syntax = str_replace("`$value`", "`$to_db`.`$value`", $actual_syntax); @@ -163,38 +155,38 @@ protected function replicate_tables($config) DB::connection($connection)->statement("INSERT INTO $to_db.$value SELECT * FROM $from_db.$value"); $current += 1; $this->info("Replicated table $value. ($current/$total)"); - $info = array( - "stage" => "db.replication", - "stage_name" => "Database Replication", - "progress" => $current / (float)$total - ); + $info = [ + 'stage' => 'db.replication', + 'stage_name' => 'Database Replication', + 'progress' => $current / (float) $total, + ]; $this->set_maintenance_info($info); } - DB::connection($connection)->statement("SET foreign_key_checks = 1;"); + DB::connection($connection)->statement('SET foreign_key_checks = 1;'); - $this->info("Finished Replicating Database."); + $this->info('Finished Replicating Database.'); } protected function finish_preparations() { - $info = array( - "stage" => "finished", - "stage_name" => "Database Maintenance!", - "progress" => 1.0 - ); - - $this->set_maintenance_info($info); - $this->info("Finished preparing Database Maintenance. You can now safely manipulate production database!"); + $info = [ + 'stage' => 'finished', + 'stage_name' => 'Database Maintenance!', + 'progress' => 1.0, + ]; + + $this->set_maintenance_info($info); + $this->info('Finished preparing Database Maintenance. You can now safely manipulate production database!'); } protected function set_maintenance_info($info) { - Storage::put("db.down", json_encode($info)); + Storage::put('db.down', json_encode($info)); } protected function free_maintenance_info() { - Storage::delete("db.down"); + Storage::delete('db.down'); } } diff --git a/app/Console/Commands/DBUp.php b/app/Console/Commands/DBUp.php index 3c899c4..6c08b21 100644 --- a/app/Console/Commands/DBUp.php +++ b/app/Console/Commands/DBUp.php @@ -3,9 +3,9 @@ namespace App\Console\Commands; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\Config; class DBUp extends Command { @@ -43,35 +43,32 @@ public function handle() // $info = $this->get_maintenance_info(); $this->free_maintenance_info(); + return; - if ($info != false) - { - $this->info("Starting maintenance mode!"); + if ($info != false) { + $this->info('Starting maintenance mode!'); $config = $this->argument('maintenance_to_use'); - if ($config == "") - { - $config = "maintenance"; + if ($config == '') { + $config = 'maintenance'; } $this->start_maintenance_mode($config); - } - else - { + } else { $this->error("Maintenance mode already on the way. Currently on stage: {$info['stage_name']}"); } } protected function get_maintenance_info() { - if (Storage::disk()->exists("db.down")) - { - $contents = Storage::get("db.down"); + if (Storage::disk()->exists('db.down')) { + $contents = Storage::get('db.down'); + return json_decode($contents, true); } return false; } - protected function start_maintenance_mode($config = "tmdb_maintenance") + protected function start_maintenance_mode($config = 'tmdb_maintenance') { $this->replicate_tables($config); @@ -80,21 +77,21 @@ protected function start_maintenance_mode($config = "tmdb_maintenance") protected function replicate_tables($config) { - $info = array( - "stage" => "db.replication", - "stage_name" => "Database Replication", - "progress" => 0.0 - ); + $info = [ + 'stage' => 'db.replication', + 'stage_name' => 'Database Replication', + 'progress' => 0.0, + ]; $this->set_maintenance_info($info); //Replicating database $from_db = Config::get("database.$config.from_database"); $to_db = Config::get("database.$config.to_database"); $connection = Config::get("database.$config.db_connection"); - if ($from_db == "" || $to_db == "") - { - $this->error("Please check your configuration!"); + if ($from_db == '' || $to_db == '') { + $this->error('Please check your configuration!'); $this->free_maintenance_info(); + return; } @@ -102,25 +99,23 @@ protected function replicate_tables($config) $conf_tables = Config::get("database.$config.tables"); $tables = $conf_tables; - if ($conf_tables == "all" || $conf_tables == "") - { - $tables = DB::select("SHOW TABLES FROM $from_db"); - $real_tables = array(); - foreach ($tables as $dict) { - foreach ($dict as $key => $value) { - $real_tables[] = $value; - } - } - $tables = $real_tables; + if ($conf_tables == 'all' || $conf_tables == '') { + $tables = DB::select("SHOW TABLES FROM $from_db"); + $real_tables = []; + foreach ($tables as $dict) { + foreach ($dict as $key => $value) { + $real_tables[] = $value; + } + } + $tables = $real_tables; } - $this->info("Replicating tables ".join(", ", $tables)); + $this->info('Replicating tables '.implode(', ', $tables)); $first_tables = Config::get("database.$config.tables_before"); - if (is_array($first_tables) && count($first_tables) > 0) - { - $this->info("Starting with table(s) ".join(",", $first_tables)); + if (is_array($first_tables) && count($first_tables) > 0) { + $this->info('Starting with table(s) '.implode(',', $first_tables)); foreach ($first_tables as $value) { if (($key = array_search($value, $tables)) !== false) { @@ -132,13 +127,13 @@ protected function replicate_tables($config) array_unshift($tables, $value); } - $this->info("Order of replication: ".join(", ", $tables)); + $this->info('Order of replication: '.implode(', ', $tables)); } $current = 0; $total = count($tables); - DB::connection($connection)->statement("SET foreign_key_checks = 0;"); + DB::connection($connection)->statement('SET foreign_key_checks = 0;'); foreach ($tables as $value) { try { DB::connection($connection)->statement("DROP TABLE $to_db.$value"); @@ -147,16 +142,14 @@ protected function replicate_tables($config) } $create_syntax = DB::select("SHOW CREATE TABLE $from_db.$value"); - $actual_syntax = ""; + $actual_syntax = ''; foreach ($create_syntax as $syntax) { //dd($syntax); foreach ($syntax as $key => $val) { - if ($key == "Create Table") - { + if ($key == 'Create Table') { $actual_syntax = $val; } } - } $actual_syntax = str_replace("`$value`", "`$to_db`.`$value`", $actual_syntax); @@ -165,38 +158,38 @@ protected function replicate_tables($config) DB::connection($connection)->statement("INSERT INTO $to_db.$value SELECT * FROM $from_db.$value"); $current += 1; $this->info("Replicated table $value. ($current/$total)"); - $info = array( - "stage" => "db.replication", - "stage_name" => "Database Replication", - "progress" => $current / (float)$total - ); + $info = [ + 'stage' => 'db.replication', + 'stage_name' => 'Database Replication', + 'progress' => $current / (float) $total, + ]; $this->set_maintenance_info($info); } - DB::connection($connection)->statement("SET foreign_key_checks = 1;"); + DB::connection($connection)->statement('SET foreign_key_checks = 1;'); - $this->info("Finished Replicating Database."); + $this->info('Finished Replicating Database.'); } protected function finish_preparations() { - $info = array( - "stage" => "finished", - "stage_name" => "Database Maintenance!", - "progress" => 1.0 - ); - - $this->set_maintenance_info($info); - $this->info("Finished preparing Database Maintenance. You can now safely manipulate production database!"); + $info = [ + 'stage' => 'finished', + 'stage_name' => 'Database Maintenance!', + 'progress' => 1.0, + ]; + + $this->set_maintenance_info($info); + $this->info('Finished preparing Database Maintenance. You can now safely manipulate production database!'); } protected function set_maintenance_info($info) { - Storage::put("db.down", json_encode($info)); + Storage::put('db.down', json_encode($info)); } protected function free_maintenance_info() { - Storage::delete("db.down"); + Storage::delete('db.down'); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7026235..ce9802a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -14,13 +14,14 @@ class Kernel extends ConsoleKernel */ protected $commands = [ Commands\DBDown::class, - Commands\DBUp::class + Commands\DBUp::class, ]; /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule + * @param \Illuminate\Console\Scheduling\Schedule $schedule + * * @return void */ protected function schedule(Schedule $schedule) diff --git a/app/Credit.php b/app/Credit.php index 86a8ac3..c90b035 100644 --- a/app/Credit.php +++ b/app/Credit.php @@ -6,9 +6,10 @@ class Credit extends Model { - protected $with = ["cast"]; + protected $with = ['cast']; - public function cast() { - return $this->hasMany("App\Person")->where("type", "=", "cast"); + public function cast() + { + return $this->hasMany("App\Person")->where('type', '=', 'cast'); } } diff --git a/app/Event.php b/app/Event.php index 62fee31..0504f52 100644 --- a/app/Event.php +++ b/app/Event.php @@ -8,36 +8,41 @@ class Event extends Model { protected $connection = 'mappings_mysql'; - protected $fillable = ["type", "mappings_id", "ip"]; + protected $fillable = ['type', 'mappings_id', 'ip']; public $timestamps = false; public function mapping() { - return $this->hasOne("App\Mapping", "id", "mappings_id"); + return $this->hasOne("App\Mapping", 'id', 'mappings_id'); } public function toArray() { $arr = parent::toArray(); - $arr["mapping"] = $this->mapping->toArray(); - unset($arr["ip"]); - $arr["mapping"]["movie"] = MappingMovie::find($arr["mapping"]["tmdbid"]); + $arr['mapping'] = $this->mapping->toArray(); + unset($arr['ip']); + $arr['mapping']['movie'] = MappingMovie::find($arr['mapping']['tmdbid']); + return $arr; } } -abstract class EventType extends Enum { +abstract class EventType extends Enum +{ const AddedMapping = 0; const ApproveMapping = 1; const DisapproveMapping = 2; const LockedMapping = 3; } -abstract class Enum { - static function getKeys(){ +abstract class Enum +{ + public static function getKeys() + { $class = new ReflectionClass(get_called_class()); + return array_keys($class->getConstants()); } } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 9433daa..81e7a7c 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,13 +3,11 @@ namespace App\Exceptions; use Exception; -use Illuminate\Auth\AuthenticationException; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use GrahamCampbell\Exceptions\NewExceptionHandler; +use Illuminate\Auth\AuthenticationException; //use GrahamCampbell\Exceptions\ExceptionIdentifier; //use GrahamCampbell\Exceptions\ExceptionHandlerTrait; use Illuminate\Support\Facades\Log; -use Psr\Log\LoggerInterface; class Handler extends NewExceptionHandler { @@ -33,7 +31,8 @@ class Handler extends NewExceptionHandler * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * - * @param \Exception $exception + * @param \Exception $exception + * * @return void */ public function report(Exception $exception) @@ -45,8 +44,9 @@ public function report(Exception $exception) /** * Render an exception into an HTTP response. * - * @param \Illuminate\Http\Request $request - * @param \Exception $e + * @param \Illuminate\Http\Request $request + * @param \Exception $e + * * @return \Illuminate\Http\Response */ public function render($request, Exception $e) @@ -89,8 +89,9 @@ public function render($request, Exception $e) /** * Convert an authentication exception into an unauthenticated response. * - * @param \Illuminate\Http\Request $request - * @param \Illuminate\Auth\AuthenticationException $exception + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Auth\AuthenticationException $exception + * * @return \Illuminate\Http\Response */ protected function unauthenticated($request, AuthenticationException $exception) diff --git a/app/Exceptions/TooManyRequestsHttpException.php b/app/Exceptions/TooManyRequestsHttpException.php index 8b6b228..6b28474 100644 --- a/app/Exceptions/TooManyRequestsHttpException.php +++ b/app/Exceptions/TooManyRequestsHttpException.php @@ -3,10 +3,11 @@ * Created by PhpStorm. * User: leonardogalli * Date: 13.08.17 - * Time: 17:42 + * Time: 17:42. */ namespace App\Exceptions; + use Carbon\Carbon; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -22,11 +23,11 @@ class TooManyRequestsHttpException extends HttpException */ public function __construct($retryAfter = null, $maxAttempts = null, \Exception $previous = null, $code = 0) { - $headers = array(); - $message = "You have sent too many requests."; + $headers = []; + $message = 'You have sent too many requests.'; if ($retryAfter) { - $headers = array('Retry-After' => $retryAfter); + $headers = ['Retry-After' => $retryAfter]; $headers['X-RateLimit-Reset'] = Carbon::now()->getTimestamp() + $retryAfter; $message .= " Please retry after $retryAfter seconds."; } diff --git a/app/Genre.php b/app/Genre.php index a1e1d08..0146584 100644 --- a/app/Genre.php +++ b/app/Genre.php @@ -6,9 +6,10 @@ class Genre extends Model { - protected $hidden = ["pivot"]; + protected $hidden = ['pivot']; - public function movies() { + public function movies() + { return $this->hasMany("App\Movie"); } } diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index a6d40ed..f4b7c28 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1,167 +1,168 @@ -addMinutes($rememberMinutes), function () use ($path, $selection) { + Log::info('Starting up imdb api'); + $resp = IMDBAPI::shared()->getJSON($path); + //dd($resp); + $ids = resolveMany($resp, $selection); + + $fullIds = []; + + foreach ($ids as $id) { + $fullIds[] = rtrim(str_ireplace('/title/', '', $id), '/'); + } + + $idStr = implode("','", $fullIds); + + $movies = DB::select("SELECT sub.* FROM (SELECT m.*, r.release_date as physical_release, r.note as physical_release_note, r.type from `movies` m LEFT JOIN release_dates r ON r.tmdbid = m.id AND r.type in (4,5,6) where m.`imdb_id` in ('$idStr') ORDER BY r.release_date) sub GROUP BY sub.id ORDER BY FIELD(imdb_id, '$idStr');"); + + $with_genres = []; + + foreach ($movies as $movie) { + $movie->genres = explode(',', $movie->genres); + $movie->adult = $movie->adult == 1; + unset($movie->type); + $with_genres[] = $movie; + } - public static function get_from_imdb_py($path, $selection, $rememberMinutes = 60*5) - { - //Cache::flush(); - return Cache::remember("imdb.$path", Carbon::now()->addMinutes($rememberMinutes), function() use ($path, $selection){ - Log::info("Starting up imdb api"); - $resp = IMDBAPI::shared()->getJSON($path); - //dd($resp); - $ids = resolveMany($resp, $selection); - - $fullIds = array(); - - foreach ($ids as $id) - { - $fullIds[] = rtrim(str_ireplace("/title/", "", $id), "/"); - } - - $idStr = join("','", $fullIds); - - $movies = DB::select("SELECT sub.* FROM (SELECT m.*, r.release_date as physical_release, r.note as physical_release_note, r.type from `movies` m LEFT JOIN release_dates r ON r.tmdbid = m.id AND r.type in (4,5,6) where m.`imdb_id` in ('$idStr') ORDER BY r.release_date) sub GROUP BY sub.id ORDER BY FIELD(imdb_id, '$idStr');"); - - $with_genres = array(); - - foreach ($movies as $movie) - { - $movie->genres = explode(",", $movie->genres); - $movie->adult = $movie->adult == 1; - unset($movie->type); - $with_genres[] = $movie; - } - - return $with_genres; - }); - } - - public static function clean_title($title) { - $title = strtolower($title); - $title = str_replace("ä", "ae", $title); - $title = str_replace("ö", "oe", $title); - $title = str_replace("ß", "ss", $title); - $title = str_replace("ü", "ue", $title); - $title = Helper::remove_accents( $title ); - $title = preg_replace("/((?:\b|_)(? 'A', chr(195).chr(129) => 'A', - chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', - chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', - chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', - chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', - chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', - chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', - chr(195).chr(143) => 'I', chr(195).chr(145) => 'N', - chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', - chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', - chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', - chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', - chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', - chr(195).chr(159) => 's', chr(195).chr(160) => 'a', - chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', - chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', - chr(195).chr(165) => 'a', chr(195).chr(167) => 'c', - chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', - chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', - chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', - chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', - chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', - chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', - chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', - chr(195).chr(182) => 'o', chr(195).chr(185) => 'u', - chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', - chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', - chr(195).chr(191) => 'y', - // Decompositions for Latin Extended-A - chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', - chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', - chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', - chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', - chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', - chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', - chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', - chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', - chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', - chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', - chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', - chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', - chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', - chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', - chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', - chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', - chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', - chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', - chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', - chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', - chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', - chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', - chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', - chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', - chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', - chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', - chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', - chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', - chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', - chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', - chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', - chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', - chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', - chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', - chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', - chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', - chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', - chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', - chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', - chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', - chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', - chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', - chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', - chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', - chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', - chr(197).chr(154) => 'S',chr(197).chr(155) => 's', - chr(197).chr(156) => 'S',chr(197).chr(157) => 's', - chr(197).chr(158) => 'S',chr(197).chr(159) => 's', - chr(197).chr(160) => 'S', chr(197).chr(161) => 's', - chr(197).chr(162) => 'T', chr(197).chr(163) => 't', - chr(197).chr(164) => 'T', chr(197).chr(165) => 't', - chr(197).chr(166) => 'T', chr(197).chr(167) => 't', - chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', - chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', - chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', - chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', - chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', - chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', - chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', - chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', - chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', - chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', - chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', - chr(197).chr(190) => 'z', chr(197).chr(191) => 's' - ); - - $string = strtr($string, $chars); - - return $string; - } + return $with_genres; + }); + } + + public static function clean_title($title) + { + $title = strtolower($title); + $title = str_replace('ä', 'ae', $title); + $title = str_replace('ö', 'oe', $title); + $title = str_replace('ß', 'ss', $title); + $title = str_replace('ü', 'ue', $title); + $title = self::remove_accents($title); + $title = preg_replace("/((?:\b|_)(? 'A', chr(195).chr(129) => 'A', + chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', + chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', + chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', + chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', + chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', + chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', + chr(195).chr(143) => 'I', chr(195).chr(145) => 'N', + chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', + chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', + chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', + chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', + chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', + chr(195).chr(159) => 's', chr(195).chr(160) => 'a', + chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', + chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', + chr(195).chr(165) => 'a', chr(195).chr(167) => 'c', + chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', + chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', + chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', + chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', + chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', + chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', + chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', + chr(195).chr(182) => 'o', chr(195).chr(185) => 'u', + chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', + chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', + chr(195).chr(191) => 'y', + // Decompositions for Latin Extended-A + chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', + chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', + chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', + chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', + chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', + chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', + chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', + chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', + chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', + chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', + chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', + chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', + chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', + chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', + chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', + chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', + chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', + chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', + chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', + chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', + chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', + chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', + chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', + chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', + chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', + chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij', + chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', + chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', + chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', + chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', + chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', + chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', + chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', + chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', + chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', + chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', + chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', + chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', + chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', + chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', + chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', + chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe', + chr(197).chr(148) => 'R', chr(197).chr(149) => 'r', + chr(197).chr(150) => 'R', chr(197).chr(151) => 'r', + chr(197).chr(152) => 'R', chr(197).chr(153) => 'r', + chr(197).chr(154) => 'S', chr(197).chr(155) => 's', + chr(197).chr(156) => 'S', chr(197).chr(157) => 's', + chr(197).chr(158) => 'S', chr(197).chr(159) => 's', + chr(197).chr(160) => 'S', chr(197).chr(161) => 's', + chr(197).chr(162) => 'T', chr(197).chr(163) => 't', + chr(197).chr(164) => 'T', chr(197).chr(165) => 't', + chr(197).chr(166) => 'T', chr(197).chr(167) => 't', + chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', + chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', + chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', + chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', + chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', + chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', + chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', + chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', + chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', + chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', + chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', + chr(197).chr(190) => 'z', chr(197).chr(191) => 's', + ]; + + $string = strtr($string, $chars); + + return $string; + } public static function generate_uuid_v4() { @@ -173,9 +174,7 @@ public static function generate_uuid_v4() $clockSeqHi &= ~(0xc0); $clockSeqHi |= 0x80; $params = [substr($hash, 0, 8), substr($hash, 8, 4), sprintf('%04x', $timeHi), sprintf('%02x', $clockSeqHi), substr($hash, 18, 2), substr($hash, 20, 12)]; + return vsprintf('%08s-%04s-%04s-%02s%02s-%012s', $params); } - } - - diff --git a/app/Helpers/HelperFunctions.php b/app/Helpers/HelperFunctions.php index 108809b..4829331 100644 --- a/app/Helpers/HelperFunctions.php +++ b/app/Helpers/HelperFunctions.php @@ -16,39 +16,31 @@ function resolveA(array $a, $path, $default = null) return $current; } -function resolveMany(array $a, $path, $default = array()) +function resolveMany(array $a, $path, $default = []) { $current = $a; $p = strtok($path, '.'); while ($p !== false) { - if ($p == "!all") - { - $ret = array(); + if ($p == '!all') { + $ret = []; $p = strtok('.'); - if ($p === false) - { + if ($p === false) { return $current; } - foreach ($current as $value) - { + foreach ($current as $value) { $ret[] = resolveMany($value, $p); - } + return $ret; - } - else - { + } else { if (!isset($current[$p])) { return $default; } $current = $current[$p]; $p = strtok('.'); } - } return $current; } - -?> \ No newline at end of file diff --git a/app/Helpers/IMDBAPI.php b/app/Helpers/IMDBAPI.php index 9ca3b91..2e37f25 100644 --- a/app/Helpers/IMDBAPI.php +++ b/app/Helpers/IMDBAPI.php @@ -3,24 +3,23 @@ * Created by PhpStorm. * User: leonardogalli * Date: 21.06.17 - * Time: 10:54 + * Time: 10:54. */ namespace App\Helpers; -use Illuminate\Foundation\Testing\HttpException; -use Illuminate\Support\Facades\Config; -use GuzzleHttp\Client; +use GuzzleHttp\Client; +use Illuminate\Support\Facades\Config; final class IMDBAPI { - private $API_KEY = ""; - private $API_SECRET = ""; + private $API_KEY = ''; + private $API_SECRET = ''; private $client; /** - * Call this method to get singleton + * Call this method to get singleton. * * @return UserFactory */ @@ -28,80 +27,73 @@ public static function shared() { static $inst = null; if ($inst === null) { - $inst = new IMDBAPI(); + $inst = new self(); } + return $inst; } /** - * Private ctor so nobody else can instance it - * + * Private ctor so nobody else can instance it. */ private function __construct() { - $this->API_KEY = Config::get("app.imdb_key"); - $this->API_SECRET = Config::get("app.imdb_secret"); + $this->API_KEY = Config::get('app.imdb_key'); + $this->API_SECRET = Config::get('app.imdb_secret'); $this->client = new Client([]); } - public function getJSON($path = "", $queryItems = array(), $host = "api.imdbws.com") + public function getJSON($path = '', $queryItems = [], $host = 'api.imdbws.com') { - try - { - $response = $this->request($path, $queryItems, "GET", $host, null); + try { + $response = $this->request($path, $queryItems, 'GET', $host, null); + return json_decode($response->getBody(), true); - } - catch (\GuzzleHttp\Exception\ClientException $e) { + } catch (\GuzzleHttp\Exception\ClientException $e) { $response = $e->getResponse(); - try - { - abort($response->getStatusCode(), json_decode($response->getBody(), true)["message"]); - } - catch (Exception $e) - { + + try { + abort($response->getStatusCode(), json_decode($response->getBody(), true)['message']); + } catch (Exception $e) { abort($response->getStatusCode(), $response->getReasonPhrase()); } - } return $response; } - public function request($path = "", $queryItems = array(), $method = "GET", $host = "api.imdbws.com", $postBody = null) + public function request($path = '', $queryItems = [], $method = 'GET', $host = 'api.imdbws.com', $postBody = null) { - $headers = ["user-agent" => "IMDb/7.2 (iPhone; iOS 10.2.1)"]; + $headers = ['user-agent' => 'IMDb/7.2 (iPhone; iOS 10.2.1)']; $signedHeaders = []; - if ($path == "" || $path == null) - { - $path = "/"; + if ($path == '' || $path == null) { + $path = '/'; } - if (!(stripos($path, "/") === 0)) - { - $path = "/" . $path; + if (!(stripos($path, '/') === 0)) { + $path = '/'.$path; } $query = $this->getCanocialQueryStr($queryItems); $url = "https://$host$path?$query"; - $timeStr = strftime("%a, %d %b %Y %H:%M:%S %Z"); - $headers["x-amz-date"] = $timeStr; + $timeStr = strftime('%a, %d %b %Y %H:%M:%S %Z'); + $headers['x-amz-date'] = $timeStr; - $headers["x-amzn-authorization"] = $this->createRequestSignature($method, $host, $path, $query, $postBody, $headers); + $headers['x-amzn-authorization'] = $this->createRequestSignature($method, $host, $path, $query, $postBody, $headers); //dd($headers); $response = $this->client->request($method, $url, [ - "headers" => $headers, - 'allow_redirects' => false + 'headers' => $headers, + 'allow_redirects' => false, ]); $statusCode = $response->getStatusCode(); - if ($statusCode == 301 || $statusCode == 302) - { - return $this->request(json_decode($response->getBody(), true)["link"], $queryItems, $method, $host, $postBody); + if ($statusCode == 301 || $statusCode == 302) { + return $this->request(json_decode($response->getBody(), true)['link'], $queryItems, $method, $host, $postBody); } return $response; @@ -110,53 +102,45 @@ public function request($path = "", $queryItems = array(), $method = "GET", $hos private function createRequestSignature($method, $host, $path, $query, $postBody, $headers) { $signedHeaders = []; - foreach ($headers as $key => $value) - { - if (stripos($key, "amz")!= false) - { + foreach ($headers as $key => $value) { + if (stripos($key, 'amz') != false) { $signedHeaders[$key] = $value; } } //$headersStr = join(";", $signedHeaders); - $cHeaders = ""; - $cHeaders .= "host:" . $host . "\n"; + $cHeaders = ''; + $cHeaders .= 'host:'.$host."\n"; foreach ($signedHeaders as $key => $value) { - $cHeaders .= $key . ":" . $value . "\n"; + $cHeaders .= $key.':'.$value."\n"; } $toSign = "$method\n$path\n$query\n$cHeaders\n"; //var_dump($toSign); //dd($toSign); - $signature = base64_encode(hash_hmac("sha256", hash("sha256", $toSign, true), $this->API_SECRET, True)); + $signature = base64_encode(hash_hmac('sha256', hash('sha256', $toSign, true), $this->API_SECRET, true)); - return "AWS3 AWSAccessKeyId={$this->API_KEY},Algorithm=HmacSHA256,Signature=$signature,SignedHeaders=" . join(";", array_keys($signedHeaders)); + return "AWS3 AWSAccessKeyId={$this->API_KEY},Algorithm=HmacSHA256,Signature=$signature,SignedHeaders=".implode(';', array_keys($signedHeaders)); } private function getCanocialQueryStr($queryItems) { - $queryStr = ""; + $queryStr = ''; foreach ($queryItems as $key => $value) { - if (is_array($value)) - { - foreach ($value as $v) - { - $queryStr .= $key . "=" . $v . "&"; + if (is_array($value)) { + foreach ($value as $v) { + $queryStr .= $key.'='.$v.'&'; } + } else { + $queryStr .= $key.'='.$value.'&'; } - else - { - $queryStr .= $key . "=" . $value . "&"; - } - } - $queryStr = rtrim($queryStr, ","); + $queryStr = rtrim($queryStr, ','); + return $queryStr; } - - -} \ No newline at end of file +} diff --git a/app/Helpers/MappingsCache.php b/app/Helpers/MappingsCache.php index 5a3f724..dcd68cc 100644 --- a/app/Helpers/MappingsCache.php +++ b/app/Helpers/MappingsCache.php @@ -3,17 +3,18 @@ namespace App\Helpers; use App\Mapping; -use Illuminate\Support\Facades\Cache; use Carbon\Carbon; +use Illuminate\Support\Facades\Cache; $mappingsStorageDate = Carbon::now()->addHours(4); class MappingsCache { - /** * Remembers a query for retrieving mapping objects in the cache. Automatically get's updated on voting as well as new additions. - * @param associative array $query Array containing keys and values to filter mappings by + * + * @param associative array $query Array containing keys and values to filter mappings by + * * @return array or object array of mappings */ /* @@ -24,17 +25,15 @@ public static function rememberQuery($query) { global $mappingsStorageDate; - if ($mappingsStorageDate == NULL) - { + if ($mappingsStorageDate == null) { $mappingsStorageDate = Carbon::now()->addHours(4); } //Cache::flush(); - $cache_key = MappingsCache::buildKeyFromQuery($query); + $cache_key = self::buildKeyFromQuery($query); - if (Cache::has($cache_key)) - { + if (Cache::has($cache_key)) { return Cache::get($cache_key); } @@ -42,94 +41,80 @@ public static function rememberQuery($query) Cache::put($cache_key, $results, $mappingsStorageDate); - if (count($results) == 0) - { + if (count($results) == 0) { return $results; } $tmdbid = 0; - $imdbid = ""; + $imdbid = ''; - if (!array_key_exists("tmdbid", $results) && !array_key_exists("id", $query)) - { - if (!array_key_exists("tmdbid", $query)) - { - $tmdbid = $results[0]["tmdbid"]; + if (!array_key_exists('tmdbid', $results) && !array_key_exists('id', $query)) { + if (!array_key_exists('tmdbid', $query)) { + $tmdbid = $results[0]['tmdbid']; } - if (!array_key_exists("imdbid", $query)) - { - $imdbid = $results[0]["imdbid"]; + if (!array_key_exists('imdbid', $query)) { + $imdbid = $results[0]['imdbid']; } } - $title_mappings = array(); + $title_mappings = []; - $year_mappings = array(); + $year_mappings = []; - foreach ($results as $mapping) - { - $type = $mapping["mapable_type"]; - if ($type == "title") - { + foreach ($results as $mapping) { + $type = $mapping['mapable_type']; + if ($type == 'title') { $title_mappings[] = $mapping; - } else if ($type == "year") - { + } elseif ($type == 'year') { $year_mappings[] = $mapping; } - Cache::put(MappingsCache::buildKeyFromQuery(array("id" => $mapping["id"])), $mapping, $mappingsStorageDate); + Cache::put(self::buildKeyFromQuery(['id' => $mapping['id']]), $mapping, $mappingsStorageDate); } - $to_cache = array(); + $to_cache = []; - $tmdb_query = array("tmdbid" => $tmdbid); - $imdb_query = array("imdbid" => $imdbid); + $tmdb_query = ['tmdbid' => $tmdbid]; + $imdb_query = ['imdbid' => $imdbid]; - if (array_key_exists("mapable_type", $query)) - { - $tmdb_query["mapable_type"] = $query["mapable_type"]; - $imdb_query["mapable_type"] = $query["mapable_type"]; + if (array_key_exists('mapable_type', $query)) { + $tmdb_query['mapable_type'] = $query['mapable_type']; + $imdb_query['mapable_type'] = $query['mapable_type']; - if ($tmdbid !== 0) - { - $to_cache[] = array($tmdb_query, $results); + if ($tmdbid !== 0) { + $to_cache[] = [$tmdb_query, $results]; } - if ($imdbid !== "") - { - $to_cache[] = array($imdb_query, $results); + if ($imdbid !== '') { + $to_cache[] = [$imdb_query, $results]; } - } else - { - if ($tmdbid !== 0) - { - $to_cache[] = array($tmdb_query, $results); + } else { + if ($tmdbid !== 0) { + $to_cache[] = [$tmdb_query, $results]; } - $tmdbid = $results[0]["tmdbid"]; - $tmdb_query = array("tmdbid" => $tmdbid); - $tmdb_query["mapable_type"] = "title"; - $to_cache[] = array($tmdb_query, $title_mappings); - $tmdb_query["mapable_type"] = "year"; - $to_cache[] = array($tmdb_query, $year_mappings); + $tmdbid = $results[0]['tmdbid']; + $tmdb_query = ['tmdbid' => $tmdbid]; + $tmdb_query['mapable_type'] = 'title'; + $to_cache[] = [$tmdb_query, $title_mappings]; + $tmdb_query['mapable_type'] = 'year'; + $to_cache[] = [$tmdb_query, $year_mappings]; - if ($imdbid !== "") - { - $to_cache[] = array($imdb_query, $results); + if ($imdbid !== '') { + $to_cache[] = [$imdb_query, $results]; } - $imdbid = $results[0]["imdbid"]; - $imdb_query = array("imdbid" => $imdbid); - $imdb_query["mapable_type"] = "title"; - $to_cache[] = array($imdb_query, $title_mappings); - $imdb_query["mapable_type"] = "year"; - $to_cache[] = array($imdb_query, $year_mappings); + $imdbid = $results[0]['imdbid']; + $imdb_query = ['imdbid' => $imdbid]; + $imdb_query['mapable_type'] = 'title'; + $to_cache[] = [$imdb_query, $title_mappings]; + $imdb_query['mapable_type'] = 'year'; + $to_cache[] = [$imdb_query, $year_mappings]; } - foreach ($to_cache as $item) - { - Cache::put(MappingsCache::buildKeyFromQuery($item[0]), $item[1], $mappingsStorageDate); + foreach ($to_cache as $item) { + Cache::put(self::buildKeyFromQuery($item[0]), $item[1], $mappingsStorageDate); } //dd($to_cache); @@ -139,23 +124,22 @@ public static function rememberQuery($query) public static function updateMapping(Mapping $mapping) { - $possible_storage_locations = array( - "tmdbid" => $mapping->tmdbid, - "imdbid" => $mapping->imdbid - ); + $possible_storage_locations = [ + 'tmdbid' => $mapping->tmdbid, + 'imdbid' => $mapping->imdbid, + ]; - $possible_object_location = array( - "id" => $mapping->id - ); + $possible_object_location = [ + 'id' => $mapping->id, + ]; $type = $mapping->mapable_type; - MappingsCache::updateMappingWithQuery($mapping, $possible_object_location); + self::updateMappingWithQuery($mapping, $possible_object_location); - foreach ($possible_storage_locations as $key => $value) - { - MappingsCache::updateMappingWithQuery($mapping, array($key => $value)); - MappingsCache::updateMappingWithQuery($mapping, array($key => $value, "mapable_type" => $type)); + foreach ($possible_storage_locations as $key => $value) { + self::updateMappingWithQuery($mapping, [$key => $value]); + self::updateMappingWithQuery($mapping, [$key => $value, 'mapable_type' => $type]); } } @@ -163,57 +147,45 @@ private static function updateMappingWithQuery(Mapping $mapping, $query) { global $mappingsStorageDate; - if ($mappingsStorageDate == NULL) - { + if ($mappingsStorageDate == null) { $mappingsStorageDate = Carbon::now()->addHours(4); } - $key = MappingsCache::buildKeyFromQuery($query); - if (Cache::has($key)) - { + $key = self::buildKeyFromQuery($query); + if (Cache::has($key)) { $results = Cache::get($key); - $newResults = array(); + $newResults = []; - if (array_key_exists("id", $results)) - { + if (array_key_exists('id', $results)) { Cache::put($key, $mapping->toArray(), $mappingsStorageDate); + return; } - foreach ($results as $result) - { - if ($result["id"] == $mapping->id) - { + foreach ($results as $result) { + if ($result['id'] == $mapping->id) { $newResults[] = $mapping->toArray(); - } else - { + } else { $newResults[] = $result; } } Cache::put($key, $newResults, $mappingsStorageDate); } - } - private static function buildKeyFromQuery($query, $key_seperator = "-", $seperator = "-", $prefix = "mappings") + private static function buildKeyFromQuery($query, $key_seperator = '-', $seperator = '-', $prefix = 'mappings') { - $cache_key = ""; - foreach ($query as $key => $value) - { - $cache_key .= $seperator . $key . $key_seperator . $value; + $cache_key = ''; + foreach ($query as $key => $value) { + $cache_key .= $seperator.$key.$key_seperator.$value; } $pos = strpos($cache_key, $seperator); - if ($pos !== false) - { - $cache_key = substr_replace($cache_key, "", $pos, strlen($seperator)); + if ($pos !== false) { + $cache_key = substr_replace($cache_key, '', $pos, strlen($seperator)); } return "$prefix.".$cache_key; } } - - - - ?> diff --git a/app/Http/Controllers/API/DiscoverController.php b/app/Http/Controllers/API/DiscoverController.php index 7c4c671..522e94a 100644 --- a/app/Http/Controllers/API/DiscoverController.php +++ b/app/Http/Controllers/API/DiscoverController.php @@ -2,19 +2,14 @@ namespace App\Http\Controllers\API; -use Carbon\Carbon; - -use App\User; use App\Movie; use App\StevenLuMovie; -use App\Http\Controllers\Controller; +use Carbon\Carbon; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Input; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; - +use Symfony\Component\HttpFoundation\Response; class DiscoverController extends JSONController { @@ -22,136 +17,139 @@ class DiscoverController extends JSONController * Returns a json string for api usage. * * @param int $id + * * @return Response */ - public function upcoming() { - $resp = array(); - $resp = Cache::remember("discovery.upcoming", Carbon::now()->addHours(12), function (){ - return Movie::whereHas("release_dates", function($query) { - $query->whereIn("type", array(4,5,6))->whereBetween("release_date", array(Carbon::now()->subWeek(), Carbon::now()->addWeeks(3)))->orderBy("release_date", "ASC"); - })->orderBy("popularity", "DESC")->filter()->get(); - }); - return $resp; - } - - public function popular() { - $movies = Cache::remember("discovery.popular", new Carbon('tomorrow midnight'), function(){ - return array_values(StevenLuMovie::all()->sortByDesc("TMDBMovie.popularity")->toArray()); - }); - $movies = $this->filterMovies($movies); - return response()->json($movies); - } - - - protected $vote_max = 0; - protected $pop_max = 0; - protected $count_max = 0; - - public function recommendations(Request $request) { - $ids = $request->input("tmdbIds", []); - $ignoredIds = $request->input("ignoredIds", []); - /*$movies = Cache::remember("discovery.recommendations.$ids.$ignoredIds", new Carbon("tomorrow midnight"), function() use($ignoredIds, $ids){ - if ($ignoredIds != "") - { - $ignoredIds = ",".$ignoredIds; - } - - if ($ids == "" || $ids == null) - { - abort(422, "Please add some movies before using our recommendation engine :)"); - } - $movies_db = DB::select("SELECT mo.id, mo.popularity, mo.imdb_id, mo.title, mo.overview, mo.vote_average, mo.vote_count, mo.tagline, mo.poster_path, mo.release_date, mo.release_year, mo.trailer_key, mo.trailer_site, mo.backdrop_path, mo.homepage, mo.runtime, mo.countO, mo.genres, mo.runtime, mo.adult FROM ( SELECT m.*, r.recommended_id, r.tmdbid, r.id as rid, count(m.id) as countO FROM movies m, recommendations r WHERE m.id = r.recommended_id AND r.tmdbid in ($ids) AND r.recommended_id not in ($ids$ignoredIds) AND m.adult = 0 GROUP BY m.id ) as mo;"); - $movies = json_decode(json_encode($movies_db), true); - - $this->count_max = maximum($movies, "countO"); - $this->pop_max = maximum($movies, "popularity"); - $this->vote_max = maximum($movies, "vote_average"); - - usort($movies, array($this, "compare_score")); - - $movies = array_slice($movies, 0, 30); - $resp = []; - - foreach ($movies as $movie) { - unset($movie["countO"]); - $movie["genres"] = explode(",", $movie["genres"]); - $movie["adult"] = $movie["adult"] == 1; - $resp[] = $movie; - } - - return $resp; - }); - - $movies = $this->filterMovies($movies); + public function upcoming() + { + $resp = []; + $resp = Cache::remember('discovery.upcoming', Carbon::now()->addHours(12), function () { + return Movie::whereHas('release_dates', function ($query) { + $query->whereIn('type', [4, 5, 6])->whereBetween('release_date', [Carbon::now()->subWeek(), Carbon::now()->addWeeks(3)])->orderBy('release_date', 'ASC'); + })->orderBy('popularity', 'DESC')->filter()->get(); + }); + + return $resp; + } + + public function popular() + { + $movies = Cache::remember('discovery.popular', new Carbon('tomorrow midnight'), function () { + return array_values(StevenLuMovie::all()->sortByDesc('TMDBMovie.popularity')->toArray()); + }); + $movies = $this->filterMovies($movies); + + return response()->json($movies); + } + + protected $vote_max = 0; + protected $pop_max = 0; + protected $count_max = 0; + + public function recommendations(Request $request) + { + $ids = $request->input('tmdbIds', []); + $ignoredIds = $request->input('ignoredIds', []); + /*$movies = Cache::remember("discovery.recommendations.$ids.$ignoredIds", new Carbon("tomorrow midnight"), function() use($ignoredIds, $ids){ + if ($ignoredIds != "") + { + $ignoredIds = ",".$ignoredIds; + } + + if ($ids == "" || $ids == null) + { + abort(422, "Please add some movies before using our recommendation engine :)"); + } + $movies_db = DB::select("SELECT mo.id, mo.popularity, mo.imdb_id, mo.title, mo.overview, mo.vote_average, mo.vote_count, mo.tagline, mo.poster_path, mo.release_date, mo.release_year, mo.trailer_key, mo.trailer_site, mo.backdrop_path, mo.homepage, mo.runtime, mo.countO, mo.genres, mo.runtime, mo.adult FROM ( SELECT m.*, r.recommended_id, r.tmdbid, r.id as rid, count(m.id) as countO FROM movies m, recommendations r WHERE m.id = r.recommended_id AND r.tmdbid in ($ids) AND r.recommended_id not in ($ids$ignoredIds) AND m.adult = 0 GROUP BY m.id ) as mo;"); + $movies = json_decode(json_encode($movies_db), true); + + $this->count_max = maximum($movies, "countO"); + $this->pop_max = maximum($movies, "popularity"); + $this->vote_max = maximum($movies, "vote_average"); + + usort($movies, array($this, "compare_score")); + + $movies = array_slice($movies, 0, 30); + $resp = []; + + foreach ($movies as $movie) { + unset($movie["countO"]); + $movie["genres"] = explode(",", $movie["genres"]); + $movie["adult"] = $movie["adult"] == 1; + $resp[] = $movie; + } + + return $resp; + }); + + $movies = $this->filterMovies($movies); return response()->json(array_values($movies));*/ - $movies = Movie::withCount(["recommendedFrom" => function($q) use ($ids){ - $q->whereIn("id", $ids); - }])->whereNotIn("id", array_merge($ignoredIds, $ids))->whereIn("id", function($q) use ($ids){ - $q->from("movies as m") + $movies = Movie::withCount(['recommendedFrom' => function ($q) use ($ids) { + $q->whereIn('id', $ids); + }])->whereNotIn('id', array_merge($ignoredIds, $ids))->whereIn('id', function ($q) use ($ids) { + $q->from('movies as m') ->selectRaw('recommendations.recommended_id') ->join('recommendations', 'm.id', '=', 'recommendations.movie_id') ->whereRaw('recommendations.recommended_id = `movies`.`id`') - ->whereIn("id", $ids); - })->filter()->get(); - - $count_max = $movies->max("recommended_from_count"); - $pop_max = $movies->max("popularity"); - //$vote_max = maximum($movies, "vote_average"); - - $sorted = $movies->sortByDesc(function($movie, $key) use ($count_max, $pop_max){ - return (float)($movie->popularity) / (2*$pop_max) + (float)($movie->recommended_from_count) / (2*$count_max); - }); - - //usort($movies, array($this, "compare_score")); - - //return response("Hi")->header("Content-Type", "text/html"); - return $sorted->values(); - } - - function filterMovies($movies) - { - $yearLower = Input::get('yearLower', 1800); - $yearUpper = Input::get('yearUpper', 2300); - $genreIds = Input::get('genreIds', ""); - if (!(is_array($genreIds) || $genreIds === null)) - { - $genreIds = explode(",", $genreIds); - } - return array_filter($movies, function($value) use ($yearLower, $yearUpper, $genreIds) { - //dd($genreIds); - return $value["release_year"] >= $yearLower && $value["release_year"] <= $yearUpper && ($genreIds != array("") ? count(array_intersect($value["genres"], $genreIds)) > 0 : true); - }); - } - - function score ($elem) - { - - return (float)($elem["vote_average"]) / ($this->vote_max) + (float)($elem["popularity"]) / (2*$this->pop_max) + (float)($elem["countO"]) / (2*$this->count_max); - } - - function compare_score ($a, $b) { - - if ($this->score($a) > $this->score($b)) { - return -1; - } else { - return 1; - } - } -} + ->whereIn('id', $ids); + })->filter()->get(); + + $count_max = $movies->max('recommended_from_count'); + $pop_max = $movies->max('popularity'); + //$vote_max = maximum($movies, "vote_average"); + + $sorted = $movies->sortByDesc(function ($movie, $key) use ($count_max, $pop_max) { + return (float) ($movie->popularity) / (2 * $pop_max) + (float) ($movie->recommended_from_count) / (2 * $count_max); + }); + + //usort($movies, array($this, "compare_score")); + + //return response("Hi")->header("Content-Type", "text/html"); + return $sorted->values(); + } -function maximum($arr, $key) { - $max = 0.0; + public function filterMovies($movies) + { + $yearLower = Input::get('yearLower', 1800); + $yearUpper = Input::get('yearUpper', 2300); + $genreIds = Input::get('genreIds', ''); + if (!(is_array($genreIds) || $genreIds === null)) { + $genreIds = explode(',', $genreIds); + } + + return array_filter($movies, function ($value) use ($yearLower, $yearUpper, $genreIds) { + //dd($genreIds); + return $value['release_year'] >= $yearLower && $value['release_year'] <= $yearUpper && ($genreIds != [''] ? count(array_intersect($value['genres'], $genreIds)) > 0 : true); + }); + } - foreach ($arr as $elem) { - $val = $elem[$key]; - if ((double)$val > $max) { - $max = $val; + public function score($elem) + { + return (float) ($elem['vote_average']) / ($this->vote_max) + (float) ($elem['popularity']) / (2 * $this->pop_max) + (float) ($elem['countO']) / (2 * $this->count_max); } - } - return $max; + public function compare_score($a, $b) + { + if ($this->score($a) > $this->score($b)) { + return -1; + } else { + return 1; + } + } } -?> +function maximum($arr, $key) +{ + $max = 0.0; + + foreach ($arr as $elem) { + $val = $elem[$key]; + if ((float) $val > $max) { + $max = $val; + } + } + + return $max; +} diff --git a/app/Http/Controllers/API/IMDBController.php b/app/Http/Controllers/API/IMDBController.php index e9ed5a3..70f2ca0 100644 --- a/app/Http/Controllers/API/IMDBController.php +++ b/app/Http/Controllers/API/IMDBController.php @@ -2,16 +2,10 @@ namespace App\Http\Controllers\API; -use App\Movie; -use Carbon\Carbon; use App\Http\Requests\IMDBListRequest; -use App\Http\Controllers\Controller; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Cache; use Helper; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; class IMDBController extends JSONController { @@ -19,37 +13,38 @@ class IMDBController extends JSONController * Returns a json string for api usage. * * @param int $id + * * @return Response */ - public function top250(Request $request) { - $movies = Helper::get_from_imdb_py("/template/imdb-android-writable/6.4.list-top250-skeleton.jstl/render", "!all"); - return response()->json($movies); - } - - public function popular(Request $request) { - $limit = 10; - if ($request->query("limit") != NULL) - { - $limit = $request->query("limit"); - } - $movies = Helper::get_from_imdb_py("/template/imdb-android-writable/6.4.movies-popular-titles.jstl/render", "ranks.!all.id"); - return response()->json($movies); - } - - public function user_list(IMDBListRequest $request) { - $listId = $request->query("listId"); - $path = "/lists/"; - if (stripos($listId, "ur") !== false) - { - $path .= $listId . "/watchlist/"; - } - else - { - $path.= $listId; - } - $movies = Helper::get_from_imdb_py($path, "list.items.!all.entityId", 5); - return response()->json($movies); - } -} + public function top250(Request $request) + { + $movies = Helper::get_from_imdb_py('/template/imdb-android-writable/6.4.list-top250-skeleton.jstl/render', '!all'); -?> + return response()->json($movies); + } + + public function popular(Request $request) + { + $limit = 10; + if ($request->query('limit') != null) { + $limit = $request->query('limit'); + } + $movies = Helper::get_from_imdb_py('/template/imdb-android-writable/6.4.movies-popular-titles.jstl/render', 'ranks.!all.id'); + + return response()->json($movies); + } + + public function user_list(IMDBListRequest $request) + { + $listId = $request->query('listId'); + $path = '/lists/'; + if (stripos($listId, 'ur') !== false) { + $path .= $listId.'/watchlist/'; + } else { + $path .= $listId; + } + $movies = Helper::get_from_imdb_py($path, 'list.items.!all.entityId', 5); + + return response()->json($movies); + } +} diff --git a/app/Http/Controllers/API/JSONController.php b/app/Http/Controllers/API/JSONController.php index f9827d6..8bfaf21 100644 --- a/app/Http/Controllers/API/JSONController.php +++ b/app/Http/Controllers/API/JSONController.php @@ -2,44 +2,45 @@ namespace App\Http\Controllers\API; -use App\User; use App\Http\Controllers\Controller; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; class JSONController extends Controller { /** * Returns a json string for api usage. * - * @param int $id + * @param int $id + * * @return Response */ - public function json_view($object) { - $ret_str = ""; - if (is_string($object)) { - $ret_str = $object; - } else { - $ret_str = json_encode($this->utf8ize($object)); + public function json_view($object) + { + $ret_str = ''; + if (is_string($object)) { + $ret_str = $object; + } else { + $ret_str = json_encode($this->utf8ize($object)); + } + + return response($ret_str, 200)->header('Content-Type', 'application/json')->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); } - return response($ret_str, 200)->header("Content-Type", "application/json")->header("Access-Control-Allow-Origin", "*")->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); - } - public function utf8ize($mixed) { - if (is_array($mixed)) { - foreach ($mixed as $key => $value) { - $mixed[$key] = $this->utf8ize($value); - } - } else if (is_string ($mixed)) { - return utf8_encode($mixed); - } + public function utf8ize($mixed) + { + if (is_array($mixed)) { + foreach ($mixed as $key => $value) { + $mixed[$key] = $this->utf8ize($value); + } + } elseif (is_string($mixed)) { + return utf8_encode($mixed); + } - return $mixed; - } + return $mixed; + } - public function ping() { - return response()->json(array("message" => "pong")); - } + public function ping() + { + return response()->json(['message' => 'pong']); + } } - -?> diff --git a/app/Http/Controllers/API/MappingsController.php b/app/Http/Controllers/API/MappingsController.php index de499ef..0fa8d77 100644 --- a/app/Http/Controllers/API/MappingsController.php +++ b/app/Http/Controllers/API/MappingsController.php @@ -2,31 +2,20 @@ namespace App\Http\Controllers\API; +use App\Event; use App\EventType; +use App\Http\Requests\MappingAddRequest; +use App\Http\Requests\MappingFindRequest; +use App\Http\Requests\MappingGetRequest; +use App\Mapping; +use App\MappingMovie; +use App\Movie; use App\TitleInfo; use App\YearInfo; use Carbon\Carbon; - -use App\User; -use App\Movie; -use App\Mapping; -use App\TitleMapping; -use App\YearMapping; -use App\Http\Controllers\Controller; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Cache; use Helper; -use MappingsCache; -use App\Event; -use App\MappingMovie; -use App\Http\Requests; -use App\Http\Requests\MappingAddRequest; -use App\Http\Requests\MappingFindRequest; -use App\Http\Requests\MappingGetRequest; - +use Illuminate\Support\Facades\Cache; +use Symfony\Component\HttpFoundation\Response; class MappingsController extends JSONController { @@ -34,65 +23,62 @@ class MappingsController extends JSONController * Returns a json string for api usage. * * @param int $id + * * @return Response */ - public function get(MappingGetRequest $request) { - $id = $request->query("id"); + public function get(MappingGetRequest $request) + { + $id = $request->query('id'); - $mapping = Mapping::find($id); + $mapping = Mapping::find($id); - if ($mapping == null) - { - abort(404, "Mapping with id $id was not found. Maybe it was removed?"); - } + if ($mapping == null) { + abort(404, "Mapping with id $id was not found. Maybe it was removed?"); + } - return response()->json($mapping)->header("Access-Control-Allow-Origin", "*"); - } + return response()->json($mapping)->header('Access-Control-Allow-Origin', '*'); + } - public function find(MappingFindRequest $request) - { - $tmdbid = $request->query("tmdbid"); - $movie = MappingMovie::find($tmdbid); + public function find(MappingFindRequest $request) + { + $tmdbid = $request->query('tmdbid'); + $movie = MappingMovie::find($tmdbid); - if ($movie == null) - { - abort(404, "Movie with tmdbid $tmdbid was not found. Either it does not exist or no mappings have been added yet."); - } + if ($movie == null) { + abort(404, "Movie with tmdbid $tmdbid was not found. Either it does not exist or no mappings have been added yet."); + } - $type = $request->query("type"); - $language = $request->query("language", "en"); + $type = $request->query('type'); + $language = $request->query('language', 'en'); - $titles = []; - $years = []; + $titles = []; + $years = []; - if ($type == "title" || $type == "all" || $type == null) - { - $titles = Mapping::where("tmdbid", "=", $tmdbid)->where("info_type", "=", "title")->whereHas("title_info", function($query) use($language){ - $query->where("language", "=", $language); - })->get()->toArray(); - } + if ($type == 'title' || $type == 'all' || $type == null) { + $titles = Mapping::where('tmdbid', '=', $tmdbid)->where('info_type', '=', 'title')->whereHas('title_info', function ($query) use ($language) { + $query->where('language', '=', $language); + })->get()->toArray(); + } - if ($type == "year" || $type == "all" || $type == null) - { - $years = Mapping::where("tmdbid", "=", $tmdbid)->where("info_type", "=", "year")->get()->toArray(); - } + if ($type == 'year' || $type == 'all' || $type == null) { + $years = Mapping::where('tmdbid', '=', $tmdbid)->where('info_type', '=', 'year')->get()->toArray(); + } - $movie["mappings"] = ["titles" => $titles, "years" => $years]; + $movie['mappings'] = ['titles' => $titles, 'years' => $years]; - return response()->json($movie)->header("Access-Control-Allow-Origin", "*"); - } + return response()->json($movie)->header('Access-Control-Allow-Origin', '*'); + } - public function add(MappingAddRequest $request) { - $tmdbid = $request->query("tmdbid"); - $type = $request->query("type"); + public function add(MappingAddRequest $request) + { + $tmdbid = $request->query('tmdbid'); + $type = $request->query('type'); //Ensure that the movie is in our mapping database! - if (!MappingMovie::find($tmdbid)) - { + if (!MappingMovie::find($tmdbid)) { $movie = Movie::find($tmdbid); - if ($movie == null) - { - abort(422, "The movie with the given tmdbid could not be found!"); + if ($movie == null) { + abort(422, 'The movie with the given tmdbid could not be found!'); } $movie->createMappingMovie()->save(); } @@ -100,33 +86,31 @@ public function add(MappingAddRequest $request) { $existing = false; $info = null; - if ($type == "title") - { - $aka_title = $request->get("aka_title"); - $title_language = $request->get("language", "en"); + if ($type == 'title') { + $aka_title = $request->get('aka_title'); + $title_language = $request->get('language', 'en'); $aka_clean_title = Helper::clean_title($aka_title); - $existing = Mapping::whereHas("title_info", function($query) use($aka_clean_title){ - $query->where("aka_clean_title", "=", $aka_clean_title); + $existing = Mapping::whereHas('title_info', function ($query) use ($aka_clean_title) { + $query->where('aka_clean_title', '=', $aka_clean_title); })->first(); - $info = new TitleInfo(["aka_title" => $aka_title, "aka_clean_title" => $aka_clean_title, "language" => $title_language]); - } - else - { - $aka_year = $request->get("aka_year"); - $existing = Mapping::whereHas("year_info", function($query) use($aka_year){ - $query->where("aka_year", "=", $aka_year); + $info = new TitleInfo(['aka_title' => $aka_title, 'aka_clean_title' => $aka_clean_title, 'language' => $title_language]); + } else { + $aka_year = $request->get('aka_year'); + $existing = Mapping::whereHas('year_info', function ($query) use ($aka_year) { + $query->where('aka_year', '=', $aka_year); })->first(); - $info = new YearInfo(["aka_year" => $aka_year]); + $info = new YearInfo(['aka_year' => $aka_year]); } if ($existing != null && $existing != false) { $existing->vote(); + return response()->json($existing); } $info->save(); - $mapping = new Mapping(["tmdbid" => $tmdbid, "info_type" => $type, "info_id" => $info->id]); + $mapping = new Mapping(['tmdbid' => $tmdbid, 'info_type' => $type, 'info_id' => $info->id]); $mapping->save(); @@ -136,43 +120,40 @@ public function add(MappingAddRequest $request) { $mapping->vote_count = 1; $mapping->locked = false; - $event = new Event(["type" => EventType::AddedMapping, "mappings_id" => $mapping->id, "ip" => md5($_SERVER['REMOTE_ADDR'])]); + $event = new Event(['type' => EventType::AddedMapping, 'mappings_id' => $mapping->id, 'ip' => md5($_SERVER['REMOTE_ADDR'])]); $event->save(); - return response()->json($mapping)->header("Access-Control-Allow-Origin", "*"); - } + return response()->json($mapping)->header('Access-Control-Allow-Origin', '*'); + } - public function vote(MappingGetRequest $request) { - $id = $request->query("id"); - $direction = $request->query("direction"); - if (!isset($direction) || $direction > 1) - { - $direction = 1; - } + public function vote(MappingGetRequest $request) + { + $id = $request->query('id'); + $direction = $request->query('direction'); + if (!isset($direction) || $direction > 1) { + $direction = 1; + } - if ($direction < 1) - { - $direction = -1; - } - $mapping = Mapping::find($id); + if ($direction < 1) { + $direction = -1; + } + $mapping = Mapping::find($id); - if ($mapping == null) - { - abort(404,"Mapping with id $id was not found. Maybe it was removed?"); - } + if ($mapping == null) { + abort(404, "Mapping with id $id was not found. Maybe it was removed?"); + } - $mapping->vote($direction); + $mapping->vote($direction); - return response()->json($mapping)->header("Access-Control-Allow-Origin", "*"); - } + return response()->json($mapping)->header('Access-Control-Allow-Origin', '*'); + } - public function latest() { - $events = Cache::remember("mappings.latest", Carbon::now()->addMinutes(1), function(){ - return Event::where("type", "=", 0)->orderByDesc("date")->limit(5)->get()->toArray(); + public function latest() + { + $events = Cache::remember('mappings.latest', Carbon::now()->addMinutes(1), function () { + return Event::where('type', '=', 0)->orderByDesc('date')->limit(5)->get()->toArray(); }); - return response()->json($events)->header("Access-Control-Allow-Origin", "*"); - } + return response()->json($events)->header('Access-Control-Allow-Origin', '*'); + } } - -?> diff --git a/app/Http/Controllers/API/MovieController.php b/app/Http/Controllers/API/MovieController.php index 1416e70..d51fa38 100644 --- a/app/Http/Controllers/API/MovieController.php +++ b/app/Http/Controllers/API/MovieController.php @@ -2,18 +2,18 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Movie; use Carbon\Carbon; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Input; -use App\Http\Controllers\Controller; class MovieController extends Controller { public function refresh_movies() { - $ids = Input::get("ids"); - $movies = Movie::whereIn("id", $ids)->where("updated_at", ">", Carbon::now()->subDay()); + $ids = Input::get('ids'); + $movies = Movie::whereIn('id', $ids)->where('updated_at', '>', Carbon::now()->subDay()); + return $movies->paginate(250); } diff --git a/app/Http/Controllers/API/PersonController.php b/app/Http/Controllers/API/PersonController.php index b1136b7..33fbdcc 100644 --- a/app/Http/Controllers/API/PersonController.php +++ b/app/Http/Controllers/API/PersonController.php @@ -2,9 +2,8 @@ namespace App\Http\Controllers\API; -use App\Person; -use Illuminate\Http\Request; use App\Http\Controllers\Controller; +use App\Person; use Illuminate\Support\Facades\Input; class PersonController extends Controller @@ -14,16 +13,14 @@ public function person_movies(int $id) $person = Person::findOrFail($id); $query = $person->movies()->filter(); - $credit_type = Input::get("credit_type", null); - if ($credit_type != null) - { - $query = $query->wherePivot("type", $credit_type); + $credit_type = Input::get('credit_type', null); + if ($credit_type != null) { + $query = $query->wherePivot('type', $credit_type); } - $credit_department = Input::get("credit_department", null); - if ($credit_department != null) - { - $deps = explode(",", $credit_department); - $query = $query->wherePivotIn("department", $deps); + $credit_department = Input::get('credit_department', null); + if ($credit_department != null) { + $deps = explode(',', $credit_department); + $query = $query->wherePivotIn('department', $deps); } return $query->get(); diff --git a/app/Http/Controllers/API/SearchController.php b/app/Http/Controllers/API/SearchController.php index 8f59db1..d8eb0e9 100644 --- a/app/Http/Controllers/API/SearchController.php +++ b/app/Http/Controllers/API/SearchController.php @@ -6,13 +6,11 @@ use App\Movie; use App\Person; use Carbon\Carbon; -use App\Http\Controllers\Controller; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Cache; use Helper; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Tmdb\ApiToken; use Tmdb\Client; @@ -22,56 +20,56 @@ class SearchController extends JSONController * Returns a json string for api usage. * * @param int $id + * * @return Response */ - public function suggestions(Request $request) { - $query = $request->query("query"); - $title = Helper::clean_title($query); - //SELECT m.id, m.title as name, m.release_year, m.poster_path FROM movies m WHERE m.clean_title LIKE '%$term%' ORDER BY m.popularity DESC LIMIT 5 - $movies = Cache::remember("suggestions.$title", new Carbon('tomorrow midnight'), function() use ($title) { - return Movie::select("id", "title as name", "release_year", "poster_path")->where("clean_title", "LIKE", "%".$title."%")->orderBy("popularity", "desc")->take(5)->get(); - });//DB::statement("SELECT m.id, m.title as name, m.release_year, m.poster_path FROM movies m WHERE m.clean_title LIKE '%$title%' ORDER BY m.popularity DESC LIMIT 5"); - return response()->json($movies->toArray()); - } + public function suggestions(Request $request) + { + $query = $request->query('query'); + $title = Helper::clean_title($query); + //SELECT m.id, m.title as name, m.release_year, m.poster_path FROM movies m WHERE m.clean_title LIKE '%$term%' ORDER BY m.popularity DESC LIMIT 5 + $movies = Cache::remember("suggestions.$title", new Carbon('tomorrow midnight'), function () use ($title) { + return Movie::select('id', 'title as name', 'release_year', 'poster_path')->where('clean_title', 'LIKE', '%'.$title.'%')->orderBy('popularity', 'desc')->take(5)->get(); + }); //DB::statement("SELECT m.id, m.title as name, m.release_year, m.poster_path FROM movies m WHERE m.clean_title LIKE '%$title%' ORDER BY m.popularity DESC LIMIT 5"); + return response()->json($movies->toArray()); + } - public function multi(string $term) - { - // Heavy caching, since the search operation is kinda expensive! - return Cache::remember("search.multi.$term", new Carbon("tomorrow midnight"), function() use ($term) { - $movie_limit = 15; - $actor_limit = 3; - $collection_limit = 3; + public function multi(string $term) + { + // Heavy caching, since the search operation is kinda expensive! + return Cache::remember("search.multi.$term", new Carbon('tomorrow midnight'), function () use ($term) { + $movie_limit = 15; + $actor_limit = 3; + $collection_limit = 3; - $client = new Client(new ApiToken(env("TMDB_API_KEY"))); + $client = new Client(new ApiToken(env('TMDB_API_KEY'))); - $movie_results = $client->getSearchApi()->searchMovies($term); - $movie_ids = array(); - foreach ($movie_results["results"] as $m_res) { - $movie_ids[] = $m_res["id"]; - } - $movies = Movie::whereIn("id", $movie_ids)->limit($movie_limit)->get(); + $movie_results = $client->getSearchApi()->searchMovies($term); + $movie_ids = []; + foreach ($movie_results['results'] as $m_res) { + $movie_ids[] = $m_res['id']; + } + $movies = Movie::whereIn('id', $movie_ids)->limit($movie_limit)->get(); $person_results = $client->getSearchApi()->searchPersons($term); - $person_ids = array(); - foreach ($person_results["results"] as $m_res) { - $person_ids[] = $m_res["id"]; + $person_ids = []; + foreach ($person_results['results'] as $m_res) { + $person_ids[] = $m_res['id']; } - $persons = Person::whereIn("id", $person_ids)->with(["movies"])->limit($actor_limit)->get(); + $persons = Person::whereIn('id', $person_ids)->with(['movies'])->limit($actor_limit)->get(); $collection_results = $client->getSearchApi()->searchCollection($term); - $collection_ids = array(); - foreach ($collection_results["results"] as $m_res) { - $collection_ids[] = $m_res["id"]; + $collection_ids = []; + foreach ($collection_results['results'] as $m_res) { + $collection_ids[] = $m_res['id']; } - $collections = Collection::whereIn("id", $collection_ids)->with(["movies"])->limit($collection_limit)->get(); + $collections = Collection::whereIn('id', $collection_ids)->with(['movies'])->limit($collection_limit)->get(); - return [ - "movies" => $movies, - "collections" => $collections, - "persons" => $persons - ]; - }); - } + return [ + 'movies' => $movies, + 'collections' => $collections, + 'persons' => $persons, + ]; + }); + } } - -?> diff --git a/app/Http/Controllers/API/TestJSONController.php b/app/Http/Controllers/API/TestJSONController.php index 97db348..8904906 100644 --- a/app/Http/Controllers/API/TestJSONController.php +++ b/app/Http/Controllers/API/TestJSONController.php @@ -2,13 +2,7 @@ namespace App\Http\Controllers\API; -use App\User; -use App\Http\Controllers\Controller; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; -use App\Helpers\IMDBAPI; -use Illuminate\Support\Facades\DB; -use App\Movie; class TestJSONController extends JSONController { @@ -16,20 +10,18 @@ class TestJSONController extends JSONController * Returns a json string for api usage. * * @param int $id + * * @return Response */ - public function hello($name = "Leo") { - $resp = array(); - $resp["message"] = "Hello $name"; - + public function hello($name = 'Leo') + { + $resp = []; + $resp['message'] = "Hello $name"; - return response()->json($resp); - } + return response()->json($resp); + } } - - - ?> diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index ed8d1b7..17c0a64 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers\Auth; -use App\User; use App\Http\Controllers\Controller; -use Illuminate\Support\Facades\Validator; +use App\User; use Illuminate\Foundation\Auth\RegistersUsers; +use Illuminate\Support\Facades\Validator; class RegisterController extends Controller { @@ -42,14 +42,15 @@ public function __construct() /** * Get a validator for an incoming registration request. * - * @param array $data + * @param array $data + * * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data) { return Validator::make($data, [ - 'name' => 'required|string|max:255', - 'email' => 'required|string|email|max:255|unique:users', + 'name' => 'required|string|max:255', + 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:6|confirmed', ]); } @@ -57,14 +58,15 @@ protected function validator(array $data) /** * Create a new user instance after a valid registration. * - * @param array $data + * @param array $data + * * @return User */ protected function create(array $data) { return User::create([ - 'name' => $data['name'], - 'email' => $data['email'], + 'name' => $data['name'], + 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); } diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 03e02a2..a0a2a8a 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; +use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController { diff --git a/app/Http/Controllers/DBMaintenanceController.php b/app/Http/Controllers/DBMaintenanceController.php index 061d9dc..bfb4cbc 100644 --- a/app/Http/Controllers/DBMaintenanceController.php +++ b/app/Http/Controllers/DBMaintenanceController.php @@ -2,17 +2,8 @@ namespace App\Http\Controllers; -use Carbon\Carbon; - -use App\User; -use App\Movie; -use App\StevenLuMovie; -use App\Http\Controllers\Controller; -use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; class DBMaintenanceController extends Controller { @@ -24,12 +15,13 @@ class DBMaintenanceController extends Controller public function activate() { $tables = DB::select('SHOW TABLES'); - $real_tables = array(); + $real_tables = []; foreach ($tables as $dict) { foreach ($dict as $key => $value) { $real_tables[] = $value; } } + return response()->json($real_tables); } } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a3af7dd..26d4635 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,8 +2,6 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; - class HomeController extends Controller { /** diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 8f8ba5c..69eb1d9 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -51,11 +51,11 @@ class Kernel extends HttpKernel * @var array */ protected $routeMiddleware = [ - 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, + 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, - 'can' => \Illuminate\Auth\Middleware\Authorize::class, - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, - 'throttle' => \App\Http\Middleware\ThrottleRequestsException::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'throttle' => \App\Http\Middleware\ThrottleRequestsException::class, ]; } diff --git a/app/Http/Middleware/CheckDBMaint.php b/app/Http/Middleware/CheckDBMaint.php index 6d42b10..403b024 100644 --- a/app/Http/Middleware/CheckDBMaint.php +++ b/app/Http/Middleware/CheckDBMaint.php @@ -10,28 +10,28 @@ class CheckDBMaint /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * * @return mixed */ public function handle($request, Closure $next) { - $request->attributes->add(["is_db_maintenance" => $this->is_db_maintenance()]); - $response = $next($request); + $request->attributes->add(['is_db_maintenance' => $this->is_db_maintenance()]); + $response = $next($request); - if ($this->is_db_maintenance()) - { - $response = $this->add_warning($response); - } + if ($this->is_db_maintenance()) { + $response = $this->add_warning($response); + } - //dd("d"); + //dd("d"); - return $response; + return $response; } public function is_db_maintenance() { - return Storage::disk()->exists("db.down"); + return Storage::disk()->exists('db.down'); } public function add_warning($response) diff --git a/app/Http/Middleware/CheckDBMaintAPI.php b/app/Http/Middleware/CheckDBMaintAPI.php index dfefc69..e8bbb6f 100644 --- a/app/Http/Middleware/CheckDBMaintAPI.php +++ b/app/Http/Middleware/CheckDBMaintAPI.php @@ -2,15 +2,13 @@ namespace App\Http\Middleware; -use Closure; -use Illuminate\Support\Facades\Storage; - class CheckDBMaintAPI extends CheckDBMaint { public function add_warning($response) { $orig = $response->original; - $orig["warnings"] = array("title" => "Database Maintenance", "details" => "Currently performing Database Maintenance. Data may be stale. No Data may be written to API."); + $orig['warnings'] = ['title' => 'Database Maintenance', 'details' => 'Currently performing Database Maintenance. Data may be stale. No Data may be written to API.']; + return $response->setData($orig); } } diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index e4cec9c..afe1c26 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -10,9 +10,10 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @param string|null $guard + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @param string|null $guard + * * @return mixed */ public function handle($request, Closure $next, $guard = null) diff --git a/app/Http/Middleware/ThrottleRequestsException.php b/app/Http/Middleware/ThrottleRequestsException.php index 5451e45..1692fa3 100644 --- a/app/Http/Middleware/ThrottleRequestsException.php +++ b/app/Http/Middleware/ThrottleRequestsException.php @@ -3,7 +3,7 @@ * Created by PhpStorm. * User: leonardogalli * Date: 13.08.17 - * Time: 17:34 + * Time: 17:34. */ namespace App\Http\Middleware; @@ -16,13 +16,15 @@ class ThrottleRequestsException extends ThrottleRequests /** * Create a 'too many attempts' response. * - * @param string $key - * @param int $maxAttempts + * @param string $key + * @param int $maxAttempts + * * @return \Symfony\Component\HttpFoundation\Response */ protected function buildResponse($key, $maxAttempts) { $retryAfter = $this->limiter->availableIn($key); + throw new TooManyRequestsHttpException($retryAfter, $maxAttempts); } -} \ No newline at end of file +} diff --git a/app/Http/Requests/IMDBListRequest.php b/app/Http/Requests/IMDBListRequest.php index 2ccd6f1..6eda11f 100644 --- a/app/Http/Requests/IMDBListRequest.php +++ b/app/Http/Requests/IMDBListRequest.php @@ -2,8 +2,6 @@ namespace App\Http\Requests; -use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Http\JsonResponse; use Symfony\Component\HttpFoundation\Request; class IMDBListRequest extends JSONRequest @@ -26,10 +24,10 @@ public function authorize() public function rules() { return [ - 'listId' => array( - "required", - "regex:/((ls)|(ur))\d{1,12}/" - ) + 'listId' => [ + 'required', + "regex:/((ls)|(ur))\d{1,12}/", + ], ]; } @@ -42,8 +40,7 @@ public function messages() { return [ 'listId.required' => 'An id for the imdb list is required!', - 'listId.regex' => 'The format of the listId given is invalid!', + 'listId.regex' => 'The format of the listId given is invalid!', ]; } - } diff --git a/app/Http/Requests/JSONRequest.php b/app/Http/Requests/JSONRequest.php index a301528..2c66f94 100644 --- a/app/Http/Requests/JSONRequest.php +++ b/app/Http/Requests/JSONRequest.php @@ -2,12 +2,10 @@ namespace App\Http\Requests; +use App\Helpers\Helper; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Http\JsonResponse; -use Symfony\Component\HttpFoundation\Request; use Illuminate\Support\Facades\Log; - -use App\Helpers\Helper; +use Symfony\Component\HttpFoundation\Request; class JSONRequest extends FormRequest { @@ -24,28 +22,29 @@ public function authorize() /** * Get the proper failed validation response for the request. * - * @param array $errors + * @param array $errors + * * @return \Symfony\Component\HttpFoundation\Response */ public function response(array $errors) { if ($this->expectsJson()) { - $json_errors = array(); - foreach ($errors as $key => $error) - { - $new_error = array(); - $new_error["id"] = Helper::generate_uuid_v4(); - $new_error["status"] = 422; - $new_error["title"] = "Unprocessable Entity! Parameter {$key} has one or more errors."; - $new_error["detail"] = "The following errors happened while processing the request parameter $key: ".implode(" ", $error); - $json_errors[] = $new_error; - } - Log::warning("Unprocessable Entity (422)!", array("errors" => $json_errors, "identification" => array("id" => $json_errors[0]["id"]))); - return response()->json(array("errors" => $json_errors), 422); + $json_errors = []; + foreach ($errors as $key => $error) { + $new_error = []; + $new_error['id'] = Helper::generate_uuid_v4(); + $new_error['status'] = 422; + $new_error['title'] = "Unprocessable Entity! Parameter {$key} has one or more errors."; + $new_error['detail'] = "The following errors happened while processing the request parameter $key: ".implode(' ', $error); + $json_errors[] = $new_error; + } + Log::warning('Unprocessable Entity (422)!', ['errors' => $json_errors, 'identification' => ['id' => $json_errors[0]['id']]]); + + return response()->json(['errors' => $json_errors], 422); } + return $this->redirector->to($this->getRedirectUrl()) ->withInput($this->except($this->dontFlash)) ->withErrors($errors, $this->errorBag); } - } diff --git a/app/Http/Requests/MappingRequests.php b/app/Http/Requests/MappingRequests.php index d791ac2..462e284 100644 --- a/app/Http/Requests/MappingRequests.php +++ b/app/Http/Requests/MappingRequests.php @@ -2,10 +2,8 @@ namespace App\Http\Requests; -use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Http\JsonResponse; -use Symfony\Component\HttpFoundation\Request; use Illuminate\Validation\Rule; +use Symfony\Component\HttpFoundation\Request; class MappingAddRequest extends JSONRequest { @@ -27,26 +25,23 @@ public function authorize() public function rules() { $arr = [ - 'tmdbid' => array( - "required", - "regex:/^\d+$/" - ), - 'type' => array( - "required", + 'tmdbid' => [ + 'required', + "regex:/^\d+$/", + ], + 'type' => [ + 'required', Rule::in(['title', 'year']), - ), - 'language' => array( - Rule::in(['en', 'fr', 'es', 'de', 'it', 'da', 'nl', 'ja', 'ru', 'pl', 'vi', 'sv', 'no', 'fi', 'tr', 'pt', 'nl', 'el', 'ko', 'hu']) - ) + ], + 'language' => [ + Rule::in(['en', 'fr', 'es', 'de', 'it', 'da', 'nl', 'ja', 'ru', 'pl', 'vi', 'sv', 'no', 'fi', 'tr', 'pt', 'nl', 'el', 'ko', 'hu']), + ], ]; - if ($this->input("type") == "title") - { - $arr["aka_title"] = ["required", "regex:/^.{2}.+/"]; - } - else if ($this->input("type") == "year") - { - $arr["aka_year"] = ["required", "regex:/^(19|20)\d{2}$/"]; + if ($this->input('type') == 'title') { + $arr['aka_title'] = ['required', 'regex:/^.{2}.+/']; + } elseif ($this->input('type') == 'year') { + $arr['aka_year'] = ['required', "regex:/^(19|20)\d{2}$/"]; } return $arr; @@ -60,18 +55,17 @@ public function rules() public function messages() { return [ - 'tmdbid.required' => 'A tmdbid for the movie is required', - 'tmdbid.regex' => 'The format of the tmdbid given is invalid!', - "type.required" => "The type of mapping to add is required", - "type.in" => "The type of mapping has to either be 'title' or 'year'.", - "aka_year.required" => "The alternative year is required with type 'year'.", - "aka_year.regex" => "The alternative year has to be a valid movie year.", - "aka_title.required" => "The alternative title is required with type 'title'", - "aka_title.regex" => "The alternative title must be at least 3 letters long", - "language.in" => "The language must be a valid ISO639-1 code." + 'tmdbid.required' => 'A tmdbid for the movie is required', + 'tmdbid.regex' => 'The format of the tmdbid given is invalid!', + 'type.required' => 'The type of mapping to add is required', + 'type.in' => "The type of mapping has to either be 'title' or 'year'.", + 'aka_year.required' => "The alternative year is required with type 'year'.", + 'aka_year.regex' => 'The alternative year has to be a valid movie year.', + 'aka_title.required' => "The alternative title is required with type 'title'", + 'aka_title.regex' => 'The alternative title must be at least 3 letters long', + 'language.in' => 'The language must be a valid ISO639-1 code.', ]; } - } class MappingFindRequest extends JSONRequest @@ -94,18 +88,18 @@ public function authorize() public function rules() { $arr = [ - 'tmdbid' => array( - "required", - "regex:/^\d+$/" - ), - 'type' => array( - "sometimes", - "required", + 'tmdbid' => [ + 'required', + "regex:/^\d+$/", + ], + 'type' => [ + 'sometimes', + 'required', Rule::in(['title', 'year', 'all']), - ), - 'language' => array( - Rule::in(['en', 'fr', 'es', 'de', 'it', 'da', 'nl', 'ja', 'ru', 'pl', 'vi', 'sv', 'no', 'fi', 'tr', 'pt', 'nl', 'el', 'ko', 'hu']) - ) + ], + 'language' => [ + Rule::in(['en', 'fr', 'es', 'de', 'it', 'da', 'nl', 'ja', 'ru', 'pl', 'vi', 'sv', 'no', 'fi', 'tr', 'pt', 'nl', 'el', 'ko', 'hu']), + ], ]; return $arr; @@ -120,13 +114,12 @@ public function messages() { return [ 'tmdbid.required' => 'A tmdbid to find mappings by is required.', - 'tmdbid.regex' => 'The format of the tmdbid given is invalid!', - "type.required" => "The type of mappings to return is required.", - "type.in" => "The type of mapping has to be on of 'title', 'year' or 'all'.", - "language.in" => "The language must be a valid ISO639-1 code." + 'tmdbid.regex' => 'The format of the tmdbid given is invalid!', + 'type.required' => 'The type of mappings to return is required.', + 'type.in' => "The type of mapping has to be on of 'title', 'year' or 'all'.", + 'language.in' => 'The language must be a valid ISO639-1 code.', ]; } - } class MappingGetRequest extends JSONRequest @@ -149,10 +142,10 @@ public function authorize() public function rules() { $arr = [ - 'id' => array( - "required", - "regex:/^\d+$/" - ) + 'id' => [ + 'required', + "regex:/^\d+$/", + ], ]; return $arr; @@ -167,8 +160,7 @@ public function messages() { return [ 'id.required' => 'The id of the mapping is required.', - 'id.regex' => 'The format of the id given is invalid!' + 'id.regex' => 'The format of the id given is invalid!', ]; } - } diff --git a/app/Keyword.php b/app/Keyword.php index fa38fb3..1c0a372 100644 --- a/app/Keyword.php +++ b/app/Keyword.php @@ -6,9 +6,10 @@ class Keyword extends Model { - protected $hidden = ["pivot"]; + protected $hidden = ['pivot']; - public function movies() { + public function movies() + { return $this->hasMany("App\Movie"); } } diff --git a/app/Mapping.php b/app/Mapping.php index f18a257..85a25ba 100644 --- a/app/Mapping.php +++ b/app/Mapping.php @@ -2,25 +2,20 @@ namespace App; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\Relation; -use Illuminate\Support\Facades\Cache; -use Helper; -use MappingsCache; use Carbon\Carbon; - +use Helper; +use Illuminate\Database\Eloquent\Model; class Mapping extends Model { protected $connection = 'mappings_mysql'; - protected $fillable = array('tmdbid', "info_type", "info_id"); + protected $fillable = ['tmdbid', 'info_type', 'info_id']; protected $casts = [ - "locked" => "boolean", + 'locked' => 'boolean', ]; - // /** @@ -32,35 +27,35 @@ class Mapping extends Model public function info() { - if ($this->info_type == "title") - { - return $this->hasOne("App\TitleInfo", "id", "info_id"); + if ($this->info_type == 'title') { + return $this->hasOne("App\TitleInfo", 'id', 'info_id'); } - return $this->hasOne("App\YearInfo", "id", "info_id"); + return $this->hasOne("App\YearInfo", 'id', 'info_id'); } public function title_info() { - return $this->hasOne("App\TitleInfo", "id", "info_id"); + return $this->hasOne("App\TitleInfo", 'id', 'info_id'); } public function year_info() { - return $this->hasOne("App\YearInfo", "id", "info_id"); + return $this->hasOne("App\YearInfo", 'id', 'info_id'); } public function toArray() { $arr = parent::toArray(); - $arr["info"] = $this->info->toArray(); + $arr['info'] = $this->info->toArray(); $total = $this->vote_count; //$random_variation = round($total / 10.0); - $variation = 0;//random_int(-$random_variation, $random_variation); - $arr["votes"] += $variation; - $arr["vote_count"] += abs($variation); + $variation = 0; //random_int(-$random_variation, $random_variation); + $arr['votes'] += $variation; + $arr['vote_count'] += abs($variation); + return $arr; } @@ -69,7 +64,7 @@ public static function newMapping($values, $class) $sub_class = new $class($values); $sub_class->save(); - $mapping = new Mapping($values); + $mapping = new self($values); $mapping->mapable()->associate($sub_class); $mapping->save(); @@ -78,36 +73,33 @@ public static function newMapping($values, $class) public function vote($direction = 1) { - if ($this->locked) - { + if ($this->locked) { return; } $ip = md5($_SERVER['REMOTE_ADDR']); - if (Event::whereIn("type", [EventType::AddedMapping, EventType::ApproveMapping, EventType::DisapproveMapping])->where("mappings_id", "=", $this->id)->where("ip", "=", $ip)->whereBetween("date", array(Carbon::now()->addDays(-1), Carbon::now()))->first()) - { + if (Event::whereIn('type', [EventType::AddedMapping, EventType::ApproveMapping, EventType::DisapproveMapping])->where('mappings_id', '=', $this->id)->where('ip', '=', $ip)->whereBetween('date', [Carbon::now()->addDays(-1), Carbon::now()])->first()) { return; } $this->votes = $this->votes + $direction; $this->vote_count += 1; $event_type = EventType::ApproveMapping; - if ($direction == -1) - { + if ($direction == -1) { $event_type = EventType::DisapproveMapping; } - $event = new Event(["type" => $event_type, "mappings_id" => $this->id, "ip" => $ip]); + $event = new Event(['type' => $event_type, 'mappings_id' => $this->id, 'ip' => $ip]); $event->save(); $this->save(); } - } -class TitleInfo extends Model { - protected $table = "title_mappings"; +class TitleInfo extends Model +{ + protected $table = 'title_mappings'; protected $connection = 'mappings_mysql'; - protected $fillable = array('aka_title', "aka_clean_title", "language"); + protected $fillable = ['aka_title', 'aka_clean_title', 'language']; /** * Indicates if the model should be timestamped. @@ -116,26 +108,24 @@ class TitleInfo extends Model { */ public $timestamps = false; - public function __construct(array $attributes = array(), $value =null) + public function __construct(array $attributes = [], $value = null) { - if (array_key_exists("aka_title", $attributes) && !array_key_exists("aka_clean_title", $attributes)) - { - $aka_title = $attributes["aka_title"]; - $attributes["aka_clean_title"] = Helper::clean_title($aka_title); + if (array_key_exists('aka_title', $attributes) && !array_key_exists('aka_clean_title', $attributes)) { + $aka_title = $attributes['aka_title']; + $attributes['aka_clean_title'] = Helper::clean_title($aka_title); } /* override your model constructor */ parent::__construct($attributes); - } - } -class YearInfo extends Model { - protected $table = "year_mappings"; +class YearInfo extends Model +{ + protected $table = 'year_mappings'; protected $connection = 'mappings_mysql'; - protected $fillable = array('aka_year'); + protected $fillable = ['aka_year']; /** * Indicates if the model should be timestamped. @@ -143,5 +133,4 @@ class YearInfo extends Model { * @var bool */ public $timestamps = false; - } diff --git a/app/MappingMovie.php b/app/MappingMovie.php index 9c29bb0..0e29bfb 100644 --- a/app/MappingMovie.php +++ b/app/MappingMovie.php @@ -3,7 +3,7 @@ * Created by PhpStorm. * User: leonardogalli * Date: 23.06.17 - * Time: 13:28 + * Time: 13:28. */ namespace App; @@ -14,14 +14,14 @@ class MappingMovie extends Model { public $timestamps = false; - protected $fillable = array("id", "title", "imdb_id"); + protected $fillable = ['id', 'title', 'imdb_id']; - protected $table = "movies"; + protected $table = 'movies'; protected $connection = 'mappings_mysql'; public function mappings() { - return $this->hasMany("App\Mapping", "tmdbid", "id"); + return $this->hasMany("App\Mapping", 'tmdbid', 'id'); } -} \ No newline at end of file +} diff --git a/app/Movie.php b/app/Movie.php index 699505c..21de469 100644 --- a/app/Movie.php +++ b/app/Movie.php @@ -17,148 +17,163 @@ class Movie extends Model public $timestamps = false; protected $casts = [ - "adult" => "boolean", + 'adult' => 'boolean', ]; - protected $hidden = ["cast", "crew"]; + protected $hidden = ['cast', 'crew']; - protected $appends = ["credits"]; + protected $appends = ['credits']; - protected $with = ["genres", "collection", "keywords", "cast", "crew", "trailer", "ratings", "release_dates", "alternative_titles"]; + protected $with = ['genres', 'collection', 'keywords', 'cast', 'crew', 'trailer', 'ratings', 'release_dates', 'alternative_titles']; public function getCreditsAttribute() { - return ["cast" => $this->cast, "crew" => $this->crew]; + return ['cast' => $this->cast, 'crew' => $this->crew]; } public function scopeDefaultWith() { - return $this->with(["similar", "recommendations"]); + return $this->with(['similar', 'recommendations']); } - public function scopeFilter($query) { - $year_range = Input::get("year"); + public function scopeFilter($query) + { + $year_range = Input::get('year'); if ($year_range != null) { $start_year = 1880; $end_year = null; - if (stripos($year_range, "<>") === false) { + if (stripos($year_range, '<>') === false) { $start_year = $year_range; $end_year = $year_range; } else { - $start_year = explode("<>", $year_range)[0]; - $end_year = explode("<>", $year_range)[1]; + $start_year = explode('<>', $year_range)[0]; + $end_year = explode('<>', $year_range)[1]; } - $query = $query->where("release_date", ">", Carbon::create($start_year-1, 12, 31)); + $query = $query->where('release_date', '>', Carbon::create($start_year - 1, 12, 31)); if ($end_year != null) { - $query = $query->where("release_date", "<", Carbon::create($end_year+1, 1, 1)); + $query = $query->where('release_date', '<', Carbon::create($end_year + 1, 1, 1)); } } - $genres = Input::get("genre"); + $genres = Input::get('genre'); if ($genres != null) { - $ids = explode(",", $genres); - $query->whereHas("genres", function($q) use ($ids){ - $q->whereIn("id", $ids); + $ids = explode(',', $genres); + $query->whereHas('genres', function ($q) use ($ids) { + $q->whereIn('id', $ids); }); } - $query = $this->filter($query, "budget", "budget"); - $query = $this->filter($query, "revenue", "revenue"); - $query = $this->filter($query, "runtime", "runtime"); - $query = $this->filter($query, "popularity", "popularity"); - $adult = Input::get("adult", false); + $query = $this->filter($query, 'budget', 'budget'); + $query = $this->filter($query, 'revenue', 'revenue'); + $query = $this->filter($query, 'runtime', 'runtime'); + $query = $this->filter($query, 'popularity', 'popularity'); + $adult = Input::get('adult', false); if ($adult == false) { - $query = $query->where("adult", "=", 0); + $query = $query->where('adult', '=', 0); } return $query; } - public function filter($query, $column, $input, $value_transformer = null) { + public function filter($query, $column, $input, $value_transformer = null) + { $value = Input::get($input); if ($value_transformer == null) { - $value_transformer = function($value, $sign) { + $value_transformer = function ($value, $sign) { return $value; }; } if ($value != null) { - if (stripos($value, "<>") === false) { + if (stripos($value, '<>') === false) { //We don't have a range! - $query = $query->where($column, "=", $value_transformer($value, "=")); + $query = $query->where($column, '=', $value_transformer($value, '=')); } else { - $start = explode("<>", $value)[0]; - $end = explode("<>", $value)[1]; - $query = $query->where($column, ">", $value_transformer($start, ">")); - $query = $query->where($column, "<", $value_transformer($end, "<")); + $start = explode('<>', $value)[0]; + $end = explode('<>', $value)[1]; + $query = $query->where($column, '>', $value_transformer($start, '>')); + $query = $query->where($column, '<', $value_transformer($end, '<')); } } return $query; } - public function trailer() { - return $this->hasOne("App\Video")->whereIn("type", ["trailer", "teaser"])->orderByDesc("size"); + public function trailer() + { + return $this->hasOne("App\Video")->whereIn('type', ['trailer', 'teaser'])->orderByDesc('size'); } - public function ratings() { + public function ratings() + { return $this->hasMany("App\Rating"); } - public function genres() { + public function genres() + { return $this->belongsToMany("App\Genre"); } - public function keywords() { + public function keywords() + { return $this->belongsToMany("App\Keyword"); } - public function release_dates() { + public function release_dates() + { return $this->hasMany("App\ReleaseDate"); } - public function alternative_titles() { + public function alternative_titles() + { return $this->hasMany("App\AlternativeTitle"); } - public function cast() { - return $this->belongsToMany("App\Person", "credits")->wherePivot("type", "=", "cast")->withPivot('character', 'order', 'credit_id'); + public function cast() + { + return $this->belongsToMany("App\Person", 'credits')->wherePivot('type', '=', 'cast')->withPivot('character', 'order', 'credit_id'); } - public function crew() { - return $this->belongsToMany("App\Person", "credits")->wherePivot("type", "=", "crew")->withPivot('job', 'department', 'credit_id');; + public function crew() + { + return $this->belongsToMany("App\Person", 'credits')->wherePivot('type', '=', 'crew')->withPivot('job', 'department', 'credit_id'); } - public function similar() { + public function similar() + { return $this->belongsToMany('App\Movie', 'similar', 'movie_id', 'similar_id'); } - public function recommendations() { + public function recommendations() + { return $this->belongsToMany('App\Movie', 'recommendations', 'movie_id', 'recommended_id'); } - public function recommendedFrom() { + public function recommendedFrom() + { return $this->belongsToMany('App\Movie', 'recommendations', 'recommended_id', 'movie_id'); } - public function collection() { + public function collection() + { return $this->belongsTo("App\Collection"); } - public function credits() { + public function credits() + { return $this->hasMany("App\Credit"); } public function mappings() { - return $this->hasMany("App\Mapping", "tmdbid", "id"); + return $this->hasMany("App\Mapping", 'tmdbid', 'id'); } - public function createMappingMovie() { - return new MappingMovie(["id" => $this->id, "title" => $this->title, "imdb_id" => $this->imdb_id]); + public function createMappingMovie() + { + return new MappingMovie(['id' => $this->id, 'title' => $this->title, 'imdb_id' => $this->imdb_id]); } } - diff --git a/app/Person.php b/app/Person.php index 72304d9..8efb151 100644 --- a/app/Person.php +++ b/app/Person.php @@ -6,49 +6,50 @@ class Person extends Model { - protected $table = "persons"; + protected $table = 'persons'; - protected $hidden = ["pivot"]; + protected $hidden = ['pivot']; - protected $appends = ["department", "job", "order", "character"]; + protected $appends = ['department', 'job', 'order', 'character']; - public function movies() { - return $this->belongsToMany("App\Movie", "credits")->withPivot('type', 'character', 'order', 'job', 'department', 'credit_id'); + public function movies() + { + return $this->belongsToMany("App\Movie", 'credits')->withPivot('type', 'character', 'order', 'job', 'department', 'credit_id'); } public function getDepartmentAttribute() { - if ($this->pivot == null) - { - return null; + if ($this->pivot == null) { + return; } + return $this->pivot->department; } public function getJobAttribute() { - if ($this->pivot == null) - { - return null; + if ($this->pivot == null) { + return; } + return $this->pivot->job; } public function getOrderAttribute() { - if ($this->pivot == null) - { - return null; + if ($this->pivot == null) { + return; } + return $this->pivot->order; } public function getCharacterAttribute() { - if ($this->pivot == null) - { - return null; + if ($this->pivot == null) { + return; } + return $this->pivot->character; } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 9784b1a..9e68caa 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,7 +2,6 @@ namespace App\Providers; -use Illuminate\Support\Facades\Gate; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider diff --git a/app/Providers/BroadcastServiceProvider.php b/app/Providers/BroadcastServiceProvider.php index 352cce4..395c518 100644 --- a/app/Providers/BroadcastServiceProvider.php +++ b/app/Providers/BroadcastServiceProvider.php @@ -2,8 +2,8 @@ namespace App\Providers; -use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Broadcast; +use Illuminate\Support\ServiceProvider; class BroadcastServiceProvider extends ServiceProvider { diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index fca6152..f106ba4 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,8 +2,8 @@ namespace App\Providers; -use Illuminate\Support\Facades\Event; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; +use Illuminate\Support\Facades\Event; class EventServiceProvider extends ServiceProvider { diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 5221b5e..89435b7 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,9 +2,9 @@ namespace App\Providers; -use Illuminate\Support\Facades\Route; -use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use App\Http\Middleware\CheckDBMaint; +use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +use Illuminate\Support\Facades\Route; class RouteServiceProvider extends ServiceProvider { diff --git a/app/Searchable.php b/app/Searchable.php index 60322d6..23c3ebe 100644 --- a/app/Searchable.php +++ b/app/Searchable.php @@ -8,4 +8,4 @@ public function search($column, $term) { //probably not gonna work :( } -} \ No newline at end of file +} diff --git a/app/StevenLuMovie.php b/app/StevenLuMovie.php index dd171be..3ffdd47 100644 --- a/app/StevenLuMovie.php +++ b/app/StevenLuMovie.php @@ -14,11 +14,11 @@ class StevenLuMovie extends Model */ public $timestamps = false; - protected $table = "stevenlu"; + protected $table = 'stevenlu'; public function TMDBMovie() { - return $this->hasOne("App\Movie", "imdb_id", "imdb_id"); + return $this->hasOne("App\Movie", 'imdb_id', 'imdb_id'); } public function toArray() diff --git a/app/User.php b/app/User.php index bfd96a6..abafe7c 100644 --- a/app/User.php +++ b/app/User.php @@ -2,8 +2,8 @@ namespace App; -use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; class User extends Authenticatable { diff --git a/config/app.php b/config/app.php index ed6f48a..f5d5875 100644 --- a/config/app.php +++ b/config/app.php @@ -107,7 +107,7 @@ 'cipher' => 'AES-256-CBC', - 'imdb_key' => env('IMDB_API_KEY'), + 'imdb_key' => env('IMDB_API_KEY'), 'imdb_secret' => env('IMDB_API_SECRET'), /* @@ -136,7 +136,7 @@ */ 'mappings' => [ - 'enabled' => env('MAPPINGS_ENABLED', false) + 'enabled' => env('MAPPINGS_ENABLED', false), ], /* @@ -212,41 +212,41 @@ */ 'aliases' => [ - 'Helper' => App\Helpers\Helper::class, + 'Helper' => App\Helpers\Helper::class, 'MappingsCache' => App\Helpers\MappingsCache::class, - 'App' => Illuminate\Support\Facades\App::class, - 'Artisan' => Illuminate\Support\Facades\Artisan::class, - 'Auth' => Illuminate\Support\Facades\Auth::class, - 'Blade' => Illuminate\Support\Facades\Blade::class, - 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, - 'Bus' => Illuminate\Support\Facades\Bus::class, - 'Cache' => Illuminate\Support\Facades\Cache::class, - 'Config' => Illuminate\Support\Facades\Config::class, - 'Cookie' => Illuminate\Support\Facades\Cookie::class, - 'Crypt' => Illuminate\Support\Facades\Crypt::class, - 'DB' => Illuminate\Support\Facades\DB::class, - 'Eloquent' => Illuminate\Database\Eloquent\Model::class, - 'Event' => Illuminate\Support\Facades\Event::class, - 'File' => Illuminate\Support\Facades\File::class, - 'Gate' => Illuminate\Support\Facades\Gate::class, - 'Hash' => Illuminate\Support\Facades\Hash::class, - 'Lang' => Illuminate\Support\Facades\Lang::class, - 'Log' => Illuminate\Support\Facades\Log::class, - 'Mail' => Illuminate\Support\Facades\Mail::class, - 'Notification' => Illuminate\Support\Facades\Notification::class, - 'Password' => Illuminate\Support\Facades\Password::class, - 'Queue' => Illuminate\Support\Facades\Queue::class, - 'Redirect' => Illuminate\Support\Facades\Redirect::class, - 'Redis' => Illuminate\Support\Facades\Redis::class, - 'Request' => Illuminate\Support\Facades\Request::class, - 'Response' => Illuminate\Support\Facades\Response::class, - 'Route' => Illuminate\Support\Facades\Route::class, - 'Schema' => Illuminate\Support\Facades\Schema::class, - 'Session' => Illuminate\Support\Facades\Session::class, - 'Storage' => Illuminate\Support\Facades\Storage::class, - 'URL' => Illuminate\Support\Facades\URL::class, - 'Validator' => Illuminate\Support\Facades\Validator::class, - 'View' => Illuminate\Support\Facades\View::class, + 'App' => Illuminate\Support\Facades\App::class, + 'Artisan' => Illuminate\Support\Facades\Artisan::class, + 'Auth' => Illuminate\Support\Facades\Auth::class, + 'Blade' => Illuminate\Support\Facades\Blade::class, + 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, + 'Bus' => Illuminate\Support\Facades\Bus::class, + 'Cache' => Illuminate\Support\Facades\Cache::class, + 'Config' => Illuminate\Support\Facades\Config::class, + 'Cookie' => Illuminate\Support\Facades\Cookie::class, + 'Crypt' => Illuminate\Support\Facades\Crypt::class, + 'DB' => Illuminate\Support\Facades\DB::class, + 'Eloquent' => Illuminate\Database\Eloquent\Model::class, + 'Event' => Illuminate\Support\Facades\Event::class, + 'File' => Illuminate\Support\Facades\File::class, + 'Gate' => Illuminate\Support\Facades\Gate::class, + 'Hash' => Illuminate\Support\Facades\Hash::class, + 'Lang' => Illuminate\Support\Facades\Lang::class, + 'Log' => Illuminate\Support\Facades\Log::class, + 'Mail' => Illuminate\Support\Facades\Mail::class, + 'Notification' => Illuminate\Support\Facades\Notification::class, + 'Password' => Illuminate\Support\Facades\Password::class, + 'Queue' => Illuminate\Support\Facades\Queue::class, + 'Redirect' => Illuminate\Support\Facades\Redirect::class, + 'Redis' => Illuminate\Support\Facades\Redis::class, + 'Request' => Illuminate\Support\Facades\Request::class, + 'Response' => Illuminate\Support\Facades\Response::class, + 'Route' => Illuminate\Support\Facades\Route::class, + 'Schema' => Illuminate\Support\Facades\Schema::class, + 'Session' => Illuminate\Support\Facades\Session::class, + 'Storage' => Illuminate\Support\Facades\Storage::class, + 'URL' => Illuminate\Support\Facades\URL::class, + 'Validator' => Illuminate\Support\Facades\Validator::class, + 'View' => Illuminate\Support\Facades\View::class, ], diff --git a/config/auth.php b/config/auth.php index 7817501..a9264b4 100644 --- a/config/auth.php +++ b/config/auth.php @@ -14,7 +14,7 @@ */ 'defaults' => [ - 'guard' => 'web', + 'guard' => 'web', 'passwords' => 'users', ], @@ -37,12 +37,12 @@ 'guards' => [ 'web' => [ - 'driver' => 'session', + 'driver' => 'session', 'provider' => 'users', ], 'api' => [ - 'driver' => 'token', + 'driver' => 'token', 'provider' => 'users', ], ], @@ -67,7 +67,7 @@ 'providers' => [ 'users' => [ 'driver' => 'eloquent', - 'model' => App\User::class, + 'model' => App\User::class, ], // 'users' => [ @@ -94,8 +94,8 @@ 'passwords' => [ 'users' => [ 'provider' => 'users', - 'table' => 'password_resets', - 'expire' => 60, + 'table' => 'password_resets', + 'expire' => 60, ], ], diff --git a/config/broadcasting.php b/config/broadcasting.php index 5eecd2b..2f41729 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -31,17 +31,17 @@ 'connections' => [ 'pusher' => [ - 'driver' => 'pusher', - 'key' => env('PUSHER_APP_KEY'), - 'secret' => env('PUSHER_APP_SECRET'), - 'app_id' => env('PUSHER_APP_ID'), + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), 'options' => [ // ], ], 'redis' => [ - 'driver' => 'redis', + 'driver' => 'redis', 'connection' => 'default', ], diff --git a/config/cache.php b/config/cache.php index e87f032..b12eff5 100644 --- a/config/cache.php +++ b/config/cache.php @@ -39,20 +39,20 @@ ], 'database' => [ - 'driver' => 'database', - 'table' => 'cache', + 'driver' => 'database', + 'table' => 'cache', 'connection' => null, ], 'file' => [ 'driver' => 'file', - 'path' => storage_path('framework/cache/data'), + 'path' => storage_path('framework/cache/data'), ], 'memcached' => [ - 'driver' => 'memcached', + 'driver' => 'memcached', 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), - 'sasl' => [ + 'sasl' => [ env('MEMCACHED_USERNAME'), env('MEMCACHED_PASSWORD'), ], @@ -61,15 +61,15 @@ ], 'servers' => [ [ - 'host' => env('MEMCACHED_HOST', '127.0.0.1'), - 'port' => env('MEMCACHED_PORT', 11211), + 'host' => env('MEMCACHED_HOST', '127.0.0.1'), + 'port' => env('MEMCACHED_PORT', 11211), 'weight' => 100, ], ], ], 'redis' => [ - 'driver' => 'redis', + 'driver' => 'redis', 'connection' => 'default', ], diff --git a/config/database.php b/config/database.php index b0ea3a9..d333a76 100644 --- a/config/database.php +++ b/config/database.php @@ -34,78 +34,78 @@ 'connections' => [ 'sqlite' => [ - 'driver' => 'sqlite', + 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database.sqlite')), - 'prefix' => '', + 'prefix' => '', ], 'tmdb_mysql' => [ - 'driver' => 'mysql', - 'host' => env('DB_HOST', '127.0.0.1'), - 'port' => env('DB_PORT', '3306'), - 'database' => env('DB_DATABASE', 'forge'), - 'username' => env('DB_USERNAME', 'forge'), - 'password' => env('DB_PASSWORD', ''), + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), - 'charset' => 'utf8mb4', - 'collation' => 'utf8mb4_unicode_ci', - 'prefix' => '', - 'strict' => false, - 'engine' => null, + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'strict' => false, + 'engine' => null, ], - "mappings_mysql" => [ - 'driver' => 'mysql', - 'host' => 'leonardogalli.ch',//env('DB_HOST', '127.0.0.1'), - 'port' => env('DB_PORT', '3306'), - 'database' => "leonard1_mappings", - 'username' => 'leonard1',//env('DB_USERNAME', 'forge'), - 'password' => env('DB_PASSWORD', ''), + 'mappings_mysql' => [ + 'driver' => 'mysql', + 'host' => 'leonardogalli.ch', //env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => 'leonard1_mappings', + 'username' => 'leonard1', //env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), - 'charset' => 'utf8mb4', - 'collation' => 'utf8mb4_unicode_ci', - 'prefix' => '', - 'strict' => true, - 'engine' => null, + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'strict' => true, + 'engine' => null, ], 'maintenance_mysql' => [ - 'driver' => 'mysql', - 'host' => env('DB_HOST', '127.0.0.1'), - 'port' => env('DB_PORT', '3306'), - 'database' => env('DB_DATABASE', 'forge'), - 'username' => env('DB_USERNAME_ROOT', 'forge'), - 'password' => env('DB_PASSWORD_ROOT', ''), + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME_ROOT', 'forge'), + 'password' => env('DB_PASSWORD_ROOT', ''), 'unix_socket' => env('DB_SOCKET', ''), - 'charset' => 'utf8mb4', - 'collation' => 'utf8mb4_unicode_ci', - 'prefix' => '', - 'strict' => false, - 'engine' => null, + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'strict' => false, + 'engine' => null, ], 'pgsql' => [ - 'driver' => 'pgsql', - 'host' => env('DB_HOST', '127.0.0.1'), - 'port' => env('DB_PORT', '5432'), + 'driver' => 'pgsql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '5432'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), - 'charset' => 'utf8', - 'prefix' => '', - 'schema' => 'public', - 'sslmode' => 'prefer', + 'charset' => 'utf8', + 'prefix' => '', + 'schema' => 'public', + 'sslmode' => 'prefer', ], 'sqlsrv' => [ - 'driver' => 'sqlsrv', - 'host' => env('DB_HOST', 'localhost'), - 'port' => env('DB_PORT', '1433'), + 'driver' => 'sqlsrv', + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', '1433'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), - 'charset' => 'utf8', - 'prefix' => '', + 'charset' => 'utf8', + 'prefix' => '', ], ], @@ -139,25 +139,25 @@ 'client' => 'predis', 'default' => [ - 'host' => env('REDIS_HOST', '127.0.0.1'), + 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), - 'port' => env('REDIS_PORT', 6379), + 'port' => env('REDIS_PORT', 6379), 'database' => 0, ], ], 'tmdb_maintenance' => [ - 'db_connection' => 'maintenance_mysql', - 'from_database' => env('DB_DATABASE', 'forge'), - 'to_database' => env('DB_DATABASE_BACKUP', 'forge'), + 'db_connection' => 'maintenance_mysql', + 'from_database' => env('DB_DATABASE', 'forge'), + 'to_database' => env('DB_DATABASE_BACKUP', 'forge'), 'affected_connections' => [ - 'tmdb_mysql' + 'tmdb_mysql', ], - 'tables' => 'all', + 'tables' => 'all', 'tables_before' => [ - 'movies' - ] - ] + 'movies', + ], + ], ]; diff --git a/config/debugbar.php b/config/debugbar.php index 0fb450f..5671d63 100644 --- a/config/debugbar.php +++ b/config/debugbar.php @@ -31,7 +31,7 @@ 'driver' => 'file', // redis, file, pdo, custom 'path' => storage_path('debugbar'), // For file driver 'connection' => null, // Leave null for default connection (Redis/PDO) - 'provider' => '' // Instance of StorageInterface for custom driver + 'provider' => '', // Instance of StorageInterface for custom driver ], /* @@ -61,7 +61,7 @@ | Optionally, you can also send ServerTiming headers on ajax requests for the Chrome DevTools. */ - 'capture_ajax' => true, + 'capture_ajax' => true, 'add_ajax_timing' => false, /* @@ -74,7 +74,7 @@ | */ 'error_handler' => false, - + /* |-------------------------------------------------------------------------- | Clockwork integration @@ -135,23 +135,23 @@ 'with_params' => true, // Render SQL with the parameters substituted 'backtrace' => true, // Use a backtrace to find the origin of the query in your files. 'timeline' => false, // Add the queries to the timeline - 'explain' => [ // Show EXPLAIN output on queries + 'explain' => [ // Show EXPLAIN output on queries 'enabled' => false, - 'types' => ['SELECT'], // ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+ + 'types' => ['SELECT'], // ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+ ], 'hints' => true, // Show hints for common mistakes ], 'mail' => [ - 'full_log' => false + 'full_log' => false, ], 'views' => [ 'data' => false, //Note: Can slow down the application, because the data can be quite large.. ], 'route' => [ - 'label' => true // show complete route on bar + 'label' => true, // show complete route on bar ], 'logs' => [ - 'file' => null + 'file' => null, ], ], diff --git a/config/filesystems.php b/config/filesystems.php index 4544f60..e9945aa 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -45,19 +45,19 @@ 'local' => [ 'driver' => 'local', - 'root' => storage_path('app'), + 'root' => storage_path('app'), ], 'public' => [ - 'driver' => 'local', - 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'driver' => 'local', + 'root' => storage_path('app/public'), + 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ], 's3' => [ 'driver' => 's3', - 'key' => env('AWS_KEY'), + 'key' => env('AWS_KEY'), 'secret' => env('AWS_SECRET'), 'region' => env('AWS_REGION'), 'bucket' => env('AWS_BUCKET'), diff --git a/config/mail.php b/config/mail.php index bb92224..0951a33 100644 --- a/config/mail.php +++ b/config/mail.php @@ -57,7 +57,7 @@ 'from' => [ 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), - 'name' => env('MAIL_FROM_NAME', 'Example'), + 'name' => env('MAIL_FROM_NAME', 'Example'), ], /* diff --git a/config/queue.php b/config/queue.php index 4d83ebd..3a5de83 100644 --- a/config/queue.php +++ b/config/queue.php @@ -35,32 +35,32 @@ ], 'database' => [ - 'driver' => 'database', - 'table' => 'jobs', - 'queue' => 'default', + 'driver' => 'database', + 'table' => 'jobs', + 'queue' => 'default', 'retry_after' => 90, ], 'beanstalkd' => [ - 'driver' => 'beanstalkd', - 'host' => 'localhost', - 'queue' => 'default', + 'driver' => 'beanstalkd', + 'host' => 'localhost', + 'queue' => 'default', 'retry_after' => 90, ], 'sqs' => [ 'driver' => 'sqs', - 'key' => 'your-public-key', + 'key' => 'your-public-key', 'secret' => 'your-secret-key', 'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id', - 'queue' => 'your-queue-name', + 'queue' => 'your-queue-name', 'region' => 'us-east-1', ], 'redis' => [ - 'driver' => 'redis', - 'connection' => 'default', - 'queue' => 'default', + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'default', 'retry_after' => 90, ], @@ -79,7 +79,7 @@ 'failed' => [ 'database' => env('DB_CONNECTION', 'mysql'), - 'table' => 'failed_jobs', + 'table' => 'failed_jobs', ], ]; diff --git a/config/services.php b/config/services.php index 3228b8d..22c17a9 100644 --- a/config/services.php +++ b/config/services.php @@ -20,7 +20,7 @@ ], 'ses' => [ - 'key' => env('SES_KEY'), + 'key' => env('SES_KEY'), 'secret' => env('SES_SECRET'), 'region' => 'us-east-1', ], @@ -30,14 +30,14 @@ ], 'stripe' => [ - 'model' => App\User::class, - 'key' => env('STRIPE_KEY'), + 'model' => App\User::class, + 'key' => env('STRIPE_KEY'), 'secret' => env('STRIPE_SECRET'), ], 'rollbar' => [ 'access_token' => env('ROLLBAR_TOKEN'), - 'level' => env('ROLLBAR_LEVEL', "warning"), + 'level' => env('ROLLBAR_LEVEL', 'warning'), ], ]; diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 7926c79..8f5259e 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -16,9 +16,9 @@ static $password; return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'password' => $password ?: $password = bcrypt('secret'), + 'name' => $faker->name, + 'email' => $faker->unique()->safeEmail, + 'password' => $password ?: $password = bcrypt('secret'), 'remember_token' => str_random(10), ]; }); diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 689cbee..056ed1c 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -1,8 +1,8 @@ create('events', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('type')->unsigned(); - $table->integer('mappings_id')->unsigned()->index('FK_mappings_events'); - $table->timestamp('date')->default(DB::raw('CURRENT_TIMESTAMP')); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::connection('mappings_mysql')->drop('events'); - } +class CreateEventsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::connection('mappings_mysql')->create('events', function (Blueprint $table) { + $table->increments('id'); + $table->integer('type')->unsigned(); + $table->integer('mappings_id')->unsigned()->index('FK_mappings_events'); + $table->timestamp('date')->default(DB::raw('CURRENT_TIMESTAMP')); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection('mappings_mysql')->drop('events'); + } } diff --git a/database/migrations/2017_06_08_114302_create_ip_adresses_table.php b/database/migrations/2017_06_08_114302_create_ip_adresses_table.php index c4123a1..e16251b 100644 --- a/database/migrations/2017_06_08_114302_create_ip_adresses_table.php +++ b/database/migrations/2017_06_08_114302_create_ip_adresses_table.php @@ -3,32 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateIpAdressesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::connection('mappings_mysql')->create('ip_adresses', function(Blueprint $table) - { - $table->increments('id'); - $table->string('ip', 32)->default(''); - $table->integer('mappingsid')->unsigned()->index('FK_mappingsid_ip'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::connection('mappings_mysql')->drop('ip_adresses'); - } +class CreateIpAdressesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::connection('mappings_mysql')->create('ip_adresses', function (Blueprint $table) { + $table->increments('id'); + $table->string('ip', 32)->default(''); + $table->integer('mappingsid')->unsigned()->index('FK_mappingsid_ip'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection('mappings_mysql')->drop('ip_adresses'); + } } diff --git a/database/migrations/2017_06_08_114302_create_mappings_table.php b/database/migrations/2017_06_08_114302_create_mappings_table.php index 42f0b55..98e0707 100644 --- a/database/migrations/2017_06_08_114302_create_mappings_table.php +++ b/database/migrations/2017_06_08_114302_create_mappings_table.php @@ -3,37 +3,34 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateMappingsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::connection('mappings_mysql')->create('mappings', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('tmdbid'); - $table->string('imdbid', 9)->default(''); - $table->integer('report_count')->default(1); - $table->boolean('locked')->default(0); - $table->integer('total_reports')->default(1); - $table->string('mapable_type', 20)->default(''); - $table->integer('mapable_id')->unsigned(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::connection('mappings_mysql')->drop('mappings'); - } +class CreateMappingsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::connection('mappings_mysql')->create('mappings', function (Blueprint $table) { + $table->increments('id'); + $table->integer('tmdbid'); + $table->string('imdbid', 9)->default(''); + $table->integer('report_count')->default(1); + $table->boolean('locked')->default(0); + $table->integer('total_reports')->default(1); + $table->string('mapable_type', 20)->default(''); + $table->integer('mapable_id')->unsigned(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection('mappings_mysql')->drop('mappings'); + } } diff --git a/database/migrations/2017_06_08_114302_create_title_mappings_table.php b/database/migrations/2017_06_08_114302_create_title_mappings_table.php index eb75214..f30c733 100644 --- a/database/migrations/2017_06_08_114302_create_title_mappings_table.php +++ b/database/migrations/2017_06_08_114302_create_title_mappings_table.php @@ -3,32 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateTitleMappingsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::connection('mappings_mysql')->create('title_mappings', function(Blueprint $table) - { - $table->increments('id'); - $table->text('aka_title', 65535); - $table->text('aka_clean_title', 65535); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::connection('mappings_mysql')->drop('title_mappings'); - } +class CreateTitleMappingsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::connection('mappings_mysql')->create('title_mappings', function (Blueprint $table) { + $table->increments('id'); + $table->text('aka_title', 65535); + $table->text('aka_clean_title', 65535); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection('mappings_mysql')->drop('title_mappings'); + } } diff --git a/database/migrations/2017_06_08_114302_create_year_mappings_table.php b/database/migrations/2017_06_08_114302_create_year_mappings_table.php index cb72f42..dffea48 100644 --- a/database/migrations/2017_06_08_114302_create_year_mappings_table.php +++ b/database/migrations/2017_06_08_114302_create_year_mappings_table.php @@ -3,31 +3,28 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateYearMappingsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::connection('mappings_mysql')->create('year_mappings', function(Blueprint $table) - { - $table->increments('id'); - $table->smallInteger('aka_year'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::connection('mappings_mysql')->drop('year_mappings'); - } +class CreateYearMappingsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::connection('mappings_mysql')->create('year_mappings', function (Blueprint $table) { + $table->increments('id'); + $table->smallInteger('aka_year'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection('mappings_mysql')->drop('year_mappings'); + } } diff --git a/database/migrations/2017_06_08_114304_add_foreign_keys_to_events_table.php b/database/migrations/2017_06_08_114304_add_foreign_keys_to_events_table.php index fa6969d..f7562c8 100644 --- a/database/migrations/2017_06_08_114304_add_foreign_keys_to_events_table.php +++ b/database/migrations/2017_06_08_114304_add_foreign_keys_to_events_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToEventsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::connection('mappings_mysql')->table('events', function(Blueprint $table) - { - $table->foreign('mappings_id', 'FK_mappings_events')->references('id')->on('mappings')->onUpdate('CASCADE')->onDelete('CASCADE'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::connection('mappings_mysql')->table('events', function(Blueprint $table) - { - $table->dropForeign('FK_mappings_events'); - }); - } +class AddForeignKeysToEventsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::connection('mappings_mysql')->table('events', function (Blueprint $table) { + $table->foreign('mappings_id', 'FK_mappings_events')->references('id')->on('mappings')->onUpdate('CASCADE')->onDelete('CASCADE'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection('mappings_mysql')->table('events', function (Blueprint $table) { + $table->dropForeign('FK_mappings_events'); + }); + } } diff --git a/database/migrations/2017_06_08_114304_add_foreign_keys_to_ip_adresses_table.php b/database/migrations/2017_06_08_114304_add_foreign_keys_to_ip_adresses_table.php index 2f64f9a..63b7e66 100644 --- a/database/migrations/2017_06_08_114304_add_foreign_keys_to_ip_adresses_table.php +++ b/database/migrations/2017_06_08_114304_add_foreign_keys_to_ip_adresses_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToIpAdressesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::connection('mappings_mysql')->table('ip_adresses', function(Blueprint $table) - { - $table->foreign('mappingsid', 'FK_mappingsid_ip')->references('id')->on('mappings')->onUpdate('CASCADE')->onDelete('CASCADE'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::connection('mappings_mysql')->table('ip_adresses', function(Blueprint $table) - { - $table->dropForeign('FK_mappingsid_ip'); - }); - } +class AddForeignKeysToIpAdressesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::connection('mappings_mysql')->table('ip_adresses', function (Blueprint $table) { + $table->foreign('mappingsid', 'FK_mappingsid_ip')->references('id')->on('mappings')->onUpdate('CASCADE')->onDelete('CASCADE'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection('mappings_mysql')->table('ip_adresses', function (Blueprint $table) { + $table->dropForeign('FK_mappingsid_ip'); + }); + } } diff --git a/public/index.php b/public/index.php index 1e1d775..4236845 100644 --- a/public/index.php +++ b/public/index.php @@ -1,9 +1,8 @@ */ diff --git a/resources/lang/en/auth.php b/resources/lang/en/auth.php index e5506df..6ef1a73 100644 --- a/resources/lang/en/auth.php +++ b/resources/lang/en/auth.php @@ -13,7 +13,7 @@ | */ - 'failed' => 'These credentials do not match our records.', + 'failed' => 'These credentials do not match our records.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', ]; diff --git a/resources/lang/en/pagination.php b/resources/lang/en/pagination.php index d481411..fcab34b 100644 --- a/resources/lang/en/pagination.php +++ b/resources/lang/en/pagination.php @@ -14,6 +14,6 @@ */ 'previous' => '« Previous', - 'next' => 'Next »', + 'next' => 'Next »', ]; diff --git a/resources/lang/en/passwords.php b/resources/lang/en/passwords.php index e5544d2..ffa19ba 100644 --- a/resources/lang/en/passwords.php +++ b/resources/lang/en/passwords.php @@ -14,9 +14,9 @@ */ 'password' => 'Passwords must be at least six characters and match the confirmation.', - 'reset' => 'Your password has been reset!', - 'sent' => 'We have e-mailed your password reset link!', - 'token' => 'This password reset token is invalid.', - 'user' => "We can't find a user with that e-mail address.", + 'reset' => 'Your password has been reset!', + 'sent' => 'We have e-mailed your password reset link!', + 'token' => 'This password reset token is invalid.', + 'user' => "We can't find a user with that e-mail address.", ]; diff --git a/routes/api.php b/routes/api.php index 1a3246d..2e1d90d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -18,57 +18,55 @@ return $request->user(); }); -Route::get("/ping", "API\JSONController@ping"); +Route::get('/ping', "API\JSONController@ping"); -Route::get("/hello", "API\TestJSONController@hello"); +Route::get('/hello', "API\TestJSONController@hello"); +Route::get('/discovery/upcoming', "API\DiscoverController@upcoming"); -Route::get("/discovery/upcoming", "API\DiscoverController@upcoming"); +Route::get('/discovery/popular', "API\DiscoverController@popular"); -Route::get("/discovery/popular", "API\DiscoverController@popular"); +Route::get('/discovery/recommendations', "API\DiscoverController@recommendations"); -Route::get("/discovery/recommendations", "API\DiscoverController@recommendations"); +Route::post('/discovery/upcoming', "API\DiscoverController@upcoming"); -Route::post("/discovery/upcoming", "API\DiscoverController@upcoming"); +Route::post('/discovery/popular', "API\DiscoverController@popular"); -Route::post("/discovery/popular", "API\DiscoverController@popular"); +Route::post('/discovery/recommendations', "API\DiscoverController@recommendations"); -Route::post("/discovery/recommendations", "API\DiscoverController@recommendations"); +Route::get('/search/suggestions', "API\SearchController@suggestions"); -Route::get("/search/suggestions", "API\SearchController@suggestions"); +if (Config::get('app.mappings.enabled') === true) { + Route::get('/mappings/get', "API\MappingsController@get"); -if (Config::get("app.mappings.enabled") === true) -{ - Route::get("/mappings/get", "API\MappingsController@get"); + Route::get('/mappings/add', "API\MappingsController@add"); - Route::get("/mappings/add", "API\MappingsController@add"); + Route::get('/mappings/vote', "API\MappingsController@vote"); - Route::get("/mappings/vote", "API\MappingsController@vote"); + Route::get('/mappings/latest', "API\MappingsController@latest"); - Route::get("/mappings/latest", "API\MappingsController@latest"); - - Route::get("/mappings/find", "API\MappingsController@find"); + Route::get('/mappings/find', "API\MappingsController@find"); } -Route::get("/imdb/top250", "API\IMDBController@top250"); +Route::get('/imdb/top250', "API\IMDBController@top250"); -Route::get("/imdb/popular", "API\IMDBController@popular"); +Route::get('/imdb/popular', "API\IMDBController@popular"); -Route::get("/imdb/list", "API\IMDBController@user_list"); +Route::get('/imdb/list', "API\IMDBController@user_list"); -Route::get("/movie/{id}", "API\MovieController@index"); +Route::get('/movie/{id}', "API\MovieController@index"); -Route::post("/movie/refresh", "API\MovieController@refresh_movies"); +Route::post('/movie/refresh', "API\MovieController@refresh_movies"); -Route::get("/collection/{id}", function($id) { - return \App\Collection::with(["movies", "movies.similar"])->findOrFail($id); +Route::get('/collection/{id}', function ($id) { + return \App\Collection::with(['movies', 'movies.similar'])->findOrFail($id); }); -Route::get("/collection/{id}/movies", function($id) { - return \App\Collection::with(["movies", "movies.similar"])->findOrFail($id)->movies; +Route::get('/collection/{id}/movies', function ($id) { + return \App\Collection::with(['movies', 'movies.similar'])->findOrFail($id)->movies; }); -Route::get("/person/{id}/movies", "API\PersonController@person_movies"); +Route::get('/person/{id}/movies', "API\PersonController@person_movies"); -Route::get("/search/multi/{term}", "API\SearchController@multi"); +Route::get('/search/multi/{term}', "API\SearchController@multi"); //Route::get("/maintenance/activate", "DBMaintenanceController@activate"); diff --git a/routes/web.php b/routes/web.php index c2348a4..88cfbde 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,8 +12,8 @@ */ Route::get('/', function () { - $movies = \App\Movie::find([11,12]); - //$movies = array(); + $movies = \App\Movie::find([11, 12]); + //$movies = array(); return view('welcome', ['movies' => $movies]); }); diff --git a/server.php b/server.php index 5fb6379..20bc389 100644 --- a/server.php +++ b/server.php @@ -1,12 +1,10 @@ */ - $uri = urldecode( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index 486dc27..8fbf370 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -3,9 +3,6 @@ namespace Tests\Feature; use Tests\TestCase; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; class ExampleTest extends TestCase { diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php index 5663bb4..06ece2c 100644 --- a/tests/Unit/ExampleTest.php +++ b/tests/Unit/ExampleTest.php @@ -3,8 +3,6 @@ namespace Tests\Unit; use Tests\TestCase; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; class ExampleTest extends TestCase {