From a0181c7e235a2af3ad18544fd669c60c0131160a Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 14 May 2016 17:12:01 +0100 Subject: [PATCH 01/62] dev: renamed variable internat to TestCase --- tests/TestCase.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index d96783ba..271fcdb7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,7 +8,7 @@ class TestCase extends \Illuminate\Foundation\Testing\TestCase { - protected $seasons = []; + protected $users = []; /** * The base URL to use while testing the application. @@ -51,8 +51,8 @@ protected function getFakeUser($userId = null) ]); $user->clearPassword = $password; $userId = $user->id; - $this->seasons[$userId] = $user; - } elseif (!isset($this->seasons[$userId])) { + $this->users[$userId] = $user; + } elseif (!isset($this->users[$userId])) { $password = str_random(10); $user = factory(User::class) ->create([ @@ -60,10 +60,10 @@ protected function getFakeUser($userId = null) 'password' => bcrypt($password), ]); $user->clearPassword = $password; - $this->seasons[$userId] = $user; + $this->users[$userId] = $user; } - return $this->seasons[$userId]; + return $this->users[$userId]; } /** From b3cb987f5cbac0809ef77761a18e7725f127c286 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 14 May 2016 17:12:17 +0100 Subject: [PATCH 02/62] dev: updated composer packages --- composer.lock | 135 ++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 66 deletions(-) diff --git a/composer.lock b/composer.lock index f849bae3..0dc2ba66 100644 --- a/composer.lock +++ b/composer.lock @@ -1044,16 +1044,16 @@ }, { "name": "swiftmailer/swiftmailer", - "version": "v5.4.1", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421" + "reference": "d8db871a54619458a805229a057ea2af33c753e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/0697e6aa65c83edf97bb0f23d8763f94e3f11421", - "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/d8db871a54619458a805229a057ea2af33c753e8", + "reference": "d8db871a54619458a805229a057ea2af33c753e8", "shasum": "" }, "require": { @@ -1093,20 +1093,20 @@ "mail", "mailer" ], - "time": "2015-06-06 14:19:39" + "time": "2016-05-01 08:45:47" }, { "name": "symfony/console", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "6b1175135bc2a74c08a28d89761272de8beed8cd" + "reference": "34a214710e0714b6efcf40ba3cd1e31373a97820" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/6b1175135bc2a74c08a28d89761272de8beed8cd", - "reference": "6b1175135bc2a74c08a28d89761272de8beed8cd", + "url": "https://api.github.com/repos/symfony/console/zipball/34a214710e0714b6efcf40ba3cd1e31373a97820", + "reference": "34a214710e0714b6efcf40ba3cd1e31373a97820", "shasum": "" }, "require": { @@ -1153,11 +1153,11 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-03-16 17:00:50" + "time": "2016-04-28 09:48:42" }, { "name": "symfony/debug", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", @@ -1214,16 +1214,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "9002dcf018d884d294b1ef20a6f968efc1128f39" + "reference": "807dde98589f9b2b00624dca326740380d78dbbc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9002dcf018d884d294b1ef20a6f968efc1128f39", - "reference": "9002dcf018d884d294b1ef20a6f968efc1128f39", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/807dde98589f9b2b00624dca326740380d78dbbc", + "reference": "807dde98589f9b2b00624dca326740380d78dbbc", "shasum": "" }, "require": { @@ -1270,11 +1270,11 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-03-10 10:34:12" + "time": "2016-05-05 06:56:13" }, { "name": "symfony/finder", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -1323,16 +1323,16 @@ }, { "name": "symfony/http-foundation", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "99f38445a874e7becb8afc4b4a79ee181cf6ec3f" + "reference": "18b24bc32d2495ae79d76e777368786a6536fe31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/99f38445a874e7becb8afc4b4a79ee181cf6ec3f", - "reference": "99f38445a874e7becb8afc4b4a79ee181cf6ec3f", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/18b24bc32d2495ae79d76e777368786a6536fe31", + "reference": "18b24bc32d2495ae79d76e777368786a6536fe31", "shasum": "" }, "require": { @@ -1372,20 +1372,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-03-27 14:50:32" + "time": "2016-04-12 18:09:53" }, { "name": "symfony/http-kernel", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "579f828489659d7b3430f4bd9b67b4618b387dea" + "reference": "6a5010978edf0a9646342232531e53bfc7abbcd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/579f828489659d7b3430f4bd9b67b4618b387dea", - "reference": "579f828489659d7b3430f4bd9b67b4618b387dea", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/6a5010978edf0a9646342232531e53bfc7abbcd3", + "reference": "6a5010978edf0a9646342232531e53bfc7abbcd3", "shasum": "" }, "require": { @@ -1454,7 +1454,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2016-03-25 01:41:20" + "time": "2016-05-09 22:13:13" }, { "name": "symfony/polyfill-mbstring", @@ -1625,16 +1625,16 @@ }, { "name": "symfony/process", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "e6f1f98bbd355d209a992bfff45e7edfbd4a0776" + "reference": "53f9407c0bb1c5a79127db8f7bfe12f0f6f3dcdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/e6f1f98bbd355d209a992bfff45e7edfbd4a0776", - "reference": "e6f1f98bbd355d209a992bfff45e7edfbd4a0776", + "url": "https://api.github.com/repos/symfony/process/zipball/53f9407c0bb1c5a79127db8f7bfe12f0f6f3dcdb", + "reference": "53f9407c0bb1c5a79127db8f7bfe12f0f6f3dcdb", "shasum": "" }, "require": { @@ -1670,20 +1670,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-03-30 10:41:14" + "time": "2016-04-14 15:30:28" }, { "name": "symfony/routing", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "d061b609f2d0769494c381ec92f5c5cc5e4a20aa" + "reference": "a6cd168310066176599442aa21f5da86c3f8e0b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/d061b609f2d0769494c381ec92f5c5cc5e4a20aa", - "reference": "d061b609f2d0769494c381ec92f5c5cc5e4a20aa", + "url": "https://api.github.com/repos/symfony/routing/zipball/a6cd168310066176599442aa21f5da86c3f8e0b3", + "reference": "a6cd168310066176599442aa21f5da86c3f8e0b3", "shasum": "" }, "require": { @@ -1745,11 +1745,11 @@ "uri", "url" ], - "time": "2016-03-23 13:23:25" + "time": "2016-05-03 12:23:49" }, { "name": "symfony/translation", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", @@ -1813,16 +1813,16 @@ }, { "name": "symfony/var-dumper", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "3841ed86527d18ee2c35fe4afb1b2fc60f8fae79" + "reference": "0e918c269093ba4c77fca14e9424fa74ed16f1a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/3841ed86527d18ee2c35fe4afb1b2fc60f8fae79", - "reference": "3841ed86527d18ee2c35fe4afb1b2fc60f8fae79", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/0e918c269093ba4c77fca14e9424fa74ed16f1a6", + "reference": "0e918c269093ba4c77fca14e9424fa74ed16f1a6", "shasum": "" }, "require": { @@ -1872,7 +1872,7 @@ "debug", "dump" ], - "time": "2016-03-10 10:34:12" + "time": "2016-04-25 11:17:47" }, { "name": "vlucas/phpdotenv", @@ -1928,16 +1928,16 @@ "packages-dev": [ { "name": "appzcoder/crud-generator", - "version": "v1.0.8", + "version": "v1.0.9", "source": { "type": "git", "url": "https://github.com/appzcoder/crud-generator.git", - "reference": "f1dee5a78f963fada17bb0d003b988e3137c4fe9" + "reference": "9f3ccfe438bf82842117538478eaddf0372362c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appzcoder/crud-generator/zipball/f1dee5a78f963fada17bb0d003b988e3137c4fe9", - "reference": "f1dee5a78f963fada17bb0d003b988e3137c4fe9", + "url": "https://api.github.com/repos/appzcoder/crud-generator/zipball/9f3ccfe438bf82842117538478eaddf0372362c6", + "reference": "9f3ccfe438bf82842117538478eaddf0372362c6", "shasum": "" }, "require": { @@ -1968,7 +1968,7 @@ "laravel", "laravel crud generator" ], - "time": "2016-04-26 18:29:26" + "time": "2016-05-11 13:12:28" }, { "name": "barryvdh/laravel-ide-helper", @@ -2953,21 +2953,24 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.7", + "version": "1.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, "type": "library", "autoload": { "classmap": [ @@ -2990,7 +2993,7 @@ "keywords": [ "timer" ], - "time": "2015-06-21 08:01:12" + "time": "2016-05-12 18:03:57" }, { "name": "phpunit/php-token-stream", @@ -3334,16 +3337,16 @@ }, { "name": "sebastian/environment", - "version": "1.3.5", + "version": "1.3.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf" + "reference": "2292b116f43c272ff4328083096114f84ea46a56" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/2292b116f43c272ff4328083096114f84ea46a56", + "reference": "2292b116f43c272ff4328083096114f84ea46a56", "shasum": "" }, "require": { @@ -3380,7 +3383,7 @@ "environment", "hhvm" ], - "time": "2016-02-26 18:40:46" + "time": "2016-05-04 07:59:13" }, { "name": "sebastian/exporter", @@ -3639,7 +3642,7 @@ }, { "name": "symfony/class-loader", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/class-loader.git", @@ -3695,7 +3698,7 @@ }, { "name": "symfony/css-selector", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", @@ -3748,16 +3751,16 @@ }, { "name": "symfony/dom-crawler", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", - "reference": "18a06d7a9af41718c20764a674a0ebba3bc40d1f" + "reference": "49b588841225b205700e5122fa01911cabada857" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/18a06d7a9af41718c20764a674a0ebba3bc40d1f", - "reference": "18a06d7a9af41718c20764a674a0ebba3bc40d1f", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/49b588841225b205700e5122fa01911cabada857", + "reference": "49b588841225b205700e5122fa01911cabada857", "shasum": "" }, "require": { @@ -3800,11 +3803,11 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2016-03-23 13:23:25" + "time": "2016-04-12 18:09:53" }, { "name": "symfony/yaml", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", From 01dc2283d6ece7304fb5575fce3b89b5303608fa Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 14 May 2016 17:12:43 +0100 Subject: [PATCH 03/62] dev: used plural for hasMany relationship --- app/Http/Controllers/Admin/DataManagement/RolesController.php | 2 +- app/Models/Role.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php index 0ec6395e..07367c3e 100644 --- a/app/Http/Controllers/Admin/DataManagement/RolesController.php +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -107,7 +107,7 @@ public function update(Request $request, $id) */ public function destroy($id) { - $canBeDeleted = empty(Role::find($id)->available_appointment->toArray()); + $canBeDeleted = empty(Role::find($id)->available_appointments->toArray()); if ($canBeDeleted) { Role::destroy($id); \Flash::success('Role deleted!'); diff --git a/app/Models/Role.php b/app/Models/Role.php index 70cdca04..b7761468 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -7,7 +7,7 @@ /** * App\Models\Role * - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AvailableAppointment[] $available_appointment + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AvailableAppointment[] $available_appointments * @mixin \Eloquent * @property integer $id * @property string $role @@ -35,7 +35,7 @@ class Role extends Model */ protected $fillable = ['role']; - public function available_appointment() + public function available_appointments() { return $this->hasMany('App\Models\AvailableAppointment'); } From f72ae2eedb51e738918f75bb4e7c2de44698625d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 21 Aug 2016 16:21:24 +0100 Subject: [PATCH 04/62] dev: fixed the vagrant machine and ignored puphpet files --- .gitignore | 4 +++- Vagrantfile | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8fba9d61..bdd403a8 100755 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,12 @@ /public/build /.phpstorm.meta.php /.idea -/lva-server +/.vagrant +/puphpet /vendor /node_modules .env .env.* !.env.example _ide_helper.php +Vagrantfile diff --git a/Vagrantfile b/Vagrantfile index c2ab2ed6..e1bffc58 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,11 +4,12 @@ dir = File.dirname(File.expand_path(__FILE__)) require 'yaml' require "#{dir}/puphpet/ruby/deep_merge.rb" +require "#{dir}/puphpet/ruby/to_bool.rb" require "#{dir}/puphpet/ruby/puppet.rb" configValues = YAML.load_file("#{dir}/puphpet/config.yaml") -provider = ENV['VAGRANT_DEFAULT_PROVIDER'] +provider = ENV['VAGRANT_DEFAULT_PROVIDER'] ? ENV['VAGRANT_DEFAULT_PROVIDER'] : 'local' if File.file?("#{dir}/puphpet/config-#{provider}.yaml") custom = YAML.load_file("#{dir}/puphpet/config-#{provider}.yaml") configValues.deep_merge!(custom) @@ -23,4 +24,6 @@ data = configValues['vagrantfile'] Vagrant.require_version '>= 1.8.1' -eval File.read("#{dir}/puphpet/vagrant/Vagrantfile-#{data['target']}") +Vagrant.configure('2') do |config| + eval File.read("#{dir}/puphpet/vagrant/Vagrantfile-#{data['target']}") +end From 776192d426d8ae6a2cde0063011ee322bddda1ff Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 21 Aug 2016 16:45:16 +0100 Subject: [PATCH 05/62] dev: new data management layout --- .../available-appointments/create.blade.php | 4 +- .../available-appointments/edit.blade.php | 4 +- .../available-appointments/index.blade.php | 4 +- .../available-appointments/show.blade.php | 4 +- .../data-management/clubs/create.blade.php | 4 +- .../data-management/clubs/edit.blade.php | 4 +- .../data-management/clubs/index.blade.php | 4 +- .../data-management/clubs/show.blade.php | 4 +- .../divisions/create.blade.php | 4 +- .../data-management/divisions/edit.blade.php | 4 +- .../data-management/divisions/index.blade.php | 4 +- .../data-management/divisions/show.blade.php | 4 +- .../data-management/fixtures/create.blade.php | 4 +- .../data-management/fixtures/edit.blade.php | 4 +- .../data-management/fixtures/index.blade.php | 4 +- .../data-management/fixtures/show.blade.php | 4 +- .../admin/data-management/home.blade.php | 98 +++++++++++-------- .../data-management/roles/create.blade.php | 4 +- .../data-management/roles/edit.blade.php | 4 +- .../data-management/roles/index.blade.php | 4 +- .../data-management/roles/show.blade.php | 4 +- .../data-management/seasons/create.blade.php | 4 +- .../data-management/seasons/edit.blade.php | 4 +- .../data-management/seasons/index.blade.php | 4 +- .../data-management/seasons/show.blade.php | 4 +- .../data-management/teams/create.blade.php | 4 +- .../data-management/teams/edit.blade.php | 4 +- .../data-management/teams/index.blade.php | 4 +- .../data-management/teams/show.blade.php | 4 +- .../data-management/venues/create.blade.php | 4 +- .../data-management/venues/edit.blade.php | 4 +- .../data-management/venues/index.blade.php | 4 +- .../data-management/venues/show.blade.php | 4 +- 33 files changed, 123 insertions(+), 103 deletions(-) diff --git a/resources/views/admin/data-management/available-appointments/create.blade.php b/resources/views/admin/data-management/available-appointments/create.blade.php index 7698fa00..338571bc 100644 --- a/resources/views/admin/data-management/available-appointments/create.blade.php +++ b/resources/views/admin/data-management/available-appointments/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Available appointments

Available appointment

diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index fba72686..2c13b2a0 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Add a new club

diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index a593dc80..9ba08102 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Edit club

diff --git a/resources/views/admin/data-management/clubs/index.blade.php b/resources/views/admin/data-management/clubs/index.blade.php index 7f0630aa..9146ed70 100644 --- a/resources/views/admin/data-management/clubs/index.blade.php +++ b/resources/views/admin/data-management/clubs/index.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Clubs New diff --git a/resources/views/admin/data-management/clubs/show.blade.php b/resources/views/admin/data-management/clubs/show.blade.php index 413d4200..6de65e44 100644 --- a/resources/views/admin/data-management/clubs/show.blade.php +++ b/resources/views/admin/data-management/clubs/show.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Club

diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php index 1950be54..8bd16b9c 100644 --- a/resources/views/admin/data-management/divisions/create.blade.php +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Add new division

diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index 7725ab70..2414407f 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Edit division

diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php index 5c7729f6..f7dbbcbf 100644 --- a/resources/views/admin/data-management/divisions/index.blade.php +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Divisions

Division

diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php index f8eda342..5eabf93f 100644 --- a/resources/views/admin/data-management/fixtures/create.blade.php +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Add new fixture

diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index e66f7b16..335d2f40 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Edit fixture

diff --git a/resources/views/admin/data-management/fixtures/index.blade.php b/resources/views/admin/data-management/fixtures/index.blade.php index b18ab69a..c076ae09 100644 --- a/resources/views/admin/data-management/fixtures/index.blade.php +++ b/resources/views/admin/data-management/fixtures/index.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Fixtures

Fixture

diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index 9f4f9507..e27b8d36 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -3,45 +3,65 @@ @section('content')
-

From here you can manage all the data. Click on the button of teh table you want to use and from there - you will be able to add, modify and delete records.

-
- - @yield('crud') +
+
+
+

+ Direct data management +

+
+
+

+ From here you can manage all the data. Click on the button of the table + you want to use and from there you will be able to add, modify and delete + records. +

+ +
+
+
@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/create.blade.php b/resources/views/admin/data-management/roles/create.blade.php index 1609ae4c..d1ae6f1b 100644 --- a/resources/views/admin/data-management/roles/create.blade.php +++ b/resources/views/admin/data-management/roles/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Add new role

diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index 1e4fc977..d5f51ff1 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Edit role

diff --git a/resources/views/admin/data-management/roles/index.blade.php b/resources/views/admin/data-management/roles/index.blade.php index 784ecded..a5940d0e 100644 --- a/resources/views/admin/data-management/roles/index.blade.php +++ b/resources/views/admin/data-management/roles/index.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Roles New diff --git a/resources/views/admin/data-management/roles/show.blade.php b/resources/views/admin/data-management/roles/show.blade.php index d9000a18..c2ccbc87 100644 --- a/resources/views/admin/data-management/roles/show.blade.php +++ b/resources/views/admin/data-management/roles/show.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Role

diff --git a/resources/views/admin/data-management/seasons/create.blade.php b/resources/views/admin/data-management/seasons/create.blade.php index 0f20d75a..30a8de27 100644 --- a/resources/views/admin/data-management/seasons/create.blade.php +++ b/resources/views/admin/data-management/seasons/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Add a new season

diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index 8c227309..6d5f9d91 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Edit season

diff --git a/resources/views/admin/data-management/seasons/index.blade.php b/resources/views/admin/data-management/seasons/index.blade.php index 0245749c..bdde1f7a 100644 --- a/resources/views/admin/data-management/seasons/index.blade.php +++ b/resources/views/admin/data-management/seasons/index.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Seasons New diff --git a/resources/views/admin/data-management/seasons/show.blade.php b/resources/views/admin/data-management/seasons/show.blade.php index 81638f3e..b12c4e5b 100644 --- a/resources/views/admin/data-management/seasons/show.blade.php +++ b/resources/views/admin/data-management/seasons/show.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Season

diff --git a/resources/views/admin/data-management/teams/create.blade.php b/resources/views/admin/data-management/teams/create.blade.php index 56ae0a07..c55a4197 100644 --- a/resources/views/admin/data-management/teams/create.blade.php +++ b/resources/views/admin/data-management/teams/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Add new team

diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index b7060454..7ce3e4ec 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Edit team

diff --git a/resources/views/admin/data-management/teams/index.blade.php b/resources/views/admin/data-management/teams/index.blade.php index 97fd3854..4a0bf1be 100644 --- a/resources/views/admin/data-management/teams/index.blade.php +++ b/resources/views/admin/data-management/teams/index.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Teams New diff --git a/resources/views/admin/data-management/teams/show.blade.php b/resources/views/admin/data-management/teams/show.blade.php index a88c1f4b..3e47bdba 100644 --- a/resources/views/admin/data-management/teams/show.blade.php +++ b/resources/views/admin/data-management/teams/show.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Team

diff --git a/resources/views/admin/data-management/venues/create.blade.php b/resources/views/admin/data-management/venues/create.blade.php index ce3dd765..96c02461 100644 --- a/resources/views/admin/data-management/venues/create.blade.php +++ b/resources/views/admin/data-management/venues/create.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Add new venue

diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index e9876621..ea4a7224 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Edit venue

diff --git a/resources/views/admin/data-management/venues/index.blade.php b/resources/views/admin/data-management/venues/index.blade.php index 10973773..6d8ae34e 100644 --- a/resources/views/admin/data-management/venues/index.blade.php +++ b/resources/views/admin/data-management/venues/index.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Venues New diff --git a/resources/views/admin/data-management/venues/show.blade.php b/resources/views/admin/data-management/venues/show.blade.php index aa173cc3..71b147cd 100644 --- a/resources/views/admin/data-management/venues/show.blade.php +++ b/resources/views/admin/data-management/venues/show.blade.php @@ -1,6 +1,6 @@ -@extends('admin.data-management.home') +@extends('layouts.app') -@section('crud') +@section('content')

Venue

From ac0e4d66b7eac8517ad4671adff1db2d444f52e8 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 21 Aug 2016 16:57:48 +0100 Subject: [PATCH 06/62] dev: new data management layout --- gulpfile.js | 2 ++ resources/assets/sass/data-management.scss | 8 ++++++++ .../sass/partials/{breadcrumbs.scss => _breadcrumbs.scss} | 0 resources/views/admin/data-management/home.blade.php | 7 ++++--- resources/views/layouts/app.blade.php | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 resources/assets/sass/data-management.scss rename resources/assets/sass/partials/{breadcrumbs.scss => _breadcrumbs.scss} (100%) diff --git a/gulpfile.js b/gulpfile.js index abe699ab..6496d29c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -14,6 +14,7 @@ var elixir = require('laravel-elixir'); elixir(function (mix) { // Styles mix.sass('app.scss'); + mix.sass('data-management.scss'); // Javascript mix.browserify('app.js'); @@ -23,6 +24,7 @@ elixir(function (mix) { mix.version([ // Stylesheets 'css/app.css', + 'css/data-management.css', // Javascripts 'js/app.js', 'js/confirm-delete.js' diff --git a/resources/assets/sass/data-management.scss b/resources/assets/sass/data-management.scss new file mode 100644 index 00000000..d0f88dce --- /dev/null +++ b/resources/assets/sass/data-management.scss @@ -0,0 +1,8 @@ +ul.nav-stacked { + li { + a { + padding-top: 5px; + padding-bottom: 5px; + } + } +} \ No newline at end of file diff --git a/resources/assets/sass/partials/breadcrumbs.scss b/resources/assets/sass/partials/_breadcrumbs.scss similarity index 100% rename from resources/assets/sass/partials/breadcrumbs.scss rename to resources/assets/sass/partials/_breadcrumbs.scss diff --git a/resources/views/admin/data-management/home.blade.php b/resources/views/admin/data-management/home.blade.php index e27b8d36..685f80b0 100644 --- a/resources/views/admin/data-management/home.blade.php +++ b/resources/views/admin/data-management/home.blade.php @@ -1,5 +1,8 @@ @extends('layouts.app') +@section('stylesheets') + +@endsection @section('content')
@@ -12,9 +15,7 @@

- From here you can manage all the data. Click on the button of the table - you want to use and from there you will be able to add, modify and delete - records. + This is where you manage raw data: add, delete or update records.

+

@endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/load/fixtures.blade.php b/resources/views/admin/data-management/load/fixtures.blade.php new file mode 100644 index 00000000..fbf10976 --- /dev/null +++ b/resources/views/admin/data-management/load/fixtures.blade.php @@ -0,0 +1,35 @@ +@extends('layouts.app') + +@section('content') + +
+

Upload fixtures

+
+ {!! Form::open(['url' => route('uploadFixtures'), 'class' => 'form-horizontal', 'files' => true]) !!} + +
+ {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} + {!! $errors->first('season_id', '

:message

') !!} +
+
+ +
+ {!! Form::label('upload_file', 'File: ', ['class' => 'col-sm-3 control-label']) !!} +
+ {!! Form::file('upload_file') !!} + {!! $errors->first('upload_file', '

:message

') !!} +
+
+ +
+
+ {!! Form::submit('Start', ['class' => 'btn btn-primary form-control']) !!} +
+
+ + {!! Form::close() !!} +
+ +@endsection \ No newline at end of file From 1c973f8602d5df3dcf1f9e78dec8b4a8d23c9e13 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 25 Aug 2016 19:47:27 +0100 Subject: [PATCH 08/62] lva-22: fixed the browse button for selection of file to upload --- gulpfile.js | 4 ++- resources/assets/js/file-browse.js | 28 +++++++++++++++++++ .../data-management/load/fixtures.blade.php | 14 +++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 resources/assets/js/file-browse.js diff --git a/gulpfile.js b/gulpfile.js index 6496d29c..8313d060 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -19,6 +19,7 @@ elixir(function (mix) { // Javascript mix.browserify('app.js'); mix.browserify('confirm-delete.js'); + mix.browserify('file-browse.js'); // Versioning mix.version([ @@ -27,6 +28,7 @@ elixir(function (mix) { 'css/data-management.css', // Javascripts 'js/app.js', - 'js/confirm-delete.js' + 'js/confirm-delete.js', + 'js/file-browse.js' ]); }); diff --git a/resources/assets/js/file-browse.js b/resources/assets/js/file-browse.js new file mode 100644 index 00000000..5cfd1273 --- /dev/null +++ b/resources/assets/js/file-browse.js @@ -0,0 +1,28 @@ +/** + * Created by Giulio Troccoli on 25/08/2016. + */ +(function ($) { + // We can attach the `fileselect` event to all file inputs on the page + $(document).on('change', ':file', function () { + var input = $(this), + numFiles = input.get(0).files ? input.get(0).files.length : 1, + label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); + input.trigger('fileselect', [numFiles, label]); + }); + + // We can watch for our custom `fileselect` event like this + $(document).ready(function () { + $(':file').on('fileselect', function (event, numFiles, label) { + + var input = $(this).parents('.input-group').find(':text'), + log = numFiles > 1 ? numFiles + ' files selected' : label; + + if (input.length) { + input.val(log); + } else { + if (log) alert(log); + } + + }); + }); +})(jQuery); \ No newline at end of file diff --git a/resources/views/admin/data-management/load/fixtures.blade.php b/resources/views/admin/data-management/load/fixtures.blade.php index fbf10976..937a3043 100644 --- a/resources/views/admin/data-management/load/fixtures.blade.php +++ b/resources/views/admin/data-management/load/fixtures.blade.php @@ -18,11 +18,19 @@
{!! Form::label('upload_file', 'File: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::file('upload_file') !!} +
+ + +
{!! $errors->first('upload_file', '

:message

') !!}
+
{!! Form::submit('Start', ['class' => 'btn btn-primary form-control']) !!} @@ -32,4 +40,8 @@ {!! Form::close() !!}
+@endsection + +@section('javascript') + @endsection \ No newline at end of file From 49f320febda02c65f1c1475c0d69c652dbc3856d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Thu, 25 Aug 2016 22:27:59 +0100 Subject: [PATCH 09/62] dev: fixed icons on various buttons --- resources/views/auth/login.blade.php | 2 +- resources/views/auth/passwords/email.blade.php | 2 +- resources/views/auth/passwords/reset.blade.php | 2 +- resources/views/auth/register.blade.php | 2 +- resources/views/layouts/app.blade.php | 6 ++++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index e6bb1896..f2308d6f 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -51,7 +51,7 @@
Forgot Your Password? diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index 8009c6a7..399b2070 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -34,7 +34,7 @@
diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php index 70580f00..599824e7 100644 --- a/resources/views/auth/passwords/reset.blade.php +++ b/resources/views/auth/passwords/reset.blade.php @@ -57,7 +57,7 @@
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 15e6cd52..83e91340 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -69,7 +69,7 @@
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index ff5a774f..0a531a98 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -75,8 +75,10 @@
- + From 4e8a2774df0f84f29d31b0547b32d81d7b142bca Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Fri, 21 Oct 2016 19:22:03 +0100 Subject: [PATCH 14/62] lva-22: Coded the front-end for the interactive loading --- .../Admin/DataManagement/LoadController.php | 1 + .../Api/v1/UploadApiController.php | 140 ++++++++++++-- app/Http/routes.php | 6 +- app/Models/UploadJob.php | 20 ++ gulpfile.js | 1 + .../assets/js/load-fixtures-status-update.js | 172 +++++++++++++++--- resources/assets/sass/app.scss | 5 - resources/assets/sass/load-fixtures.scss | 17 ++ .../_partial/load-fixture-modal.blade.php | 58 ++++++ .../data-management/load/status.blade.php | 8 +- 10 files changed, 387 insertions(+), 41 deletions(-) create mode 100644 resources/assets/sass/load-fixtures.scss create mode 100644 resources/views/_partial/load-fixture-modal.blade.php diff --git a/app/Http/Controllers/Admin/DataManagement/LoadController.php b/app/Http/Controllers/Admin/DataManagement/LoadController.php index a68572c1..85a7ff58 100644 --- a/app/Http/Controllers/Admin/DataManagement/LoadController.php +++ b/app/Http/Controllers/Admin/DataManagement/LoadController.php @@ -56,6 +56,7 @@ public function startUploadFixtures(Request $request) public function uploadStatus(UploadJob $uploadJob) { + $uploadJob->save(); return view('admin.data-management.load.status', ['job' => $uploadJob]); } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 24becfcc..ea868940 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -8,7 +8,6 @@ namespace App\Http\Controllers\Api\v1; - use App\Http\Controllers\Controller; use App\Models\UploadJob; use Illuminate\Support\Facades\Input; @@ -16,27 +15,144 @@ class UploadApiController extends Controller { public function getUploadStatus() + { + $uploadJob = $this->checkForJob(); + if (!$uploadJob instanceof UploadJob) { + return response()->json($uploadJob); + } + + $status = UploadJob::STATUS_UNKNOWN_DATA; + $uploadJob->status = [ + 'StatusCode' => $status, + 'StatusMessage' => UploadJob::getStatusMessage($status), + 'Progress' => rand(10, 99), + 'Fixture' => [ + 'Division' => 'M1A', + 'MatchNumber' => '05', + 'HomeTeam' => 'K.S. Osmeka Men 2', + 'AwayTeam' => 'Flaming Six Blackjacks', + 'Date' => date('D d/m/y'), + 'WarmUpTime' => '15:00', + 'StartTime' => '15:20', + 'Venue' => 'Battersea Sports Centre', + ], + 'Unknowns' => [ + 'HomeTeam' => [ + 'Mapping' => [ + ['value' => 1, 'text' => 'KS Osemka Men 2'], + ['value' => 3, 'text' => 'KS Osemka Men 3'], + ['value' => 4, 'text' => 'KS Osemka Men 4'], + ['value' => 2, 'text' => 'k.s. Osemka Men 2'], + ], + 'ApiUrls' => [ + 'Add' => '/api/v1/teams', + 'Map' => '/api/v1/maps/team', + ], + ], + 'AwayTeam' => [ + 'Mapping' => [ + ['value' => 1, 'text' => 'KS Osemka Men 2'], + ['value' => 3, 'text' => 'KS Osemka Men 3'], + ['value' => 4, 'text' => 'KS Osemka Men 4'], + ['value' => 2, 'text' => 'k.s. Osemka Men 2'], + ], + 'ApiUrls' => [ + 'Add' => '/api/v1/teams', + 'Map' => '/api/v1/maps/team', + ], + ], + 'Venue' => [ + 'Mapping' => [ + ['value' => 10, 'text' => 'Sobell S.C.'], + ['value' => 22, 'text' => 'SportsDock'], + ], + 'ApiUrls' => [ + 'Add' => route('loading-add-venue'), + 'Map' => route('loading-map-venue'), + ], + ], + + ], + + + ]; + + return response()->json([ + 'Timestamp' => time(), + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $uploadJob->status, + ]); + } + + private function checkForJob() { $jobId = Input::get('job', null); if (null === $jobId) { - return response([ - 'error' => true, - 'message' => 'Job parameter missing', - ]); + return [ + 'Timestamp' => time(), + 'Error' => true, + 'Message' => 'Job parameter missing', + ]; } $uploadJob = UploadJob::find($jobId); if (is_null($uploadJob)) { - return response([ - 'error' => true, - 'message' => 'Job not found', - ]); + return [ + 'Timestamp' => time(), + 'Error' => true, + 'Message' => 'Job not found', + ]; + } + + return $uploadJob; + } + + public function addTeam() + { + $uploadJob = $this->checkForJob(); + if (!$uploadJob instanceof UploadJob) { + return response($uploadJob); + } + + return response()->json([ + 'success' => true, + ]); + } + + public function mapTeam() + { + $uploadJob = $this->checkForJob(); + if (!$uploadJob instanceof UploadJob) { + return response($uploadJob); + } + + return response()->json([ + 'success' => false, + ]); + } + + public function addVenue() + { + $uploadJob = $this->checkForJob(); + if (!$uploadJob instanceof UploadJob) { + return response($uploadJob); + } + + return response()->json([ + 'success' => true, + ]); + } + + public function mapVenue() + { + $uploadJob = $this->checkForJob(); + if (!$uploadJob instanceof UploadJob) { + return response($uploadJob); } return response()->json([ - 'error' => false, - 'message' => 'Job found', - 'status' => $uploadJob->status, + 'success' => false, ]); } } \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 5d8b27f8..695e4be3 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -24,7 +24,11 @@ | */ Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api', 'namespace' => 'Api\v1'], function () { - Route::get('upload_status.json', ['uses' => 'UploadApiController@getUploadStatus']); + Route::get('uploads/status.json', ['uses' => 'UploadApiController@getUploadStatus']); + Route::post('teams', ['as' => 'loading-add-team', 'uses' => 'UploadApiController@addTeam']); + Route::post('maps/team', ['as' => 'loading-map-team', 'uses' => 'UploadApiController@mapTeam']); + Route::post('venues', ['as' => 'loading-add-venue', 'uses' => 'UploadApiController@addVenue']); + Route::post('maps/venue', ['as' => 'loading-map-venue', 'uses' => 'UploadApiController@mapVenue']); }); Route::group(['middleware' => 'web'], function () { diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index ba2db325..3dc2b64b 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -28,11 +28,31 @@ class UploadJob extends Model const STATUS_NOT_STARTED = 0; const STATUS_VALIDATING_RECORDS = 1; const STATUS_INSERTING_RECORDS = 2; + const STATUS_UNKNOWN_DATA = 11; + const STATUS_UNKNOWN_VENUE = 12; const STATUS_DONE = 99; protected $table = 'upload_jobs'; protected $fillable = ['file', 'type', 'status']; + public static function getStatusMessage($statusCode) + { + switch ($statusCode) { + case self::STATUS_NOT_STARTED: + return 'Not started'; + case self::STATUS_VALIDATING_RECORDS: + return 'Validating records'; + case self::STATUS_INSERTING_RECORDS: + return 'Inserting records'; + case self::STATUS_UNKNOWN_DATA: + return 'Unknown data'; + case self::STATUS_DONE: + return 'Done'; + default: + return "Status code $statusCode not recognised"; + } + } + /** * @param string $value * @return array diff --git a/gulpfile.js b/gulpfile.js index 69c55e4a..7b5b6b71 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -15,6 +15,7 @@ elixir(function (mix) { // Styles mix.sass('app.scss'); mix.sass('data-management.scss'); + mix.sass('load-fixtures.scss'); // Javascript mix.browserify('app.js'); diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index 0240ac76..1000f0fc 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -5,29 +5,157 @@ "use strict"; var apiToken = $('#api_token').val(), - jobId = $('#job_id').val(); - - var poll = function poll() { - - $.get({ - 'url' : '/api/v1/upload_status.json', - 'data' : { - 'job' : jobId, - 'api_token': apiToken - }, - 'dataType': 'json' - }).done(function (data) { - if (data.error) { - $('#message').html(data.message); - } else { - $('#message').html(data.status.message); - $('.progress-bar').css('width', data.status.progress + '%').attr('aria-valuenow', data.status.progress) - .find('.sr-only').html(data.status.progress + '% Complete'); - setTimeout(poll, 1000); + jobId = $('#job_id').val(), + lastTimestamp = 0, + + disableRow = function disableRow(row) { + row.off('click', '.add-button').off('click', '.map-button'); + row.find('button').addClass('disabled').blur(); + row.find('select').prop('disabled', true); + + if ($('#unknowns').find('button').not('.disabled').length == 0) { + $('#continue-button').removeClass('disabled'); } - }); - }; + }, - poll(); + ShowLoading = function ShowLoading(row) { + row.find('button:focus').blur(); + row.LoadingOverlay("show", {image: "", fontawesome: "fa fa-spinner fa-spin", zIndex: 10000}); + }, + + HideLoading = function HideLoading(row) { + row.LoadingOverlay("hide"); + }, + + AddUnknown = function AddUnknow(e) { + var row = $(e.target).parent('.unknown.row'), + name = row.find('p').text(); + + console.log('Calling ' + $(e.target).data('apiurl') + ' to add ' + name); + ShowLoading(row); + $.post({ + url : $(e.target).data('apiurl'), + data : { + name : name, + job : jobId, + api_token: apiToken + }, + dataType: 'json' + }).done(function (data) { + if (data.success) { + disableRow(row); + } + }).always(function () { + HideLoading(row); + }); + }, + + MapUnknown = function MapUnknow(e) { + var row = $(e.target).parent('.unknown.row'), + name = row.find('p').text(), + option = row.find('select').find('option:selected').text(); + + console.log('Calling ' + $(e.target).data('apiurl') + ' to map ' + name + ' to ' + option); + ShowLoading(row); + $.post({ + url : $(e.target).data('apiurl'), + data : { + name : name, + newName : option, + job : jobId, + api_token: apiToken + }, + dataType: 'json' + }).done(function (data) { + if (data.success) { + disableRow(row); + } + }).always(function () { + HideLoading(row); + }); + }, + + populateCurrentFixture = function populateCurrentFixture(element, fixture) { + element.find('#fixture-division').text(fixture.Division); + element.find('#fixture-match-number').text(fixture.MatchNumber); + element.find('#fixture-home-team').text(fixture.HomeTeam); + element.find('#fixture-away-team').text(fixture.AwayTeam); + element.find('#fixture-date').text(fixture.Date); + element.find('#fixture-warm-up-time').text(fixture.WarmUpTime); + element.find('#fixture-start-time').text(fixture.StartTime); + element.find('#fixture-venue').text(fixture.Venue); + }, + + createUnknownRow = function createUnknownRow(tmplId, text, map) { + var unknown = $('#' + tmplId).clone(true).removeClass('hidden').attr('id', ''); + + unknown.find('p').text(text); + unknown.find('.add-button').data('apiurl', map.ApiUrls.Add); + + var select = unknown.find('select'); + $.each(map.Mapping, function (index, option) { + var $option = $("") + .attr("value", option.value) + .text(option.text); + select.append($option); + }); + unknown.find('.map-button').data('apiurl', map.ApiUrls.Map); + unknown.on('click', '.add-button', AddUnknown).on('click', '.map-button', MapUnknown); + + return unknown; + }, + + poll = function poll() { + $.get({ + url : '/api/v1/uploads/status.json', + data : { + job : jobId, + api_token: apiToken + }, + dataType: 'json' + }).done(function (data) { + if (lastTimestamp == data.Timestamp) { + setTimeout(poll, 1000); + console.log('Same timestamp - nothing to do'); + return; + } + lastTimestamp = data.Timestamp; + + if (data.Error) { + $('#message').html(data.Message); + return; + } + var status = data.Status; + $('.progress-bar') + .css('width', status.Progress + '%') + .attr('aria-valuenow', status.Progress) + .find('.sr-only').html(status.Progress + '% Complete'); + + if (status.StatusCode == 11) { + $('#load-fixture-modal').find('.modal-title').text(status.StatusMessage); + + populateCurrentFixture($('#load-fixture-modal'), status.Fixture); + + $('#load-fixture-modal').find('#unknowns').empty(); + $.each(status.Unknowns, function (field, map) { + var newUnknown = createUnknownRow('unknown-data-template', status.Fixture[field], map); + $('#load-fixture-modal').find('#unknowns').append(newUnknown); + }); + + $('#continue-button').addClass('disabled'); + $('#load-fixture-modal').modal('show'); + + } else if (status.StatusCode != 99) { + setTimeout(poll, 1000); + } + + }); + }; + + poll(); + $('#load-fixture-modal').modal({show: false}); + $('#load-fixture-modal').on('hidden.bs.modal', function () { + setTimeout(poll, 1000); + }); })(jQuery); \ No newline at end of file diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index d9465cee..a008f9a9 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -3,8 +3,3 @@ @import "partials/navbar"; @import "partials/breadcrumbs"; @import "partials/lva-header"; - -#page-content { - //position: absolute; - //top: 348px; -} \ No newline at end of file diff --git a/resources/assets/sass/load-fixtures.scss b/resources/assets/sass/load-fixtures.scss new file mode 100644 index 00000000..a6a4c50a --- /dev/null +++ b/resources/assets/sass/load-fixtures.scss @@ -0,0 +1,17 @@ +#load-fixture-modal { + .modal-dialog { + width: 69%; + .unknown.row { + margin-bottom: 5px; + p { + margin-top: 7px; + margin-bottom: 0; + } + } + .add-button, + .map-button { + padding-left: 8px; + padding-right: 8px; + } + } +} diff --git a/resources/views/_partial/load-fixture-modal.blade.php b/resources/views/_partial/load-fixture-modal.blade.php new file mode 100644 index 00000000..b3f2992d --- /dev/null +++ b/resources/views/_partial/load-fixture-modal.blade.php @@ -0,0 +1,58 @@ + \ No newline at end of file diff --git a/resources/views/admin/data-management/load/status.blade.php b/resources/views/admin/data-management/load/status.blade.php index 0f554a02..fd4d2a47 100644 --- a/resources/views/admin/data-management/load/status.blade.php +++ b/resources/views/admin/data-management/load/status.blade.php @@ -1,5 +1,9 @@ @extends('layouts.app') +@section('stylesheets') + +@endsection + @section('content') {!! Form::hidden('api_token', Auth::user()->api_token, ['id' => 'api_token']) !!} {!! Form::hidden('job_id', $job->id, ['id' => 'job_id']) !!} @@ -18,9 +22,11 @@

+ @include('_partial.load-fixture-modal'); @endsection @section('javascript') - + @endsection \ No newline at end of file From 4ce47bc8d92e639b45dc9544ae9dde8293521fa4 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 20 Nov 2016 13:21:07 +0000 Subject: [PATCH 15/62] lva-22: Added migration scripts for synonyms, mapped and new tables --- ...16_11_20_120809_create_synonyms_tables.sql | 35 ++++++++++ ..._create_mapped_venues_and_teams_tables.sql | 37 +++++++++++ ...340_create_new_venues_and_teams_tables.sql | 33 ++++++++++ ...16_11_20_120809_create_synonyms_tables.sql | 7 ++ ..._create_mapped_venues_and_teams_tables.sql | 11 ++++ ...340_create_new_venues_and_teams_tables.sql | 7 ++ ...16_11_20_120809_create_synonyms_tables.php | 63 ++++++++++++++++++ ..._create_mapped_venues_and_teams_tables.php | 65 +++++++++++++++++++ ...340_create_new_venues_and_teams_tables.php | 61 +++++++++++++++++ 9 files changed, 319 insertions(+) create mode 100644 database/deployment/2016_11_20_120809_create_synonyms_tables.sql create mode 100644 database/deployment/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql create mode 100644 database/deployment/2016_11_20_124340_create_new_venues_and_teams_tables.sql create mode 100644 database/deployment/rollbacks/2016_11_20_120809_create_synonyms_tables.sql create mode 100644 database/deployment/rollbacks/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql create mode 100644 database/deployment/rollbacks/2016_11_20_124340_create_new_venues_and_teams_tables.sql create mode 100644 database/migrations/2016_11_20_120809_create_synonyms_tables.php create mode 100644 database/migrations/2016_11_20_123304_create_mapped_venues_and_teams_tables.php create mode 100644 database/migrations/2016_11_20_124340_create_new_venues_and_teams_tables.php diff --git a/database/deployment/2016_11_20_120809_create_synonyms_tables.sql b/database/deployment/2016_11_20_120809_create_synonyms_tables.sql new file mode 100644 index 00000000..f1094baf --- /dev/null +++ b/database/deployment/2016_11_20_120809_create_synonyms_tables.sql @@ -0,0 +1,35 @@ +CREATE TABLE `venues_synonyms` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `synonym` VARCHAR(255) NOT NULL, + `venue_id` INT UNSIGNED NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `venues_synonyms` + ADD INDEX `venues_synonyms_synonym_index`(`synonym`); +ALTER TABLE `venues_synonyms` + ADD INDEX `venues_synonyms_venue_id_index`(`venue_id`); +ALTER TABLE `venues_synonyms` + ADD CONSTRAINT `venues_synonyms_venue_id_foreign` FOREIGN KEY (`venue_id`) REFERENCES `venues` (`id`); + +CREATE TABLE `teams_synonyms` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `synonym` VARCHAR(255) NOT NULL, + `team_id` INT UNSIGNED NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `teams_synonyms` + ADD INDEX `teams_synonyms_synonym_index`(`synonym`); +ALTER TABLE `teams_synonyms` + ADD INDEX `teams_synonyms_team_id_index`(`team_id`); +ALTER TABLE `teams_synonyms` + ADD CONSTRAINT `teams_synonyms_team_id_foreign` FOREIGN KEY (`team_id`) REFERENCES `teams` (`id`); diff --git a/database/deployment/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql b/database/deployment/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql new file mode 100644 index 00000000..3926264e --- /dev/null +++ b/database/deployment/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql @@ -0,0 +1,37 @@ +CREATE TABLE `mapped_venues` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `upload_job_id` INT UNSIGNED NOT NULL, + `venue` VARCHAR(255) NOT NULL, + `venue_id` INT UNSIGNED NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `mapped_venues` + ADD INDEX `mapped_venues_venue_index`(`venue`); +ALTER TABLE `mapped_venues` + ADD CONSTRAINT `mapped_venues_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); +ALTER TABLE `mapped_venues` + ADD CONSTRAINT `mapped_venues_venue_id_foreign` FOREIGN KEY (`venue_id`) REFERENCES `venues` (`id`); + +CREATE TABLE `mapped_teams` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `upload_job_id` INT UNSIGNED NOT NULL, + `team` VARCHAR(255) NOT NULL, + `team_id` INT UNSIGNED NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `mapped_teams` + ADD INDEX `mapped_teams_team_index`(`team`); +ALTER TABLE `mapped_teams` + ADD CONSTRAINT `mapped_teams_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); +ALTER TABLE `mapped_teams` + ADD CONSTRAINT `mapped_teams_team_id_foreign` FOREIGN KEY (`team_id`) REFERENCES `teams` (`id`); diff --git a/database/deployment/2016_11_20_124340_create_new_venues_and_teams_tables.sql b/database/deployment/2016_11_20_124340_create_new_venues_and_teams_tables.sql new file mode 100644 index 00000000..afdea911 --- /dev/null +++ b/database/deployment/2016_11_20_124340_create_new_venues_and_teams_tables.sql @@ -0,0 +1,33 @@ +CREATE TABLE `new_venues` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `upload_job_id` INT UNSIGNED NOT NULL, + `venue` VARCHAR(255) NOT NULL, + `venue_id` INT UNSIGNED NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `new_venues` + ADD INDEX `new_venues_venue_index`(`venue`); +ALTER TABLE `new_venues` + ADD CONSTRAINT `new_venues_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); + +CREATE TABLE `new_teams` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `upload_job_id` INT UNSIGNED NOT NULL, + `team` VARCHAR(255) NOT NULL, + `team_id` INT UNSIGNED NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `new_teams` + ADD INDEX `new_teams_team_index`(`team`); +ALTER TABLE `new_teams` + ADD CONSTRAINT `new_teams_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_11_20_120809_create_synonyms_tables.sql b/database/deployment/rollbacks/2016_11_20_120809_create_synonyms_tables.sql new file mode 100644 index 00000000..c6217894 --- /dev/null +++ b/database/deployment/rollbacks/2016_11_20_120809_create_synonyms_tables.sql @@ -0,0 +1,7 @@ +ALTER TABLE `venues_synonyms` + DROP FOREIGN KEY `venues_synonyms_venue_id_foreign`; +DROP TABLE `venues_synonyms`; + +ALTER TABLE `teams_synonyms` + DROP FOREIGN KEY `teams_synonyms_team_id_foreign`; +DROP TABLE `teams_synonyms`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql b/database/deployment/rollbacks/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql new file mode 100644 index 00000000..17cf3913 --- /dev/null +++ b/database/deployment/rollbacks/2016_11_20_123304_create_mapped_venues_and_teams_tables.sql @@ -0,0 +1,11 @@ +ALTER TABLE `mapped_venues` + DROP FOREIGN KEY `mapped_venues_upload_job_id_foreign`; +ALTER TABLE `mapped_venues` + DROP FOREIGN KEY `mapped_venues_venue_id_foreign`; +DROP TABLE `mapped_venues`; + +ALTER TABLE `mapped_teams` + DROP FOREIGN KEY `mapped_teams_upload_job_id_foreign`; +ALTER TABLE `mapped_teams` + DROP FOREIGN KEY `mapped_teams_team_id_foreign`; +DROP TABLE `mapped_teams`; diff --git a/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_and_teams_tables.sql b/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_and_teams_tables.sql new file mode 100644 index 00000000..1b96b78d --- /dev/null +++ b/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_and_teams_tables.sql @@ -0,0 +1,7 @@ +ALTER TABLE `new_venues` + DROP FOREIGN KEY `new_venues_upload_job_id_foreign`; +DROP TABLE `new_venues`; + +ALTER TABLE `new_teams` + DROP FOREIGN KEY `new_teams_upload_job_id_foreign`; +DROP TABLE `new_teams`; diff --git a/database/migrations/2016_11_20_120809_create_synonyms_tables.php b/database/migrations/2016_11_20_120809_create_synonyms_tables.php new file mode 100644 index 00000000..34aaa8b9 --- /dev/null +++ b/database/migrations/2016_11_20_120809_create_synonyms_tables.php @@ -0,0 +1,63 @@ +engine = 'InnoDB'; + + $table->increments('id'); + $table->string('synonym'); + $table->unsignedInteger('venue_id'); + + $table->timestamps(); + + $table->index('synonym'); + $table->index('venue_id'); + + $table->foreign('venue_id')->references('id')->on('venues'); + }); + + Schema::create('teams_synonyms', function (Blueprint $table) { + $table->engine = 'InnoDB'; + + $table->increments('id'); + $table->string('synonym'); + $table->unsignedInteger('team_id'); + + $table->timestamps(); + + $table->index('synonym'); + $table->index('team_id'); + + $table->foreign('team_id')->references('id')->on('teams'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('venues_synonyms', function (Blueprint $table) { + $table->dropForeign(['venue_id']); + }); + Schema::drop('venues_synonyms'); + + Schema::table('teams_synonyms', function (Blueprint $table) { + $table->dropForeign(['team_id']); + }); + Schema::drop('teams_synonyms'); + } +} diff --git a/database/migrations/2016_11_20_123304_create_mapped_venues_and_teams_tables.php b/database/migrations/2016_11_20_123304_create_mapped_venues_and_teams_tables.php new file mode 100644 index 00000000..570172f2 --- /dev/null +++ b/database/migrations/2016_11_20_123304_create_mapped_venues_and_teams_tables.php @@ -0,0 +1,65 @@ +engine = 'InnoDB'; + + $table->increments('id'); + $table->unsignedInteger('upload_job_id'); + $table->string('venue'); + $table->unsignedInteger('venue_id'); + + $table->timestamps(); + + $table->index('venue'); + $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); + $table->foreign('venue_id')->references('id')->on('venues'); + }); + + Schema::create('mapped_teams', function (Blueprint $table) { + $table->engine = 'InnoDB'; + + $table->increments('id'); + $table->unsignedInteger('upload_job_id'); + $table->string('team'); + $table->unsignedInteger('team_id'); + + $table->timestamps(); + + $table->index('team'); + $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); + $table->foreign('team_id')->references('id')->on('teams'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('mapped_venues', function (Blueprint $table) { + $table->dropForeign(['upload_job_id']); + $table->dropForeign(['venue_id']); + }); + Schema::drop('mapped_venues'); + + Schema::table('mapped_teams', function (Blueprint $table) { + $table->dropForeign(['upload_job_id']); + $table->dropForeign(['team_id']); + }); + Schema::drop('mapped_teams'); + } +} diff --git a/database/migrations/2016_11_20_124340_create_new_venues_and_teams_tables.php b/database/migrations/2016_11_20_124340_create_new_venues_and_teams_tables.php new file mode 100644 index 00000000..35b47340 --- /dev/null +++ b/database/migrations/2016_11_20_124340_create_new_venues_and_teams_tables.php @@ -0,0 +1,61 @@ +engine = 'InnoDB'; + + $table->increments('id'); + $table->unsignedInteger('upload_job_id'); + $table->string('venue'); + $table->unsignedInteger('venue_id')->nullable(); + + $table->timestamps(); + + $table->index('venue'); + $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); + }); + + Schema::create('new_teams', function (Blueprint $table) { + $table->engine = 'InnoDB'; + + $table->increments('id'); + $table->unsignedInteger('upload_job_id'); + $table->string('team'); + $table->unsignedInteger('team_id')->nullable(); + + $table->timestamps(); + + $table->index('team'); + $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('new_venues', function (Blueprint $table) { + $table->dropForeign(['upload_job_id']); + }); + Schema::drop('new_venues'); + + Schema::table('new_teams', function (Blueprint $table) { + $table->dropForeign(['upload_job_id']); + }); + Schema::drop('new_teams'); + } +} From 4241a5fc67a13042b9e36e672fb4b199d8ea1874 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 20 Nov 2016 16:29:57 +0000 Subject: [PATCH 16/62] lva-22: Added migration scripts for synonyms, mapped and new tables, and relative models --- .gitignore | 1 + app/Models/AvailableAppointment.php | 21 ++----- app/Models/Club.php | 16 +----- app/Models/Division.php | 23 ++------ app/Models/Fixture.php | 48 ++++------------ app/Models/MappedTeam.php | 48 ++++++++++++++++ app/Models/MappedVenue.php | 48 ++++++++++++++++ app/Models/NewTeams.php | 40 +++++++++++++ app/Models/NewVenues.php | 40 +++++++++++++ app/Models/Role.php | 16 +----- app/Models/Season.php | 16 +----- app/Models/Team.php | 52 ++++++++++------- app/Models/TeamSynonym.php | 40 +++++++++++++ app/Models/UploadJob.php | 57 ++++++++++++++----- app/Models/UploadJobData.php | 40 +++++++++++++ app/Models/Venue.php | 38 ++++++++----- app/Models/VenueSynonym.php | 34 +++++++++++ app/User.php | 22 +------ ...0_152523_create_upload_jobs_data_table.sql | 14 +++++ ...0_152523_create_upload_jobs_data_table.sql | 4 ++ ...0_152523_create_upload_jobs_data_table.php | 42 ++++++++++++++ 21 files changed, 481 insertions(+), 179 deletions(-) create mode 100644 app/Models/MappedTeam.php create mode 100644 app/Models/MappedVenue.php create mode 100644 app/Models/NewTeams.php create mode 100644 app/Models/NewVenues.php create mode 100644 app/Models/TeamSynonym.php create mode 100644 app/Models/UploadJobData.php create mode 100644 app/Models/VenueSynonym.php create mode 100644 database/deployment/2016_11_20_152523_create_upload_jobs_data_table.sql create mode 100644 database/deployment/rollbacks/2016_11_20_152523_create_upload_jobs_data_table.sql create mode 100644 database/migrations/2016_11_20_152523_create_upload_jobs_data_table.php diff --git a/.gitignore b/.gitignore index bdd403a8..f5486579 100755 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ .env.* !.env.example _ide_helper.php +_ide_helper_models.php Vagrantfile diff --git a/app/Models/AvailableAppointment.php b/app/Models/AvailableAppointment.php index 6de3e5ff..25db0c12 100644 --- a/app/Models/AvailableAppointment.php +++ b/app/Models/AvailableAppointment.php @@ -5,21 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\AvailableAppointment - * - * @property-read \App\Models\Fixture $fixture - * @property-read \App\Models\Role $role - * @mixin \Eloquent - * @property integer $id - * @property integer $fixture_id - * @property integer $role_id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereFixtureId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereRoleId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\AvailableAppointment whereUpdatedAt($value) + * Class AvailableAppointment + * @package App\Models */ class AvailableAppointment extends Model { @@ -40,11 +27,11 @@ class AvailableAppointment extends Model public function fixture() { - return $this->belongsTo('App\Models\Fixture'); + return $this->belongsTo(Fixture::class); } public function role() { - return $this->belongsTo('App\Models\Role'); + return $this->belongsTo(Role::class); } } diff --git a/app/Models/Club.php b/app/Models/Club.php index 914c76e4..9506c404 100644 --- a/app/Models/Club.php +++ b/app/Models/Club.php @@ -5,18 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\Club - * - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Team[] $teams - * @mixin \Eloquent - * @property integer $id - * @property string $club - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereClub($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Club whereUpdatedAt($value) + * Class Club + * @package App\Models */ class Club extends Model { @@ -37,7 +27,7 @@ class Club extends Model public function teams() { - return $this->hasMany('App\Models\Team'); + return $this->hasMany(Team::class); } public function __toString() diff --git a/app/Models/Division.php b/app/Models/Division.php index 6e4d8706..3b558122 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -5,21 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\Division - * - * @property-read \App\Models\Season $season - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $fixtures - * @mixin \Eloquent - * @property integer $id - * @property integer $season_id - * @property string $division - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereSeasonId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereDivision($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Division whereUpdatedAt($value) + * Class Division + * @package App\Models */ class Division extends Model { @@ -40,12 +27,12 @@ class Division extends Model public function season() { - return $this->belongsTo('App\Models\Season'); + return $this->belongsTo(Season::class); } - + public function fixtures() { - return $this->hasMany('App\Models\Fixture'); + return $this->hasMany(Fixture::class); } public function __toString() diff --git a/app/Models/Fixture.php b/app/Models/Fixture.php index a7819f5b..ad58ea0e 100644 --- a/app/Models/Fixture.php +++ b/app/Models/Fixture.php @@ -6,36 +6,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\Fixture - * - * @property-read \App\Models\Division $division - * @property-read \App\Models\Team $home_team - * @property-read \App\Models\Team $away_team - * @property-read \App\Models\Venue $venue - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AvailableAppointment[] $available_appointments - * @property-read mixed $warm_up_time - * @property-read mixed $start_time - * @property-read mixed $match_date - * @mixin \Eloquent - * @property integer $id - * @property integer $division_id - * @property integer $match_number - * @property integer $home_team_id - * @property integer $away_team_id - * @property integer $venue_id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereDivisionId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereMatchNumber($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereMatchDate($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereWarmUpTime($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereStartTime($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereHomeTeamId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereAwayTeamId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereVenueId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Fixture whereUpdatedAt($value) + * Class Fixture + * @package App\Models */ class Fixture extends Model { @@ -60,34 +32,34 @@ class Fixture extends Model 'start_time', 'home_team_id', 'away_team_id', - 'venue_id' + 'venue_id', ]; - + public function division() { - return $this->belongsTo('App\Models\Division'); + return $this->belongsTo(Division::class); } public function home_team() { - return $this->belongsTo('App\Models\Team'); + return $this->belongsTo(Team::class); } public function away_team() { - return $this->belongsTo('App\Models\Team'); + return $this->belongsTo(Team::class); } public function venue() { - return $this->belongsTo('App\Models\Venue'); + return $this->belongsTo(Venue::class); } public function available_appointments() { - return $this->hasMany('App\Models\AvailableAppointment'); + return $this->hasMany(AvailableAppointment::class); } - + public function getWarmUpTimeAttribute($time) { return Carbon::createFromFormat('H:i:s', $time); diff --git a/app/Models/MappedTeam.php b/app/Models/MappedTeam.php new file mode 100644 index 00000000..a572b6cd --- /dev/null +++ b/app/Models/MappedTeam.php @@ -0,0 +1,48 @@ + + * Date: 20/11/2016 + * Time: 15:28 + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +/** + * Class MappedTeam + * @package App\Models + */ +class MappedTeam extends Model +{ + /** + * The database table used by the model. + * + * @var string + */ + protected $table = 'mapped_teams'; + + /** + * Attributes that should be mass-assignable. + * + * @var array + */ + protected $fillable = ['upload_job_id', 'team', 'team_id']; + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function uploadJob() + { + return $this->hasOne(UploadJob::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function team() + { + return $this->hasOne(Team::class); + } +} \ No newline at end of file diff --git a/app/Models/MappedVenue.php b/app/Models/MappedVenue.php new file mode 100644 index 00000000..0540cbf2 --- /dev/null +++ b/app/Models/MappedVenue.php @@ -0,0 +1,48 @@ + + * Date: 20/11/2016 + * Time: 16:05 + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +/** + * Class MappedVenue + * @package App\Models + */ +class MappedVenue extends Model +{ + /** + * The database table used by the model. + * + * @var string + */ + protected $table = 'mapped_venues'; + + /** + * Attributes that should be mass-assignable. + * + * @var array + */ + protected $fillable = ['upload_job_id', 'venue', 'venue_id']; + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function uploadJob() + { + return $this->hasOne(UploadJob::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function venue() + { + return $this->hasOne(Venue::class); + } +} \ No newline at end of file diff --git a/app/Models/NewTeams.php b/app/Models/NewTeams.php new file mode 100644 index 00000000..396986a2 --- /dev/null +++ b/app/Models/NewTeams.php @@ -0,0 +1,40 @@ + + * Date: 20/11/2016 + * Time: 16:07 + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +/** + * Class NewTeams + * @package App\Models + */ +class NewTeams extends Model +{ + /** + * The database table used by the model. + * + * @var string + */ + protected $table = 'new_teams'; + + /** + * Attributes that should be mass-assignable. + * + * @var array + */ + protected $fillable = ['upload_job_id', 'team', 'team_id']; + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function uploadJob() + { + return $this->hasOne(UploadJob::class); + } +} \ No newline at end of file diff --git a/app/Models/NewVenues.php b/app/Models/NewVenues.php new file mode 100644 index 00000000..f38d5858 --- /dev/null +++ b/app/Models/NewVenues.php @@ -0,0 +1,40 @@ + + * Date: 20/11/2016 + * Time: 16:09 + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +/** + * Class NewVenues + * @package App\Models + */ +class NewVenues extends Model +{ + /** + * The database table used by the model. + * + * @var string + */ + protected $table = 'new_venues'; + + /** + * Attributes that should be mass-assignable. + * + * @var array + */ + protected $fillable = ['upload_job_id', 'venue', 'venue_id']; + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function uploadJob() + { + return $this->hasOne(UploadJob::class); + } +} \ No newline at end of file diff --git a/app/Models/Role.php b/app/Models/Role.php index b7761468..f09cb27b 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -5,18 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\Role - * - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AvailableAppointment[] $available_appointments - * @mixin \Eloquent - * @property integer $id - * @property string $role - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereRole($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereUpdatedAt($value) + * Class Role + * @package App\Models */ class Role extends Model { @@ -37,7 +27,7 @@ class Role extends Model public function available_appointments() { - return $this->hasMany('App\Models\AvailableAppointment'); + return $this->hasMany(AvailableAppointment::class); } public function __toString() diff --git a/app/Models/Season.php b/app/Models/Season.php index 4b9171ab..3542c113 100644 --- a/app/Models/Season.php +++ b/app/Models/Season.php @@ -5,18 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\Season - * - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Division[] $divisions - * @mixin \Eloquent - * @property integer $id - * @property string $season - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereSeason($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Season whereUpdatedAt($value) + * Class Season + * @package App\Models */ class Season extends Model { @@ -37,7 +27,7 @@ class Season extends Model public function divisions() { - return $this->hasMany('App\Models\Division'); + return $this->hasMany(Division::class); } public function __toString() diff --git a/app/Models/Team.php b/app/Models/Team.php index e6c8b2d3..5f2d991e 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -5,22 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\Team - * - * @property-read \App\Models\Club $club - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $awayFixtures - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $homeFixtures - * @mixin \Eloquent - * @property integer $id - * @property integer $club_id - * @property string $team - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereClubId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereTeam($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Team whereUpdatedAt($value) + * Class Team + * @package App\Models */ class Team extends Model { @@ -39,21 +25,49 @@ class Team extends Model */ protected $fillable = ['club_id', 'team']; + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function club() { - return $this->belongsTo('App\Models\Club'); + return $this->belongsTo(Club::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function awayFixtures() { - return $this->hasMany('App\Models\Fixture', 'away_team_id'); + return $this->hasMany(Fixture::class, 'away_team_id'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function homeFixtures() { - return $this->hasMany('App\Models\Fixture', 'home_team_id'); + return $this->hasMany(Fixture::class, 'home_team_id'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function synonyms() + { + return $this->hasMany(TeamSynonym::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function mapped() + { + return $this->hasMany(MappedTeam::class); + } + + /** + * @return string + */ public function __toString() { return $this->team; diff --git a/app/Models/TeamSynonym.php b/app/Models/TeamSynonym.php new file mode 100644 index 00000000..cfa02dc7 --- /dev/null +++ b/app/Models/TeamSynonym.php @@ -0,0 +1,40 @@ + + * Date: 20/11/2016 + * Time: 14:51 + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +/** + * Class TeamSynonym + * @package App\Models + */ +class TeamSynonym extends Model +{ + /** + * The database table used by the model. + * + * @var string + */ + protected $table = 'teams_synonyms'; + + /** + * Attributes that should be mass-assignable. + * + * @var array + */ + protected $fillable = ['synonym', 'team_id']; + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function team() + { + return $this->hasOne(Team::class); + } +} \ No newline at end of file diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index 3dc2b64b..9e868aa6 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -5,21 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\UploadJob - * - * @property integer $id - * @property string $file - * @property string $type - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\UploadJob whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\UploadJob whereFile($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\UploadJob whereType($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\UploadJob whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\UploadJob whereUpdatedAt($value) - * @mixin \Eloquent - * @property string $status - * @method static \Illuminate\Database\Query\Builder|\App\Models\UploadJob whereStatus($value) + * Class UploadJob + * @package App\Models */ class UploadJob extends Model { @@ -53,6 +40,46 @@ public static function getStatusMessage($statusCode) } } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function mappedTeams() + { + return $this->hasMany(MappedTeam::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function mappedVenues() + { + return $this->hasMany(MappedVenue::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function newTeams() + { + return $this->hasMany(NewTeams::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function newVenues() + { + return $this->hasMany(NewVenues::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function modelData() + { + return $this->hasMany(UploadJobData::class); + } + /** * @param string $value * @return array diff --git a/app/Models/UploadJobData.php b/app/Models/UploadJobData.php new file mode 100644 index 00000000..c1d21f36 --- /dev/null +++ b/app/Models/UploadJobData.php @@ -0,0 +1,40 @@ + + * Date: 20/11/2016 + * Time: 15:56 + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +/** + * Class UploadJobData + * @package App\Models + */ +class UploadJobData extends Model +{ + /** + * The database table used by the model. + * + * @var string + */ + protected $table = 'upload_jobs_data'; + + /** + * Attributes that should be mass-assignable. + * + * @var array + */ + protected $fillable = ['upload_job_id', 'model_data']; + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function uploadJob() + { + return $this->hasOne(UploadJob::class); + } +} \ No newline at end of file diff --git a/app/Models/Venue.php b/app/Models/Venue.php index 01dc56bd..8328f6eb 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -5,18 +5,8 @@ use Illuminate\Database\Eloquent\Model; /** - * App\Models\Venue - * - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Fixture[] $fixtures - * @mixin \Eloquent - * @property integer $id - * @property string $venue - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereVenue($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\Models\Venue whereUpdatedAt($value) + * Class Venue + * @package App\Models */ class Venue extends Model { @@ -35,11 +25,33 @@ class Venue extends Model */ protected $fillable = ['venue']; + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function fixtures() { - return $this->hasMany('App\Models\Fixture'); + return $this->hasMany(Fixture::class); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function synonyms() + { + return $this->hasMany(VenueSynonym::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function mapped() + { + return $this->hasMany(MappedVenue::class); + } + + /** + * @return string + */ public function __toString() { return $this->venue; diff --git a/app/Models/VenueSynonym.php b/app/Models/VenueSynonym.php new file mode 100644 index 00000000..937a6263 --- /dev/null +++ b/app/Models/VenueSynonym.php @@ -0,0 +1,34 @@ +hasOne(Venue::class); + } +} diff --git a/app/User.php b/app/User.php index 40ecb901..c89dd861 100644 --- a/app/User.php +++ b/app/User.php @@ -4,27 +4,9 @@ use Illuminate\Foundation\Auth\User as Authenticatable; - /** - * App\User - * - * @property integer $id - * @property string $name - * @property string $email - * @property string $password - * @property string $remember_token - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $api_token - * @method static \Illuminate\Database\Query\Builder|\App\User whereId($value) - * @method static \Illuminate\Database\Query\Builder|\App\User whereName($value) - * @method static \Illuminate\Database\Query\Builder|\App\User whereEmail($value) - * @method static \Illuminate\Database\Query\Builder|\App\User wherePassword($value) - * @method static \Illuminate\Database\Query\Builder|\App\User whereRememberToken($value) - * @method static \Illuminate\Database\Query\Builder|\App\User whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\User whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\App\User whereApiToken($value) - * @mixin \Eloquent + * Class User + * @package App */ class User extends Authenticatable { diff --git a/database/deployment/2016_11_20_152523_create_upload_jobs_data_table.sql b/database/deployment/2016_11_20_152523_create_upload_jobs_data_table.sql new file mode 100644 index 00000000..1d826c69 --- /dev/null +++ b/database/deployment/2016_11_20_152523_create_upload_jobs_data_table.sql @@ -0,0 +1,14 @@ +CREATE TABLE `upload_jobs_data` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `upload_job_id` INT UNSIGNED NOT NULL, + `model` VARCHAR(255) NOT NULL, + `model_data` TEXT NOT NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_unicode_ci + ENGINE = InnoDB; + +ALTER TABLE `upload_jobs_data` + ADD CONSTRAINT `upload_jobs_data_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_11_20_152523_create_upload_jobs_data_table.sql b/database/deployment/rollbacks/2016_11_20_152523_create_upload_jobs_data_table.sql new file mode 100644 index 00000000..34c9b4c8 --- /dev/null +++ b/database/deployment/rollbacks/2016_11_20_152523_create_upload_jobs_data_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE `upload_jobs_data` + DROP FOREIGN KEY `upload_jobs_data_upload_job_id_foreign`; + +DROP TABLE `upload_jobs_data`; \ No newline at end of file diff --git a/database/migrations/2016_11_20_152523_create_upload_jobs_data_table.php b/database/migrations/2016_11_20_152523_create_upload_jobs_data_table.php new file mode 100644 index 00000000..4d26b174 --- /dev/null +++ b/database/migrations/2016_11_20_152523_create_upload_jobs_data_table.php @@ -0,0 +1,42 @@ +engine = 'InnoDB'; + + $table->increments('id'); + + $table->unsignedInteger('upload_job_id'); + $table->string('model'); + $table->text('model_data'); + + $table->timestamps(); + + $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('upload_jobs_data', function (Blueprint $table) { + $table->dropForeign(['upload_job_id']); + }); + Schema::drop('upload_jobs_data'); + } +} From 73e86f4950a8e9d5bf6a0d9d7ee75e247fe70037 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 21 Jan 2017 17:40:03 +0000 Subject: [PATCH 17/62] lva-22: Added basic flow for validation of CSV file --- .../Api/v1/UploadApiController.php | 54 ++++--- app/Models/Team.php | 11 ++ app/Models/TeamSynonym.php | 11 ++ app/Models/UploadJob.php | 21 ++- app/Models/Venue.php | 10 ++ app/Models/VenueSynonym.php | 10 ++ .../Contracts/InteractiveUploadContract.php | 9 +- app/Services/Contracts/StatusContract.php | 20 +++ .../InteractiveFixturesUploadService.php | 146 ++++++++++++++---- app/Services/StatusService.php | 106 +++++++++++++ composer.json | 3 +- composer.lock | 61 +------- ..._01_21_173202_add_index_for_team_table.sql | 2 + ..._01_21_173202_add_index_for_team_table.sql | 2 + ..._01_21_173202_add_index_for_team_table.php | 31 ++++ 15 files changed, 365 insertions(+), 132 deletions(-) create mode 100644 app/Services/Contracts/StatusContract.php create mode 100644 app/Services/StatusService.php create mode 100644 database/deployment/2017_01_21_173202_add_index_for_team_table.sql create mode 100644 database/deployment/rollbacks/2017_01_21_173202_add_index_for_team_table.sql create mode 100644 database/migrations/2017_01_21_173202_add_index_for_team_table.php diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index ea868940..1e816d0e 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -22,7 +22,7 @@ public function getUploadStatus() } $status = UploadJob::STATUS_UNKNOWN_DATA; - $uploadJob->status = [ + $uploadJob->setStatus([ 'StatusCode' => $status, 'StatusMessage' => UploadJob::getStatusMessage($status), 'Progress' => rand(10, 99), @@ -73,41 +73,16 @@ public function getUploadStatus() ], ], - - - ]; + ]); return response()->json([ 'Timestamp' => time(), 'Error' => false, 'Message' => 'Job found', - 'Status' => $uploadJob->status, + 'Status' => $uploadJob->getStatus(), ]); } - private function checkForJob() - { - $jobId = Input::get('job', null); - if (null === $jobId) { - return [ - 'Timestamp' => time(), - 'Error' => true, - 'Message' => 'Job parameter missing', - ]; - } - $uploadJob = UploadJob::find($jobId); - - if (is_null($uploadJob)) { - return [ - 'Timestamp' => time(), - 'Error' => true, - 'Message' => 'Job not found', - ]; - } - - return $uploadJob; - } - public function addTeam() { $uploadJob = $this->checkForJob(); @@ -155,4 +130,27 @@ public function mapVenue() 'success' => false, ]); } + + private function checkForJob() + { + $jobId = Input::get('job', null); + if (null === $jobId) { + return [ + 'Timestamp' => time(), + 'Error' => true, + 'Message' => 'Job parameter missing', + ]; + } + $uploadJob = UploadJob::find($jobId); + + if (is_null($uploadJob)) { + return [ + 'Timestamp' => time(), + 'Error' => true, + 'Message' => 'Job not found', + ]; + } + + return $uploadJob; + } } \ No newline at end of file diff --git a/app/Models/Team.php b/app/Models/Team.php index 5f2d991e..9fa70b87 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -6,6 +6,7 @@ /** * Class Team + * * @package App\Models */ class Team extends Model @@ -25,6 +26,16 @@ class Team extends Model */ protected $fillable = ['club_id', 'team']; + /** + * @param string $team + * + * @return Team|null + */ + public static function findByName($team) + { + return self::where('team', $team)->first(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/TeamSynonym.php b/app/Models/TeamSynonym.php index cfa02dc7..a0995acf 100644 --- a/app/Models/TeamSynonym.php +++ b/app/Models/TeamSynonym.php @@ -12,6 +12,7 @@ /** * Class TeamSynonym + * * @package App\Models */ class TeamSynonym extends Model @@ -30,6 +31,16 @@ class TeamSynonym extends Model */ protected $fillable = ['synonym', 'team_id']; + /** + * @param string $synonym + * + * @return Team|null + */ + public static function findBySynonym($synonym) + { + return self::where('synonym', $synonym)->first()->team; + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index 9e868aa6..a00d8a47 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -6,6 +6,7 @@ /** * Class UploadJob + * * @package App\Models */ class UploadJob extends Model @@ -81,19 +82,27 @@ public function modelData() } /** - * @param string $value * @return array */ - public function getStatusAttribute($value) + public function getStatus() { - return json_decode($value, true); + return json_decode($this->status, true); } /** - * @param array $value + * @param array $status + * + * @return UploadJob */ - public function setStatusAttribute($value) + public function setStatus($status) { - $this->attributes['status'] = json_encode($value); + $this->status = json_encode($status); + + return $this; + } + + public function getFile() + { + return $this->file; } } diff --git a/app/Models/Venue.php b/app/Models/Venue.php index 8328f6eb..3c3e25b1 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -25,6 +25,16 @@ class Venue extends Model */ protected $fillable = ['venue']; + /** + * @param string $venue + * + * @return Venue|null + */ + public static function findByName($venue) + { + return self::where('venue', $venue)->first(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/VenueSynonym.php b/app/Models/VenueSynonym.php index 937a6263..4754acaa 100644 --- a/app/Models/VenueSynonym.php +++ b/app/Models/VenueSynonym.php @@ -24,6 +24,16 @@ class VenueSynonym extends Model */ protected $fillable = ['synonym', 'venue_id']; + /** + * @param string $synonym + * + * @return Venue|null + */ + public static function findBySynonym($synonym) + { + return self::where('synonym', $synonym)->first()->venue; + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ diff --git a/app/Services/Contracts/InteractiveUploadContract.php b/app/Services/Contracts/InteractiveUploadContract.php index ebbb66a2..239fc272 100644 --- a/app/Services/Contracts/InteractiveUploadContract.php +++ b/app/Services/Contracts/InteractiveUploadContract.php @@ -15,20 +15,15 @@ interface InteractiveUploadContract { /** * @param UploadedFile $file + * * @return int */ public function createJob(UploadedFile $file); /** * @param UploadJob $job + * * @return mixed */ public function processJob(UploadJob $job); - - /** - * @param UploadJob $job - * @param array $newStatus - * @return mixed - */ - public function updateStatus(UploadJob $job, array $newStatus); } \ No newline at end of file diff --git a/app/Services/Contracts/StatusContract.php b/app/Services/Contracts/StatusContract.php new file mode 100644 index 00000000..5d8cf984 --- /dev/null +++ b/app/Services/Contracts/StatusContract.php @@ -0,0 +1,20 @@ + + * Date: 21/01/2017 + * Time: 15:02 + */ + +namespace App\Services\Contracts; + +interface StatusContract +{ + public function getNextStepStatus($status); + + public function getStatusCode($status); + + public function getStatusProcessedLines($status); + + public function setStatusProcessedLines(&$status, $lines); +} \ No newline at end of file diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index cf05e95c..86625b9c 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -8,7 +8,12 @@ namespace App\Services; +use App\Models\Team; +use App\Models\TeamSynonym; +use App\Models\Venue; +use App\Models\VenueSynonym; use App\Services\Contracts\InteractiveUploadContract; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\UploadedFile; use App\Models\UploadJob; @@ -17,15 +22,37 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract { const UPLOAD_DIR = '/app/files/'; - /******************* - * PRIVATE METHODS * - *******************/ + /** @var StatusService */ + private $statusService; + + /** @var Collection */ + private $mappedTeams; + /** @var Collection */ + private $mappedVenues; + /** @var Collection */ + private $newTeams; + /** @var Collection */ + private $newVenues; + + /** + * @inheritDoc + */ + public function __construct(StatusService $statusService) + { + $this->statusService = $statusService; + } + + + /************************************ + * INTERFACE IMPLEMENTATION METHODS * + ************************************/ /** * @inheritdoc */ public function createJob(UploadedFile $file) { + /** @var UploadedFile $fixtureFile */ $fixtureFile = $file->move(storage_path() . self::UPLOAD_DIR, $file->getClientOriginalName()); $job = UploadJob::create([ @@ -42,15 +69,46 @@ public function createJob(UploadedFile $file) */ public function processJob(UploadJob $job) { - $statusCode = $this->getStatusCode($job); + $this->mappedTeams = $job->mappedTeams; + $this->mappedVenues = $job->mappedVenues; + $this->newTeams = $job->newTeams; + $this->newVenues = $job->newVenues; + + $status = $job->getStatus(); + + $statusCode = $this->statusService->getStatusCode($status); if ($statusCode == UploadJob::STATUS_NOT_STARTED) { - $status = $this->initialStatus(); - $this->updateStatus($job, $status); + + $status = $this->statusService->getNextStepStatus($status); + $job->setStatus($status)->save(); } if ($statusCode == UploadJob::STATUS_VALIDATING_RECORDS) { - //$this->validateFixtures(); + $processedLines = $this->statusService->getStatusProcessedLines($status); + + /** @var resource $csvFile */ + $csvFile = fopen(storage_path() . self::UPLOAD_DIR . $job->getFile(), 'r'); + + $headers = fgets($csvFile); + + $this->getIntoPosition($csvFile, $processedLines); + + while (!feof($csvFile)) { + $row = array_combine($headers, fgets($csvFile)); + if (!$this->isValidRow($row)) { + // Prepare for asking the user what to do + fclose($csvFile); + break; + } + $processedLines++; + $this->statusService->setStatusProcessedLines($status, $processedLines); + $job->setStatus($status)->save(); + } + fclose($csvFile); + + $status = $this->statusService->getNextStepStatus($status); + $job->setStatus($status)->save(); } if ($statusCode == UploadJob::STATUS_INSERTING_RECORDS) { @@ -62,43 +120,71 @@ public function processJob(UploadJob $job) } } - /************************************ - * INTERFACE IMPLEMENTATION METHODS * - ************************************/ + /******************* + * PRIVATE METHODS * + *******************/ /** - * @param UploadJob $job - * @return int + * @param resource $file + * @param int $numberOfLines */ - private function getStatusCode(UploadJob $job) + private function getIntoPosition($file, $numberOfLines) { - $status = $job->status; - - if (array_has($status, 'status_code')) { - return $status['status_code']; + $counter = 0; + while ($counter < $numberOfLines && !feof($file)) { + fgets($file); + $counter++; } - - return UploadJob::STATUS_NOT_STARTED; } /** - * @return array + * @param array $row + * + * @return bool */ - private function initialStatus() + private function isValidRow($row) { - return [ - 'status_code' => UploadJob::STATUS_VALIDATING_RECORDS, - ]; + $isValid = true; + + $isValid = $isValid && $this->isValidTeam($row['Home']); + $isValid = $isValid && $this->isValidTeam($row['Away']); + + $isValid = $isValid && $this->isValidVenue($row['Hall']); + + return $isValid; } - /** - * @inheritDoc - */ - public function updateStatus(UploadJob $job, array $newStatus) + private function isValidTeam($team) { - $job->status = $newStatus; - $job->save(); + $model = Team::findByName($team); + if (is_null($model)) { + $model = TeamSynonym::findBySynonym($team); + } + if (is_null($model)) { + if (!in_array($team, $this->mappedTeams->pluck('team')->all()) && + !in_array($team, $this->newTeams->pluck('team')->all()) + ) { + return false; + } + } + + return true; } + private function isValidVenue($venue) + { + $model = Venue::findByName($venue); + if (is_null($model)) { + $model = VenueSynonym::findBySynonym($venue); + } + if (is_null($model)) { + if (!in_array($venue, $this->mappedVenues->pluck('venue')->all()) && + !in_array($venue, $this->newVenues->pluck('venue')->all()) + ) { + return false; + } + } + return true; + } } \ No newline at end of file diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php new file mode 100644 index 00000000..f7ff2439 --- /dev/null +++ b/app/Services/StatusService.php @@ -0,0 +1,106 @@ + + * Date: 21/01/2017 + * Time: 15:02 + */ + +namespace App\Services; + +use App\Services\Contracts\StatusContract; +use App\Models\UploadJob; + +/** + * Class StatusService + * + * This class implements the StatusContract interface using the UploadJobs model. + * This means that the status will be saved in the DB and that the status codes + * are the ones defined in the UploadJobs model class. + * + * @package App\Services + */ +class StatusService implements StatusContract +{ + /** + * @param array $status + * + * @return array + */ + public function getNextStepStatus($status) + { + $newStatus = [ + 'status_code' => UploadJob::STATUS_NOT_STARTED, + ]; + + switch ($status['status_code']) { + case UploadJob::STATUS_NOT_STARTED: + $newStatus = [ + 'status_code' => UploadJob::STATUS_VALIDATING_RECORDS, + 'processed_lines' => 0, + ]; + break; + case UploadJob::STATUS_VALIDATING_RECORDS: + $newStatus = [ + 'status_code' => UploadJob::STATUS_INSERTING_RECORDS, + ]; + break; + case UploadJob::STATUS_INSERTING_RECORDS: + $newStatus = [ + 'status_code' => UploadJob::STATUS_DONE, + ]; + break; + } + + return $newStatus; + } + + /** + * @param array $status + * + * @return int + */ + public function getStatusCode($status) + { + if (array_has($status, 'status_code')) { + return $status['status_code']; + } + + return UploadJob::STATUS_NOT_STARTED; + } + + /** + * @param array $status + * + * @return int + * @throws \RuntimeException + */ + public function getStatusProcessedLines($status) + { + $statusCode = $this->getStatusCode($status); + + if ($statusCode == UploadJob::STATUS_VALIDATING_RECORDS && array_has($status, 'processed_lines')) { + return $status['processed_lines']; + } + + throw new \RuntimeException('Invalid status for retrieving number of already processed lines.'); + } + + /** + * @param array $status + * @param int $processedLines + * + * @throws \RuntimeException + */ + public function setStatusProcessedLines(&$status, $processedLines) + { + $statusCode = $this->getStatusCode($status); + + if ($statusCode == UploadJob::STATUS_VALIDATING_RECORDS) { + $status['processed_lines'] = $processedLines; + } + + throw new \RuntimeException('Invalid status for setting number of already processed lines.'); + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json index 457f1dfc..7e3b655b 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,7 @@ "laravel/framework": "5.2.*", "davejamesmiller/laravel-breadcrumbs": "^3.0", "laravelcollective/html": "^5.2", - "laracasts/flash": "^2.0", - "league/csv": "^8.0" + "laracasts/flash": "^2.0" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index 67561ac7..90a3794e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "54a8d4ae878cd90becf955112762602f", - "content-hash": "0efb3d17e3cbe8118c948da57617fc34", + "hash": "e76003e428c05dd2ecad50593a5d7c7e", + "content-hash": "1e1a72b5a999e3b23204b8f7039882e0", "packages": [ { "name": "classpreloader/classpreloader", @@ -582,63 +582,6 @@ "homepage": "http://laravelcollective.com", "time": "2016-01-27 22:29:54" }, - { - "name": "league/csv", - "version": "8.1.1", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/csv.git", - "reference": "3b22a40804aa0bc5224ffb2f5e8248edf0a9a38c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/csv/zipball/3b22a40804aa0bc5224ffb2f5e8248edf0a9a38c", - "reference": "3b22a40804aa0bc5224ffb2f5e8248edf0a9a38c", - "shasum": "" - }, - "require": { - "ext-mbstring": "*", - "php": ">=5.5.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^1.9", - "phpunit/phpunit": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "8.0-dev" - } - }, - "autoload": { - "psr-4": { - "League\\Csv\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ignace Nyamagana Butera", - "email": "nyamsprod@gmail.com", - "homepage": "https://github.com/nyamsprod/", - "role": "Developer" - } - ], - "description": "Csv data manipulation made easy in PHP", - "homepage": "http://csv.thephpleague.com", - "keywords": [ - "csv", - "export", - "filter", - "import", - "read", - "write" - ], - "time": "2016-09-05 08:16:07" - }, { "name": "league/flysystem", "version": "1.0.27", diff --git a/database/deployment/2017_01_21_173202_add_index_for_team_table.sql b/database/deployment/2017_01_21_173202_add_index_for_team_table.sql new file mode 100644 index 00000000..f2c4fffd --- /dev/null +++ b/database/deployment/2017_01_21_173202_add_index_for_team_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE `teams` + ADD INDEX `teams_team_index`(`team`); \ No newline at end of file diff --git a/database/deployment/rollbacks/2017_01_21_173202_add_index_for_team_table.sql b/database/deployment/rollbacks/2017_01_21_173202_add_index_for_team_table.sql new file mode 100644 index 00000000..48721510 --- /dev/null +++ b/database/deployment/rollbacks/2017_01_21_173202_add_index_for_team_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE `teams` + DROP INDEX `teams_team_index`; \ No newline at end of file diff --git a/database/migrations/2017_01_21_173202_add_index_for_team_table.php b/database/migrations/2017_01_21_173202_add_index_for_team_table.php new file mode 100644 index 00000000..4d19de6c --- /dev/null +++ b/database/migrations/2017_01_21_173202_add_index_for_team_table.php @@ -0,0 +1,31 @@ +index(['team']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('teams', function (Blueprint $table) { + $table->dropIndex(['team']); + }); + } +} From 4d45f31e4c7ca0f4b7c955cb142531ae8e452b2e Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 29 Jan 2017 13:15:18 +0000 Subject: [PATCH 18/62] lva-22: Some refactoring and saved a valid row into the DB --- app/Models/AvailableAppointment.php | 16 +- app/Models/Club.php | 24 ++- app/Models/Division.php | 26 ++++ app/Models/Fixture.php | 139 +++++++++++++++++- app/Models/MappedTeam.php | 10 ++ app/Models/MappedVenue.php | 9 ++ app/Models/NewTeams.php | 9 ++ app/Models/NewVenues.php | 9 ++ app/Models/Role.php | 15 ++ app/Models/Season.php | 16 +- app/Models/Team.php | 9 +- app/Models/TeamSynonym.php | 8 + app/Models/UploadJob.php | 13 +- app/Models/UploadJobData.php | 63 +++++++- app/Models/Venue.php | 18 ++- app/Models/VenueSynonym.php | 9 ++ .../InteractiveFixturesUploadService.php | 49 +++++- 17 files changed, 428 insertions(+), 14 deletions(-) diff --git a/app/Models/AvailableAppointment.php b/app/Models/AvailableAppointment.php index 25db0c12..2801bf61 100644 --- a/app/Models/AvailableAppointment.php +++ b/app/Models/AvailableAppointment.php @@ -6,11 +6,11 @@ /** * Class AvailableAppointment + * * @package App\Models */ class AvailableAppointment extends Model { - /** * The database table used by the model. * @@ -25,13 +25,27 @@ class AvailableAppointment extends Model */ protected $fillable = ['fixture_id', 'role_id']; + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function fixture() { return $this->belongsTo(Fixture::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function role() { return $this->belongsTo(Role::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } } diff --git a/app/Models/Club.php b/app/Models/Club.php index 9506c404..87811406 100644 --- a/app/Models/Club.php +++ b/app/Models/Club.php @@ -6,11 +6,11 @@ /** * Class Club + * * @package App\Models */ class Club extends Model { - /** * The database table used by the model. * @@ -25,11 +25,33 @@ class Club extends Model */ protected $fillable = ['club']; + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function teams() { return $this->hasMany(Team::class); } + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getName() + { + return $this->club; + } + + /** + * @return string + */ public function __toString() { return $this->club; diff --git a/app/Models/Division.php b/app/Models/Division.php index 3b558122..db88ed42 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -6,6 +6,7 @@ /** * Class Division + * * @package App\Models */ class Division extends Model @@ -25,16 +26,41 @@ class Division extends Model */ protected $fillable = ['season_id', 'division']; + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function season() { return $this->belongsTo(Season::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function fixtures() { return $this->hasMany(Fixture::class); } + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getName() + { + return $this->division; + } + + /** + * @return string + */ public function __toString() { return $this->season . ' ' . $this->division; diff --git a/app/Models/Fixture.php b/app/Models/Fixture.php index ad58ea0e..98e9cf0c 100644 --- a/app/Models/Fixture.php +++ b/app/Models/Fixture.php @@ -7,11 +7,11 @@ /** * Class Fixture + * * @package App\Models */ class Fixture extends Model { - /** * The database table used by the model. * @@ -35,46 +35,183 @@ class Fixture extends Model 'venue_id', ]; + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function division() { return $this->belongsTo(Division::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function home_team() { return $this->belongsTo(Team::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function away_team() { return $this->belongsTo(Team::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function venue() { return $this->belongsTo(Venue::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function available_appointments() { return $this->hasMany(AvailableAppointment::class); } + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $divisionId + * + * @return Fixture + */ + public function setDivision($divisionId) + { + $this->division_id = $divisionId; + + return $this; + } + + /** + * @param int $macthNumber + * + * @return Fixture + */ + public function setMatchNumber($macthNumber) + { + $this->match_number = $macthNumber; + + return $this; + } + + /** + * @param Carbon $date + * + * @return Fixture + */ + public function setMatchDate(Carbon $date) + { + $this->match_date = $date->format('Y-m-d'); + + return $this; + } + + /** + * @param Carbon $time + * + * @return Fixture + */ + public function setWarmUpTime(Carbon $time) + { + $this->warm_up_time = $time->format('H:i:s'); + + return $this; + } + + /** + * @param Carbon $time + * + * @return Fixture + */ + public function setStartTime(Carbon $time) + { + $this->start_time = $time->format('H:i:s'); + + return $this; + } + + /** + * @param int $teamId + * + * @return Fixture + */ + public function setHomeTeam($teamId) + { + $this->home_team_id = $teamId; + + return $this; + } + + /** + * @param int $teamId + * + * @return Fixture + */ + public function setAwayTeam($teamId) + { + $this->away_team_id = $teamId; + + return $this; + } + + /** + * @param int $venueId + * + * @return Fixture + */ + public function setVenue($venueId) + { + $this->venue_id = $venueId; + + return $this; + } + + /** + * @param string $time + * + * @return Carbon + */ public function getWarmUpTimeAttribute($time) { return Carbon::createFromFormat('H:i:s', $time); } + /** + * @param string $time + * + * @return Carbon + */ public function getStartTimeAttribute($time) { return Carbon::createFromFormat('H:i:s', $time); } + /** + * @param string $date + * + * @return Carbon + */ public function getMatchDateAttribute($date) { return Carbon::createFromFormat('Y-m-d', $date); } + /** + * @return string + */ public function __toString() { return diff --git a/app/Models/MappedTeam.php b/app/Models/MappedTeam.php index a572b6cd..89d38b2a 100644 --- a/app/Models/MappedTeam.php +++ b/app/Models/MappedTeam.php @@ -12,6 +12,7 @@ /** * Class MappedTeam + * * @package App\Models */ class MappedTeam extends Model @@ -45,4 +46,13 @@ public function team() { return $this->hasOne(Team::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + } \ No newline at end of file diff --git a/app/Models/MappedVenue.php b/app/Models/MappedVenue.php index 0540cbf2..41e1827e 100644 --- a/app/Models/MappedVenue.php +++ b/app/Models/MappedVenue.php @@ -12,6 +12,7 @@ /** * Class MappedVenue + * * @package App\Models */ class MappedVenue extends Model @@ -45,4 +46,12 @@ public function venue() { return $this->hasOne(Venue::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } } \ No newline at end of file diff --git a/app/Models/NewTeams.php b/app/Models/NewTeams.php index 396986a2..b8045783 100644 --- a/app/Models/NewTeams.php +++ b/app/Models/NewTeams.php @@ -12,6 +12,7 @@ /** * Class NewTeams + * * @package App\Models */ class NewTeams extends Model @@ -37,4 +38,12 @@ public function uploadJob() { return $this->hasOne(UploadJob::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } } \ No newline at end of file diff --git a/app/Models/NewVenues.php b/app/Models/NewVenues.php index f38d5858..c340ccca 100644 --- a/app/Models/NewVenues.php +++ b/app/Models/NewVenues.php @@ -12,6 +12,7 @@ /** * Class NewVenues + * * @package App\Models */ class NewVenues extends Model @@ -37,4 +38,12 @@ public function uploadJob() { return $this->hasOne(UploadJob::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } } \ No newline at end of file diff --git a/app/Models/Role.php b/app/Models/Role.php index f09cb27b..adb5f31a 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -6,6 +6,7 @@ /** * Class Role + * * @package App\Models */ class Role extends Model @@ -25,11 +26,25 @@ class Role extends Model */ protected $fillable = ['role']; + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function available_appointments() { return $this->hasMany(AvailableAppointment::class); } + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ public function __toString() { return $this->role; diff --git a/app/Models/Season.php b/app/Models/Season.php index 3542c113..e984b00c 100644 --- a/app/Models/Season.php +++ b/app/Models/Season.php @@ -6,11 +6,11 @@ /** * Class Season + * * @package App\Models */ class Season extends Model { - /** * The database table used by the model. * @@ -25,11 +25,25 @@ class Season extends Model */ protected $fillable = ['season']; + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function divisions() { return $this->hasMany(Division::class); } + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ public function __toString() { return $this->season; diff --git a/app/Models/Team.php b/app/Models/Team.php index 9fa70b87..03ffacc1 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -11,7 +11,6 @@ */ class Team extends Model { - /** * The database table used by the model. * @@ -76,6 +75,14 @@ public function mapped() return $this->hasMany(MappedTeam::class); } + /** + * @return int + */ + public function getId() + { + return $this->id; + } + /** * @return string */ diff --git a/app/Models/TeamSynonym.php b/app/Models/TeamSynonym.php index a0995acf..330d6b7d 100644 --- a/app/Models/TeamSynonym.php +++ b/app/Models/TeamSynonym.php @@ -48,4 +48,12 @@ public function team() { return $this->hasOne(Team::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } } \ No newline at end of file diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index a00d8a47..00cc4c78 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -76,11 +76,19 @@ public function newVenues() /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ - public function modelData() + public function uploadData() { return $this->hasMany(UploadJobData::class); } + /** + * @return int + */ + public function getId() + { + return $this->id; + } + /** * @return array */ @@ -101,6 +109,9 @@ public function setStatus($status) return $this; } + /** + * @return string + */ public function getFile() { return $this->file; diff --git a/app/Models/UploadJobData.php b/app/Models/UploadJobData.php index c1d21f36..089738c3 100644 --- a/app/Models/UploadJobData.php +++ b/app/Models/UploadJobData.php @@ -12,6 +12,7 @@ /** * Class UploadJobData + * * @package App\Models */ class UploadJobData extends Model @@ -28,7 +29,7 @@ class UploadJobData extends Model * * @var array */ - protected $fillable = ['upload_job_id', 'model_data']; + protected $fillable = ['upload_job_id', 'model', 'model_data']; /** * @return \Illuminate\Database\Eloquent\Relations\HasOne @@ -37,4 +38,64 @@ public function uploadJob() { return $this->hasOne(UploadJob::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $jobId + * + * @return UploadJobData + */ + public function setJobId($jobId) + { + $this->upload_job_id = $jobId; + + return $this; + } + + /** + * @return string + */ + public function getModel() + { + return $this->model; + } + + /** + * @param string $model + * + * @return UploadJobData + */ + public function setModel($model) + { + $this->model = $model; + + return $this; + } + + /** + * @return string + */ + public function getData() + { + return $this->model_data; + } + + /** + * @param string $data + * + * @return UploadJobData + */ + public function setData($data) + { + $this->model_data = $data; + + return $this; + } } \ No newline at end of file diff --git a/app/Models/Venue.php b/app/Models/Venue.php index 3c3e25b1..86dd317e 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -6,11 +6,11 @@ /** * Class Venue + * * @package App\Models */ class Venue extends Model { - /** * The database table used by the model. * @@ -59,6 +59,22 @@ public function mapped() return $this->hasMany(MappedVenue::class); } + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->venue(); + } + /** * @return string */ diff --git a/app/Models/VenueSynonym.php b/app/Models/VenueSynonym.php index 4754acaa..7e6ac61a 100644 --- a/app/Models/VenueSynonym.php +++ b/app/Models/VenueSynonym.php @@ -6,6 +6,7 @@ /** * Class VenueSynonym + * * @package App\Models */ class VenueSynonym extends Model @@ -41,4 +42,12 @@ public function venue() { return $this->hasOne(Venue::class); } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } } diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index 86625b9c..5ee57fcd 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -8,11 +8,15 @@ namespace App\Services; +use App\Models\Division; +use App\Models\Fixture; use App\Models\Team; use App\Models\TeamSynonym; +use App\Models\UploadJobData; use App\Models\Venue; use App\Models\VenueSynonym; use App\Services\Contracts\InteractiveUploadContract; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\UploadedFile; @@ -61,7 +65,7 @@ public function createJob(UploadedFile $file) 'status' => ['status_code' => UploadJob::STATUS_NOT_STARTED], ]); - return $job->id; + return $job->getId(); } /** @@ -81,6 +85,7 @@ public function processJob(UploadJob $job) if ($statusCode == UploadJob::STATUS_NOT_STARTED) { $status = $this->statusService->getNextStepStatus($status); + $statusCode = $this->statusService->getStatusCode($status); $job->setStatus($status)->save(); } @@ -94,29 +99,36 @@ public function processJob(UploadJob $job) $this->getIntoPosition($csvFile, $processedLines); + $allRowsProcessed = true; while (!feof($csvFile)) { $row = array_combine($headers, fgets($csvFile)); if (!$this->isValidRow($row)) { - // Prepare for asking the user what to do + // @todo Prepare for asking the user what to do + $allRowsProcessed = false; fclose($csvFile); break; } + $this->insertFixture($job->getId(), $row); + $processedLines++; $this->statusService->setStatusProcessedLines($status, $processedLines); $job->setStatus($status)->save(); } fclose($csvFile); - $status = $this->statusService->getNextStepStatus($status); - $job->setStatus($status)->save(); + if ($allRowsProcessed) { + $status = $this->statusService->getNextStepStatus($status); + $statusCode = $this->statusService->getStatusCode($status); + $job->setStatus($status)->save(); + } } if ($statusCode == UploadJob::STATUS_INSERTING_RECORDS) { - // insert into DB + // @todo insert into DB } if ($statusCode == UploadJob::STATUS_DONE) { - // Clean up + // @todo Clean up } } @@ -187,4 +199,29 @@ private function isValidVenue($venue) return true; } + + private function insertFixture($jobId, $data) + { + + $fixture = new Fixture(); + $fixture + ->setDivision(Division::find($data['Code'])->getId()) + ->setMatchNumber($data['Match']) + ->setMatchDate(Carbon::createFromFormat('d/m/Y', $data['date'])) + ->setWarmUpTime(Carbon::createFromFormat('H:i:s', $data['WUTime'])) + ->setStartTime(Carbon::createFromFormat('H:i:s', $data['StartTime'])) + ->setHomeTeam(Team::findByName($data['Home'])->getId()) + ->setAwayTeam(Team::findByName($data['Away'])->getId()) + ->setVenue(Venue::findByName($data['Hall'])->getId()); + + $jobData = new UploadJobData(); + + $jobData + ->setJobId($jobId) + ->setModel(Fixture::class) + ->setData($fixture->toJson()) + ->save(); + + unset($fixture); + } } \ No newline at end of file From c486a2684f632966545428fcf9d5300fbca24f60 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 29 Jan 2017 16:53:42 +0000 Subject: [PATCH 19/62] lva-22: More work --- app/Models/TeamSynonym.php | 7 ++- app/Models/UploadJob.php | 60 +++++++++++++++++-- .../InteractiveFixturesUploadService.php | 43 +++++++++---- app/Validators/CustomValidators.php | 6 +- ...d_row_count_field_to_upload_jobs_table.sql | 2 + ...d_row_count_field_to_upload_jobs_table.sql | 2 + ...d_row_count_field_to_upload_jobs_table.php | 31 ++++++++++ 7 files changed, 131 insertions(+), 20 deletions(-) create mode 100644 database/deployment/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql create mode 100644 database/deployment/rollbacks/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql create mode 100644 database/migrations/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.php diff --git a/app/Models/TeamSynonym.php b/app/Models/TeamSynonym.php index 330d6b7d..646c8237 100644 --- a/app/Models/TeamSynonym.php +++ b/app/Models/TeamSynonym.php @@ -38,7 +38,12 @@ class TeamSynonym extends Model */ public static function findBySynonym($synonym) { - return self::where('synonym', $synonym)->first()->team; + $synonym = self::where('synonym', $synonym)->first(); + if ($synonym) { + return $synonym->name; + } + + return null; } /** diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index 00cc4c78..3ea973e3 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -21,7 +21,7 @@ class UploadJob extends Model const STATUS_DONE = 99; protected $table = 'upload_jobs'; - protected $fillable = ['file', 'type', 'status']; + protected $fillable = ['file', 'row_count', 'type', 'status']; public static function getStatusMessage($statusCode) { @@ -89,6 +89,46 @@ public function getId() return $this->id; } + /** + * @return string + */ + public function getFile() + { + return $this->file; + } + + /** + * @param string $filename + * + * @return UploadJob + */ + public function setFile($filename) + { + $this->file = $filename; + + return $this; + } + + /** + * @return mixed + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * + * @return UploadJob + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } + /** * @return array */ @@ -110,10 +150,22 @@ public function setStatus($status) } /** - * @return string + * @return int|null */ - public function getFile() + public function getRowCount() { - return $this->file; + return $this->row_count; + } + + /** + * @param int $count + * + * @return UploadJob + */ + public function setRowCount($count) + { + $this->row_count = $count; + + return $this; } } diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index 5ee57fcd..3961c336 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -51,6 +51,18 @@ public function __construct(StatusService $statusService) * INTERFACE IMPLEMENTATION METHODS * ************************************/ + /** + * @param resource $handle + * + * @return array + */ + public static function readOneLine(&$handle) + { + return array_map(function ($field) { + return str_replace(['"', "\n", "\r"], '', $field); + }, explode(',', fgets($handle))); + } + /** * @inheritdoc */ @@ -59,15 +71,27 @@ public function createJob(UploadedFile $file) /** @var UploadedFile $fixtureFile */ $fixtureFile = $file->move(storage_path() . self::UPLOAD_DIR, $file->getClientOriginalName()); - $job = UploadJob::create([ - 'file' => $fixtureFile->getFilename(), - 'type' => UploadJob::TYPE_FIXTURES, - 'status' => ['status_code' => UploadJob::STATUS_NOT_STARTED], - ]); + $handle = fopen($fixtureFile->getRealPath(), 'rb'); + $lines = 0; + while (!feof($handle)) { + $lines += substr_count(fread($handle, 8192), "\n"); + } + fclose($handle); + + $job = new UploadJob(); + $job->setFile($fixtureFile->getFilename()) + ->setType(UploadJob::TYPE_FIXTURES) + ->setRowCount($lines - 1)// Don't count the first line as they are the headers + ->setStatus(['status_code' => UploadJob::STATUS_NOT_STARTED]) + ->save(); return $job->getId(); } + /******************* + * PRIVATE METHODS * + *******************/ + /** * @inheritDoc */ @@ -95,17 +119,16 @@ public function processJob(UploadJob $job) /** @var resource $csvFile */ $csvFile = fopen(storage_path() . self::UPLOAD_DIR . $job->getFile(), 'r'); - $headers = fgets($csvFile); + $headers = self::readOneLine($csvFile); $this->getIntoPosition($csvFile, $processedLines); $allRowsProcessed = true; while (!feof($csvFile)) { - $row = array_combine($headers, fgets($csvFile)); + $row = array_combine($headers, self::readOneLine($csvFile)); if (!$this->isValidRow($row)) { // @todo Prepare for asking the user what to do $allRowsProcessed = false; - fclose($csvFile); break; } $this->insertFixture($job->getId(), $row); @@ -132,10 +155,6 @@ public function processJob(UploadJob $job) } } - /******************* - * PRIVATE METHODS * - *******************/ - /** * @param resource $file * @param int $numberOfLines diff --git a/app/Validators/CustomValidators.php b/app/Validators/CustomValidators.php index 9b8cceda..bfa2f8be 100644 --- a/app/Validators/CustomValidators.php +++ b/app/Validators/CustomValidators.php @@ -8,16 +8,16 @@ namespace App\Validators; +use App\Services\InteractiveFixturesUploadService; use Illuminate\Http\UploadedFile; -use League\Csv\Reader; class CustomValidators { public function requiredHeaders($attribute, $value, $parameters, $validator) { if ($value instanceof UploadedFile) { - $csv = Reader::createFromPath($value->getRealPath()); - $headers = $csv->fetchOne(); + $handle = fopen($value->getRealPath(), 'r'); + $headers = InteractiveFixturesUploadService::readOneLine($handle); if ($parameters == array_intersect($parameters, $headers)) { return true; diff --git a/database/deployment/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql b/database/deployment/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql new file mode 100644 index 00000000..5780ed4b --- /dev/null +++ b/database/deployment/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE `upload_jobs` + ADD `row_count` INT UNSIGNED NULL; \ No newline at end of file diff --git a/database/deployment/rollbacks/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql b/database/deployment/rollbacks/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql new file mode 100644 index 00000000..027157fe --- /dev/null +++ b/database/deployment/rollbacks/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE `upload_jobs` + DROP `row_count`; \ No newline at end of file diff --git a/database/migrations/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.php b/database/migrations/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.php new file mode 100644 index 00000000..a26bd226 --- /dev/null +++ b/database/migrations/2017_01_29_160139_add_row_count_field_to_upload_jobs_table.php @@ -0,0 +1,31 @@ +unsignedInteger('row_count')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('upload_jobs', function (Blueprint $table) { + $table->dropColumn('row_count'); + }); + } +} From 64146e34af2eea8bdda6434c6e0672875cc6fbda Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Fri, 3 Feb 2017 17:46:40 +0000 Subject: [PATCH 20/62] Fixed the findBySynonim methods --- app/Models/TeamSynonym.php | 2 +- app/Models/VenueSynonym.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Models/TeamSynonym.php b/app/Models/TeamSynonym.php index 646c8237..a582875b 100644 --- a/app/Models/TeamSynonym.php +++ b/app/Models/TeamSynonym.php @@ -40,7 +40,7 @@ public static function findBySynonym($synonym) { $synonym = self::where('synonym', $synonym)->first(); if ($synonym) { - return $synonym->name; + return $synonym->team; } return null; diff --git a/app/Models/VenueSynonym.php b/app/Models/VenueSynonym.php index 7e6ac61a..dd3756da 100644 --- a/app/Models/VenueSynonym.php +++ b/app/Models/VenueSynonym.php @@ -32,7 +32,12 @@ class VenueSynonym extends Model */ public static function findBySynonym($synonym) { - return self::where('synonym', $synonym)->first()->venue; + $synonym = self::where('synonym', $synonym)->first(); + if ($synonym) { + return $synonym->venue; + } + + return null; } /** From a002db5234838aaf976851176efb45d048fb196b Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Fri, 3 Feb 2017 17:47:29 +0000 Subject: [PATCH 21/62] Refactored the resource controllers to use Request objects --- .../AvailableAppointmentsController.php | 31 +++++--- .../Admin/DataManagement/ClubsController.php | 41 +++++----- .../DataManagement/DivisionsController.php | 40 +++++----- .../DataManagement/FixturesController.php | 75 +++++-------------- .../Admin/DataManagement/RolesController.php | 35 +++++---- .../DataManagement/SeasonsController.php | 33 ++++---- .../Admin/DataManagement/TeamsController.php | 39 +++++----- .../Admin/DataManagement/VenuesController.php | 35 +++++---- ...p => StoreAvailableAppointmentRequest.php} | 17 +++-- app/Http/Requests/StoreClubRequest.php | 35 +++++++++ app/Http/Requests/StoreDivisionRequest.php | 36 +++++++++ app/Http/Requests/StoreFixtureRequest.php | 63 ++++++++++++++++ app/Http/Requests/StoreRoleRequest.php | 35 +++++++++ app/Http/Requests/StoreSeasonRequest.php | 35 +++++++++ app/Http/Requests/StoreTeamRequest.php | 36 +++++++++ app/Http/Requests/StoreVenueRequest.php | 35 +++++++++ .../UpdateAvailableAppointmentRequest.php | 47 ++++++++++++ app/Http/Requests/UpdateClubRequest.php | 35 +++++++++ app/Http/Requests/UpdateDivisionRequest.php | 36 +++++++++ app/Http/Requests/UpdateFixtureRequest.php | 59 +++++++++++++++ app/Http/Requests/UpdateRoleRequest.php | 35 +++++++++ app/Http/Requests/UpdateSeasonRequest.php | 35 +++++++++ app/Http/Requests/UpdateTeamRequest.php | 36 +++++++++ app/Http/Requests/UpdateVenueRequest.php | 35 +++++++++ 24 files changed, 755 insertions(+), 184 deletions(-) rename app/Http/Requests/{AvailableAppointmentRequest.php => StoreAvailableAppointmentRequest.php} (73%) create mode 100644 app/Http/Requests/StoreClubRequest.php create mode 100644 app/Http/Requests/StoreDivisionRequest.php create mode 100644 app/Http/Requests/StoreFixtureRequest.php create mode 100644 app/Http/Requests/StoreRoleRequest.php create mode 100644 app/Http/Requests/StoreSeasonRequest.php create mode 100644 app/Http/Requests/StoreTeamRequest.php create mode 100644 app/Http/Requests/StoreVenueRequest.php create mode 100644 app/Http/Requests/UpdateAvailableAppointmentRequest.php create mode 100644 app/Http/Requests/UpdateClubRequest.php create mode 100644 app/Http/Requests/UpdateDivisionRequest.php create mode 100644 app/Http/Requests/UpdateFixtureRequest.php create mode 100644 app/Http/Requests/UpdateRoleRequest.php create mode 100644 app/Http/Requests/UpdateSeasonRequest.php create mode 100644 app/Http/Requests/UpdateTeamRequest.php create mode 100644 app/Http/Requests/UpdateVenueRequest.php diff --git a/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php b/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php index b3f1b167..c1ba5f60 100644 --- a/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php +++ b/app/Http/Controllers/Admin/DataManagement/AvailableAppointmentsController.php @@ -2,15 +2,21 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreAvailableAppointmentRequest as StoreRequest; +use App\Http\Requests\UpdateAvailableAppointmentRequest as UpdateRequest; use App\Http\Controllers\Controller; -use App\Http\Requests\AvailableAppointmentRequest; +use Laracasts\Flash\Flash; use App\Models\AvailableAppointment; use App\Models\Fixture; use App\Models\Role; +/** + * Class AvailableAppointmentsController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class AvailableAppointmentsController extends Controller { @@ -42,14 +48,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param AvailableAppointmentRequest $request + * @param StoreRequest $request + * * @return mixed */ - public function store(AvailableAppointmentRequest $request) + public function store(StoreRequest $request) { AvailableAppointment::create($request->all()); - \Flash::success('Appointment added!'); + Flash::success('Appointment added!'); return redirect('admin/data-management/available-appointments'); } @@ -82,23 +89,25 @@ public function edit($id) $fixtures = Fixture::all(); $roles = Role::all(); - return view('admin.data-management.available-appointments.edit', compact('availableAppointment', 'fixtures', 'roles')); + return view('admin.data-management.available-appointments.edit', + compact('availableAppointment', 'fixtures', 'roles')); } /** * Update the specified resource in storage. * - * @param AvailableAppointmentRequest $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(AvailableAppointmentRequest $request, $id) + public function update(UpdateRequest $request, $id) { + /** @var AvailableAppointment $availableAppointment */ $availableAppointment = AvailableAppointment::findOrFail($id); $availableAppointment->update($request->all()); - \Flash::success('Appointment updated!'); + Flash::success('Appointment updated!'); return redirect('admin/data-management/available-appointments'); } @@ -114,7 +123,7 @@ public function destroy($id) { AvailableAppointment::destroy($id); - \Flash::success('Appointment deleted!'); + Flash::success('Appointment deleted!'); return redirect('admin/data-management/available-appointments'); } diff --git a/app/Http/Controllers/Admin/DataManagement/ClubsController.php b/app/Http/Controllers/Admin/DataManagement/ClubsController.php index 62f200b9..e7a418e9 100644 --- a/app/Http/Controllers/Admin/DataManagement/ClubsController.php +++ b/app/Http/Controllers/Admin/DataManagement/ClubsController.php @@ -2,12 +2,18 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreClubRequest as StoreRequest; +use App\Http\Requests\UpdateClubRequest as UpdateRequest; use App\Http\Controllers\Controller; +use Laracasts\Flash\Flash; use App\Models\Club; -use Illuminate\Http\Request; +/** + * Class ClubsController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class ClubsController extends Controller { @@ -36,17 +42,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param Request $request + * @param StoreRequest $request * * @return mixed */ - public function store(Request $request) + public function store(StoreRequest $request) { - $this->validate($request, ['club' => 'required|unique:clubs']); - Club::create($request->all()); - \Flash::success('Club added!'); + Flash::success('Club added!'); return redirect('admin/data-management/clubs'); } @@ -54,7 +58,7 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * * @return mixed */ @@ -68,7 +72,7 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * * @return mixed */ @@ -82,19 +86,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Request $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(Request $request, $id) + public function update(UpdateRequest $request, $id) { - $this->validate($request, ['club' => 'required|unique:clubs,club,' . $id]); - + /** @var Club $club */ $club = Club::findOrFail($id); $club->update($request->all()); - \Flash::success('Club updated!'); + Flash::success('Club updated!'); return redirect('admin/data-management/clubs'); } @@ -102,7 +105,7 @@ public function update(Request $request, $id) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * * @return mixed */ @@ -111,11 +114,11 @@ public function destroy($id) $canBeDeleted = empty(Club::find($id)->teams->toArray()); if ($canBeDeleted) { Club::destroy($id); - \Flash::success('Club deleted!'); + Flash::success('Club deleted!'); } else { - \Flash::error('Cannot delete because they are existing teams in this club.'); + Flash::error('Cannot delete because they are existing teams in this club.'); } - + return redirect('admin/data-management/clubs'); } diff --git a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php index 46ef7c0d..ca092aa0 100644 --- a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php +++ b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php @@ -2,14 +2,19 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreDivisionRequest as StoreRequest; +use App\Http\Requests\UpdateDivisionRequest as UpdateRequest; use App\Http\Controllers\Controller; +use Laracasts\Flash\Flash; use App\Models\Division; -use Illuminate\Http\Request; - use App\Models\Season; +/** + * Class DivisionsController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class DivisionsController extends Controller { /** @@ -37,20 +42,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param Request $request + * @param StoreRequest $request * * @return mixed */ - public function store(Request $request) + public function store(StoreRequest $request) { - $this->validate($request, [ - 'season_id' => 'required|exists:seasons,id', - 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $request->get('season_id'), - ]); - Division::create($request->all()); - \Flash::success('Division added!'); + Flash::success('Division added!'); return redirect('admin/data-management/divisions'); } @@ -87,22 +87,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Request $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(Request $request, $id) + public function update(UpdateRequest $request, $id) { - $this->validate($request, [ - 'season_id' => 'required|exists:seasons,id', - 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $request->get('season_id'), - ]); - + /** @var Division $division */ $division = Division::findOrFail($id); $division->update($request->all()); - \Flash::success('Division updated!'); + Flash::success('Division updated!'); return redirect('admin/data-management/divisions'); } @@ -119,9 +115,9 @@ public function destroy($id) $canBeDeleted = empty(Division::find($id)->fixtures->toArray()); if ($canBeDeleted) { Division::destroy($id); - \Flash::success('Division deleted!'); + Flash::success('Division deleted!'); } else { - \Flash::error('Cannot delete because they are existing fixtures in this division.'); + Flash::error('Cannot delete because they are existing fixtures in this division.'); } return redirect('admin/data-management/divisions'); diff --git a/app/Http/Controllers/Admin/DataManagement/FixturesController.php b/app/Http/Controllers/Admin/DataManagement/FixturesController.php index 6105d96b..97d022a0 100644 --- a/app/Http/Controllers/Admin/DataManagement/FixturesController.php +++ b/app/Http/Controllers/Admin/DataManagement/FixturesController.php @@ -2,15 +2,21 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreFixtureRequest as StoreRequest; +use App\Http\Requests\UpdateFixtureRequest as UpdateRequest; use App\Http\Controllers\Controller; +use Laracasts\Flash\Flash; use App\Models\Division; use App\Models\Fixture; use App\Models\Team; use App\Models\Venue; -use Illuminate\Http\Request; +/** + * Class FixturesController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class FixturesController extends Controller { /** @@ -42,38 +48,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param Request $request + * @param StoreRequest $request * * @return mixed */ - public function store(Request $request) + public function store(StoreRequest $request) { - $this->validate($request, - [ - 'division_id' => - 'required|' . - 'exists:divisions,id|' . - 'unique:fixtures,division_id,NULL,id' . - ',home_team_id,' . $request->get('home_team_id') . - ',away_team_id,' . $request->get('away_team_id'), - 'match_number' => 'required|unique:fixtures,match_number,NULL,id,division_id,' . $request->get('division_id'), - 'match_date' => 'required', - 'warm_up_time' => 'required', - 'start_time' => 'required', - 'home_team_id' => 'required|exists:teams,id', - 'away_team_id' => 'required|exists:teams,id|different:home_team_id', - 'venue_id' => 'required|exists:venues,id', - ], - [ - 'away_team_id.different' => 'The away team cannot be the same as the home team.', - 'division_id.unique' => 'The fixture for these two teams have already been added in this division.', - 'match_number.unique' => 'There is already a match with the same number in this division.', - ] - ); - Fixture::create($request->all()); - \Flash::success('Fixture added!'); + Flash::success('Fixture added!'); return redirect('admin/data-management/fixtures'); } @@ -112,40 +95,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Request $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(Request $request, $id) + public function update(UpdateRequest $request, $id) { - $this->validate($request, - [ - 'division_id' => - 'required|' . - 'exists:divisions,id|' . - 'unique:fixtures,division_id,NULL,id' . - ',home_team_id,' . $request->get('home_team_id') . - ',away_team_id,' . $request->get('away_team_id'), - 'match_number' => 'required|unique:fixtures,match_number,NULL,id,division_id,' . $request->get('division_id'), - 'match_date' => 'required', - 'warm_up_time' => 'required', - 'start_time' => 'required', - 'home_team_id' => 'required|exists:teams,id', - 'away_team_id' => 'required|exists:teams,id|different:home_team_id', - 'venue_id' => 'required|exists:venues,id', - ], - [ - 'away_team_id.different' => 'The away team cannot be the same as the home team.', - 'division_id.unique' => 'The fixture for these two teams have already been added in this division.', - 'match_number.unique' => 'There is already a match with the same number in this division.', - ] - ); - + /** @var Fixture $fixture */ $fixture = Fixture::findOrFail($id); $fixture->update($request->all()); - \Flash::success('Fixture updated!'); + Flash::success('Fixture updated!'); return redirect('admin/data-management/fixtures'); } @@ -162,9 +123,9 @@ public function destroy($id) $canBeDeleted = empty(Fixture::find($id)->available_appointments->toArray()); if ($canBeDeleted) { Fixture::destroy($id); - \Flash::success('Fixture deleted!'); + Flash::success('Fixture deleted!'); } else { - \Flash::error('Cannot delete because they are existing appointments for this fixture.'); + Flash::error('Cannot delete because they are existing appointments for this fixture.'); } return redirect('admin/data-management/fixtures'); } diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php index 07367c3e..162d5049 100644 --- a/app/Http/Controllers/Admin/DataManagement/RolesController.php +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -2,12 +2,18 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreRoleRequest as StoreRequest; +use App\Http\Requests\UpdateRoleRequest as UpdateRequest; use App\Http\Controllers\Controller; +use Laracasts\Flash\Flash; use App\Models\Role; -use Illuminate\Http\Request; +/** + * Class RolesController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class RolesController extends Controller { /** @@ -35,17 +41,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param Request $request + * @param StoreRequest $request * * @return mixed */ - public function store(Request $request) + public function store(StoreRequest $request) { - $this->validate($request, ['role' => 'required|unique:roles']); - Role::create($request->all()); - \Flash::success('Role added!'); + Flash::success('Role added!'); return redirect('admin/data-management/roles'); } @@ -81,19 +85,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Request $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(Request $request, $id) + public function update(UpdateRequest $request, $id) { - $this->validate($request, ['role' => 'required|unique:roles,role,' . $id]); - + /** @var Role $role */ $role = Role::findOrFail($id); $role->update($request->all()); - \Flash::success('Role updated!'); + Flash::success('Role updated!'); return redirect('admin/data-management/roles'); } @@ -110,11 +113,11 @@ public function destroy($id) $canBeDeleted = empty(Role::find($id)->available_appointments->toArray()); if ($canBeDeleted) { Role::destroy($id); - \Flash::success('Role deleted!'); + Flash::success('Role deleted!'); } else { - \Flash::error('Cannot delete because they are existing appointments for this role.'); + Flash::error('Cannot delete because they are existing appointments for this role.'); } - + return redirect('admin/data-management/roles'); } diff --git a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php index 2cfaf9a0..2a096b4f 100644 --- a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php +++ b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php @@ -2,12 +2,18 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreSeasonRequest as StoreRequest; +use App\Http\Requests\UpdateSeasonRequest as UpdateRequest; use App\Http\Controllers\Controller; +use Laracasts\Flash\Flash; use App\Models\Season; -use Illuminate\Http\Request; +/** + * Class SeasonsController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class SeasonsController extends Controller { /** @@ -35,17 +41,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param Request $request + * @param StoreRequest $request * * @return mixed */ - public function store(Request $request) + public function store(StoreRequest $request) { - $this->validate($request, ['season' => 'required|unique:seasons']); - Season::create($request->all()); - \Flash::success('Season added!'); + Flash::success('Season added!'); return redirect('admin/data-management/seasons'); } @@ -81,19 +85,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Request $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(Request $request, $id) + public function update(UpdateRequest $request, $id) { - $this->validate($request, ['season' => 'required|unique:seasons,season,' . $id]); - + /** @var Season $season */ $season = Season::findOrFail($id); $season->update($request->all()); - \Flash::success('Season updated!'); + Flash::success('Season updated!'); return redirect('admin/data-management/seasons'); } @@ -110,9 +113,9 @@ public function destroy($id) $canBeDeleted = empty(Season::find($id)->divisions->toArray()); if ($canBeDeleted) { Season::destroy($id); - \Flash::success('Season deleted!'); + Flash::success('Season deleted!'); } else { - \Flash::error('Cannot delete because they are existing divisions in this season.'); + Flash::error('Cannot delete because they are existing divisions in this season.'); } return redirect('admin/data-management/seasons'); diff --git a/app/Http/Controllers/Admin/DataManagement/TeamsController.php b/app/Http/Controllers/Admin/DataManagement/TeamsController.php index bd6fd851..f4c26b80 100644 --- a/app/Http/Controllers/Admin/DataManagement/TeamsController.php +++ b/app/Http/Controllers/Admin/DataManagement/TeamsController.php @@ -2,13 +2,19 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreTeamRequest as StoreRequest; +use App\Http\Requests\UpdateTeamRequest as UpdateRequest; use App\Http\Controllers\Controller; +use Laracasts\Flash\Flash; use App\Models\Club; use App\Models\Team; -use Illuminate\Http\Request; +/** + * Class TeamsController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class TeamsController extends Controller { /** @@ -36,20 +42,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param Request $request + * @param StoreRequest $request * * @return mixed */ - public function store(Request $request) + public function store(StoreRequest $request) { - $this->validate($request, [ - 'club_id' => 'required|exists:clubs,id', - 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $request->get('club_id'), - ]); - Team::create($request->all()); - \Flash::success('Team added!'); + Flash::success('Team added!'); return redirect('admin/data-management/teams'); } @@ -86,22 +87,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Request $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(Request $request, $id) + public function update(UpdateRequest $request, $id) { - $this->validate($request, [ - 'club_id' => 'required|exists:clubs,id', - 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $request->get('club_id'), - ]); - + /** @var Team $team */ $team = Team::findOrFail($id); $team->update($request->all()); - \Flash::success('Team updated!'); + Flash::success('Team updated!'); return redirect('admin/data-management/teams'); } @@ -119,9 +116,9 @@ public function destroy($id) $canBeDeleted = empty($team->homeFixtures->toArray()) && empty($team->awayFixtures->toArray()); if ($canBeDeleted) { Team::destroy($id); - \Flash::success('Team deleted!'); + Flash::success('Team deleted!'); } else { - \Flash::error('Cannot delete because they are existing fixtures for this team.'); + Flash::error('Cannot delete because they are existing fixtures for this team.'); } return redirect('admin/data-management/teams'); diff --git a/app/Http/Controllers/Admin/DataManagement/VenuesController.php b/app/Http/Controllers/Admin/DataManagement/VenuesController.php index e8a96d29..638217d5 100644 --- a/app/Http/Controllers/Admin/DataManagement/VenuesController.php +++ b/app/Http/Controllers/Admin/DataManagement/VenuesController.php @@ -2,12 +2,18 @@ namespace App\Http\Controllers\Admin\DataManagement; -use App\Http\Requests; +use App\Http\Requests\StoreVenueRequest as StoreRequest; +use App\Http\Requests\UpdateVenueRequest as UpdateRequest; use App\Http\Controllers\Controller; +use Laracasts\Flash\Flash; use App\Models\Venue; -use Illuminate\Http\Request; +/** + * Class VenuesController + * + * @package App\Http\Controllers\Admin\DataManagement + */ class VenuesController extends Controller { /** @@ -35,17 +41,15 @@ public function create() /** * Store a newly created resource in storage. * - * @param Request $request + * @param StoreRequest $request * * @return mixed */ - public function store(Request $request) + public function store(StoreRequest $request) { - $this->validate($request, ['venue' => 'required|unique:venues']); - Venue::create($request->all()); - \Flash::success('Venue added!'); + Flash::success('Venue added!'); return redirect('admin/data-management/venues'); } @@ -81,19 +85,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param Request $request - * @param int $id + * @param UpdateRequest $request + * @param int $id * * @return mixed */ - public function update(Request $request, $id) + public function update(UpdateRequest $request, $id) { - $this->validate($request, ['venue' => 'required|unique:venues,venue,' . $id]); - + /** @var Venue $venue */ $venue = Venue::findOrFail($id); $venue->update($request->all()); - \Flash::success('Venue updated!'); + Flash::success('Venue updated!'); return redirect('admin/data-management/venues'); } @@ -110,11 +113,11 @@ public function destroy($id) $canBeDeleted = empty(Venue::find($id)->fixtures->toArray()); if ($canBeDeleted) { Venue::destroy($id); - \Flash::success('Venue deleted!'); + Flash::success('Venue deleted!'); } else { - \Flash::error('Cannot delete because they are existing fixtures at this venue.'); + Flash::error('Cannot delete because they are existing fixtures at this venue.'); } - + return redirect('admin/data-management/venues'); } diff --git a/app/Http/Requests/AvailableAppointmentRequest.php b/app/Http/Requests/StoreAvailableAppointmentRequest.php similarity index 73% rename from app/Http/Requests/AvailableAppointmentRequest.php rename to app/Http/Requests/StoreAvailableAppointmentRequest.php index 4503bebe..5f84f0a5 100644 --- a/app/Http/Requests/AvailableAppointmentRequest.php +++ b/app/Http/Requests/StoreAvailableAppointmentRequest.php @@ -2,10 +2,15 @@ namespace App\Http\Requests; -use App\Http\Requests\Request; +use Illuminate\Support\Facades\Auth; use Illuminate\Contracts\Validation\Validator; -class AvailableAppointmentRequest extends Request +/** + * Class StoreAvailableAppointmentRequest + * + * @package App\Http\Requests + */ +class StoreAvailableAppointmentRequest extends Request { /** * Determine if the user is authorized to make this request. @@ -14,7 +19,7 @@ class AvailableAppointmentRequest extends Request */ public function authorize() { - return true; + return Auth::check(); } /** @@ -36,9 +41,7 @@ public function rules() protected function formatErrors(Validator $validator) { return [[ - 'Appointment already added.', - ]]; + 'Appointment already added.', + ]]; } - - } diff --git a/app/Http/Requests/StoreClubRequest.php b/app/Http/Requests/StoreClubRequest.php new file mode 100644 index 00000000..d5a3b7a9 --- /dev/null +++ b/app/Http/Requests/StoreClubRequest.php @@ -0,0 +1,35 @@ + 'required|unique:clubs', + ]; + } +} diff --git a/app/Http/Requests/StoreDivisionRequest.php b/app/Http/Requests/StoreDivisionRequest.php new file mode 100644 index 00000000..e515bf33 --- /dev/null +++ b/app/Http/Requests/StoreDivisionRequest.php @@ -0,0 +1,36 @@ + 'required|exists:seasons,id', + 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $this->input('season_id'), + ]; + } +} diff --git a/app/Http/Requests/StoreFixtureRequest.php b/app/Http/Requests/StoreFixtureRequest.php new file mode 100644 index 00000000..98e47402 --- /dev/null +++ b/app/Http/Requests/StoreFixtureRequest.php @@ -0,0 +1,63 @@ + + 'required|' . + 'exists:divisions,id|' . + 'unique:fixtures,division_id,NULL,id' . + ',home_team_id,' . $this->input('home_team_id') . + ',away_team_id,' . $this->input('away_team_id'), + 'match_number' => + 'required|' . + 'unique:fixtures,match_number,NULL,id,division_id,' . $this->input('division_id'), + 'match_date' => 'required', + 'warm_up_time' => 'required', + 'start_time' => 'required', + 'home_team_id' => 'required|exists:teams,id', + 'away_team_id' => 'required|exists:teams,id|different:home_team_id', + 'venue_id' => 'required|exists:venues,id', + ]; + } + + /** + * @return array + */ + public function messages() + { + return [ + 'away_team_id.different' => 'The away team cannot be the same as the home team.', + 'division_id.unique' => 'The fixture for these two teams have already been added in this division.', + 'match_number.unique' => 'There is already a match with the same number in this division.', + ]; + } + + +} diff --git a/app/Http/Requests/StoreRoleRequest.php b/app/Http/Requests/StoreRoleRequest.php new file mode 100644 index 00000000..8919f72d --- /dev/null +++ b/app/Http/Requests/StoreRoleRequest.php @@ -0,0 +1,35 @@ + 'required|unique:roles' + ]; + } +} diff --git a/app/Http/Requests/StoreSeasonRequest.php b/app/Http/Requests/StoreSeasonRequest.php new file mode 100644 index 00000000..e15817f6 --- /dev/null +++ b/app/Http/Requests/StoreSeasonRequest.php @@ -0,0 +1,35 @@ + 'required|unique:seasons' + ]; + } +} diff --git a/app/Http/Requests/StoreTeamRequest.php b/app/Http/Requests/StoreTeamRequest.php new file mode 100644 index 00000000..1f5d4ccf --- /dev/null +++ b/app/Http/Requests/StoreTeamRequest.php @@ -0,0 +1,36 @@ + 'required|exists:clubs,id', + 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $this->input('club_id'), + ]; + } +} diff --git a/app/Http/Requests/StoreVenueRequest.php b/app/Http/Requests/StoreVenueRequest.php new file mode 100644 index 00000000..ebadf8c7 --- /dev/null +++ b/app/Http/Requests/StoreVenueRequest.php @@ -0,0 +1,35 @@ + 'required|unique:venues', + ]; + } +} diff --git a/app/Http/Requests/UpdateAvailableAppointmentRequest.php b/app/Http/Requests/UpdateAvailableAppointmentRequest.php new file mode 100644 index 00000000..966773be --- /dev/null +++ b/app/Http/Requests/UpdateAvailableAppointmentRequest.php @@ -0,0 +1,47 @@ + 'unique:available_appointments,fixture_id,NULL,id,role_id,' . $this->input('role_id'), + 'role_id' => 'unique:available_appointments,role_id,NULL,id,fixture_id,' . $this->input('fixture_id'), + ]; + } + + /** + * {@inheritdoc} + */ + protected function formatErrors(Validator $validator) + { + return [[ + 'Appointment already added.', + ]]; + } +} diff --git a/app/Http/Requests/UpdateClubRequest.php b/app/Http/Requests/UpdateClubRequest.php new file mode 100644 index 00000000..40e2f389 --- /dev/null +++ b/app/Http/Requests/UpdateClubRequest.php @@ -0,0 +1,35 @@ + 'required|unique:clubs,club,' . $this->input('id') + ]; + } +} diff --git a/app/Http/Requests/UpdateDivisionRequest.php b/app/Http/Requests/UpdateDivisionRequest.php new file mode 100644 index 00000000..1ff167ad --- /dev/null +++ b/app/Http/Requests/UpdateDivisionRequest.php @@ -0,0 +1,36 @@ + 'required|exists:seasons,id', + 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $this->input('season_id'), + ]; + } +} diff --git a/app/Http/Requests/UpdateFixtureRequest.php b/app/Http/Requests/UpdateFixtureRequest.php new file mode 100644 index 00000000..308ad8ff --- /dev/null +++ b/app/Http/Requests/UpdateFixtureRequest.php @@ -0,0 +1,59 @@ + + 'required|' . + 'exists:divisions,id|' . + 'unique:fixtures,division_id,NULL,id' . + ',home_team_id,' . $this->input('home_team_id') . + ',away_team_id,' . $this->input('away_team_id'), + 'match_number' => 'required|unique:fixtures,match_number,NULL,id,division_id,' . $this->input('division_id'), + 'match_date' => 'required', + 'warm_up_time' => 'required', + 'start_time' => 'required', + 'home_team_id' => 'required|exists:teams,id', + 'away_team_id' => 'required|exists:teams,id|different:home_team_id', + 'venue_id' => 'required|exists:venues,id', + ]; + } + + /** + * @return array + */ + public function messages() + { + return [ + 'away_team_id.different' => 'The away team cannot be the same as the home team.', + 'division_id.unique' => 'The fixture for these two teams have already been added in this division.', + 'match_number.unique' => 'There is already a match with the same number in this division.', + ]; + } +} diff --git a/app/Http/Requests/UpdateRoleRequest.php b/app/Http/Requests/UpdateRoleRequest.php new file mode 100644 index 00000000..fb4be1a4 --- /dev/null +++ b/app/Http/Requests/UpdateRoleRequest.php @@ -0,0 +1,35 @@ + 'required|unique:roles,role,' . $this->input('id'), + ]; + } +} diff --git a/app/Http/Requests/UpdateSeasonRequest.php b/app/Http/Requests/UpdateSeasonRequest.php new file mode 100644 index 00000000..d33e0441 --- /dev/null +++ b/app/Http/Requests/UpdateSeasonRequest.php @@ -0,0 +1,35 @@ + 'required|unique:seasons,season,' . $this->input('id') + ]; + } +} diff --git a/app/Http/Requests/UpdateTeamRequest.php b/app/Http/Requests/UpdateTeamRequest.php new file mode 100644 index 00000000..b5189950 --- /dev/null +++ b/app/Http/Requests/UpdateTeamRequest.php @@ -0,0 +1,36 @@ + 'required|exists:clubs,id', + 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $this->input('club_id') + ]; + } +} diff --git a/app/Http/Requests/UpdateVenueRequest.php b/app/Http/Requests/UpdateVenueRequest.php new file mode 100644 index 00000000..2a1358c1 --- /dev/null +++ b/app/Http/Requests/UpdateVenueRequest.php @@ -0,0 +1,35 @@ + 'required|unique:venues,venue,' . $this->input('id') + ]; + } +} From e170fe2cc3108048f2b6251726484185d1ee416d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 4 Feb 2017 22:31:34 +0000 Subject: [PATCH 22/62] dev: run Travis on dev branch only --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1dbbe11c..c44b0e04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +branches: + only: + - dev language: php php: - 5.6.30 From c137e7865be27a307160743f4c0a6c35ea9da921 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 4 Feb 2017 22:33:36 +0000 Subject: [PATCH 23/62] dev: added master and lva-22 branches to Travis builds --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index c44b0e04..26a12e94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ branches: only: + - master - dev + - lva-22-interactive-loading language: php php: - 5.6.30 From b5d130c74cd45f61e0357fceba2bca779de6d636 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 5 Feb 2017 17:58:05 +0000 Subject: [PATCH 24/62] lva-22: more work on the validating process --- app/Console/Commands/LoadFixtures.php | 58 --- app/Console/Kernel.php | 1 - .../Admin/DataManagement/LoadController.php | 8 +- .../Api/v1/UploadApiController.php | 51 +- app/Http/routes.php | 1 - app/Models/Division.php | 10 + app/Models/NewTeams.php | 49 -- app/Models/UploadJob.php | 33 -- app/Models/UploadJobData.php | 11 + app/Models/UploadJobStatus.php | 447 ++++++++++++++++++ .../Contracts/InteractiveUploadContract.php | 2 +- app/Services/Contracts/StatusContract.php | 20 - .../InteractiveFixturesUploadService.php | 132 ++++-- app/Services/StatusService.php | 193 ++++++-- app/Services/UploadDataService.php | 31 ++ ..._11_20_124340_create_new_venues_table.sql} | 17 - ..._11_20_124340_create_new_venues_table.sql} | 3 - ..._11_20_124340_create_new_venues_table.php} | 21 +- .../assets/js/load-fixtures-status-update.js | 36 +- .../_partial/load-fixture-modal.blade.php | 2 +- 20 files changed, 780 insertions(+), 346 deletions(-) delete mode 100644 app/Console/Commands/LoadFixtures.php delete mode 100644 app/Models/NewTeams.php create mode 100644 app/Models/UploadJobStatus.php delete mode 100644 app/Services/Contracts/StatusContract.php create mode 100644 app/Services/UploadDataService.php rename database/deployment/{2016_11_20_124340_create_new_venues_and_teams_tables.sql => 2016_11_20_124340_create_new_venues_table.sql} (50%) rename database/deployment/rollbacks/{2016_11_20_124340_create_new_venues_and_teams_tables.sql => 2016_11_20_124340_create_new_venues_table.sql} (50%) rename database/migrations/{2016_11_20_124340_create_new_venues_and_teams_tables.php => 2016_11_20_124340_create_new_venues_table.php} (58%) diff --git a/app/Console/Commands/LoadFixtures.php b/app/Console/Commands/LoadFixtures.php deleted file mode 100644 index 70f9f98f..00000000 --- a/app/Console/Commands/LoadFixtures.php +++ /dev/null @@ -1,58 +0,0 @@ -service = $service; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - $jobId = $this->argument('job'); - - $job = UploadJob::findOrFail($jobId); - - $this->service->processJob($job); - - // Get the status and find out last stage of the process - - // Skip already processed stages - - // Run current and all next stages - } -} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 0ede67e0..5497b0b5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -14,7 +14,6 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ - LoadFixtures::class, ]; /** diff --git a/app/Http/Controllers/Admin/DataManagement/LoadController.php b/app/Http/Controllers/Admin/DataManagement/LoadController.php index 85a7ff58..16dc22ff 100644 --- a/app/Http/Controllers/Admin/DataManagement/LoadController.php +++ b/app/Http/Controllers/Admin/DataManagement/LoadController.php @@ -41,17 +41,17 @@ public function startUploadFixtures(Request $request) { $this->validate($request, [ 'season_id' => 'required|exists:seasons,id', - 'upload_file' => 'required|file|required_headers:Region,Code,Match,Home,Away,WUTime,StartTime,Discipline,Hall', + 'upload_file' => 'required|file|required_headers:Region,Code,Match,Home,Away,Date,WUTime,StartTime,Discipline,Hall', ]); // Create upload job - $jobId = $this->uploadService->createJob($request->file('upload_file')); + $job = $this->uploadService->createJob($request->file('upload_file')); // Start the uploading - Artisan::call('lva:load:fixtures', ['job' => $jobId]); + $this->uploadService->processJob($job); // Redirect to the status page - return Redirect::route('uploadStatus', ['job_id' => $jobId]); + return Redirect::route('uploadStatus', ['job_id' => $job->getId()]); } public function uploadStatus(UploadJob $uploadJob) diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 1e816d0e..64c4dd39 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -10,10 +10,24 @@ use App\Http\Controllers\Controller; use App\Models\UploadJob; +use App\Models\UploadJobStatus; +use App\Services\StatusService; use Illuminate\Support\Facades\Input; class UploadApiController extends Controller { + /** @var StatusService */ + private $statusService; + + /** + * @inheritDoc + */ + public function __construct(StatusService $statusService) + { + $this->statusService = $statusService; + } + + public function getUploadStatus() { $uploadJob = $this->checkForJob(); @@ -21,10 +35,13 @@ public function getUploadStatus() return response()->json($uploadJob); } - $status = UploadJob::STATUS_UNKNOWN_DATA; - $uploadJob->setStatus([ - 'StatusCode' => $status, - 'StatusMessage' => UploadJob::getStatusMessage($status), + $status = new UploadJobStatus(); + $status->load([ + 'status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA, + ]); + $f = [ + 'StatusCode' => $status->getStatusCode(), + 'StatusMessage' => $status->getStatusCodeMessage(), 'Progress' => rand(10, 99), 'Fixture' => [ 'Division' => 'M1A', @@ -45,7 +62,6 @@ public function getUploadStatus() ['value' => 2, 'text' => 'k.s. Osemka Men 2'], ], 'ApiUrls' => [ - 'Add' => '/api/v1/teams', 'Map' => '/api/v1/maps/team', ], ], @@ -57,7 +73,6 @@ public function getUploadStatus() ['value' => 2, 'text' => 'k.s. Osemka Men 2'], ], 'ApiUrls' => [ - 'Add' => '/api/v1/teams', 'Map' => '/api/v1/maps/team', ], ], @@ -73,25 +88,13 @@ public function getUploadStatus() ], ], - ]); + ]; return response()->json([ 'Timestamp' => time(), 'Error' => false, 'Message' => 'Job found', - 'Status' => $uploadJob->getStatus(), - ]); - } - - public function addTeam() - { - $uploadJob = $this->checkForJob(); - if (!$uploadJob instanceof UploadJob) { - return response($uploadJob); - } - - return response()->json([ - 'success' => true, + 'Status' => $f, ]); } @@ -102,8 +105,10 @@ public function mapTeam() return response($uploadJob); } + // @todo implement mapping a team + return response()->json([ - 'success' => false, + 'success' => true, ]); } @@ -114,6 +119,8 @@ public function addVenue() return response($uploadJob); } + // @todo implement adding a venue + return response()->json([ 'success' => true, ]); @@ -126,6 +133,8 @@ public function mapVenue() return response($uploadJob); } + // @todo implemenr mapping a venue + return response()->json([ 'success' => false, ]); diff --git a/app/Http/routes.php b/app/Http/routes.php index 695e4be3..6f86c63c 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -25,7 +25,6 @@ */ Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api', 'namespace' => 'Api\v1'], function () { Route::get('uploads/status.json', ['uses' => 'UploadApiController@getUploadStatus']); - Route::post('teams', ['as' => 'loading-add-team', 'uses' => 'UploadApiController@addTeam']); Route::post('maps/team', ['as' => 'loading-map-team', 'uses' => 'UploadApiController@mapTeam']); Route::post('venues', ['as' => 'loading-add-venue', 'uses' => 'UploadApiController@addVenue']); Route::post('maps/venue', ['as' => 'loading-map-venue', 'uses' => 'UploadApiController@mapVenue']); diff --git a/app/Models/Division.php b/app/Models/Division.php index db88ed42..c778c0b1 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -26,6 +26,16 @@ class Division extends Model */ protected $fillable = ['season_id', 'division']; + /** + * @param string $division + * + * @return Division|null + */ + public static function findByName($division) + { + return self::where('division', $division)->first(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/NewTeams.php b/app/Models/NewTeams.php deleted file mode 100644 index b8045783..00000000 --- a/app/Models/NewTeams.php +++ /dev/null @@ -1,49 +0,0 @@ - - * Date: 20/11/2016 - * Time: 16:07 - */ - -namespace App\Models; - -use Illuminate\Database\Eloquent\Model; - -/** - * Class NewTeams - * - * @package App\Models - */ -class NewTeams extends Model -{ - /** - * The database table used by the model. - * - * @var string - */ - protected $table = 'new_teams'; - - /** - * Attributes that should be mass-assignable. - * - * @var array - */ - protected $fillable = ['upload_job_id', 'team', 'team_id']; - - /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function uploadJob() - { - return $this->hasOne(UploadJob::class); - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } -} \ No newline at end of file diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index 3ea973e3..6bb7372a 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -13,34 +13,9 @@ class UploadJob extends Model { const TYPE_FIXTURES = 'fixtures'; - const STATUS_NOT_STARTED = 0; - const STATUS_VALIDATING_RECORDS = 1; - const STATUS_INSERTING_RECORDS = 2; - const STATUS_UNKNOWN_DATA = 11; - const STATUS_UNKNOWN_VENUE = 12; - const STATUS_DONE = 99; - protected $table = 'upload_jobs'; protected $fillable = ['file', 'row_count', 'type', 'status']; - public static function getStatusMessage($statusCode) - { - switch ($statusCode) { - case self::STATUS_NOT_STARTED: - return 'Not started'; - case self::STATUS_VALIDATING_RECORDS: - return 'Validating records'; - case self::STATUS_INSERTING_RECORDS: - return 'Inserting records'; - case self::STATUS_UNKNOWN_DATA: - return 'Unknown data'; - case self::STATUS_DONE: - return 'Done'; - default: - return "Status code $statusCode not recognised"; - } - } - /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -57,14 +32,6 @@ public function mappedVenues() return $this->hasMany(MappedVenue::class); } - /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function newTeams() - { - return $this->hasMany(NewTeams::class); - } - /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/UploadJobData.php b/app/Models/UploadJobData.php index 089738c3..b888243c 100644 --- a/app/Models/UploadJobData.php +++ b/app/Models/UploadJobData.php @@ -8,6 +8,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; /** @@ -31,6 +32,16 @@ class UploadJobData extends Model */ protected $fillable = ['upload_job_id', 'model', 'model_data']; + /** + * @param $jobId + * + * @return Collection + */ + public static function findByJobId($jobId) + { + return self::where('upload_job_id', $jobId)->get(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php new file mode 100644 index 00000000..09f6c5b6 --- /dev/null +++ b/app/Models/UploadJobStatus.php @@ -0,0 +1,447 @@ + + * Date: 05/02/2017 + * Time: 12:13 + */ + +namespace App\Models; + + +/** + * Class UploadJobStatus + * + * NOTE: This model does not extend the Eloquent Model class because it is not + * to be store in the DB. It's just a convenient way to encapsulate all + * the data and functionality needed for the status + * + * @package App\Models + */ +class UploadJobStatus +{ + const STATUS_VALIDATING_RECORDS = 1; + const STATUS_INSERTING_RECORDS = 2; + const STATUS_NOT_STARTED = 0; + const STATUS_UNKNOWN_DATA = 10; + const STATUS_DONE = 99; + + const UNKNOWN_HOME_TEAM = 1; + const UNKNOWN_AWAY_TEAM = 2; + const UNKNOWN_VENUE = 3; + + private $status_code; + private $total_lines; + private $processed_lines; + private $total_rows; + private $processed_rows; + private $processing_line; + private $unknowns; + + /** + * @inheritDoc + */ + public function __construct() + { + $this->status_code = self::STATUS_NOT_STARTED; + $this->total_lines = 0; + $this->processed_lines = 0; + $this->total_rows = 0; + $this->processed_rows = 0; + $this->processing_line = []; + $this->unknowns = null; + } + + /** + * @return string + */ + public function getStatusCodeMessage() + { + switch ($this->status_code) { + case self::STATUS_NOT_STARTED: + return 'Not started'; + case self::STATUS_VALIDATING_RECORDS: + return 'Validating records'; + case self::STATUS_INSERTING_RECORDS: + return 'Inserting records'; + case self::STATUS_UNKNOWN_DATA: + return 'Unknown data'; + case self::STATUS_DONE: + return 'Done'; + default: + return "Status code {$this->status_code} not recognised"; + } + } + + /** + * @param array $data + * + * @return UploadJobStatus + */ + public function load(array $data) + { + $this->status_code = $data['status_code']; + + if (array_has($data, 'total_lines')) { + $this->total_lines = $data['total_lines']; + } + if (array_has($data, 'processed_lines')) { + $this->processed_lines = $data['processed_lines']; + } + if (array_has($data, 'total_rows')) { + $this->total_rows = $data['total_rows']; + } + if (array_has($data, 'processed_rows')) { + $this->processed_rows = $data['processed_rows']; + } + + return $this; + } + + /** + * @return array + */ + public function toArray() + { + return [ + 'status_code' => $this->status_code, + 'total_lines' => $this->total_lines, + 'processed_lines' => $this->processed_lines, + 'total_rows' => $this->total_rows, + 'processed_rows' => $this->processed_rows, + ]; + } + + /** + * @return bool + */ + public function isNotStarted() + { + return $this->status_code === self::STATUS_NOT_STARTED; + } + + /** + * @return bool + */ + public function isValidating() + { + return $this->status_code === self::STATUS_VALIDATING_RECORDS; + } + + /** + * @return bool + */ + public function isInserting() + { + return $this->status_code === self::STATUS_INSERTING_RECORDS; + } + + /** + * @return bool + */ + public function isDone() + { + return $this->status_code === self::STATUS_DONE; + } + + /** + * @return array + */ + public function getUnknowns() + { + if (empty($this->unknowns)) { + return []; + } + + return $this->unknowns; + } + + /** + * @param int $unknownType + * @param array $mappings + */ + public function setUnknown($unknownType, $mappings) + { + $this->unknowns[$unknownType] = $mappings; + } + + /** + * @return int + */ + public function getStatusCode() + { + return $this->status_code; + } + + /** + * @return int + */ + public function getTotalLines() + { + return $this->total_lines; + } + + /** + * @param int $total_lines + * + * @return UploadJobStatus + */ + public function setTotalLines($total_lines) + { + $this->total_lines = $total_lines; + + return $this; + } + + /** + * @return int + */ + public function getProcessedLines() + { + return $this->processed_lines; + } + + /** + * @param int $processed_lines + * + * @return UploadJobStatus + */ + public function setProcessedLines($processed_lines) + { + $this->processed_lines = $processed_lines; + + return $this; + } + + /** + * @return int + */ + public function getTotalRows() + { + return $this->total_rows; + } + + /** + * @param int $total_rows + * + * @return UploadJobStatus + */ + public function setTotalRows($total_rows) + { + $this->total_rows = $total_rows; + + return $this; + } + + /** + * @return int + */ + public function getProcessedRows() + { + return $this->processed_rows; + } + + /** + * @param int $processed_rows + * + * @return UploadJobStatus + */ + public function setProcessedRows($processed_rows) + { + $this->processed_rows = $processed_rows; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineDivision() + { + return $this->processing_line['division']; + + } + + /** + * @param string $division + * + * @return UploadJobStatus + */ + public function setProcessingLineDivision($division) + { + $this->processing_line['division'] = $division; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineMatchNumber() + { + return $this->processing_line['match_number']; + + } + + /** + * @param string $matchNumber + * + * @return UploadJobStatus + */ + public function setProcessingLineMatchNumber($matchNumber) + { + $this->processing_line['match_number'] = $matchNumber; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineHomeTeam() + { + return $this->processing_line['home_team']; + + } + + /** + * @param string $team + * + * @return UploadJobStatus + */ + public function setProcessingLineHomeTeam($team) + { + $this->processing_line['home_team'] = $team; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineAwayTeam() + { + return $this->processing_line['away_team']; + + } + + /** + * @param string $team + * + * @return UploadJobStatus + */ + public function setProcessingLineAwayTeam($team) + { + $this->processing_line['away_team'] = $team; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineDate() + { + return $this->processing_line['date']; + + } + + /** + * @param string $date + * + * @return UploadJobStatus + */ + public function setProcessingLineDate($date) + { + $this->processing_line['date'] = $date; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineWarmUpTime() + { + return $this->processing_line['warm_up_time']; + + } + + /** + * @param string $time + * + * @return UploadJobStatus + */ + public function setProcessingLineWarmUpTime($time) + { + $this->processing_line['warm_up_time'] = $time; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineStartTime() + { + return $this->processing_line['start_time']; + + } + + /** + * @param string $time + * + * @return UploadJobStatus + */ + public function setProcessingLineStartTime($time) + { + $this->processing_line['start_time'] = $time; + + return $this; + } + + /** + * @return string + */ + public function getProcessingLineVenue() + { + return $this->processing_line['venue']; + + } + + /** + * @param string $venue + * + * @return UploadJobStatus + */ + public function setProcessingLineVenue($venue) + { + $this->processing_line['venue'] = $venue; + + return $this; + } + + /** + * @return UploadJobStatus + */ + public function moveForward() + { + switch ($this->status_code) { + case self::STATUS_NOT_STARTED: + $this->status_code = self::STATUS_VALIDATING_RECORDS; + break; + case self::STATUS_VALIDATING_RECORDS: + $this->status_code = self::STATUS_INSERTING_RECORDS; + break; + case self::STATUS_INSERTING_RECORDS: + $this->status_code = self::STATUS_DONE; + break; + case self::STATUS_DONE: + break; + default: + throw new \RuntimeException("Invalid status code {$this->status_code}."); + } + + return $this; + } +} \ No newline at end of file diff --git a/app/Services/Contracts/InteractiveUploadContract.php b/app/Services/Contracts/InteractiveUploadContract.php index 239fc272..371b119e 100644 --- a/app/Services/Contracts/InteractiveUploadContract.php +++ b/app/Services/Contracts/InteractiveUploadContract.php @@ -16,7 +16,7 @@ interface InteractiveUploadContract /** * @param UploadedFile $file * - * @return int + * @return mixed */ public function createJob(UploadedFile $file); diff --git a/app/Services/Contracts/StatusContract.php b/app/Services/Contracts/StatusContract.php deleted file mode 100644 index 5d8cf984..00000000 --- a/app/Services/Contracts/StatusContract.php +++ /dev/null @@ -1,20 +0,0 @@ - - * Date: 21/01/2017 - * Time: 15:02 - */ - -namespace App\Services\Contracts; - -interface StatusContract -{ - public function getNextStepStatus($status); - - public function getStatusCode($status); - - public function getStatusProcessedLines($status); - - public function setStatusProcessedLines(&$status, $lines); -} \ No newline at end of file diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index 3961c336..e2f8aeff 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -13,6 +13,7 @@ use App\Models\Team; use App\Models\TeamSynonym; use App\Models\UploadJobData; +use App\Models\UploadJobStatus; use App\Models\Venue; use App\Models\VenueSynonym; use App\Services\Contracts\InteractiveUploadContract; @@ -28,22 +29,25 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract /** @var StatusService */ private $statusService; + private $uploadDataService; /** @var Collection */ private $mappedTeams; /** @var Collection */ private $mappedVenues; /** @var Collection */ - private $newTeams; - /** @var Collection */ private $newVenues; /** * @inheritDoc */ - public function __construct(StatusService $statusService) + public function __construct( + StatusService $statusService, + UploadDataService $uploadDataService + ) { $this->statusService = $statusService; + $this->uploadDataService = $uploadDataService; } @@ -82,10 +86,10 @@ public function createJob(UploadedFile $file) $job->setFile($fixtureFile->getFilename()) ->setType(UploadJob::TYPE_FIXTURES) ->setRowCount($lines - 1)// Don't count the first line as they are the headers - ->setStatus(['status_code' => UploadJob::STATUS_NOT_STARTED]) + ->setStatus($this->statusService->getInitialStatus()->toArray()) ->save(); - return $job->getId(); + return $job; } /******************* @@ -99,58 +103,91 @@ public function processJob(UploadJob $job) { $this->mappedTeams = $job->mappedTeams; $this->mappedVenues = $job->mappedVenues; - $this->newTeams = $job->newTeams; $this->newVenues = $job->newVenues; - $status = $job->getStatus(); - - $statusCode = $this->statusService->getStatusCode($status); + /** @var UploadJobStatus $status */ + $status = $this->statusService->loadStatus($job->getStatus()); - if ($statusCode == UploadJob::STATUS_NOT_STARTED) { - - $status = $this->statusService->getNextStepStatus($status); - $statusCode = $this->statusService->getStatusCode($status); - $job->setStatus($status)->save(); + if ($status->isNotStarted()) { + $status->moveForward()->setTotalLines($job->getRowCount()); + $job->setStatus($status->toArray())->save(); } - if ($statusCode == UploadJob::STATUS_VALIDATING_RECORDS) { - $processedLines = $this->statusService->getStatusProcessedLines($status); + if ($status->isValidating()) { + $processedLines = $status->getProcessedLines(); /** @var resource $csvFile */ $csvFile = fopen(storage_path() . self::UPLOAD_DIR . $job->getFile(), 'r'); + // Get the headers $headers = self::readOneLine($csvFile); + // Skip already processed lines $this->getIntoPosition($csvFile, $processedLines); + // Start processing $allRowsProcessed = true; while (!feof($csvFile)) { $row = array_combine($headers, self::readOneLine($csvFile)); - if (!$this->isValidRow($row)) { - // @todo Prepare for asking the user what to do + + // Store the current line + $this->statusService->setProcessingLine($status, + $row['Code'], + $row['Match'], + $row['Home'], + $row['Away'], + Carbon::createFromFormat('d/m/Y', $row['Date']), + Carbon::createFromFormat('H:i:s', $row['WUTime']), + Carbon::createFromFormat('H:i:s', $row['StartTime']), + $row['Hall'] + ); + + // Start validation + $isValid = true; + if (!$this->isValidTeam($row['Home'])) { + $allRowsProcessed = false; + $isValid = false; + $this->statusService->setUnknownHomeTeam($status); + } + if (!$this->isValidTeam($row['Away'])) { + $allRowsProcessed = false; + $isValid = false; + $this->statusService->setUnknownHomeTeam($status); + } + if (!$this->isValidVenue($row['Hall'])) { $allRowsProcessed = false; + $isValid = false; + $this->statusService->setUnknownVenue($status); + } + + // Is something is not valid stop the process + if (!$isValid) { break; } + + // Everything is ok, so store the fixture to be inserted later $this->insertFixture($job->getId(), $row); - $processedLines++; - $this->statusService->setStatusProcessedLines($status, $processedLines); - $job->setStatus($status)->save(); + // Update the line counter + $status->setProcessedLines(++$processedLines); + $job->setStatus($status->toArray())->save(); } fclose($csvFile); + // If we exited the loop because we have processed all line then advance to next stage if ($allRowsProcessed) { - $status = $this->statusService->getNextStepStatus($status); - $statusCode = $this->statusService->getStatusCode($status); - $job->setStatus($status)->save(); + $status->moveForward()->setTotalRows(UploadJobData::findByJobId($job->getId())->count()); } + + // Whether we stop because of an error or because we're finished validating, save the status + $job->setStatus($status->toArray())->save(); } - if ($statusCode == UploadJob::STATUS_INSERTING_RECORDS) { + if ($status->isInserting()) { // @todo insert into DB } - if ($statusCode == UploadJob::STATUS_DONE) { + if ($status->isDone()) { // @todo Clean up } } @@ -169,32 +206,19 @@ private function getIntoPosition($file, $numberOfLines) } /** - * @param array $row + * @param string $team * * @return bool */ - private function isValidRow($row) - { - $isValid = true; - - $isValid = $isValid && $this->isValidTeam($row['Home']); - $isValid = $isValid && $this->isValidTeam($row['Away']); - - $isValid = $isValid && $this->isValidVenue($row['Hall']); - - return $isValid; - } - private function isValidTeam($team) { + /** @var Team $model */ $model = Team::findByName($team); if (is_null($model)) { $model = TeamSynonym::findBySynonym($team); } if (is_null($model)) { - if (!in_array($team, $this->mappedTeams->pluck('team')->all()) && - !in_array($team, $this->newTeams->pluck('team')->all()) - ) { + if (!in_array($team, $this->mappedTeams->pluck('team')->all())) { return false; } } @@ -202,8 +226,14 @@ private function isValidTeam($team) return true; } + /** + * @param string $venue + * + * @return bool + */ private function isValidVenue($venue) { + /** @var Venue $model */ $model = Venue::findByName($venue); if (is_null($model)) { $model = VenueSynonym::findBySynonym($venue); @@ -219,27 +249,25 @@ private function isValidVenue($venue) return true; } + /** + * @param int $jobId + * @param array $data + */ private function insertFixture($jobId, $data) { - + /** @var Fixture $fixture */ $fixture = new Fixture(); $fixture - ->setDivision(Division::find($data['Code'])->getId()) + ->setDivision(Division::findByName($data['Code'])->getId()) ->setMatchNumber($data['Match']) - ->setMatchDate(Carbon::createFromFormat('d/m/Y', $data['date'])) + ->setMatchDate(Carbon::createFromFormat('d/m/Y', $data['Date'])) ->setWarmUpTime(Carbon::createFromFormat('H:i:s', $data['WUTime'])) ->setStartTime(Carbon::createFromFormat('H:i:s', $data['StartTime'])) ->setHomeTeam(Team::findByName($data['Home'])->getId()) ->setAwayTeam(Team::findByName($data['Away'])->getId()) ->setVenue(Venue::findByName($data['Hall'])->getId()); - $jobData = new UploadJobData(); - - $jobData - ->setJobId($jobId) - ->setModel(Fixture::class) - ->setData($fixture->toJson()) - ->save(); + $this->uploadDataService->add($jobId, Fixture::class, $fixture); unset($fixture); } diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php index f7ff2439..2e059333 100644 --- a/app/Services/StatusService.php +++ b/app/Services/StatusService.php @@ -8,8 +8,8 @@ namespace App\Services; -use App\Services\Contracts\StatusContract; -use App\Models\UploadJob; +use App\Models\UploadJobStatus; +use Carbon\Carbon; /** * Class StatusService @@ -20,87 +20,176 @@ * * @package App\Services */ -class StatusService implements StatusContract +class StatusService { /** - * @param array $status + * @param array $statusArray + * + * @return UploadJobStatus + */ + public function loadStatus(array $statusArray) + { + $status = new UploadJobStatus(); + $status->load($statusArray); + + return $status; + } + + /** + * @return UploadJobStatus + */ + public function getInitialStatus() + { + return new UploadJobStatus(); + } + + /** + * @param UploadJobStatus $status + * @param string $division + * @param string $matchNumber + * @param string $homeTeam + * @param string $awayTeam + * @param Carbon $date + * @param Carbon $warmUpTime + * @param Carbon $startTime + * @param string $venue + */ + public function setProcessingLine( + UploadJobStatus $status, + $division, + $matchNumber, + $homeTeam, + $awayTeam, + Carbon $date, + Carbon $warmUpTime, + Carbon $startTime, + $venue + ) + { + $status + ->setProcessingLineDivision($division) + ->setProcessingLineMatchNumber($matchNumber) + ->setProcessingLineHomeTeam($homeTeam) + ->setProcessingLineAwayTeam($awayTeam) + ->setProcessingLineDate($date->format('D d/m/y')) + ->setProcessingLineWarmUpTime($warmUpTime->format('H:i')) + ->setProcessingLineStartTime($startTime->format('H:i')) + ->setProcessingLineVenue($venue); + } + + /** + * @param array $statusArray * * @return array */ - public function getNextStepStatus($status) + public function apiFormat($statusArray) { - $newStatus = [ - 'status_code' => UploadJob::STATUS_NOT_STARTED, + $status = new UploadJobStatus(); + $status->load($statusArray); + + $formattedStatus = [ + 'StatusCode' => $status->getStatusCode(), + 'StatusMessage' => $status->getStatusCodeMessage(), + ]; + + if ($status->isValidating()) { + $formattedStatus['Progress'] = floor($status->getProcessedLines() * 100 / $status->getTotalLines()); + } elseif ($status->isInserting()) { + $formattedStatus['Progress'] = floor($status->getProcessedRows() * 100 / $status->getTotalRows()); + } + + $formattedStatus['Fixture'] = [ + 'Division' => $status->getProcessingLineDivision(), + 'MatchNumber' => $status->getProcessingLineMatchNumber(), + 'HomeTeam' => $status->getProcessingLineHomeTeam(), + 'AwayTeam' => $status->getProcessingLineAwayTeam(), + 'Date' => $status->getProcessingLineDate(), + 'WarmUpTime' => $status->getProcessingLineWarmUpTime(), + 'StartTime' => $status->getProcessingLineStartTime(), + 'Venue' => $status->getProcessingLineVenue(), ]; - switch ($status['status_code']) { - case UploadJob::STATUS_NOT_STARTED: - $newStatus = [ - 'status_code' => UploadJob::STATUS_VALIDATING_RECORDS, - 'processed_lines' => 0, - ]; - break; - case UploadJob::STATUS_VALIDATING_RECORDS: - $newStatus = [ - 'status_code' => UploadJob::STATUS_INSERTING_RECORDS, - ]; - break; - case UploadJob::STATUS_INSERTING_RECORDS: - $newStatus = [ - 'status_code' => UploadJob::STATUS_DONE, - ]; - break; + foreach ($status->getUnknowns() as $unknownType => $mappings) { + switch ($unknownType) { + case UploadJobStatus::UNKNOWN_HOME_TEAM: + $formattedStatus['Unknowns']['HomeTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_AWAY_TEAM: + $formattedStatus['Unknowns']['AwayTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_VENUE: + $formattedStatus['Unknowns']['Venue'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Add' => route('loading-add-venue'), + 'Map' => route('loading-map-venue'), + ], + ]; + break; + } } - return $newStatus; + return $formattedStatus; } /** - * @param array $status + * @param UploadJobStatus $status * - * @return int + * @return UploadJobStatus */ - public function getStatusCode($status) + public function getNextStepStatus($status) { - if (array_has($status, 'status_code')) { - return $status['status_code']; - } - - return UploadJob::STATUS_NOT_STARTED; + return $status->moveForward(); } /** * @param array $status * * @return int - * @throws \RuntimeException */ - public function getStatusProcessedLines($status) + public function getStatusCode($status) { - $statusCode = $this->getStatusCode($status); - - if ($statusCode == UploadJob::STATUS_VALIDATING_RECORDS && array_has($status, 'processed_lines')) { - return $status['processed_lines']; + if (array_has($status, 'status_code')) { + return $status['status_code']; } - throw new \RuntimeException('Invalid status for retrieving number of already processed lines.'); + return UploadJobStatus::STATUS_NOT_STARTED; } - /** - * @param array $status - * @param int $processedLines - * - * @throws \RuntimeException - */ - public function setStatusProcessedLines(&$status, $processedLines) + public function setUnknownHomeTeam(UploadJobStatus $status) { - $statusCode = $this->getStatusCode($status); + // Get the possible mapping + $mappings = []; - if ($statusCode == UploadJob::STATUS_VALIDATING_RECORDS) { - $status['processed_lines'] = $processedLines; - } + // Add the unknown + $status->setUnknown(UploadJobStatus::UNKNOWN_HOME_TEAM, $mappings); + } - throw new \RuntimeException('Invalid status for setting number of already processed lines.'); + public function setUnknownAwayTeam(UploadJobStatus $status) + { + // Get the possible mapping + $mappings = []; + + // Add the unknown + $status->setUnknown(UploadJobStatus::UNKNOWN_AWAY_TEAM, $mappings); } + public function setUnknownVenue(UploadJobStatus $status) + { + // Get the possible mapping + $mappings = []; + + // Add the unknown + $status->setUnknown(UploadJobStatus::UNKNOWN_VENUE, $mappings); + } } \ No newline at end of file diff --git a/app/Services/UploadDataService.php b/app/Services/UploadDataService.php new file mode 100644 index 00000000..17281f06 --- /dev/null +++ b/app/Services/UploadDataService.php @@ -0,0 +1,31 @@ + + * Date: 05/02/2017 + * Time: 17:02 + */ + +namespace App\Services; + +use App\Models\UploadJobData; +use Illuminate\Database\Eloquent\Model; + +class UploadDataService +{ + /** + * @param int $jobId + * @param string $modelClass + * @param Model $model + */ + public function add($jobId, $modelClass, Model $model) + { + $jobData = new UploadJobData(); + + $jobData + ->setJobId($jobId) + ->setModel($modelClass) + ->setData($model->toJson()) + ->save(); + } +} \ No newline at end of file diff --git a/database/deployment/2016_11_20_124340_create_new_venues_and_teams_tables.sql b/database/deployment/2016_11_20_124340_create_new_venues_table.sql similarity index 50% rename from database/deployment/2016_11_20_124340_create_new_venues_and_teams_tables.sql rename to database/deployment/2016_11_20_124340_create_new_venues_table.sql index afdea911..29135f7e 100644 --- a/database/deployment/2016_11_20_124340_create_new_venues_and_teams_tables.sql +++ b/database/deployment/2016_11_20_124340_create_new_venues_table.sql @@ -14,20 +14,3 @@ ALTER TABLE `new_venues` ADD INDEX `new_venues_venue_index`(`venue`); ALTER TABLE `new_venues` ADD CONSTRAINT `new_venues_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); - -CREATE TABLE `new_teams` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `upload_job_id` INT UNSIGNED NOT NULL, - `team` VARCHAR(255) NOT NULL, - `team_id` INT UNSIGNED NULL, - `created_at` TIMESTAMP NULL, - `updated_at` TIMESTAMP NULL -) - DEFAULT CHARACTER SET utf8 - COLLATE utf8_unicode_ci - ENGINE = InnoDB; - -ALTER TABLE `new_teams` - ADD INDEX `new_teams_team_index`(`team`); -ALTER TABLE `new_teams` - ADD CONSTRAINT `new_teams_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); \ No newline at end of file diff --git a/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_and_teams_tables.sql b/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_table.sql similarity index 50% rename from database/deployment/rollbacks/2016_11_20_124340_create_new_venues_and_teams_tables.sql rename to database/deployment/rollbacks/2016_11_20_124340_create_new_venues_table.sql index 1b96b78d..ff9f29fc 100644 --- a/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_and_teams_tables.sql +++ b/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_table.sql @@ -2,6 +2,3 @@ ALTER TABLE `new_venues` DROP FOREIGN KEY `new_venues_upload_job_id_foreign`; DROP TABLE `new_venues`; -ALTER TABLE `new_teams` - DROP FOREIGN KEY `new_teams_upload_job_id_foreign`; -DROP TABLE `new_teams`; diff --git a/database/migrations/2016_11_20_124340_create_new_venues_and_teams_tables.php b/database/migrations/2016_11_20_124340_create_new_venues_table.php similarity index 58% rename from database/migrations/2016_11_20_124340_create_new_venues_and_teams_tables.php rename to database/migrations/2016_11_20_124340_create_new_venues_table.php index 35b47340..a904b56b 100644 --- a/database/migrations/2016_11_20_124340_create_new_venues_and_teams_tables.php +++ b/database/migrations/2016_11_20_124340_create_new_venues_table.php @@ -3,7 +3,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateNewVenuesAndTeamsTables extends Migration +class CreateNewVenuesTable extends Migration { /** * Run the migrations. @@ -25,20 +25,6 @@ public function up() $table->index('venue'); $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); }); - - Schema::create('new_teams', function (Blueprint $table) { - $table->engine = 'InnoDB'; - - $table->increments('id'); - $table->unsignedInteger('upload_job_id'); - $table->string('team'); - $table->unsignedInteger('team_id')->nullable(); - - $table->timestamps(); - - $table->index('team'); - $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); - }); } /** @@ -52,10 +38,5 @@ public function down() $table->dropForeign(['upload_job_id']); }); Schema::drop('new_venues'); - - Schema::table('new_teams', function (Blueprint $table) { - $table->dropForeign(['upload_job_id']); - }); - Schema::drop('new_teams'); } } diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index 1000f0fc..7ea38c44 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -87,21 +87,31 @@ }, createUnknownRow = function createUnknownRow(tmplId, text, map) { - var unknown = $('#' + tmplId).clone(true).removeClass('hidden').attr('id', ''); + var unknown = $('#' + tmplId).clone(true).removeClass('hidden').attr('id', ''), + addButton = unknown.find('.add-button'), + mapButton = unknown.find('.map-button'); unknown.find('p').text(text); - unknown.find('.add-button').data('apiurl', map.ApiUrls.Add); - - var select = unknown.find('select'); - $.each(map.Mapping, function (index, option) { - var $option = $("") - .attr("value", option.value) - .text(option.text); - select.append($option); - }); - unknown.find('.map-button').data('apiurl', map.ApiUrls.Map); + if (map.ApiUrls.Add) { + addButton.data('apiurl', map.ApiUrls.Add); + addButton.on('click', AddUnknown); + } else { + addButton.addClass('disabled').blur(); + } - unknown.on('click', '.add-button', AddUnknown).on('click', '.map-button', MapUnknown); + if (map.ApiUrls.Map) { + var select = unknown.find('select'); + $.each(map.Mapping, function (index, option) { + var $option = $("") + .attr("value", option.value) + .text(option.text); + select.append($option); + }); + mapButton.data('apiurl', map.ApiUrls.Map); + mapButton.on('click', MapUnknown); + } else { + mapButton.addClass('disabled').blur(); + } return unknown; }, @@ -132,7 +142,7 @@ .attr('aria-valuenow', status.Progress) .find('.sr-only').html(status.Progress + '% Complete'); - if (status.StatusCode == 11) { + if (status.StatusCode == 10) { $('#load-fixture-modal').find('.modal-title').text(status.StatusMessage); populateCurrentFixture($('#load-fixture-modal'), status.Fixture); diff --git a/resources/views/_partial/load-fixture-modal.blade.php b/resources/views/_partial/load-fixture-modal.blade.php index b3f2992d..4f137485 100644 --- a/resources/views/_partial/load-fixture-modal.blade.php +++ b/resources/views/_partial/load-fixture-modal.blade.php @@ -24,7 +24,7 @@

- The follolwing data has not been found in the database. If it's new then add it. If not, then + The following data has not been found in the database. If it's new then add it. If not, then please check the available options and map it to one of the existing.

What would you like to do?

From d67c9dd90c97646f928265b2b9663df2f6d1ee4d Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Mon, 6 Feb 2017 12:57:15 +0000 Subject: [PATCH 25/62] lva-22: implemented API actions to add/map venues and map teams, other refactoring --- .../Admin/DataManagement/LoadController.php | 2 +- .../Api/v1/UploadApiController.php | 47 ++++++++++--------- app/Http/Requests/Api/v1/MapTeamRequest.php | 40 ++++++++++++++++ app/Http/Requests/Api/v1/MapVenueRequest.php | 40 ++++++++++++++++ app/Http/Requests/Api/v1/NewVenueRequest.php | 39 +++++++++++++++ app/Models/Division.php | 4 +- app/Models/MappedTeam.php | 35 ++++++++++++++ app/Models/MappedVenue.php | 36 ++++++++++++++ app/Models/{NewVenues.php => NewVenue.php} | 28 ++++++++++- app/Models/UploadJob.php | 24 +++++++++- .../Contracts/InteractiveUploadContract.php | 3 +- .../InteractiveFixturesUploadService.php | 44 +++++++++++++---- app/Services/MappingService.php | 33 +++++++++++++ app/Services/StatusService.php | 47 ++++++++++++------- ..._add_season_field_to_upload_jobs_table.sql | 4 ++ ..._remove_venue_id_from_new_venues_table.sql | 2 + ..._add_season_field_to_upload_jobs_table.sql | 4 ++ ..._remove_venue_id_from_new_venues_table.sql | 2 + ..._add_season_field_to_upload_jobs_table.php | 34 ++++++++++++++ ..._remove_venue_id_from_new_venues_table.php | 31 ++++++++++++ 20 files changed, 445 insertions(+), 54 deletions(-) create mode 100644 app/Http/Requests/Api/v1/MapTeamRequest.php create mode 100644 app/Http/Requests/Api/v1/MapVenueRequest.php create mode 100644 app/Http/Requests/Api/v1/NewVenueRequest.php rename app/Models/{NewVenues.php => NewVenue.php} (62%) create mode 100644 app/Services/MappingService.php create mode 100644 database/deployment/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql create mode 100644 database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql create mode 100644 database/deployment/rollbacks/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql create mode 100644 database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql create mode 100644 database/migrations/2017_02_06_113853_add_season_field_to_upload_jobs_table.php create mode 100644 database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php diff --git a/app/Http/Controllers/Admin/DataManagement/LoadController.php b/app/Http/Controllers/Admin/DataManagement/LoadController.php index 16dc22ff..6323b0d9 100644 --- a/app/Http/Controllers/Admin/DataManagement/LoadController.php +++ b/app/Http/Controllers/Admin/DataManagement/LoadController.php @@ -45,7 +45,7 @@ public function startUploadFixtures(Request $request) ]); // Create upload job - $job = $this->uploadService->createJob($request->file('upload_file')); + $job = $this->uploadService->createJob($request->input('season_id'), $request->file('upload_file')); // Start the uploading $this->uploadService->processJob($job); diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 64c4dd39..c9c65e85 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -9,6 +9,12 @@ namespace App\Http\Controllers\Api\v1; use App\Http\Controllers\Controller; +use App\Http\Requests\Api\v1\MapTeamRequest; +use App\Http\Requests\Api\v1\MapVenueRequest; +use App\Http\Requests\Api\v1\NewVenueRequest; +use App\Models\MappedTeam; +use App\Models\MappedVenue; +use App\Models\NewVenue; use App\Models\UploadJob; use App\Models\UploadJobStatus; use App\Services\StatusService; @@ -98,42 +104,41 @@ public function getUploadStatus() ]); } - public function mapTeam() + public function mapTeam(MapTeamRequest $request) { - $uploadJob = $this->checkForJob(); - if (!$uploadJob instanceof UploadJob) { - return response($uploadJob); - } - - // @todo implement mapping a team + $mappedTeam = new MappedTeam(); + $mappedTeam + ->setUploadJob($request->input('job')) + ->setTeam($request->input('name')) + ->setMappedTeam($request->input('newName')) + ->save(); return response()->json([ 'success' => true, ]); } - public function addVenue() + public function addVenue(NewVenueRequest $request) { - $uploadJob = $this->checkForJob(); - if (!$uploadJob instanceof UploadJob) { - return response($uploadJob); - } - - // @todo implement adding a venue + $newVenue = new NewVenue(); + $newVenue + ->setUploadJob($request->input('job')) + ->setVenue($request->input('name')) + ->save(); return response()->json([ 'success' => true, ]); } - public function mapVenue() + public function mapVenue(MapVenueRequest $request) { - $uploadJob = $this->checkForJob(); - if (!$uploadJob instanceof UploadJob) { - return response($uploadJob); - } - - // @todo implemenr mapping a venue + $mappedVenue = new MappedVenue(); + $mappedVenue + ->setUploadJob($request->input('job')) + ->setVenue($request->input('name')) + ->setMappedVenue($request->input('newName')) + ->save(); return response()->json([ 'success' => false, diff --git a/app/Http/Requests/Api/v1/MapTeamRequest.php b/app/Http/Requests/Api/v1/MapTeamRequest.php new file mode 100644 index 00000000..a3a8798b --- /dev/null +++ b/app/Http/Requests/Api/v1/MapTeamRequest.php @@ -0,0 +1,40 @@ + 'required|exists:upload_jobs', + 'name' => 'required', + 'newName' => 'required', + ]; + } +} \ No newline at end of file diff --git a/app/Http/Requests/Api/v1/MapVenueRequest.php b/app/Http/Requests/Api/v1/MapVenueRequest.php new file mode 100644 index 00000000..869480fa --- /dev/null +++ b/app/Http/Requests/Api/v1/MapVenueRequest.php @@ -0,0 +1,40 @@ + 'required|exists:upload_jobs', + 'name' => 'required', + 'newName' => 'required', + ]; + } +} \ No newline at end of file diff --git a/app/Http/Requests/Api/v1/NewVenueRequest.php b/app/Http/Requests/Api/v1/NewVenueRequest.php new file mode 100644 index 00000000..7d1ce1fa --- /dev/null +++ b/app/Http/Requests/Api/v1/NewVenueRequest.php @@ -0,0 +1,39 @@ + 'required|exists:upload_jobs', + 'name' => 'required', + ]; + } +} \ No newline at end of file diff --git a/app/Models/Division.php b/app/Models/Division.php index c778c0b1..0905e2b8 100644 --- a/app/Models/Division.php +++ b/app/Models/Division.php @@ -31,9 +31,9 @@ class Division extends Model * * @return Division|null */ - public static function findByName($division) + public static function findByName($seasonId, $division) { - return self::where('division', $division)->first(); + return self::where('season_id', $seasonId)->where('division', $division)->first(); } /** diff --git a/app/Models/MappedTeam.php b/app/Models/MappedTeam.php index 89d38b2a..830e3b0e 100644 --- a/app/Models/MappedTeam.php +++ b/app/Models/MappedTeam.php @@ -55,4 +55,39 @@ public function getId() return $this->id; } + /** + * @param int $jobId + * + * @return MappedTeam + */ + public function setUploadJob($jobId) + { + $this->upload_job_id = $jobId; + + return $this; + } + + /** + * @param string $team + * + * @return MappedTeam + */ + public function setTeam($team) + { + $this->team = $team; + + return $this; + } + + /** + * @param string $team + * + * @return MappedTeam + */ + public function setMappedTeam($team) + { + $this->team_id = Team::findByName($team); + + return $this; + } } \ No newline at end of file diff --git a/app/Models/MappedVenue.php b/app/Models/MappedVenue.php index 41e1827e..34ddaee5 100644 --- a/app/Models/MappedVenue.php +++ b/app/Models/MappedVenue.php @@ -54,4 +54,40 @@ public function getId() { return $this->id; } + + /** + * @param int $jobId + * + * @return MappedVenue + */ + public function setUploadJob($jobId) + { + $this->upload_job_id = $jobId; + + return $this; + } + + /** + * @param string $venue + * + * @return MappedVenue + */ + public function setVenue($venue) + { + $this->venue = $venue; + + return $this; + } + + /** + * @param string $venue + * + * @return MappedVenue + */ + public function setMappedVenue($venue) + { + $this->venue_id = Venue::findByName($venue); + + return $this; + } } \ No newline at end of file diff --git a/app/Models/NewVenues.php b/app/Models/NewVenue.php similarity index 62% rename from app/Models/NewVenues.php rename to app/Models/NewVenue.php index c340ccca..b8a28d55 100644 --- a/app/Models/NewVenues.php +++ b/app/Models/NewVenue.php @@ -15,7 +15,7 @@ * * @package App\Models */ -class NewVenues extends Model +class NewVenue extends Model { /** * The database table used by the model. @@ -29,7 +29,7 @@ class NewVenues extends Model * * @var array */ - protected $fillable = ['upload_job_id', 'venue', 'venue_id']; + protected $fillable = ['upload_job_id', 'venue']; /** * @return \Illuminate\Database\Eloquent\Relations\HasOne @@ -46,4 +46,28 @@ public function getId() { return $this->id; } + + /** + * @param int $jobId + * + * @return NewVenue + */ + public function setUploadJob($jobId) + { + $this->upload_job_id = $jobId; + + return $this; + } + + /** + * @param string $venue + * + * @return NewVenue + */ + public function setVenue($venue) + { + $this->venue = $venue; + + return $this; + } } \ No newline at end of file diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index 6bb7372a..7963e069 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -14,7 +14,7 @@ class UploadJob extends Model const TYPE_FIXTURES = 'fixtures'; protected $table = 'upload_jobs'; - protected $fillable = ['file', 'row_count', 'type', 'status']; + protected $fillable = ['season_id', 'file', 'row_count', 'type', 'status']; /** * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -37,7 +37,7 @@ public function mappedVenues() */ public function newVenues() { - return $this->hasMany(NewVenues::class); + return $this->hasMany(NewVenue::class); } /** @@ -56,6 +56,26 @@ public function getId() return $this->id; } + /** + * @return int + */ + public function getSeason() + { + return $this->season_id; + } + + /** + * @param int $seasonId + * + * @return UploadJob + */ + public function setSeason($seasonId) + { + $this->season_id = $seasonId; + + return $this; + } + /** * @return string */ diff --git a/app/Services/Contracts/InteractiveUploadContract.php b/app/Services/Contracts/InteractiveUploadContract.php index 371b119e..8bd488b5 100644 --- a/app/Services/Contracts/InteractiveUploadContract.php +++ b/app/Services/Contracts/InteractiveUploadContract.php @@ -14,11 +14,12 @@ interface InteractiveUploadContract { /** + * @param int $seasonId * @param UploadedFile $file * * @return mixed */ - public function createJob(UploadedFile $file); + public function createJob($seasonId, UploadedFile $file); /** * @param UploadJob $job diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index e2f8aeff..2c3cab4f 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -10,6 +10,7 @@ use App\Models\Division; use App\Models\Fixture; +use App\Models\Season; use App\Models\Team; use App\Models\TeamSynonym; use App\Models\UploadJobData; @@ -29,7 +30,9 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract /** @var StatusService */ private $statusService; + /** @var UploadDataService */ private $uploadDataService; + private $mappingService; /** @var Collection */ private $mappedTeams; @@ -43,11 +46,12 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract */ public function __construct( StatusService $statusService, - UploadDataService $uploadDataService - ) - { + UploadDataService $uploadDataService, + MappingService $mappingService + ) { $this->statusService = $statusService; $this->uploadDataService = $uploadDataService; + $this->mappingService = $mappingService; } @@ -70,7 +74,7 @@ public static function readOneLine(&$handle) /** * @inheritdoc */ - public function createJob(UploadedFile $file) + public function createJob($seasonId, UploadedFile $file) { /** @var UploadedFile $fixtureFile */ $fixtureFile = $file->move(storage_path() . self::UPLOAD_DIR, $file->getClientOriginalName()); @@ -83,7 +87,8 @@ public function createJob(UploadedFile $file) fclose($handle); $job = new UploadJob(); - $job->setFile($fixtureFile->getFilename()) + $job->setSeason($seasonId) + ->setFile($fixtureFile->getFilename()) ->setType(UploadJob::TYPE_FIXTURES) ->setRowCount($lines - 1)// Don't count the first line as they are the headers ->setStatus($this->statusService->getInitialStatus()->toArray()) @@ -142,22 +147,45 @@ public function processJob(UploadJob $job) $row['Hall'] ); + // Skip lines that are not for London or indoor volleyball + if ($row['Region'] != 'L' || $row['Discipline'] != 'I') { + // Update the line counter + $status->setProcessedLines(++$processedLines); + $job->setStatus($status->toArray())->save(); + continue; + } + + // Skip lines that are for divisions not in the system for the selected season + $division = Division::findByName($job->getSeason(), $row['Code']); + if (is_null($division)) { + // Update the line counter + $status->setProcessedLines(++$processedLines); + $job->setStatus($status->toArray())->save(); + continue; + } + // Start validation $isValid = true; if (!$this->isValidTeam($row['Home'])) { + $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Home']); + $this->statusService->setUnknownHomeTeam($status, $mappings); + $allRowsProcessed = false; $isValid = false; - $this->statusService->setUnknownHomeTeam($status); } if (!$this->isValidTeam($row['Away'])) { + $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Away']); + $this->statusService->setUnknownHomeTeam($status, $mappings); + $allRowsProcessed = false; $isValid = false; - $this->statusService->setUnknownHomeTeam($status); } if (!$this->isValidVenue($row['Hall'])) { + $mappings = $this->mappingService->findVenueMappings($row['Hall']); + $this->statusService->setUnknownHomeTeam($status, $mappings); + $allRowsProcessed = false; $isValid = false; - $this->statusService->setUnknownVenue($status); } // Is something is not valid stop the process diff --git a/app/Services/MappingService.php b/app/Services/MappingService.php new file mode 100644 index 00000000..0b930a4c --- /dev/null +++ b/app/Services/MappingService.php @@ -0,0 +1,33 @@ +mappingService = $mappingService; + } + + /** * @param array $statusArray * @@ -64,8 +78,7 @@ public function setProcessingLine( Carbon $warmUpTime, Carbon $startTime, $venue - ) - { + ) { $status ->setProcessingLineDivision($division) ->setProcessingLineMatchNumber($matchNumber) @@ -166,30 +179,30 @@ public function getStatusCode($status) return UploadJobStatus::STATUS_NOT_STARTED; } - public function setUnknownHomeTeam(UploadJobStatus $status) + /** + * @param UploadJobStatus $status + * @param array $mappings + */ + public function setUnknownHomeTeam(UploadJobStatus $status, $mappings) { - // Get the possible mapping - $mappings = []; - - // Add the unknown $status->setUnknown(UploadJobStatus::UNKNOWN_HOME_TEAM, $mappings); } - public function setUnknownAwayTeam(UploadJobStatus $status) + /** + * @param UploadJobStatus $status + * @param array $mappings + */ + public function setUnknownAwayTeam(UploadJobStatus $status, $mappings) { - // Get the possible mapping - $mappings = []; - - // Add the unknown $status->setUnknown(UploadJobStatus::UNKNOWN_AWAY_TEAM, $mappings); } - public function setUnknownVenue(UploadJobStatus $status) + /** + * @param UploadJobStatus $status + * @param array $mappings + */ + public function setUnknownVenue(UploadJobStatus $status, $mappings) { - // Get the possible mapping - $mappings = []; - - // Add the unknown $status->setUnknown(UploadJobStatus::UNKNOWN_VENUE, $mappings); } } \ No newline at end of file diff --git a/database/deployment/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql b/database/deployment/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql new file mode 100644 index 00000000..20d250dd --- /dev/null +++ b/database/deployment/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE `upload_jobs` + ADD `season_id` INT UNSIGNED NOT NULL; +ALTER TABLE `upload_jobs` + ADD CONSTRAINT `upload_jobs_season_id_foreign` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`); \ No newline at end of file diff --git a/database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql b/database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql new file mode 100644 index 00000000..865ba8b3 --- /dev/null +++ b/database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE `new_venues` + DROP `venue_id`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql b/database/deployment/rollbacks/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql new file mode 100644 index 00000000..38b76edb --- /dev/null +++ b/database/deployment/rollbacks/2017_02_06_113853_add_season_field_to_upload_jobs_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE `upload_jobs` + DROP FOREIGN KEY `upload_jobs_season_id_foreign`; +ALTER TABLE `upload_jobs` + DROP `season_id`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql b/database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql new file mode 100644 index 00000000..846b28a6 --- /dev/null +++ b/database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE `new_venues` + ADD `venue_id` INT UNSIGNED NULL; \ No newline at end of file diff --git a/database/migrations/2017_02_06_113853_add_season_field_to_upload_jobs_table.php b/database/migrations/2017_02_06_113853_add_season_field_to_upload_jobs_table.php new file mode 100644 index 00000000..d7d1faef --- /dev/null +++ b/database/migrations/2017_02_06_113853_add_season_field_to_upload_jobs_table.php @@ -0,0 +1,34 @@ +unsignedInteger('season_id'); + + $table->foreign('season_id')->references('id')->on('seasons'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('upload_jobs', function (Blueprint $table) { + $table->dropForeign(['season_id']); + $table->dropColumn('season_id'); + }); + } +} diff --git a/database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php b/database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php new file mode 100644 index 00000000..b5abf63f --- /dev/null +++ b/database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php @@ -0,0 +1,31 @@ +dropColumn('venue_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('new_venues', function (Blueprint $table) { + $table->unsignedInteger('venue_id')->nullable(); + }); + } +} From d57650deb15323973476a000825b7501f9c43283 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Tue, 7 Feb 2017 16:00:54 +0000 Subject: [PATCH 26/62] dev: make sure Travis sends an email on success and on failure --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 26a12e94..f50aecc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ branches: - master - dev - lva-22-interactive-loading +notifications: + email: + on_success: always + on_failure: always language: php php: - 5.6.30 From 9209257cb038f6c090365aa5576396501d67a589 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Tue, 7 Feb 2017 16:05:43 +0000 Subject: [PATCH 27/62] lva-22: Added code to cope with mapped teams and venues --- app/Models/MappedTeam.php | 19 +++ app/Models/MappedVenue.php | 19 +++ app/Repositories/TeamsRepository.php | 90 +++++++++++ app/Repositories/VenuesRepository.php | 88 ++++++++++ .../InteractiveFixturesUploadService.php | 150 +++++++++++++++--- app/Services/StatusService.php | 2 +- 6 files changed, 341 insertions(+), 27 deletions(-) create mode 100644 app/Repositories/TeamsRepository.php create mode 100644 app/Repositories/VenuesRepository.php diff --git a/app/Models/MappedTeam.php b/app/Models/MappedTeam.php index 830e3b0e..1d2956d6 100644 --- a/app/Models/MappedTeam.php +++ b/app/Models/MappedTeam.php @@ -8,6 +8,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; /** @@ -31,6 +32,16 @@ class MappedTeam extends Model */ protected $fillable = ['upload_job_id', 'team', 'team_id']; + /** + * @param $jobId + * + * @return Collection + */ + public static function findByJob($jobId) + { + return MappedTeam::where('upload_job_id', $jobId)->get(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ @@ -67,6 +78,14 @@ public function setUploadJob($jobId) return $this; } + /** + * @return mixed + */ + public function getName() + { + return $this->team; + } + /** * @param string $team * diff --git a/app/Models/MappedVenue.php b/app/Models/MappedVenue.php index 34ddaee5..a578f344 100644 --- a/app/Models/MappedVenue.php +++ b/app/Models/MappedVenue.php @@ -9,6 +9,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Collection; /** * Class MappedVenue @@ -31,6 +32,16 @@ class MappedVenue extends Model */ protected $fillable = ['upload_job_id', 'venue', 'venue_id']; + /** + * @param $jobId + * + * @return Collection + */ + public static function findByJob($jobId) + { + return MappedTeam::where('upload_job_id', $jobId)->get(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ @@ -67,6 +78,14 @@ public function setUploadJob($jobId) return $this; } + /** + * @return mixed + */ + public function getName() + { + return $this->venue; + } + /** * @param string $venue * diff --git a/app/Repositories/TeamsRepository.php b/app/Repositories/TeamsRepository.php new file mode 100644 index 00000000..f2a3050e --- /dev/null +++ b/app/Repositories/TeamsRepository.php @@ -0,0 +1,90 @@ +modelsById[$id])) { + return $this->modelsById[$id]; + } + + /** @var Team $model */ + $model = Team::find($id); + if ($model) { + $this->modelsById[$id] = $model; + return $model; + } + return null; + } + + /** + * @param string $name + * + * @return Team|null + */ + public function findByName($name) + { + if (isset($this->modelsByName[$name])) { + return $this->modelsByName[$name]; + } + + /** @var Team $model */ + $model = Team::findByName($name); + if ($model) { + $this->modelsByName[$name] = $model; + return $model; + } else { + /** @var TeamSynonym $modelSynonym */ + $modelSynonym = TeamSynonym::findBySynonym($name); + if ($modelSynonym) { + $$model = $modelSynonym->team; + $this->modelsByName[$name] = $model; + return $model; + } + } + return null; + } + + public function findByNameWithinMapped(UploadJob $job, $team) + { + $jobId = $job->getId(); + if (is_null($this->mappedModelsByName[$jobId])) { + /** @var MappedTeam $mappedTeam */ + foreach (MappedTeam::findByJob($jobId) as $mappedTeam) { + $this->mappedModelsByName[$jobId][$mappedTeam->getName()] = $mappedTeam->team; + } + } + + if (isset($this->mappedModelsByName[$jobId][$team])) { + return $this->mappedModelsByName[$jobId][$team]; + } else { + return null; + } + } + +} \ No newline at end of file diff --git a/app/Repositories/VenuesRepository.php b/app/Repositories/VenuesRepository.php new file mode 100644 index 00000000..6db4f195 --- /dev/null +++ b/app/Repositories/VenuesRepository.php @@ -0,0 +1,88 @@ +modelsById[$id])) { + return $this->modelsById[$id]; + } + + /** @var Venue $model */ + $model = Venue::find($id); + if ($model) { + $this->modelsById[$id] = $model; + return $model; + } + return null; + } + + /** + * @param string $name + * + * @return Venue|null + */ + public function findByName($name) + { + if (isset($this->modelsByName[$name])) { + return $this->modelsByName[$name]; + } + + /** @var Venue $model */ + $model = Venue::findByName($name); + if ($model) { + $this->modelsByName[$name] = $model; + return $model; + } else { + /** @var VenueSynonym $modelSynonym */ + $modelSynonym = VenueSynonym::findBySynonym($name); + if ($modelSynonym) { + $$model = $modelSynonym->team; + $this->modelsByName[$name] = $model; + return $model; + } + } + return null; + } + + public function findByNameWithinMapped(UploadJob $job, $team) + { + $jobId = $job->getId(); + if (is_null($this->mappedModelsByName[$jobId])) { + /** @var MappedVenue $mappedTeam */ + foreach (MappedVenue::findByJob($jobId) as $mappedTeam) { + $this->mappedModelsByName[$jobId][$mappedTeam->getName()] = $mappedTeam->team; + } + } + + if (isset($this->mappedModelsByName[$jobId][$team])) { + return $this->mappedModelsByName[$jobId][$team]; + } else { + return null; + } + } +} \ No newline at end of file diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index 2c3cab4f..90d6890d 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -17,12 +17,14 @@ use App\Models\UploadJobStatus; use App\Models\Venue; use App\Models\VenueSynonym; +use App\Repositories\TeamsRepository; use App\Services\Contracts\InteractiveUploadContract; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\UploadedFile; use App\Models\UploadJob; +use Repositories\VenuesRepository; class InteractiveFixturesUploadService implements InteractiveUploadContract { @@ -32,8 +34,15 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract private $statusService; /** @var UploadDataService */ private $uploadDataService; + /** @var MappingService */ private $mappingService; + /** @var TeamsRepository */ + private $teamsRepository; + /** @var VenuesRepository */ + private $venuesRepository; + + /** @var Collection */ private $mappedTeams; /** @var Collection */ @@ -47,11 +56,16 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract public function __construct( StatusService $statusService, UploadDataService $uploadDataService, - MappingService $mappingService + MappingService $mappingService, + TeamsRepository $teamsRepository, + VenuesRepository $venuesRepository ) { $this->statusService = $statusService; $this->uploadDataService = $uploadDataService; $this->mappingService = $mappingService; + + $this->teamsRepository = $teamsRepository; + $this->venuesRepository = $venuesRepository; } @@ -164,38 +178,76 @@ public function processJob(UploadJob $job) continue; } - // Start validation + /** @var Team|null $homeTeam */ + $homeTeam = $this->teamsRepository->findByName($row['Home']); + /** @var Team|null $awayTeam */ + $awayTeam = $this->teamsRepository->findByName($row['Away']); + /** @var Venue|null $venue */ + $venue = $this->venuesRepository->findByName($row['Hall']); + $isValid = true; - if (!$this->isValidTeam($row['Home'])) { - $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Home']); - $this->statusService->setUnknownHomeTeam($status, $mappings); - $allRowsProcessed = false; - $isValid = false; + if (is_null($homeTeam)) { + // We can't find an existing team matching this one, so checked the + // one mapped during this job + $homeTeam = $this->teamsRepository->findByNameWithinMapped($job, $row['Home']); + if (is_null($homeTeam)) { + // Nope, can't find it, so ask the user what to do + $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Home']); + $this->statusService->setUnknownHomeTeam($status, $mappings); + + $allRowsProcessed = false; + $isValid = false; + } } - if (!$this->isValidTeam($row['Away'])) { - $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Away']); - $this->statusService->setUnknownHomeTeam($status, $mappings); - - $allRowsProcessed = false; - $isValid = false; + if (is_null($awayTeam)) { + // We can't find an existing team matching this one, so checked the + // one mapped during this job + $awayTeam = $this->teamsRepository->findByNameWithinMapped($job, $row['Away']); + if (is_null($awayTeam)) { + // Nope, can't find it, so ask the user what to do + $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Away']); + $this->statusService->setUnknownAwayTeam($status, $mappings); + + $allRowsProcessed = false; + $isValid = false; + } } - if (!$this->isValidVenue($row['Hall'])) { - $mappings = $this->mappingService->findVenueMappings($row['Hall']); - $this->statusService->setUnknownHomeTeam($status, $mappings); - - $allRowsProcessed = false; - $isValid = false; + if (is_null($venue)) { + // We can't find an existing venue matching this one, so checked the + // one mapped during this job + $venue = $this->venuesRepository->findByNameWithinMapped($job, $row['Hall']); + if (is_null($venue)) { + // Nope, can't find it, so ask the user what to do + $mappings = $this->mappingService->findVenueMappings($row['Hall']); + $this->statusService->setUnknownHomeTeam($status, $mappings); + + $allRowsProcessed = false; + $isValid = false; + } } // Is something is not valid stop the process if (!$isValid) { break; + } else { + /** @var Fixture $fixture */ + $fixture = new Fixture(); + $fixture + ->setDivision($division->getId()) + ->setMatchNumber($row['Match']) + ->setMatchDate(Carbon::createFromFormat('d/m/Y', $row['Date'])) + ->setWarmUpTime(Carbon::createFromFormat('H:i:s', $row['WUTime'])) + ->setStartTime(Carbon::createFromFormat('H:i:s', $row['StartTime'])) + ->setHomeTeam($homeTeam->getId()) + ->setAwayTeam($awayTeam->getId()) + ->setVenue($venue->getId()); + + $this->uploadDataService->add($job->getId(), Fixture::class, $fixture); + + unset($fixture); } - // Everything is ok, so store the fixture to be inserted later - $this->insertFixture($job->getId(), $row); - // Update the line counter $status->setProcessedLines(++$processedLines); $job->setStatus($status->toArray())->save(); @@ -278,15 +330,61 @@ private function isValidVenue($venue) } /** - * @param int $jobId + * @param string $team + * + * @return Team|null + */ + private function findTeamByName($team) + { + /** @var Team $model */ + $model = Team::findByName($team); + if ($model) { + return $model; + } + + /** @var TeamSynonym $modelSynonym */ + $modelSynonym = TeamSynonym::findBySynonym($team); + if ($modelSynonym) { + $model = $modelSynonym->team; + return $model; + } + + return null; + } + + /** + * @param string $venue + * + * @return Venue|null + */ + private function findVenueByName($venue) + { + /** @var Venue $model */ + $model = Venue::findByName($venue); + if ($model) { + return $model; + } + + /** @var VenueSynonym $modelSynonym */ + $modelSynonym = VenueSynonym::findBySynonym($venue); + if ($modelSynonym) { + $model = $modelSynonym->venue; + return $model; + } + + return null; + } + + /** + * @param UploadJob $job * @param array $data */ - private function insertFixture($jobId, $data) + private function insertFixture($job, $data) { /** @var Fixture $fixture */ $fixture = new Fixture(); $fixture - ->setDivision(Division::findByName($data['Code'])->getId()) + ->setDivision(Division::findByName($job->getSeason(), $data['Code'])->getId()) ->setMatchNumber($data['Match']) ->setMatchDate(Carbon::createFromFormat('d/m/Y', $data['Date'])) ->setWarmUpTime(Carbon::createFromFormat('H:i:s', $data['WUTime'])) @@ -295,7 +393,7 @@ private function insertFixture($jobId, $data) ->setAwayTeam(Team::findByName($data['Away'])->getId()) ->setVenue(Venue::findByName($data['Hall'])->getId()); - $this->uploadDataService->add($jobId, Fixture::class, $fixture); + $this->uploadDataService->add($job->getId(), Fixture::class, $fixture); unset($fixture); } diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php index f7156e92..8314476e 100644 --- a/app/Services/StatusService.php +++ b/app/Services/StatusService.php @@ -144,7 +144,7 @@ public function apiFormat($statusArray) $formattedStatus['Unknowns']['Venue'] = [ 'Mapping' => $mappings, 'ApiUrls' => [ - 'Add' => route('loading-add-venue'), + //'Add' => route('loading-add-venue'), 'Map' => route('loading-map-venue'), ], ]; From af0809792bdcd3f6797e8eef382ec6faaa8002a9 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Tue, 7 Feb 2017 17:05:31 +0000 Subject: [PATCH 28/62] lva-22: refactored the MappedTeam and MappedVenue to avoid a conflict with a field name and a relationship --- .../Api/v1/UploadApiController.php | 6 ++-- app/Models/MappedTeam.php | 8 ++--- app/Models/MappedVenue.php | 8 ++--- app/Models/NewVenue.php | 2 +- ...rename_team_field_in_mapped_teams_name.sql | 6 ++++ ...name_venue_field_in_mapped_venues_name.sql | 6 ++++ ...rename_team_field_in_mapped_teams_name.sql | 6 ++++ ...name_venue_field_in_mapped_venues_name.sql | 6 ++++ ...rename_team_field_in_mapped_teams_name.php | 35 +++++++++++++++++++ ...name_venue_field_in_mapped_venues_name.php | 35 +++++++++++++++++++ 10 files changed, 106 insertions(+), 12 deletions(-) create mode 100644 database/deployment/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql create mode 100644 database/deployment/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql create mode 100644 database/deployment/rollbacks/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql create mode 100644 database/deployment/rollbacks/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql create mode 100644 database/migrations/2017_02_07_165431_rename_team_field_in_mapped_teams_name.php create mode 100644 database/migrations/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.php diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index c9c65e85..ddfdc7d5 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -109,7 +109,7 @@ public function mapTeam(MapTeamRequest $request) $mappedTeam = new MappedTeam(); $mappedTeam ->setUploadJob($request->input('job')) - ->setTeam($request->input('name')) + ->setName($request->input('name')) ->setMappedTeam($request->input('newName')) ->save(); @@ -123,7 +123,7 @@ public function addVenue(NewVenueRequest $request) $newVenue = new NewVenue(); $newVenue ->setUploadJob($request->input('job')) - ->setVenue($request->input('name')) + ->setName($request->input('name')) ->save(); return response()->json([ @@ -136,7 +136,7 @@ public function mapVenue(MapVenueRequest $request) $mappedVenue = new MappedVenue(); $mappedVenue ->setUploadJob($request->input('job')) - ->setVenue($request->input('name')) + ->setName($request->input('name')) ->setMappedVenue($request->input('newName')) ->save(); diff --git a/app/Models/MappedTeam.php b/app/Models/MappedTeam.php index 1d2956d6..df5e74fa 100644 --- a/app/Models/MappedTeam.php +++ b/app/Models/MappedTeam.php @@ -30,7 +30,7 @@ class MappedTeam extends Model * * @var array */ - protected $fillable = ['upload_job_id', 'team', 'team_id']; + protected $fillable = ['upload_job_id', 'mapped_team', 'team_id']; /** * @param $jobId @@ -83,7 +83,7 @@ public function setUploadJob($jobId) */ public function getName() { - return $this->team; + return $this->mapped_team; } /** @@ -91,9 +91,9 @@ public function getName() * * @return MappedTeam */ - public function setTeam($team) + public function setName($team) { - $this->team = $team; + $this->mapped_team = $team; return $this; } diff --git a/app/Models/MappedVenue.php b/app/Models/MappedVenue.php index a578f344..c3d080e5 100644 --- a/app/Models/MappedVenue.php +++ b/app/Models/MappedVenue.php @@ -30,7 +30,7 @@ class MappedVenue extends Model * * @var array */ - protected $fillable = ['upload_job_id', 'venue', 'venue_id']; + protected $fillable = ['upload_job_id', 'mapped_venue', 'venue_id']; /** * @param $jobId @@ -83,7 +83,7 @@ public function setUploadJob($jobId) */ public function getName() { - return $this->venue; + return $this->mapped_venue; } /** @@ -91,9 +91,9 @@ public function getName() * * @return MappedVenue */ - public function setVenue($venue) + public function setName($venue) { - $this->venue = $venue; + $this->mapped_venue = $venue; return $this; } diff --git a/app/Models/NewVenue.php b/app/Models/NewVenue.php index b8a28d55..78939543 100644 --- a/app/Models/NewVenue.php +++ b/app/Models/NewVenue.php @@ -64,7 +64,7 @@ public function setUploadJob($jobId) * * @return NewVenue */ - public function setVenue($venue) + public function setName($venue) { $this->venue = $venue; diff --git a/database/deployment/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql b/database/deployment/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql new file mode 100644 index 00000000..ab29457e --- /dev/null +++ b/database/deployment/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql @@ -0,0 +1,6 @@ +ALTER TABLE `mapped_teams` + DROP INDEX `mapped_teams_team_index`; +ALTER TABLE mapped_teams + CHANGE team mapped_team VARCHAR(255) NOT NULL; +ALTER TABLE `mapped_teams` + ADD INDEX `mapped_teams_mapped_team_index`(`mapped_team`); diff --git a/database/deployment/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql b/database/deployment/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql new file mode 100644 index 00000000..b6e30e34 --- /dev/null +++ b/database/deployment/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql @@ -0,0 +1,6 @@ +ALTER TABLE `mapped_venues` + DROP INDEX `mapped_venues_venue_index`; +ALTER TABLE mapped_venues + CHANGE venue mapped_venue VARCHAR(255) NOT NULL; +ALTER TABLE `mapped_venues` + ADD INDEX `mapped_venues_mapped_venue_index`(`mapped_venue`); diff --git a/database/deployment/rollbacks/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql b/database/deployment/rollbacks/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql new file mode 100644 index 00000000..bc9c64f9 --- /dev/null +++ b/database/deployment/rollbacks/2017_02_07_165431_rename_team_field_in_mapped_teams_name.sql @@ -0,0 +1,6 @@ +ALTER TABLE `mapped_teams` + DROP INDEX `mapped_teams_mapped_team_index`; +ALTER TABLE mapped_teams + CHANGE mapped_team team VARCHAR(255) NOT NULL; +ALTER TABLE `mapped_teams` + ADD INDEX `mapped_teams_team_index`(`team`); diff --git a/database/deployment/rollbacks/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql b/database/deployment/rollbacks/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql new file mode 100644 index 00000000..c5a8b374 --- /dev/null +++ b/database/deployment/rollbacks/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.sql @@ -0,0 +1,6 @@ +ALTER TABLE `mapped_venues` + DROP INDEX `mapped_venues_mapped_venue_index`; +ALTER TABLE mapped_venues + CHANGE mapped_venue venue VARCHAR(255) NOT NULL; +ALTER TABLE `mapped_venues` + ADD INDEX `mapped_venues_venue_index`(`venue`); diff --git a/database/migrations/2017_02_07_165431_rename_team_field_in_mapped_teams_name.php b/database/migrations/2017_02_07_165431_rename_team_field_in_mapped_teams_name.php new file mode 100644 index 00000000..35840d86 --- /dev/null +++ b/database/migrations/2017_02_07_165431_rename_team_field_in_mapped_teams_name.php @@ -0,0 +1,35 @@ +dropIndex(['team']); + $table->renameColumn('team', 'mapped_team'); + $table->index(['mapped_team']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('mapped_teams', function (Blueprint $table) { + $table->dropIndex(['mapped_team']); + $table->renameColumn('mapped_team', 'team'); + $table->index(['team']); + }); + } +} diff --git a/database/migrations/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.php b/database/migrations/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.php new file mode 100644 index 00000000..ef18e391 --- /dev/null +++ b/database/migrations/2017_02_07_165447_rename_venue_field_in_mapped_venues_name.php @@ -0,0 +1,35 @@ +dropIndex(['venue']); + $table->renameColumn('venue', 'mapped_venue'); + $table->index(['mapped_venue']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('mapped_venues', function (Blueprint $table) { + $table->dropIndex(['mapped_venue']); + $table->renameColumn('mapped_venue', 'venue'); + $table->index(['venue']); + }); + } +} From d461345fcfff7fe9e15e05cf26792c18e2d76749 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Mon, 13 Feb 2017 12:38:32 +0000 Subject: [PATCH 29/62] dev: upgraded composer packages --- composer.lock | 505 ++++++++++++++++++++++++++------------------------ 1 file changed, 258 insertions(+), 247 deletions(-) diff --git a/composer.lock b/composer.lock index 90a3794e..a52357e8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,25 +4,24 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e76003e428c05dd2ecad50593a5d7c7e", "content-hash": "1e1a72b5a999e3b23204b8f7039882e0", "packages": [ { "name": "classpreloader/classpreloader", - "version": "3.0.0", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/ClassPreloader/ClassPreloader.git", - "reference": "9b10b913c2bdf90c3d2e0d726b454fb7f77c552a" + "reference": "bc7206aa892b5a33f4680421b69b191efd32b096" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ClassPreloader/ClassPreloader/zipball/9b10b913c2bdf90c3d2e0d726b454fb7f77c552a", - "reference": "9b10b913c2bdf90c3d2e0d726b454fb7f77c552a", + "url": "https://api.github.com/repos/ClassPreloader/ClassPreloader/zipball/bc7206aa892b5a33f4680421b69b191efd32b096", + "reference": "bc7206aa892b5a33f4680421b69b191efd32b096", "shasum": "" }, "require": { - "nikic/php-parser": "^1.0|^2.0", + "nikic/php-parser": "^1.0|^2.0|^3.0", "php": ">=5.5.9" }, "require-dev": { @@ -31,7 +30,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -59,20 +58,20 @@ "class", "preload" ], - "time": "2015-11-09 22:51:51" + "time": "2016-09-16T12:50:15+00:00" }, { "name": "davejamesmiller/laravel-breadcrumbs", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/davejamesmiller/laravel-breadcrumbs.git", - "reference": "460bf79e83ff9e3db1e3f1c40169d8893893f8ff" + "reference": "6ca5a600003ecb52a5b5af14dad82033058604e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/davejamesmiller/laravel-breadcrumbs/zipball/460bf79e83ff9e3db1e3f1c40169d8893893f8ff", - "reference": "460bf79e83ff9e3db1e3f1c40169d8893893f8ff", + "url": "https://api.github.com/repos/davejamesmiller/laravel-breadcrumbs/zipball/6ca5a600003ecb52a5b5af14dad82033058604e1", + "reference": "6ca5a600003ecb52a5b5af14dad82033058604e1", "shasum": "" }, "require": { @@ -100,15 +99,15 @@ { "name": "Dave James Miller", "email": "dave@davejamesmiller.com", - "homepage": "http://davejamesmiller.com/" + "homepage": "https://davejamesmiller.com/" } ], "description": "A simple Laravel-style way to create breadcrumbs in Laravel 4+.", - "homepage": "http://laravel-breadcrumbs.davejamesmiller.com", + "homepage": "https://laravel-breadcrumbs.readthedocs.io/", "keywords": [ "laravel" ], - "time": "2016-08-28 16:57:03" + "time": "2017-01-30T21:16:53+00:00" }, { "name": "dnoegel/php-xdg-base-dir", @@ -141,7 +140,7 @@ "MIT" ], "description": "implementation of xdg base directory specification for php", - "time": "2014-10-24 07:27:01" + "time": "2014-10-24T07:27:01+00:00" }, { "name": "doctrine/inflector", @@ -208,7 +207,7 @@ "singularize", "string" ], - "time": "2015-11-06 14:35:42" + "time": "2015-11-06T14:35:42+00:00" }, { "name": "jakub-onderka/php-console-color", @@ -251,7 +250,7 @@ "homepage": "http://www.acci.cz" } ], - "time": "2014-04-08 15:00:19" + "time": "2014-04-08T15:00:19+00:00" }, { "name": "jakub-onderka/php-console-highlighter", @@ -295,24 +294,24 @@ "homepage": "http://www.acci.cz/" } ], - "time": "2015-04-20 18:58:01" + "time": "2015-04-20T18:58:01+00:00" }, { "name": "jeremeamia/SuperClosure", - "version": "2.2.0", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/jeremeamia/super_closure.git", - "reference": "29a88be2a4846d27c1613aed0c9071dfad7b5938" + "reference": "443c3df3207f176a1b41576ee2a66968a507b3db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jeremeamia/super_closure/zipball/29a88be2a4846d27c1613aed0c9071dfad7b5938", - "reference": "29a88be2a4846d27c1613aed0c9071dfad7b5938", + "url": "https://api.github.com/repos/jeremeamia/super_closure/zipball/443c3df3207f176a1b41576ee2a66968a507b3db", + "reference": "443c3df3207f176a1b41576ee2a66968a507b3db", "shasum": "" }, "require": { - "nikic/php-parser": "^1.2|^2.0", + "nikic/php-parser": "^1.2|^2.0|^3.0", "php": ">=5.4", "symfony/polyfill-php56": "^1.0" }, @@ -322,7 +321,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "2.3-dev" } }, "autoload": { @@ -353,7 +352,7 @@ "serialize", "tokenizer" ], - "time": "2015-12-05 17:17:57" + "time": "2016-12-07T09:37:55+00:00" }, { "name": "laracasts/flash", @@ -396,7 +395,7 @@ } ], "description": "Easy flash notifications", - "time": "2016-07-11 20:46:02" + "time": "2016-07-11T20:46:02+00:00" }, { "name": "laravel/framework", @@ -526,20 +525,20 @@ "framework", "laravel" ], - "time": "2016-08-26 11:44:52" + "time": "2016-08-26T11:44:52+00:00" }, { "name": "laravelcollective/html", - "version": "v5.2.4", + "version": "v5.2.5", "source": { "type": "git", "url": "https://github.com/LaravelCollective/html.git", - "reference": "3a312d39ffe37da0f57b602618b61fd07c1fcec5" + "reference": "8956f004753d7b1bc793076f6adfb678e31d1250" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/LaravelCollective/html/zipball/3a312d39ffe37da0f57b602618b61fd07c1fcec5", - "reference": "3a312d39ffe37da0f57b602618b61fd07c1fcec5", + "url": "https://api.github.com/repos/LaravelCollective/html/zipball/8956f004753d7b1bc793076f6adfb678e31d1250", + "reference": "8956f004753d7b1bc793076f6adfb678e31d1250", "shasum": "" }, "require": { @@ -580,24 +579,24 @@ ], "description": "HTML and Form Builders for the Laravel Framework", "homepage": "http://laravelcollective.com", - "time": "2016-01-27 22:29:54" + "time": "2016-12-13T14:28:46+00:00" }, { "name": "league/flysystem", - "version": "1.0.27", + "version": "1.0.35", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "50e2045ed70a7e75a5e30bc3662904f3b67af8a9" + "reference": "dda7f3ab94158a002d9846a97dc18ebfb7acc062" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/50e2045ed70a7e75a5e30bc3662904f3b67af8a9", - "reference": "50e2045ed70a7e75a5e30bc3662904f3b67af8a9", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/dda7f3ab94158a002d9846a97dc18ebfb7acc062", + "reference": "dda7f3ab94158a002d9846a97dc18ebfb7acc062", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": ">=5.5.9" }, "conflict": { "league/flysystem-sftp": "<1.0.6" @@ -663,20 +662,20 @@ "sftp", "storage" ], - "time": "2016-08-10 08:55:11" + "time": "2017-02-09T11:33:58+00:00" }, { "name": "monolog/monolog", - "version": "1.21.0", + "version": "1.22.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952" + "reference": "bad29cb8d18ab0315e6c477751418a82c850d558" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/f42fbdfd53e306bda545845e4dbfd3e72edb4952", - "reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bad29cb8d18ab0315e6c477751418a82c850d558", + "reference": "bad29cb8d18ab0315e6c477751418a82c850d558", "shasum": "" }, "require": { @@ -687,7 +686,7 @@ "psr/log-implementation": "1.0.0" }, "require-dev": { - "aws/aws-sdk-php": "^2.4.9", + "aws/aws-sdk-php": "^2.4.9 || ^3.0", "doctrine/couchdb": "~1.0@dev", "graylog2/gelf-php": "~1.0", "jakub-onderka/php-parallel-lint": "0.9", @@ -741,20 +740,20 @@ "logging", "psr-3" ], - "time": "2016-07-29 03:23:52" + "time": "2016-11-26T00:15:39+00:00" }, { "name": "mtdowling/cron-expression", - "version": "v1.1.0", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/mtdowling/cron-expression.git", - "reference": "c9ee7886f5a12902b225a1a12f36bb45f9ab89e5" + "reference": "9504fa9ea681b586028adaaa0877db4aecf32bad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mtdowling/cron-expression/zipball/c9ee7886f5a12902b225a1a12f36bb45f9ab89e5", - "reference": "c9ee7886f5a12902b225a1a12f36bb45f9ab89e5", + "url": "https://api.github.com/repos/mtdowling/cron-expression/zipball/9504fa9ea681b586028adaaa0877db4aecf32bad", + "reference": "9504fa9ea681b586028adaaa0877db4aecf32bad", "shasum": "" }, "require": { @@ -765,8 +764,8 @@ }, "type": "library", "autoload": { - "psr-0": { - "Cron": "src/" + "psr-4": { + "Cron\\": "src/Cron/" } }, "notification-url": "https://packagist.org/downloads/", @@ -785,30 +784,36 @@ "cron", "schedule" ], - "time": "2016-01-26 21:23:30" + "time": "2017-01-23T04:29:33+00:00" }, { "name": "nesbot/carbon", - "version": "1.21.0", + "version": "1.22.1", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "7b08ec6f75791e130012f206e3f7b0e76e18e3d7" + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/7b08ec6f75791e130012f206e3f7b0e76e18e3d7", - "reference": "7b08ec6f75791e130012f206e3f7b0e76e18e3d7", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", "shasum": "" }, "require": { "php": ">=5.3.0", - "symfony/translation": "~2.6|~3.0" + "symfony/translation": "~2.6 || ~3.0" }, "require-dev": { - "phpunit/phpunit": "~4.0|~5.0" + "friendsofphp/php-cs-fixer": "~2", + "phpunit/phpunit": "~4.0 || ~5.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.23-dev" + } + }, "autoload": { "psr-4": { "Carbon\\": "src/Carbon/" @@ -832,7 +837,7 @@ "datetime", "time" ], - "time": "2015-11-04 20:07:17" + "time": "2017-01-16T07:55:07+00:00" }, { "name": "nikic/php-parser", @@ -883,7 +888,7 @@ "parser", "php" ], - "time": "2016-09-16 12:04:44" + "time": "2016-09-16T12:04:44+00:00" }, { "name": "paragonie/random_compat", @@ -931,20 +936,20 @@ "pseudorandom", "random" ], - "time": "2016-03-18 20:34:03" + "time": "2016-03-18T20:34:03+00:00" }, { "name": "psr/log", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "5277094ed527a1c4477177d102fe4c53551953e0" + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/5277094ed527a1c4477177d102fe4c53551953e0", - "reference": "5277094ed527a1c4477177d102fe4c53551953e0", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", "shasum": "" }, "require": { @@ -978,7 +983,7 @@ "psr", "psr-3" ], - "time": "2016-09-19 16:02:08" + "time": "2016-10-10T12:19:37+00:00" }, { "name": "psy/psysh", @@ -1050,27 +1055,28 @@ "interactive", "shell" ], - "time": "2016-03-09 05:03:14" + "time": "2016-03-09T05:03:14+00:00" }, { "name": "swiftmailer/swiftmailer", - "version": "v5.4.3", + "version": "v5.4.6", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153" + "reference": "81fdccfaf8bdc5d5d7a1ef6bb3a61bbb1a6c4a3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", - "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/81fdccfaf8bdc5d5d7a1ef6bb3a61bbb1a6c4a3e", + "reference": "81fdccfaf8bdc5d5d7a1ef6bb3a61bbb1a6c4a3e", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "mockery/mockery": "~0.9.1" + "mockery/mockery": "~0.9.1", + "symfony/phpunit-bridge": "~3.2" }, "type": "library", "extra": { @@ -1103,7 +1109,7 @@ "mail", "mailer" ], - "time": "2016-07-08 11:51:25" + "time": "2017-02-13T07:52:53+00:00" }, { "name": "symfony/console", @@ -1163,7 +1169,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/debug", @@ -1220,20 +1226,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v3.1.4", + "version": "v3.2.3", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "c0c00c80b3a69132c4e55c3e7db32b4a387615e5" + "reference": "9137eb3a3328e413212826d63eeeb0217836e2b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/c0c00c80b3a69132c4e55c3e7db32b4a387615e5", - "reference": "c0c00c80b3a69132c4e55c3e7db32b4a387615e5", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9137eb3a3328e413212826d63eeeb0217836e2b6", + "reference": "9137eb3a3328e413212826d63eeeb0217836e2b6", "shasum": "" }, "require": { @@ -1253,7 +1259,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -1280,7 +1286,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-07-19 10:45:57" + "time": "2017-01-02T20:32:22+00:00" }, { "name": "symfony/finder", @@ -1329,7 +1335,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" + "time": "2016-06-29T05:40:00+00:00" }, { "name": "symfony/http-foundation", @@ -1382,7 +1388,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-07-17 13:54:30" + "time": "2016-07-17T13:54:30+00:00" }, { "name": "symfony/http-kernel", @@ -1464,20 +1470,20 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2016-07-30 09:10:37" + "time": "2016-07-30T09:10:37+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.2.0", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "dff51f72b0706335131b00a7f49606168c582594" + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594", - "reference": "dff51f72b0706335131b00a7f49606168c582594", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4", + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4", "shasum": "" }, "require": { @@ -1489,7 +1495,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.3-dev" } }, "autoload": { @@ -1523,20 +1529,20 @@ "portable", "shim" ], - "time": "2016-05-18 14:26:46" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/polyfill-php56", - "version": "v1.2.0", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php56.git", - "reference": "3edf57a8fbf9a927533344cef65ad7e1cf31030a" + "reference": "1dd42b9b89556f18092f3d1ada22cb05ac85383c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/3edf57a8fbf9a927533344cef65ad7e1cf31030a", - "reference": "3edf57a8fbf9a927533344cef65ad7e1cf31030a", + "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/1dd42b9b89556f18092f3d1ada22cb05ac85383c", + "reference": "1dd42b9b89556f18092f3d1ada22cb05ac85383c", "shasum": "" }, "require": { @@ -1546,7 +1552,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.3-dev" } }, "autoload": { @@ -1579,20 +1585,20 @@ "portable", "shim" ], - "time": "2016-05-18 14:26:46" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/polyfill-util", - "version": "v1.2.0", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-util.git", - "reference": "ef830ce3d218e622b221d6bfad42c751d974bf99" + "reference": "746bce0fca664ac0a575e465f65c6643faddf7fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/ef830ce3d218e622b221d6bfad42c751d974bf99", - "reference": "ef830ce3d218e622b221d6bfad42c751d974bf99", + "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/746bce0fca664ac0a575e465f65c6643faddf7fb", + "reference": "746bce0fca664ac0a575e465f65c6643faddf7fb", "shasum": "" }, "require": { @@ -1601,7 +1607,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.3-dev" } }, "autoload": { @@ -1631,7 +1637,7 @@ "polyfill", "shim" ], - "time": "2016-05-18 14:26:46" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/process", @@ -1680,7 +1686,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-07-28 11:13:34" + "time": "2016-07-28T11:13:34+00:00" }, { "name": "symfony/routing", @@ -1755,7 +1761,7 @@ "uri", "url" ], - "time": "2016-06-29 05:40:00" + "time": "2016-06-29T05:40:00+00:00" }, { "name": "symfony/translation", @@ -1819,7 +1825,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/var-dumper", @@ -1882,7 +1888,7 @@ "debug", "dump" ], - "time": "2016-07-26 08:03:56" + "time": "2016-07-26T08:03:56+00:00" }, { "name": "vlucas/phpdotenv", @@ -1932,22 +1938,22 @@ "env", "environment" ], - "time": "2016-09-01 10:05:43" + "time": "2016-09-01T10:05:43+00:00" } ], "packages-dev": [ { "name": "appzcoder/crud-generator", - "version": "v1.2.1", + "version": "v1.2.3", "source": { "type": "git", "url": "https://github.com/appzcoder/crud-generator.git", - "reference": "84e3a5071a04138f86ad0d21a5acc0b367027f5c" + "reference": "ab6805c276ab79d139dda24dcf58802b50fd00ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appzcoder/crud-generator/zipball/84e3a5071a04138f86ad0d21a5acc0b367027f5c", - "reference": "84e3a5071a04138f86ad0d21a5acc0b367027f5c", + "url": "https://api.github.com/repos/appzcoder/crud-generator/zipball/ab6805c276ab79d139dda24dcf58802b50fd00ae", + "reference": "ab6805c276ab79d139dda24dcf58802b50fd00ae", "shasum": "" }, "require": { @@ -1958,10 +1964,7 @@ "autoload": { "psr-4": { "Appzcoder\\CrudGenerator\\": "src/" - }, - "files": [ - "src/helpers.php" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1981,27 +1984,27 @@ "laravel", "laravel crud generator" ], - "time": "2016-09-17 04:59:18" + "time": "2016-09-28T18:05:53+00:00" }, { "name": "barryvdh/laravel-ide-helper", - "version": "v2.2.1", + "version": "v2.2.3", "source": { "type": "git", "url": "https://github.com/barryvdh/laravel-ide-helper.git", - "reference": "28af7cd19ca41cc0c63dd1de2b46c2b84d31c463" + "reference": "a7fc2ec489aada6062d3a63ddc915004a21e38af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-ide-helper/zipball/28af7cd19ca41cc0c63dd1de2b46c2b84d31c463", - "reference": "28af7cd19ca41cc0c63dd1de2b46c2b84d31c463", + "url": "https://api.github.com/repos/barryvdh/laravel-ide-helper/zipball/a7fc2ec489aada6062d3a63ddc915004a21e38af", + "reference": "a7fc2ec489aada6062d3a63ddc915004a21e38af", "shasum": "" }, "require": { "barryvdh/reflection-docblock": "^2.0.4", - "illuminate/console": "^5.0,<5.4", - "illuminate/filesystem": "^5.0,<5.4", - "illuminate/support": "^5.0,<5.4", + "illuminate/console": "^5.0,<5.5", + "illuminate/filesystem": "^5.0,<5.5", + "illuminate/support": "^5.0,<5.5", "php": ">=5.4.0", "symfony/class-loader": "^2.3|^3.0" }, @@ -2047,7 +2050,7 @@ "phpstorm", "sublime" ], - "time": "2016-07-04 11:52:48" + "time": "2017-01-05T21:20:42+00:00" }, { "name": "barryvdh/reflection-docblock", @@ -2096,39 +2099,39 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2016-06-13 19:28:20" + "time": "2016-06-13T19:28:20+00:00" }, { "name": "doctrine/annotations", - "version": "v1.2.7", + "version": "v1.3.1", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535" + "reference": "bd4461328621bde0ae6b1b2675fbc6aca4ceb558" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/f25c8aab83e0c3e976fd7d19875f198ccf2f7535", - "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/bd4461328621bde0ae6b1b2675fbc6aca4ceb558", + "reference": "bd4461328621bde0ae6b1b2675fbc6aca4ceb558", "shasum": "" }, "require": { "doctrine/lexer": "1.*", - "php": ">=5.3.2" + "php": "^5.6 || ^7.0" }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "4.*" + "phpunit/phpunit": "^5.6.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "1.4.x-dev" } }, "autoload": { - "psr-0": { - "Doctrine\\Common\\Annotations\\": "lib/" + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" } }, "notification-url": "https://packagist.org/downloads/", @@ -2164,20 +2167,20 @@ "docblock", "parser" ], - "time": "2015-08-31 12:32:49" + "time": "2016-12-30T15:59:45+00:00" }, { "name": "doctrine/cache", - "version": "v1.6.0", + "version": "v1.6.1", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6" + "reference": "b6f544a20f4807e81f7044d31e679ccbb1866dc3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/f8af318d14bdb0eff0336795b428b547bd39ccb6", - "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6", + "url": "https://api.github.com/repos/doctrine/cache/zipball/b6f544a20f4807e81f7044d31e679ccbb1866dc3", + "reference": "b6f544a20f4807e81f7044d31e679ccbb1866dc3", "shasum": "" }, "require": { @@ -2234,32 +2237,33 @@ "cache", "caching" ], - "time": "2015-12-31 16:37:02" + "time": "2016-10-29T11:16:17+00:00" }, { "name": "doctrine/collections", - "version": "v1.3.0", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/doctrine/collections.git", - "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a" + "reference": "1a4fb7e902202c33cce8c55989b945612943c2ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/6c1e4eef75f310ea1b3e30945e9f06e652128b8a", - "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "url": "https://api.github.com/repos/doctrine/collections/zipball/1a4fb7e902202c33cce8c55989b945612943c2ba", + "reference": "1a4fb7e902202c33cce8c55989b945612943c2ba", "shasum": "" }, "require": { - "php": ">=5.3.2" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "doctrine/coding-standard": "~0.1@dev", + "phpunit/phpunit": "^5.7" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -2300,20 +2304,20 @@ "collections", "iterator" ], - "time": "2015-04-14 22:21:58" + "time": "2017-01-03T10:49:41+00:00" }, { "name": "doctrine/common", - "version": "v2.6.1", + "version": "v2.7.2", "source": { "type": "git", "url": "https://github.com/doctrine/common.git", - "reference": "a579557bc689580c19fee4e27487a67fe60defc0" + "reference": "930297026c8009a567ac051fd545bf6124150347" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/common/zipball/a579557bc689580c19fee4e27487a67fe60defc0", - "reference": "a579557bc689580c19fee4e27487a67fe60defc0", + "url": "https://api.github.com/repos/doctrine/common/zipball/930297026c8009a567ac051fd545bf6124150347", + "reference": "930297026c8009a567ac051fd545bf6124150347", "shasum": "" }, "require": { @@ -2322,10 +2326,10 @@ "doctrine/collections": "1.*", "doctrine/inflector": "1.*", "doctrine/lexer": "1.*", - "php": "~5.5|~7.0" + "php": "~5.6|~7.0" }, "require-dev": { - "phpunit/phpunit": "~4.8|~5.0" + "phpunit/phpunit": "^5.4.6" }, "type": "library", "extra": { @@ -2373,24 +2377,24 @@ "persistence", "spl" ], - "time": "2015-12-25 13:18:31" + "time": "2017-01-13T14:02:13+00:00" }, { "name": "doctrine/dbal", - "version": "v2.5.5", + "version": "v2.5.12", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "9f8c05cd5225a320d56d4bfdb4772f10d045a0c9" + "reference": "7b9e911f9d8b30d43b96853dab26898c710d8f44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/9f8c05cd5225a320d56d4bfdb4772f10d045a0c9", - "reference": "9f8c05cd5225a320d56d4bfdb4772f10d045a0c9", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/7b9e911f9d8b30d43b96853dab26898c710d8f44", + "reference": "7b9e911f9d8b30d43b96853dab26898c710d8f44", "shasum": "" }, "require": { - "doctrine/common": ">=2.4,<2.7-dev", + "doctrine/common": ">=2.4,<2.8-dev", "php": ">=5.3.2" }, "require-dev": { @@ -2444,7 +2448,7 @@ "persistence", "queryobject" ], - "time": "2016-09-09 19:13:33" + "time": "2017-02-08T12:53:47+00:00" }, { "name": "doctrine/instantiator", @@ -2498,7 +2502,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "doctrine/lexer", @@ -2552,7 +2556,7 @@ "lexer", "parser" ], - "time": "2014-09-09 13:34:57" + "time": "2014-09-09T13:34:57+00:00" }, { "name": "fzaninotto/faker", @@ -2600,7 +2604,7 @@ "faker", "fixtures" ], - "time": "2016-04-29 12:21:54" + "time": "2016-04-29T12:21:54+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -2645,20 +2649,20 @@ "keywords": [ "test" ], - "time": "2015-05-11 14:41:42" + "time": "2015-05-11T14:41:42+00:00" }, { "name": "mockery/mockery", - "version": "0.9.5", + "version": "0.9.8", "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "4db079511a283e5aba1b3c2fb19037c645e70fc2" + "reference": "1e5e2ffdc4d71d7358ed58a6fdd30a4a0c506855" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/4db079511a283e5aba1b3c2fb19037c645e70fc2", - "reference": "4db079511a283e5aba1b3c2fb19037c645e70fc2", + "url": "https://api.github.com/repos/padraic/mockery/zipball/1e5e2ffdc4d71d7358ed58a6fdd30a4a0c506855", + "reference": "1e5e2ffdc4d71d7358ed58a6fdd30a4a0c506855", "shasum": "" }, "require": { @@ -2710,20 +2714,20 @@ "test double", "testing" ], - "time": "2016-05-22 21:52:33" + "time": "2017-02-09T13:29:38+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.5.4", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f" + "reference": "5a5a9fc8025a08d8919be87d6884d5a92520cefe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/ea74994a3dc7f8d2f65a06009348f2d63c81e61f", - "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/5a5a9fc8025a08d8919be87d6884d5a92520cefe", + "reference": "5a5a9fc8025a08d8919be87d6884d5a92520cefe", "shasum": "" }, "require": { @@ -2752,7 +2756,7 @@ "object", "object graph" ], - "time": "2016-09-16 13:37:59" + "time": "2017-01-26T22:05:40+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -2806,20 +2810,20 @@ "reflection", "static analysis" ], - "time": "2015-12-27 11:43:31" + "time": "2015-12-27T11:43:31+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", "shasum": "" }, "require": { @@ -2851,20 +2855,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-06-10 09:48:41" + "time": "2016-09-30T07:12:33+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.2", + "version": "0.2.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", "shasum": "" }, "require": { @@ -2898,20 +2902,20 @@ "email": "me@mikevanriel.com" } ], - "time": "2016-06-10 07:14:17" + "time": "2016-11-25T06:54:22+00:00" }, { "name": "phpspec/prophecy", - "version": "v1.6.1", + "version": "v1.6.2", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "58a8137754bc24b25740d4281399a4a3596058e0" + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0", - "reference": "58a8137754bc24b25740d4281399a4a3596058e0", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/6c52c2722f8460122f96f86346600e1077ce22cb", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb", "shasum": "" }, "require": { @@ -2919,10 +2923,11 @@ "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", "sebastian/comparator": "^1.1", - "sebastian/recursion-context": "^1.0" + "sebastian/recursion-context": "^1.0|^2.0" }, "require-dev": { - "phpspec/phpspec": "^2.0" + "phpspec/phpspec": "^2.0", + "phpunit/phpunit": "^4.8 || ^5.6.5" }, "type": "library", "extra": { @@ -2960,7 +2965,7 @@ "spy", "stub" ], - "time": "2016-06-07 08:13:47" + "time": "2016-11-21T14:58:47+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3023,20 +3028,20 @@ "testing", "xunit" ], - "time": "2016-05-27 16:24:29" + "time": "2016-05-27T16:24:29+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", "shasum": "" }, "require": { @@ -3070,7 +3075,7 @@ "filesystem", "iterator" ], - "time": "2015-06-21 13:08:43" + "time": "2016-10-03T07:40:28+00:00" }, { "name": "phpunit/php-text-template", @@ -3111,7 +3116,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -3155,20 +3160,20 @@ "keywords": [ "timer" ], - "time": "2016-05-12 18:03:57" + "time": "2016-05-12T18:03:57+00:00" }, { "name": "phpunit/php-token-stream", - "version": "1.4.8", + "version": "1.4.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b", "shasum": "" }, "require": { @@ -3204,7 +3209,7 @@ "keywords": [ "tokenizer" ], - "time": "2015-09-15 10:49:45" + "time": "2016-11-15T14:06:22+00:00" }, { "name": "phpunit/phpunit", @@ -3278,7 +3283,7 @@ "testing", "xunit" ], - "time": "2016-03-15 05:59:58" + "time": "2016-03-15T05:59:58+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -3334,7 +3339,7 @@ "mock", "xunit" ], - "time": "2016-04-20 14:39:26" + "time": "2016-04-20T14:39:26+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -3379,26 +3384,26 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2016-02-13 06:45:14" + "time": "2016-02-13T06:45:14+00:00" }, { "name": "sebastian/comparator", - "version": "1.2.0", + "version": "1.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", "shasum": "" }, "require": { "php": ">=5.3.3", "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2" + "sebastian/exporter": "~1.2 || ~2.0" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -3443,7 +3448,7 @@ "compare", "equality" ], - "time": "2015-07-26 15:48:44" + "time": "2017-01-29T09:50:25+00:00" }, { "name": "sebastian/diff", @@ -3495,7 +3500,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08 07:14:41" + "time": "2015-12-08T07:14:41+00:00" }, { "name": "sebastian/environment", @@ -3545,7 +3550,7 @@ "environment", "hhvm" ], - "time": "2016-08-18 05:49:44" + "time": "2016-08-18T05:49:44+00:00" }, { "name": "sebastian/exporter", @@ -3612,7 +3617,7 @@ "export", "exporter" ], - "time": "2016-06-17 09:04:28" + "time": "2016-06-17T09:04:28+00:00" }, { "name": "sebastian/global-state", @@ -3663,7 +3668,7 @@ "keywords": [ "global state" ], - "time": "2015-10-12 03:26:01" + "time": "2015-10-12T03:26:01+00:00" }, { "name": "sebastian/recursion-context", @@ -3716,7 +3721,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11 19:50:13" + "time": "2015-11-11T19:50:13+00:00" }, { "name": "sebastian/resource-operations", @@ -3758,20 +3763,20 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28 20:34:47" + "time": "2015-07-28T20:34:47+00:00" }, { "name": "sebastian/version", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5" + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", - "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", "shasum": "" }, "require": { @@ -3801,20 +3806,20 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-02-04 12:56:52" + "time": "2016-10-03T07:35:21+00:00" }, { "name": "symfony/class-loader", - "version": "v3.1.4", + "version": "v3.2.3", "source": { "type": "git", "url": "https://github.com/symfony/class-loader.git", - "reference": "2d0ba77c46ecc96a6641009a98f72632216811ba" + "reference": "2847d56f518ad5721bf85aa9174b3aa3fd12aa03" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/class-loader/zipball/2d0ba77c46ecc96a6641009a98f72632216811ba", - "reference": "2d0ba77c46ecc96a6641009a98f72632216811ba", + "url": "https://api.github.com/repos/symfony/class-loader/zipball/2847d56f518ad5721bf85aa9174b3aa3fd12aa03", + "reference": "2847d56f518ad5721bf85aa9174b3aa3fd12aa03", "shasum": "" }, "require": { @@ -3830,7 +3835,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -3857,7 +3862,7 @@ ], "description": "Symfony ClassLoader Component", "homepage": "https://symfony.com", - "time": "2016-08-23 13:39:15" + "time": "2017-01-21T17:06:35+00:00" }, { "name": "symfony/css-selector", @@ -3910,7 +3915,7 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" + "time": "2016-06-29T05:40:00+00:00" }, { "name": "symfony/dom-crawler", @@ -3966,29 +3971,35 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/yaml", - "version": "v3.1.4", + "version": "v3.2.3", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d" + "reference": "e1718c6bf57e1efbb8793ada951584b2ab27775b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/f291ed25eb1435bddbe8a96caaef16469c2a092d", - "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d", + "url": "https://api.github.com/repos/symfony/yaml/zipball/e1718c6bf57e1efbb8793ada951584b2ab27775b", + "reference": "e1718c6bf57e1efbb8793ada951584b2ab27775b", "shasum": "" }, "require": { "php": ">=5.5.9" }, + "require-dev": { + "symfony/console": "~2.8|~3.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -4015,24 +4026,24 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-09-02 02:12:52" + "time": "2017-01-21T17:06:35+00:00" }, { "name": "webmozart/assert", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "bb2d123231c095735130cc8f6d31385a44c7b308" + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bb2d123231c095735130cc8f6d31385a44c7b308", - "reference": "bb2d123231c095735130cc8f6d31385a44c7b308", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", "shasum": "" }, "require": { - "php": "^5.3.3|^7.0" + "php": "^5.3.3 || ^7.0" }, "require-dev": { "phpunit/phpunit": "^4.6", @@ -4041,7 +4052,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.3-dev" } }, "autoload": { @@ -4065,7 +4076,7 @@ "check", "validate" ], - "time": "2016-08-09 15:02:57" + "time": "2016-11-23T20:04:58+00:00" } ], "aliases": [], From 2f01ec631646730c31d7a7920cb173739cc2c7e0 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Mon, 13 Feb 2017 12:38:56 +0000 Subject: [PATCH 30/62] dev: moved to LVA base namespace --- app/Console/Kernel.php | 3 +- app/Events/Event.php | 2 +- app/Exceptions/Handler.php | 2 +- .../AvailableAppointmentsController.php | 16 ++++----- .../Admin/DataManagement/ClubsController.php | 12 +++---- .../DataManagement/DivisionsController.php | 14 ++++---- .../DataManagement/FixturesController.php | 18 +++++----- .../Admin/DataManagement/LoadController.php | 10 +++--- .../Admin/DataManagement/RolesController.php | 12 +++---- .../DataManagement/SeasonsController.php | 12 +++---- .../Admin/DataManagement/TeamsController.php | 14 ++++---- .../Admin/DataManagement/VenuesController.php | 12 +++---- .../Admin/DataManagementController.php | 4 +-- .../Api/v1/UploadApiController.php | 24 ++++++------- app/Http/Controllers/Auth/AuthController.php | 6 ++-- .../Controllers/Auth/PasswordController.php | 4 +-- app/Http/Controllers/Controller.php | 2 +- app/Http/Controllers/HomeController.php | 4 +-- app/Http/Kernel.php | 10 +++--- app/Http/Middleware/Authenticate.php | 2 +- app/Http/Middleware/EncryptCookies.php | 2 +- .../Middleware/RedirectIfAuthenticated.php | 2 +- app/Http/Middleware/VerifyCsrfToken.php | 2 +- app/Http/Requests/Api/v1/MapTeamRequest.php | 6 ++-- app/Http/Requests/Api/v1/MapVenueRequest.php | 6 ++-- app/Http/Requests/Api/v1/NewVenueRequest.php | 6 ++-- app/Http/Requests/Request.php | 2 +- .../StoreAvailableAppointmentRequest.php | 4 +-- app/Http/Requests/StoreClubRequest.php | 4 +-- app/Http/Requests/StoreDivisionRequest.php | 4 +-- app/Http/Requests/StoreFixtureRequest.php | 4 +-- app/Http/Requests/StoreRoleRequest.php | 4 +-- app/Http/Requests/StoreSeasonRequest.php | 4 +-- app/Http/Requests/StoreTeamRequest.php | 4 +-- app/Http/Requests/StoreVenueRequest.php | 4 +-- .../UpdateAvailableAppointmentRequest.php | 4 +-- app/Http/Requests/UpdateClubRequest.php | 4 +-- app/Http/Requests/UpdateDivisionRequest.php | 4 +-- app/Http/Requests/UpdateFixtureRequest.php | 4 +-- app/Http/Requests/UpdateRoleRequest.php | 4 +-- app/Http/Requests/UpdateSeasonRequest.php | 4 +-- app/Http/Requests/UpdateTeamRequest.php | 4 +-- app/Http/Requests/UpdateVenueRequest.php | 4 +-- app/Jobs/Job.php | 2 +- app/Models/AvailableAppointment.php | 4 +-- app/Models/Club.php | 4 +-- app/Models/Division.php | 4 +-- app/Models/Fixture.php | 4 +-- app/Models/MappedTeam.php | 4 +-- app/Models/MappedVenue.php | 4 +-- app/Models/NewVenue.php | 4 +-- app/Models/Role.php | 4 +-- app/Models/Season.php | 4 +-- app/Models/Team.php | 4 +-- app/Models/TeamSynonym.php | 4 +-- app/Models/UploadJob.php | 4 +-- app/Models/UploadJobData.php | 4 +-- app/Models/UploadJobStatus.php | 4 +-- app/Models/Venue.php | 4 +-- app/Models/VenueSynonym.php | 4 +-- app/Providers/AppServiceProvider.php | 4 +-- app/Providers/AuthServiceProvider.php | 4 +-- app/Providers/EventServiceProvider.php | 8 ++--- app/Providers/RouteServiceProvider.php | 6 ++-- app/Repositories/TeamsRepository.php | 12 +++---- app/Repositories/VenuesRepository.php | 8 ++--- .../Contracts/InteractiveUploadContract.php | 4 +-- .../InteractiveFixturesUploadService.php | 28 +++++++-------- app/Services/MappingService.php | 4 +-- app/Services/StatusService.php | 6 ++-- app/Services/UploadDataService.php | 4 +-- app/User.php | 4 +-- app/Validators/CustomValidators.php | 4 +-- bootstrap/app.php | 6 ++-- composer.json | 2 +- config/app.php | 8 ++--- config/auth.php | 2 +- config/services.php | 2 +- database/factories/ModelFactory.php | 34 +++++++++---------- .../AvailableAppointmentsTableTest.php | 6 ++-- tests/Admin/DataManagement/ClubsTableTest.php | 4 +-- .../DataManagement/DivisionsTableTest.php | 6 ++-- .../DataManagement/FixturesTableTest.php | 4 +-- tests/Admin/DataManagement/RolesTableTest.php | 4 +-- .../Admin/DataManagement/SeasonsTableTest.php | 4 +-- tests/Admin/DataManagement/TeamsTableTest.php | 6 ++-- .../Admin/DataManagement/VenuesTableTest.php | 4 +-- tests/Authentication/LoginLogoutTest.php | 1 - tests/TestCase.php | 2 +- 89 files changed, 264 insertions(+), 266 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5497b0b5..4bb7ae3b 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -1,8 +1,7 @@ [ - \App\Http\Middleware\EncryptCookies::class, + \LVA\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \App\Http\Middleware\VerifyCsrfToken::class, + \LVA\Http\Middleware\VerifyCsrfToken::class, ], 'api' => [ @@ -44,9 +44,9 @@ class Kernel extends HttpKernel * @var array */ protected $routeMiddleware = [ - 'auth' => \App\Http\Middleware\Authenticate::class, + 'auth' => \LVA\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'guest' => \LVA\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 67abcaea..cf630326 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -1,6 +1,6 @@ 'App\Policies\ModelPolicy', + //'App\Model' => 'App\Policies\ModelPolicy', ]; /** diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 58ce9624..6609fefc 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -1,6 +1,6 @@ [ - 'App\Listeners\EventListener', - ], + //'App\Events\SomeEvent' => [ + // 'App\Listeners\EventListener', + //], ]; /** diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index d65eb737..a2f93e20 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -1,8 +1,8 @@ singleton( Illuminate\Contracts\Http\Kernel::class, - App\Http\Kernel::class + LVA\Http\Kernel::class ); $app->singleton( Illuminate\Contracts\Console\Kernel::class, - App\Console\Kernel::class + LVA\Console\Kernel::class ); $app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, - App\Exceptions\Handler::class + LVA\Exceptions\Handler::class ); /* diff --git a/composer.json b/composer.json index 7e3b655b..71558113 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "database" ], "psr-4": { - "App\\": "app/" + "LVA\\": "app/" } }, "autoload-dev": { diff --git a/config/app.php b/config/app.php index 26fe4597..39a67a8a 100644 --- a/config/app.php +++ b/config/app.php @@ -151,10 +151,10 @@ /* * Application Service Providers... */ - App\Providers\AppServiceProvider::class, - App\Providers\AuthServiceProvider::class, - App\Providers\EventServiceProvider::class, - App\Providers\RouteServiceProvider::class, + LVA\Providers\AppServiceProvider::class, + LVA\Providers\AuthServiceProvider::class, + LVA\Providers\EventServiceProvider::class, + LVA\Providers\RouteServiceProvider::class, DaveJamesMiller\Breadcrumbs\ServiceProvider::class, Collective\Html\HtmlServiceProvider::class, diff --git a/config/auth.php b/config/auth.php index 3fa7f491..c98aac4d 100644 --- a/config/auth.php +++ b/config/auth.php @@ -67,7 +67,7 @@ 'providers' => [ 'users' => [ 'driver' => 'eloquent', - 'model' => App\User::class, + 'model' => LVA\User::class, ], // 'users' => [ diff --git a/config/services.php b/config/services.php index 93eec863..fa5ce29c 100644 --- a/config/services.php +++ b/config/services.php @@ -30,7 +30,7 @@ ], 'stripe' => [ - 'model' => App\User::class, + 'model' => LVA\User::class, 'key' => env('STRIPE_KEY'), 'secret' => env('STRIPE_SECRET'), ], diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index c3334a46..22a0357f 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -11,7 +11,7 @@ | */ -$factory->define(App\User::class, function (Faker\Generator $faker) { +$factory->define(LVA\User::class, function (Faker\Generator $faker) { return [ 'name' => $faker->unique()->name, 'email' => $faker->unique()->email, @@ -20,61 +20,61 @@ ]; }); -$factory->define(\App\Models\Season::class, function (\Faker\Generator $faker) { +$factory->define(\LVA\Models\Season::class, function (\Faker\Generator $faker) { return [ 'season' => $faker->unique()->word, ]; }); -$factory->define(App\Models\Division::class, function (\Faker\Generator $faker) { +$factory->define(LVA\Models\Division::class, function (\Faker\Generator $faker) { return [ 'division' => $faker->unique()->word, 'season_id' => function () { - return factory(App\Models\Season::class)->create()->id; + return factory(LVA\Models\Season::class)->create()->id; }, ]; }); -$factory->define(\App\Models\Club::class, function (\Faker\Generator $faker) { +$factory->define(\LVA\Models\Club::class, function (\Faker\Generator $faker) { return [ 'club' => $faker->unique()->word, ]; }); -$factory->define(App\Models\Team::class, function (\Faker\Generator $faker) { +$factory->define(LVA\Models\Team::class, function (\Faker\Generator $faker) { return [ 'team' => $faker->unique()->word, 'club_id' => function () { - return factory(App\Models\Club::class)->create()->id; + return factory(LVA\Models\Club::class)->create()->id; }, ]; }); -$factory->define(\App\Models\Role::class, function (\Faker\Generator $faker) { +$factory->define(\LVA\Models\Role::class, function (\Faker\Generator $faker) { return [ 'role' => $faker->unique()->word, ]; }); -$factory->define(\App\Models\Venue::class, function (\Faker\Generator $faker) { +$factory->define(\LVA\Models\Venue::class, function (\Faker\Generator $faker) { return [ 'venue' => $faker->unique()->word, ]; }); -$factory->define(\App\Models\Fixture::class, function (\Faker\Generator $faker) { +$factory->define(\LVA\Models\Fixture::class, function (\Faker\Generator $faker) { return [ 'division_id' => function () { - return factory(\App\Models\Division::class)->create()->id; + return factory(\LVA\Models\Division::class)->create()->id; }, 'home_team_id' => function () { - return factory(\App\Models\Team::class)->create()->id; + return factory(\LVA\Models\Team::class)->create()->id; }, 'away_team_id' => function () { - return factory(\App\Models\Team::class)->create()->id; + return factory(\LVA\Models\Team::class)->create()->id; }, 'venue_id' => function () { - return factory(\App\Models\Venue::class)->create()->id; + return factory(\LVA\Models\Venue::class)->create()->id; }, 'match_number' => $faker->unique()->numberBetween(1, 100), 'match_date' => $faker->unique()->date('Y-m-d'), @@ -83,13 +83,13 @@ ]; }); -$factory->define(\App\Models\AvailableAppointment::class, function (\Faker\Generator $faker) { +$factory->define(\LVA\Models\AvailableAppointment::class, function (\Faker\Generator $faker) { return [ 'fixture_id' => function () { - return factory(\App\Models\Fixture::class)->create()->id; + return factory(\LVA\Models\Fixture::class)->create()->id; }, 'role_id' => function () { - return factory(\App\Models\Role::class)->create()->id; + return factory(\LVA\Models\Role::class)->create()->id; }, ]; }); \ No newline at end of file diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php index 482f249c..a38c02ea 100644 --- a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -9,9 +9,9 @@ namespace Admin\DataManagement; use Tests\TestCase; -use App\Models\AvailableAppointment; -use App\Models\Fixture; -use App\Models\Role; +use LVA\Models\AvailableAppointment; +use LVA\Models\Fixture; +use LVA\Models\Role; class AvailableAppointmentsTableTest extends TestCase { diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/Admin/DataManagement/ClubsTableTest.php index 2f8689f8..dc0ce2e2 100644 --- a/tests/Admin/DataManagement/ClubsTableTest.php +++ b/tests/Admin/DataManagement/ClubsTableTest.php @@ -8,9 +8,9 @@ namespace Admin\DataManagement; -use App\Models\Team; +use LVA\Models\Team; use Tests\TestCase; -use App\Models\Club; +use LVA\Models\Club; class ClubsTableTest extends TestCase { diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/Admin/DataManagement/DivisionsTableTest.php index fcae02aa..90a04f65 100644 --- a/tests/Admin/DataManagement/DivisionsTableTest.php +++ b/tests/Admin/DataManagement/DivisionsTableTest.php @@ -8,10 +8,10 @@ namespace Admin\DataManagement; -use App\Models\Fixture; +use LVA\Models\Fixture; use Tests\TestCase; -use App\Models\Division; -use App\Models\Season; +use LVA\Models\Division; +use LVA\Models\Season; class DivisionsTableTest extends TestCase { diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php index c3c52651..369eee35 100644 --- a/tests/Admin/DataManagement/FixturesTableTest.php +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -8,9 +8,9 @@ namespace Admin\DataManagement; -use App\Models\AvailableAppointment; +use LVA\Models\AvailableAppointment; use Tests\TestCase; -use App\Models\Fixture; +use LVA\Models\Fixture; class FixturesTableTest extends TestCase { diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/Admin/DataManagement/RolesTableTest.php index 33cbfbad..7b1c2ff8 100644 --- a/tests/Admin/DataManagement/RolesTableTest.php +++ b/tests/Admin/DataManagement/RolesTableTest.php @@ -8,9 +8,9 @@ namespace Admin\DataManagement; -use App\Models\AvailableAppointment; +use LVA\Models\AvailableAppointment; use Tests\TestCase; -use App\Models\Role; +use LVA\Models\Role; class RolesTableTest extends TestCase { diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index f80d9021..196ba8a4 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -8,10 +8,10 @@ namespace Admin\DataManagement; -use App\Models\Division; +use LVA\Models\Division; use PhpParser\Node\Expr\AssignOp\Div; use Tests\TestCase; -use App\Models\Season; +use LVA\Models\Season; class SeasonsTableTest extends TestCase { diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/Admin/DataManagement/TeamsTableTest.php index 6a9624d0..f3cd3460 100644 --- a/tests/Admin/DataManagement/TeamsTableTest.php +++ b/tests/Admin/DataManagement/TeamsTableTest.php @@ -8,10 +8,10 @@ namespace Admin\DataManagement; -use App\Models\Fixture; +use LVA\Models\Fixture; use Tests\TestCase; -use App\Models\Team; -use App\Models\Club; +use LVA\Models\Team; +use LVA\Models\Club; class TeamsTableTest extends TestCase { diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/Admin/DataManagement/VenuesTableTest.php index 7fd8da3c..1c7d88a6 100644 --- a/tests/Admin/DataManagement/VenuesTableTest.php +++ b/tests/Admin/DataManagement/VenuesTableTest.php @@ -8,9 +8,9 @@ namespace Admin\DataManagement; -use App\Models\Fixture; +use LVA\Models\Fixture; use Tests\TestCase; -use App\Models\Venue; +use LVA\Models\Venue; class VenuesTableTest extends TestCase { diff --git a/tests/Authentication/LoginLogoutTest.php b/tests/Authentication/LoginLogoutTest.php index e6c33cf1..5bbbcf84 100644 --- a/tests/Authentication/LoginLogoutTest.php +++ b/tests/Authentication/LoginLogoutTest.php @@ -2,7 +2,6 @@ namespace Authentication; -use App; use Tests\TestCase; class LoginLogoutTest extends TestCase diff --git a/tests/TestCase.php b/tests/TestCase.php index 271fcdb7..d8ce8315 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,7 +4,7 @@ use Illuminate\Contracts\Console\Kernel; use Artisan; -use App\User; +use LVA\User; class TestCase extends \Illuminate\Foundation\Testing\TestCase { From a40d32f33dc31a61e7ef88c4ed95df8d5101d9af Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Wed, 15 Feb 2017 17:05:54 +0000 Subject: [PATCH 31/62] dev: added the APP_URL parameter to the .env --- .env.example | 1 + config/app.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 3d884761..bab9c2dd 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ APP_ENV=local APP_DEBUG=true APP_KEY=SomeRandomString +APP_URL= DB_HOST=127.0.0.1 DB_DATABASE=homestead diff --git a/config/app.php b/config/app.php index 39a67a8a..e92fd777 100644 --- a/config/app.php +++ b/config/app.php @@ -39,7 +39,7 @@ | */ - 'url' => 'http://localhost', + 'url' => env('APP_URL', 'http://localhost'), /* |-------------------------------------------------------------------------- From d6b85b565d2233d9005a8a5c082a9f71bdf445a6 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Fri, 3 Mar 2017 19:24:05 +0000 Subject: [PATCH 32/62] dev: fixed the change to LVA namespace --- app/Repositories/VenuesRepository.php | 4 ++-- app/Services/InteractiveFixturesUploadService.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Repositories/VenuesRepository.php b/app/Repositories/VenuesRepository.php index 66224273..141ad48c 100644 --- a/app/Repositories/VenuesRepository.php +++ b/app/Repositories/VenuesRepository.php @@ -1,7 +1,7 @@ Date: Fri, 3 Mar 2017 19:24:17 +0000 Subject: [PATCH 33/62] dev: update composer packages --- composer.lock | 224 ++++++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 109 deletions(-) diff --git a/composer.lock b/composer.lock index a52357e8..db275bf3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,6 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], + "hash": "e2e2866df0ed28d53bc785d61c0e743c", "content-hash": "1e1a72b5a999e3b23204b8f7039882e0", "packages": [ { @@ -58,7 +59,7 @@ "class", "preload" ], - "time": "2016-09-16T12:50:15+00:00" + "time": "2016-09-16 12:50:15" }, { "name": "davejamesmiller/laravel-breadcrumbs", @@ -107,7 +108,7 @@ "keywords": [ "laravel" ], - "time": "2017-01-30T21:16:53+00:00" + "time": "2017-01-30 21:16:53" }, { "name": "dnoegel/php-xdg-base-dir", @@ -140,7 +141,7 @@ "MIT" ], "description": "implementation of xdg base directory specification for php", - "time": "2014-10-24T07:27:01+00:00" + "time": "2014-10-24 07:27:01" }, { "name": "doctrine/inflector", @@ -207,7 +208,7 @@ "singularize", "string" ], - "time": "2015-11-06T14:35:42+00:00" + "time": "2015-11-06 14:35:42" }, { "name": "jakub-onderka/php-console-color", @@ -250,7 +251,7 @@ "homepage": "http://www.acci.cz" } ], - "time": "2014-04-08T15:00:19+00:00" + "time": "2014-04-08 15:00:19" }, { "name": "jakub-onderka/php-console-highlighter", @@ -294,7 +295,7 @@ "homepage": "http://www.acci.cz/" } ], - "time": "2015-04-20T18:58:01+00:00" + "time": "2015-04-20 18:58:01" }, { "name": "jeremeamia/SuperClosure", @@ -352,7 +353,7 @@ "serialize", "tokenizer" ], - "time": "2016-12-07T09:37:55+00:00" + "time": "2016-12-07 09:37:55" }, { "name": "laracasts/flash", @@ -395,7 +396,7 @@ } ], "description": "Easy flash notifications", - "time": "2016-07-11T20:46:02+00:00" + "time": "2016-07-11 20:46:02" }, { "name": "laravel/framework", @@ -525,7 +526,7 @@ "framework", "laravel" ], - "time": "2016-08-26T11:44:52+00:00" + "time": "2016-08-26 11:44:52" }, { "name": "laravelcollective/html", @@ -579,7 +580,7 @@ ], "description": "HTML and Form Builders for the Laravel Framework", "homepage": "http://laravelcollective.com", - "time": "2016-12-13T14:28:46+00:00" + "time": "2016-12-13 14:28:46" }, { "name": "league/flysystem", @@ -662,7 +663,7 @@ "sftp", "storage" ], - "time": "2017-02-09T11:33:58+00:00" + "time": "2017-02-09 11:33:58" }, { "name": "monolog/monolog", @@ -740,7 +741,7 @@ "logging", "psr-3" ], - "time": "2016-11-26T00:15:39+00:00" + "time": "2016-11-26 00:15:39" }, { "name": "mtdowling/cron-expression", @@ -784,7 +785,7 @@ "cron", "schedule" ], - "time": "2017-01-23T04:29:33+00:00" + "time": "2017-01-23 04:29:33" }, { "name": "nesbot/carbon", @@ -837,7 +838,7 @@ "datetime", "time" ], - "time": "2017-01-16T07:55:07+00:00" + "time": "2017-01-16 07:55:07" }, { "name": "nikic/php-parser", @@ -888,7 +889,7 @@ "parser", "php" ], - "time": "2016-09-16T12:04:44+00:00" + "time": "2016-09-16 12:04:44" }, { "name": "paragonie/random_compat", @@ -936,7 +937,7 @@ "pseudorandom", "random" ], - "time": "2016-03-18T20:34:03+00:00" + "time": "2016-03-18 20:34:03" }, { "name": "psr/log", @@ -983,7 +984,7 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2016-10-10 12:19:37" }, { "name": "psy/psysh", @@ -1055,7 +1056,7 @@ "interactive", "shell" ], - "time": "2016-03-09T05:03:14+00:00" + "time": "2016-03-09 05:03:14" }, { "name": "swiftmailer/swiftmailer", @@ -1109,7 +1110,7 @@ "mail", "mailer" ], - "time": "2017-02-13T07:52:53+00:00" + "time": "2017-02-13 07:52:53" }, { "name": "symfony/console", @@ -1169,7 +1170,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-07-30T07:22:48+00:00" + "time": "2016-07-30 07:22:48" }, { "name": "symfony/debug", @@ -1226,11 +1227,11 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-07-30T07:22:48+00:00" + "time": "2016-07-30 07:22:48" }, { "name": "symfony/event-dispatcher", - "version": "v3.2.3", + "version": "v3.2.4", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -1286,7 +1287,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-01-02T20:32:22+00:00" + "time": "2017-01-02 20:32:22" }, { "name": "symfony/finder", @@ -1335,7 +1336,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2016-06-29T05:40:00+00:00" + "time": "2016-06-29 05:40:00" }, { "name": "symfony/http-foundation", @@ -1388,7 +1389,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-07-17T13:54:30+00:00" + "time": "2016-07-17 13:54:30" }, { "name": "symfony/http-kernel", @@ -1470,7 +1471,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2016-07-30T09:10:37+00:00" + "time": "2016-07-30 09:10:37" }, { "name": "symfony/polyfill-mbstring", @@ -1529,7 +1530,7 @@ "portable", "shim" ], - "time": "2016-11-14T01:06:16+00:00" + "time": "2016-11-14 01:06:16" }, { "name": "symfony/polyfill-php56", @@ -1585,7 +1586,7 @@ "portable", "shim" ], - "time": "2016-11-14T01:06:16+00:00" + "time": "2016-11-14 01:06:16" }, { "name": "symfony/polyfill-util", @@ -1637,7 +1638,7 @@ "polyfill", "shim" ], - "time": "2016-11-14T01:06:16+00:00" + "time": "2016-11-14 01:06:16" }, { "name": "symfony/process", @@ -1686,7 +1687,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-07-28T11:13:34+00:00" + "time": "2016-07-28 11:13:34" }, { "name": "symfony/routing", @@ -1761,7 +1762,7 @@ "uri", "url" ], - "time": "2016-06-29T05:40:00+00:00" + "time": "2016-06-29 05:40:00" }, { "name": "symfony/translation", @@ -1825,7 +1826,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2016-07-30T07:22:48+00:00" + "time": "2016-07-30 07:22:48" }, { "name": "symfony/var-dumper", @@ -1888,7 +1889,7 @@ "debug", "dump" ], - "time": "2016-07-26T08:03:56+00:00" + "time": "2016-07-26 08:03:56" }, { "name": "vlucas/phpdotenv", @@ -1938,7 +1939,7 @@ "env", "environment" ], - "time": "2016-09-01T10:05:43+00:00" + "time": "2016-09-01 10:05:43" } ], "packages-dev": [ @@ -1984,20 +1985,20 @@ "laravel", "laravel crud generator" ], - "time": "2016-09-28T18:05:53+00:00" + "time": "2016-09-28 18:05:53" }, { "name": "barryvdh/laravel-ide-helper", - "version": "v2.2.3", + "version": "v2.3.2", "source": { "type": "git", "url": "https://github.com/barryvdh/laravel-ide-helper.git", - "reference": "a7fc2ec489aada6062d3a63ddc915004a21e38af" + "reference": "e82de98cef0d6597b1b686be0b5813a3a4bb53c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-ide-helper/zipball/a7fc2ec489aada6062d3a63ddc915004a21e38af", - "reference": "a7fc2ec489aada6062d3a63ddc915004a21e38af", + "url": "https://api.github.com/repos/barryvdh/laravel-ide-helper/zipball/e82de98cef0d6597b1b686be0b5813a3a4bb53c5", + "reference": "e82de98cef0d6597b1b686be0b5813a3a4bb53c5", "shasum": "" }, "require": { @@ -2020,7 +2021,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "2.3-dev" } }, "autoload": { @@ -2050,7 +2051,7 @@ "phpstorm", "sublime" ], - "time": "2017-01-05T21:20:42+00:00" + "time": "2017-02-22 12:27:33" }, { "name": "barryvdh/reflection-docblock", @@ -2099,20 +2100,20 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2016-06-13T19:28:20+00:00" + "time": "2016-06-13 19:28:20" }, { "name": "doctrine/annotations", - "version": "v1.3.1", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "bd4461328621bde0ae6b1b2675fbc6aca4ceb558" + "reference": "54cacc9b81758b14e3ce750f205a393d52339e97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/bd4461328621bde0ae6b1b2675fbc6aca4ceb558", - "reference": "bd4461328621bde0ae6b1b2675fbc6aca4ceb558", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/54cacc9b81758b14e3ce750f205a393d52339e97", + "reference": "54cacc9b81758b14e3ce750f205a393d52339e97", "shasum": "" }, "require": { @@ -2121,7 +2122,7 @@ }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^5.6.1" + "phpunit/phpunit": "^5.7" }, "type": "library", "extra": { @@ -2167,7 +2168,7 @@ "docblock", "parser" ], - "time": "2016-12-30T15:59:45+00:00" + "time": "2017-02-24 16:22:25" }, { "name": "doctrine/cache", @@ -2237,7 +2238,7 @@ "cache", "caching" ], - "time": "2016-10-29T11:16:17+00:00" + "time": "2016-10-29 11:16:17" }, { "name": "doctrine/collections", @@ -2304,7 +2305,7 @@ "collections", "iterator" ], - "time": "2017-01-03T10:49:41+00:00" + "time": "2017-01-03 10:49:41" }, { "name": "doctrine/common", @@ -2377,7 +2378,7 @@ "persistence", "spl" ], - "time": "2017-01-13T14:02:13+00:00" + "time": "2017-01-13 14:02:13" }, { "name": "doctrine/dbal", @@ -2448,7 +2449,7 @@ "persistence", "queryobject" ], - "time": "2017-02-08T12:53:47+00:00" + "time": "2017-02-08 12:53:47" }, { "name": "doctrine/instantiator", @@ -2502,7 +2503,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14T21:17:01+00:00" + "time": "2015-06-14 21:17:01" }, { "name": "doctrine/lexer", @@ -2556,7 +2557,7 @@ "lexer", "parser" ], - "time": "2014-09-09T13:34:57+00:00" + "time": "2014-09-09 13:34:57" }, { "name": "fzaninotto/faker", @@ -2604,7 +2605,7 @@ "faker", "fixtures" ], - "time": "2016-04-29T12:21:54+00:00" + "time": "2016-04-29 12:21:54" }, { "name": "hamcrest/hamcrest-php", @@ -2649,20 +2650,20 @@ "keywords": [ "test" ], - "time": "2015-05-11T14:41:42+00:00" + "time": "2015-05-11 14:41:42" }, { "name": "mockery/mockery", - "version": "0.9.8", + "version": "0.9.9", "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "1e5e2ffdc4d71d7358ed58a6fdd30a4a0c506855" + "reference": "6fdb61243844dc924071d3404bb23994ea0b6856" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/1e5e2ffdc4d71d7358ed58a6fdd30a4a0c506855", - "reference": "1e5e2ffdc4d71d7358ed58a6fdd30a4a0c506855", + "url": "https://api.github.com/repos/padraic/mockery/zipball/6fdb61243844dc924071d3404bb23994ea0b6856", + "reference": "6fdb61243844dc924071d3404bb23994ea0b6856", "shasum": "" }, "require": { @@ -2714,7 +2715,7 @@ "test double", "testing" ], - "time": "2017-02-09T13:29:38+00:00" + "time": "2017-02-28 12:52:32" }, { "name": "myclabs/deep-copy", @@ -2756,7 +2757,7 @@ "object", "object graph" ], - "time": "2017-01-26T22:05:40+00:00" + "time": "2017-01-26 22:05:40" }, { "name": "phpdocumentor/reflection-common", @@ -2810,7 +2811,7 @@ "reflection", "static analysis" ], - "time": "2015-12-27T11:43:31+00:00" + "time": "2015-12-27 11:43:31" }, { "name": "phpdocumentor/reflection-docblock", @@ -2855,7 +2856,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-09-30T07:12:33+00:00" + "time": "2016-09-30 07:12:33" }, { "name": "phpdocumentor/type-resolver", @@ -2902,31 +2903,31 @@ "email": "me@mikevanriel.com" } ], - "time": "2016-11-25T06:54:22+00:00" + "time": "2016-11-25 06:54:22" }, { "name": "phpspec/prophecy", - "version": "v1.6.2", + "version": "v1.7.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "6c52c2722f8460122f96f86346600e1077ce22cb" + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/6c52c2722f8460122f96f86346600e1077ce22cb", - "reference": "6c52c2722f8460122f96f86346600e1077ce22cb", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", - "sebastian/comparator": "^1.1", - "sebastian/recursion-context": "^1.0|^2.0" + "sebastian/comparator": "^1.1|^2.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { - "phpspec/phpspec": "^2.0", + "phpspec/phpspec": "^2.5|^3.2", "phpunit/phpunit": "^4.8 || ^5.6.5" }, "type": "library", @@ -2965,7 +2966,7 @@ "spy", "stub" ], - "time": "2016-11-21T14:58:47+00:00" + "time": "2017-03-02 20:05:34" }, { "name": "phpunit/php-code-coverage", @@ -3028,7 +3029,7 @@ "testing", "xunit" ], - "time": "2016-05-27T16:24:29+00:00" + "time": "2016-05-27 16:24:29" }, { "name": "phpunit/php-file-iterator", @@ -3075,7 +3076,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2016-10-03 07:40:28" }, { "name": "phpunit/php-text-template", @@ -3116,29 +3117,34 @@ "keywords": [ "template" ], - "time": "2015-06-21T13:50:34+00:00" + "time": "2015-06-21 13:50:34" }, { "name": "phpunit/php-timer", - "version": "1.0.8", + "version": "1.0.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", - "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4|~5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -3160,20 +3166,20 @@ "keywords": [ "timer" ], - "time": "2016-05-12T18:03:57+00:00" + "time": "2017-02-26 11:10:40" }, { "name": "phpunit/php-token-stream", - "version": "1.4.9", + "version": "1.4.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b" + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b", - "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", "shasum": "" }, "require": { @@ -3209,7 +3215,7 @@ "keywords": [ "tokenizer" ], - "time": "2016-11-15T14:06:22+00:00" + "time": "2017-02-27 10:12:30" }, { "name": "phpunit/phpunit", @@ -3283,7 +3289,7 @@ "testing", "xunit" ], - "time": "2016-03-15T05:59:58+00:00" + "time": "2016-03-15 05:59:58" }, { "name": "phpunit/phpunit-mock-objects", @@ -3339,7 +3345,7 @@ "mock", "xunit" ], - "time": "2016-04-20T14:39:26+00:00" + "time": "2016-04-20 14:39:26" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -3384,7 +3390,7 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2016-02-13T06:45:14+00:00" + "time": "2016-02-13 06:45:14" }, { "name": "sebastian/comparator", @@ -3448,7 +3454,7 @@ "compare", "equality" ], - "time": "2017-01-29T09:50:25+00:00" + "time": "2017-01-29 09:50:25" }, { "name": "sebastian/diff", @@ -3500,7 +3506,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08T07:14:41+00:00" + "time": "2015-12-08 07:14:41" }, { "name": "sebastian/environment", @@ -3550,7 +3556,7 @@ "environment", "hhvm" ], - "time": "2016-08-18T05:49:44+00:00" + "time": "2016-08-18 05:49:44" }, { "name": "sebastian/exporter", @@ -3617,7 +3623,7 @@ "export", "exporter" ], - "time": "2016-06-17T09:04:28+00:00" + "time": "2016-06-17 09:04:28" }, { "name": "sebastian/global-state", @@ -3668,7 +3674,7 @@ "keywords": [ "global state" ], - "time": "2015-10-12T03:26:01+00:00" + "time": "2015-10-12 03:26:01" }, { "name": "sebastian/recursion-context", @@ -3721,7 +3727,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11T19:50:13+00:00" + "time": "2015-11-11 19:50:13" }, { "name": "sebastian/resource-operations", @@ -3763,7 +3769,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" + "time": "2015-07-28 20:34:47" }, { "name": "sebastian/version", @@ -3806,11 +3812,11 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" + "time": "2016-10-03 07:35:21" }, { "name": "symfony/class-loader", - "version": "v3.2.3", + "version": "v3.2.4", "source": { "type": "git", "url": "https://github.com/symfony/class-loader.git", @@ -3862,7 +3868,7 @@ ], "description": "Symfony ClassLoader Component", "homepage": "https://symfony.com", - "time": "2017-01-21T17:06:35+00:00" + "time": "2017-01-21 17:06:35" }, { "name": "symfony/css-selector", @@ -3915,7 +3921,7 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2016-06-29T05:40:00+00:00" + "time": "2016-06-29 05:40:00" }, { "name": "symfony/dom-crawler", @@ -3971,20 +3977,20 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2016-07-30T07:22:48+00:00" + "time": "2016-07-30 07:22:48" }, { "name": "symfony/yaml", - "version": "v3.2.3", + "version": "v3.2.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "e1718c6bf57e1efbb8793ada951584b2ab27775b" + "reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/e1718c6bf57e1efbb8793ada951584b2ab27775b", - "reference": "e1718c6bf57e1efbb8793ada951584b2ab27775b", + "url": "https://api.github.com/repos/symfony/yaml/zipball/9724c684646fcb5387d579b4bfaa63ee0b0c64c8", + "reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8", "shasum": "" }, "require": { @@ -4026,7 +4032,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-01-21T17:06:35+00:00" + "time": "2017-02-16 22:46:52" }, { "name": "webmozart/assert", @@ -4076,7 +4082,7 @@ "check", "validate" ], - "time": "2016-11-23T20:04:58+00:00" + "time": "2016-11-23 20:04:58" } ], "aliases": [], From 92a7f830e7226caf06b6536a6ed8300e4f1ffb9a Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sat, 4 Mar 2017 13:51:40 +0000 Subject: [PATCH 34/62] lva-22: Fixed the getting of the status and the restarting of the uploading process --- .gitignore | 2 +- .../Api/v1/UploadApiController.php | 80 ++----- app/Http/routes.php | 1 + app/Models/UploadJobStatus.php | 115 +++++++++- app/Providers/AppServiceProvider.php | 2 +- .../InteractiveFixturesUploadService.php | 157 +++---------- app/Services/MappingService.php | 14 +- app/Services/StatusService.php | 208 ------------------ .../assets/js/load-fixtures-status-update.js | 9 + .../data-management/load/status.blade.php | 8 +- 10 files changed, 185 insertions(+), 411 deletions(-) delete mode 100644 app/Services/StatusService.php diff --git a/.gitignore b/.gitignore index 8a6f3e71..df398aa2 100755 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ storage/ !.env.example _ide_helper.php _ide_helper_models.php -Vagrantfile +/Vagrantfile diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 79210caa..7945b22c 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -17,22 +17,36 @@ use LVA\Models\NewVenue; use LVA\Models\UploadJob; use LVA\Models\UploadJobStatus; -use LVA\Services\StatusService; +use LVA\Services\InteractiveFixturesUploadService; use Illuminate\Support\Facades\Input; class UploadApiController extends Controller { - /** @var StatusService */ - private $statusService; + /** @var InteractiveFixturesUploadService */ + private $uploadService; /** * @inheritDoc */ - public function __construct(StatusService $statusService) + public function __construct(InteractiveFixturesUploadService $uploadService) { - $this->statusService = $statusService; + $this->uploadService = $uploadService; } + public function resumeUpload() + { + $uploadJob = $this->checkForJob(); + if (!$uploadJob instanceof UploadJob) { + return response()->json($uploadJob); + } + + $status = new UploadJobStatus(); + $status->load($uploadJob->getStatus())->resume(); + + $uploadJob->setStatus($status->toArray())->save(); + + $this->uploadService->processJob($uploadJob); + } public function getUploadStatus() { @@ -42,65 +56,13 @@ public function getUploadStatus() } $status = new UploadJobStatus(); - $status->load([ - 'status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA, - ]); - $f = [ - 'StatusCode' => $status->getStatusCode(), - 'StatusMessage' => $status->getStatusCodeMessage(), - 'Progress' => rand(10, 99), - 'Fixture' => [ - 'Division' => 'M1A', - 'MatchNumber' => '05', - 'HomeTeam' => 'K.S. Osmeka Men 2', - 'AwayTeam' => 'Flaming Six Blackjacks', - 'Date' => date('D d/m/y'), - 'WarmUpTime' => '15:00', - 'StartTime' => '15:20', - 'Venue' => 'Battersea Sports Centre', - ], - 'Unknowns' => [ - 'HomeTeam' => [ - 'Mapping' => [ - ['value' => 1, 'text' => 'KS Osemka Men 2'], - ['value' => 3, 'text' => 'KS Osemka Men 3'], - ['value' => 4, 'text' => 'KS Osemka Men 4'], - ['value' => 2, 'text' => 'k.s. Osemka Men 2'], - ], - 'ApiUrls' => [ - 'Map' => '/api/v1/maps/team', - ], - ], - 'AwayTeam' => [ - 'Mapping' => [ - ['value' => 1, 'text' => 'KS Osemka Men 2'], - ['value' => 3, 'text' => 'KS Osemka Men 3'], - ['value' => 4, 'text' => 'KS Osemka Men 4'], - ['value' => 2, 'text' => 'k.s. Osemka Men 2'], - ], - 'ApiUrls' => [ - 'Map' => '/api/v1/maps/team', - ], - ], - 'Venue' => [ - 'Mapping' => [ - ['value' => 10, 'text' => 'Sobell S.C.'], - ['value' => 22, 'text' => 'SportsDock'], - ], - 'ApiUrls' => [ - 'Add' => route('loading-add-venue'), - 'Map' => route('loading-map-venue'), - ], - ], - - ], - ]; + $status->load($uploadJob->getStatus()); return response()->json([ 'Timestamp' => time(), 'Error' => false, 'Message' => 'Job found', - 'Status' => $f, + 'Status' => $status->toApiJson(), ]); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 6f86c63c..06f0a1a7 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -28,6 +28,7 @@ Route::post('maps/team', ['as' => 'loading-map-team', 'uses' => 'UploadApiController@mapTeam']); Route::post('venues', ['as' => 'loading-add-venue', 'uses' => 'UploadApiController@addVenue']); Route::post('maps/venue', ['as' => 'loading-map-venue', 'uses' => 'UploadApiController@mapVenue']); + Route::get('uploads/resume', ['as' => 'resume-upload', 'uses' => 'UploadApiController@resumeUpload']); }); Route::group(['middleware' => 'web'], function () { diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 0fac09c3..6b1d1918 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -8,6 +8,8 @@ namespace LVA\Models; +use Carbon\Carbon; + /** * Class UploadJobStatus @@ -52,6 +54,14 @@ public function __construct() $this->unknowns = null; } + public static function loadStatus($statusArray) + { + $status = new static(); + $status->load($statusArray); + + return $status; + } + /** * @return string */ @@ -94,6 +104,12 @@ public function load(array $data) if (array_has($data, 'processed_rows')) { $this->processed_rows = $data['processed_rows']; } + if (array_has($data, 'processing_line')) { + $this->processing_line = $data['processing_line']; + } + if (array_has($data, 'unknowns')) { + $this->unknowns = $data['unknowns']; + } return $this; } @@ -104,12 +120,74 @@ public function load(array $data) public function toArray() { return [ - 'status_code' => $this->status_code, - 'total_lines' => $this->total_lines, - 'processed_lines' => $this->processed_lines, - 'total_rows' => $this->total_rows, - 'processed_rows' => $this->processed_rows, + 'status_code' => $this->getStatusCode(), + 'total_lines' => $this->getTotalLines(), + 'processed_lines' => $this->getProcessedLines(), + 'total_rows' => $this->getTotalRows(), + 'processed_rows' => $this->getProcessedRows(), + 'processing_line' => $this->processing_line, + 'unknowns' => $this->getUnknowns(), + ]; + } + + /** + * @return array + */ + public function toApiJson() + { + $formattedStatus = [ + 'StatusCode' => $this->getStatusCode(), + 'StatusMessage' => $this->getStatusCodeMessage(), + ]; + + if ($this->isValidating()) { + $formattedStatus['Progress'] = floor($this->getProcessedLines() * 100 / $this->getTotalLines()); + } elseif ($this->isInserting()) { + $formattedStatus['Progress'] = floor($this->getProcessedRows() * 100 / $this->getTotalRows()); + } + + $formattedStatus['Fixture'] = [ + 'Division' => $this->getProcessingLineDivision(), + 'MatchNumber' => $this->getProcessingLineMatchNumber(), + 'HomeTeam' => $this->getProcessingLineHomeTeam(), + 'AwayTeam' => $this->getProcessingLineAwayTeam(), + 'Date' => $this->getProcessingLineDate(), + 'WarmUpTime' => $this->getProcessingLineWarmUpTime(), + 'StartTime' => $this->getProcessingLineStartTime(), + 'Venue' => $this->getProcessingLineVenue(), ]; + + foreach ($this->getUnknowns() as $unknownType => $mappings) { + switch ($unknownType) { + case UploadJobStatus::UNKNOWN_HOME_TEAM: + $formattedStatus['Unknowns']['HomeTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_AWAY_TEAM: + $formattedStatus['Unknowns']['AwayTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_VENUE: + $formattedStatus['Unknowns']['Venue'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + //'Add' => route('loading-add-venue'), + 'Map' => route('loading-map-venue'), + ], + ]; + break; + } + } + + return $formattedStatus; } /** @@ -144,6 +222,14 @@ public function isDone() return $this->status_code === self::STATUS_DONE; } + /** + * @return bool + */ + public function hasUnknownData() + { + return $this->status_code === self::STATUS_UNKNOWN_DATA; + } + /** * @return array */ @@ -162,6 +248,7 @@ public function getUnknowns() */ public function setUnknown($unknownType, $mappings) { + $this->status_code = self::STATUS_UNKNOWN_DATA; $this->unknowns[$unknownType] = $mappings; } @@ -353,7 +440,7 @@ public function getProcessingLineDate() */ public function setProcessingLineDate($date) { - $this->processing_line['date'] = $date; + $this->processing_line['date'] = Carbon::createFromFormat('d/m/Y', $date)->format('D, d/m/Y'); return $this; } @@ -374,7 +461,7 @@ public function getProcessingLineWarmUpTime() */ public function setProcessingLineWarmUpTime($time) { - $this->processing_line['warm_up_time'] = $time; + $this->processing_line['warm_up_time'] = Carbon::createFromFormat('H:i:s', $time)->format('H:i'); return $this; } @@ -395,7 +482,7 @@ public function getProcessingLineStartTime() */ public function setProcessingLineStartTime($time) { - $this->processing_line['start_time'] = $time; + $this->processing_line['start_time'] = Carbon::createFromFormat('H:i:s', $time)->format('H:i'); return $this; } @@ -444,4 +531,16 @@ public function moveForward() return $this; } + + /** + * @return UploadJobStatus + */ + public function resume() + { + if ($this->status_code === self::STATUS_UNKNOWN_DATA) { + $this->status_code = self::STATUS_VALIDATING_RECORDS; + } + + return $this; + } } \ No newline at end of file diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index f04ea546..0f022439 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -26,7 +26,7 @@ public function boot() */ public function register() { - if($this->app->environment('local')) + if ($this->app->environment() == 'local') { $this->app->register('Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider'); $this->app->register('Appzcoder\CrudGenerator\CrudGeneratorServiceProvider'); diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index dd57c2a4..e5e5634e 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -10,13 +10,10 @@ use LVA\Models\Division; use LVA\Models\Fixture; -use LVA\Models\Season; use LVA\Models\Team; -use LVA\Models\TeamSynonym; use LVA\Models\UploadJobData; use LVA\Models\UploadJobStatus; use LVA\Models\Venue; -use LVA\Models\VenueSynonym; use LVA\Repositories\TeamsRepository; use LVA\Repositories\VenuesRepository; use LVA\Services\Contracts\InteractiveUploadContract; @@ -30,8 +27,6 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract { const UPLOAD_DIR = '/app/files/'; - /** @var StatusService */ - private $statusService; /** @var UploadDataService */ private $uploadDataService; /** @var MappingService */ @@ -54,13 +49,12 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract * @inheritDoc */ public function __construct( - StatusService $statusService, UploadDataService $uploadDataService, MappingService $mappingService, TeamsRepository $teamsRepository, VenuesRepository $venuesRepository - ) { - $this->statusService = $statusService; + ) + { $this->uploadDataService = $uploadDataService; $this->mappingService = $mappingService; @@ -68,11 +62,6 @@ public function __construct( $this->venuesRepository = $venuesRepository; } - - /************************************ - * INTERFACE IMPLEMENTATION METHODS * - ************************************/ - /** * @param resource $handle * @@ -80,11 +69,13 @@ public function __construct( */ public static function readOneLine(&$handle) { - return array_map(function ($field) { - return str_replace(['"', "\n", "\r"], '', $field); - }, explode(',', fgets($handle))); + return explode(',', str_replace(['"', "\n", "\r"], '', fgets($handle))); } + /************************************ + * INTERFACE IMPLEMENTATION METHODS * + ************************************/ + /** * @inheritdoc */ @@ -105,16 +96,12 @@ public function createJob($seasonId, UploadedFile $file) ->setFile($fixtureFile->getFilename()) ->setType(UploadJob::TYPE_FIXTURES) ->setRowCount($lines - 1)// Don't count the first line as they are the headers - ->setStatus($this->statusService->getInitialStatus()->toArray()) + ->setStatus((new UploadJobStatus())->toArray()) ->save(); return $job; } - /******************* - * PRIVATE METHODS * - *******************/ - /** * @inheritDoc */ @@ -125,7 +112,7 @@ public function processJob(UploadJob $job) $this->newVenues = $job->newVenues; /** @var UploadJobStatus $status */ - $status = $this->statusService->loadStatus($job->getStatus()); + $status = UploadJobStatus::loadStatus($job->getStatus()); if ($status->isNotStarted()) { $status->moveForward()->setTotalLines($job->getRowCount()); @@ -150,16 +137,15 @@ public function processJob(UploadJob $job) $row = array_combine($headers, self::readOneLine($csvFile)); // Store the current line - $this->statusService->setProcessingLine($status, - $row['Code'], - $row['Match'], - $row['Home'], - $row['Away'], - Carbon::createFromFormat('d/m/Y', $row['Date']), - Carbon::createFromFormat('H:i:s', $row['WUTime']), - Carbon::createFromFormat('H:i:s', $row['StartTime']), - $row['Hall'] - ); + $status + ->setProcessingLineDivision($row['Code']) + ->setProcessingLineMatchNumber($row['Match']) + ->setProcessingLineHomeTeam($row['Home']) + ->setProcessingLineAwayTeam($row['Away']) + ->setProcessingLineDate($row['Date']) + ->setProcessingLineWarmUpTime($row['WUTime']) + ->setProcessingLineStartTime($row['StartTime']) + ->setProcessingLineVenue($row['Hall']); // Skip lines that are not for London or indoor volleyball if ($row['Region'] != 'L' || $row['Discipline'] != 'I') { @@ -194,7 +180,7 @@ public function processJob(UploadJob $job) if (is_null($homeTeam)) { // Nope, can't find it, so ask the user what to do $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Home']); - $this->statusService->setUnknownHomeTeam($status, $mappings); + $status->setUnknown(UploadJobStatus::UNKNOWN_HOME_TEAM, $mappings); $allRowsProcessed = false; $isValid = false; @@ -207,7 +193,7 @@ public function processJob(UploadJob $job) if (is_null($awayTeam)) { // Nope, can't find it, so ask the user what to do $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Away']); - $this->statusService->setUnknownAwayTeam($status, $mappings); + $status->setUnknown(UploadJobStatus::UNKNOWN_AWAY_TEAM, $mappings); $allRowsProcessed = false; $isValid = false; @@ -220,7 +206,7 @@ public function processJob(UploadJob $job) if (is_null($venue)) { // Nope, can't find it, so ask the user what to do $mappings = $this->mappingService->findVenueMappings($row['Hall']); - $this->statusService->setUnknownHomeTeam($status, $mappings); + $status->setUnknown(UploadJobStatus::UNKNOWN_VENUE, $mappings); $allRowsProcessed = false; $isValid = false; @@ -272,11 +258,16 @@ public function processJob(UploadJob $job) } } + + /******************* + * PRIVATE METHODS * + *******************/ + /** * @param resource $file * @param int $numberOfLines */ - private function getIntoPosition($file, $numberOfLines) + private function getIntoPosition(&$file, $numberOfLines) { $counter = 0; while ($counter < $numberOfLines && !feof($file)) { @@ -286,98 +277,8 @@ private function getIntoPosition($file, $numberOfLines) } /** - * @param string $team - * - * @return bool - */ - private function isValidTeam($team) - { - /** @var Team $model */ - $model = Team::findByName($team); - if (is_null($model)) { - $model = TeamSynonym::findBySynonym($team); - } - if (is_null($model)) { - if (!in_array($team, $this->mappedTeams->pluck('team')->all())) { - return false; - } - } - - return true; - } - - /** - * @param string $venue - * - * @return bool - */ - private function isValidVenue($venue) - { - /** @var Venue $model */ - $model = Venue::findByName($venue); - if (is_null($model)) { - $model = VenueSynonym::findBySynonym($venue); - } - if (is_null($model)) { - if (!in_array($venue, $this->mappedVenues->pluck('venue')->all()) && - !in_array($venue, $this->newVenues->pluck('venue')->all()) - ) { - return false; - } - } - - return true; - } - - /** - * @param string $team - * - * @return Team|null - */ - private function findTeamByName($team) - { - /** @var Team $model */ - $model = Team::findByName($team); - if ($model) { - return $model; - } - - /** @var TeamSynonym $modelSynonym */ - $modelSynonym = TeamSynonym::findBySynonym($team); - if ($modelSynonym) { - $model = $modelSynonym->team; - return $model; - } - - return null; - } - - /** - * @param string $venue - * - * @return Venue|null - */ - private function findVenueByName($venue) - { - /** @var Venue $model */ - $model = Venue::findByName($venue); - if ($model) { - return $model; - } - - /** @var VenueSynonym $modelSynonym */ - $modelSynonym = VenueSynonym::findBySynonym($venue); - if ($modelSynonym) { - $model = $modelSynonym->venue; - return $model; - } - - return null; - } - - /** - * @param UploadJob $job - * @param array $data + * @param UploadJob $job + * @param array $data */ private function insertFixture($job, $data) { diff --git a/app/Services/MappingService.php b/app/Services/MappingService.php index b561738d..069cc327 100644 --- a/app/Services/MappingService.php +++ b/app/Services/MappingService.php @@ -1,8 +1,9 @@ $team->id, + 'text' => $team->team, + ]; + } + + return $mappings; } /** @@ -28,6 +38,6 @@ public function findTeamMappings($divisionId, $team) */ public function findVenueMappings($venue) { - + return []; } } \ No newline at end of file diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php deleted file mode 100644 index 266ee2d6..00000000 --- a/app/Services/StatusService.php +++ /dev/null @@ -1,208 +0,0 @@ - - * Date: 21/01/2017 - * Time: 15:02 - */ - -namespace LVA\Services; - -use LVA\Models\UploadJobStatus; -use Carbon\Carbon; - -/** - * Class StatusService - * - * This class implements the StatusContract interface using the UploadJobs model. - * This means that the status will be saved in the DB and that the status codes - * are the ones defined in the UploadJobs model class. - * - * @package LVA\Services - */ -class StatusService -{ - /** @var MappingService */ - private $mappingService; - - /** - * StatusService constructor. - * - * @param MappingService $mappingService - */ - public function __construct(MappingService $mappingService) - { - $this->mappingService = $mappingService; - } - - - /** - * @param array $statusArray - * - * @return UploadJobStatus - */ - public function loadStatus(array $statusArray) - { - $status = new UploadJobStatus(); - $status->load($statusArray); - - return $status; - } - - /** - * @return UploadJobStatus - */ - public function getInitialStatus() - { - return new UploadJobStatus(); - } - - /** - * @param UploadJobStatus $status - * @param string $division - * @param string $matchNumber - * @param string $homeTeam - * @param string $awayTeam - * @param Carbon $date - * @param Carbon $warmUpTime - * @param Carbon $startTime - * @param string $venue - */ - public function setProcessingLine( - UploadJobStatus $status, - $division, - $matchNumber, - $homeTeam, - $awayTeam, - Carbon $date, - Carbon $warmUpTime, - Carbon $startTime, - $venue - ) { - $status - ->setProcessingLineDivision($division) - ->setProcessingLineMatchNumber($matchNumber) - ->setProcessingLineHomeTeam($homeTeam) - ->setProcessingLineAwayTeam($awayTeam) - ->setProcessingLineDate($date->format('D d/m/y')) - ->setProcessingLineWarmUpTime($warmUpTime->format('H:i')) - ->setProcessingLineStartTime($startTime->format('H:i')) - ->setProcessingLineVenue($venue); - } - - /** - * @param array $statusArray - * - * @return array - */ - public function apiFormat($statusArray) - { - $status = new UploadJobStatus(); - $status->load($statusArray); - - $formattedStatus = [ - 'StatusCode' => $status->getStatusCode(), - 'StatusMessage' => $status->getStatusCodeMessage(), - ]; - - if ($status->isValidating()) { - $formattedStatus['Progress'] = floor($status->getProcessedLines() * 100 / $status->getTotalLines()); - } elseif ($status->isInserting()) { - $formattedStatus['Progress'] = floor($status->getProcessedRows() * 100 / $status->getTotalRows()); - } - - $formattedStatus['Fixture'] = [ - 'Division' => $status->getProcessingLineDivision(), - 'MatchNumber' => $status->getProcessingLineMatchNumber(), - 'HomeTeam' => $status->getProcessingLineHomeTeam(), - 'AwayTeam' => $status->getProcessingLineAwayTeam(), - 'Date' => $status->getProcessingLineDate(), - 'WarmUpTime' => $status->getProcessingLineWarmUpTime(), - 'StartTime' => $status->getProcessingLineStartTime(), - 'Venue' => $status->getProcessingLineVenue(), - ]; - - foreach ($status->getUnknowns() as $unknownType => $mappings) { - switch ($unknownType) { - case UploadJobStatus::UNKNOWN_HOME_TEAM: - $formattedStatus['Unknowns']['HomeTeam'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - 'Map' => route('loading-map-team'), - ], - ]; - break; - case UploadJobStatus::UNKNOWN_AWAY_TEAM: - $formattedStatus['Unknowns']['AwayTeam'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - 'Map' => route('loading-map-team'), - ], - ]; - break; - case UploadJobStatus::UNKNOWN_VENUE: - $formattedStatus['Unknowns']['Venue'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - //'Add' => route('loading-add-venue'), - 'Map' => route('loading-map-venue'), - ], - ]; - break; - } - } - - return $formattedStatus; - } - - /** - * @param UploadJobStatus $status - * - * @return UploadJobStatus - */ - public function getNextStepStatus($status) - { - return $status->moveForward(); - } - - /** - * @param array $status - * - * @return int - */ - public function getStatusCode($status) - { - if (array_has($status, 'status_code')) { - return $status['status_code']; - } - - return UploadJobStatus::STATUS_NOT_STARTED; - } - - /** - * @param UploadJobStatus $status - * @param array $mappings - */ - public function setUnknownHomeTeam(UploadJobStatus $status, $mappings) - { - $status->setUnknown(UploadJobStatus::UNKNOWN_HOME_TEAM, $mappings); - } - - /** - * @param UploadJobStatus $status - * @param array $mappings - */ - public function setUnknownAwayTeam(UploadJobStatus $status, $mappings) - { - $status->setUnknown(UploadJobStatus::UNKNOWN_AWAY_TEAM, $mappings); - } - - /** - * @param UploadJobStatus $status - * @param array $mappings - */ - public function setUnknownVenue(UploadJobStatus $status, $mappings) - { - $status->setUnknown(UploadJobStatus::UNKNOWN_VENUE, $mappings); - } -} \ No newline at end of file diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index 7ea38c44..dfd1634e 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -167,5 +167,14 @@ $('#load-fixture-modal').modal({show: false}); $('#load-fixture-modal').on('hidden.bs.modal', function () { setTimeout(poll, 1000); + // Restart the uploading + $.get({ + url : '/api/v1/uploads/resume', + data : { + job : jobId, + api_token: apiToken + }, + async: true + }); }); })(jQuery); \ No newline at end of file diff --git a/resources/views/admin/data-management/load/status.blade.php b/resources/views/admin/data-management/load/status.blade.php index fd4d2a47..68d8f22e 100644 --- a/resources/views/admin/data-management/load/status.blade.php +++ b/resources/views/admin/data-management/load/status.blade.php @@ -12,9 +12,9 @@

Processing {{$job->file}}

-
- 60% Complete +
+ 0% Complete
@@ -22,7 +22,7 @@

- @include('_partial.load-fixture-modal'); + @include('_partial.load-fixture-modal') @endsection @section('javascript') From 6f9de65fe18109c04c5f72a2598524b315250755 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 5 Mar 2017 11:02:18 +0000 Subject: [PATCH 35/62] lva-22: fixed the mapping of teams and venues --- .../Api/v1/UploadApiController.php | 24 ++++++++++++++-- app/Http/Requests/Api/v1/MapTeamRequest.php | 2 +- app/Http/Requests/Api/v1/MapVenueRequest.php | 2 +- app/Models/MappedTeam.php | 12 ++++---- app/Models/MappedVenue.php | 12 ++++---- app/Models/TeamSynonym.php | 28 +++++++++++++++++-- app/Models/UploadJobStatus.php | 1 + app/Models/VenueSynonym.php | 28 +++++++++++++++++-- app/Repositories/VenuesRepository.php | 12 ++++---- .../InteractiveFixturesUploadService.php | 12 -------- app/Services/MappingService.php | 11 +++++++- .../assets/js/load-fixtures-status-update.js | 2 +- 12 files changed, 106 insertions(+), 40 deletions(-) diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 7945b22c..7c76c225 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -15,22 +15,28 @@ use LVA\Models\MappedTeam; use LVA\Models\MappedVenue; use LVA\Models\NewVenue; +use LVA\Models\TeamSynonym; use LVA\Models\UploadJob; use LVA\Models\UploadJobStatus; +use LVA\Models\VenueSynonym; use LVA\Services\InteractiveFixturesUploadService; use Illuminate\Support\Facades\Input; +use LVA\Services\UploadDataService; class UploadApiController extends Controller { /** @var InteractiveFixturesUploadService */ private $uploadService; + /** @var UploadDataService */ + private $uploadDataService; /** * @inheritDoc */ - public function __construct(InteractiveFixturesUploadService $uploadService) + public function __construct(InteractiveFixturesUploadService $uploadService, UploadDataService $uploadDataService) { $this->uploadService = $uploadService; + $this->uploadDataService = $uploadDataService; } public function resumeUpload() @@ -75,6 +81,13 @@ public function mapTeam(MapTeamRequest $request) ->setMappedTeam($request->input('newName')) ->save(); + $synonym = new TeamSynonym(); + $synonym + ->setSynonym($mappedTeam->getName()) + ->setTeamId($mappedTeam->getId()); + + $this->uploadDataService->add($request->input('job'), TeamSynonym::class, $synonym); + return response()->json([ 'success' => true, ]); @@ -102,8 +115,15 @@ public function mapVenue(MapVenueRequest $request) ->setMappedVenue($request->input('newName')) ->save(); + $synonym = new VenueSynonym(); + $synonym + ->setSynonym($mappedVenue->getName()) + ->setTeamId($mappedVenue->getId()); + + $this->uploadDataService->add($request->input('job'), VenueSynonym::class, $synonym); + return response()->json([ - 'success' => false, + 'success' => true, ]); } diff --git a/app/Http/Requests/Api/v1/MapTeamRequest.php b/app/Http/Requests/Api/v1/MapTeamRequest.php index 1c25e745..ce7cbfda 100644 --- a/app/Http/Requests/Api/v1/MapTeamRequest.php +++ b/app/Http/Requests/Api/v1/MapTeamRequest.php @@ -32,7 +32,7 @@ public function authorize() public function rules() { return [ - 'job' => 'required|exists:upload_jobs', + 'job' => 'required|exists:upload_jobs,id', 'name' => 'required', 'newName' => 'required', ]; diff --git a/app/Http/Requests/Api/v1/MapVenueRequest.php b/app/Http/Requests/Api/v1/MapVenueRequest.php index 096d8f7e..9da4babd 100644 --- a/app/Http/Requests/Api/v1/MapVenueRequest.php +++ b/app/Http/Requests/Api/v1/MapVenueRequest.php @@ -32,7 +32,7 @@ public function authorize() public function rules() { return [ - 'job' => 'required|exists:upload_jobs', + 'job' => 'required|exists:upload_jobs,id', 'name' => 'required', 'newName' => 'required', ]; diff --git a/app/Models/MappedTeam.php b/app/Models/MappedTeam.php index 3236eb22..4bfe5852 100644 --- a/app/Models/MappedTeam.php +++ b/app/Models/MappedTeam.php @@ -39,23 +39,23 @@ class MappedTeam extends Model */ public static function findByJob($jobId) { - return MappedTeam::where('upload_job_id', $jobId)->get(); + return self::where('upload_job_id', $jobId)->get(); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function uploadJob() { - return $this->hasOne(UploadJob::class); + return $this->belongsTo(UploadJob::class); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function team() { - return $this->hasOne(Team::class); + return $this->belongsTo(Team::class); } /** @@ -105,7 +105,7 @@ public function setName($team) */ public function setMappedTeam($team) { - $this->team_id = Team::findByName($team); + $this->team_id = Team::findByName($team)->getId(); return $this; } diff --git a/app/Models/MappedVenue.php b/app/Models/MappedVenue.php index 03f0e0a0..1a7e8e91 100644 --- a/app/Models/MappedVenue.php +++ b/app/Models/MappedVenue.php @@ -39,23 +39,23 @@ class MappedVenue extends Model */ public static function findByJob($jobId) { - return MappedTeam::where('upload_job_id', $jobId)->get(); + return self::where('upload_job_id', $jobId)->get(); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function uploadJob() { - return $this->hasOne(UploadJob::class); + return $this->belongsTo(UploadJob::class); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function venue() { - return $this->hasOne(Venue::class); + return $this->belongsTo(Venue::class); } /** @@ -105,7 +105,7 @@ public function setName($venue) */ public function setMappedVenue($venue) { - $this->venue_id = Venue::findByName($venue); + $this->venue_id = Venue::findByName($venue)->getId(); return $this; } diff --git a/app/Models/TeamSynonym.php b/app/Models/TeamSynonym.php index a8a20495..c4feb86b 100644 --- a/app/Models/TeamSynonym.php +++ b/app/Models/TeamSynonym.php @@ -47,11 +47,11 @@ public static function findBySynonym($synonym) } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function team() { - return $this->hasOne(Team::class); + return $this->belongsTo(Team::class); } /** @@ -61,4 +61,28 @@ public function getId() { return $this->id; } + + /** + * @param string $synonym + * + * @return TeamSynonym + */ + public function setSynonym($synonym) + { + $this->synonym = $synonym; + + return $this; + } + + /** + * @param int $teamId + * + * @return TeamSynonym + */ + public function setTeamId($teamId) + { + $this->team_id = $teamId; + + return $this; + } } \ No newline at end of file diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 6b1d1918..721390e9 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -539,6 +539,7 @@ public function resume() { if ($this->status_code === self::STATUS_UNKNOWN_DATA) { $this->status_code = self::STATUS_VALIDATING_RECORDS; + $this->unknowns = null; } return $this; diff --git a/app/Models/VenueSynonym.php b/app/Models/VenueSynonym.php index a03e2379..1a21baee 100644 --- a/app/Models/VenueSynonym.php +++ b/app/Models/VenueSynonym.php @@ -41,11 +41,11 @@ public static function findBySynonym($synonym) } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function venue() { - return $this->hasOne(Venue::class); + return $this->belongsTo(Venue::class); } /** @@ -55,4 +55,28 @@ public function getId() { return $this->id; } + + /** + * @param string $synonym + * + * @return VenueSynonym + */ + public function setSynonym($synonym) + { + $this->synonym = $synonym; + + return $this; + } + + /** + * @param int $venueId + * + * @return VenueSynonym + */ + public function setTeamId($venueId) + { + $this->venue_id = $venueId; + + return $this; + } } diff --git a/app/Repositories/VenuesRepository.php b/app/Repositories/VenuesRepository.php index 141ad48c..cc6cb7dc 100644 --- a/app/Repositories/VenuesRepository.php +++ b/app/Repositories/VenuesRepository.php @@ -69,18 +69,18 @@ public function findByName($name) return null; } - public function findByNameWithinMapped(UploadJob $job, $team) + public function findByNameWithinMapped(UploadJob $job, $venue) { $jobId = $job->getId(); if (is_null($this->mappedModelsByName[$jobId])) { - /** @var MappedVenue $mappedTeam */ - foreach (MappedVenue::findByJob($jobId) as $mappedTeam) { - $this->mappedModelsByName[$jobId][$mappedTeam->getName()] = $mappedTeam->team; + /** @var MappedVenue $mappedVenue */ + foreach (MappedVenue::findByJob($jobId) as $mappedVenue) { + $this->mappedModelsByName[$jobId][$mappedVenue->getName()] = $mappedVenue->venue; } } - if (isset($this->mappedModelsByName[$jobId][$team])) { - return $this->mappedModelsByName[$jobId][$team]; + if (isset($this->mappedModelsByName[$jobId][$venue])) { + return $this->mappedModelsByName[$jobId][$venue]; } else { return null; } diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index e5e5634e..47862132 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -37,14 +37,6 @@ class InteractiveFixturesUploadService implements InteractiveUploadContract /** @var VenuesRepository */ private $venuesRepository; - - /** @var Collection */ - private $mappedTeams; - /** @var Collection */ - private $mappedVenues; - /** @var Collection */ - private $newVenues; - /** * @inheritDoc */ @@ -107,10 +99,6 @@ public function createJob($seasonId, UploadedFile $file) */ public function processJob(UploadJob $job) { - $this->mappedTeams = $job->mappedTeams; - $this->mappedVenues = $job->mappedVenues; - $this->newVenues = $job->newVenues; - /** @var UploadJobStatus $status */ $status = UploadJobStatus::loadStatus($job->getStatus()); diff --git a/app/Services/MappingService.php b/app/Services/MappingService.php index 069cc327..95f55850 100644 --- a/app/Services/MappingService.php +++ b/app/Services/MappingService.php @@ -3,6 +3,7 @@ namespace LVA\Services; use LVA\Models\Team; +use LVA\Models\Venue; /** @@ -38,6 +39,14 @@ public function findTeamMappings($divisionId, $team) */ public function findVenueMappings($venue) { - return []; + $mappings = []; + foreach (Venue::all() as $venue) { + $mappings[] = [ + 'value' => $venue->id, + 'text' => $venue->venue, + ]; + } + + return $mappings; } } \ No newline at end of file diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index dfd1634e..deb868d3 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -153,7 +153,7 @@ $('#load-fixture-modal').find('#unknowns').append(newUnknown); }); - $('#continue-button').addClass('disabled'); + $('#continue-button').addClass('disabled').blur(); $('#load-fixture-modal').modal('show'); } else if (status.StatusCode != 99) { From e24d47926342bd988694532d5ff94046b2b33189 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 5 Mar 2017 11:37:49 +0000 Subject: [PATCH 36/62] lva-22: fixed the required property (it's not an attribute) --- .../available-appointments/create.blade.php | 4 ++-- .../available-appointments/edit.blade.php | 4 ++-- .../admin/data-management/clubs/create.blade.php | 2 +- .../admin/data-management/clubs/edit.blade.php | 2 +- .../data-management/divisions/create.blade.php | 2 +- .../data-management/divisions/edit.blade.php | 2 +- .../data-management/fixtures/create.blade.php | 16 ++++++++-------- .../data-management/fixtures/edit.blade.php | 16 ++++++++-------- .../admin/data-management/roles/create.blade.php | 2 +- .../admin/data-management/roles/edit.blade.php | 2 +- .../data-management/seasons/create.blade.php | 2 +- .../admin/data-management/seasons/edit.blade.php | 2 +- .../admin/data-management/teams/create.blade.php | 4 ++-- .../admin/data-management/teams/edit.blade.php | 4 ++-- .../data-management/venues/create.blade.php | 2 +- .../admin/data-management/venues/edit.blade.php | 2 +- 16 files changed, 34 insertions(+), 34 deletions(-) diff --git a/resources/views/admin/data-management/available-appointments/create.blade.php b/resources/views/admin/data-management/available-appointments/create.blade.php index 338571bc..4d1f573a 100644 --- a/resources/views/admin/data-management/available-appointments/create.blade.php +++ b/resources/views/admin/data-management/available-appointments/create.blade.php @@ -19,7 +19,7 @@
{!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('fixture_id', '

:message

') !!}
@@ -27,7 +27,7 @@
{!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('role_id', '

:message

') !!}
diff --git a/resources/views/admin/data-management/available-appointments/edit.blade.php b/resources/views/admin/data-management/available-appointments/edit.blade.php index a662fbc1..5b6ef5fa 100644 --- a/resources/views/admin/data-management/available-appointments/edit.blade.php +++ b/resources/views/admin/data-management/available-appointments/edit.blade.php @@ -26,7 +26,7 @@
{!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('fixture_id', '

:message

') !!}
@@ -34,7 +34,7 @@
{!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('role_id', '

:message

') !!}
diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index 2c13b2a0..4cae5b5f 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('club', null, ['class' => 'form-control']) !!} + {!! Form::text('club', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('club', '

:message

') !!}
diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index 9ba08102..f7477a6b 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('club', null, ['class' => 'form-control']) !!} + {!! Form::text('club', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('club', '

:message

') !!}
diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php index 8bd16b9c..21507de8 100644 --- a/resources/views/admin/data-management/divisions/create.blade.php +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -21,7 +21,7 @@
{!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('division', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('division', '

:message

') !!}
diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index 2414407f..cc5905d5 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -25,7 +25,7 @@
{!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('division', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('division', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('division', '

:message

') !!}
diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php index 5eabf93f..0302ae55 100644 --- a/resources/views/admin/data-management/fixtures/create.blade.php +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('division_id', 'Division: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('division_id', '

:message

') !!}
@@ -21,7 +21,7 @@
{!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('match_number', '

:message

') !!}
@@ -29,7 +29,7 @@
{!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('match_date', '

:message

') !!}
@@ -37,7 +37,7 @@
{!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('warm_up_time', '

:message

') !!}
@@ -45,7 +45,7 @@
{!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('start_time', '

:message

') !!}
@@ -53,7 +53,7 @@
{!! Form::label('home_team_id', 'Home Team: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('home_team_id', '

:message

') !!}
@@ -61,7 +61,7 @@
{!! Form::label('away_team_id', 'Away Team: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('away_team_id', '

:message

') !!}
@@ -69,7 +69,7 @@
{!! Form::label('venue_id', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('venue_id', '

:message

') !!}
diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index 335d2f40..34679de3 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('division_id', 'Division Id: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('division_id', '

:message

') !!}
@@ -25,7 +25,7 @@
{!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('match_number', '

:message

') !!}
@@ -33,7 +33,7 @@
{!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::date('match_date', $fixture->match_date->format('Y-m-d'), ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::date('match_date', $fixture->match_date->format('Y-m-d'), ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('match_date', '

:message

') !!}
@@ -41,7 +41,7 @@
{!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::input('time', 'warm_up_time', $fixture->warm_up_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::input('time', 'warm_up_time', $fixture->warm_up_time->format('H:i'), ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('warm_up_time', '

:message

') !!}
@@ -49,7 +49,7 @@
{!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::input('time', 'start_time', $fixture->start_time->format('H:i'), ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::input('time', 'start_time', $fixture->start_time->format('H:i'), ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('start_time', '

:message

') !!}
@@ -57,7 +57,7 @@
{!! Form::label('home_team_id', 'Home Team Id: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('home_team_id', '

:message

') !!}
@@ -65,7 +65,7 @@
{!! Form::label('away_team_id', 'Away Team Id: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('away_team_id', '

:message

') !!}
@@ -73,7 +73,7 @@
{!! Form::label('venue_id', 'Venue Id: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('venue_id', '

:message

') !!}
diff --git a/resources/views/admin/data-management/roles/create.blade.php b/resources/views/admin/data-management/roles/create.blade.php index d1ae6f1b..f2ec15cb 100644 --- a/resources/views/admin/data-management/roles/create.blade.php +++ b/resources/views/admin/data-management/roles/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('role', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('role', '

:message

') !!}
diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index d5f51ff1..f67a54d0 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('role', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('role', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('role', '

:message

') !!}
diff --git a/resources/views/admin/data-management/seasons/create.blade.php b/resources/views/admin/data-management/seasons/create.blade.php index 30a8de27..b98a2607 100644 --- a/resources/views/admin/data-management/seasons/create.blade.php +++ b/resources/views/admin/data-management/seasons/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('season', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('season', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('season', '

:message

') !!}
diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index 6d5f9d91..589d5674 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('season', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('season', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('season', '

:message

') !!}
diff --git a/resources/views/admin/data-management/teams/create.blade.php b/resources/views/admin/data-management/teams/create.blade.php index c55a4197..8fa5e1d4 100644 --- a/resources/views/admin/data-management/teams/create.blade.php +++ b/resources/views/admin/data-management/teams/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('club_id', 'Club: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), null, ['class' => 'form-control']) !!} {!! $errors->first('club_id', '

:message

') !!}
@@ -21,7 +21,7 @@
{!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('team', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('team', '

:message

') !!}
diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index 7ce3e4ec..8132d666 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control']) !!} {!! $errors->first('club_id', '

:message

') !!}
@@ -25,7 +25,7 @@
{!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('team', null, ['class' => 'form-control', 'required' => 'required']) !!} + {!! Form::text('team', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('team', '

:message

') !!}
diff --git a/resources/views/admin/data-management/venues/create.blade.php b/resources/views/admin/data-management/venues/create.blade.php index 96c02461..f2defe5c 100644 --- a/resources/views/admin/data-management/venues/create.blade.php +++ b/resources/views/admin/data-management/venues/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('venue', null, ['class' => 'form-control']) !!} + {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('venue', '

:message

') !!}
diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index ea4a7224..81fa302e 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('venue', null, ['class' => 'form-control']) !!} + {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true]) !!} {!! $errors->first('venue', '

:message

') !!}
From d6e4fdf8253bde126134002d1df5a62bf89ca1bc Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 5 Mar 2017 11:46:40 +0000 Subject: [PATCH 37/62] lva-22: added the autofocus property when appropriate --- resources/views/admin/data-management/clubs/create.blade.php | 2 +- resources/views/admin/data-management/clubs/edit.blade.php | 2 +- .../views/admin/data-management/divisions/create.blade.php | 2 +- resources/views/admin/data-management/divisions/edit.blade.php | 2 +- resources/views/admin/data-management/fixtures/create.blade.php | 2 +- resources/views/admin/data-management/fixtures/edit.blade.php | 2 +- resources/views/admin/data-management/roles/create.blade.php | 2 +- resources/views/admin/data-management/roles/edit.blade.php | 2 +- resources/views/admin/data-management/seasons/create.blade.php | 2 +- resources/views/admin/data-management/seasons/edit.blade.php | 2 +- resources/views/admin/data-management/teams/create.blade.php | 2 +- resources/views/admin/data-management/teams/edit.blade.php | 2 +- resources/views/admin/data-management/venues/create.blade.php | 2 +- resources/views/admin/data-management/venues/edit.blade.php | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index 4cae5b5f..ce0b98d0 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('club', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('club', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('club', '

:message

') !!}
diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index f7477a6b..888deeeb 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('club', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('club', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('club', '

:message

') !!}
diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php index 21507de8..aeaeb42e 100644 --- a/resources/views/admin/data-management/divisions/create.blade.php +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -21,7 +21,7 @@
{!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('division', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('division', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('division', '

:message

') !!}
diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index cc5905d5..112410a1 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -25,7 +25,7 @@
{!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('division', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('division', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('division', '

:message

') !!}
diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php index 0302ae55..e824acc3 100644 --- a/resources/views/admin/data-management/fixtures/create.blade.php +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -21,7 +21,7 @@
{!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('match_number', '

:message

') !!}
diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index 34679de3..6ba8c534 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -25,7 +25,7 @@
{!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('match_number', '

:message

') !!}
diff --git a/resources/views/admin/data-management/roles/create.blade.php b/resources/views/admin/data-management/roles/create.blade.php index f2ec15cb..cd148c3c 100644 --- a/resources/views/admin/data-management/roles/create.blade.php +++ b/resources/views/admin/data-management/roles/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('role', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('role', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('role', '

:message

') !!}
diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index f67a54d0..00585285 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('role', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('role', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('role', '

:message

') !!}
diff --git a/resources/views/admin/data-management/seasons/create.blade.php b/resources/views/admin/data-management/seasons/create.blade.php index b98a2607..07f4a537 100644 --- a/resources/views/admin/data-management/seasons/create.blade.php +++ b/resources/views/admin/data-management/seasons/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('season', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('season', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('season', '

:message

') !!}
diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index 589d5674..2b658579 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('season', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('season', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('season', '

:message

') !!}
diff --git a/resources/views/admin/data-management/teams/create.blade.php b/resources/views/admin/data-management/teams/create.blade.php index 8fa5e1d4..4da246ae 100644 --- a/resources/views/admin/data-management/teams/create.blade.php +++ b/resources/views/admin/data-management/teams/create.blade.php @@ -21,7 +21,7 @@
{!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('team', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('team', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('team', '

:message

') !!}
diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index 8132d666..b234b299 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -25,7 +25,7 @@
{!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('team', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('team', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('team', '

:message

') !!}
diff --git a/resources/views/admin/data-management/venues/create.blade.php b/resources/views/admin/data-management/venues/create.blade.php index f2defe5c..44a0944a 100644 --- a/resources/views/admin/data-management/venues/create.blade.php +++ b/resources/views/admin/data-management/venues/create.blade.php @@ -13,7 +13,7 @@
{!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('venue', '

:message

') !!}
diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index 81fa302e..fbe4e36f 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -17,7 +17,7 @@
{!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!}
- {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true]) !!} + {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} {!! $errors->first('venue', '

:message

') !!}
From e35ca614e42f19db517697cfa6477a12a85a52d8 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 5 Mar 2017 13:11:58 +0000 Subject: [PATCH 38/62] lva-22: Fixed updating some data without changin anything --- .../UpdateAvailableAppointmentRequest.php | 8 +++--- app/Http/Requests/UpdateDivisionRequest.php | 2 +- app/Http/Requests/UpdateFixtureRequest.php | 4 +-- app/Http/Requests/UpdateTeamRequest.php | 2 +- database/factories/ModelFactory.php | 4 +-- .../available-appointments/edit.blade.php | 1 - .../data-management/clubs/edit.blade.php | 1 + .../data-management/divisions/edit.blade.php | 1 + .../data-management/fixtures/edit.blade.php | 1 + .../data-management/roles/edit.blade.php | 1 + .../data-management/seasons/edit.blade.php | 1 + .../data-management/teams/edit.blade.php | 1 + .../data-management/venues/edit.blade.php | 1 + .../AvailableAppointmentsTableTest.php | 16 +++++++++++ tests/Admin/DataManagement/ClubsTableTest.php | 14 ++++++++++ .../DataManagement/DivisionsTableTest.php | 16 +++++++++++ .../DataManagement/FixturesTableTest.php | 28 +++++++++++++++++++ tests/Admin/DataManagement/RolesTableTest.php | 19 +++++++++++-- .../Admin/DataManagement/SeasonsTableTest.php | 14 ++++++++++ tests/Admin/DataManagement/TeamsTableTest.php | 16 +++++++++++ .../Admin/DataManagement/VenuesTableTest.php | 14 ++++++++++ 21 files changed, 151 insertions(+), 14 deletions(-) diff --git a/app/Http/Requests/UpdateAvailableAppointmentRequest.php b/app/Http/Requests/UpdateAvailableAppointmentRequest.php index fb455740..624a2759 100644 --- a/app/Http/Requests/UpdateAvailableAppointmentRequest.php +++ b/app/Http/Requests/UpdateAvailableAppointmentRequest.php @@ -30,8 +30,8 @@ public function authorize() public function rules() { return [ - 'fixture_id' => 'unique:available_appointments,fixture_id,NULL,id,role_id,' . $this->input('role_id'), - 'role_id' => 'unique:available_appointments,role_id,NULL,id,fixture_id,' . $this->input('fixture_id'), + 'fixture_id' => 'unique:available_appointments,fixture_id,' . $this->input('id') . ',id,role_id,' . $this->input('role_id'), + 'role_id' => 'unique:available_appointments,role_id,' . $this->input('id') . ',id,fixture_id,' . $this->input('fixture_id'), ]; } @@ -41,7 +41,7 @@ public function rules() protected function formatErrors(Validator $validator) { return [[ - 'Appointment already added.', - ]]; + 'Appointment already added.', + ]]; } } diff --git a/app/Http/Requests/UpdateDivisionRequest.php b/app/Http/Requests/UpdateDivisionRequest.php index 84855730..dc987073 100644 --- a/app/Http/Requests/UpdateDivisionRequest.php +++ b/app/Http/Requests/UpdateDivisionRequest.php @@ -30,7 +30,7 @@ public function rules() { return [ 'season_id' => 'required|exists:seasons,id', - 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $this->input('season_id'), + 'division' => 'required|unique:divisions,division,' . $this->input('id') . ',id,season_id,' . $this->input('season_id'), ]; } } diff --git a/app/Http/Requests/UpdateFixtureRequest.php b/app/Http/Requests/UpdateFixtureRequest.php index bd799ac1..dc3709f8 100644 --- a/app/Http/Requests/UpdateFixtureRequest.php +++ b/app/Http/Requests/UpdateFixtureRequest.php @@ -32,10 +32,10 @@ public function rules() 'division_id' => 'required|' . 'exists:divisions,id|' . - 'unique:fixtures,division_id,NULL,id' . + 'unique:fixtures,division_id,' . $this->input('id') . ',id' . ',home_team_id,' . $this->input('home_team_id') . ',away_team_id,' . $this->input('away_team_id'), - 'match_number' => 'required|unique:fixtures,match_number,NULL,id,division_id,' . $this->input('division_id'), + 'match_number' => 'required|unique:fixtures,match_number,' . $this->input('id') . ',id,division_id,' . $this->input('division_id'), 'match_date' => 'required', 'warm_up_time' => 'required', 'start_time' => 'required', diff --git a/app/Http/Requests/UpdateTeamRequest.php b/app/Http/Requests/UpdateTeamRequest.php index 33911cca..721615b9 100644 --- a/app/Http/Requests/UpdateTeamRequest.php +++ b/app/Http/Requests/UpdateTeamRequest.php @@ -30,7 +30,7 @@ public function rules() { return [ 'club_id' => 'required|exists:clubs,id', - 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $this->input('club_id') + 'team' => 'required|unique:teams,team,' . $this->input('id') . ',id,club_id,' . $this->input('club_id'), ]; } } diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 22a0357f..d218142a 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -78,8 +78,8 @@ }, 'match_number' => $faker->unique()->numberBetween(1, 100), 'match_date' => $faker->unique()->date('Y-m-d'), - 'warm_up_time' => $faker->unique()->time('H:i:s'), - 'start_time' => $faker->unique()->time('H:i:s'), + 'warm_up_time' => $faker->unique()->time('H:i:00'), + 'start_time' => $faker->unique()->time('H:i:00'), ]; }); diff --git a/resources/views/admin/data-management/available-appointments/edit.blade.php b/resources/views/admin/data-management/available-appointments/edit.blade.php index 5b6ef5fa..8d28c740 100644 --- a/resources/views/admin/data-management/available-appointments/edit.blade.php +++ b/resources/views/admin/data-management/available-appointments/edit.blade.php @@ -20,7 +20,6 @@ 'url' => ['admin/data-management/available-appointments', $availableAppointment->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $availableAppointment->id) !!}
diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index 888deeeb..fe50e8d1 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/clubs', $club->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $club->id) !!}
{!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index 112410a1..359ea86a 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/divisions', $division->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $division->id) !!}
{!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index 6ba8c534..ae4527ad 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/fixtures', $fixture->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $fixture->id) !!}
{!! Form::label('division_id', 'Division Id: ', ['class' => 'col-sm-3 control-label']) !!} diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index 00585285..a37042d6 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/roles', $role->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $role->id) !!}
{!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index 2b658579..397d32d5 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/seasons', $season->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $season->id) !!}
{!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index b234b299..549e624c 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/teams', $team->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $team->id) !!}
{!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!} diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index fbe4e36f..b9ac2863 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/venues', $venue->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $venue->id) !!}
{!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php index a38c02ea..f7d11370 100644 --- a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -115,6 +115,22 @@ public function testEditAvailableAppointment() /** @var AvailableAppointment $appointment */ $appointment = factory(AvailableAppointment::class)->create(); + // Don't change anything + $this->seeInDatabase('available_appointments', [ + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->role_id, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$appointment->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Appointment updated!') + ->seeInDatabase('available_appointments', [ + 'id' => $appointment->id, + 'fixture_id' => $appointment->fixture_id, + 'role_id' => $appointment->id, + ]); + /** @var Fixture $newFixture */ $newFixture = factory(Fixture::class)->create(); /** @var Role $newRole */ diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/Admin/DataManagement/ClubsTableTest.php index dc0ce2e2..a5ad1d69 100644 --- a/tests/Admin/DataManagement/ClubsTableTest.php +++ b/tests/Admin/DataManagement/ClubsTableTest.php @@ -83,6 +83,20 @@ public function testEditClub() /** @var Club $club */ $club = factory(Club::class)->create(); + // Don't change anything + $this->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$club->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Club updated!') + ->seeInDatabase('clubs', [ + 'id' => $club->id, + 'club' => $club->club, + ]); + /** @var Club $newClub */ $newClub = factory(Club::class)->make(); diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/Admin/DataManagement/DivisionsTableTest.php index 90a04f65..5ad719b4 100644 --- a/tests/Admin/DataManagement/DivisionsTableTest.php +++ b/tests/Admin/DataManagement/DivisionsTableTest.php @@ -88,6 +88,22 @@ public function testEditDivision() /** @var Division $division */ $division = factory(Division::class)->create(); + // Don't change anything + $this->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$division->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Division updated!') + ->seeInDatabase('divisions', [ + 'id' => $division->id, + 'season_id' => $division->season_id, + 'division' => $division->division, + ]); + /** @var Division $newDivision */ $newDivision = factory(Division::class)->make(); diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php index 369eee35..7d2aa03b 100644 --- a/tests/Admin/DataManagement/FixturesTableTest.php +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -131,6 +131,34 @@ public function testEditFixture() /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(); + // Don't change anything + $this->seeInDatabase('fixtures', [ + 'id' => $fixture->id, + 'division_id' => $fixture->division_id, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + 'venue_id' => $fixture->venue_id, + 'match_number' => $fixture->match_number, + 'match_date' => $fixture->match_date->format('Y-m-d'), + 'warm_up_time' => $fixture->warm_up_time, + 'start_time' => $fixture->start_time, + ]); + $this->visit(route(self::BASE_ROUTE . '.edit', [$fixture->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Fixture updated!') + ->seeInDatabase('fixtures', [ + 'id' => $fixture->id, + 'division_id' => $fixture->division_id, + 'home_team_id' => $fixture->home_team_id, + 'away_team_id' => $fixture->away_team_id, + 'venue_id' => $fixture->venue_id, + 'match_number' => $fixture->match_number, + 'match_date' => $fixture->match_date->format('Y-m-d'), + 'warm_up_time' => $fixture->warm_up_time, + 'start_time' => $fixture->start_time, + ]); + /** @var Fixture $newFixture */ $newFixture = factory(Fixture::class)->make(['id' => $fixture->id]); diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/Admin/DataManagement/RolesTableTest.php index 7b1c2ff8..5138ec51 100644 --- a/tests/Admin/DataManagement/RolesTableTest.php +++ b/tests/Admin/DataManagement/RolesTableTest.php @@ -83,12 +83,25 @@ public function testEditRole() /** @var Role $role */ $role = factory(Role::class)->create(); + // Don't change anything + $this->seeInDatabase('roles', [ + 'id' => $role->id, + 'role' => $role->role, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$role->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Role updated!') + ->seeInDatabase('roles', [ + 'id' => $role->id, + 'role' => $role->role, + ]); + /** @var Role $newRole */ $newRole = factory(Role::class)->make(); - $this->seeInDatabase('roles', [ - 'id' => 1, + 'id' => $role->id, 'role' => $role->role, ]) ->visit(route(self::BASE_ROUTE . '.edit', [$role->id])) @@ -97,7 +110,7 @@ public function testEditRole() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Role updated!') ->seeInDatabase('roles', [ - 'id' => 1, + 'id' => $role->id, 'role' => $newRole->role, ]); $role->role = $newRole->role; diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index 196ba8a4..f7953081 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -84,6 +84,20 @@ public function testEditSeason() /** @var Season $season */ $season = factory(Season::class)->create(); + // Don't change anything + $this->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$season->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Season updated!') + ->seeInDatabase('seasons', [ + 'id' => $season->id, + 'season' => $season->season, + ]); + /** @var Season $newSeason */ $newSeason = factory(Season::class)->make(); diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/Admin/DataManagement/TeamsTableTest.php index f3cd3460..8ce65d0f 100644 --- a/tests/Admin/DataManagement/TeamsTableTest.php +++ b/tests/Admin/DataManagement/TeamsTableTest.php @@ -88,6 +88,22 @@ public function testEditTeam() /** @var Team $team */ $team = factory(Team::class)->create(); + // Don't change anything + $this->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$team->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Team updated!') + ->seeInDatabase('teams', [ + 'id' => $team->id, + 'club_id' => $team->club_id, + 'team' => $team->team, + ]); + /** @var Team $newTeam */ $newTeam = factory(Team::class)->make(); diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/Admin/DataManagement/VenuesTableTest.php index 1c7d88a6..5721e77e 100644 --- a/tests/Admin/DataManagement/VenuesTableTest.php +++ b/tests/Admin/DataManagement/VenuesTableTest.php @@ -83,6 +83,20 @@ public function testEditVenue() /** @var Venue $venue */ $venue = factory(Venue::class)->create(); + // Don't change anything + $this->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]) + ->visit(route(self::BASE_ROUTE . '.edit', [$venue->id])) + ->press('Update') + ->seePageIs(route(self::BASE_ROUTE . '.index')) + ->seeInElement('#flash-notification .alert.alert-success', 'Venue updated!') + ->seeInDatabase('venues', [ + 'id' => $venue->id, + 'venue' => $venue->venue, + ]); + /** @var Venue $newVenue */ $newVenue = factory(Venue::class)->make(); From 285eef5603ab8d6f09ddc43dbaca18a14f58a4d9 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 5 Mar 2017 18:54:58 +0000 Subject: [PATCH 39/62] lva-22: added validation for each row (still to do: present the errors to the end user) --- app/Models/UploadJobStatus.php | 118 ++++++++++++------ .../InteractiveFixturesUploadService.php | 17 +++ .../assets/js/load-fixtures-status-update.js | 2 + 3 files changed, 99 insertions(+), 38 deletions(-) diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 721390e9..19f27842 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -26,6 +26,7 @@ class UploadJobStatus const STATUS_INSERTING_RECORDS = 2; const STATUS_NOT_STARTED = 0; const STATUS_UNKNOWN_DATA = 10; + const STATUS_UNRECOVERABLE_ERROR = 20; const STATUS_DONE = 99; const UNKNOWN_HOME_TEAM = 1; @@ -39,6 +40,7 @@ class UploadJobStatus private $processed_rows; private $processing_line; private $unknowns; + private $errors; /** * @inheritDoc @@ -52,6 +54,7 @@ public function __construct() $this->processed_rows = 0; $this->processing_line = []; $this->unknowns = null; + $this->errors = []; } public static function loadStatus($statusArray) @@ -76,6 +79,8 @@ public function getStatusCodeMessage() return 'Inserting records'; case self::STATUS_UNKNOWN_DATA: return 'Unknown data'; + case self::STATUS_UNRECOVERABLE_ERROR: + return 'Unrecoverable error'; case self::STATUS_DONE: return 'Done'; default: @@ -110,6 +115,9 @@ public function load(array $data) if (array_has($data, 'unknowns')) { $this->unknowns = $data['unknowns']; } + if (array_has($data, 'errors')) { + $this->errors = $data['errors']; + } return $this; } @@ -127,6 +135,7 @@ public function toArray() 'processed_rows' => $this->getProcessedRows(), 'processing_line' => $this->processing_line, 'unknowns' => $this->getUnknowns(), + 'errors' => $this->getErrors(), ]; } @@ -146,44 +155,48 @@ public function toApiJson() $formattedStatus['Progress'] = floor($this->getProcessedRows() * 100 / $this->getTotalRows()); } - $formattedStatus['Fixture'] = [ - 'Division' => $this->getProcessingLineDivision(), - 'MatchNumber' => $this->getProcessingLineMatchNumber(), - 'HomeTeam' => $this->getProcessingLineHomeTeam(), - 'AwayTeam' => $this->getProcessingLineAwayTeam(), - 'Date' => $this->getProcessingLineDate(), - 'WarmUpTime' => $this->getProcessingLineWarmUpTime(), - 'StartTime' => $this->getProcessingLineStartTime(), - 'Venue' => $this->getProcessingLineVenue(), - ]; - - foreach ($this->getUnknowns() as $unknownType => $mappings) { - switch ($unknownType) { - case UploadJobStatus::UNKNOWN_HOME_TEAM: - $formattedStatus['Unknowns']['HomeTeam'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - 'Map' => route('loading-map-team'), - ], - ]; - break; - case UploadJobStatus::UNKNOWN_AWAY_TEAM: - $formattedStatus['Unknowns']['AwayTeam'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - 'Map' => route('loading-map-team'), - ], - ]; - break; - case UploadJobStatus::UNKNOWN_VENUE: - $formattedStatus['Unknowns']['Venue'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - //'Add' => route('loading-add-venue'), - 'Map' => route('loading-map-venue'), - ], - ]; - break; + if ($this->hasErrors()) { + $formattedStatus['Errors'] = $this->getErrors(); + } else { + $formattedStatus['Fixture'] = [ + 'Division' => $this->getProcessingLineDivision(), + 'MatchNumber' => $this->getProcessingLineMatchNumber(), + 'HomeTeam' => $this->getProcessingLineHomeTeam(), + 'AwayTeam' => $this->getProcessingLineAwayTeam(), + 'Date' => $this->getProcessingLineDate(), + 'WarmUpTime' => $this->getProcessingLineWarmUpTime(), + 'StartTime' => $this->getProcessingLineStartTime(), + 'Venue' => $this->getProcessingLineVenue(), + ]; + + foreach ($this->getUnknowns() as $unknownType => $mappings) { + switch ($unknownType) { + case UploadJobStatus::UNKNOWN_HOME_TEAM: + $formattedStatus['Unknowns']['HomeTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_AWAY_TEAM: + $formattedStatus['Unknowns']['AwayTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_VENUE: + $formattedStatus['Unknowns']['Venue'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + //'Add' => route('loading-add-venue'), + 'Map' => route('loading-map-venue'), + ], + ]; + break; + } } } @@ -252,6 +265,35 @@ public function setUnknown($unknownType, $mappings) $this->unknowns[$unknownType] = $mappings; } + /** + * @return bool + */ + public function hasErrors() + { + return $this->getStatusCode() === self::STATUS_UNRECOVERABLE_ERROR; + } + + /** + * @return string[] + */ + public function getErrors() + { + if (empty($this->errors)) { + return []; + } + + return $this->errors; + } + + /** + * @param string[] $errors + */ + public function setErrors($errors) + { + $this->status_code = self::STATUS_UNRECOVERABLE_ERROR; + $this->errors = $errors; + } + /** * @return int */ diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index 47862132..fc28f6cd 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -124,6 +124,23 @@ public function processJob(UploadJob $job) while (!feof($csvFile)) { $row = array_combine($headers, self::readOneLine($csvFile)); + $validator = \Validator::make($row, [ + 'Code' => 'required', + 'Match' => 'required|integer|min:1', + 'Home' => 'required', + 'Away' => 'required', + 'Date' => 'required|date_format:d/m/Y', + 'WUTime' => 'required|date_format:H:i:00', + 'StartTime' => 'required|date_format:H:i:00', + 'Hall' => 'required', + ]); + + if ($validator->fails()) { + $status->setErrors($validator->errors()->all()); + $allRowsProcessed = false; + break; + } + // Store the current line $status ->setProcessingLineDivision($row['Code']) diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index deb868d3..c27b2723 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -156,6 +156,8 @@ $('#continue-button').addClass('disabled').blur(); $('#load-fixture-modal').modal('show'); + } else if (status.StatusCode == 20) { + console.log(status.Errors); } else if (status.StatusCode != 99) { setTimeout(poll, 1000); } From 8a69039f532198f789cd381f5f10799bf9696fbb Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Mon, 6 Mar 2017 17:13:54 +0000 Subject: [PATCH 40/62] dev: refactored test to migrate the DB only once and thus running much, much faster --- database/factories/ModelFactory.php | 1 + .../DataManagement/AvailableAppointmentsTableTest.php | 2 +- tests/Admin/DataManagement/ClubsTableTest.php | 2 -- tests/Admin/DataManagement/DivisionsTableTest.php | 2 -- tests/Admin/DataManagement/FixturesTableTest.php | 1 - tests/Admin/DataManagement/RolesTableTest.php | 2 -- tests/Admin/DataManagement/SeasonsTableTest.php | 2 -- tests/Admin/DataManagement/TeamsTableTest.php | 2 -- tests/Admin/DataManagement/VenuesTableTest.php | 2 -- tests/TestCase.php | 10 +++++++++- 10 files changed, 11 insertions(+), 15 deletions(-) diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index d218142a..71fb4bf3 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -17,6 +17,7 @@ 'email' => $faker->unique()->email, 'password' => bcrypt($faker->unique()->password()), 'remember_token' => $faker->unique()->md5, + 'api_token' => $faker->unique()->md5, ]; }); diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php index f7d11370..8ef2e3aa 100644 --- a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -128,7 +128,7 @@ public function testEditAvailableAppointment() ->seeInDatabase('available_appointments', [ 'id' => $appointment->id, 'fixture_id' => $appointment->fixture_id, - 'role_id' => $appointment->id, + 'role_id' => $appointment->role_id, ]); /** @var Fixture $newFixture */ diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/Admin/DataManagement/ClubsTableTest.php index a5ad1d69..633319d3 100644 --- a/tests/Admin/DataManagement/ClubsTableTest.php +++ b/tests/Admin/DataManagement/ClubsTableTest.php @@ -60,7 +60,6 @@ public function testAddClub() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Club added!') ->seeInDatabase('clubs', [ - 'id' => 1, 'club' => $club->club, ]); @@ -71,7 +70,6 @@ public function testAddClub() ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The club already exists.') ->seeInDatabase('clubs', [ - 'id' => 1, 'club' => $club->club, ]); } diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/Admin/DataManagement/DivisionsTableTest.php index 5ad719b4..a3af0dde 100644 --- a/tests/Admin/DataManagement/DivisionsTableTest.php +++ b/tests/Admin/DataManagement/DivisionsTableTest.php @@ -62,7 +62,6 @@ public function testAddDivision() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Division added!') ->seeInDatabase('divisions', [ - 'id' => 1, 'season_id' => $division->season_id, 'division' => $division->division, ]); @@ -75,7 +74,6 @@ public function testAddDivision() ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The division already exists in the same season.') ->seeInDatabase('divisions', [ - 'id' => 1, 'season_id' => $division->season_id, 'division' => $division->division, ]); diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/Admin/DataManagement/FixturesTableTest.php index 7d2aa03b..84546cca 100644 --- a/tests/Admin/DataManagement/FixturesTableTest.php +++ b/tests/Admin/DataManagement/FixturesTableTest.php @@ -67,7 +67,6 @@ public function testAddFixture() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Fixture added!') ->seeInDatabase('fixtures', [ - 'id' => 1, 'division_id' => $fixture->division_id, 'home_team_id' => $fixture->home_team_id, 'away_team_id' => $fixture->away_team_id, diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/Admin/DataManagement/RolesTableTest.php index 5138ec51..015ca1d5 100644 --- a/tests/Admin/DataManagement/RolesTableTest.php +++ b/tests/Admin/DataManagement/RolesTableTest.php @@ -60,7 +60,6 @@ public function testAddRole() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Role added!') ->seeInDatabase('roles', [ - 'id' => 1, 'role' => $role->role, ]); @@ -71,7 +70,6 @@ public function testAddRole() ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The role already exists.') ->seeInDatabase('roles', [ - 'id' => 1, 'role' => $role->role, ]); } diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/Admin/DataManagement/SeasonsTableTest.php index f7953081..c85b294f 100644 --- a/tests/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/Admin/DataManagement/SeasonsTableTest.php @@ -61,7 +61,6 @@ public function testAddSeason() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Season added!') ->seeInDatabase('seasons', [ - 'id' => 1, 'season' => $season->season, ]); @@ -72,7 +71,6 @@ public function testAddSeason() ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The season already exists.') ->seeInDatabase('seasons', [ - 'id' => 1, 'season' => $season->season, ]); } diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/Admin/DataManagement/TeamsTableTest.php index 8ce65d0f..b6df1424 100644 --- a/tests/Admin/DataManagement/TeamsTableTest.php +++ b/tests/Admin/DataManagement/TeamsTableTest.php @@ -62,7 +62,6 @@ public function testAddTeam() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Team added!') ->seeInDatabase('teams', [ - 'id' => 1, 'club_id' => $team->club_id, 'team' => $team->team, ]); @@ -75,7 +74,6 @@ public function testAddTeam() ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The team already exists in the same club.') ->seeInDatabase('teams', [ - 'id' => 1, 'club_id' => $team->club_id, 'team' => $team->team, ]); diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/Admin/DataManagement/VenuesTableTest.php index 5721e77e..f4fc912f 100644 --- a/tests/Admin/DataManagement/VenuesTableTest.php +++ b/tests/Admin/DataManagement/VenuesTableTest.php @@ -60,7 +60,6 @@ public function testAddVenue() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Venue added!') ->seeInDatabase('venues', [ - 'id' => 1, 'venue' => $venue->venue, ]); @@ -71,7 +70,6 @@ public function testAddVenue() ->seePageIs(route(self::BASE_ROUTE . '.create')) ->seeInElement('.alert.alert-danger', 'The venue already exists.') ->seeInDatabase('venues', [ - 'id' => 1, 'venue' => $venue->venue, ]); } diff --git a/tests/TestCase.php b/tests/TestCase.php index d8ce8315..7aecc604 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,12 +4,17 @@ use Illuminate\Contracts\Console\Kernel; use Artisan; +use Illuminate\Foundation\Testing\DatabaseTransactions; use LVA\User; class TestCase extends \Illuminate\Foundation\Testing\TestCase { + use DatabaseTransactions; + protected $users = []; + protected static $refreshDatabase = true; + /** * The base URL to use while testing the application. * @@ -34,7 +39,10 @@ public function createApplication() protected function setUp() { parent::setUp(); - Artisan::call('migrate:refresh'); + if (self::$refreshDatabase) { + Artisan::call('migrate:refresh'); + self::$refreshDatabase = false; + } } /** From ef55bdd782e1e6afeaaf79bbc0a18d14c4347889 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Tue, 7 Mar 2017 12:34:16 +0000 Subject: [PATCH 41/62] lva-22: added the unrecoverable errors panel in the status page --- app/Models/UploadJobStatus.php | 20 ++++++++++++++++++- .../InteractiveFixturesUploadService.php | 9 +++++---- .../assets/js/load-fixtures-status-update.js | 8 +++++++- .../data-management/load/status.blade.php | 6 ++++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 19f27842..71f34547 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -41,6 +41,7 @@ class UploadJobStatus private $processing_line; private $unknowns; private $errors; + private $error_line; /** * @inheritDoc @@ -55,6 +56,7 @@ public function __construct() $this->processing_line = []; $this->unknowns = null; $this->errors = []; + $this->error_line = null; } public static function loadStatus($statusArray) @@ -118,6 +120,9 @@ public function load(array $data) if (array_has($data, 'errors')) { $this->errors = $data['errors']; } + if (array_has($data, 'error_line')) { + $this->error_line = $data['error_line']; + } return $this; } @@ -136,6 +141,7 @@ public function toArray() 'processing_line' => $this->processing_line, 'unknowns' => $this->getUnknowns(), 'errors' => $this->getErrors(), + 'error_line' => $this->getErrorLine(), ]; } @@ -157,6 +163,8 @@ public function toApiJson() if ($this->hasErrors()) { $formattedStatus['Errors'] = $this->getErrors(); + $formattedStatus['ErrorLine'] = $this->getErrorLine(); + } else { $formattedStatus['Fixture'] = [ 'Division' => $this->getProcessingLineDivision(), @@ -287,11 +295,21 @@ public function getErrors() /** * @param string[] $errors + * @param int $errorLine */ - public function setErrors($errors) + public function setErrors($errors, $errorLine) { $this->status_code = self::STATUS_UNRECOVERABLE_ERROR; $this->errors = $errors; + $this->error_line = $errorLine; + } + + /** + * @return int|null + */ + public function getErrorLine() + { + return $this->error_line; } /** diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index fc28f6cd..0e0a17d0 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -18,10 +18,9 @@ use LVA\Repositories\VenuesRepository; use LVA\Services\Contracts\InteractiveUploadContract; use Carbon\Carbon; -use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\UploadedFile; - use LVA\Models\UploadJob; +use Illuminate\Support\Facades\Validator; class InteractiveFixturesUploadService implements InteractiveUploadContract { @@ -124,7 +123,7 @@ public function processJob(UploadJob $job) while (!feof($csvFile)) { $row = array_combine($headers, self::readOneLine($csvFile)); - $validator = \Validator::make($row, [ + $validator = Validator::make($row, [ 'Code' => 'required', 'Match' => 'required|integer|min:1', 'Home' => 'required', @@ -136,11 +135,13 @@ public function processJob(UploadJob $job) ]); if ($validator->fails()) { - $status->setErrors($validator->errors()->all()); + $status->setErrors($validator->errors()->all(), $processedLines + 2); $allRowsProcessed = false; break; } + unset($validator); + // Store the current line $status ->setProcessingLineDivision($row['Code']) diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index c27b2723..47e2a03e 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -157,7 +157,13 @@ $('#load-fixture-modal').modal('show'); } else if (status.StatusCode == 20) { - console.log(status.Errors); + var alert = $('#unrecoverable-errors'); + alert.find('#error-line-number').text(status.ErrorLine); + $.each(status.Errors, function (key, error) { + alert.find('ul').append($('
  • ' + error + '
  • ')) + }); + alert.show(); + $('.progress-bar').removeClass('progress-bar-striped active'); } else if (status.StatusCode != 99) { setTimeout(poll, 1000); } diff --git a/resources/views/admin/data-management/load/status.blade.php b/resources/views/admin/data-management/load/status.blade.php index 68d8f22e..5b03bc40 100644 --- a/resources/views/admin/data-management/load/status.blade.php +++ b/resources/views/admin/data-management/load/status.blade.php @@ -20,6 +20,12 @@

    +
    @include('_partial.load-fixture-modal') From a97f8ce396a6bdd484739f809d56cbe5572c3963 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Tue, 7 Mar 2017 16:44:46 +0000 Subject: [PATCH 42/62] lva-22: added method to clean-up a job --- app/Console/Commands/PurgeUploadJobs.php | 51 +++++++++++++++++++ app/Console/Kernel.php | 2 + app/Models/UploadJob.php | 12 +++++ .../InteractiveFixturesUploadService.php | 12 ++++- 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/PurgeUploadJobs.php diff --git a/app/Console/Commands/PurgeUploadJobs.php b/app/Console/Commands/PurgeUploadJobs.php new file mode 100644 index 00000000..4842ee18 --- /dev/null +++ b/app/Console/Commands/PurgeUploadJobs.php @@ -0,0 +1,51 @@ +uploadService = $uploadService; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $jobs = UploadJob::stale()->get(); + + foreach ($jobs as $job) { + $this->uploadService->cleanUp($job); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 4bb7ae3b..47aba48d 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -4,6 +4,7 @@ use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use LVA\Console\Commands\PurgeUploadJobs; class Kernel extends ConsoleKernel { @@ -13,6 +14,7 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ + PurgeUploadJobs::class ]; /** diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index 097acbdf..a15b2190 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -2,6 +2,8 @@ namespace LVA\Models; +use Carbon\Carbon; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; /** @@ -48,6 +50,16 @@ public function uploadData() return $this->hasMany(UploadJobData::class); } + /** + * @param Builder $query + * + * @return Builder + */ + public function scopeStale(Builder $query) + { + return $query->where('updated_at', '<', Carbon::now()->subWeek()); + } + /** * @return int */ diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index 0e0a17d0..aa0fbcba 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -260,10 +260,20 @@ public function processJob(UploadJob $job) } if ($status->isDone()) { - // @todo Clean up + $this->cleanUp($job); } } + /** + * @param UploadJob $job + */ + public function cleanUp(UploadJob $job) + { + $job->mappedTeams()->delete(); + $job->mappedVenues()->delete(); + $job->uploadData()->delete(); + $job->delete(); + } /******************* * PRIVATE METHODS * From 07696df033e389a8a5a8f83b730ac882f4db9204 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Tue, 7 Mar 2017 22:06:04 +0000 Subject: [PATCH 43/62] lva-22: fixed the reporting of an unrecoverable error --- app/Models/UploadJobStatus.php | 6 +++--- resources/assets/js/load-fixtures-status-update.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 71f34547..67637cc0 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -155,10 +155,10 @@ public function toApiJson() 'StatusMessage' => $this->getStatusCodeMessage(), ]; - if ($this->isValidating()) { - $formattedStatus['Progress'] = floor($this->getProcessedLines() * 100 / $this->getTotalLines()); - } elseif ($this->isInserting()) { + if ($this->isInserting()) { $formattedStatus['Progress'] = floor($this->getProcessedRows() * 100 / $this->getTotalRows()); + } else { + $formattedStatus['Progress'] = floor($this->getProcessedLines() * 100 / $this->getTotalLines()); } if ($this->hasErrors()) { diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index 47e2a03e..f60c1fdb 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -162,7 +162,7 @@ $.each(status.Errors, function (key, error) { alert.find('ul').append($('
  • ' + error + '
  • ')) }); - alert.show(); + alert.removeClass('hidden'); $('.progress-bar').removeClass('progress-bar-striped active'); } else if (status.StatusCode != 99) { setTimeout(poll, 1000); From bac058a5a9756a38427e10f00a33eaff3f1815bb Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Fri, 10 Mar 2017 15:51:12 +0000 Subject: [PATCH 44/62] dev: started added integration tests --- app/Models/UploadJobStatus.php | 2 +- database/factories/ModelFactory.php | 33 +++ tests/TestCase.php | 38 ++- tests/data/fixtures_empty.csv | 0 .../Models/AvailableAppointmentTest.php | 49 +++ tests/integration/Models/ClubTest.php | 66 +++++ tests/integration/Models/DivisionTest.php | 94 ++++++ tests/integration/Models/FixtureTest.php | 278 ++++++++++++++++++ tests/integration/Models/MappedTeamTest.php | 18 ++ tests/integration/Models/MappedVenueTest.php | 18 ++ tests/integration/Models/RoleTest.php | 53 ++++ tests/integration/Models/SeasonTest.php | 56 ++++ tests/integration/Models/TeamSynonymTest.php | 18 ++ tests/integration/Models/TeamTest.php | 116 ++++++++ .../integration/Models/UploadJobDataTest.php | 18 ++ .../Models/UploadJobStatusTest.php | 18 ++ tests/integration/Models/UploadJobTest.php | 237 +++++++++++++++ tests/integration/Models/VenueSynonymTest.php | 18 ++ tests/integration/Models/VenueTest.php | 63 ++++ .../InteractiveFixturesUploadServiceTest.php | 27 ++ .../AvailableAppointmentsTableTest.php | 3 - .../Admin/DataManagement/ClubsTableTest.php | 0 .../DataManagement/DivisionsTableTest.php | 0 .../DataManagement/FixturesTableTest.php | 0 .../Admin/DataManagement/RolesTableTest.php | 0 .../Admin/DataManagement/SeasonsTableTest.php | 0 .../Admin/DataManagement/TeamsTableTest.php | 0 .../Admin/DataManagement/VenuesTableTest.php | 0 tests/{ => unit}/Admin/DataManagementTest.php | 0 .../Authentication/LoginLogoutTest.php | 0 .../Authentication/PasswordResetTest.php | 0 .../Authentication/RegistrationTest.php | 0 tests/{ => unit}/HomePageTest.php | 0 33 files changed, 1214 insertions(+), 9 deletions(-) create mode 100644 tests/data/fixtures_empty.csv create mode 100644 tests/integration/Models/AvailableAppointmentTest.php create mode 100644 tests/integration/Models/ClubTest.php create mode 100644 tests/integration/Models/DivisionTest.php create mode 100644 tests/integration/Models/FixtureTest.php create mode 100644 tests/integration/Models/MappedTeamTest.php create mode 100644 tests/integration/Models/MappedVenueTest.php create mode 100644 tests/integration/Models/RoleTest.php create mode 100644 tests/integration/Models/SeasonTest.php create mode 100644 tests/integration/Models/TeamSynonymTest.php create mode 100644 tests/integration/Models/TeamTest.php create mode 100644 tests/integration/Models/UploadJobDataTest.php create mode 100644 tests/integration/Models/UploadJobStatusTest.php create mode 100644 tests/integration/Models/UploadJobTest.php create mode 100644 tests/integration/Models/VenueSynonymTest.php create mode 100644 tests/integration/Models/VenueTest.php create mode 100644 tests/integration/Services/InteractiveFixturesUploadServiceTest.php rename tests/{ => unit}/Admin/DataManagement/AvailableAppointmentsTableTest.php (98%) rename tests/{ => unit}/Admin/DataManagement/ClubsTableTest.php (100%) rename tests/{ => unit}/Admin/DataManagement/DivisionsTableTest.php (100%) rename tests/{ => unit}/Admin/DataManagement/FixturesTableTest.php (100%) rename tests/{ => unit}/Admin/DataManagement/RolesTableTest.php (100%) rename tests/{ => unit}/Admin/DataManagement/SeasonsTableTest.php (100%) rename tests/{ => unit}/Admin/DataManagement/TeamsTableTest.php (100%) rename tests/{ => unit}/Admin/DataManagement/VenuesTableTest.php (100%) rename tests/{ => unit}/Admin/DataManagementTest.php (100%) rename tests/{ => unit}/Authentication/LoginLogoutTest.php (100%) rename tests/{ => unit}/Authentication/PasswordResetTest.php (100%) rename tests/{ => unit}/Authentication/RegistrationTest.php (100%) rename tests/{ => unit}/HomePageTest.php (100%) diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 67637cc0..aa9a8eae 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -141,7 +141,7 @@ public function toArray() 'processing_line' => $this->processing_line, 'unknowns' => $this->getUnknowns(), 'errors' => $this->getErrors(), - 'error_line' => $this->getErrorLine(), + 'error_line' => $this->getErrorLine(), ]; } diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 71fb4bf3..d7a62ca5 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -93,4 +93,37 @@ return factory(\LVA\Models\Role::class)->create()->id; }, ]; +}); + +$factory->define(\LVA\Models\UploadJobStatus::class, function (\Faker\Generator $faker) { + $totalLines = $faker->numberBetween(10, 200); + $processedLines = $faker->numberBetween(0, $totalLines); + $totalRows = $faker->numberBetween($totalLines, $totalLines * 2); + $processedRows = $faker->numberBetween(0, $totalRows); + + return [ + "status_code" => 1, + "total_lines" => $totalLines, + "processed_lines" => $processedLines, + "total_rows" => $totalRows, + "processed_rows" => $processedRows, + "processing_line" => [], + "unknowns" => null, + "errors" => [], + "error_line" => null, + ]; +}); + +$factory->define(\LVA\Models\UploadJob::class, function (\Faker\Generator $faker) { + return [ + 'file' => $faker->word . str_random(5) . '.csv', + 'type' => 'fixtures', + 'status' => function () { + return json_encode(factory(\LVA\Models\UploadJobStatus::class)->make()); + }, + 'season_id' => function () { + return factory(\LVA\Models\Season::class)->create()->id; + }, + 'row_count' => $faker->numberBetween(1, 100), + ]; }); \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 7aecc604..35e38464 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,14 +3,28 @@ namespace Tests; use Illuminate\Contracts\Console\Kernel; -use Artisan; -use Illuminate\Foundation\Testing\DatabaseTransactions; use LVA\User; +/** + * Class TestCase + * + * Some notes about the testing DB + * + * I cannot use a SQLite DB as the migrations that added new columns to an existing table don't specify a default + * and this is not acceptable for a non nullable column in SQLite. So, I need to use a MySQL DB + * + * Using the DatabaseMigrations trait is not an option as practically dropping and recreating the DB for every test + * it's too time consuming + * + * For some reason the DatabaseTransactions trait doesn't work properly. Records are left in the DB and therefore + * some tests will fail because the factory cannot add a new, unique, role, or season, or something else. Therefore + * I'm left to manually start a transaction in the setUp() and roll it back in tearDown(). This seems to work quite + * well. And quickly. + * + * @package Tests + */ class TestCase extends \Illuminate\Foundation\Testing\TestCase { - use DatabaseTransactions; - protected $users = []; protected static $refreshDatabase = true; @@ -39,14 +53,28 @@ public function createApplication() protected function setUp() { parent::setUp(); + + // Refresh the DB, but only once if (self::$refreshDatabase) { - Artisan::call('migrate:refresh'); + \Artisan::call('migrate:refresh'); self::$refreshDatabase = false; } + + // Manually start a transaction (see comment in the class PHPDoc + \DB::beginTransaction(); + } + + protected function tearDown() + { + // Manually rollback the transaction + \DB::rollback(); + + parent::tearDown(); } /** * @param int|null $userId + * * @return mixed */ protected function getFakeUser($userId = null) diff --git a/tests/data/fixtures_empty.csv b/tests/data/fixtures_empty.csv new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/Models/AvailableAppointmentTest.php b/tests/integration/Models/AvailableAppointmentTest.php new file mode 100644 index 00000000..4aa7c6c5 --- /dev/null +++ b/tests/integration/Models/AvailableAppointmentTest.php @@ -0,0 +1,49 @@ +create(); + + $this->assertInstanceOf(Fixture::class, $appointment->fixture); + } + + /** + * @test + */ + public function it_has_one_role() + { + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->create(); + + $this->assertInstanceOf(Role::class, $appointment->role); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var AvailableAppointment $appointment */ + $appointment = factory(AvailableAppointment::class)->create(); + + $this->assertEquals($appointment->id, $appointment->getId()); + } +} diff --git a/tests/integration/Models/ClubTest.php b/tests/integration/Models/ClubTest.php new file mode 100644 index 00000000..27d15a52 --- /dev/null +++ b/tests/integration/Models/ClubTest.php @@ -0,0 +1,66 @@ +times(2)->create(); + + // Create the appointments for the first role; + factory(Team::class)->times($teams)->create(['club_id' => $clubs[0]->id]); + + $this->assertCount(0, $clubs[1]->teams); + $this->assertCount($teams, $clubs[0]->teams); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var Club $club */ + $club = factory(Club::class)->create(); + + $this->assertEquals($club->id, $club->getId()); + } + + /** + * @test + */ + public function it_gets_the_name() + { + /** @var Club $club */ + $club = factory(Club::class)->create(); + + $this->assertEquals($club->club, $club->getName()); + } + + /** + * @test + */ + public function it_is_a_string() + { + /** @var Club $club */ + $club = factory(Club::class)->create(); + + $this->assertEquals($club->club, (string)$club); + } +} diff --git a/tests/integration/Models/DivisionTest.php b/tests/integration/Models/DivisionTest.php new file mode 100644 index 00000000..884861c4 --- /dev/null +++ b/tests/integration/Models/DivisionTest.php @@ -0,0 +1,94 @@ +create(); + + $this->assertInstanceOf(Season::class, $division->season); + } + + /** + * @test + */ + public function it_has_many_fixtures() + { + // Random number of fixtures to create + $fixtures = mt_rand(2, 10); + + /** @var Division[] $divisions */ + $divisions = factory(Division::class)->times(2)->create(); + + // Create a random number of fixture for the first division + factory(Fixture::class, $fixtures)->times($fixtures)->create(['division_id' => $divisions[0]->id]); + + $this->assertCount(0, $divisions[1]->fixtures); + $this->assertCount($fixtures, $divisions[0]->fixtures); + } + + /** + * @test + */ + public function it_can_be_found_by_name_in_a_season() + { + /** @var Season $season */ + $season = factory(Season::class)->create(); + /** @var Division $division */ + $division = factory(Division::class)->create(['season_id' => $season->getId()]); + + $this->assertEquals($division->getId(), Division::findByName($season->getId(), $division->getName())->getId()); + $this->assertNull(Division::findByName(0, $division->getName())); + $this->assertNull(Division::findByName($season->getId(), $division->getName() . '--')); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var Division $division */ + $division = factory(Division::class)->create(); + + $this->assertEquals($division->id, $division->getId()); + } + + /** + * @test + */ + public function it_gets_the_name() + { + /** @var Division $division */ + $division = factory(Division::class)->create(); + + $this->assertEquals($division->division, $division->getName()); + } + + /** + * @test + */ + public function it_is_a_string() + { + /** @var Division $division */ + $division = factory(Division::class)->create(); + + $this->assertEquals($division->season . ' ' . $division->division, (string)$division); + + } +} diff --git a/tests/integration/Models/FixtureTest.php b/tests/integration/Models/FixtureTest.php new file mode 100644 index 00000000..2af88354 --- /dev/null +++ b/tests/integration/Models/FixtureTest.php @@ -0,0 +1,278 @@ +create(); + + $this->assertInstanceOf(Division::class, $fixture->division); + } + + /** + * @test + */ + public function it_has_a_home_team() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertInstanceOf(Team::class, $fixture->home_team); + } + + /** + * @test + */ + public function it_has_an_away_team() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertInstanceOf(Team::class, $fixture->away_team); + } + + /** + * @test + */ + public function it_has_a_venue() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertInstanceOf(Venue::class, $fixture->venue); + + } + + /** + * @test + */ + public function it_has_many_available_appointments() + { + // Random number of available appointments + $appointmens = mt_rand(2, 10); + + /** @var Fixture[] $fixtures */ + $fixtures = factory(Fixture::class)->times(2)->create(); + + // create a random number of available appointments for the first fixture + factory(AvailableAppointment::class)->times($appointmens)->create(['fixture_id' => $fixtures[0]->getId()]); + + $this->assertCount(0, $fixtures[1]->available_appointments); + $this->assertCount($appointmens, $fixtures[0]->available_appointments); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertEquals($fixture->id, $fixture->getId()); + } + + /** + * @test + */ + public function it_can_set_the_division_id() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + /** @var Division $newDivision */ + $newDivision = factory(Division::class)->create(); + + $this->assertNotEquals($newDivision->getId(), $fixture->division_id); + + $fixture->setDivision($newDivision->getId()); + $this->assertEquals($newDivision->getId(), $fixture->division_id); + } + + /** + * @test + */ + public function it_can_set_the_match_number() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $newMatchNumber = $fixture->match_number + 1; + + $this->assertNotEquals($newMatchNumber, $fixture->match_number); + + $fixture->setMatchNumber($newMatchNumber); + $this->assertEquals($newMatchNumber, $fixture->match_number); + } + + /** + * @test + */ + public function it_can_set_the_match_date() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + /** @var Carbon $newDate */ + $newDate = $fixture->match_date->addDay(); + + $this->assertNotEquals($newDate, $fixture->match_date); + + $fixture->setMatchDate($newDate); + $this->assertEquals($newDate, $fixture->match_date); + } + + /** + * @test + */ + public function it_can_set_the_warm_up_time() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + /** @var Carbon $newWarmUpTime */ + $newWarmUpTime = $fixture->warm_up_time->addHour(); + + $this->assertNotEquals($newWarmUpTime, $fixture->warm_up_time); + + $fixture->setWarmUpTime($newWarmUpTime); + $this->assertEquals($newWarmUpTime, $fixture->warm_up_time); + } + + /** + * @test + */ + public function it_can_set_the_start_time() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + /** @var Carbon $newStartTime */ + $newStartTime = $fixture->start_time->addHour(); + + $this->assertNotEquals($newStartTime, $fixture->start_time); + + $fixture->setStartTime($newStartTime); + $this->assertEquals($newStartTime, $fixture->start_time); + } + + /** + * @test + */ + public function it_can_set_the_home_team() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + /** @var Team $newHomeTeam */ + $newHomeTeam = factory(Team::class)->create(); + + $this->assertNotEquals($newHomeTeam->getId(), $fixture->home_team_id); + + $fixture->setHomeTeam($newHomeTeam->getId()); + $this->assertEquals($newHomeTeam->getId(), $fixture->home_team_id); + } + + /** + * @test + */ + public function it_can_set_the_away_team() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + /** @var Team $newAwayTeam */ + $newAwayTeam = factory(Team::class)->create(); + + $this->assertNotEquals($newAwayTeam->getId(), $fixture->away_team_id); + + $fixture->setAwayTeam($newAwayTeam->getId()); + $this->assertEquals($newAwayTeam->getId(), $fixture->away_team_id); + } + + /** + * @test + */ + public function it_can_set_the_venue() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + /** @var Venue $newVenue */ + $newVenue = factory(Team::class)->create(); + + $this->assertNotEquals($newVenue->getId(), $fixture->venue_id); + + $fixture->setVenue($newVenue->getId()); + $this->assertEquals($newVenue->getId(), $fixture->venue_id); + } + + /** + * @test + */ + public function it_returns_the_warm_up_time_as_Carbon() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertInstanceOf(Carbon::class, $fixture->warm_up_time); + } + + /** + * @test + */ + public function it_returns_the_start_time_as_Carbon() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertInstanceOf(Carbon::class, $fixture->start_time); + } + + /** + * @test + */ + public function it_returns_the_match_date_as_Carbon() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertInstanceOf(Carbon::class, $fixture->match_date); + } + + /** + * @test + */ + public function it_is_a_string() + { + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $string = $fixture->division . ':' . $fixture->match_number . ' ' . + $fixture->match_date->format('d/m/y') . ' ' . + $fixture->start_time->format('H:i') . '(' . $fixture->warm_up_time->format('H:i') . ') ' . + $fixture->home_team . ' v ' . $fixture->away_team; + + $this->assertEquals($string, (string)$fixture); + } + +} diff --git a/tests/integration/Models/MappedTeamTest.php b/tests/integration/Models/MappedTeamTest.php new file mode 100644 index 00000000..71c9e484 --- /dev/null +++ b/tests/integration/Models/MappedTeamTest.php @@ -0,0 +1,18 @@ +create(); + + $this->assertEquals($role->id, $role->getId()); + } + + /** + * @test + */ + public function it_is_a_string() + { + $role = factory(Role::class)->create(); + + $this->assertEquals($role->role, (string)$role); + } + + /** + * @test + */ + public function it_has_many_appointments() + { + // random number of appointments to create + $appointments = mt_rand(2,10); + + /** @var Role[] $roles */ + $roles = factory(Role::class)->times(2)->create(); + + // Create the appointments for the first role; + factory(AvailableAppointment::class)->times($appointments)->create(['role_id' => $roles[0]->id]); + + $this->assertCount(0, $roles[1]->available_appointments); + $this->assertCount($appointments, $roles[0]->available_appointments); + } +} diff --git a/tests/integration/Models/SeasonTest.php b/tests/integration/Models/SeasonTest.php new file mode 100644 index 00000000..dbf3d46d --- /dev/null +++ b/tests/integration/Models/SeasonTest.php @@ -0,0 +1,56 @@ +times(2)->create(); + + // create a random number of division for the first season + factory(Division::class)->times($divisions)->create(['season_id' => $seasons[0]->getId()]); + + $this->assertCount(0, $seasons[1]->divisions); + $this->assertCount($divisions, $seasons[0]->divisions); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var Season $season */ + $season = factory(Season::class)->create(); + + $this->assertEquals($season->id, $season->getId()); + } + + /** + * @test + */ + public function it_is_a_string() + { + /** @var Season $season */ + $season = factory(Season::class)->create(); + + $this->assertEquals($season->season, (string)$season); + + } +} diff --git a/tests/integration/Models/TeamSynonymTest.php b/tests/integration/Models/TeamSynonymTest.php new file mode 100644 index 00000000..862099c7 --- /dev/null +++ b/tests/integration/Models/TeamSynonymTest.php @@ -0,0 +1,18 @@ +times(2)->create(); + + $this->assertEquals($teams[0]->getId(), Team::findByName($teams[0]->team)->getId()); + $this->assertNull(Team::findByName($teams[0]->team . '--')); + $this->assertEquals($teams[1]->getId(), Team::findByName($teams[1]->team)->getId()); + $this->assertNull(Team::findByName($teams[1]->team . '--')); + } + + /** + * @test + */ + public function it_belongs_to_a_club() + { + /** @var Team $team */ + $team = factory(Team::class)->create(); + + $this->assertInstanceOf(Club::class, $team->club); + } + + /** + * @test + */ + public function it_has_many_fixtures_as_away_team() + { + // Random number of fixtures to create + $fixtures = mt_rand(2, 10); + + /** @var Team[] $teams */ + $teams = factory(Team::class)->times(2)->create(); + + // Create a random number of fixture for the first team as away team + factory(Fixture::class, $fixtures)->times($fixtures)->create(['away_team_id' => $teams[0]->id]); + + $this->assertCount(0, $teams[1]->awayFixtures); + $this->assertCount($fixtures, $teams[0]->awayFixtures); + } + + /** + * @test + */ + public function it_has_many_fixtures_as_home_team() + { + // Random number of fixtures to create + $fixtures = mt_rand(2, 10); + + /** @var Team[] $teams */ + $teams = factory(Team::class)->times(2)->create(); + + // Create a random number of fixture for the first team as home team + factory(Fixture::class, $fixtures)->times($fixtures)->create(['home_team_id' => $teams[0]->id]); + + $this->assertCount(0, $teams[1]->homeFixtures); + $this->assertCount($fixtures, $teams[0]->homeFixtures); + } + + /** + * @test + */ + public function it_has_many_synonyms() + { + $this->markTestIncomplete('Need to create the factory for team synonyms.'); + } + + /** + * @test + */ + public function it_has_many_mapped_teams() + { + $this->markTestIncomplete('Need to create the factory for the mapped teams.'); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var Team $team */ + $team = factory(Team::class)->create(); + + $this->assertEquals($team->id, $team->getId()); + } + + /** + * @test + */ + public function it_is_a_string() + { + /** @var Team $team */ + $team = factory(Team::class)->create(); + + $this->assertEquals($team->team, (string)$team); + } + +} diff --git a/tests/integration/Models/UploadJobDataTest.php b/tests/integration/Models/UploadJobDataTest.php new file mode 100644 index 00000000..47040366 --- /dev/null +++ b/tests/integration/Models/UploadJobDataTest.php @@ -0,0 +1,18 @@ +faker = Factory::create(); + } + + /** + * @test + */ + public function it_has_many_mapped_teams() + { + $this->markTestIncomplete('Need to create the factory for the MappedTeam.'); + } + + /** + * @test + */ + public function it_has_many_mapped_venues() + { + $this->markTestIncomplete('Need to create the factory for MappedVenue.'); + + } + + /** + * @test + */ + public function it_has_many_new_venues() + { + $this->markTestIncomplete('Need to create the factory for NewVenue.'); + } + + /** + * @test + */ + public function it_has_many_data() + { + $this->markTestIncomplete('Need to create the factory for UploadJobsData.'); + } + + /** + * @test + */ + public function it_returns_stale_jobs() + { + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $this->assertEquals($job->id, $job->getId()); + } + + /** + * @test + */ + public function it_gets_the_associated_season() + { + /** @var Season $season */ + $season = factory(Season::class)->create(); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(['season_id' => $season->getId()]); + + $this->assertEquals($season->getId(), $job->getSeason()); + } + + /** + * @test + */ + public function it_sets_the_associated_season() + { + /** @var Season $season */ + $season = factory(Season::class)->create(); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $this->assertNotEquals($season->getId(), $job->getSeason()); + + $job->setSeason($season->getId()); + $this->assertEquals($season->getId(), $job->getSeason()); + } + + /** + * @test + */ + public function it_gets_the_file() + { + $file = $this->faker->file('/', '/tmp', false); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(['file' => $file]); + + $this->assertEquals($file, $job->getFile()); + } + + /** + * @test + */ + public function it_sets_the_file() + { + $faker = Factory::create(); + $file = $faker->file('/', '/tmp', false); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $this->assertNotEquals($file, $job->getFile()); + + $job->setFile($file); + $this->assertEquals($file, $job->getFile()); + } + + /** + * @test + */ + public function it_gets_the_job_type() + { + $type = $this->faker->word; + + // DO NOT USE create() as the DB only accept 'fixture' as a type + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->make(['type' => $type]); + + $this->assertEquals($type, $job->getType()); + } + + /** + * @test + */ + public function it_sets_the_job_type() + { + $type = $this->faker->word; + + // DO NOT USE create() as the DB only accept 'fixture' as a type + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->make(); + + $this->assertNotEquals($type, $job->getType()); + + $job->setType($type); + $this->assertEquals($type, $job->getType()); + } + + /** + * @test + */ + public function it_gets_the_status() + { + $this->markTestIncomplete('To be fixed.'); + // The UploadJobStatus does not have an Eloquent model, so we cannot use create() + /** @var UploadJobStatus $status */ + $status = factory(UploadJobStatus::class)->make(); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(['status' => json_encode($status->toArray())]); + + $this->assertEquals($status->toArray(), $job->getStatus()); + } + + /** + * @test + */ + public function it_sets_the_status() + { + $this->markTestIncomplete('To be fixed.'); + // The UploadJobStatus does not have an Eloquent model, so we cannot use create() + /** @var UploadJobStatus $status */ + $status = factory(UploadJobStatus::class)->make(); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $this->assertNotEquals($status->toArray(), $job->getStatus()); + + $job->setStatus($status->toArray()); + $this->assertEquals($status->toArray(), $job->getStatus()); + } + + /** + * @test + */ + public function it_store_the_status_as_json() + { + $this->markTestIncomplete('To be fixed.'); + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + dd($job); + $status = \DB::table($job->getTable())->where('id', $job->getId())->first(['status']); + + dd($status->status); + $this->assertJson($status->status); + } + + /** + * @test + */ + public function it_gets_the_total_row_number() + { + } + + /** + * @test + */ + public function it_sets_the_total_row_number() + { + } + + +} diff --git a/tests/integration/Models/VenueSynonymTest.php b/tests/integration/Models/VenueSynonymTest.php new file mode 100644 index 00000000..60250960 --- /dev/null +++ b/tests/integration/Models/VenueSynonymTest.php @@ -0,0 +1,18 @@ +times(2)->create(); + + $this->assertEquals($venues[0]->getId(), Venue::findByName($venues[0]->venue)->getId()); + $this->assertNull(Venue::findByName($venues[0]->venue . '--')); + $this->assertEquals($venues[1]->getId(), Venue::findByName($venues[1]->venue)->getId()); + $this->assertNull(Venue::findByName($venues[1]->venue . '--')); + } + + /** + * @test + */ + public function it_has_many_fixtures() + { + // Random number of fixtures to create + $fixtures = mt_rand(2, 10); + + /** @var Venue[] $venues */ + $venues = factory(Venue::class)->times(2)->create(); + + // Create a random number of fixture for the first team as away team + factory(Fixture::class, $fixtures)->times($fixtures)->create(['venue_id' => $venues[0]->id]); + + $this->assertCount(0, $venues[1]->fixtures); + $this->assertCount($fixtures, $venues[0]->fixtures); + } + + /** + * @test + */ + public function it_has_many_synonyms() + { + $this->markTestIncomplete('Need to create the factory for the mapped teams.'); + } + + /** + * @test + */ + public function it_has_many_mapped_venues() + { + $this->markTestIncomplete('Need to create the factory for the mapped teams.'); + } +} diff --git a/tests/integration/Services/InteractiveFixturesUploadServiceTest.php b/tests/integration/Services/InteractiveFixturesUploadServiceTest.php new file mode 100644 index 00000000..722b0e07 --- /dev/null +++ b/tests/integration/Services/InteractiveFixturesUploadServiceTest.php @@ -0,0 +1,27 @@ +create(); + } +} diff --git a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/unit/Admin/DataManagement/AvailableAppointmentsTableTest.php similarity index 98% rename from tests/Admin/DataManagement/AvailableAppointmentsTableTest.php rename to tests/unit/Admin/DataManagement/AvailableAppointmentsTableTest.php index 8ef2e3aa..4600bde5 100644 --- a/tests/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/unit/Admin/DataManagement/AvailableAppointmentsTableTest.php @@ -67,7 +67,6 @@ public function testAddAvailableAppointment() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') ->seeInDatabase('available_appointments', [ - 'id' => 1, 'fixture_id' => $appointment->fixture_id, 'role_id' => $appointment->role_id, ]); @@ -80,7 +79,6 @@ public function testAddAvailableAppointment() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') ->seeInDatabase('available_appointments', [ - 'id' => 2, 'fixture_id' => $appointment->fixture_id, 'role_id' => $newRole->id, ]); @@ -93,7 +91,6 @@ public function testAddAvailableAppointment() ->seePageIs(route(self::BASE_ROUTE . '.index')) ->seeInElement('#flash-notification .alert.alert-success', 'Appointment added!') ->seeInDatabase('available_appointments', [ - 'id' => 3, 'fixture_id' => $newFixture->id, 'role_id' => $appointment->role_id, ]); diff --git a/tests/Admin/DataManagement/ClubsTableTest.php b/tests/unit/Admin/DataManagement/ClubsTableTest.php similarity index 100% rename from tests/Admin/DataManagement/ClubsTableTest.php rename to tests/unit/Admin/DataManagement/ClubsTableTest.php diff --git a/tests/Admin/DataManagement/DivisionsTableTest.php b/tests/unit/Admin/DataManagement/DivisionsTableTest.php similarity index 100% rename from tests/Admin/DataManagement/DivisionsTableTest.php rename to tests/unit/Admin/DataManagement/DivisionsTableTest.php diff --git a/tests/Admin/DataManagement/FixturesTableTest.php b/tests/unit/Admin/DataManagement/FixturesTableTest.php similarity index 100% rename from tests/Admin/DataManagement/FixturesTableTest.php rename to tests/unit/Admin/DataManagement/FixturesTableTest.php diff --git a/tests/Admin/DataManagement/RolesTableTest.php b/tests/unit/Admin/DataManagement/RolesTableTest.php similarity index 100% rename from tests/Admin/DataManagement/RolesTableTest.php rename to tests/unit/Admin/DataManagement/RolesTableTest.php diff --git a/tests/Admin/DataManagement/SeasonsTableTest.php b/tests/unit/Admin/DataManagement/SeasonsTableTest.php similarity index 100% rename from tests/Admin/DataManagement/SeasonsTableTest.php rename to tests/unit/Admin/DataManagement/SeasonsTableTest.php diff --git a/tests/Admin/DataManagement/TeamsTableTest.php b/tests/unit/Admin/DataManagement/TeamsTableTest.php similarity index 100% rename from tests/Admin/DataManagement/TeamsTableTest.php rename to tests/unit/Admin/DataManagement/TeamsTableTest.php diff --git a/tests/Admin/DataManagement/VenuesTableTest.php b/tests/unit/Admin/DataManagement/VenuesTableTest.php similarity index 100% rename from tests/Admin/DataManagement/VenuesTableTest.php rename to tests/unit/Admin/DataManagement/VenuesTableTest.php diff --git a/tests/Admin/DataManagementTest.php b/tests/unit/Admin/DataManagementTest.php similarity index 100% rename from tests/Admin/DataManagementTest.php rename to tests/unit/Admin/DataManagementTest.php diff --git a/tests/Authentication/LoginLogoutTest.php b/tests/unit/Authentication/LoginLogoutTest.php similarity index 100% rename from tests/Authentication/LoginLogoutTest.php rename to tests/unit/Authentication/LoginLogoutTest.php diff --git a/tests/Authentication/PasswordResetTest.php b/tests/unit/Authentication/PasswordResetTest.php similarity index 100% rename from tests/Authentication/PasswordResetTest.php rename to tests/unit/Authentication/PasswordResetTest.php diff --git a/tests/Authentication/RegistrationTest.php b/tests/unit/Authentication/RegistrationTest.php similarity index 100% rename from tests/Authentication/RegistrationTest.php rename to tests/unit/Authentication/RegistrationTest.php diff --git a/tests/HomePageTest.php b/tests/unit/HomePageTest.php similarity index 100% rename from tests/HomePageTest.php rename to tests/unit/HomePageTest.php From cef43a9776b4af106f52558f85640f928cd3d5e7 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Fri, 10 Mar 2017 17:45:36 +0000 Subject: [PATCH 45/62] dev: set the test to log email instead of actually sending them --- phpunit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml b/phpunit.xml index 022d4029..8193fdd8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -23,6 +23,7 @@ + From 0f4e55d5a399c79663eed44e469adda508664d77 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 12 Mar 2017 18:15:11 +0000 Subject: [PATCH 46/62] lva-22: implemented insertion of data into the DB (and other various fixes) --- .../Admin/DataManagement/LoadController.php | 3 - .../Api/v1/UploadApiController.php | 20 ++- app/Models/UploadJobData.php | 2 +- app/Models/UploadJobStatus.php | 161 +++++++++++------- app/Repositories/TeamsRepository.php | 6 +- app/Repositories/VenuesRepository.php | 6 +- .../InteractiveFixturesUploadService.php | 107 +++++++++--- app/Services/MappingService.php | 4 +- app/Services/UploadDataService.php | 17 +- .../assets/js/load-fixtures-status-update.js | 87 +++++++--- .../data-management/fixtures/index.blade.php | 4 +- .../data-management/load/status.blade.php | 22 ++- 12 files changed, 302 insertions(+), 137 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/LoadController.php b/app/Http/Controllers/Admin/DataManagement/LoadController.php index fb63701a..e14a0de9 100644 --- a/app/Http/Controllers/Admin/DataManagement/LoadController.php +++ b/app/Http/Controllers/Admin/DataManagement/LoadController.php @@ -47,9 +47,6 @@ public function startUploadFixtures(Request $request) // Create upload job $job = $this->uploadService->createJob($request->input('season_id'), $request->file('upload_file')); - // Start the uploading - $this->uploadService->processJob($job); - // Redirect to the status page return Redirect::route('uploadStatus', ['job_id' => $job->getId()]); } diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 7c76c225..3e62630b 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -46,12 +46,16 @@ public function resumeUpload() return response()->json($uploadJob); } - $status = new UploadJobStatus(); - $status->load($uploadJob->getStatus())->resume(); + /** @var UploadJobStatus $status */ + $status = UploadJobStatus::loadStatus($uploadJob->getStatus()); - $uploadJob->setStatus($status->toArray())->save(); + if ($status->canResume()) { + $status->resume(); - $this->uploadService->processJob($uploadJob); + $uploadJob->setStatus($status->toArray())->save(); + + $this->uploadService->processJob($uploadJob); + } } public function getUploadStatus() @@ -61,8 +65,8 @@ public function getUploadStatus() return response()->json($uploadJob); } - $status = new UploadJobStatus(); - $status->load($uploadJob->getStatus()); + /** @var UploadJobStatus $status */ + $status = UploadJobStatus::loadStatus($uploadJob->getStatus()); return response()->json([ 'Timestamp' => time(), @@ -84,7 +88,7 @@ public function mapTeam(MapTeamRequest $request) $synonym = new TeamSynonym(); $synonym ->setSynonym($mappedTeam->getName()) - ->setTeamId($mappedTeam->getId()); + ->setTeamId($mappedTeam->team->getId()); $this->uploadDataService->add($request->input('job'), TeamSynonym::class, $synonym); @@ -118,7 +122,7 @@ public function mapVenue(MapVenueRequest $request) $synonym = new VenueSynonym(); $synonym ->setSynonym($mappedVenue->getName()) - ->setTeamId($mappedVenue->getId()); + ->setTeamId($mappedVenue->venue->getId()); $this->uploadDataService->add($request->input('job'), VenueSynonym::class, $synonym); diff --git a/app/Models/UploadJobData.php b/app/Models/UploadJobData.php index cf7dd315..ecbcbe61 100644 --- a/app/Models/UploadJobData.php +++ b/app/Models/UploadJobData.php @@ -39,7 +39,7 @@ class UploadJobData extends Model */ public static function findByJobId($jobId) { - return self::where('upload_job_id', $jobId)->get(); + return self::where('upload_job_id', $jobId)->orderBy('id', 'asc')->get(); } /** diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index aa9a8eae..536e74c0 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -22,11 +22,12 @@ */ class UploadJobStatus { - const STATUS_VALIDATING_RECORDS = 1; - const STATUS_INSERTING_RECORDS = 2; const STATUS_NOT_STARTED = 0; - const STATUS_UNKNOWN_DATA = 10; - const STATUS_UNRECOVERABLE_ERROR = 20; + const STATUS_VALIDATING_RECORDS = 10; + const STATUS_UNRECOVERABLE_VALIDATION_ERROR = 19; + const STATUS_INSERTING_RECORDS = 20; + const STATUS_UNRECOVERABLE_INSERT_ERROR = 29; + const STATUS_UNKNOWN_DATA = 11; const STATUS_DONE = 99; const UNKNOWN_HOME_TEAM = 1; @@ -81,7 +82,8 @@ public function getStatusCodeMessage() return 'Inserting records'; case self::STATUS_UNKNOWN_DATA: return 'Unknown data'; - case self::STATUS_UNRECOVERABLE_ERROR: + case self::STATUS_UNRECOVERABLE_VALIDATION_ERROR: + case self::STATUS_UNRECOVERABLE_INSERT_ERROR: return 'Unrecoverable error'; case self::STATUS_DONE: return 'Done'; @@ -155,55 +157,56 @@ public function toApiJson() 'StatusMessage' => $this->getStatusCodeMessage(), ]; - if ($this->isInserting()) { - $formattedStatus['Progress'] = floor($this->getProcessedRows() * 100 / $this->getTotalRows()); - } else { - $formattedStatus['Progress'] = floor($this->getProcessedLines() * 100 / $this->getTotalLines()); - } + if ($this->hasStarted()) { + if ($this->isInserting()) { + $formattedStatus['Progress'] = floor($this->getProcessedRows() * 100 / $this->getTotalRows()); + } else { + $formattedStatus['Progress'] = floor($this->getProcessedLines() * 100 / $this->getTotalLines()); + } - if ($this->hasErrors()) { - $formattedStatus['Errors'] = $this->getErrors(); - $formattedStatus['ErrorLine'] = $this->getErrorLine(); - - } else { - $formattedStatus['Fixture'] = [ - 'Division' => $this->getProcessingLineDivision(), - 'MatchNumber' => $this->getProcessingLineMatchNumber(), - 'HomeTeam' => $this->getProcessingLineHomeTeam(), - 'AwayTeam' => $this->getProcessingLineAwayTeam(), - 'Date' => $this->getProcessingLineDate(), - 'WarmUpTime' => $this->getProcessingLineWarmUpTime(), - 'StartTime' => $this->getProcessingLineStartTime(), - 'Venue' => $this->getProcessingLineVenue(), - ]; - - foreach ($this->getUnknowns() as $unknownType => $mappings) { - switch ($unknownType) { - case UploadJobStatus::UNKNOWN_HOME_TEAM: - $formattedStatus['Unknowns']['HomeTeam'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - 'Map' => route('loading-map-team'), - ], - ]; - break; - case UploadJobStatus::UNKNOWN_AWAY_TEAM: - $formattedStatus['Unknowns']['AwayTeam'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - 'Map' => route('loading-map-team'), - ], - ]; - break; - case UploadJobStatus::UNKNOWN_VENUE: - $formattedStatus['Unknowns']['Venue'] = [ - 'Mapping' => $mappings, - 'ApiUrls' => [ - //'Add' => route('loading-add-venue'), - 'Map' => route('loading-map-venue'), - ], - ]; - break; + if ($this->hasErrors()) { + $formattedStatus['Errors'] = $this->getErrors(); + $formattedStatus['ErrorLine'] = $this->getErrorLine(); + + } elseif ($this->hasUnknownData()) { + $formattedStatus['Fixture'] = [ + 'Division' => $this->getProcessingLineDivision(), + 'MatchNumber' => $this->getProcessingLineMatchNumber(), + 'HomeTeam' => $this->getProcessingLineHomeTeam(), + 'AwayTeam' => $this->getProcessingLineAwayTeam(), + 'Date' => $this->getProcessingLineDate(), + 'WarmUpTime' => $this->getProcessingLineWarmUpTime(), + 'StartTime' => $this->getProcessingLineStartTime(), + 'Venue' => $this->getProcessingLineVenue(), + ]; + + foreach ($this->getUnknowns() as $unknownType => $mappings) { + switch ($unknownType) { + case UploadJobStatus::UNKNOWN_HOME_TEAM: + $formattedStatus['Unknowns']['HomeTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_AWAY_TEAM: + $formattedStatus['Unknowns']['AwayTeam'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-team'), + ], + ]; + break; + case UploadJobStatus::UNKNOWN_VENUE: + $formattedStatus['Unknowns']['Venue'] = [ + 'Mapping' => $mappings, + 'ApiUrls' => [ + 'Map' => route('loading-map-venue'), + ], + ]; + break; + } } } } @@ -214,11 +217,19 @@ public function toApiJson() /** * @return bool */ - public function isNotStarted() + public function hasNotStarted() { return $this->status_code === self::STATUS_NOT_STARTED; } + /** + * @return bool + */ + public function hasStarted() + { + return !$this->hasNotStarted(); + } + /** * @return bool */ @@ -251,6 +262,21 @@ public function hasUnknownData() return $this->status_code === self::STATUS_UNKNOWN_DATA; } + /** + * @return bool + */ + public function canResume() + { + return !$this->isWorking() && !$this->isDone(); + } + + /** + * @return bool + */ + public function isWorking() + { + return $this->isValidating() || $this->isInserting(); + } /** * @return array */ @@ -278,7 +304,7 @@ public function setUnknown($unknownType, $mappings) */ public function hasErrors() { - return $this->getStatusCode() === self::STATUS_UNRECOVERABLE_ERROR; + return in_array($this->getStatusCode(), [self::STATUS_UNRECOVERABLE_VALIDATION_ERROR, self::STATUS_UNRECOVERABLE_INSERT_ERROR]); } /** @@ -297,11 +323,17 @@ public function getErrors() * @param string[] $errors * @param int $errorLine */ - public function setErrors($errors, $errorLine) + public function setValidationErrors($errors, $errorLine) { - $this->status_code = self::STATUS_UNRECOVERABLE_ERROR; - $this->errors = $errors; - $this->error_line = $errorLine; + $this->setErrors(self::STATUS_UNRECOVERABLE_VALIDATION_ERROR, $errors, $errorLine); + } + + /** + * @param string $error + */ + public function setInsertingError($error) + { + $this->setErrors(self::STATUS_UNRECOVERABLE_INSERT_ERROR, [$error]); } /** @@ -604,4 +636,15 @@ public function resume() return $this; } + + /** + * @param string[] $errors + * @param int|null $errorLine + */ + private function setErrors($statusCode, $errors, $errorLine = null) + { + $this->status_code = $statusCode; + $this->errors = $errors; + $this->error_line = $errorLine; + } } \ No newline at end of file diff --git a/app/Repositories/TeamsRepository.php b/app/Repositories/TeamsRepository.php index 68db2943..8045ab77 100644 --- a/app/Repositories/TeamsRepository.php +++ b/app/Repositories/TeamsRepository.php @@ -59,10 +59,8 @@ public function findByName($name) $this->modelsByName[$name] = $model; return $model; } else { - /** @var TeamSynonym $modelSynonym */ - $modelSynonym = TeamSynonym::findBySynonym($name); - if ($modelSynonym) { - $$model = $modelSynonym->team; + $model = TeamSynonym::findBySynonym($name); + if ($model) { $this->modelsByName[$name] = $model; return $model; } diff --git a/app/Repositories/VenuesRepository.php b/app/Repositories/VenuesRepository.php index cc6cb7dc..d84fcf2f 100644 --- a/app/Repositories/VenuesRepository.php +++ b/app/Repositories/VenuesRepository.php @@ -58,10 +58,8 @@ public function findByName($name) $this->modelsByName[$name] = $model; return $model; } else { - /** @var VenueSynonym $modelSynonym */ - $modelSynonym = VenueSynonym::findBySynonym($name); - if ($modelSynonym) { - $$model = $modelSynonym->team; + $model = VenueSynonym::findBySynonym($name); + if ($model) { $this->modelsByName[$name] = $model; return $model; } diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index aa0fbcba..e42597c6 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -8,6 +8,9 @@ namespace LVA\Services; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\DB; use LVA\Models\Division; use LVA\Models\Fixture; use LVA\Models\Team; @@ -60,7 +63,16 @@ public function __construct( */ public static function readOneLine(&$handle) { - return explode(',', str_replace(['"', "\n", "\r"], '', fgets($handle))); + $line = []; + foreach (explode(',', str_replace(['"', "\n", "\r"], '', fgets($handle))) as $field) { + if (is_numeric($field)) { + $line[] = (int)$field; + } else { + $line[] = $field; + } + } + + return $line; } /************************************ @@ -72,8 +84,15 @@ public static function readOneLine(&$handle) */ public function createJob($seasonId, UploadedFile $file) { + $job = new UploadJob(); + $job->setSeason($seasonId) + ->setFile($file->getClientOriginalName()) + ->setType(UploadJob::TYPE_FIXTURES) + ->setStatus((new UploadJobStatus())->toArray()) + ->save(); + /** @var UploadedFile $fixtureFile */ - $fixtureFile = $file->move(storage_path() . self::UPLOAD_DIR, $file->getClientOriginalName()); + $fixtureFile = $file->move(storage_path() . self::UPLOAD_DIR, $job->getId() . '.csv'); $handle = fopen($fixtureFile->getRealPath(), 'rb'); $lines = 0; @@ -82,13 +101,8 @@ public function createJob($seasonId, UploadedFile $file) } fclose($handle); - $job = new UploadJob(); - $job->setSeason($seasonId) - ->setFile($fixtureFile->getFilename()) - ->setType(UploadJob::TYPE_FIXTURES) - ->setRowCount($lines - 1)// Don't count the first line as they are the headers - ->setStatus((new UploadJobStatus())->toArray()) - ->save(); + $job->setRowCount($lines - 1)// Don't count the first line as they are the headers + ->save(); return $job; } @@ -101,7 +115,7 @@ public function processJob(UploadJob $job) /** @var UploadJobStatus $status */ $status = UploadJobStatus::loadStatus($job->getStatus()); - if ($status->isNotStarted()) { + if ($status->hasNotStarted()) { $status->moveForward()->setTotalLines($job->getRowCount()); $job->setStatus($status->toArray())->save(); } @@ -110,7 +124,7 @@ public function processJob(UploadJob $job) $processedLines = $status->getProcessedLines(); /** @var resource $csvFile */ - $csvFile = fopen(storage_path() . self::UPLOAD_DIR . $job->getFile(), 'r'); + $csvFile = fopen(storage_path() . self::UPLOAD_DIR . $job->getId() . '.csv', 'r'); // Get the headers $headers = self::readOneLine($csvFile); @@ -119,9 +133,13 @@ public function processJob(UploadJob $job) $this->getIntoPosition($csvFile, $processedLines); // Start processing - $allRowsProcessed = true; + $allLinesProcessed = true; while (!feof($csvFile)) { - $row = array_combine($headers, self::readOneLine($csvFile)); + $line = self::readOneLine($csvFile); + if (empty($line) || count($headers) != count($line)) { + continue; + } + $row = array_combine($headers, $line); $validator = Validator::make($row, [ 'Code' => 'required', @@ -135,8 +153,8 @@ public function processJob(UploadJob $job) ]); if ($validator->fails()) { - $status->setErrors($validator->errors()->all(), $processedLines + 2); - $allRowsProcessed = false; + $status->setValidationErrors($validator->errors()->all(), $processedLines + 2); + $allLinesProcessed = false; break; } @@ -188,7 +206,7 @@ public function processJob(UploadJob $job) $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Home']); $status->setUnknown(UploadJobStatus::UNKNOWN_HOME_TEAM, $mappings); - $allRowsProcessed = false; + $allLinesProcessed = false; $isValid = false; } } @@ -201,7 +219,7 @@ public function processJob(UploadJob $job) $mappings = $this->mappingService->findTeamMappings($division->getId(), $row['Away']); $status->setUnknown(UploadJobStatus::UNKNOWN_AWAY_TEAM, $mappings); - $allRowsProcessed = false; + $allLinesProcessed = false; $isValid = false; } } @@ -214,7 +232,7 @@ public function processJob(UploadJob $job) $mappings = $this->mappingService->findVenueMappings($row['Hall']); $status->setUnknown(UploadJobStatus::UNKNOWN_VENUE, $mappings); - $allRowsProcessed = false; + $allLinesProcessed = false; $isValid = false; } } @@ -246,8 +264,8 @@ public function processJob(UploadJob $job) } fclose($csvFile); - // If we exited the loop because we have processed all line then advance to next stage - if ($allRowsProcessed) { + // If we exited the loop because we have processed all the lines then advance to the next stage + if ($allLinesProcessed) { $status->moveForward()->setTotalRows(UploadJobData::findByJobId($job->getId())->count()); } @@ -256,7 +274,49 @@ public function processJob(UploadJob $job) } if ($status->isInserting()) { - // @todo insert into DB + /** @var Collection $rows */ + $rows = $this->uploadDataService->getUnprocessed($job->getId()); + + // Pass 1: + // Run all the SQL in a transaction so see if they are all valid + $valid = true; + DB::beginTransaction(); + try { + /** @var UploadJobData $row */ + foreach ($rows as $row) { + /** @var Model $model */ + $model = unserialize($row->model_data); + $model->save(); + //$model->save(json_decode($row->model_data, true)); + unset($model); + } + } catch (\Exception $e) { + $valid = false; + } + DB::rollBack(); + + // Pass 2: + // If all SQL is valid run them updating the status and progress + if (!$valid) { + $status->setInsertingError($e->getMessage()); + $job->setStatus($status->toArray())->save(); + } else { + $processedRows = 0; + /** @var UploadJobData $row */ + foreach ($rows as $row) { + /** @var Model $model */ + $model = unserialize($row->model_data); + $model->save(); + unset($model); + + // Update the row counter + $status->setProcessedRows(++$processedRows); + $job->setStatus($status->toArray())->save(); + } + + $status->moveForward(); + $job->setStatus($status->toArray())->save(); + } } if ($status->isDone()) { @@ -272,7 +332,10 @@ public function cleanUp(UploadJob $job) $job->mappedTeams()->delete(); $job->mappedVenues()->delete(); $job->uploadData()->delete(); - $job->delete(); + unlink(storage_path() . self::UPLOAD_DIR . $job->getId() . '.csv'); + if (!UploadJobStatus::loadStatus($job->getStatus())->isDone()) { + $job->delete(); + } } /******************* diff --git a/app/Services/MappingService.php b/app/Services/MappingService.php index 95f55850..e05eaf99 100644 --- a/app/Services/MappingService.php +++ b/app/Services/MappingService.php @@ -22,7 +22,7 @@ class MappingService public function findTeamMappings($divisionId, $team) { $mappings = []; - foreach (Team::all() as $team) { + foreach (Team::orderby('team', 'asc')->get() as $team) { $mappings[] = [ 'value' => $team->id, 'text' => $team->team, @@ -40,7 +40,7 @@ public function findTeamMappings($divisionId, $team) public function findVenueMappings($venue) { $mappings = []; - foreach (Venue::all() as $venue) { + foreach (Venue::orderBy('venue', 'asc')->get() as $venue) { $mappings[] = [ 'value' => $venue->id, 'text' => $venue->venue, diff --git a/app/Services/UploadDataService.php b/app/Services/UploadDataService.php index fae5dd2e..b739d95d 100644 --- a/app/Services/UploadDataService.php +++ b/app/Services/UploadDataService.php @@ -8,6 +8,7 @@ namespace LVA\Services; +use Illuminate\Database\Eloquent\Collection; use LVA\Models\UploadJobData; use Illuminate\Database\Eloquent\Model; @@ -25,7 +26,21 @@ public function add($jobId, $modelClass, Model $model) $jobData ->setJobId($jobId) ->setModel($modelClass) - ->setData($model->toJson()) + ->setData(serialize($model)) ->save(); } + + /** + * @param int $jobId + * @param int $processedRows + * + * @return Collection + */ + public function getUnprocessed($jobId, $processedRows = 0) + { + /** @var Collection $rows */ + $rows = UploadJobData::findByJobId($jobId); + + return $rows->slice($processedRows); + } } \ No newline at end of file diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index f60c1fdb..8b11ee2c 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -6,12 +6,28 @@ var apiToken = $('#api_token').val(), jobId = $('#job_id').val(), + modal = $('#load-fixture-modal'), lastTimestamp = 0, + updateProgressBar = function updateProgressBar(bar, progress) { + bar.removeClass('hidden'); + bar.find('.progress-bar') + .css('width', progress + '%') + .attr('aria-valuenow', progress) + .find('.sr-only').html(progress + '% Complete'); + + if (progress == 100) { + bar.find('.progress-bar') + .removeClass('progress-bar-striped active') + .addClass('progress-bar-success'); + } + }, + disableRow = function disableRow(row) { row.off('click', '.add-button').off('click', '.map-button'); row.find('button').addClass('disabled').blur(); row.find('select').prop('disabled', true); + row.css('opacity', 0.5); if ($('#unknowns').find('button').not('.disabled').length == 0) { $('#continue-button').removeClass('disabled'); @@ -126,7 +142,7 @@ dataType: 'json' }).done(function (data) { if (lastTimestamp == data.Timestamp) { - setTimeout(poll, 1000); + setTimeout(poll, 500); console.log('Same timestamp - nothing to do'); return; } @@ -137,52 +153,71 @@ return; } var status = data.Status; - $('.progress-bar') - .css('width', status.Progress + '%') - .attr('aria-valuenow', status.Progress) - .find('.sr-only').html(status.Progress + '% Complete'); - if (status.StatusCode == 10) { - $('#load-fixture-modal').find('.modal-title').text(status.StatusMessage); + if (status.StatusCode >= 10) { + var validatingProgress = status.StatusCode < 20 ? status.Progress : 100; + updateProgressBar($('#validating-progress'), validatingProgress); + } + if (status.StatusCode >= 20) { + var insertingProgress = status.StatusCode < 30 ? status.Progress : 100; + updateProgressBar($('#inserting-progress'), insertingProgress); + } + + if (status.StatusCode == 11) { + modal.find('.modal-title').text(status.StatusMessage); - populateCurrentFixture($('#load-fixture-modal'), status.Fixture); + populateCurrentFixture(modal, status.Fixture); - $('#load-fixture-modal').find('#unknowns').empty(); + modal.find('#unknowns').empty(); $.each(status.Unknowns, function (field, map) { var newUnknown = createUnknownRow('unknown-data-template', status.Fixture[field], map); $('#load-fixture-modal').find('#unknowns').append(newUnknown); }); $('#continue-button').addClass('disabled').blur(); - $('#load-fixture-modal').modal('show'); + modal.modal('show'); - } else if (status.StatusCode == 20) { + } else if (status.StatusCode == 19 || status.StatusCode == 29) { var alert = $('#unrecoverable-errors'); - alert.find('#error-line-number').text(status.ErrorLine); + if (status.ErrorLine) { + var errorLine = alert.find('#error-line-number'); + + errorLine.find('span').text(status.ErrorLine); + errorLine.removeClass('hidden'); + } $.each(status.Errors, function (key, error) { alert.find('ul').append($('
  • ' + error + '
  • ')) }); alert.removeClass('hidden'); - $('.progress-bar').removeClass('progress-bar-striped active'); + if (status.StatusCode == 19) { + $('#validating-progress .progress-bar').removeClass('progress-bar-striped active').addClass('progress-bar-danger'); + } else if (status.StatusCode == 29) { + $('#inserting-progress .progress-bar').removeClass('progress-bar-striped active').addClass('progress-bar-danger'); + } } else if (status.StatusCode != 99) { - setTimeout(poll, 1000); + setTimeout(poll, 500); } }); + }, + + restart = function restart() { + // Restart the uploading + $.get({ + url : '/api/v1/uploads/resume', + data : { + job : jobId, + api_token: apiToken + }, + async: true + }); }; + restart(); poll(); - $('#load-fixture-modal').modal({show: false}); - $('#load-fixture-modal').on('hidden.bs.modal', function () { - setTimeout(poll, 1000); - // Restart the uploading - $.get({ - url : '/api/v1/uploads/resume', - data : { - job : jobId, - api_token: apiToken - }, - async: true - }); + modal.modal({show: false}); + modal.on('hidden.bs.modal', function () { + setTimeout(poll, 500); + restart(); }); })(jQuery); \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/index.blade.php b/resources/views/admin/data-management/fixtures/index.blade.php index c076ae09..6c6b86ff 100644 --- a/resources/views/admin/data-management/fixtures/index.blade.php +++ b/resources/views/admin/data-management/fixtures/index.blade.php @@ -11,8 +11,8 @@ class="btn btn-primary pull-right btn-sm">New fixture

    Date - Warm-up time - Start time + Warm-up + Start Home Away Venue diff --git a/resources/views/admin/data-management/load/status.blade.php b/resources/views/admin/data-management/load/status.blade.php index 5b03bc40..961aad55 100644 --- a/resources/views/admin/data-management/load/status.blade.php +++ b/resources/views/admin/data-management/load/status.blade.php @@ -11,10 +11,22 @@

    Processing {{$job->file}}

    -
    -
    - 0% Complete + +
    @@ -23,7 +35,7 @@
    From 43cc78e38807739c41afd33dc56b9b8a5697ed44 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Mon, 13 Mar 2017 11:02:44 +0000 Subject: [PATCH 47/62] lva-22: changed the index on synonym for teams and venues to be unique --- ..._index_on_synonyms_tables_to_be_unique.sql | 8 ++++ ..._index_on_synonyms_tables_to_be_unique.sql | 8 ++++ ..._index_on_synonyms_tables_to_be_unique.php | 43 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 database/deployment/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql create mode 100644 database/deployment/rollbacks/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql create mode 100644 database/migrations/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.php diff --git a/database/deployment/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql b/database/deployment/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql new file mode 100644 index 00000000..64e2df09 --- /dev/null +++ b/database/deployment/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql @@ -0,0 +1,8 @@ +ALTER TABLE `teams_synonyms` + DROP INDEX `teams_synonyms_synonym_index`; +ALTER TABLE `teams_synonyms` + ADD UNIQUE `teams_synonyms_synonym_unique`(`synonym`); +ALTER TABLE `venues_synonyms` + DROP INDEX `venues_synonyms_synonym_index`; +ALTER TABLE `venues_synonyms` + ADD UNIQUE `venues_synonyms_synonym_unique`(`synonym`); diff --git a/database/deployment/rollbacks/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql b/database/deployment/rollbacks/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql new file mode 100644 index 00000000..0fde1379 --- /dev/null +++ b/database/deployment/rollbacks/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.sql @@ -0,0 +1,8 @@ +ALTER TABLE `teams_synonyms` + DROP INDEX `teams_synonyms_synonym_unique`; +ALTER TABLE `teams_synonyms` + ADD INDEX `teams_synonyms_synonym_index`(`synonym`); +ALTER TABLE `venues_synonyms` + DROP INDEX `venues_synonyms_synonym_unique`; +ALTER TABLE `venues_synonyms` + ADD INDEX `venues_synonyms_synonym_index`(`synonym`); \ No newline at end of file diff --git a/database/migrations/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.php b/database/migrations/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.php new file mode 100644 index 00000000..df70cbd1 --- /dev/null +++ b/database/migrations/2017_03_13_105646_change_index_on_synonyms_tables_to_be_unique.php @@ -0,0 +1,43 @@ +dropIndex(['synonym']); + $table->unique(['synonym']); + }); + + Schema::table('venues_synonyms', function (Blueprint $table) { + $table->dropIndex(['synonym']); + $table->unique(['synonym']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('teams_synonyms', function (Blueprint $table) { + $table->dropUnique(['synonym']); + $table->index(['synonym']); + }); + + Schema::table('venues_synonyms', function (Blueprint $table) { + $table->dropUnique(['synonym']); + $table->index(['synonym']); + }); + } +} From 1274016238a0214c49bfb8c8170888a17caa8796 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 13 Mar 2017 19:10:54 +0000 Subject: [PATCH 48/62] dev: added the Factory Muffins package to create test dummies for the UploadJobStatus model (since it's not an Eloquent model) --- composer.json | 4 +- composer.lock | 119 +++++++++++++++++- database/muffins/UploadJobStatus.php | 13 ++ .../Models/UploadJobStatusTest.php | 30 +++++ 4 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 database/muffins/UploadJobStatus.php diff --git a/composer.json b/composer.json index 71558113..8a0afd34 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,9 @@ "symfony/dom-crawler": "2.8.*|3.0.*", "barryvdh/laravel-ide-helper": "^2.1", "appzcoder/crud-generator": "^1.0", - "doctrine/dbal": "~2.3" + "doctrine/dbal": "~2.3", + "league/factory-muffin": "^3.0", + "league/factory-muffin-faker": "^2.0" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index db275bf3..a8659465 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e2e2866df0ed28d53bc785d61c0e743c", - "content-hash": "1e1a72b5a999e3b23204b8f7039882e0", + "hash": "135aedc26a6639013172dee065b54b31", + "content-hash": "c7193ae7c2e6e433692a3f334dffa7d8", "packages": [ { "name": "classpreloader/classpreloader", @@ -2652,6 +2652,121 @@ ], "time": "2015-05-11 14:41:42" }, + { + "name": "league/factory-muffin", + "version": "v3.0.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/factory-muffin.git", + "reference": "316ed2bac70178567f995d877b831804c9c58d5a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/factory-muffin/zipball/316ed2bac70178567f995d877b831804c9c58d5a", + "reference": "316ed2bac70178567f995d877b831804c9c58d5a", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "replace": { + "zizaco/factory-muff": "self.version" + }, + "require-dev": { + "doctrine/orm": "2.5.*", + "illuminate/database": "5.0.*|5.1.*", + "league/factory-muffin-faker": "^2.0", + "phpunit/phpunit": "^4.8|^5.0" + }, + "suggest": { + "doctrine/orm": "Factory Muffin supports doctrine through the repository store.", + "illuminate/database": "Factory Muffin supports eloquent through the model store.", + "league/factory-muffin-faker": "Factory Muffin is very powerful together with faker." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\FactoryMuffin\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Scott Robertson", + "email": "scottymeuk@gmail.com" + }, + { + "name": "Graham Campbell", + "email": "graham@alt-three.com" + } + ], + "description": "The goal of this package is to enable the rapid creation of objects for the purpose of testing.", + "homepage": "http://factory-muffin.thephpleague.com/", + "keywords": [ + "factory", + "testing" + ], + "time": "2016-05-13 10:56:41" + }, + { + "name": "league/factory-muffin-faker", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/factory-muffin-faker.git", + "reference": "61e0e40356edee0502f379cc85ca74e4234c687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/factory-muffin-faker/zipball/61e0e40356edee0502f379cc85ca74e4234c687c", + "reference": "61e0e40356edee0502f379cc85ca74e4234c687c", + "shasum": "" + }, + "require": { + "fzaninotto/faker": "1.6.*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8|^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\FactoryMuffin\\Faker\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@alt-three.com" + } + ], + "description": "The goal of this package is to wrap faker to make it super easy to use with factory muffin.", + "homepage": "http://factory-muffin.thephpleague.com/", + "keywords": [ + "factory", + "faker", + "testing" + ], + "time": "2016-05-13 10:47:29" + }, { "name": "mockery/mockery", "version": "0.9.9", diff --git a/database/muffins/UploadJobStatus.php b/database/muffins/UploadJobStatus.php new file mode 100644 index 00000000..34b03a4b --- /dev/null +++ b/database/muffins/UploadJobStatus.php @@ -0,0 +1,13 @@ + + * Date: 13/03/2017 + * Time: 19:01 + */ + +use League\FactoryMuffin\Faker\Faker; + +$fm->define(\LVA\Models\UploadJobStatus::class)->setDefinitions([ + 'status_code' => \LVA\Models\UploadJobStatus::STATUS_NOT_STARTED, +]); \ No newline at end of file diff --git a/tests/integration/Models/UploadJobStatusTest.php b/tests/integration/Models/UploadJobStatusTest.php index 4a72d9ca..6ffe1160 100644 --- a/tests/integration/Models/UploadJobStatusTest.php +++ b/tests/integration/Models/UploadJobStatusTest.php @@ -4,11 +4,41 @@ namespace Tests\Models; +use League\FactoryMuffin\FactoryMuffin; +use League\FactoryMuffin\Faker\Faker; use Tests\TestCase; use LVA\Models\UploadJobStatus; class UploadJobStatusTest extends TestCase { + /** @var FactoryMuffin */ + protected static $fm; + + /** + * @inheritDoc + */ + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + // create a new factory muffin instance + static::$fm = new FactoryMuffin(); + + // load your model definitions + static::$fm->loadFactories(database_path() . '/muffins'); + } + + /** + * @inheritDoc + */ + public static function tearDownAfterClass() + { + static::$fm->deleteSaved(); + + parent::tearDownAfterClass(); + } + + /** * @test */ From 39fdcedb02691c3c11773d750660cbf4e3c87439 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Wed, 15 Mar 2017 17:12:59 +0000 Subject: [PATCH 49/62] lva-22: separated unit and integration tests, added integration tests, fixed the code, removed Muffins package and some refactoring --- .../Api/v1/UploadApiController.php | 10 +- app/Models/MappedTeam.php | 2 +- app/Models/MappedVenue.php | 2 +- app/Models/Team.php | 8 + app/Models/TeamSynonym.php | 15 +- app/Models/UploadJob.php | 2 +- app/Models/UploadJobData.php | 8 +- app/Models/UploadJobStatus.php | 97 +- app/Models/Venue.php | 2 +- app/Models/VenueSynonym.php | 15 +- .../InteractiveFixturesUploadService.php | 27 +- app/Services/UploadDataService.php | 3 +- composer.json | 7 +- composer.lock | 262 ++--- database/factories/ModelFactory.php | 54 +- database/factories/TeamFactories.php | 31 + database/factories/UploadFactories.php | 55 + database/factories/VenueFactories.php | 37 + database/muffins/UploadJobStatus.php | 13 - tests/integration/IntegrationTestCase.php | 66 ++ .../Models/AvailableAppointmentTest.php | 4 +- tests/integration/Models/ClubTest.php | 4 +- tests/integration/Models/DivisionTest.php | 7 +- tests/integration/Models/FixtureTest.php | 16 +- tests/integration/Models/MappedTeamTest.php | 117 ++- tests/integration/Models/MappedVenueTest.php | 117 ++- tests/integration/Models/RoleTest.php | 4 +- tests/integration/Models/SeasonTest.php | 4 +- tests/integration/Models/TeamSynonymTest.php | 86 +- tests/integration/Models/TeamTest.php | 41 +- .../integration/Models/UploadJobDataTest.php | 128 ++- .../Models/UploadJobStatusTest.php | 957 +++++++++++++++++- tests/integration/Models/UploadJobTest.php | 92 +- tests/integration/Models/VenueSynonymTest.php | 85 +- tests/integration/Models/VenueTest.php | 62 +- .../InteractiveFixturesUploadServiceTest.php | 18 +- ...p => AvailableAppointmentResourceTest.php} | 2 +- ...lubsTableTest.php => ClubResourceTest.php} | 2 +- ...TableTest.php => DivisionResourceTest.php} | 2 +- ...sTableTest.php => FixtureResourceTest.php} | 2 +- ...olesTableTest.php => RoleResourceTest.php} | 2 +- ...nsTableTest.php => SeasonResourceTest.php} | 2 +- ...eamsTableTest.php => TeamResourceTest.php} | 2 +- ...uesTableTest.php => VenueResourceTest.php} | 2 +- tests/unit/Api/v1/UploadApiTest.php | 58 ++ 45 files changed, 2055 insertions(+), 477 deletions(-) create mode 100644 database/factories/TeamFactories.php create mode 100644 database/factories/UploadFactories.php create mode 100644 database/factories/VenueFactories.php delete mode 100644 database/muffins/UploadJobStatus.php create mode 100644 tests/integration/IntegrationTestCase.php rename tests/unit/Admin/DataManagement/{AvailableAppointmentsTableTest.php => AvailableAppointmentResourceTest.php} (99%) rename tests/unit/Admin/DataManagement/{ClubsTableTest.php => ClubResourceTest.php} (99%) rename tests/unit/Admin/DataManagement/{DivisionsTableTest.php => DivisionResourceTest.php} (99%) rename tests/unit/Admin/DataManagement/{FixturesTableTest.php => FixtureResourceTest.php} (99%) rename tests/unit/Admin/DataManagement/{RolesTableTest.php => RoleResourceTest.php} (99%) rename tests/unit/Admin/DataManagement/{SeasonsTableTest.php => SeasonResourceTest.php} (99%) rename tests/unit/Admin/DataManagement/{TeamsTableTest.php => TeamResourceTest.php} (99%) rename tests/unit/Admin/DataManagement/{VenuesTableTest.php => VenueResourceTest.php} (99%) create mode 100644 tests/unit/Api/v1/UploadApiTest.php diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 3e62630b..6253f588 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -47,7 +47,7 @@ public function resumeUpload() } /** @var UploadJobStatus $status */ - $status = UploadJobStatus::loadStatus($uploadJob->getStatus()); + $status = UploadJobStatus::factory($uploadJob->getStatus()); if ($status->canResume()) { $status->resume(); @@ -66,13 +66,13 @@ public function getUploadStatus() } /** @var UploadJobStatus $status */ - $status = UploadJobStatus::loadStatus($uploadJob->getStatus()); + $status = UploadJobStatus::factory($uploadJob->getStatus()); return response()->json([ 'Timestamp' => time(), 'Error' => false, 'Message' => 'Job found', - 'Status' => $status->toApiJson(), + 'Status' => $status->toApiArray(), ]); } @@ -88,7 +88,7 @@ public function mapTeam(MapTeamRequest $request) $synonym = new TeamSynonym(); $synonym ->setSynonym($mappedTeam->getName()) - ->setTeamId($mappedTeam->team->getId()); + ->setTeam($request->input('newName')); $this->uploadDataService->add($request->input('job'), TeamSynonym::class, $synonym); @@ -122,7 +122,7 @@ public function mapVenue(MapVenueRequest $request) $synonym = new VenueSynonym(); $synonym ->setSynonym($mappedVenue->getName()) - ->setTeamId($mappedVenue->venue->getId()); + ->setVenue($request->input('newName')); $this->uploadDataService->add($request->input('job'), VenueSynonym::class, $synonym); diff --git a/app/Models/MappedTeam.php b/app/Models/MappedTeam.php index 4bfe5852..de4a118b 100644 --- a/app/Models/MappedTeam.php +++ b/app/Models/MappedTeam.php @@ -105,7 +105,7 @@ public function setName($team) */ public function setMappedTeam($team) { - $this->team_id = Team::findByName($team)->getId(); + $this->team()->associate(Team::findByName($team)); return $this; } diff --git a/app/Models/MappedVenue.php b/app/Models/MappedVenue.php index 1a7e8e91..525bef19 100644 --- a/app/Models/MappedVenue.php +++ b/app/Models/MappedVenue.php @@ -105,7 +105,7 @@ public function setName($venue) */ public function setMappedVenue($venue) { - $this->venue_id = Venue::findByName($venue)->getId(); + $this->venue()->associate(Venue::findByName($venue)); return $this; } diff --git a/app/Models/Team.php b/app/Models/Team.php index d763c2ac..fc396c7c 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -83,6 +83,14 @@ public function getId() return $this->id; } + /** + * @return string + */ + public function getName() + { + return $this->team; + } + /** * @return string */ diff --git a/app/Models/TeamSynonym.php b/app/Models/TeamSynonym.php index c4feb86b..953b96a4 100644 --- a/app/Models/TeamSynonym.php +++ b/app/Models/TeamSynonym.php @@ -38,6 +38,7 @@ class TeamSynonym extends Model */ public static function findBySynonym($synonym) { + /** @var TeamSynonym $synonym */ $synonym = self::where('synonym', $synonym)->first(); if ($synonym) { return $synonym->team; @@ -62,6 +63,14 @@ public function getId() return $this->id; } + /** + * @return string + */ + public function getSynonym() + { + return $this->synonym; + } + /** * @param string $synonym * @@ -75,13 +84,13 @@ public function setSynonym($synonym) } /** - * @param int $teamId + * @param string $team * * @return TeamSynonym */ - public function setTeamId($teamId) + public function setTeam($team) { - $this->team_id = $teamId; + $this->team()->associate(Team::findByName($team)); return $this; } diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index a15b2190..6ce1ae46 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -57,7 +57,7 @@ public function uploadData() */ public function scopeStale(Builder $query) { - return $query->where('updated_at', '<', Carbon::now()->subWeek()); + return $query->where('updated_at', '<=', Carbon::now()->subWeek()); } /** diff --git a/app/Models/UploadJobData.php b/app/Models/UploadJobData.php index ecbcbe61..c49252ab 100644 --- a/app/Models/UploadJobData.php +++ b/app/Models/UploadJobData.php @@ -43,11 +43,11 @@ public static function findByJobId($jobId) } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function uploadJob() { - return $this->hasOne(UploadJob::class); + return $this->belongsTo(UploadJob::class); } /** @@ -63,9 +63,9 @@ public function getId() * * @return UploadJobData */ - public function setJobId($jobId) + public function setJob($jobId) { - $this->upload_job_id = $jobId; + $this->uploadJob()->associate(UploadJob::find($jobId)); return $this; } diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 536e74c0..756b98c6 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -24,28 +24,28 @@ class UploadJobStatus { const STATUS_NOT_STARTED = 0; const STATUS_VALIDATING_RECORDS = 10; + const STATUS_UNKNOWN_DATA = 11; const STATUS_UNRECOVERABLE_VALIDATION_ERROR = 19; const STATUS_INSERTING_RECORDS = 20; const STATUS_UNRECOVERABLE_INSERT_ERROR = 29; - const STATUS_UNKNOWN_DATA = 11; const STATUS_DONE = 99; const UNKNOWN_HOME_TEAM = 1; const UNKNOWN_AWAY_TEAM = 2; const UNKNOWN_VENUE = 3; - private $status_code; - private $total_lines; - private $processed_lines; - private $total_rows; - private $processed_rows; - private $processing_line; - private $unknowns; - private $errors; - private $error_line; + public $status_code; + public $total_lines; + public $processed_lines; + public $total_rows; + public $processed_rows; + public $processing_line; + public $unknowns; + public $errors; + public $error_line; /** - * @inheritDoc + * UploadJobStatus constructor. */ public function __construct() { @@ -55,12 +55,17 @@ public function __construct() $this->total_rows = 0; $this->processed_rows = 0; $this->processing_line = []; - $this->unknowns = null; + $this->unknowns = []; $this->errors = []; $this->error_line = null; } - public static function loadStatus($statusArray) + /** + * @param array $statusArray + * + * @return UploadJobStatus + */ + public static function factory($statusArray) { $status = new static(); $status->load($statusArray); @@ -101,30 +106,14 @@ public function load(array $data) { $this->status_code = $data['status_code']; - if (array_has($data, 'total_lines')) { - $this->total_lines = $data['total_lines']; - } - if (array_has($data, 'processed_lines')) { - $this->processed_lines = $data['processed_lines']; - } - if (array_has($data, 'total_rows')) { - $this->total_rows = $data['total_rows']; - } - if (array_has($data, 'processed_rows')) { - $this->processed_rows = $data['processed_rows']; - } - if (array_has($data, 'processing_line')) { - $this->processing_line = $data['processing_line']; - } - if (array_has($data, 'unknowns')) { - $this->unknowns = $data['unknowns']; - } - if (array_has($data, 'errors')) { - $this->errors = $data['errors']; - } - if (array_has($data, 'error_line')) { - $this->error_line = $data['error_line']; - } + $this->total_lines = array_has($data, 'total_lines') ? $data['total_lines'] : 0; + $this->processed_lines = array_has($data, 'processed_lines') ? $data['processed_lines'] : 0; + $this->total_rows = array_has($data, 'total_rows') ? $data['total_rows'] : 0; + $this->processed_rows = array_has($data, 'processed_rows') ? $data['processed_rows'] : 0; + $this->processing_line = array_has($data, 'processing_line') ? $data['processing_line'] : []; + $this->unknowns = array_has($data, 'unknowns') ? $data['unknowns'] : []; + $this->errors = array_has($data, 'errors') ? $data['errors'] : []; + $this->error_line = array_has($data, 'error_line') ? $data['error_line'] : null; return $this; } @@ -150,14 +139,14 @@ public function toArray() /** * @return array */ - public function toApiJson() + public function toApiArray() { $formattedStatus = [ 'StatusCode' => $this->getStatusCode(), 'StatusMessage' => $this->getStatusCodeMessage(), ]; - if ($this->hasStarted()) { + if ($this->hasStarted() && !$this->isDone()) { if ($this->isInserting()) { $formattedStatus['Progress'] = floor($this->getProcessedRows() * 100 / $this->getTotalRows()); } else { @@ -267,7 +256,7 @@ public function hasUnknownData() */ public function canResume() { - return !$this->isWorking() && !$this->isDone(); + return $this->hasNotStarted() || $this->hasUnknownData(); } /** @@ -277,6 +266,7 @@ public function isWorking() { return $this->isValidating() || $this->isInserting(); } + /** * @return array */ @@ -304,7 +294,8 @@ public function setUnknown($unknownType, $mappings) */ public function hasErrors() { - return in_array($this->getStatusCode(), [self::STATUS_UNRECOVERABLE_VALIDATION_ERROR, self::STATUS_UNRECOVERABLE_INSERT_ERROR]); + return in_array($this->getStatusCode(), + [self::STATUS_UNRECOVERABLE_VALIDATION_ERROR, self::STATUS_UNRECOVERABLE_INSERT_ERROR]); } /** @@ -437,8 +428,7 @@ public function setProcessedRows($processed_rows) */ public function getProcessingLineDivision() { - return $this->processing_line['division']; - + return isset($this->processing_line['division']) ? $this->processing_line['division'] : ''; } /** @@ -458,8 +448,7 @@ public function setProcessingLineDivision($division) */ public function getProcessingLineMatchNumber() { - return $this->processing_line['match_number']; - + return isset($this->processing_line['match_number']) ? $this->processing_line['match_number'] : ''; } /** @@ -479,8 +468,7 @@ public function setProcessingLineMatchNumber($matchNumber) */ public function getProcessingLineHomeTeam() { - return $this->processing_line['home_team']; - + return isset($this->processing_line['home_team']) ? $this->processing_line['home_team'] : ''; } /** @@ -500,8 +488,7 @@ public function setProcessingLineHomeTeam($team) */ public function getProcessingLineAwayTeam() { - return $this->processing_line['away_team']; - + return isset($this->processing_line['away_team']) ? $this->processing_line['away_team'] : ''; } /** @@ -521,8 +508,7 @@ public function setProcessingLineAwayTeam($team) */ public function getProcessingLineDate() { - return $this->processing_line['date']; - + return isset($this->processing_line['date']) ? $this->processing_line['date'] : ''; } /** @@ -542,8 +528,7 @@ public function setProcessingLineDate($date) */ public function getProcessingLineWarmUpTime() { - return $this->processing_line['warm_up_time']; - + return isset($this->processing_line['warm_up_time']) ? $this->processing_line['warm_up_time'] : ''; } /** @@ -563,8 +548,7 @@ public function setProcessingLineWarmUpTime($time) */ public function getProcessingLineStartTime() { - return $this->processing_line['start_time']; - + return isset($this->processing_line['start_time']) ? $this->processing_line['start_time'] : ''; } /** @@ -584,8 +568,7 @@ public function setProcessingLineStartTime($time) */ public function getProcessingLineVenue() { - return $this->processing_line['venue']; - + return isset($this->processing_line['venue']) ? $this->processing_line['venue'] : ''; } /** diff --git a/app/Models/Venue.php b/app/Models/Venue.php index 3bad6ca3..fa43e4aa 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -72,7 +72,7 @@ public function getId() */ public function getName() { - return $this->venue(); + return $this->venue; } /** diff --git a/app/Models/VenueSynonym.php b/app/Models/VenueSynonym.php index 1a21baee..ae1f4f86 100644 --- a/app/Models/VenueSynonym.php +++ b/app/Models/VenueSynonym.php @@ -32,6 +32,7 @@ class VenueSynonym extends Model */ public static function findBySynonym($synonym) { + /** @var VenueSynonym $synonym */ $synonym = self::where('synonym', $synonym)->first(); if ($synonym) { return $synonym->venue; @@ -56,6 +57,14 @@ public function getId() return $this->id; } + /** + * @return string + */ + public function getSynonym() + { + return $this->synonym; + } + /** * @param string $synonym * @@ -69,13 +78,13 @@ public function setSynonym($synonym) } /** - * @param int $venueId + * @param string $venue * * @return VenueSynonym */ - public function setTeamId($venueId) + public function setVenue($venue) { - $this->venue_id = $venueId; + $this->venue()->associate(Venue::findByName($venue)); return $this; } diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index e42597c6..36b7413c 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -113,7 +113,7 @@ public function createJob($seasonId, UploadedFile $file) public function processJob(UploadJob $job) { /** @var UploadJobStatus $status */ - $status = UploadJobStatus::loadStatus($job->getStatus()); + $status = UploadJobStatus::factory($job->getStatus()); if ($status->hasNotStarted()) { $status->moveForward()->setTotalLines($job->getRowCount()); @@ -333,7 +333,7 @@ public function cleanUp(UploadJob $job) $job->mappedVenues()->delete(); $job->uploadData()->delete(); unlink(storage_path() . self::UPLOAD_DIR . $job->getId() . '.csv'); - if (!UploadJobStatus::loadStatus($job->getStatus())->isDone()) { + if (!UploadJobStatus::factory($job->getStatus())->isDone()) { $job->delete(); } } @@ -354,27 +354,4 @@ private function getIntoPosition(&$file, $numberOfLines) $counter++; } } - - /** - * @param UploadJob $job - * @param array $data - */ - private function insertFixture($job, $data) - { - /** @var Fixture $fixture */ - $fixture = new Fixture(); - $fixture - ->setDivision(Division::findByName($job->getSeason(), $data['Code'])->getId()) - ->setMatchNumber($data['Match']) - ->setMatchDate(Carbon::createFromFormat('d/m/Y', $data['Date'])) - ->setWarmUpTime(Carbon::createFromFormat('H:i:s', $data['WUTime'])) - ->setStartTime(Carbon::createFromFormat('H:i:s', $data['StartTime'])) - ->setHomeTeam(Team::findByName($data['Home'])->getId()) - ->setAwayTeam(Team::findByName($data['Away'])->getId()) - ->setVenue(Venue::findByName($data['Hall'])->getId()); - - $this->uploadDataService->add($job->getId(), Fixture::class, $fixture); - - unset($fixture); - } } \ No newline at end of file diff --git a/app/Services/UploadDataService.php b/app/Services/UploadDataService.php index b739d95d..4cae723b 100644 --- a/app/Services/UploadDataService.php +++ b/app/Services/UploadDataService.php @@ -9,6 +9,7 @@ namespace LVA\Services; use Illuminate\Database\Eloquent\Collection; +use LVA\Models\UploadJob; use LVA\Models\UploadJobData; use Illuminate\Database\Eloquent\Model; @@ -24,7 +25,7 @@ public function add($jobId, $modelClass, Model $model) $jobData = new UploadJobData(); $jobData - ->setJobId($jobId) + ->setJob($jobId) ->setModel($modelClass) ->setData(serialize($model)) ->save(); diff --git a/composer.json b/composer.json index 8a0afd34..399cf6ae 100644 --- a/composer.json +++ b/composer.json @@ -33,9 +33,7 @@ "symfony/dom-crawler": "2.8.*|3.0.*", "barryvdh/laravel-ide-helper": "^2.1", "appzcoder/crud-generator": "^1.0", - "doctrine/dbal": "~2.3", - "league/factory-muffin": "^3.0", - "league/factory-muffin-faker": "^2.0" + "doctrine/dbal": "~2.3" }, "autoload": { "classmap": [ @@ -47,7 +45,8 @@ }, "autoload-dev": { "classmap": [ - "tests/TestCase.php" + "tests/TestCase.php", + "tests/integration/IntegrationTestCase.php" ] }, "scripts": { diff --git a/composer.lock b/composer.lock index a8659465..788e4163 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "135aedc26a6639013172dee065b54b31", - "content-hash": "c7193ae7c2e6e433692a3f334dffa7d8", + "content-hash": "1e1a72b5a999e3b23204b8f7039882e0", "packages": [ { "name": "classpreloader/classpreloader", @@ -59,7 +58,7 @@ "class", "preload" ], - "time": "2016-09-16 12:50:15" + "time": "2016-09-16T12:50:15+00:00" }, { "name": "davejamesmiller/laravel-breadcrumbs", @@ -108,7 +107,7 @@ "keywords": [ "laravel" ], - "time": "2017-01-30 21:16:53" + "time": "2017-01-30T21:16:53+00:00" }, { "name": "dnoegel/php-xdg-base-dir", @@ -141,7 +140,7 @@ "MIT" ], "description": "implementation of xdg base directory specification for php", - "time": "2014-10-24 07:27:01" + "time": "2014-10-24T07:27:01+00:00" }, { "name": "doctrine/inflector", @@ -208,7 +207,7 @@ "singularize", "string" ], - "time": "2015-11-06 14:35:42" + "time": "2015-11-06T14:35:42+00:00" }, { "name": "jakub-onderka/php-console-color", @@ -251,7 +250,7 @@ "homepage": "http://www.acci.cz" } ], - "time": "2014-04-08 15:00:19" + "time": "2014-04-08T15:00:19+00:00" }, { "name": "jakub-onderka/php-console-highlighter", @@ -295,7 +294,7 @@ "homepage": "http://www.acci.cz/" } ], - "time": "2015-04-20 18:58:01" + "time": "2015-04-20T18:58:01+00:00" }, { "name": "jeremeamia/SuperClosure", @@ -353,7 +352,7 @@ "serialize", "tokenizer" ], - "time": "2016-12-07 09:37:55" + "time": "2016-12-07T09:37:55+00:00" }, { "name": "laracasts/flash", @@ -396,7 +395,7 @@ } ], "description": "Easy flash notifications", - "time": "2016-07-11 20:46:02" + "time": "2016-07-11T20:46:02+00:00" }, { "name": "laravel/framework", @@ -526,7 +525,7 @@ "framework", "laravel" ], - "time": "2016-08-26 11:44:52" + "time": "2016-08-26T11:44:52+00:00" }, { "name": "laravelcollective/html", @@ -580,7 +579,7 @@ ], "description": "HTML and Form Builders for the Laravel Framework", "homepage": "http://laravelcollective.com", - "time": "2016-12-13 14:28:46" + "time": "2016-12-13T14:28:46+00:00" }, { "name": "league/flysystem", @@ -663,7 +662,7 @@ "sftp", "storage" ], - "time": "2017-02-09 11:33:58" + "time": "2017-02-09T11:33:58+00:00" }, { "name": "monolog/monolog", @@ -741,7 +740,7 @@ "logging", "psr-3" ], - "time": "2016-11-26 00:15:39" + "time": "2016-11-26T00:15:39+00:00" }, { "name": "mtdowling/cron-expression", @@ -785,7 +784,7 @@ "cron", "schedule" ], - "time": "2017-01-23 04:29:33" + "time": "2017-01-23T04:29:33+00:00" }, { "name": "nesbot/carbon", @@ -838,7 +837,7 @@ "datetime", "time" ], - "time": "2017-01-16 07:55:07" + "time": "2017-01-16T07:55:07+00:00" }, { "name": "nikic/php-parser", @@ -889,7 +888,7 @@ "parser", "php" ], - "time": "2016-09-16 12:04:44" + "time": "2016-09-16T12:04:44+00:00" }, { "name": "paragonie/random_compat", @@ -937,7 +936,7 @@ "pseudorandom", "random" ], - "time": "2016-03-18 20:34:03" + "time": "2016-03-18T20:34:03+00:00" }, { "name": "psr/log", @@ -984,7 +983,7 @@ "psr", "psr-3" ], - "time": "2016-10-10 12:19:37" + "time": "2016-10-10T12:19:37+00:00" }, { "name": "psy/psysh", @@ -1056,7 +1055,7 @@ "interactive", "shell" ], - "time": "2016-03-09 05:03:14" + "time": "2016-03-09T05:03:14+00:00" }, { "name": "swiftmailer/swiftmailer", @@ -1110,7 +1109,7 @@ "mail", "mailer" ], - "time": "2017-02-13 07:52:53" + "time": "2017-02-13T07:52:53+00:00" }, { "name": "symfony/console", @@ -1170,7 +1169,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/debug", @@ -1227,7 +1226,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/event-dispatcher", @@ -1287,7 +1286,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-01-02 20:32:22" + "time": "2017-01-02T20:32:22+00:00" }, { "name": "symfony/finder", @@ -1336,7 +1335,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" + "time": "2016-06-29T05:40:00+00:00" }, { "name": "symfony/http-foundation", @@ -1389,7 +1388,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-07-17 13:54:30" + "time": "2016-07-17T13:54:30+00:00" }, { "name": "symfony/http-kernel", @@ -1471,7 +1470,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2016-07-30 09:10:37" + "time": "2016-07-30T09:10:37+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -1530,7 +1529,7 @@ "portable", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/polyfill-php56", @@ -1586,7 +1585,7 @@ "portable", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/polyfill-util", @@ -1638,7 +1637,7 @@ "polyfill", "shim" ], - "time": "2016-11-14 01:06:16" + "time": "2016-11-14T01:06:16+00:00" }, { "name": "symfony/process", @@ -1687,7 +1686,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-07-28 11:13:34" + "time": "2016-07-28T11:13:34+00:00" }, { "name": "symfony/routing", @@ -1762,7 +1761,7 @@ "uri", "url" ], - "time": "2016-06-29 05:40:00" + "time": "2016-06-29T05:40:00+00:00" }, { "name": "symfony/translation", @@ -1826,7 +1825,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/var-dumper", @@ -1889,7 +1888,7 @@ "debug", "dump" ], - "time": "2016-07-26 08:03:56" + "time": "2016-07-26T08:03:56+00:00" }, { "name": "vlucas/phpdotenv", @@ -1939,7 +1938,7 @@ "env", "environment" ], - "time": "2016-09-01 10:05:43" + "time": "2016-09-01T10:05:43+00:00" } ], "packages-dev": [ @@ -1985,7 +1984,7 @@ "laravel", "laravel crud generator" ], - "time": "2016-09-28 18:05:53" + "time": "2016-09-28T18:05:53+00:00" }, { "name": "barryvdh/laravel-ide-helper", @@ -2051,7 +2050,7 @@ "phpstorm", "sublime" ], - "time": "2017-02-22 12:27:33" + "time": "2017-02-22T12:27:33+00:00" }, { "name": "barryvdh/reflection-docblock", @@ -2100,7 +2099,7 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2016-06-13 19:28:20" + "time": "2016-06-13T19:28:20+00:00" }, { "name": "doctrine/annotations", @@ -2168,7 +2167,7 @@ "docblock", "parser" ], - "time": "2017-02-24 16:22:25" + "time": "2017-02-24T16:22:25+00:00" }, { "name": "doctrine/cache", @@ -2238,7 +2237,7 @@ "cache", "caching" ], - "time": "2016-10-29 11:16:17" + "time": "2016-10-29T11:16:17+00:00" }, { "name": "doctrine/collections", @@ -2305,7 +2304,7 @@ "collections", "iterator" ], - "time": "2017-01-03 10:49:41" + "time": "2017-01-03T10:49:41+00:00" }, { "name": "doctrine/common", @@ -2378,7 +2377,7 @@ "persistence", "spl" ], - "time": "2017-01-13 14:02:13" + "time": "2017-01-13T14:02:13+00:00" }, { "name": "doctrine/dbal", @@ -2449,7 +2448,7 @@ "persistence", "queryobject" ], - "time": "2017-02-08 12:53:47" + "time": "2017-02-08T12:53:47+00:00" }, { "name": "doctrine/instantiator", @@ -2503,7 +2502,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "doctrine/lexer", @@ -2557,7 +2556,7 @@ "lexer", "parser" ], - "time": "2014-09-09 13:34:57" + "time": "2014-09-09T13:34:57+00:00" }, { "name": "fzaninotto/faker", @@ -2605,7 +2604,7 @@ "faker", "fixtures" ], - "time": "2016-04-29 12:21:54" + "time": "2016-04-29T12:21:54+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -2650,122 +2649,7 @@ "keywords": [ "test" ], - "time": "2015-05-11 14:41:42" - }, - { - "name": "league/factory-muffin", - "version": "v3.0.1", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/factory-muffin.git", - "reference": "316ed2bac70178567f995d877b831804c9c58d5a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/factory-muffin/zipball/316ed2bac70178567f995d877b831804c9c58d5a", - "reference": "316ed2bac70178567f995d877b831804c9c58d5a", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "replace": { - "zizaco/factory-muff": "self.version" - }, - "require-dev": { - "doctrine/orm": "2.5.*", - "illuminate/database": "5.0.*|5.1.*", - "league/factory-muffin-faker": "^2.0", - "phpunit/phpunit": "^4.8|^5.0" - }, - "suggest": { - "doctrine/orm": "Factory Muffin supports doctrine through the repository store.", - "illuminate/database": "Factory Muffin supports eloquent through the model store.", - "league/factory-muffin-faker": "Factory Muffin is very powerful together with faker." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "League\\FactoryMuffin\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Scott Robertson", - "email": "scottymeuk@gmail.com" - }, - { - "name": "Graham Campbell", - "email": "graham@alt-three.com" - } - ], - "description": "The goal of this package is to enable the rapid creation of objects for the purpose of testing.", - "homepage": "http://factory-muffin.thephpleague.com/", - "keywords": [ - "factory", - "testing" - ], - "time": "2016-05-13 10:56:41" - }, - { - "name": "league/factory-muffin-faker", - "version": "v2.0.0", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/factory-muffin-faker.git", - "reference": "61e0e40356edee0502f379cc85ca74e4234c687c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/factory-muffin-faker/zipball/61e0e40356edee0502f379cc85ca74e4234c687c", - "reference": "61e0e40356edee0502f379cc85ca74e4234c687c", - "shasum": "" - }, - "require": { - "fzaninotto/faker": "1.6.*", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8|^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-4": { - "League\\FactoryMuffin\\Faker\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "graham@alt-three.com" - } - ], - "description": "The goal of this package is to wrap faker to make it super easy to use with factory muffin.", - "homepage": "http://factory-muffin.thephpleague.com/", - "keywords": [ - "factory", - "faker", - "testing" - ], - "time": "2016-05-13 10:47:29" + "time": "2015-05-11T14:41:42+00:00" }, { "name": "mockery/mockery", @@ -2830,7 +2714,7 @@ "test double", "testing" ], - "time": "2017-02-28 12:52:32" + "time": "2017-02-28T12:52:32+00:00" }, { "name": "myclabs/deep-copy", @@ -2872,7 +2756,7 @@ "object", "object graph" ], - "time": "2017-01-26 22:05:40" + "time": "2017-01-26T22:05:40+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -2926,7 +2810,7 @@ "reflection", "static analysis" ], - "time": "2015-12-27 11:43:31" + "time": "2015-12-27T11:43:31+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -2971,7 +2855,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-09-30 07:12:33" + "time": "2016-09-30T07:12:33+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -3018,7 +2902,7 @@ "email": "me@mikevanriel.com" } ], - "time": "2016-11-25 06:54:22" + "time": "2016-11-25T06:54:22+00:00" }, { "name": "phpspec/prophecy", @@ -3081,7 +2965,7 @@ "spy", "stub" ], - "time": "2017-03-02 20:05:34" + "time": "2017-03-02T20:05:34+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3144,7 +3028,7 @@ "testing", "xunit" ], - "time": "2016-05-27 16:24:29" + "time": "2016-05-27T16:24:29+00:00" }, { "name": "phpunit/php-file-iterator", @@ -3191,7 +3075,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03 07:40:28" + "time": "2016-10-03T07:40:28+00:00" }, { "name": "phpunit/php-text-template", @@ -3232,7 +3116,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -3281,7 +3165,7 @@ "keywords": [ "timer" ], - "time": "2017-02-26 11:10:40" + "time": "2017-02-26T11:10:40+00:00" }, { "name": "phpunit/php-token-stream", @@ -3330,7 +3214,7 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27 10:12:30" + "time": "2017-02-27T10:12:30+00:00" }, { "name": "phpunit/phpunit", @@ -3404,7 +3288,7 @@ "testing", "xunit" ], - "time": "2016-03-15 05:59:58" + "time": "2016-03-15T05:59:58+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -3460,7 +3344,7 @@ "mock", "xunit" ], - "time": "2016-04-20 14:39:26" + "time": "2016-04-20T14:39:26+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -3505,7 +3389,7 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2016-02-13 06:45:14" + "time": "2016-02-13T06:45:14+00:00" }, { "name": "sebastian/comparator", @@ -3569,7 +3453,7 @@ "compare", "equality" ], - "time": "2017-01-29 09:50:25" + "time": "2017-01-29T09:50:25+00:00" }, { "name": "sebastian/diff", @@ -3621,7 +3505,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08 07:14:41" + "time": "2015-12-08T07:14:41+00:00" }, { "name": "sebastian/environment", @@ -3671,7 +3555,7 @@ "environment", "hhvm" ], - "time": "2016-08-18 05:49:44" + "time": "2016-08-18T05:49:44+00:00" }, { "name": "sebastian/exporter", @@ -3738,7 +3622,7 @@ "export", "exporter" ], - "time": "2016-06-17 09:04:28" + "time": "2016-06-17T09:04:28+00:00" }, { "name": "sebastian/global-state", @@ -3789,7 +3673,7 @@ "keywords": [ "global state" ], - "time": "2015-10-12 03:26:01" + "time": "2015-10-12T03:26:01+00:00" }, { "name": "sebastian/recursion-context", @@ -3842,7 +3726,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11 19:50:13" + "time": "2015-11-11T19:50:13+00:00" }, { "name": "sebastian/resource-operations", @@ -3884,7 +3768,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28 20:34:47" + "time": "2015-07-28T20:34:47+00:00" }, { "name": "sebastian/version", @@ -3927,7 +3811,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03 07:35:21" + "time": "2016-10-03T07:35:21+00:00" }, { "name": "symfony/class-loader", @@ -3983,7 +3867,7 @@ ], "description": "Symfony ClassLoader Component", "homepage": "https://symfony.com", - "time": "2017-01-21 17:06:35" + "time": "2017-01-21T17:06:35+00:00" }, { "name": "symfony/css-selector", @@ -4036,7 +3920,7 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" + "time": "2016-06-29T05:40:00+00:00" }, { "name": "symfony/dom-crawler", @@ -4092,7 +3976,7 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2016-07-30 07:22:48" + "time": "2016-07-30T07:22:48+00:00" }, { "name": "symfony/yaml", @@ -4147,7 +4031,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-02-16 22:46:52" + "time": "2017-02-16T22:46:52+00:00" }, { "name": "webmozart/assert", @@ -4197,7 +4081,7 @@ "check", "validate" ], - "time": "2016-11-23 20:04:58" + "time": "2016-11-23T20:04:58+00:00" } ], "aliases": [], diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index d7a62ca5..2197bffc 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -11,7 +11,7 @@ | */ -$factory->define(LVA\User::class, function (Faker\Generator $faker) { +$factory->define(\LVA\User::class, function (\Faker\Generator $faker) { return [ 'name' => $faker->unique()->name, 'email' => $faker->unique()->email, @@ -27,11 +27,11 @@ ]; }); -$factory->define(LVA\Models\Division::class, function (\Faker\Generator $faker) { +$factory->define(\LVA\Models\Division::class, function (\Faker\Generator $faker) { return [ 'division' => $faker->unique()->word, 'season_id' => function () { - return factory(LVA\Models\Season::class)->create()->id; + return factory(\LVA\Models\Season::class)->create()->id; }, ]; }); @@ -42,27 +42,12 @@ ]; }); -$factory->define(LVA\Models\Team::class, function (\Faker\Generator $faker) { - return [ - 'team' => $faker->unique()->word, - 'club_id' => function () { - return factory(LVA\Models\Club::class)->create()->id; - }, - ]; -}); - $factory->define(\LVA\Models\Role::class, function (\Faker\Generator $faker) { return [ 'role' => $faker->unique()->word, ]; }); -$factory->define(\LVA\Models\Venue::class, function (\Faker\Generator $faker) { - return [ - 'venue' => $faker->unique()->word, - ]; -}); - $factory->define(\LVA\Models\Fixture::class, function (\Faker\Generator $faker) { return [ 'division_id' => function () { @@ -94,36 +79,3 @@ }, ]; }); - -$factory->define(\LVA\Models\UploadJobStatus::class, function (\Faker\Generator $faker) { - $totalLines = $faker->numberBetween(10, 200); - $processedLines = $faker->numberBetween(0, $totalLines); - $totalRows = $faker->numberBetween($totalLines, $totalLines * 2); - $processedRows = $faker->numberBetween(0, $totalRows); - - return [ - "status_code" => 1, - "total_lines" => $totalLines, - "processed_lines" => $processedLines, - "total_rows" => $totalRows, - "processed_rows" => $processedRows, - "processing_line" => [], - "unknowns" => null, - "errors" => [], - "error_line" => null, - ]; -}); - -$factory->define(\LVA\Models\UploadJob::class, function (\Faker\Generator $faker) { - return [ - 'file' => $faker->word . str_random(5) . '.csv', - 'type' => 'fixtures', - 'status' => function () { - return json_encode(factory(\LVA\Models\UploadJobStatus::class)->make()); - }, - 'season_id' => function () { - return factory(\LVA\Models\Season::class)->create()->id; - }, - 'row_count' => $faker->numberBetween(1, 100), - ]; -}); \ No newline at end of file diff --git a/database/factories/TeamFactories.php b/database/factories/TeamFactories.php new file mode 100644 index 00000000..3bb6003b --- /dev/null +++ b/database/factories/TeamFactories.php @@ -0,0 +1,31 @@ +define(LVA\Models\Team::class, function (\Faker\Generator $faker) { + return [ + 'team' => $faker->unique()->word, + 'club_id' => function () { + return factory(\LVA\Models\Club::class)->create()->id; + }, + ]; +}); + +$factory->define(\LVA\Models\MappedTeam::class, function (\Faker\Generator $faker) { + return [ + 'upload_job_id' => function () { + return factory(\LVA\Models\UploadJob::class)->create()->id; + }, + 'mapped_team' => $faker->unique()->name, + 'team_id' => function () { + return factory(\LVA\Models\Team::class)->create()->id; + }, + ]; +}); + +$factory->define(\LVA\Models\TeamSynonym::class, function (\Faker\Generator $faker) { + return [ + 'synonym' => $faker->unique()->word, + 'team_id' => function () { + return factory(\LVA\Models\Team::class)->create()->id; + }, + ]; +}); diff --git a/database/factories/UploadFactories.php b/database/factories/UploadFactories.php new file mode 100644 index 00000000..f1157599 --- /dev/null +++ b/database/factories/UploadFactories.php @@ -0,0 +1,55 @@ +define(\LVA\Models\UploadJob::class, function (\Faker\Generator $faker) { + return [ + 'file' => $faker->word . str_random(5) . '.csv', + 'type' => 'fixtures', + 'status' => json_encode(['status_code' => \LVA\Models\UploadJobStatus::STATUS_NOT_STARTED]), + 'season_id' => function () { + return factory(\LVA\Models\Season::class)->create()->id; + }, + 'row_count' => $faker->numberBetween(1, 100), + ]; +}); + +$factory->define(\LVA\Models\UploadJobData::class, function (\Faker\Generator $faker) { + return [ + 'upload_job_id' => function () { + return factory(\LVA\Models\UploadJob::class)->create()->id; + }, + 'model' => \LVA\Models\Fixture::class, + 'model_data' => serialize(factory(\LVA\Models\Fixture::class)->make()), + ]; +}); + +$factory->defineAs(\LVA\Models\UploadJobData::class, \LVA\Models\TeamSynonym::class, + function (\Faker\Generator $faker) { + return [ + 'upload_job_id' => function () { + return factory(\LVA\Models\UploadJob::class)->create()->id; + }, + 'model' => \LVA\Models\TeamSynonym::class, + 'model_data' => serialize(factory(\LVA\Models\TeamSynonym::class)->make()), + ]; + }); + +$factory->defineAs(\LVA\Models\UploadJobData::class, \LVA\Models\VenueSynonym::class, + function (\Faker\Generator $faker) { + return [ + 'upload_job_id' => function () { + return factory(\LVA\Models\UploadJob::class)->create()->id; + }, + 'model' => \LVA\Models\VenueSynonym::class, + 'model_data' => serialize(factory(\LVA\Models\VenueSynonym::class)->make()), + ]; + }); + +$factory->defineAs(\LVA\Models\UploadJobData::class, \LVA\Models\Fixture::class, function (\Faker\Generator $faker) { + return [ + 'upload_job_id' => function () { + return factory(\LVA\Models\UploadJob::class)->create()->id; + }, + 'model' => \LVA\Models\Fixture::class, + 'model_data' => serialize(factory(\LVA\Models\Fixture::class)->make()), + ]; +}); diff --git a/database/factories/VenueFactories.php b/database/factories/VenueFactories.php new file mode 100644 index 00000000..7ede0f17 --- /dev/null +++ b/database/factories/VenueFactories.php @@ -0,0 +1,37 @@ +define(\LVA\Models\Venue::class, function (\Faker\Generator $faker) { + return [ + 'venue' => $faker->unique()->word, + ]; +}); + +$factory->define(\LVA\Models\MappedVenue::class, function (\Faker\Generator $faker) { + return [ + 'upload_job_id' => function () { + return factory(\LVA\Models\UploadJob::class)->create()->id; + }, + 'mapped_venue' => $faker->unique()->name, + 'venue_id' => function () { + return factory(\LVA\Models\Venue::class)->create()->id; + }, + ]; +}); + +$factory->define(\LVA\Models\NewVenue::class, function (\Faker\Generator $faker) { + return [ + 'upload_job_id' => function () { + return factory(\LVA\Models\UploadJob::class)->create()->id; + }, + 'venue' => $faker->unique()->word, + ]; +}); + +$factory->define(\LVA\Models\VenueSynonym::class, function (\Faker\Generator $faker) { + return [ + 'synonym' => $faker->unique()->word, + 'venue_id' => function () { + return factory(\LVA\Models\Venue::class)->create()->id; + }, + ]; +}); \ No newline at end of file diff --git a/database/muffins/UploadJobStatus.php b/database/muffins/UploadJobStatus.php deleted file mode 100644 index 34b03a4b..00000000 --- a/database/muffins/UploadJobStatus.php +++ /dev/null @@ -1,13 +0,0 @@ - - * Date: 13/03/2017 - * Time: 19:01 - */ - -use League\FactoryMuffin\Faker\Faker; - -$fm->define(\LVA\Models\UploadJobStatus::class)->setDefinitions([ - 'status_code' => \LVA\Models\UploadJobStatus::STATUS_NOT_STARTED, -]); \ No newline at end of file diff --git a/tests/integration/IntegrationTestCase.php b/tests/integration/IntegrationTestCase.php new file mode 100644 index 00000000..72d15996 --- /dev/null +++ b/tests/integration/IntegrationTestCase.php @@ -0,0 +1,66 @@ +faker = \Faker\Factory::create(); + } + + /** + * @param array $overrides + * + * @return UploadJobStatus + */ + protected function uploadJobTestFactory($overrides = []) + { + $totalLines = $this->faker->numberBetween(10, 200); + $totalRows = $this->faker->numberBetween($totalLines, $totalLines * 2); + + /** @var \LVA\Models\Venue[] $mapping */ + $mapping = factory(\LVA\Models\Venue::class)->times(3)->make(); + + $defaults = [ + "status_code" => \LVA\Models\UploadJobStatus::STATUS_NOT_STARTED, + "total_lines" => $totalLines, + "processed_lines" => $this->faker->numberBetween(0, $totalLines), + "total_rows" => $totalRows, + "processed_rows" => $this->faker->numberBetween(0, $totalRows), + 'processing_line' => [ + 'division' => factory(\LVA\Models\Division::class)->make()->getName(), + 'match_number' => $this->faker->numberBetween(1, 20), + 'home_team' => factory(\LVA\Models\Team::class)->make()->getName(), + 'away_team' => factory(\LVA\Models\Team::class)->make()->getName(), + 'date' => $this->faker->date('D, d/m/Y'), + 'warm_up_time' => $this->faker->date('H:i'), + 'start_time' => $this->faker->date('H:i'), + 'venue' => factory(\LVA\Models\Venue::class)->make()->getName(), + ], + 'unknowns' => [ + \LVA\Models\UploadJobStatus::UNKNOWN_VENUE => [ + ['value' => $mapping[0]->getId(), 'text' => $mapping[0]->getName()], + ['value' => $mapping[1]->getId(), 'text' => $mapping[1]->getName()], + ['value' => $mapping[2]->getId(), 'text' => $mapping[2]->getName()], + ], + ], + "errors" => $this->faker->unique()->sentences(), + "error_line" => $this->faker->numberBetween(1, $totalLines - 1), + ]; + + return UploadJobStatus::factory(array_merge($defaults, $overrides)); + } +} \ No newline at end of file diff --git a/tests/integration/Models/AvailableAppointmentTest.php b/tests/integration/Models/AvailableAppointmentTest.php index 4aa7c6c5..a7eff7eb 100644 --- a/tests/integration/Models/AvailableAppointmentTest.php +++ b/tests/integration/Models/AvailableAppointmentTest.php @@ -4,15 +4,15 @@ use LVA\Models\Fixture; use LVA\Models\Role; -use Tests\TestCase; use LVA\Models\AvailableAppointment; +use Tests\Integration\IntegrationTestCase; /** * Class AvailableAppointmentTest * * @package Tests\Models */ -class AvailableAppointmentTest extends TestCase +class AvailableAppointmentTest extends IntegrationTestCase { /** * @test diff --git a/tests/integration/Models/ClubTest.php b/tests/integration/Models/ClubTest.php index 27d15a52..9b858d39 100644 --- a/tests/integration/Models/ClubTest.php +++ b/tests/integration/Models/ClubTest.php @@ -3,7 +3,7 @@ namespace Tests\Models; use LVA\Models\Team; -use Tests\TestCase; +use Tests\Integration\IntegrationTestCase; use LVA\Models\Club; /** @@ -11,7 +11,7 @@ * * @package Tests\Models */ -class ClubTest extends TestCase +class ClubTest extends IntegrationTestCase { /** * @test diff --git a/tests/integration/Models/DivisionTest.php b/tests/integration/Models/DivisionTest.php index 884861c4..4b864d70 100644 --- a/tests/integration/Models/DivisionTest.php +++ b/tests/integration/Models/DivisionTest.php @@ -4,7 +4,7 @@ use LVA\Models\Fixture; use LVA\Models\Season; -use Tests\TestCase; +use Tests\Integration\IntegrationTestCase; use LVA\Models\Division; /** @@ -12,7 +12,7 @@ * * @package Tests\Models */ -class DivisionTest extends TestCase +class DivisionTest extends IntegrationTestCase { /** * @test @@ -53,7 +53,8 @@ public function it_can_be_found_by_name_in_a_season() /** @var Division $division */ $division = factory(Division::class)->create(['season_id' => $season->getId()]); - $this->assertEquals($division->getId(), Division::findByName($season->getId(), $division->getName())->getId()); + // I have to use the toArray() method as I'm only interested in the table's fields and not any internal ones + $this->assertEquals($division->toArray(), Division::findByName($season->getId(), $division->getName())->toArray()); $this->assertNull(Division::findByName(0, $division->getName())); $this->assertNull(Division::findByName($season->getId(), $division->getName() . '--')); } diff --git a/tests/integration/Models/FixtureTest.php b/tests/integration/Models/FixtureTest.php index 2af88354..b90c9a55 100644 --- a/tests/integration/Models/FixtureTest.php +++ b/tests/integration/Models/FixtureTest.php @@ -7,7 +7,7 @@ use LVA\Models\Division; use LVA\Models\Team; use LVA\Models\Venue; -use Tests\TestCase; +use Tests\Integration\IntegrationTestCase; use LVA\Models\Fixture; /** @@ -15,7 +15,7 @@ * * @package Tests\Models */ -class FixtureTest extends TestCase +class FixtureTest extends IntegrationTestCase { /** * @test @@ -135,10 +135,10 @@ public function it_can_set_the_match_date() /** @var Carbon $newDate */ $newDate = $fixture->match_date->addDay(); - $this->assertNotEquals($newDate, $fixture->match_date); + $this->assertNotEquals($newDate->format('Y-m-d'), $fixture->match_date->format('Y-m-d')); $fixture->setMatchDate($newDate); - $this->assertEquals($newDate, $fixture->match_date); + $this->assertEquals($newDate->format('Y-m-d'), $fixture->match_date->format('Y-m-d')); } /** @@ -152,10 +152,10 @@ public function it_can_set_the_warm_up_time() /** @var Carbon $newWarmUpTime */ $newWarmUpTime = $fixture->warm_up_time->addHour(); - $this->assertNotEquals($newWarmUpTime, $fixture->warm_up_time); + $this->assertNotEquals($newWarmUpTime->format('H:i'), $fixture->warm_up_time->format('H:i')); $fixture->setWarmUpTime($newWarmUpTime); - $this->assertEquals($newWarmUpTime, $fixture->warm_up_time); + $this->assertEquals($newWarmUpTime->format('H:i'), $fixture->warm_up_time->format('H:i')); } /** @@ -169,10 +169,10 @@ public function it_can_set_the_start_time() /** @var Carbon $newStartTime */ $newStartTime = $fixture->start_time->addHour(); - $this->assertNotEquals($newStartTime, $fixture->start_time); + $this->assertNotEquals($newStartTime->format('H:i'), $fixture->start_time->format('H:i')); $fixture->setStartTime($newStartTime); - $this->assertEquals($newStartTime, $fixture->start_time); + $this->assertEquals($newStartTime->format('H:i'), $fixture->start_time->format('H:i')); } /** diff --git a/tests/integration/Models/MappedTeamTest.php b/tests/integration/Models/MappedTeamTest.php index 71c9e484..3941249f 100644 --- a/tests/integration/Models/MappedTeamTest.php +++ b/tests/integration/Models/MappedTeamTest.php @@ -1,18 +1,125 @@ times(2)->create(); + + $teams = mt_rand(2, 20); + factory(MappedTeam::class)->times($teams)->create(['upload_job_id' => $jobs[0]->getId()]); + + $this->assertCount($teams, MappedTeam::findByJob($jobs[0]->getId())); + $this->assertCount(0, MappedTeam::findByJob($jobs[1]->getId())); + } + + /** + * @test + */ + public function it_belongs_to_a_job() + { + /** @var MappedTeam $mappedTeam */ + $mappedTeam = factory(MappedTeam::class)->create(); + + $this->assertInstanceOf(UploadJob::class, $mappedTeam->uploadJob); + } + + /** + * @test + */ + public function it_belong_to_a_team() + { + /** @var MappedTeam $mappedTeam */ + $mappedTeam = factory(MappedTeam::class)->create(); + + $this->assertInstanceOf(Team::class, $mappedTeam->team); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var MappedTeam $mappedTeam */ + $mappedTeam = factory(MappedTeam::class)->create(); + + $this->assertEquals($mappedTeam->id, $mappedTeam->getId()); + } + + /** + * @test + */ + public function it_sets_the_job() { + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + /** @var MappedTeam $mappedTeam */ + $mappedTeam = factory(MappedTeam::class)->create(); + + $this->assertNotEquals($job->getId(), $mappedTeam->upload_job_id); + + $mappedTeam->setUploadJob($job->getId()); + $this->assertEquals($job->getId(), $mappedTeam->upload_job_id); + } + + /** + * @test + */ + public function it_gets_the_name_of_the_mapped_team() + { + /** @var MappedTeam $mappedTeam */ + $mappedTeam = factory(MappedTeam::class)->create(); + + $this->assertEquals($mappedTeam->mapped_team, $mappedTeam->getName()); + } + + /** + * @test + */ + public function it_sets_the_name_of_the_mapped_team() + { + /** @var MappedTeam $mappedTeam */ + $mappedTeam = factory(MappedTeam::class)->create(); + + $this->assertEquals($mappedTeam->mapped_team, $mappedTeam->getName()); + + $newName = str_random(); + $this->assertNotEquals($newName, $mappedTeam->getName()); + $mappedTeam->setName($newName); + $this->assertEquals($newName, $mappedTeam->mapped_team); + } + + /** + * @test + */ + public function it_sets_the_team_it_is_mapped_to() + { + /** @var Team $team */ + $team = factory(Team::class)->create(); + + /** @var MappedTeam $mappedTeam */ + $mappedTeam = factory(MappedTeam::class)->create(); + + $this->assertNotEquals($team->getId(), $mappedTeam->team->id); + + $mappedTeam->setMappedTeam($team->getName()); + $this->assertEquals($team->getId(), $mappedTeam->team->getId()); } } diff --git a/tests/integration/Models/MappedVenueTest.php b/tests/integration/Models/MappedVenueTest.php index 1d7f12f5..91bc0d74 100644 --- a/tests/integration/Models/MappedVenueTest.php +++ b/tests/integration/Models/MappedVenueTest.php @@ -1,18 +1,125 @@ times(2)->create(); + + $venues = mt_rand(2, 20); + factory(MappedVenue::class)->times($venues)->create(['upload_job_id' => $jobs[0]->getId()]); + + $this->assertCount($venues, MappedVenue::findByJob($jobs[0]->getId())); + $this->assertCount(0, MappedVenue::findByJob($jobs[1]->getId())); + } + + /** + * @test + */ + public function it_belongs_to_a_job() + { + /** @var MappedVenue $mappedVenue */ + $mappedVenue = factory(MappedVenue::class)->create(); + + $this->assertInstanceOf(UploadJob::class, $mappedVenue->uploadJob); + } + + /** + * @test + */ + public function it_belong_to_a_venue() + { + /** @var MappedVenue $mappedVenue */ + $mappedVenue = factory(MappedVenue::class)->create(); + + $this->assertInstanceOf(Venue::class, $mappedVenue->venue); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var MappedVenue $mappedVenue */ + $mappedVenue = factory(MappedVenue::class)->create(); + + $this->assertEquals($mappedVenue->id, $mappedVenue->getId()); + } + + /** + * @test + */ + public function it_sets_the_job() { + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + /** @var MappedVenue $mappedVenue */ + $mappedVenue = factory(MappedVenue::class)->create(); + + $this->assertNotEquals($job->getId(), $mappedVenue->upload_job_id); + + $mappedVenue->setUploadJob($job->getId()); + $this->assertEquals($job->getId(), $mappedVenue->upload_job_id); + } + + /** + * @test + */ + public function it_gets_the_name_of_the_mapped_venue() + { + /** @var MappedVenue $mappedVenue */ + $mappedVenue = factory(MappedVenue::class)->create(); + + $this->assertEquals($mappedVenue->mapped_venue, $mappedVenue->getName()); + } + + /** + * @test + */ + public function it_sets_the_name_of_the_mapped_tesm() + { + /** @var MappedVenue $mappedVenue */ + $mappedVenue = factory(MappedVenue::class)->create(); + + $this->assertEquals($mappedVenue->mapped_venue, $mappedVenue->getName()); + + $newName = str_random(); + $this->assertNotEquals($newName, $mappedVenue->getName()); + $mappedVenue->setName($newName); + $this->assertEquals($newName, $mappedVenue->mapped_venue); + } + + /** + * @test + */ + public function it_sets_the_venue_it_is_mapped_to() + { + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + + /** @var MappedVenue $mappedVenue */ + $mappedVenue = factory(MappedVenue::class)->create(); + + $this->assertNotEquals($venue->getId(), $mappedVenue->venue->id); + + $mappedVenue->setMappedVenue($venue->getName()); + $this->assertEquals($venue->getId(), $mappedVenue->venue->getId()); } } diff --git a/tests/integration/Models/RoleTest.php b/tests/integration/Models/RoleTest.php index 6b2eb9de..5dca66c7 100644 --- a/tests/integration/Models/RoleTest.php +++ b/tests/integration/Models/RoleTest.php @@ -3,15 +3,15 @@ namespace Tests\Models; use LVA\Models\AvailableAppointment; -use Tests\TestCase; use LVA\Models\Role; +use Tests\Integration\IntegrationTestCase; /** * Class RoleTest * * @package Tests\Models */ -class RoleTest extends TestCase +class RoleTest extends IntegrationTestCase { /** * @test diff --git a/tests/integration/Models/SeasonTest.php b/tests/integration/Models/SeasonTest.php index dbf3d46d..29202625 100644 --- a/tests/integration/Models/SeasonTest.php +++ b/tests/integration/Models/SeasonTest.php @@ -3,15 +3,15 @@ namespace Tests\Models; use LVA\Models\Division; -use Tests\TestCase; use LVA\Models\Season; +use Tests\Integration\IntegrationTestCase; /** * Class SeasonTest * * @package Tests\Models */ -class SeasonTest extends TestCase +class SeasonTest extends IntegrationTestCase { /** * @test diff --git a/tests/integration/Models/TeamSynonymTest.php b/tests/integration/Models/TeamSynonymTest.php index 862099c7..0a16d8a6 100644 --- a/tests/integration/Models/TeamSynonymTest.php +++ b/tests/integration/Models/TeamSynonymTest.php @@ -1,18 +1,94 @@ times(2)->create(); + + $this->assertEquals($teamSynonyms[0]->team, TeamSynonym::findBySynonym($teamSynonyms[0]->getSynonym())); + $this->assertNull(TeamSynonym::findBySynonym($teamSynonyms[0]->getSynonym() . '---')); + $this->assertEquals($teamSynonyms[1]->team, TeamSynonym::findBySynonym($teamSynonyms[1]->getSynonym())); + $this->assertNull(TeamSynonym::findBySynonym($teamSynonyms[1]->getSynonym() . '---')); + } + + /** + * @test + */ + public function it_belongs_to_a_team() + { + /** @var TeamSynonym $teamSynonym */ + $teamSynonym = factory(TeamSynonym::class)->create(); + + $this->assertInstanceOf(Team::class, $teamSynonym->team); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var TeamSynonym $teamSynonym */ + $teamSynonym = factory(TeamSynonym::class)->create(); + + $this->assertEquals($teamSynonym->id, $teamSynonym->getId()); + } + + /** + * @test + */ + public function it_gets_the_synonym() + { + /** @var TeamSynonym $teamSynonym */ + $teamSynonym = factory(TeamSynonym::class)->create(); + + $this->assertEquals($teamSynonym->synonym, $teamSynonym->getSynonym()); + } + + /** + * @test + */ + public function it_sets_the_synonym() + { + /** @var TeamSynonym $teamSynonym */ + $teamSynonym = factory(TeamSynonym::class)->create(); + + $this->assertEquals($teamSynonym->synonym, $teamSynonym->getSynonym()); + + $newSynonym = str_random(); + $teamSynonym->setSynonym($newSynonym); + $this->assertEquals($newSynonym, $teamSynonym->getSynonym()); + } + + /** + * @test + */ + public function it_sets_the_team() + { + /** @var Team $team */ + $team = factory(Team::class)->create(); + + /** @var TeamSynonym $teamSynonym */ + $teamSynonym = factory(TeamSynonym::class)->create(); + + $this->assertNotEquals($team->getId(), $teamSynonym->team->getId()); + + $teamSynonym->setTeam($team->getName()); + $this->assertEquals($team->getId(), $teamSynonym->team->getId()); } } diff --git a/tests/integration/Models/TeamTest.php b/tests/integration/Models/TeamTest.php index 05010ca0..8bcb635c 100644 --- a/tests/integration/Models/TeamTest.php +++ b/tests/integration/Models/TeamTest.php @@ -4,15 +4,17 @@ use LVA\Models\Club; use LVA\Models\Fixture; -use Tests\TestCase; +use LVA\Models\MappedTeam; +use LVA\Models\TeamSynonym; use LVA\Models\Team; +use Tests\Integration\IntegrationTestCase; /** * Class TeamTest * * @package Tests\Models */ -class TeamTest extends TestCase +class TeamTest extends IntegrationTestCase { /** * @test @@ -22,9 +24,10 @@ public function it_can_be_found_by_name() /** @var Team[] $teams */ $teams = factory(Team::class)->times(2)->create(); - $this->assertEquals($teams[0]->getId(), Team::findByName($teams[0]->team)->getId()); + // I have to use the toArray() method as I'm only interested in the table's fields and not any internal ones + $this->assertEquals($teams[0]->toArray(), Team::findByName($teams[0]->team)->toArray()); $this->assertNull(Team::findByName($teams[0]->team . '--')); - $this->assertEquals($teams[1]->getId(), Team::findByName($teams[1]->team)->getId()); + $this->assertEquals($teams[1]->toArray(), Team::findByName($teams[1]->team)->toArray()); $this->assertNull(Team::findByName($teams[1]->team . '--')); } @@ -80,7 +83,14 @@ public function it_has_many_fixtures_as_home_team() */ public function it_has_many_synonyms() { - $this->markTestIncomplete('Need to create the factory for team synonyms.'); + /** @var Team[] $teams */ + $teams = factory(Team::class)->times(2)->create(); + + $synonyms = mt_rand(2,20); + factory(TeamSynonym::class)->times($synonyms)->create(['team_id' => $teams[0]->getId()]); + + $this->assertCount($synonyms, $teams[0]->synonyms); + $this->assertCount(0, $teams[1]->synonyms); } /** @@ -88,7 +98,14 @@ public function it_has_many_synonyms() */ public function it_has_many_mapped_teams() { - $this->markTestIncomplete('Need to create the factory for the mapped teams.'); + /** @var Team[] $teams */ + $teams = factory(Team::class)->times(2)->create(); + + $mapped = mt_rand(2,20); + factory(MappedTeam::class)->times($mapped)->create(['team_id' => $teams[0]->getId()]); + + $this->assertCount($mapped, $teams[0]->mapped); + $this->assertCount(0, $teams[1]->mapped); } /** @@ -102,6 +119,17 @@ public function it_gets_the_id() $this->assertEquals($team->id, $team->getId()); } + /** + * @test + */ + public function it_gets_the_name() + { + /** @var Team $team */ + $team = factory(Team::class)->create(); + + $this->assertEquals($team->team, $team->getName()); + } + /** * @test */ @@ -112,5 +140,4 @@ public function it_is_a_string() $this->assertEquals($team->team, (string)$team); } - } diff --git a/tests/integration/Models/UploadJobDataTest.php b/tests/integration/Models/UploadJobDataTest.php index 47040366..9125ea99 100644 --- a/tests/integration/Models/UploadJobDataTest.php +++ b/tests/integration/Models/UploadJobDataTest.php @@ -1,18 +1,136 @@ times(2)->create(); + + $teamSynonyms = mt_rand(1, 10); + factory(UploadJobData::class, + TeamSynonym::class)->times($teamSynonyms)->create(['upload_job_id' => $jobs[0]->getId()]); + + $venueSynonyms = mt_rand(1, 10); + factory(UploadJobData::class, + VenueSynonym::class)->times($venueSynonyms)->create(['upload_job_id' => $jobs[0]->getId()]); + + $fixtures = mt_rand(2, 20); + factory(UploadJobData::class, Fixture::class)->times($fixtures)->create(['upload_job_id' => $jobs[0]->getId()]); + + $this->assertCount($teamSynonyms + $venueSynonyms + $fixtures, UploadJobData::findByJobId($jobs[0]->getId())); + $this->assertCount(0, UploadJobData::findByJobId($jobs[1]->getId())); + } + + /** + * @test + */ + public function it_belongs_to_a_job() { + /** @var UploadJobData $data */ + $data = factory(UploadJobData::class)->create(); + + $this->assertInstanceOf(UploadJob::class, $data->uploadJob); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var UploadJobData $data */ + $data = factory(UploadJobData::class)->create(); + + $this->assertEquals($data->id, $data->getId()); + } + + /** + * @test + */ + public function it_sets_the_job_id() + { + /** @var UploadJobData $data */ + $data = factory(UploadJobData::class)->create(); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $this->assertNotEquals($job->toArray(), $data->uploadJob->toArray()); + + $data->setJob($job->getId()); + $this->assertEquals($job->toArray(), $data->uploadJob->toArray()); + } + + /** + * @test + */ + public function it_gets_the_model() + { + /** @var UploadJobData $data */ + $data = factory(UploadJobData::class)->create(); + + $this->assertEquals($data->model, $data->getModel()); + } + + /** + * @test + */ + public function it_sets_the_model() + { + /** @var UploadJobData $data */ + $data = factory(UploadJobData::class, Fixture::class)->create(); + + /** @var string $model */ + $model = TeamSynonym::class; + + $this->assertNotEquals($model, $data->getModel()); + + $data->setModel($model); + $this->assertEquals($model, $data->getModel()); + } + + /** + * @test + */ + public function it_gets_the_data() + { + /** @var UploadJobData $data */ + $data = factory(UploadJobData::class)->create(); + + $this->assertEquals($data->model_data, $data->getData()); + } + + /** + * @test + */ + public function it_sets_the_data() + { + /** @var UploadJobData $data */ + $data = factory(UploadJobData::class)->create(); + + /** @var Fixture $fixture */ + $fixture = factory(Fixture::class)->create(); + + $this->assertNotEquals(serialize($fixture), $data->getData()); + + $data->setData(serialize($fixture)); + $this->assertEquals(serialize($fixture), $data->getData()); } } diff --git a/tests/integration/Models/UploadJobStatusTest.php b/tests/integration/Models/UploadJobStatusTest.php index 6ffe1160..e2ce590c 100644 --- a/tests/integration/Models/UploadJobStatusTest.php +++ b/tests/integration/Models/UploadJobStatusTest.php @@ -1,48 +1,963 @@ uploadJobTestFactory()->toArray(); + $status = UploadJobStatus::factory($statusArray); + $this->assertEquals($statusArray, $status->toArray()); + } + + /** + * @test + */ + public function it_gets_the_status_message() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertEquals('Not started', $status->getStatusCodeMessage()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertEquals('Validating records', $status->getStatusCodeMessage()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertEquals('Unrecoverable error', $status->getStatusCodeMessage()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertEquals('Inserting records', $status->getStatusCodeMessage()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertEquals('Unrecoverable error', $status->getStatusCodeMessage()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertEquals('Unknown data', $status->getStatusCodeMessage()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertEquals('Done', $status->getStatusCodeMessage()); + + $status = $this->uploadJobTestFactory(['status_code' => -1]); + $this->assertEquals('Status code -1 not recognised', $status->getStatusCodeMessage()); + } + + + /** + * @test + */ + public function it_loads_a_status_from_an_array() + { + $statusArray = [ + 'status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS, + 'total_lines' => $this->faker->numberBetween(10, 200), + 'processed_lines' => $this->faker->numberBetween(10, 200), + 'total_rows' => $this->faker->numberBetween(10, 200), + 'processed_rows' => $this->faker->numberBetween(10, 200), + 'processing_line' => [ + 'division' => $this->faker->word, + 'match_number' => $this->faker->numberBetween(1, 20), + 'home_team' => $this->faker->word, + 'away_team' => $this->faker->word, + 'date' => $this->faker->date('D, d/m/Y'), + 'warm_up_time' => $this->faker->date('H:i'), + 'start_time' => $this->faker->date('H:i'), + 'venue' => $this->faker->word, + ], + 'unknowns' => [ + \LVA\Models\UploadJobStatus::UNKNOWN_VENUE => [ + ['value' => $this->faker->numberBetween(10, 200), 'text' => $this->faker->word], + ['value' => $this->faker->numberBetween(10, 200), 'text' => $this->faker->word], + ['value' => $this->faker->numberBetween(10, 200), 'text' => $this->faker->word], + ], + ], + 'errors' => $this->faker->sentences(), + 'error_line' => $this->faker->numberBetween(10, 200), + ]; + + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertNotEquals($statusArray, $status->toArray()); + + $status->load($statusArray); + $this->assertEquals($statusArray, $status->toArray()); + } + + /** + * @test + */ + public function it_is_an_array() + { + $statusArray = $this->uploadJobTestFactory()->toArray(); + + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('status_code', $statusArray); + $this->assertArrayHasKey('total_lines', $statusArray); + $this->assertArrayHasKey('processed_lines', $statusArray); + $this->assertArrayHasKey('total_rows', $statusArray); + $this->assertArrayHasKey('processed_rows', $statusArray); + $this->assertArrayHasKey('processing_line', $statusArray); + $this->assertArrayHasKey('unknowns', $statusArray); + $this->assertArrayHasKey('errors', $statusArray); + $this->assertArrayHasKey('error_line', $statusArray); + } + + /** + * @test + */ + public function it_is_an_array_for_an_api_response() + { + $statusArray = $this->uploadJobTestFactory()->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayNotHasKey('Progress', $statusArray); + $this->assertArrayNotHasKey('Fixture', $statusArray); + $this->assertArrayNotHasKey('Unknowns', $statusArray); + $this->assertArrayNotHasKey('Errors', $statusArray); + $this->assertArrayNotHasKey('ErrorLine', $statusArray); + + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS])->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayHasKey('Progress', $statusArray); + $this->assertArrayNotHasKey('Fixture', $statusArray); + $this->assertArrayNotHasKey('Unknowns', $statusArray); + $this->assertArrayNotHasKey('Errors', $statusArray); + $this->assertArrayNotHasKey('ErrorLine', $statusArray); + + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA])->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayHasKey('Progress', $statusArray); + $this->assertArrayHasKey('Fixture', $statusArray); + $this->assertArrayHasKey('Division', $statusArray['Fixture']); + $this->assertArrayHasKey('MatchNumber', $statusArray['Fixture']); + $this->assertArrayHasKey('HomeTeam', $statusArray['Fixture']); + $this->assertArrayHasKey('AwayTeam', $statusArray['Fixture']); + $this->assertArrayHasKey('Date', $statusArray['Fixture']); + $this->assertArrayHasKey('WarmUpTime', $statusArray['Fixture']); + $this->assertArrayHasKey('StartTime', $statusArray['Fixture']); + $this->assertArrayHasKey('Venue', $statusArray['Fixture']); + $this->assertArrayHasKey('Unknowns', $statusArray); + $this->assertArrayNotHasKey('Errors', $statusArray); + $this->assertArrayNotHasKey('ErrorLine', $statusArray); + + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR])->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayHasKey('Progress', $statusArray); + $this->assertArrayNotHasKey('Fixture', $statusArray); + $this->assertArrayNotHasKey('Unknowns', $statusArray); + $this->assertArrayHasKey('Errors', $statusArray); + $this->assertInternalType('array', $statusArray['Errors']); + $this->assertArrayHasKey('ErrorLine', $statusArray); + + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS])->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayHasKey('Progress', $statusArray); + $this->assertArrayNotHasKey('Fixture', $statusArray); + $this->assertArrayNotHasKey('Unknowns', $statusArray); + $this->assertArrayNotHasKey('Errors', $statusArray); + $this->assertArrayNotHasKey('ErrorLine', $statusArray); + + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR])->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayHasKey('Progress', $statusArray); + $this->assertArrayNotHasKey('Fixture', $statusArray); + $this->assertArrayNotHasKey('Unknowns', $statusArray); + $this->assertArrayHasKey('Errors', $statusArray); + $this->assertInternalType('array', $statusArray['Errors']); + $this->assertArrayHasKey('ErrorLine', $statusArray); + + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE])->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayNotHasKey('Progress', $statusArray); + $this->assertArrayNotHasKey('Fixture', $statusArray); + $this->assertArrayNotHasKey('Unknowns', $statusArray); + $this->assertArrayNotHasKey('Errors', $statusArray); + $this->assertArrayNotHasKey('ErrorLine', $statusArray); + } + + /** + * @test + */ + public function it_checks_if_it_has_started() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->hasStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertTrue($status->hasStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertTrue($status->hasStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertTrue($status->hasStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertTrue($status->hasStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertTrue($status->hasStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertTrue($status->hasStarted()); + } + + /** + * @test + */ + public function it_checks_if_it_has_not_started_yet() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertTrue($status->hasNotStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertFalse($status->hasNotStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertFalse($status->hasNotStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->hasNotStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertFalse($status->hasNotStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->hasNotStarted()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->hasNotStarted()); + } + + /** + * @test + */ + public function it_checks_if_it_is_validating() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->isValidating()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertTrue($status->isValidating()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertFalse($status->isValidating()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->isValidating()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertFalse($status->isValidating()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->isValidating()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->isValidating()); + } + + /** + * @test + */ + public function it_checks_if_it_is_inserting() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->isInserting()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertFalse($status->isInserting()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertFalse($status->isInserting()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->isInserting()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertTrue($status->isInserting()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->isInserting()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->isInserting()); + } + + /** + * @test + */ + public function it_checks_if_it_is_done() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->isDone()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertFalse($status->isDone()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertFalse($status->isDone()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->isDone()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertFalse($status->isDone()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->isDone()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertTrue($status->isDone()); + } + + /** + * @test + */ + public function it_checks_if_it_has_unknownd_data() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->hasUnknownData()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertFalse($status->hasUnknownData()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertTrue($status->hasUnknownData()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->hasUnknownData()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertFalse($status->hasUnknownData()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->hasUnknownData()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->hasUnknownData()); + } + + /** + * @test + */ + public function it_checks_if_it_can_resume() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertTrue($status->canResume()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertFalse($status->canResume()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertTrue($status->canResume()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->canResume()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertFalse($status->canResume()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->canResume()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->canResume()); + } + + /** + * @test + */ + public function it_check_if_it_is_in_the_middle_of_processing_some_data() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->isWorking()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertTrue($status->isWorking()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertFalse($status->isWorking()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->isWorking()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertTrue($status->isWorking()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->isWorking()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->isWorking()); + } + + /** + * @test + */ + public function it_gets_the_unknown_data() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->unknowns, $status->getUnknowns()); + } + + /** + * @test + */ + public function it_adds_a_new_unknown_data() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $unknowns = [ + UploadJobStatus::UNKNOWN_HOME_TEAM => factory(Team::class)->times(3)->make(), + UploadJobStatus::UNKNOWN_AWAY_TEAM => factory(Team::class)->times(3)->make(), + UploadJobStatus::UNKNOWN_VENUE => factory(Team::class)->times(3)->make(), + ]; + $status->setUnknown(UploadJobStatus::UNKNOWN_HOME_TEAM, $unknowns[UploadJobStatus::UNKNOWN_HOME_TEAM]); + $status->setUnknown(UploadJobStatus::UNKNOWN_AWAY_TEAM, $unknowns[UploadJobStatus::UNKNOWN_AWAY_TEAM]); + $status->setUnknown(UploadJobStatus::UNKNOWN_VENUE, $unknowns[UploadJobStatus::UNKNOWN_VENUE]); + + $this->assertEquals($unknowns, $status->getUnknowns()); + } + + /** + * @test + */ + public function it_checks_if_it_has_errors() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->hasErrors()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertFalse($status->hasErrors()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertFalse($status->hasErrors()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertTrue($status->hasErrors()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertFalse($status->hasErrors()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertTrue($status->hasErrors()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->hasErrors()); + } + + /** + * @test + */ + public function it_gets_the_errors() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->errors, $status->getErrors()); + } + + /** + * @test + */ + public function it_sets_validation_errors() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $errors = $this->faker->unique()->sentences; + $status->setValidationErrors($errors, 0); + + $this->assertEquals($errors, $status->getErrors()); + } + + /** + * @test + */ + public function it_sets_a_inserting_error() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $error = $this->faker->unique()->sentence; + $status->setInsertingError($error); + + $this->assertEquals([$error], $status->getErrors()); + } + + /** + * @test + */ + public function it_gets_the_line_where_the_error_occured() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->error_line, $status->getErrorLine()); + } + + /** + * @test + */ + public function it_gets_the_status_code() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->status_code, $status->getStatusCode()); + } + + /** + * @test + */ + public function it_gets_the_total_number_of_lines() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->total_lines, $status->getTotalLines()); + } + + /** + * @test + */ + public function it_sets_the_total_number_of_lines() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $lines = $this->faker->numberBetween(10, 200); + + $status->setTotalLines($lines); + $this->assertEquals($lines, $status->getTotalLines()); + } + + /** + * @test + */ + public function it_gets_the_number_of_lines_that_has_been_processed_so_far() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processed_lines, $status->getProcessedLines()); + } + + /** + * @test + */ + public function it_sets_the_number_of_lines_that_has_been_processed_so_far() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $lines = $this->faker->numberBetween(10, 200); + + $status->setProcessedLines($lines); + $this->assertEquals($lines, $status->getProcessedLines()); + } + + /** + * @test + */ + public function it_gets_the_total_number_of_rows_to_insert_into_the_db() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->total_rows, $status->getTotalRows()); + } + + /** + * @test + */ + public function it_sets_the_total_number_of_rows_to_insert_into_the_db() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $lines = $this->faker->numberBetween(10, 200); + + $status->setTotalRows($lines); + $this->assertEquals($lines, $status->getTotalRows()); + } + + /** + * @test + */ + public function it_gets_the_number_of_rows_to_insert_into_the_db_that_has_been_processed_so_far() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processed_rows, $status->getProcessedRows()); + } + + /** + * @test + */ + public function it_sets_the_number_of_rows_to_insert_into_the_db_that_has_been_processed_so_far() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $lines = $this->faker->numberBetween(10, 200); + + $status->setProcessedRows($lines); + $this->assertEquals($lines, $status->getProcessedRows()); + } + + /** + * @test + */ + public function it_gets_the_division_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['division'], $status->getProcessingLineDivision()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineDivision()); + } + + /** + * @test + */ + public function it_sets_the_division_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $division = factory(Division::class)->make()->getName(); + + $status->setProcessingLineDivision($division); + $this->assertEquals($division, $status->getProcessingLineDivision()); + } + + /** + * @test + */ + public function it_gets_the_match_number_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['match_number'], $status->getProcessingLineMatchNumber()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineMatchNumber()); + } + + /** + * @test + */ + public function it_sets_the_match_number_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $matchNumber = $this->faker->numberBetween(1, 100); + + $status->setProcessingLineMatchNumber($matchNumber); + $this->assertEquals($matchNumber, $status->getProcessingLineMatchNumber()); + } + + /** + * @test + */ + public function it_gets_the_home_team_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['home_team'], $status->getProcessingLineHomeTeam()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineHomeTeam()); + } + + /** + * @test + */ + public function it_sets_the_home_team_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $team = factory(Team::class)->make()->getName(); + + $status->setProcessingLineHomeTeam($team); + $this->assertEquals($team, $status->getProcessingLineHomeTeam()); + } + + /** + * @test + */ + public function it_gets_the_away_team_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['away_team'], $status->getProcessingLineAwayTeam()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineAwayTeam()); + } + + /** + * @test + */ + public function it_sets_the_away_team_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $team = factory(Team::class)->make()->getName(); + + $status->setProcessingLineAwayTeam($team); + $this->assertEquals($team, $status->getProcessingLineAwayTeam()); + } + + /** + * @test + */ + public function it_gets_the_match_date_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['date'], $status->getProcessingLineDate()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineDate()); + } + + /** + * @test + */ + public function it_sets_the_match_date_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $time = Carbon::now(); + + $status->setProcessingLineDate($time->format('d/m/Y')); + $this->assertEquals($time->format('D, d/m/Y'), $status->getProcessingLineDate()); + } + + /** + * @test + */ + public function it_gets_the_warm_up_time_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['warm_up_time'], $status->getProcessingLineWarmUpTime()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineWarmUpTime()); + } + + /** + * @test + */ + public function it_sets_the_warm_up_time_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $time = Carbon::now(); + + $status->setProcessingLineWarmUpTime($time->format('H:i:s')); + $this->assertEquals($time->format('H:i'), $status->getProcessingLineWarmUpTime()); + } + + /** + * @test + */ + public function it_gets_the_start_time_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['start_time'], $status->getProcessingLineStartTime()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineStartTime()); + } + + /** + * @test + */ + public function it_sets_the_start_time_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $time = Carbon::now(); + + $status->setProcessingLineStartTime($time->format('H:i:s')); + $this->assertEquals($time->format('H:i'), $status->getProcessingLineStartTime()); + } + + /** + * @test + */ + public function it_gets_the_venue_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $this->assertEquals($status->processing_line['venue'], $status->getProcessingLineVenue()); + + $status = $this->uploadJobTestFactory(['processing_line' => []]); + $this->assertEmpty($status->getProcessingLineVenue()); + } + + /** + * @test + */ + public function it_sets_the_venue_for_the_current_line() + { + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $venue = factory(Venue::class)->make()->getName(); + + $status->setProcessingLineVenue($venue); + $this->assertEquals($venue, $status->getProcessingLineVenue()); + } /** - * @inheritDoc + * @test */ - public static function setUpBeforeClass() + public function it_can_move_forward() { - parent::setUpBeforeClass(); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertEquals(UploadJobStatus::STATUS_VALIDATING_RECORDS, $status->moveForward()->getStatusCode()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertEquals(UploadJobStatus::STATUS_INSERTING_RECORDS, $status->moveForward()->getStatusCode()); - // create a new factory muffin instance - static::$fm = new FactoryMuffin(); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertEquals(UploadJobStatus::STATUS_DONE, $status->moveForward()->getStatusCode()); - // load your model definitions - static::$fm->loadFactories(database_path() . '/muffins'); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertEquals(UploadJobStatus::STATUS_DONE, $status->moveForward()->getStatusCode()); } /** - * @inheritDoc + * @test + * @expectedException \RuntimeException */ - public static function tearDownAfterClass() + public function it_cannot_move_forward_from_unknown_data() { - static::$fm->deleteSaved(); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $status->moveForward(); + $this->expectExceptionMessage("Invalid status code " . UploadJobStatus::STATUS_UNKNOWN_DATA . "."); + } - parent::tearDownAfterClass(); + /** + * @test + * @expectedException \RuntimeException + */ + public function it_cannot_move_forward_from_an_unrecoverable_validation_error() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $status->moveForward(); + $this->expectExceptionMessage("Invalid status code " . UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR . "."); } + /** + * @test + * @expectedException \RuntimeException + */ + public function it_cannot_move_forward_from_an_unrecoverable_insert_error() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $status->moveForward(); + $this->expectExceptionMessage("Invalid status code " . UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR . "."); + } /** * @test */ - public function it_() + public function it_can_resume() { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $prevStatus = clone $status; + $status->resume(); + $this->assertEquals($prevStatus, $status); + unset($prevStatus); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $prevStatus = clone $status; + $status->resume(); + $this->assertEquals($prevStatus, $status); + unset($prevStatus); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $status->resume(); + $this->assertEquals(UploadJobStatus::STATUS_VALIDATING_RECORDS, $status->getStatusCode()); + $this->assertEmpty($status->getUnknowns()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $prevStatus = clone $status; + $status->resume(); + $this->assertEquals($prevStatus, $status); + unset($prevStatus); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $prevStatus = clone $status; + $status->resume(); + $this->assertEquals($prevStatus, $status); + unset($prevStatus); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $prevStatus = clone $status; + $status->resume(); + $this->assertEquals($prevStatus, $status); + unset($prevStatus); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $prevStatus = clone $status; + $status->resume(); + $this->assertEquals($prevStatus, $status); + unset($prevStatus); } } diff --git a/tests/integration/Models/UploadJobTest.php b/tests/integration/Models/UploadJobTest.php index 0575b965..5b6b77e9 100644 --- a/tests/integration/Models/UploadJobTest.php +++ b/tests/integration/Models/UploadJobTest.php @@ -2,34 +2,36 @@ namespace Tests\Models; -use Faker\Factory; +use Carbon\Carbon; +use LVA\Models\MappedTeam; +use LVA\Models\MappedVenue; +use LVA\Models\NewVenue; use LVA\Models\Season; +use LVA\Models\UploadJobData; use LVA\Models\UploadJobStatus; -use Tests\TestCase; use LVA\Models\UploadJob; +use Tests\Integration\IntegrationTestCase; /** * Class UploadJobTest * * @package Tests\Models */ -class UploadJobTest extends TestCase +class UploadJobTest extends IntegrationTestCase { - /** @var \Faker\Generator */ - private $faker; - - protected function setUp() - { - parent::setUp(); - $this->faker = Factory::create(); - } - /** * @test */ public function it_has_many_mapped_teams() { - $this->markTestIncomplete('Need to create the factory for the MappedTeam.'); + /** @var UploadJob[] $jobs */ + $jobs = factory(UploadJob::class)->times(2)->create(); + + $teams = mt_rand(2, 10); + factory(MappedTeam::class)->times($teams)->create(['upload_job_id' => $jobs[0]->getId()]); + + $this->assertCount($teams, $jobs[0]->mappedTeams); + $this->assertCount(0, $jobs[1]->mappedTeams); } /** @@ -37,8 +39,14 @@ public function it_has_many_mapped_teams() */ public function it_has_many_mapped_venues() { - $this->markTestIncomplete('Need to create the factory for MappedVenue.'); + /** @var UploadJob[] $jobs */ + $jobs = factory(UploadJob::class)->times(2)->create(); + $venues = mt_rand(2, 10); + factory(MappedVenue::class)->times($venues)->create(['upload_job_id' => $jobs[0]->getId()]); + + $this->assertCount($venues, $jobs[0]->mappedVenues); + $this->assertCount(0, $jobs[1]->mappedVenues); } /** @@ -46,7 +54,14 @@ public function it_has_many_mapped_venues() */ public function it_has_many_new_venues() { - $this->markTestIncomplete('Need to create the factory for NewVenue.'); + /** @var UploadJob[] $jobs */ + $jobs = factory(UploadJob::class)->times(2)->create(); + + $venues = mt_rand(2, 10); + factory(NewVenue::class)->times($venues)->create(['upload_job_id' => $jobs[0]->getId()]); + + $this->assertCount($venues, $jobs[0]->newVenues); + $this->assertCount(0, $jobs[1]->newVenues); } /** @@ -54,7 +69,14 @@ public function it_has_many_new_venues() */ public function it_has_many_data() { - $this->markTestIncomplete('Need to create the factory for UploadJobsData.'); + /** @var UploadJob[] $jobs */ + $jobs = factory(UploadJob::class)->times(2)->create(); + + $data = mt_rand(2, 10); + factory(UploadJobData::class)->times($data)->create(['upload_job_id' => $jobs[0]->getId()]); + + $this->assertCount($data, $jobs[0]->uploadData); + $this->assertCount(0, $jobs[1]->uploadData); } /** @@ -62,7 +84,12 @@ public function it_has_many_data() */ public function it_returns_stale_jobs() { - $this->markTestIncomplete(); + $staleDate = Carbon::now()->subWeek(); + + $jobs = mt_rand(2, 20); + factory(UploadJob::class)->times($jobs)->create(['created_at' => $staleDate, 'updated_at' => $staleDate]); + + $this->assertCount($jobs, UploadJob::stale()->get()); } /** @@ -125,8 +152,7 @@ public function it_gets_the_file() */ public function it_sets_the_file() { - $faker = Factory::create(); - $file = $faker->file('/', '/tmp', false); + $file = $this->faker->file('/', '/tmp', false); /** @var UploadJob $job */ $job = factory(UploadJob::class)->create(); @@ -142,7 +168,7 @@ public function it_sets_the_file() */ public function it_gets_the_job_type() { - $type = $this->faker->word; + $type = str_random(10); // DO NOT USE create() as the DB only accept 'fixture' as a type /** @var UploadJob $job */ @@ -156,7 +182,7 @@ public function it_gets_the_job_type() */ public function it_sets_the_job_type() { - $type = $this->faker->word; + $type = str_random(10); // DO NOT USE create() as the DB only accept 'fixture' as a type /** @var UploadJob $job */ @@ -173,10 +199,8 @@ public function it_sets_the_job_type() */ public function it_gets_the_status() { - $this->markTestIncomplete('To be fixed.'); - // The UploadJobStatus does not have an Eloquent model, so we cannot use create() /** @var UploadJobStatus $status */ - $status = factory(UploadJobStatus::class)->make(); + $status = $this->uploadJobTestFactory(); /** @var UploadJob $job */ $job = factory(UploadJob::class)->create(['status' => json_encode($status->toArray())]); @@ -189,10 +213,8 @@ public function it_gets_the_status() */ public function it_sets_the_status() { - $this->markTestIncomplete('To be fixed.'); - // The UploadJobStatus does not have an Eloquent model, so we cannot use create() /** @var UploadJobStatus $status */ - $status = factory(UploadJobStatus::class)->make(); + $status = $this->uploadJobTestFactory(); /** @var UploadJob $job */ $job = factory(UploadJob::class)->create(); @@ -208,14 +230,11 @@ public function it_sets_the_status() */ public function it_store_the_status_as_json() { - $this->markTestIncomplete('To be fixed.'); /** @var UploadJob $job */ $job = factory(UploadJob::class)->create(); - dd($job); $status = \DB::table($job->getTable())->where('id', $job->getId())->first(['status']); - dd($status->status); $this->assertJson($status->status); } @@ -224,6 +243,10 @@ public function it_store_the_status_as_json() */ public function it_gets_the_total_row_number() { + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $this->assertEquals($job->row_count, $job->getRowCount()); } /** @@ -231,7 +254,14 @@ public function it_gets_the_total_row_number() */ public function it_sets_the_total_row_number() { - } + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + $rows = $job->getRowCount() + mt_rand(1, 10); + $this->assertNotEquals($rows, $job->getRowCount()); + + $job->setRowCount($rows); + $this->assertEquals($rows, $job->getRowCount()); + } } diff --git a/tests/integration/Models/VenueSynonymTest.php b/tests/integration/Models/VenueSynonymTest.php index 60250960..d371029a 100644 --- a/tests/integration/Models/VenueSynonymTest.php +++ b/tests/integration/Models/VenueSynonymTest.php @@ -1,18 +1,93 @@ times(2)->create(); + + $this->assertEquals($venueSynonyms[0]->venue, VenueSynonym::findBySynonym($venueSynonyms[0]->getSynonym())); + $this->assertNull(VenueSynonym::findBySynonym($venueSynonyms[0]->getSynonym() . '---')); + $this->assertEquals($venueSynonyms[1]->venue, VenueSynonym::findBySynonym($venueSynonyms[1]->getSynonym())); + $this->assertNull(VenueSynonym::findBySynonym($venueSynonyms[1]->getSynonym() . '---'));} + + /** + * @test + */ + public function it_belongs_to_a_venue() + { + /** @var VenueSynonym $venueSynonym */ + $venueSynonym = factory(VenueSynonym::class)->create(); + + $this->assertInstanceOf(Venue::class, $venueSynonym->venue); + } + + /** + * @test + */ + public function it_gets_the_id() + { + /** @var VenueSynonym $venueSynonym */ + $venueSynonym = factory(VenueSynonym::class)->create(); + + $this->assertEquals($venueSynonym->id, $venueSynonym->getId()); + } + + /** + * @test + */ + public function it_gets_the_synonym() + { + /** @var VenueSynonym $venueSynonym */ + $venueSynonym = factory(VenueSynonym::class)->create(); + + $this->assertEquals($venueSynonym->synonym, $venueSynonym->getSynonym()); + } + + /** + * @test + */ + public function it_sets_the_synonym() + { + /** @var VenueSynonym $venueSynonym */ + $venueSynonym = factory(VenueSynonym::class)->create(); + + $this->assertEquals($venueSynonym->synonym, $venueSynonym->getSynonym()); + + $newSynonym = str_random(); + $venueSynonym->setSynonym($newSynonym); + $this->assertEquals($newSynonym, $venueSynonym->getSynonym()); + } + + /** + * @test + */ + public function it_sets_the_venue() { + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + + /** @var VenueSynonym $venueSynonym */ + $venueSynonym = factory(VenueSynonym::class)->create(); + + $this->assertNotEquals($venue->getId(), $venueSynonym->venue->getId()); + + $venueSynonym->setVenue($venue->getName()); + $this->assertEquals($venue->getId(), $venueSynonym->venue->getId()); } } diff --git a/tests/integration/Models/VenueTest.php b/tests/integration/Models/VenueTest.php index 1397d23e..698a9525 100644 --- a/tests/integration/Models/VenueTest.php +++ b/tests/integration/Models/VenueTest.php @@ -3,15 +3,17 @@ namespace Tests\Models; use LVA\Models\Fixture; -use Tests\TestCase; +use LVA\Models\MappedVenue; +use LVA\Models\VenueSynonym; use LVA\Models\Venue; +use Tests\Integration\IntegrationTestCase; /** * Class VenueTest * * @package Tests\Models */ -class VenueTest extends TestCase +class VenueTest extends IntegrationTestCase { /** * @test @@ -21,9 +23,10 @@ public function it_can_be_found_by_name() /** @var Venue[] $venues */ $venues = factory(Venue::class)->times(2)->create(); - $this->assertEquals($venues[0]->getId(), Venue::findByName($venues[0]->venue)->getId()); + // I have to use the toArray() method as I'm only interested in the table's fields and not any internal ones + $this->assertEquals($venues[0]->toArray(), Venue::findByName($venues[0]->venue)->toArray()); $this->assertNull(Venue::findByName($venues[0]->venue . '--')); - $this->assertEquals($venues[1]->getId(), Venue::findByName($venues[1]->venue)->getId()); + $this->assertEquals($venues[1]->toArray(), Venue::findByName($venues[1]->venue)->toArray()); $this->assertNull(Venue::findByName($venues[1]->venue . '--')); } @@ -50,7 +53,14 @@ public function it_has_many_fixtures() */ public function it_has_many_synonyms() { - $this->markTestIncomplete('Need to create the factory for the mapped teams.'); + /** @var Venue[] $venues */ + $venues = factory(Venue::class)->times(2)->create(); + + $synonyms = mt_rand(2,20); + factory(VenueSynonym::class)->times($synonyms)->create(['venue_id' => $venues[0]->getId()]); + + $this->assertCount($synonyms, $venues[0]->synonyms); + $this->assertCount(0, $venues[1]->synonyms); } /** @@ -58,6 +68,46 @@ public function it_has_many_synonyms() */ public function it_has_many_mapped_venues() { - $this->markTestIncomplete('Need to create the factory for the mapped teams.'); + /** @var Venue[] $venues */ + $venues = factory(Venue::class)->times(2)->create(); + + $mapped = mt_rand(2,20); + factory(MappedVenue::class)->times($mapped)->create(['venue_id' => $venues[0]->getId()]); + + $this->assertCount($mapped, $venues[0]->mapped); + $this->assertCount(0, $venues[1]->mapped); } + /** + * @test + */ + public function it_gets_the_id() + { + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + + $this->assertEquals($venue->id, $venue->getId()); + } + + /** + * @test + */ + public function it_gets_the_name() + { + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + + $this->assertEquals($venue->venue, $venue->getName()); + } + + /** + * @test + */ + public function it_is_a_string() + { + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + + $this->assertEquals($venue->venue, (string)$venue); + } + } diff --git a/tests/integration/Services/InteractiveFixturesUploadServiceTest.php b/tests/integration/Services/InteractiveFixturesUploadServiceTest.php index 722b0e07..31dc76e3 100644 --- a/tests/integration/Services/InteractiveFixturesUploadServiceTest.php +++ b/tests/integration/Services/InteractiveFixturesUploadServiceTest.php @@ -4,7 +4,6 @@ use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Http\UploadedFile; use LVA\Models\Season; use LVA\Services\InteractiveFixturesUploadService; @@ -23,5 +22,22 @@ class InteractiveFixturesUploadServiceTest extends TestCase public function it_creates_a_job() { $season = factory(Season::class)->create(); + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_can_process_a_job() + { + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_can_clean_up() + { + $this->markTestIncomplete(); } } diff --git a/tests/unit/Admin/DataManagement/AvailableAppointmentsTableTest.php b/tests/unit/Admin/DataManagement/AvailableAppointmentResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/AvailableAppointmentsTableTest.php rename to tests/unit/Admin/DataManagement/AvailableAppointmentResourceTest.php index 4600bde5..2cb1c063 100644 --- a/tests/unit/Admin/DataManagement/AvailableAppointmentsTableTest.php +++ b/tests/unit/Admin/DataManagement/AvailableAppointmentResourceTest.php @@ -13,7 +13,7 @@ use LVA\Models\Fixture; use LVA\Models\Role; -class AvailableAppointmentsTableTest extends TestCase +class AvailableAppointmentResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.available-appointments'; diff --git a/tests/unit/Admin/DataManagement/ClubsTableTest.php b/tests/unit/Admin/DataManagement/ClubResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/ClubsTableTest.php rename to tests/unit/Admin/DataManagement/ClubResourceTest.php index 633319d3..608b3bea 100644 --- a/tests/unit/Admin/DataManagement/ClubsTableTest.php +++ b/tests/unit/Admin/DataManagement/ClubResourceTest.php @@ -12,7 +12,7 @@ use Tests\TestCase; use LVA\Models\Club; -class ClubsTableTest extends TestCase +class ClubResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.clubs'; diff --git a/tests/unit/Admin/DataManagement/DivisionsTableTest.php b/tests/unit/Admin/DataManagement/DivisionResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/DivisionsTableTest.php rename to tests/unit/Admin/DataManagement/DivisionResourceTest.php index a3af0dde..9518570c 100644 --- a/tests/unit/Admin/DataManagement/DivisionsTableTest.php +++ b/tests/unit/Admin/DataManagement/DivisionResourceTest.php @@ -13,7 +13,7 @@ use LVA\Models\Division; use LVA\Models\Season; -class DivisionsTableTest extends TestCase +class DivisionResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.divisions'; diff --git a/tests/unit/Admin/DataManagement/FixturesTableTest.php b/tests/unit/Admin/DataManagement/FixtureResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/FixturesTableTest.php rename to tests/unit/Admin/DataManagement/FixtureResourceTest.php index 84546cca..ca762695 100644 --- a/tests/unit/Admin/DataManagement/FixturesTableTest.php +++ b/tests/unit/Admin/DataManagement/FixtureResourceTest.php @@ -12,7 +12,7 @@ use Tests\TestCase; use LVA\Models\Fixture; -class FixturesTableTest extends TestCase +class FixtureResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.fixtures'; diff --git a/tests/unit/Admin/DataManagement/RolesTableTest.php b/tests/unit/Admin/DataManagement/RoleResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/RolesTableTest.php rename to tests/unit/Admin/DataManagement/RoleResourceTest.php index 015ca1d5..93973989 100644 --- a/tests/unit/Admin/DataManagement/RolesTableTest.php +++ b/tests/unit/Admin/DataManagement/RoleResourceTest.php @@ -12,7 +12,7 @@ use Tests\TestCase; use LVA\Models\Role; -class RolesTableTest extends TestCase +class RoleResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.roles'; diff --git a/tests/unit/Admin/DataManagement/SeasonsTableTest.php b/tests/unit/Admin/DataManagement/SeasonResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/SeasonsTableTest.php rename to tests/unit/Admin/DataManagement/SeasonResourceTest.php index c85b294f..8750d2aa 100644 --- a/tests/unit/Admin/DataManagement/SeasonsTableTest.php +++ b/tests/unit/Admin/DataManagement/SeasonResourceTest.php @@ -13,7 +13,7 @@ use Tests\TestCase; use LVA\Models\Season; -class SeasonsTableTest extends TestCase +class SeasonResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.seasons'; diff --git a/tests/unit/Admin/DataManagement/TeamsTableTest.php b/tests/unit/Admin/DataManagement/TeamResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/TeamsTableTest.php rename to tests/unit/Admin/DataManagement/TeamResourceTest.php index b6df1424..fc384a5e 100644 --- a/tests/unit/Admin/DataManagement/TeamsTableTest.php +++ b/tests/unit/Admin/DataManagement/TeamResourceTest.php @@ -13,7 +13,7 @@ use LVA\Models\Team; use LVA\Models\Club; -class TeamsTableTest extends TestCase +class TeamResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.teams'; diff --git a/tests/unit/Admin/DataManagement/VenuesTableTest.php b/tests/unit/Admin/DataManagement/VenueResourceTest.php similarity index 99% rename from tests/unit/Admin/DataManagement/VenuesTableTest.php rename to tests/unit/Admin/DataManagement/VenueResourceTest.php index f4fc912f..4b4c40f9 100644 --- a/tests/unit/Admin/DataManagement/VenuesTableTest.php +++ b/tests/unit/Admin/DataManagement/VenueResourceTest.php @@ -12,7 +12,7 @@ use Tests\TestCase; use LVA\Models\Venue; -class VenuesTableTest extends TestCase +class VenueResourceTest extends TestCase { const BASE_ROUTE = 'admin.data-management.venues'; diff --git a/tests/unit/Api/v1/UploadApiTest.php b/tests/unit/Api/v1/UploadApiTest.php new file mode 100644 index 00000000..aee4a3ed --- /dev/null +++ b/tests/unit/Api/v1/UploadApiTest.php @@ -0,0 +1,58 @@ +markTestIncomplete(); + } + + /** + * @test + */ + public function it_gets_the_job_status() + { + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_maps_a_team() + { + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_maps_a_venue() + { + $this->markTestIncomplete(); + } + + /** + * @test + */ + public function it_adds_a_venue() + { + $this->markTestIncomplete(); + } +} From 3dd6c53f3b0ca28d6827d6bec15685368f9deb3c Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Wed, 15 Mar 2017 17:16:01 +0000 Subject: [PATCH 50/62] dev: updated composer packages --- composer.lock | 74 +++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/composer.lock b/composer.lock index 788e4163..97477a27 100644 --- a/composer.lock +++ b/composer.lock @@ -666,16 +666,16 @@ }, { "name": "monolog/monolog", - "version": "1.22.0", + "version": "1.22.1", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "bad29cb8d18ab0315e6c477751418a82c850d558" + "reference": "1e044bc4b34e91743943479f1be7a1d5eb93add0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bad29cb8d18ab0315e6c477751418a82c850d558", - "reference": "bad29cb8d18ab0315e6c477751418a82c850d558", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/1e044bc4b34e91743943479f1be7a1d5eb93add0", + "reference": "1e044bc4b34e91743943479f1be7a1d5eb93add0", "shasum": "" }, "require": { @@ -740,7 +740,7 @@ "logging", "psr-3" ], - "time": "2016-11-26T00:15:39+00:00" + "time": "2017-03-13T07:08:03+00:00" }, { "name": "mtdowling/cron-expression", @@ -892,16 +892,16 @@ }, { "name": "paragonie/random_compat", - "version": "v1.4.1", + "version": "v1.4.2", "source": { "type": "git", "url": "https://github.com/paragonie/random_compat.git", - "reference": "c7e26a21ba357863de030f0b9e701c7d04593774" + "reference": "965cdeb01fdcab7653253aa81d40441d261f1e66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/c7e26a21ba357863de030f0b9e701c7d04593774", - "reference": "c7e26a21ba357863de030f0b9e701c7d04593774", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/965cdeb01fdcab7653253aa81d40441d261f1e66", + "reference": "965cdeb01fdcab7653253aa81d40441d261f1e66", "shasum": "" }, "require": { @@ -936,7 +936,7 @@ "pseudorandom", "random" ], - "time": "2016-03-18T20:34:03+00:00" + "time": "2017-03-13T16:22:52+00:00" }, { "name": "psr/log", @@ -1230,16 +1230,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v3.2.4", + "version": "v3.2.6", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "9137eb3a3328e413212826d63eeeb0217836e2b6" + "reference": "b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9137eb3a3328e413212826d63eeeb0217836e2b6", - "reference": "9137eb3a3328e413212826d63eeeb0217836e2b6", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d", + "reference": "b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d", "shasum": "" }, "require": { @@ -1286,7 +1286,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-01-02T20:32:22+00:00" + "time": "2017-02-21T09:12:04+00:00" }, { "name": "symfony/finder", @@ -3348,23 +3348,23 @@ }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe" + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c36f5e7cfce482fde5bf8d10d41a53591e0198fe", - "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", "shasum": "" }, "require": { - "php": ">=5.6" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^5.7 || ^6.0" }, "type": "library", "extra": { @@ -3389,7 +3389,7 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2016-02-13T06:45:14+00:00" + "time": "2017-03-04T06:30:41+00:00" }, { "name": "sebastian/comparator", @@ -3677,16 +3677,16 @@ }, { "name": "sebastian/recursion-context", - "version": "1.0.2", + "version": "1.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791" + "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b19cc3298482a335a95f3016d2f8a6950f0fbcd7", + "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7", "shasum": "" }, "require": { @@ -3726,7 +3726,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11T19:50:13+00:00" + "time": "2016-10-03T07:41:43+00:00" }, { "name": "sebastian/resource-operations", @@ -3815,16 +3815,16 @@ }, { "name": "symfony/class-loader", - "version": "v3.2.4", + "version": "v3.2.6", "source": { "type": "git", "url": "https://github.com/symfony/class-loader.git", - "reference": "2847d56f518ad5721bf85aa9174b3aa3fd12aa03" + "reference": "c29a5bc6ca14cfff1f5e3d7781ed74b6e898d2b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/class-loader/zipball/2847d56f518ad5721bf85aa9174b3aa3fd12aa03", - "reference": "2847d56f518ad5721bf85aa9174b3aa3fd12aa03", + "url": "https://api.github.com/repos/symfony/class-loader/zipball/c29a5bc6ca14cfff1f5e3d7781ed74b6e898d2b9", + "reference": "c29a5bc6ca14cfff1f5e3d7781ed74b6e898d2b9", "shasum": "" }, "require": { @@ -3867,7 +3867,7 @@ ], "description": "Symfony ClassLoader Component", "homepage": "https://symfony.com", - "time": "2017-01-21T17:06:35+00:00" + "time": "2017-02-18T17:28:00+00:00" }, { "name": "symfony/css-selector", @@ -3980,16 +3980,16 @@ }, { "name": "symfony/yaml", - "version": "v3.2.4", + "version": "v3.2.6", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8" + "reference": "093e416ad096355149e265ea2e4cc1f9ee40ab1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/9724c684646fcb5387d579b4bfaa63ee0b0c64c8", - "reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8", + "url": "https://api.github.com/repos/symfony/yaml/zipball/093e416ad096355149e265ea2e4cc1f9ee40ab1a", + "reference": "093e416ad096355149e265ea2e4cc1f9ee40ab1a", "shasum": "" }, "require": { @@ -4031,7 +4031,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-02-16T22:46:52+00:00" + "time": "2017-03-07T16:47:02+00:00" }, { "name": "webmozart/assert", From 5877eb97a0866dee6eeb77fcd1f1e3998e7d05b6 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Thu, 16 Mar 2017 12:47:34 +0000 Subject: [PATCH 51/62] dev: refactored the forms out fo the create and edit views for more reusability --- .../available-appointments/_form.blade.php | 21 ++++++ .../available-appointments/create.blade.php | 24 +------ .../available-appointments/edit.blade.php | 24 +------ .../data-management/clubs/_form.blade.php | 13 ++++ .../data-management/clubs/create.blade.php | 14 +--- .../data-management/clubs/edit.blade.php | 15 +--- .../data-management/divisions/_form.blade.php | 21 ++++++ .../divisions/create.blade.php | 22 +----- .../data-management/divisions/edit.blade.php | 23 +----- .../data-management/fixtures/_form.blade.php | 69 ++++++++++++++++++ .../data-management/fixtures/create.blade.php | 70 +----------------- .../data-management/fixtures/edit.blade.php | 71 +------------------ .../data-management/roles/_form.blade.php | 13 ++++ .../data-management/roles/create.blade.php | 14 +--- .../data-management/roles/edit.blade.php | 15 +--- .../data-management/seasons/_form.blade.php | 13 ++++ .../data-management/seasons/create.blade.php | 14 +--- .../data-management/seasons/edit.blade.php | 15 +--- .../data-management/teams/_form.blade.php | 21 ++++++ .../data-management/teams/create.blade.php | 22 +----- .../data-management/teams/edit.blade.php | 23 +----- .../data-management/venues/_form.blade.php | 13 ++++ .../data-management/venues/create.blade.php | 14 +--- .../data-management/venues/edit.blade.php | 15 +--- 24 files changed, 202 insertions(+), 377 deletions(-) create mode 100644 resources/views/admin/data-management/available-appointments/_form.blade.php create mode 100644 resources/views/admin/data-management/clubs/_form.blade.php create mode 100644 resources/views/admin/data-management/divisions/_form.blade.php create mode 100644 resources/views/admin/data-management/fixtures/_form.blade.php create mode 100644 resources/views/admin/data-management/roles/_form.blade.php create mode 100644 resources/views/admin/data-management/seasons/_form.blade.php create mode 100644 resources/views/admin/data-management/teams/_form.blade.php create mode 100644 resources/views/admin/data-management/venues/_form.blade.php diff --git a/resources/views/admin/data-management/available-appointments/_form.blade.php b/resources/views/admin/data-management/available-appointments/_form.blade.php new file mode 100644 index 00000000..6469970e --- /dev/null +++ b/resources/views/admin/data-management/available-appointments/_form.blade.php @@ -0,0 +1,21 @@ +
    + {!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('fixture_id', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('role_id', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/create.blade.php b/resources/views/admin/data-management/available-appointments/create.blade.php index 4d1f573a..10d2fe13 100644 --- a/resources/views/admin/data-management/available-appointments/create.blade.php +++ b/resources/views/admin/data-management/available-appointments/create.blade.php @@ -14,29 +14,9 @@ @include('_partial.crud-errors') - {!! Form::open(['url' => 'admin/data-management/available-appointments', 'class' => 'form-horizontal']) !!} + {!! Form::open(['route' => 'admin.data-management.available-appointments.store', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('fixture_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('role_id', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.available-appointments._form', ['submitText' => 'Add']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/available-appointments/edit.blade.php b/resources/views/admin/data-management/available-appointments/edit.blade.php index 8d28c740..f60fbca4 100644 --- a/resources/views/admin/data-management/available-appointments/edit.blade.php +++ b/resources/views/admin/data-management/available-appointments/edit.blade.php @@ -17,32 +17,12 @@ {!! Form::model($availableAppointment, [ 'method' => 'PATCH', - 'url' => ['admin/data-management/available-appointments', $availableAppointment->id], + 'route' => ['admin.data-management.available-appointments.update', $availableAppointment->id], 'class' => 'form-horizontal' ]) !!} {!! Form::hidden('id', $availableAppointment->id) !!} -
    - {!! Form::label('fixture_id', 'Fixture: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('fixture_id', $fixturesSelect, null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('fixture_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('role_id', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('role_id', array_column($roles->toArray(), 'role', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('role_id', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.available-appointments._form', ['submitText' => 'Update']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/clubs/_form.blade.php b/resources/views/admin/data-management/clubs/_form.blade.php new file mode 100644 index 00000000..4dbf9f66 --- /dev/null +++ b/resources/views/admin/data-management/clubs/_form.blade.php @@ -0,0 +1,13 @@ +
    + {!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::text('club', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} + {!! $errors->first('club', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    \ No newline at end of file diff --git a/resources/views/admin/data-management/clubs/create.blade.php b/resources/views/admin/data-management/clubs/create.blade.php index ce0b98d0..1b990412 100644 --- a/resources/views/admin/data-management/clubs/create.blade.php +++ b/resources/views/admin/data-management/clubs/create.blade.php @@ -10,19 +10,7 @@ {!! Form::open(['url' => 'admin/data-management/clubs', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('club', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('club', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.clubs._form', ['submitText' => 'Add']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index fe50e8d1..c580bfef 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -13,21 +13,8 @@ 'url' => ['admin/data-management/clubs', $club->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $club->id) !!} -
    - {!! Form::label('club', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('club', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('club', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.clubs._form', ['submitText' => 'Update']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/divisions/_form.blade.php b/resources/views/admin/data-management/divisions/_form.blade.php new file mode 100644 index 00000000..57ddb175 --- /dev/null +++ b/resources/views/admin/data-management/divisions/_form.blade.php @@ -0,0 +1,21 @@ +
    + {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} + {!! $errors->first('season_id', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::text('division', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} + {!! $errors->first('division', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/create.blade.php b/resources/views/admin/data-management/divisions/create.blade.php index aeaeb42e..2e6d3657 100644 --- a/resources/views/admin/data-management/divisions/create.blade.php +++ b/resources/views/admin/data-management/divisions/create.blade.php @@ -10,27 +10,7 @@ {!! Form::open(['url' => 'admin/data-management/divisions', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), null, ['class' => 'form-control']) !!} - {!! $errors->first('season_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('division', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('division', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.divisions._form', ['submitText' => 'Add']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index 359ea86a..b4f41fd4 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -13,29 +13,8 @@ 'url' => ['admin/data-management/divisions', $division->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $division->id) !!} -
    - {!! Form::label('season_id', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('season_id', array_column($seasons->toArray(), 'season', 'id'), $division->season->id, ['class' => 'form-control']) !!} - {!! $errors->first('season_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('division', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('division', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('division', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.divisions._form', ['submitText' => 'Update']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/fixtures/_form.blade.php b/resources/views/admin/data-management/fixtures/_form.blade.php new file mode 100644 index 00000000..929f11e8 --- /dev/null +++ b/resources/views/admin/data-management/fixtures/_form.blade.php @@ -0,0 +1,69 @@ +
    + {!! Form::label('division_id', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('division_id', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} + {!! $errors->first('match_number', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('match_date', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('warm_up_time', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('start_time', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('home_team_id', 'Home Team: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('home_team_id', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('away_team_id', 'Away Team: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('away_team_id', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('venue_id', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} + {!! $errors->first('venue_id', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    diff --git a/resources/views/admin/data-management/fixtures/create.blade.php b/resources/views/admin/data-management/fixtures/create.blade.php index e824acc3..fb3ee8db 100644 --- a/resources/views/admin/data-management/fixtures/create.blade.php +++ b/resources/views/admin/data-management/fixtures/create.blade.php @@ -10,75 +10,7 @@ {!! Form::open(['url' => 'admin/data-management/fixtures', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('division_id', 'Division: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('division_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('match_number', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::date('match_date', null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('match_date', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::input('time', 'warm_up_time', null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('warm_up_time', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::input('time', 'start_time', null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('start_time', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('home_team_id', 'Home Team: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('home_team_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('away_team_id', 'Away Team: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('away_team_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('venue_id', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('venue_id', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.fixtures._form', ['submitText' => 'Add']) {!! Form::close() !!}

    diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index ae4527ad..e36572e2 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -13,77 +13,8 @@ 'url' => ['admin/data-management/fixtures', $fixture->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $fixture->id) !!} -
    - {!! Form::label('division_id', 'Division Id: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('division_id', array_column($divisions->toArray(), 'division', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('division_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('match_number', 'Match Number: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::number('match_number', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('match_number', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('match_date', 'Match Date: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::date('match_date', $fixture->match_date->format('Y-m-d'), ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('match_date', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('warm_up_time', 'Warm Up Time: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::input('time', 'warm_up_time', $fixture->warm_up_time->format('H:i'), ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('warm_up_time', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('start_time', 'Start Time: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::input('time', 'start_time', $fixture->start_time->format('H:i'), ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('start_time', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('home_team_id', 'Home Team Id: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('home_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('home_team_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('away_team_id', 'Away Team Id: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('away_team_id', array_column($teams->toArray(), 'team', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('away_team_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('venue_id', 'Venue Id: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('venue_id', array_column($venues->toArray(), 'venue', 'id'), null, ['class' => 'form-control', 'required' => true]) !!} - {!! $errors->first('venue_id', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.fixtures._form', ['submitText' => 'Update']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/roles/_form.blade.php b/resources/views/admin/data-management/roles/_form.blade.php new file mode 100644 index 00000000..cebca978 --- /dev/null +++ b/resources/views/admin/data-management/roles/_form.blade.php @@ -0,0 +1,13 @@ +
    + {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::text('role', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} + {!! $errors->first('role', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/create.blade.php b/resources/views/admin/data-management/roles/create.blade.php index cd148c3c..4cea376d 100644 --- a/resources/views/admin/data-management/roles/create.blade.php +++ b/resources/views/admin/data-management/roles/create.blade.php @@ -10,19 +10,7 @@ {!! Form::open(['url' => 'admin/data-management/roles', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('role', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('role', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.roles._form', ['submitText' => 'Add']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index a37042d6..fb7b7fc0 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -13,21 +13,8 @@ 'url' => ['admin/data-management/roles', $role->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $role->id) !!} -
    - {!! Form::label('role', 'Role: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('role', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('role', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.roles._form', ['submitText' => 'Update']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/seasons/_form.blade.php b/resources/views/admin/data-management/seasons/_form.blade.php new file mode 100644 index 00000000..9e945564 --- /dev/null +++ b/resources/views/admin/data-management/seasons/_form.blade.php @@ -0,0 +1,13 @@ +
    + {!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::text('season', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} + {!! $errors->first('season', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    \ No newline at end of file diff --git a/resources/views/admin/data-management/seasons/create.blade.php b/resources/views/admin/data-management/seasons/create.blade.php index 07f4a537..36cb8221 100644 --- a/resources/views/admin/data-management/seasons/create.blade.php +++ b/resources/views/admin/data-management/seasons/create.blade.php @@ -10,19 +10,7 @@ {!! Form::open(['url' => 'admin/data-management/seasons', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('season', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('season', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.seasons._form', ['submitText' => 'Add']) {!! Form::close() !!}

    diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index 397d32d5..06d1da02 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -13,21 +13,8 @@ 'url' => ['admin/data-management/seasons', $season->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $season->id) !!} -
    - {!! Form::label('season', 'Season: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('season', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('season', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.seasons._form', ['submitText' => 'Update']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/teams/_form.blade.php b/resources/views/admin/data-management/teams/_form.blade.php new file mode 100644 index 00000000..6f2019f1 --- /dev/null +++ b/resources/views/admin/data-management/teams/_form.blade.php @@ -0,0 +1,21 @@ +
    + {!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control']) !!} + {!! $errors->first('club_id', '

    :message

    ') !!} +
    +
    + +
    + {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::text('team', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} + {!! $errors->first('team', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/create.blade.php b/resources/views/admin/data-management/teams/create.blade.php index 4da246ae..e729f3cc 100644 --- a/resources/views/admin/data-management/teams/create.blade.php +++ b/resources/views/admin/data-management/teams/create.blade.php @@ -10,27 +10,7 @@ {!! Form::open(['url' => 'admin/data-management/teams', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('club_id', 'Club: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), null, ['class' => 'form-control']) !!} - {!! $errors->first('club_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('team', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('team', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.teams._form', ['submitText' => 'Add']) {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index 549e624c..6d5d4702 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -13,29 +13,8 @@ 'url' => ['admin/data-management/teams', $team->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $team->id) !!} -
    - {!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control']) !!} - {!! $errors->first('club_id', '

    :message

    ') !!} -
    -
    - -
    - {!! Form::label('team', 'Team: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('team', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('team', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.teams._form', ['submitText' => 'Update']) {!! Form::close() !!}

    diff --git a/resources/views/admin/data-management/venues/_form.blade.php b/resources/views/admin/data-management/venues/_form.blade.php new file mode 100644 index 00000000..d2ad3dc0 --- /dev/null +++ b/resources/views/admin/data-management/venues/_form.blade.php @@ -0,0 +1,13 @@ +
    + {!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} +
    + {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} + {!! $errors->first('venue', '

    :message

    ') !!} +
    +
    + +
    +
    + {!! Form::submit($submitText, ['class' => 'btn btn-primary form-control']) !!} +
    +
    diff --git a/resources/views/admin/data-management/venues/create.blade.php b/resources/views/admin/data-management/venues/create.blade.php index 44a0944a..80399790 100644 --- a/resources/views/admin/data-management/venues/create.blade.php +++ b/resources/views/admin/data-management/venues/create.blade.php @@ -10,19 +10,7 @@ {!! Form::open(['url' => 'admin/data-management/venues', 'class' => 'form-horizontal']) !!} -
    - {!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('venue', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.venues._form', ['submitText' => 'Add']); {!! Form::close() !!}
    diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index b9ac2863..ef0582a9 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -13,21 +13,8 @@ 'url' => ['admin/data-management/venues', $venue->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $venue->id) !!} -
    - {!! Form::label('venue', 'Venue: ', ['class' => 'col-sm-3 control-label']) !!} -
    - {!! Form::text('venue', null, ['class' => 'form-control', 'required' => true, 'autofocus' => true]) !!} - {!! $errors->first('venue', '

    :message

    ') !!} -
    -
    - -
    -
    - {!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!} -
    -
    + @include('admin.data-management.venues._form', ['submitText' => 'Update']); {!! Form::close() !!}
    From 6b3eff8664d42d8084a0e697542f4657509d06ed Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Thu, 16 Mar 2017 12:48:11 +0000 Subject: [PATCH 52/62] dev: fixed the missing boostrap-confirmation script --- public/libraries/bootstrap-confirmation.2.4.0.min.js | 7 +++++++ .../data-management/available-appointments/index.blade.php | 4 ++-- .../views/admin/data-management/clubs/index.blade.php | 4 ++-- .../views/admin/data-management/divisions/index.blade.php | 4 ++-- .../views/admin/data-management/fixtures/index.blade.php | 4 ++-- .../views/admin/data-management/roles/index.blade.php | 4 ++-- .../views/admin/data-management/seasons/index.blade.php | 4 ++-- .../views/admin/data-management/teams/index.blade.php | 4 ++-- .../views/admin/data-management/venues/index.blade.php | 4 ++-- 9 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 public/libraries/bootstrap-confirmation.2.4.0.min.js diff --git a/public/libraries/bootstrap-confirmation.2.4.0.min.js b/public/libraries/bootstrap-confirmation.2.4.0.min.js new file mode 100644 index 00000000..45755b6b --- /dev/null +++ b/public/libraries/bootstrap-confirmation.2.4.0.min.js @@ -0,0 +1,7 @@ +/*! + * Bootstrap Confirmation 2.4.0 + * Copyright 2013 Nimit Suwannagate + * Copyright 2014-2016 Damien "Mistic" Sorel + * Licensed under the Apache License, Version 2.0 + */ +!function($){"use strict";function a(a){for(var b=window,c=a.split("."),d=c.pop(),e=0,f=c.length;e

    '}),c.prototype=$.extend({},$.fn.popover.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.init=function(a,b){if($.fn.popover.Constructor.prototype.init.call(this,"confirmation",a,b),(this.options.popout||this.options.singleton)&&!b.rootSelector)throw new Error("The rootSelector option is required to use popout and singleton features since jQuery 3.");this.options._isDelegate=!1,b.selector?this.options._selector=this._options._selector=b.rootSelector+" "+b.selector:b._selector?(this.options._selector=b._selector,this.options._isDelegate=!0):this.options._selector=b.rootSelector;var c=this;this.options.selector?this.$element.on(this.options.trigger,this.options.selector,function(a,b){b||(a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation())}):(this.options._attributes={},this.options.copyAttributes?"string"==typeof this.options.copyAttributes&&(this.options.copyAttributes=this.options.copyAttributes.split(" ")):this.options.copyAttributes=[],this.options.copyAttributes.forEach(function(a){this.options._attributes[a]=this.$element.attr(a)},this),this.$element.on(this.options.trigger,function(a,b){b||(a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation())}),this.$element.on("show.bs.confirmation",function(a){c.options.singleton&&$(c.options._selector).not($(this)).filter(function(){return void 0!==$(this).data("bs.confirmation")}).confirmation("hide")})),this.options._isDelegate||(this.eventBody=!1,this.uid=this.$element[0].id||this.getUID("group_"),this.$element.on("shown.bs.confirmation",function(a){c.options.popout&&!c.eventBody&&(c.eventBody=$("body").on("click.bs.confirmation."+c.uid,function(a){$(c.options._selector).is(a.target)||($(c.options._selector).filter(function(){return void 0!==$(this).data("bs.confirmation")}).confirmation("hide"),$("body").off("click.bs."+c.uid),c.eventBody=!1)}))}))},c.prototype.hasContent=function(){return!0},c.prototype.setContent=function(){var a=this,c=this.tip(),d=this.getTitle(),e=this.getContent();if(c.find(".popover-title")[this.options.html?"html":"text"](d),c.find(".confirmation-content").toggle(!!e).children().detach().end()[this.options.html?"string"==typeof e?"html":"append":"text"](e),c.on("click",function(a){a.stopPropagation()}),this.options.buttons){var f=c.find(".confirmation-buttons .btn-group").empty();this.options.buttons.forEach(function(b){f.append($('').addClass(b["class"]||"btn btn-xs btn-default").html(b.label||"").attr(b.attr||{}).prepend($("").addClass(b.icon)," ").one("click",function(c){"#"===$(this).attr("href")&&c.preventDefault(),b.onClick&&b.onClick.call(a.$element),b.cancel?(a.getOnCancel.call(a).call(a.$element),a.$element.trigger("canceled.bs.confirmation")):(a.getOnConfirm.call(a).call(a.$element),a.$element.trigger("confirmed.bs.confirmation")),a.inState&&(a.inState.click=!1),a.hide()}))},this)}else c.find('[data-apply="confirmation"]').addClass(this.options.btnOkClass).html(this.options.btnOkLabel).attr(this.options._attributes).prepend($("").addClass(this.options.btnOkIcon)," ").off("click").one("click",function(b){"#"===$(this).attr("href")&&b.preventDefault(),a.getOnConfirm.call(a).call(a.$element),a.$element.trigger("confirmed.bs.confirmation"),a.$element.trigger(a.options.trigger,[!0]),a.hide()}),c.find('[data-dismiss="confirmation"]').addClass(this.options.btnCancelClass).html(this.options.btnCancelLabel).prepend($("").addClass(this.options.btnCancelIcon)," ").off("click").one("click",function(b){b.preventDefault(),a.getOnCancel.call(a).call(a.$element),a.$element.trigger("canceled.bs.confirmation"),a.inState&&(a.inState.click=!1),a.hide()});c.removeClass("fade top bottom left right in"),c.find(".popover-title").html()||c.find(".popover-title").hide(),b=this,$(window).off("keyup.bs.confirmation").on("keyup.bs.confirmation",this._onKeyup.bind(this))},c.prototype.destroy=function(){b===this&&(b=void 0,$(window).off("keyup.bs.confirmation")),$.fn.popover.Constructor.prototype.destroy.call(this)},c.prototype.hide=function(){b===this&&(b=void 0,$(window).off("keyup.bs.confirmation")),$.fn.popover.Constructor.prototype.hide.call(this)},c.prototype._onKeyup=function(a){if(!this.$tip)return b=void 0,void $(window).off("keyup.bs.confirmation");var d,e=a.key||c.KEYMAP[a.keyCode||a.which],f=this.$tip.find(".confirmation-buttons .btn-group"),g=f.find(".active");switch(e){case"Escape":this.hide();break;case"ArrowRight":d=g.length&&g.next().length?g.next():f.children().first(),g.removeClass("active"),d.addClass("active").focus();break;case"ArrowLeft":d=g.length&&g.prev().length?g.prev():f.children().last(),g.removeClass("active"),d.addClass("active").focus()}},c.prototype.getOnConfirm=function(){return this.$element.attr("data-on-confirm")?a(this.$element.attr("data-on-confirm")):this.options.onConfirm},c.prototype.getOnCancel=function(){return this.$element.attr("data-on-cancel")?a(this.$element.attr("data-on-cancel")):this.options.onCancel};var d=$.fn.confirmation;$.fn.confirmation=function(a){var b="object"==typeof a&&a||{};return b.rootSelector=this.selector||b.rootSelector,this.each(function(){var d=$(this),e=d.data("bs.confirmation");(e||"destroy"!=a)&&(e||d.data("bs.confirmation",e=new c(this,b)),"string"==typeof a&&(e[a](),"hide"==a&&e.inState&&(e.inState.click=!1)))})},$.fn.confirmation.Constructor=c,$.fn.confirmation.noConflict=function(){return $.fn.confirmation=d,this}}(jQuery); \ No newline at end of file diff --git a/resources/views/admin/data-management/available-appointments/index.blade.php b/resources/views/admin/data-management/available-appointments/index.blade.php index 2da6580c..4a538c8d 100644 --- a/resources/views/admin/data-management/available-appointments/index.blade.php +++ b/resources/views/admin/data-management/available-appointments/index.blade.php @@ -26,7 +26,7 @@ class="btn btn-primary pull-right btn-sm">New appointment

    - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/available-appointments', $appointment->id], @@ -46,6 +46,6 @@ class="btn btn-primary pull-right btn-sm">New appointment

    @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/clubs/index.blade.php b/resources/views/admin/data-management/clubs/index.blade.php index 9146ed70..c0c1d77b 100644 --- a/resources/views/admin/data-management/clubs/index.blade.php +++ b/resources/views/admin/data-management/clubs/index.blade.php @@ -20,7 +20,7 @@ - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/clubs', $club->id], @@ -40,6 +40,6 @@ @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/divisions/index.blade.php b/resources/views/admin/data-management/divisions/index.blade.php index f7dbbcbf..25ca41c9 100644 --- a/resources/views/admin/data-management/divisions/index.blade.php +++ b/resources/views/admin/data-management/divisions/index.blade.php @@ -24,7 +24,7 @@ class="btn btn-primary pull-right btn-sm">New division - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/divisions', $division->id], @@ -44,6 +44,6 @@ class="btn btn-primary pull-right btn-sm">New division @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/fixtures/index.blade.php b/resources/views/admin/data-management/fixtures/index.blade.php index 6c6b86ff..ad58ba0b 100644 --- a/resources/views/admin/data-management/fixtures/index.blade.php +++ b/resources/views/admin/data-management/fixtures/index.blade.php @@ -36,7 +36,7 @@ class="btn btn-primary pull-right btn-sm">New fixture - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/fixtures', $fixture->id], @@ -56,6 +56,6 @@ class="btn btn-primary pull-right btn-sm">New fixture @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/roles/index.blade.php b/resources/views/admin/data-management/roles/index.blade.php index a5940d0e..0497000d 100644 --- a/resources/views/admin/data-management/roles/index.blade.php +++ b/resources/views/admin/data-management/roles/index.blade.php @@ -20,7 +20,7 @@ - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/roles', $role->id], @@ -40,6 +40,6 @@ @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/seasons/index.blade.php b/resources/views/admin/data-management/seasons/index.blade.php index bdde1f7a..ac50aaed 100644 --- a/resources/views/admin/data-management/seasons/index.blade.php +++ b/resources/views/admin/data-management/seasons/index.blade.php @@ -19,7 +19,7 @@ - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/seasons', $season->id], @@ -39,6 +39,6 @@ @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/teams/index.blade.php b/resources/views/admin/data-management/teams/index.blade.php index 4a0bf1be..763b59fc 100644 --- a/resources/views/admin/data-management/teams/index.blade.php +++ b/resources/views/admin/data-management/teams/index.blade.php @@ -22,7 +22,7 @@ - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/teams', $team->id], @@ -42,6 +42,6 @@ @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/resources/views/admin/data-management/venues/index.blade.php b/resources/views/admin/data-management/venues/index.blade.php index 6d8ae34e..d51bb656 100644 --- a/resources/views/admin/data-management/venues/index.blade.php +++ b/resources/views/admin/data-management/venues/index.blade.php @@ -20,7 +20,7 @@ - / + {!! Form::open([ 'method'=>'DELETE', 'url' => ['admin/data-management/venues', $venue->id], @@ -40,6 +40,6 @@ @endsection @section('javascript') - + @endsection \ No newline at end of file From 1bbebd5145ff67c82ead5233977a50c639079169 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Thu, 16 Mar 2017 13:00:12 +0000 Subject: [PATCH 53/62] dev: fixed after test failures after last commit --- resources/views/admin/data-management/clubs/edit.blade.php | 1 + resources/views/admin/data-management/divisions/edit.blade.php | 1 + resources/views/admin/data-management/fixtures/edit.blade.php | 1 + resources/views/admin/data-management/roles/edit.blade.php | 1 + resources/views/admin/data-management/seasons/edit.blade.php | 1 + resources/views/admin/data-management/teams/_form.blade.php | 2 +- resources/views/admin/data-management/teams/edit.blade.php | 1 + resources/views/admin/data-management/venues/edit.blade.php | 1 + 8 files changed, 8 insertions(+), 1 deletion(-) diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index c580bfef..838dc2de 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/clubs', $club->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $club->id) !!} @include('admin.data-management.clubs._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index b4f41fd4..e022bd68 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/divisions', $division->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $division->id) !!} @include('admin.data-management.divisions._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/fixtures/edit.blade.php b/resources/views/admin/data-management/fixtures/edit.blade.php index e36572e2..a3a474b7 100644 --- a/resources/views/admin/data-management/fixtures/edit.blade.php +++ b/resources/views/admin/data-management/fixtures/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/fixtures', $fixture->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $fixture->id) !!} @include('admin.data-management.fixtures._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index fb7b7fc0..8ca0524d 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/roles', $role->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $role->id) !!} @include('admin.data-management.roles._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index 06d1da02..c15e29b8 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/seasons', $season->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $season->id) !!} @include('admin.data-management.seasons._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/teams/_form.blade.php b/resources/views/admin/data-management/teams/_form.blade.php index 6f2019f1..8edb64c1 100644 --- a/resources/views/admin/data-management/teams/_form.blade.php +++ b/resources/views/admin/data-management/teams/_form.blade.php @@ -1,7 +1,7 @@
    {!! Form::label('club_id', 'Club Id: ', ['class' => 'col-sm-3 control-label']) !!}
    - {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), $team->club->id, ['class' => 'form-control']) !!} + {!! Form::select('club_id', array_column($clubs->toArray(), 'club', 'id'), null, ['class' => 'form-control']) !!} {!! $errors->first('club_id', '

    :message

    ') !!}
    diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index 6d5d4702..58a659b5 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/teams', $team->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $team->id) !!} @include('admin.data-management.teams._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index ef0582a9..d15ffffd 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -13,6 +13,7 @@ 'url' => ['admin/data-management/venues', $venue->id], 'class' => 'form-horizontal' ]) !!} + {!! Form::hidden('id', $venue->id) !!} @include('admin.data-management.venues._form', ['submitText' => 'Update']); From be232c24d7c02779c75769fc0e1e3d0deee78711 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Thu, 16 Mar 2017 17:18:38 +0000 Subject: [PATCH 54/62] dev: refactored some Requests as they didn't provide any beneficial help --- .../Admin/DataManagement/ClubsController.php | 17 +++++++------ .../DataManagement/DivisionsController.php | 25 +++++++++++++------ .../Admin/DataManagement/RolesController.php | 15 ++++++----- .../DataManagement/SeasonsController.php | 18 +++++++------ .../Admin/DataManagement/TeamsController.php | 23 +++++++++++------ .../Admin/DataManagement/VenuesController.php | 17 +++++++------ app/Http/Requests/UpdateFixtureRequest.php | 4 ++- .../data-management/clubs/edit.blade.php | 1 - .../data-management/divisions/edit.blade.php | 1 - .../data-management/roles/edit.blade.php | 1 - .../data-management/seasons/edit.blade.php | 1 - .../data-management/teams/edit.blade.php | 1 - .../data-management/venues/edit.blade.php | 1 - 13 files changed, 76 insertions(+), 49 deletions(-) diff --git a/app/Http/Controllers/Admin/DataManagement/ClubsController.php b/app/Http/Controllers/Admin/DataManagement/ClubsController.php index cf3d12a8..ea21c7f2 100644 --- a/app/Http/Controllers/Admin/DataManagement/ClubsController.php +++ b/app/Http/Controllers/Admin/DataManagement/ClubsController.php @@ -2,8 +2,7 @@ namespace LVA\Http\Controllers\Admin\DataManagement; -use LVA\Http\Requests\StoreClubRequest as StoreRequest; -use LVA\Http\Requests\UpdateClubRequest as UpdateRequest; +use Illuminate\Http\Request; use LVA\Http\Controllers\Controller; use Laracasts\Flash\Flash; @@ -42,12 +41,14 @@ public function create() /** * Store a newly created resource in storage. * - * @param StoreRequest $request + * @param Request $request * * @return mixed */ - public function store(StoreRequest $request) + public function store(Request $request) { + $this->validate($request, ['club' => 'required|unique:clubs']); + Club::create($request->all()); Flash::success('Club added!'); @@ -86,13 +87,15 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param UpdateRequest $request - * @param int $id + * @param Request $request + * @param int $id * * @return mixed */ - public function update(UpdateRequest $request, $id) + public function update(Request $request, $id) { + $this->validate($request, ['club' => 'required|unique:clubs,club,' . $id]); + /** @var Club $club */ $club = Club::findOrFail($id); $club->update($request->all()); diff --git a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php index 05b0df44..990decd9 100644 --- a/app/Http/Controllers/Admin/DataManagement/DivisionsController.php +++ b/app/Http/Controllers/Admin/DataManagement/DivisionsController.php @@ -2,11 +2,10 @@ namespace LVA\Http\Controllers\Admin\DataManagement; -use LVA\Http\Requests\StoreDivisionRequest as StoreRequest; -use LVA\Http\Requests\UpdateDivisionRequest as UpdateRequest; +use Illuminate\Http\Request; use LVA\Http\Controllers\Controller; -use Laracasts\Flash\Flash; +use Laracasts\Flash\Flash; use LVA\Models\Division; use LVA\Models\Season; @@ -42,12 +41,17 @@ public function create() /** * Store a newly created resource in storage. * - * @param StoreRequest $request + * @param Request $request * * @return mixed */ - public function store(StoreRequest $request) + public function store(Request $request) { + $this->validate($request, [ + 'season_id' => 'required|exists:seasons,id', + 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $request->input('season_id'), + ]); + Division::create($request->all()); Flash::success('Division added!'); @@ -87,13 +91,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param UpdateRequest $request - * @param int $id + * @param Request $request + * @param int $id * * @return mixed */ - public function update(UpdateRequest $request, $id) + public function update(Request $request, $id) { + $this->validate($request, [ + 'season_id' => 'required|exists:seasons,id', + 'division' => 'required|unique:divisions,division,' . $id . ',id,season_id,' . $request->input('season_id'), + ]); + /** @var Division $division */ $division = Division::findOrFail($id); $division->update($request->all()); diff --git a/app/Http/Controllers/Admin/DataManagement/RolesController.php b/app/Http/Controllers/Admin/DataManagement/RolesController.php index 9096a1db..f5111e53 100644 --- a/app/Http/Controllers/Admin/DataManagement/RolesController.php +++ b/app/Http/Controllers/Admin/DataManagement/RolesController.php @@ -2,8 +2,7 @@ namespace LVA\Http\Controllers\Admin\DataManagement; -use LVA\Http\Requests\StoreRoleRequest as StoreRequest; -use LVA\Http\Requests\UpdateRoleRequest as UpdateRequest; +use Illuminate\Http\Request; use LVA\Http\Controllers\Controller; use Laracasts\Flash\Flash; @@ -41,12 +40,14 @@ public function create() /** * Store a newly created resource in storage. * - * @param StoreRequest $request + * @param Request $request * * @return mixed */ - public function store(StoreRequest $request) + public function store(Request $request) { + $this->validate($request, ['role' => 'required|unique:roles']); + Role::create($request->all()); Flash::success('Role added!'); @@ -85,13 +86,15 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param UpdateRequest $request + * @param Request $request * @param int $id * * @return mixed */ - public function update(UpdateRequest $request, $id) + public function update(Request $request, $id) { + $this->validate($request, ['role' => 'required|unique:roles,role,' . $id]); + /** @var Role $role */ $role = Role::findOrFail($id); $role->update($request->all()); diff --git a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php index 06e4c0aa..13a7ce5e 100644 --- a/app/Http/Controllers/Admin/DataManagement/SeasonsController.php +++ b/app/Http/Controllers/Admin/DataManagement/SeasonsController.php @@ -2,13 +2,13 @@ namespace LVA\Http\Controllers\Admin\DataManagement; -use LVA\Http\Requests\StoreSeasonRequest as StoreRequest; -use LVA\Http\Requests\UpdateSeasonRequest as UpdateRequest; +use Illuminate\Http\Request; use LVA\Http\Controllers\Controller; use Laracasts\Flash\Flash; use LVA\Models\Season; + /** * Class SeasonsController * @@ -41,12 +41,14 @@ public function create() /** * Store a newly created resource in storage. * - * @param StoreRequest $request + * @param Request $request * * @return mixed */ - public function store(StoreRequest $request) + public function store(Request $request) { + $this->validate($request, ['season' => 'required|unique:seasons']); + Season::create($request->all()); Flash::success('Season added!'); @@ -85,13 +87,15 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param UpdateRequest $request - * @param int $id + * @param Request $request + * @param int $id * * @return mixed */ - public function update(UpdateRequest $request, $id) + public function update(Request $request, $id) { + $this->validate($request, ['season' => 'required|unique:seasons,season,' . $id]); + /** @var Season $season */ $season = Season::findOrFail($id); $season->update($request->all()); diff --git a/app/Http/Controllers/Admin/DataManagement/TeamsController.php b/app/Http/Controllers/Admin/DataManagement/TeamsController.php index 0e543515..e4f82685 100644 --- a/app/Http/Controllers/Admin/DataManagement/TeamsController.php +++ b/app/Http/Controllers/Admin/DataManagement/TeamsController.php @@ -2,8 +2,7 @@ namespace LVA\Http\Controllers\Admin\DataManagement; -use LVA\Http\Requests\StoreTeamRequest as StoreRequest; -use LVA\Http\Requests\UpdateTeamRequest as UpdateRequest; +use Illuminate\Http\Request; use LVA\Http\Controllers\Controller; use Laracasts\Flash\Flash; @@ -42,12 +41,17 @@ public function create() /** * Store a newly created resource in storage. * - * @param StoreRequest $request + * @param Request $request * * @return mixed */ - public function store(StoreRequest $request) + public function store(Request $request) { + $this->validate($request, [ + 'club_id' => 'required|exists:clubs,id', + 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $request->input('club_id'), + ]); + Team::create($request->all()); Flash::success('Team added!'); @@ -87,13 +91,18 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param UpdateRequest $request - * @param int $id + * @param Request $request + * @param int $id * * @return mixed */ - public function update(UpdateRequest $request, $id) + public function update(Request $request, $id) { + $this->validate($request, [ + 'club_id' => 'required|exists:clubs,id', + 'team' => 'required|unique:teams,team,' . $id . ',id,club_id,' . $request->input('club_id'), + ]); + /** @var Team $team */ $team = Team::findOrFail($id); $team->update($request->all()); diff --git a/app/Http/Controllers/Admin/DataManagement/VenuesController.php b/app/Http/Controllers/Admin/DataManagement/VenuesController.php index 3e6756eb..9bf600f1 100644 --- a/app/Http/Controllers/Admin/DataManagement/VenuesController.php +++ b/app/Http/Controllers/Admin/DataManagement/VenuesController.php @@ -2,8 +2,7 @@ namespace LVA\Http\Controllers\Admin\DataManagement; -use LVA\Http\Requests\StoreVenueRequest as StoreRequest; -use LVA\Http\Requests\UpdateVenueRequest as UpdateRequest; +use Illuminate\Http\Request; use LVA\Http\Controllers\Controller; use Laracasts\Flash\Flash; @@ -41,12 +40,14 @@ public function create() /** * Store a newly created resource in storage. * - * @param StoreRequest $request + * @param Request $request * * @return mixed */ - public function store(StoreRequest $request) + public function store(Request $request) { + $this->validate($request, ['venue' => 'required|unique:venues']); + Venue::create($request->all()); Flash::success('Venue added!'); @@ -85,13 +86,15 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param UpdateRequest $request - * @param int $id + * @param Request $request + * @param int $id * * @return mixed */ - public function update(UpdateRequest $request, $id) + public function update(Request $request, $id) { + $this->validate($request, ['venue' => 'required|unique:venues,venue,' . $id]); + /** @var Venue $venue */ $venue = Venue::findOrFail($id); $venue->update($request->all()); diff --git a/app/Http/Requests/UpdateFixtureRequest.php b/app/Http/Requests/UpdateFixtureRequest.php index dc3709f8..a8addb32 100644 --- a/app/Http/Requests/UpdateFixtureRequest.php +++ b/app/Http/Requests/UpdateFixtureRequest.php @@ -35,7 +35,9 @@ public function rules() 'unique:fixtures,division_id,' . $this->input('id') . ',id' . ',home_team_id,' . $this->input('home_team_id') . ',away_team_id,' . $this->input('away_team_id'), - 'match_number' => 'required|unique:fixtures,match_number,' . $this->input('id') . ',id,division_id,' . $this->input('division_id'), + 'match_number' => + 'required|' . + 'unique:fixtures,match_number,' . $this->input('id') . ',id,division_id,' . $this->input('division_id'), 'match_date' => 'required', 'warm_up_time' => 'required', 'start_time' => 'required', diff --git a/resources/views/admin/data-management/clubs/edit.blade.php b/resources/views/admin/data-management/clubs/edit.blade.php index 838dc2de..c580bfef 100644 --- a/resources/views/admin/data-management/clubs/edit.blade.php +++ b/resources/views/admin/data-management/clubs/edit.blade.php @@ -13,7 +13,6 @@ 'url' => ['admin/data-management/clubs', $club->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $club->id) !!} @include('admin.data-management.clubs._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/divisions/edit.blade.php b/resources/views/admin/data-management/divisions/edit.blade.php index e022bd68..b4f41fd4 100644 --- a/resources/views/admin/data-management/divisions/edit.blade.php +++ b/resources/views/admin/data-management/divisions/edit.blade.php @@ -13,7 +13,6 @@ 'url' => ['admin/data-management/divisions', $division->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $division->id) !!} @include('admin.data-management.divisions._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/roles/edit.blade.php b/resources/views/admin/data-management/roles/edit.blade.php index 8ca0524d..fb7b7fc0 100644 --- a/resources/views/admin/data-management/roles/edit.blade.php +++ b/resources/views/admin/data-management/roles/edit.blade.php @@ -13,7 +13,6 @@ 'url' => ['admin/data-management/roles', $role->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $role->id) !!} @include('admin.data-management.roles._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/seasons/edit.blade.php b/resources/views/admin/data-management/seasons/edit.blade.php index c15e29b8..06d1da02 100644 --- a/resources/views/admin/data-management/seasons/edit.blade.php +++ b/resources/views/admin/data-management/seasons/edit.blade.php @@ -13,7 +13,6 @@ 'url' => ['admin/data-management/seasons', $season->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $season->id) !!} @include('admin.data-management.seasons._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/teams/edit.blade.php b/resources/views/admin/data-management/teams/edit.blade.php index 58a659b5..6d5d4702 100644 --- a/resources/views/admin/data-management/teams/edit.blade.php +++ b/resources/views/admin/data-management/teams/edit.blade.php @@ -13,7 +13,6 @@ 'url' => ['admin/data-management/teams', $team->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $team->id) !!} @include('admin.data-management.teams._form', ['submitText' => 'Update']) diff --git a/resources/views/admin/data-management/venues/edit.blade.php b/resources/views/admin/data-management/venues/edit.blade.php index d15ffffd..ef0582a9 100644 --- a/resources/views/admin/data-management/venues/edit.blade.php +++ b/resources/views/admin/data-management/venues/edit.blade.php @@ -13,7 +13,6 @@ 'url' => ['admin/data-management/venues', $venue->id], 'class' => 'form-horizontal' ]) !!} - {!! Form::hidden('id', $venue->id) !!} @include('admin.data-management.venues._form', ['submitText' => 'Update']); From 7abf08bbd0e821e3176197a4cfb22a00799058f9 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Sun, 19 Mar 2017 17:16:03 +0000 Subject: [PATCH 55/62] lva-22: removed the new_venues tables, as I'm not implementing the functionality for now --- app/Models/NewVenue.php | 73 ------------------- ...6_11_20_124340_create_new_venues_table.sql | 16 ---- ...6_11_20_124340_create_new_venues_table.sql | 4 - ...6_11_20_124340_create_new_venues_table.php | 42 ----------- 4 files changed, 135 deletions(-) delete mode 100644 app/Models/NewVenue.php delete mode 100644 database/deployment/2016_11_20_124340_create_new_venues_table.sql delete mode 100644 database/deployment/rollbacks/2016_11_20_124340_create_new_venues_table.sql delete mode 100644 database/migrations/2016_11_20_124340_create_new_venues_table.php diff --git a/app/Models/NewVenue.php b/app/Models/NewVenue.php deleted file mode 100644 index 705a44c3..00000000 --- a/app/Models/NewVenue.php +++ /dev/null @@ -1,73 +0,0 @@ - - * Date: 20/11/2016 - * Time: 16:09 - */ - -namespace LVA\Models; - -use Illuminate\Database\Eloquent\Model; - -/** - * Class NewVenues - * - * @package LVA\Models - */ -class NewVenue extends Model -{ - /** - * The database table used by the model. - * - * @var string - */ - protected $table = 'new_venues'; - - /** - * Attributes that should be mass-assignable. - * - * @var array - */ - protected $fillable = ['upload_job_id', 'venue']; - - /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function uploadJob() - { - return $this->hasOne(UploadJob::class); - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param int $jobId - * - * @return NewVenue - */ - public function setUploadJob($jobId) - { - $this->upload_job_id = $jobId; - - return $this; - } - - /** - * @param string $venue - * - * @return NewVenue - */ - public function setName($venue) - { - $this->venue = $venue; - - return $this; - } -} \ No newline at end of file diff --git a/database/deployment/2016_11_20_124340_create_new_venues_table.sql b/database/deployment/2016_11_20_124340_create_new_venues_table.sql deleted file mode 100644 index 29135f7e..00000000 --- a/database/deployment/2016_11_20_124340_create_new_venues_table.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE `new_venues` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `upload_job_id` INT UNSIGNED NOT NULL, - `venue` VARCHAR(255) NOT NULL, - `venue_id` INT UNSIGNED NULL, - `created_at` TIMESTAMP NULL, - `updated_at` TIMESTAMP NULL -) - DEFAULT CHARACTER SET utf8 - COLLATE utf8_unicode_ci - ENGINE = InnoDB; - -ALTER TABLE `new_venues` - ADD INDEX `new_venues_venue_index`(`venue`); -ALTER TABLE `new_venues` - ADD CONSTRAINT `new_venues_upload_job_id_foreign` FOREIGN KEY (`upload_job_id`) REFERENCES `upload_jobs` (`id`); diff --git a/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_table.sql b/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_table.sql deleted file mode 100644 index ff9f29fc..00000000 --- a/database/deployment/rollbacks/2016_11_20_124340_create_new_venues_table.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE `new_venues` - DROP FOREIGN KEY `new_venues_upload_job_id_foreign`; -DROP TABLE `new_venues`; - diff --git a/database/migrations/2016_11_20_124340_create_new_venues_table.php b/database/migrations/2016_11_20_124340_create_new_venues_table.php deleted file mode 100644 index a904b56b..00000000 --- a/database/migrations/2016_11_20_124340_create_new_venues_table.php +++ /dev/null @@ -1,42 +0,0 @@ -engine = 'InnoDB'; - - $table->increments('id'); - $table->unsignedInteger('upload_job_id'); - $table->string('venue'); - $table->unsignedInteger('venue_id')->nullable(); - - $table->timestamps(); - - $table->index('venue'); - $table->foreign('upload_job_id')->references('id')->on('upload_jobs'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('new_venues', function (Blueprint $table) { - $table->dropForeign(['upload_job_id']); - }); - Schema::drop('new_venues'); - } -} From b7b38604d556a33c826c702e43c152e6cc4683ef Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 20 Mar 2017 18:53:41 +0000 Subject: [PATCH 56/62] lva-22: added more test and some refactoring --- .../Api/v1/UploadApiController.php | 80 +++- app/Http/Requests/Api/v1/MapTeamRequest.php | 40 -- app/Http/Requests/Api/v1/MapVenueRequest.php | 40 -- app/Http/Requests/Api/v1/NewVenueRequest.php | 39 -- app/Http/Requests/StoreClubRequest.php | 35 -- app/Http/Requests/StoreDivisionRequest.php | 36 -- app/Http/Requests/StoreRoleRequest.php | 35 -- app/Http/Requests/StoreSeasonRequest.php | 35 -- app/Http/Requests/StoreTeamRequest.php | 36 -- app/Http/Requests/StoreVenueRequest.php | 35 -- app/Http/Requests/UpdateClubRequest.php | 35 -- app/Http/Requests/UpdateDivisionRequest.php | 36 -- app/Http/Requests/UpdateRoleRequest.php | 35 -- app/Http/Requests/UpdateSeasonRequest.php | 35 -- app/Http/Requests/UpdateTeamRequest.php | 36 -- app/Http/Requests/UpdateVenueRequest.php | 35 -- app/Http/routes.php | 4 +- app/Models/UploadJob.php | 8 - app/Models/UploadJobStatus.php | 25 +- composer.json | 3 +- ..._remove_venue_id_from_new_venues_table.sql | 2 - ..._remove_venue_id_from_new_venues_table.sql | 2 - database/factories/VenueFactories.php | 9 - ..._remove_venue_id_from_new_venues_table.php | 31 -- env.travis | 2 +- .../assets/js/load-fixtures-status-update.js | 84 +++- .../_partial/load-fixture-modal.blade.php | 58 --- .../data-management/load/status.blade.php | 90 +++- tests/TestCase.php | 54 ++- tests/integration/IntegrationTestCase.php | 66 --- .../Models/AvailableAppointmentTest.php | 4 +- tests/integration/Models/ClubTest.php | 4 +- tests/integration/Models/DivisionTest.php | 4 +- tests/integration/Models/FixtureTest.php | 4 +- tests/integration/Models/MappedTeamTest.php | 4 +- tests/integration/Models/MappedVenueTest.php | 4 +- tests/integration/Models/RoleTest.php | 4 +- tests/integration/Models/SeasonTest.php | 4 +- tests/integration/Models/TeamSynonymTest.php | 4 +- tests/integration/Models/TeamTest.php | 4 +- .../integration/Models/UploadJobDataTest.php | 4 +- .../Models/UploadJobStatusTest.php | 97 ++++- tests/integration/Models/UploadJobTest.php | 20 +- tests/integration/Models/VenueSynonymTest.php | 4 +- tests/integration/Models/VenueTest.php | 4 +- .../InteractiveFixturesUploadServiceTest.php | 3 - tests/unit/Api/v1/UploadApiTest.php | 399 +++++++++++++++++- 47 files changed, 784 insertions(+), 848 deletions(-) delete mode 100644 app/Http/Requests/Api/v1/MapTeamRequest.php delete mode 100644 app/Http/Requests/Api/v1/MapVenueRequest.php delete mode 100644 app/Http/Requests/Api/v1/NewVenueRequest.php delete mode 100644 app/Http/Requests/StoreClubRequest.php delete mode 100644 app/Http/Requests/StoreDivisionRequest.php delete mode 100644 app/Http/Requests/StoreRoleRequest.php delete mode 100644 app/Http/Requests/StoreSeasonRequest.php delete mode 100644 app/Http/Requests/StoreTeamRequest.php delete mode 100644 app/Http/Requests/StoreVenueRequest.php delete mode 100644 app/Http/Requests/UpdateClubRequest.php delete mode 100644 app/Http/Requests/UpdateDivisionRequest.php delete mode 100644 app/Http/Requests/UpdateRoleRequest.php delete mode 100644 app/Http/Requests/UpdateSeasonRequest.php delete mode 100644 app/Http/Requests/UpdateTeamRequest.php delete mode 100644 app/Http/Requests/UpdateVenueRequest.php delete mode 100644 database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql delete mode 100644 database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql delete mode 100644 database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php delete mode 100644 resources/views/_partial/load-fixture-modal.blade.php delete mode 100644 tests/integration/IntegrationTestCase.php diff --git a/app/Http/Controllers/Api/v1/UploadApiController.php b/app/Http/Controllers/Api/v1/UploadApiController.php index 6253f588..ae9f751d 100644 --- a/app/Http/Controllers/Api/v1/UploadApiController.php +++ b/app/Http/Controllers/Api/v1/UploadApiController.php @@ -8,13 +8,10 @@ namespace LVA\Http\Controllers\Api\v1; +use Illuminate\Http\Request; use LVA\Http\Controllers\Controller; -use LVA\Http\Requests\Api\v1\MapTeamRequest; -use LVA\Http\Requests\Api\v1\MapVenueRequest; -use LVA\Http\Requests\Api\v1\NewVenueRequest; use LVA\Models\MappedTeam; use LVA\Models\MappedVenue; -use LVA\Models\NewVenue; use LVA\Models\TeamSynonym; use LVA\Models\UploadJob; use LVA\Models\UploadJobStatus; @@ -39,6 +36,9 @@ public function __construct(InteractiveFixturesUploadService $uploadService, Upl $this->uploadDataService = $uploadDataService; } + /** + * @return \Illuminate\Http\JsonResponse + */ public function resumeUpload() { $uploadJob = $this->checkForJob(); @@ -49,13 +49,52 @@ public function resumeUpload() /** @var UploadJobStatus $status */ $status = UploadJobStatus::factory($uploadJob->getStatus()); - if ($status->canResume()) { - $status->resume(); + if (!$status->canResume()) { + return response()->json([ + 'Timestamp' => time(), + 'Error' => true, + 'Message' => 'Job cannot be resumed', + ]); + } + + $status->resume(); + + $uploadJob->setStatus($status->toArray())->save(); + + $this->uploadService->processJob($uploadJob); + + return response()->json([ + 'Timestamp' => time(), + 'Error' => false, + 'Message' => 'Job resumed', + ]); + } + + public function abandonUpload() + { + $uploadJob = $this->checkForJob(); + if (!$uploadJob instanceof UploadJob) { + return response()->json($uploadJob); + } - $uploadJob->setStatus($status->toArray())->save(); + /** @var UploadJobStatus $status */ + $status = UploadJobStatus::factory($uploadJob->getStatus()); - $this->uploadService->processJob($uploadJob); + if (!$status->isWaitingConfirmation()) { + return response()->json([ + 'Timestamp' => time(), + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); } + + $this->uploadService->cleanUp($uploadJob); + + return response()->json([ + 'Timestamp' => time(), + 'Error' => false, + 'Message' => 'Job abandoned', + ]); } public function getUploadStatus() @@ -76,8 +115,14 @@ public function getUploadStatus() ]); } - public function mapTeam(MapTeamRequest $request) + public function mapTeam(Request $request) { + $this->validate($request, [ + 'job' => 'required|exists:upload_jobs,id', + 'name' => 'required', + 'newName' => 'required', + ]); + $mappedTeam = new MappedTeam(); $mappedTeam ->setUploadJob($request->input('job')) @@ -97,21 +142,14 @@ public function mapTeam(MapTeamRequest $request) ]); } - public function addVenue(NewVenueRequest $request) + public function mapVenue(Request $request) { - $newVenue = new NewVenue(); - $newVenue - ->setUploadJob($request->input('job')) - ->setName($request->input('name')) - ->save(); - - return response()->json([ - 'success' => true, + $this->validate($request, [ + 'job' => 'required|exists:upload_jobs,id', + 'name' => 'required', + 'newName' => 'required', ]); - } - public function mapVenue(MapVenueRequest $request) - { $mappedVenue = new MappedVenue(); $mappedVenue ->setUploadJob($request->input('job')) diff --git a/app/Http/Requests/Api/v1/MapTeamRequest.php b/app/Http/Requests/Api/v1/MapTeamRequest.php deleted file mode 100644 index ce7cbfda..00000000 --- a/app/Http/Requests/Api/v1/MapTeamRequest.php +++ /dev/null @@ -1,40 +0,0 @@ - 'required|exists:upload_jobs,id', - 'name' => 'required', - 'newName' => 'required', - ]; - } -} \ No newline at end of file diff --git a/app/Http/Requests/Api/v1/MapVenueRequest.php b/app/Http/Requests/Api/v1/MapVenueRequest.php deleted file mode 100644 index 9da4babd..00000000 --- a/app/Http/Requests/Api/v1/MapVenueRequest.php +++ /dev/null @@ -1,40 +0,0 @@ - 'required|exists:upload_jobs,id', - 'name' => 'required', - 'newName' => 'required', - ]; - } -} \ No newline at end of file diff --git a/app/Http/Requests/Api/v1/NewVenueRequest.php b/app/Http/Requests/Api/v1/NewVenueRequest.php deleted file mode 100644 index ab410f76..00000000 --- a/app/Http/Requests/Api/v1/NewVenueRequest.php +++ /dev/null @@ -1,39 +0,0 @@ - 'required|exists:upload_jobs', - 'name' => 'required', - ]; - } -} \ No newline at end of file diff --git a/app/Http/Requests/StoreClubRequest.php b/app/Http/Requests/StoreClubRequest.php deleted file mode 100644 index 4cff40e6..00000000 --- a/app/Http/Requests/StoreClubRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:clubs', - ]; - } -} diff --git a/app/Http/Requests/StoreDivisionRequest.php b/app/Http/Requests/StoreDivisionRequest.php deleted file mode 100644 index ac219663..00000000 --- a/app/Http/Requests/StoreDivisionRequest.php +++ /dev/null @@ -1,36 +0,0 @@ - 'required|exists:seasons,id', - 'division' => 'required|unique:divisions,division,NULL,id,season_id,' . $this->input('season_id'), - ]; - } -} diff --git a/app/Http/Requests/StoreRoleRequest.php b/app/Http/Requests/StoreRoleRequest.php deleted file mode 100644 index 2510c55d..00000000 --- a/app/Http/Requests/StoreRoleRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:roles' - ]; - } -} diff --git a/app/Http/Requests/StoreSeasonRequest.php b/app/Http/Requests/StoreSeasonRequest.php deleted file mode 100644 index 08e39287..00000000 --- a/app/Http/Requests/StoreSeasonRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:seasons' - ]; - } -} diff --git a/app/Http/Requests/StoreTeamRequest.php b/app/Http/Requests/StoreTeamRequest.php deleted file mode 100644 index 272cee65..00000000 --- a/app/Http/Requests/StoreTeamRequest.php +++ /dev/null @@ -1,36 +0,0 @@ - 'required|exists:clubs,id', - 'team' => 'required|unique:teams,team,NULL,id,club_id,' . $this->input('club_id'), - ]; - } -} diff --git a/app/Http/Requests/StoreVenueRequest.php b/app/Http/Requests/StoreVenueRequest.php deleted file mode 100644 index 3b2bde1a..00000000 --- a/app/Http/Requests/StoreVenueRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:venues', - ]; - } -} diff --git a/app/Http/Requests/UpdateClubRequest.php b/app/Http/Requests/UpdateClubRequest.php deleted file mode 100644 index b13b0d24..00000000 --- a/app/Http/Requests/UpdateClubRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:clubs,club,' . $this->input('id') - ]; - } -} diff --git a/app/Http/Requests/UpdateDivisionRequest.php b/app/Http/Requests/UpdateDivisionRequest.php deleted file mode 100644 index dc987073..00000000 --- a/app/Http/Requests/UpdateDivisionRequest.php +++ /dev/null @@ -1,36 +0,0 @@ - 'required|exists:seasons,id', - 'division' => 'required|unique:divisions,division,' . $this->input('id') . ',id,season_id,' . $this->input('season_id'), - ]; - } -} diff --git a/app/Http/Requests/UpdateRoleRequest.php b/app/Http/Requests/UpdateRoleRequest.php deleted file mode 100644 index 5f84ecc0..00000000 --- a/app/Http/Requests/UpdateRoleRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:roles,role,' . $this->input('id'), - ]; - } -} diff --git a/app/Http/Requests/UpdateSeasonRequest.php b/app/Http/Requests/UpdateSeasonRequest.php deleted file mode 100644 index fbb639d2..00000000 --- a/app/Http/Requests/UpdateSeasonRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:seasons,season,' . $this->input('id') - ]; - } -} diff --git a/app/Http/Requests/UpdateTeamRequest.php b/app/Http/Requests/UpdateTeamRequest.php deleted file mode 100644 index 721615b9..00000000 --- a/app/Http/Requests/UpdateTeamRequest.php +++ /dev/null @@ -1,36 +0,0 @@ - 'required|exists:clubs,id', - 'team' => 'required|unique:teams,team,' . $this->input('id') . ',id,club_id,' . $this->input('club_id'), - ]; - } -} diff --git a/app/Http/Requests/UpdateVenueRequest.php b/app/Http/Requests/UpdateVenueRequest.php deleted file mode 100644 index 7c8a53aa..00000000 --- a/app/Http/Requests/UpdateVenueRequest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'required|unique:venues,venue,' . $this->input('id') - ]; - } -} diff --git a/app/Http/routes.php b/app/Http/routes.php index 06f0a1a7..dcda6b08 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -24,11 +24,11 @@ | */ Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api', 'namespace' => 'Api\v1'], function () { - Route::get('uploads/status.json', ['uses' => 'UploadApiController@getUploadStatus']); + Route::get('uploads/status.json', ['as' => 'upload-status', 'uses' => 'UploadApiController@getUploadStatus']); Route::post('maps/team', ['as' => 'loading-map-team', 'uses' => 'UploadApiController@mapTeam']); - Route::post('venues', ['as' => 'loading-add-venue', 'uses' => 'UploadApiController@addVenue']); Route::post('maps/venue', ['as' => 'loading-map-venue', 'uses' => 'UploadApiController@mapVenue']); Route::get('uploads/resume', ['as' => 'resume-upload', 'uses' => 'UploadApiController@resumeUpload']); + Route::get('uploads/abandon', ['as' => 'abandon-upload', 'uses' => 'UploadApiController@abandonUpload']); }); Route::group(['middleware' => 'web'], function () { diff --git a/app/Models/UploadJob.php b/app/Models/UploadJob.php index 6ce1ae46..1898ef73 100644 --- a/app/Models/UploadJob.php +++ b/app/Models/UploadJob.php @@ -34,14 +34,6 @@ public function mappedVenues() return $this->hasMany(MappedVenue::class); } - /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function newVenues() - { - return $this->hasMany(NewVenue::class); - } - /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/UploadJobStatus.php b/app/Models/UploadJobStatus.php index 756b98c6..4c3098c3 100644 --- a/app/Models/UploadJobStatus.php +++ b/app/Models/UploadJobStatus.php @@ -10,7 +10,6 @@ use Carbon\Carbon; - /** * Class UploadJobStatus * @@ -26,8 +25,9 @@ class UploadJobStatus const STATUS_VALIDATING_RECORDS = 10; const STATUS_UNKNOWN_DATA = 11; const STATUS_UNRECOVERABLE_VALIDATION_ERROR = 19; - const STATUS_INSERTING_RECORDS = 20; - const STATUS_UNRECOVERABLE_INSERT_ERROR = 29; + const STATUS_WAITING_CONFIRMATION_TO_INSERT = 20; + const STATUS_INSERTING_RECORDS = 30; + const STATUS_UNRECOVERABLE_INSERT_ERROR = 39; const STATUS_DONE = 99; const UNKNOWN_HOME_TEAM = 1; @@ -83,6 +83,8 @@ public function getStatusCodeMessage() return 'Not started'; case self::STATUS_VALIDATING_RECORDS: return 'Validating records'; + case self::STATUS_WAITING_CONFIRMATION_TO_INSERT: + return 'Waiting for confirmation from user'; case self::STATUS_INSERTING_RECORDS: return 'Inserting records'; case self::STATUS_UNKNOWN_DATA: @@ -146,7 +148,7 @@ public function toApiArray() 'StatusMessage' => $this->getStatusCodeMessage(), ]; - if ($this->hasStarted() && !$this->isDone()) { + if ($this->hasStarted() && !$this->isWaitingConfirmation() && !$this->isDone()) { if ($this->isInserting()) { $formattedStatus['Progress'] = floor($this->getProcessedRows() * 100 / $this->getTotalRows()); } else { @@ -227,6 +229,14 @@ public function isValidating() return $this->status_code === self::STATUS_VALIDATING_RECORDS; } + /** + * @return bool + */ + public function isWaitingConfirmation() + { + return $this->status_code === self::STATUS_WAITING_CONFIRMATION_TO_INSERT; + } + /** * @return bool */ @@ -256,7 +266,7 @@ public function hasUnknownData() */ public function canResume() { - return $this->hasNotStarted() || $this->hasUnknownData(); + return $this->hasNotStarted() || $this->hasUnknownData() || $this->isWaitingConfirmation(); } /** @@ -593,7 +603,7 @@ public function moveForward() $this->status_code = self::STATUS_VALIDATING_RECORDS; break; case self::STATUS_VALIDATING_RECORDS: - $this->status_code = self::STATUS_INSERTING_RECORDS; + $this->status_code = self::STATUS_WAITING_CONFIRMATION_TO_INSERT; break; case self::STATUS_INSERTING_RECORDS: $this->status_code = self::STATUS_DONE; @@ -615,6 +625,9 @@ public function resume() if ($this->status_code === self::STATUS_UNKNOWN_DATA) { $this->status_code = self::STATUS_VALIDATING_RECORDS; $this->unknowns = null; + } elseif ($this->status_code === self::STATUS_WAITING_CONFIRMATION_TO_INSERT) { + $this->status_code = self::STATUS_INSERTING_RECORDS; + $this->processing_line = null; } return $this; diff --git a/composer.json b/composer.json index 399cf6ae..71558113 100644 --- a/composer.json +++ b/composer.json @@ -45,8 +45,7 @@ }, "autoload-dev": { "classmap": [ - "tests/TestCase.php", - "tests/integration/IntegrationTestCase.php" + "tests/TestCase.php" ] }, "scripts": { diff --git a/database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql b/database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql deleted file mode 100644 index 865ba8b3..00000000 --- a/database/deployment/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `new_venues` - DROP `venue_id`; \ No newline at end of file diff --git a/database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql b/database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql deleted file mode 100644 index 846b28a6..00000000 --- a/database/deployment/rollbacks/2017_02_06_124316_remove_venue_id_from_new_venues_table.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `new_venues` - ADD `venue_id` INT UNSIGNED NULL; \ No newline at end of file diff --git a/database/factories/VenueFactories.php b/database/factories/VenueFactories.php index 7ede0f17..4ab7f5aa 100644 --- a/database/factories/VenueFactories.php +++ b/database/factories/VenueFactories.php @@ -18,15 +18,6 @@ ]; }); -$factory->define(\LVA\Models\NewVenue::class, function (\Faker\Generator $faker) { - return [ - 'upload_job_id' => function () { - return factory(\LVA\Models\UploadJob::class)->create()->id; - }, - 'venue' => $faker->unique()->word, - ]; -}); - $factory->define(\LVA\Models\VenueSynonym::class, function (\Faker\Generator $faker) { return [ 'synonym' => $faker->unique()->word, diff --git a/database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php b/database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php deleted file mode 100644 index b5abf63f..00000000 --- a/database/migrations/2017_02_06_124316_remove_venue_id_from_new_venues_table.php +++ /dev/null @@ -1,31 +0,0 @@ -dropColumn('venue_id'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('new_venues', function (Blueprint $table) { - $table->unsignedInteger('venue_id')->nullable(); - }); - } -} diff --git a/env.travis b/env.travis index 0eb8c523..0a6f4555 100644 --- a/env.travis +++ b/env.travis @@ -1,4 +1,4 @@ -APP_ENV=trevis +APP_ENV=travis APP_DEBUG=true APP_KEY=SomeRandomString diff --git a/resources/assets/js/load-fixtures-status-update.js b/resources/assets/js/load-fixtures-status-update.js index 8b11ee2c..6dac2fd7 100644 --- a/resources/assets/js/load-fixtures-status-update.js +++ b/resources/assets/js/load-fixtures-status-update.js @@ -6,9 +6,19 @@ var apiToken = $('#api_token').val(), jobId = $('#job_id').val(), - modal = $('#load-fixture-modal'), + userActionModal = $('#user-action-modal'), + userConfirmationModal = $('#user-confirmation-modal'), lastTimestamp = 0, + // These variables reflects the statuses maintaned in the UploadJobStatus model class + statusValidating = 10, + statusUnknownData = 11, + statusErrorValidating = 19, + statusWaitingConfirmation = 20, + statusInserting = 30, + statusErrorInserting = 39, + statusDone = 99, + updateProgressBar = function updateProgressBar(bar, progress) { bar.removeClass('hidden'); bar.find('.progress-bar') @@ -30,7 +40,7 @@ row.css('opacity', 0.5); if ($('#unknowns').find('button').not('.disabled').length == 0) { - $('#continue-button').removeClass('disabled'); + $('#resume-button').removeClass('disabled'); } }, @@ -143,7 +153,6 @@ }).done(function (data) { if (lastTimestamp == data.Timestamp) { setTimeout(poll, 500); - console.log('Same timestamp - nothing to do'); return; } lastTimestamp = data.Timestamp; @@ -154,30 +163,37 @@ } var status = data.Status; - if (status.StatusCode >= 10) { - var validatingProgress = status.StatusCode < 20 ? status.Progress : 100; + if (status.StatusCode >= statusValidating) { + var validatingProgress = status.StatusCode < (statusValidating + 10) ? status.Progress : 100; updateProgressBar($('#validating-progress'), validatingProgress); } - if (status.StatusCode >= 20) { - var insertingProgress = status.StatusCode < 30 ? status.Progress : 100; + if (status.StatusCode >= statusInserting) { + var insertingProgress = status.StatusCode < (statusInserting + 10) ? status.Progress : 100; updateProgressBar($('#inserting-progress'), insertingProgress); } - if (status.StatusCode == 11) { - modal.find('.modal-title').text(status.StatusMessage); + if (status.StatusCode == statusUnknownData) { + userActionModal.find('.modal-title').text(status.StatusMessage); - populateCurrentFixture(modal, status.Fixture); + populateCurrentFixture(userActionModal, status.Fixture); - modal.find('#unknowns').empty(); + userActionModal.find('#unknowns').empty(); $.each(status.Unknowns, function (field, map) { var newUnknown = createUnknownRow('unknown-data-template', status.Fixture[field], map); - $('#load-fixture-modal').find('#unknowns').append(newUnknown); + userActionModal.find('#unknowns').append(newUnknown); }); - $('#continue-button').addClass('disabled').blur(); - modal.modal('show'); + $('#resume-button').addClass('disabled').blur(); + userActionModal.modal('show'); - } else if (status.StatusCode == 19 || status.StatusCode == 29) { + } else if (status.StatusCode == statusWaitingConfirmation) { + // create confirmation pop up + userConfirmationModal.modal('show'); + // if user click on Proceed + // call to resume + // else + // call clean-up + } else if (status.StatusCode == statusErrorValidating || status.StatusCode == statusErrorInserting) { var alert = $('#unrecoverable-errors'); if (status.ErrorLine) { var errorLine = alert.find('#error-line-number'); @@ -189,19 +205,19 @@ alert.find('ul').append($('
  • ' + error + '
  • ')) }); alert.removeClass('hidden'); - if (status.StatusCode == 19) { + if (status.StatusCode == statusErrorValidating) { $('#validating-progress .progress-bar').removeClass('progress-bar-striped active').addClass('progress-bar-danger'); - } else if (status.StatusCode == 29) { + } else if (status.StatusCode == statusErrorInserting) { $('#inserting-progress .progress-bar').removeClass('progress-bar-striped active').addClass('progress-bar-danger'); } - } else if (status.StatusCode != 99) { + } else if (status.StatusCode != statusDone) { setTimeout(poll, 500); } }); }, - restart = function restart() { + resume = function restart() { // Restart the uploading $.get({ url : '/api/v1/uploads/resume', @@ -211,13 +227,35 @@ }, async: true }); + }, + + abandon = function abandon() { + // Abandon the uploading + $.get({ + url : '/api/v1/uploads/abandon', + data: { + job : jobId, + api_token: apiToken + } + }); + location.href = '/admin/data-management/upload/fixtures'; }; - restart(); + resume(); poll(); - modal.modal({show: false}); - modal.on('hidden.bs.modal', function () { + + $('.modal').modal({background: false, keyboard: false, show: false}); + $('.modal').on('hidden.bs.modal', function () { setTimeout(poll, 500); - restart(); + }); + + $('#resume-button').on('click', function () { + resume(); + }); + $('#abandon-button').on('click', function (event) { + abandon(); + }); + $('#continue-button').on('click', function (event) { + resume(); }); })(jQuery); \ No newline at end of file diff --git a/resources/views/_partial/load-fixture-modal.blade.php b/resources/views/_partial/load-fixture-modal.blade.php deleted file mode 100644 index 4f137485..00000000 --- a/resources/views/_partial/load-fixture-modal.blade.php +++ /dev/null @@ -1,58 +0,0 @@ - \ No newline at end of file diff --git a/resources/views/admin/data-management/load/status.blade.php b/resources/views/admin/data-management/load/status.blade.php index 961aad55..c4b08674 100644 --- a/resources/views/admin/data-management/load/status.blade.php +++ b/resources/views/admin/data-management/load/status.blade.php @@ -40,11 +40,95 @@ - @include('_partial.load-fixture-modal') + + + @endsection @section('javascript') - + @endsection \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 35e38464..ff03d9c4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,10 @@ namespace Tests; +use Faker\Factory; +use Faker\Generator; use Illuminate\Contracts\Console\Kernel; +use LVA\Models\UploadJobStatus; use LVA\User; /** @@ -25,10 +28,10 @@ */ class TestCase extends \Illuminate\Foundation\Testing\TestCase { - protected $users = []; - protected static $refreshDatabase = true; - + protected $users = []; + /** @var Generator */ + protected $faker; /** * The base URL to use while testing the application. * @@ -54,6 +57,8 @@ protected function setUp() { parent::setUp(); + $this->faker = Factory::create(); + // Refresh the DB, but only once if (self::$refreshDatabase) { \Artisan::call('migrate:refresh'); @@ -72,6 +77,49 @@ protected function tearDown() parent::tearDown(); } + /** + * @param array $overrides + * + * @return UploadJobStatus + */ + protected function uploadJobTestFactory($overrides = []) + { + $totalLines = $this->faker->numberBetween(10, 200); + $totalRows = $this->faker->numberBetween($totalLines, $totalLines * 2); + + /** @var \LVA\Models\Venue[] $mapping */ + $mapping = factory(\LVA\Models\Venue::class)->times(3)->make(); + + $defaults = [ + "status_code" => \LVA\Models\UploadJobStatus::STATUS_NOT_STARTED, + "total_lines" => $totalLines, + "processed_lines" => $this->faker->numberBetween(0, $totalLines), + "total_rows" => $totalRows, + "processed_rows" => $this->faker->numberBetween(0, $totalRows), + 'processing_line' => [ + 'division' => factory(\LVA\Models\Division::class)->make()->getName(), + 'match_number' => $this->faker->numberBetween(1, 20), + 'home_team' => factory(\LVA\Models\Team::class)->make()->getName(), + 'away_team' => factory(\LVA\Models\Team::class)->make()->getName(), + 'date' => $this->faker->date('D, d/m/Y'), + 'warm_up_time' => $this->faker->date('H:i'), + 'start_time' => $this->faker->date('H:i'), + 'venue' => factory(\LVA\Models\Venue::class)->make()->getName(), + ], + 'unknowns' => [ + \LVA\Models\UploadJobStatus::UNKNOWN_VENUE => [ + ['value' => $mapping[0]->getId(), 'text' => $mapping[0]->getName()], + ['value' => $mapping[1]->getId(), 'text' => $mapping[1]->getName()], + ['value' => $mapping[2]->getId(), 'text' => $mapping[2]->getName()], + ], + ], + "errors" => $this->faker->unique()->sentences(), + "error_line" => $this->faker->numberBetween(1, $totalLines - 1), + ]; + + return UploadJobStatus::factory(array_merge($defaults, $overrides)); + } + /** * @param int|null $userId * diff --git a/tests/integration/IntegrationTestCase.php b/tests/integration/IntegrationTestCase.php deleted file mode 100644 index 72d15996..00000000 --- a/tests/integration/IntegrationTestCase.php +++ /dev/null @@ -1,66 +0,0 @@ -faker = \Faker\Factory::create(); - } - - /** - * @param array $overrides - * - * @return UploadJobStatus - */ - protected function uploadJobTestFactory($overrides = []) - { - $totalLines = $this->faker->numberBetween(10, 200); - $totalRows = $this->faker->numberBetween($totalLines, $totalLines * 2); - - /** @var \LVA\Models\Venue[] $mapping */ - $mapping = factory(\LVA\Models\Venue::class)->times(3)->make(); - - $defaults = [ - "status_code" => \LVA\Models\UploadJobStatus::STATUS_NOT_STARTED, - "total_lines" => $totalLines, - "processed_lines" => $this->faker->numberBetween(0, $totalLines), - "total_rows" => $totalRows, - "processed_rows" => $this->faker->numberBetween(0, $totalRows), - 'processing_line' => [ - 'division' => factory(\LVA\Models\Division::class)->make()->getName(), - 'match_number' => $this->faker->numberBetween(1, 20), - 'home_team' => factory(\LVA\Models\Team::class)->make()->getName(), - 'away_team' => factory(\LVA\Models\Team::class)->make()->getName(), - 'date' => $this->faker->date('D, d/m/Y'), - 'warm_up_time' => $this->faker->date('H:i'), - 'start_time' => $this->faker->date('H:i'), - 'venue' => factory(\LVA\Models\Venue::class)->make()->getName(), - ], - 'unknowns' => [ - \LVA\Models\UploadJobStatus::UNKNOWN_VENUE => [ - ['value' => $mapping[0]->getId(), 'text' => $mapping[0]->getName()], - ['value' => $mapping[1]->getId(), 'text' => $mapping[1]->getName()], - ['value' => $mapping[2]->getId(), 'text' => $mapping[2]->getName()], - ], - ], - "errors" => $this->faker->unique()->sentences(), - "error_line" => $this->faker->numberBetween(1, $totalLines - 1), - ]; - - return UploadJobStatus::factory(array_merge($defaults, $overrides)); - } -} \ No newline at end of file diff --git a/tests/integration/Models/AvailableAppointmentTest.php b/tests/integration/Models/AvailableAppointmentTest.php index a7eff7eb..2b512da3 100644 --- a/tests/integration/Models/AvailableAppointmentTest.php +++ b/tests/integration/Models/AvailableAppointmentTest.php @@ -5,14 +5,14 @@ use LVA\Models\Fixture; use LVA\Models\Role; use LVA\Models\AvailableAppointment; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class AvailableAppointmentTest * * @package Tests\Models */ -class AvailableAppointmentTest extends IntegrationTestCase +class AvailableAppointmentTest extends TestCase { /** * @test diff --git a/tests/integration/Models/ClubTest.php b/tests/integration/Models/ClubTest.php index 9b858d39..e47033a2 100644 --- a/tests/integration/Models/ClubTest.php +++ b/tests/integration/Models/ClubTest.php @@ -3,15 +3,15 @@ namespace Tests\Models; use LVA\Models\Team; -use Tests\Integration\IntegrationTestCase; use LVA\Models\Club; +use Tests\TestCase; /** * Class ClubTest * * @package Tests\Models */ -class ClubTest extends IntegrationTestCase +class ClubTest extends TestCase { /** * @test diff --git a/tests/integration/Models/DivisionTest.php b/tests/integration/Models/DivisionTest.php index 4b864d70..f1a1dfb1 100644 --- a/tests/integration/Models/DivisionTest.php +++ b/tests/integration/Models/DivisionTest.php @@ -4,15 +4,15 @@ use LVA\Models\Fixture; use LVA\Models\Season; -use Tests\Integration\IntegrationTestCase; use LVA\Models\Division; +use Tests\TestCase; /** * Class DivisionTest * * @package Tests\Models */ -class DivisionTest extends IntegrationTestCase +class DivisionTest extends TestCase { /** * @test diff --git a/tests/integration/Models/FixtureTest.php b/tests/integration/Models/FixtureTest.php index b90c9a55..455ee09f 100644 --- a/tests/integration/Models/FixtureTest.php +++ b/tests/integration/Models/FixtureTest.php @@ -7,15 +7,15 @@ use LVA\Models\Division; use LVA\Models\Team; use LVA\Models\Venue; -use Tests\Integration\IntegrationTestCase; use LVA\Models\Fixture; +use Tests\TestCase; /** * Class FixtureTest * * @package Tests\Models */ -class FixtureTest extends IntegrationTestCase +class FixtureTest extends TestCase { /** * @test diff --git a/tests/integration/Models/MappedTeamTest.php b/tests/integration/Models/MappedTeamTest.php index 3941249f..b5093a45 100644 --- a/tests/integration/Models/MappedTeamTest.php +++ b/tests/integration/Models/MappedTeamTest.php @@ -4,15 +4,15 @@ use LVA\Models\Team; use LVA\Models\UploadJob; -use Tests\Integration\IntegrationTestCase; use LVA\Models\MappedTeam; +use Tests\TestCase; /** * Class MappedTeamTest * * @package Tests\Models */ -class MappedTeamTest extends IntegrationTestCase +class MappedTeamTest extends TestCase { /** * @test diff --git a/tests/integration/Models/MappedVenueTest.php b/tests/integration/Models/MappedVenueTest.php index 91bc0d74..efcb1f53 100644 --- a/tests/integration/Models/MappedVenueTest.php +++ b/tests/integration/Models/MappedVenueTest.php @@ -5,14 +5,14 @@ use LVA\Models\UploadJob; use LVA\Models\Venue; use LVA\Models\MappedVenue; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class MappedVenueTest * * @package Tests\Models */ -class MappedVenueTest extends IntegrationTestCase +class MappedVenueTest extends TestCase { /** * @test diff --git a/tests/integration/Models/RoleTest.php b/tests/integration/Models/RoleTest.php index 5dca66c7..cb715730 100644 --- a/tests/integration/Models/RoleTest.php +++ b/tests/integration/Models/RoleTest.php @@ -4,14 +4,14 @@ use LVA\Models\AvailableAppointment; use LVA\Models\Role; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class RoleTest * * @package Tests\Models */ -class RoleTest extends IntegrationTestCase +class RoleTest extends TestCase { /** * @test diff --git a/tests/integration/Models/SeasonTest.php b/tests/integration/Models/SeasonTest.php index 29202625..f792ad67 100644 --- a/tests/integration/Models/SeasonTest.php +++ b/tests/integration/Models/SeasonTest.php @@ -4,14 +4,14 @@ use LVA\Models\Division; use LVA\Models\Season; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class SeasonTest * * @package Tests\Models */ -class SeasonTest extends IntegrationTestCase +class SeasonTest extends TestCase { /** * @test diff --git a/tests/integration/Models/TeamSynonymTest.php b/tests/integration/Models/TeamSynonymTest.php index 0a16d8a6..b728fda2 100644 --- a/tests/integration/Models/TeamSynonymTest.php +++ b/tests/integration/Models/TeamSynonymTest.php @@ -4,14 +4,14 @@ use LVA\Models\Team; use LVA\Models\TeamSynonym; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class TeamSynonymTest * * @package Tests\Models */ -class TeamSynonymTest extends IntegrationTestCase +class TeamSynonymTest extends TestCase { /** * @test diff --git a/tests/integration/Models/TeamTest.php b/tests/integration/Models/TeamTest.php index 8bcb635c..85ce02e7 100644 --- a/tests/integration/Models/TeamTest.php +++ b/tests/integration/Models/TeamTest.php @@ -7,14 +7,14 @@ use LVA\Models\MappedTeam; use LVA\Models\TeamSynonym; use LVA\Models\Team; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class TeamTest * * @package Tests\Models */ -class TeamTest extends IntegrationTestCase +class TeamTest extends TestCase { /** * @test diff --git a/tests/integration/Models/UploadJobDataTest.php b/tests/integration/Models/UploadJobDataTest.php index 9125ea99..223557fe 100644 --- a/tests/integration/Models/UploadJobDataTest.php +++ b/tests/integration/Models/UploadJobDataTest.php @@ -7,14 +7,14 @@ use LVA\Models\UploadJob; use LVA\Models\VenueSynonym; use LVA\Models\UploadJobData; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class UploadJobDataTest * * @package Tests\Models */ -class UploadJobDataTest extends IntegrationTestCase +class UploadJobDataTest extends TestCase { /** * @test diff --git a/tests/integration/Models/UploadJobStatusTest.php b/tests/integration/Models/UploadJobStatusTest.php index e2ce590c..21f0c659 100644 --- a/tests/integration/Models/UploadJobStatusTest.php +++ b/tests/integration/Models/UploadJobStatusTest.php @@ -6,15 +6,15 @@ use LVA\Models\Division; use LVA\Models\Team; use LVA\Models\Venue; -use Tests\Integration\IntegrationTestCase; use LVA\Models\UploadJobStatus; +use Tests\TestCase; /** * Class UploadJobStatusTest * * @package Tests\Models */ -class UploadJobStatusTest extends IntegrationTestCase +class UploadJobStatusTest extends TestCase { /** * @test @@ -41,6 +41,9 @@ public function it_gets_the_status_message() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertEquals('Unrecoverable error', $status->getStatusCodeMessage()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertEquals('Waiting for confirmation from user', $status->getStatusCodeMessage()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertEquals('Inserting records', $status->getStatusCodeMessage()); @@ -172,6 +175,16 @@ public function it_is_an_array_for_an_api_response() $this->assertInternalType('array', $statusArray['Errors']); $this->assertArrayHasKey('ErrorLine', $statusArray); + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT])->toApiArray(); + $this->assertInternalType('array', $statusArray); + $this->assertArrayHasKey('StatusCode', $statusArray); + $this->assertArrayHasKey('StatusMessage', $statusArray); + $this->assertArrayNotHasKey('Progress', $statusArray); + $this->assertArrayNotHasKey('Fixture', $statusArray); + $this->assertArrayNotHasKey('Unknowns', $statusArray); + $this->assertArrayNotHasKey('Errors', $statusArray); + $this->assertArrayNotHasKey('ErrorLine', $statusArray); + $statusArray = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS])->toApiArray(); $this->assertInternalType('array', $statusArray); $this->assertArrayHasKey('StatusCode', $statusArray); @@ -221,6 +234,9 @@ public function it_checks_if_it_has_started() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertTrue($status->hasStarted()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertTrue($status->hasStarted()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertTrue($status->hasStarted()); @@ -248,6 +264,9 @@ public function it_checks_if_it_has_not_started_yet() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertFalse($status->hasNotStarted()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertFalse($status->hasNotStarted()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertFalse($status->hasNotStarted()); @@ -275,6 +294,9 @@ public function it_checks_if_it_is_validating() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertFalse($status->isValidating()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertFalse($status->isValidating()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertFalse($status->isValidating()); @@ -285,6 +307,36 @@ public function it_checks_if_it_is_validating() $this->assertFalse($status->isValidating()); } + /** + * @test + */ + public function it_checks_if_it_is_waiting_for_user_confirmation() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED]); + $this->assertFalse($status->isWaitingConfirmation()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); + $this->assertFalse($status->isWaitingConfirmation()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); + $this->assertFalse($status->isWaitingConfirmation()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); + $this->assertFalse($status->isWaitingConfirmation()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertTrue($status->isWaitingConfirmation()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); + $this->assertFalse($status->isWaitingConfirmation()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); + $this->assertFalse($status->isWaitingConfirmation()); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); + $this->assertFalse($status->isWaitingConfirmation()); + } + /** * @test */ @@ -302,6 +354,9 @@ public function it_checks_if_it_is_inserting() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertFalse($status->isInserting()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertFalse($status->isInserting()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertTrue($status->isInserting()); @@ -329,6 +384,9 @@ public function it_checks_if_it_is_done() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertFalse($status->isDone()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertFalse($status->isDone()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertFalse($status->isDone()); @@ -356,6 +414,9 @@ public function it_checks_if_it_has_unknownd_data() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertFalse($status->hasUnknownData()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertFalse($status->hasUnknownData()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertFalse($status->hasUnknownData()); @@ -383,6 +444,9 @@ public function it_checks_if_it_can_resume() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertFalse($status->canResume()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertTrue($status->canResume()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertFalse($status->canResume()); @@ -410,6 +474,9 @@ public function it_check_if_it_is_in_the_middle_of_processing_some_data() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertFalse($status->isWorking()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertFalse($status->isWorking()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertTrue($status->isWorking()); @@ -468,6 +535,9 @@ public function it_checks_if_it_has_errors() $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR]); $this->assertTrue($status->hasErrors()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $this->assertFalse($status->hasErrors()); + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertFalse($status->hasErrors()); @@ -872,7 +942,7 @@ public function it_can_move_forward() $this->assertEquals(UploadJobStatus::STATUS_VALIDATING_RECORDS, $status->moveForward()->getStatusCode()); $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); - $this->assertEquals(UploadJobStatus::STATUS_INSERTING_RECORDS, $status->moveForward()->getStatusCode()); + $this->assertEquals(UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT, $status->moveForward()->getStatusCode()); $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $this->assertEquals(UploadJobStatus::STATUS_DONE, $status->moveForward()->getStatusCode()); @@ -914,6 +984,17 @@ public function it_cannot_move_forward_from_an_unrecoverable_insert_error() $this->expectExceptionMessage("Invalid status code " . UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR . "."); } + /** + * @test + * @expectedException \RuntimeException + */ + public function it_cannot_move_forward_from_waiting_for_user_confirmation() + { + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $status->moveForward(); + $this->expectExceptionMessage("Invalid status code " . UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT . "."); + } + /** * @test */ @@ -923,13 +1004,11 @@ public function it_can_resume() $prevStatus = clone $status; $status->resume(); $this->assertEquals($prevStatus, $status); - unset($prevStatus); $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS]); $prevStatus = clone $status; $status->resume(); $this->assertEquals($prevStatus, $status); - unset($prevStatus); $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA]); $status->resume(); @@ -940,24 +1019,24 @@ public function it_can_resume() $prevStatus = clone $status; $status->resume(); $this->assertEquals($prevStatus, $status); - unset($prevStatus); + + $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT]); + $status->resume(); + $this->assertEquals(UploadJobStatus::STATUS_INSERTING_RECORDS, $status->getStatusCode()); $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS]); $prevStatus = clone $status; $status->resume(); $this->assertEquals($prevStatus, $status); - unset($prevStatus); $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR]); $prevStatus = clone $status; $status->resume(); $this->assertEquals($prevStatus, $status); - unset($prevStatus); $status = $this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE]); $prevStatus = clone $status; $status->resume(); $this->assertEquals($prevStatus, $status); - unset($prevStatus); } } diff --git a/tests/integration/Models/UploadJobTest.php b/tests/integration/Models/UploadJobTest.php index 5b6b77e9..fe7f67b6 100644 --- a/tests/integration/Models/UploadJobTest.php +++ b/tests/integration/Models/UploadJobTest.php @@ -5,19 +5,18 @@ use Carbon\Carbon; use LVA\Models\MappedTeam; use LVA\Models\MappedVenue; -use LVA\Models\NewVenue; use LVA\Models\Season; use LVA\Models\UploadJobData; use LVA\Models\UploadJobStatus; use LVA\Models\UploadJob; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class UploadJobTest * * @package Tests\Models */ -class UploadJobTest extends IntegrationTestCase +class UploadJobTest extends TestCase { /** * @test @@ -49,21 +48,6 @@ public function it_has_many_mapped_venues() $this->assertCount(0, $jobs[1]->mappedVenues); } - /** - * @test - */ - public function it_has_many_new_venues() - { - /** @var UploadJob[] $jobs */ - $jobs = factory(UploadJob::class)->times(2)->create(); - - $venues = mt_rand(2, 10); - factory(NewVenue::class)->times($venues)->create(['upload_job_id' => $jobs[0]->getId()]); - - $this->assertCount($venues, $jobs[0]->newVenues); - $this->assertCount(0, $jobs[1]->newVenues); - } - /** * @test */ diff --git a/tests/integration/Models/VenueSynonymTest.php b/tests/integration/Models/VenueSynonymTest.php index d371029a..847e84d9 100644 --- a/tests/integration/Models/VenueSynonymTest.php +++ b/tests/integration/Models/VenueSynonymTest.php @@ -4,14 +4,14 @@ use LVA\Models\Venue; use LVA\Models\VenueSynonym; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class VenueSynonymTest * * @package Tests\Models */ -class VenueSynonymTest extends IntegrationTestCase +class VenueSynonymTest extends TestCase { /** * @test diff --git a/tests/integration/Models/VenueTest.php b/tests/integration/Models/VenueTest.php index 698a9525..8462b7fa 100644 --- a/tests/integration/Models/VenueTest.php +++ b/tests/integration/Models/VenueTest.php @@ -6,14 +6,14 @@ use LVA\Models\MappedVenue; use LVA\Models\VenueSynonym; use LVA\Models\Venue; -use Tests\Integration\IntegrationTestCase; +use Tests\TestCase; /** * Class VenueTest * * @package Tests\Models */ -class VenueTest extends IntegrationTestCase +class VenueTest extends TestCase { /** * @test diff --git a/tests/integration/Services/InteractiveFixturesUploadServiceTest.php b/tests/integration/Services/InteractiveFixturesUploadServiceTest.php index 31dc76e3..4715b209 100644 --- a/tests/integration/Services/InteractiveFixturesUploadServiceTest.php +++ b/tests/integration/Services/InteractiveFixturesUploadServiceTest.php @@ -4,8 +4,6 @@ use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions; -use LVA\Models\Season; -use LVA\Services\InteractiveFixturesUploadService; /** * Class InteractiveFixturesUploadServiceTest @@ -21,7 +19,6 @@ class InteractiveFixturesUploadServiceTest extends TestCase */ public function it_creates_a_job() { - $season = factory(Season::class)->create(); $this->markTestIncomplete(); } diff --git a/tests/unit/Api/v1/UploadApiTest.php b/tests/unit/Api/v1/UploadApiTest.php index aee4a3ed..d98002a7 100644 --- a/tests/unit/Api/v1/UploadApiTest.php +++ b/tests/unit/Api/v1/UploadApiTest.php @@ -2,6 +2,13 @@ namespace Tests\Api\v1; +use LVA\Models\Team; +use LVA\Models\UploadJob; +use LVA\Models\UploadJobStatus; +use LVA\Models\Venue; +use LVA\Services\InteractiveFixturesUploadService; +use LVA\User; +use Prophecy\Argument; use Tests\TestCase; /** @@ -16,43 +23,411 @@ class UploadApiTest extends TestCase */ public function it_resumes_a_job() { - // create a job in a resumable status + $service = $this->prophesize(InteractiveFixturesUploadService::class); + $service->processJob(Argument::any())->shouldBeCalled()->willReturn(null); + $this->app->bind(InteractiveFixturesUploadService::class, function () use ($service) { + return $service->reveal(); + }); - // calls route('resume-upload') + // Without an api token it redirects + $this->get(route('resume-upload'))->seeStatusCode(302); - // check the new status - $this->markTestIncomplete(); + /** @var User $user */ + $user = factory(User::class)->create(); + + // Without a job it fails + $this->get(route('resume-upload', ['api_token' => $user->api_token])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job parameter missing', + ]); + + // Without a valid job it fails too + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => 1])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job not found', + ]); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job resumed', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be resumed', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job resumed', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be resumed', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job resumed', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be resumed', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be resumed', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE])->toArray())->save(); + $this->get(route('resume-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be resumed', + ]); } /** * @test */ - public function it_gets_the_job_status() + public function it_abandons_a_job() { - $this->markTestIncomplete(); + $service = $this->prophesize(InteractiveFixturesUploadService::class); + $service->cleanUp(Argument::any())->shouldBeCalled()->willReturn(null); + $this->app->bind(InteractiveFixturesUploadService::class, function () use ($service) { + return $service->reveal(); + }); + + // Without an api token it redirects + $this->get(route('abandon-upload'))->seeStatusCode(302); + + /** @var User $user */ + $user = factory(User::class)->create(); + + // Without a job it fails + $this->get(route('abandon-upload', ['api_token' => $user->api_token])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job parameter missing', + ]); + + // Without a valid job it fails too + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => 1])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job not found', + ]); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_NOT_STARTED])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_VALIDATING_RECORDS])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNKNOWN_DATA])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job abandoned', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_INSERTING_RECORDS])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); + + $job->setStatus($this->uploadJobTestFactory(['status_code' => UploadJobStatus::STATUS_DONE])->toArray())->save(); + $this->get(route('abandon-upload', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job cannot be abandoned', + ]); } /** * @test */ - public function it_maps_a_team() + public function it_gets_the_job_status() { - $this->markTestIncomplete(); + // Without an api token it redirects + $this->get(route('upload-status'))->seeStatusCode(302); + + /** @var User $user */ + $user = factory(User::class)->create(); + + // Without a job it fails + $this->get(route('upload-status', ['api_token' => $user->api_token])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job parameter missing', + ]); + + // Without a valid job it fails too + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => 1])) + ->seeJsonContains([ + 'Error' => true, + 'Message' => 'Job not found', + ]); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + /** @var UploadJobStatus $status */ + $status = $this->uploadJobTestFactory(); + + $status->status_code = UploadJobStatus::STATUS_NOT_STARTED; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); + + $status->status_code = UploadJobStatus::STATUS_VALIDATING_RECORDS; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); + + $status->status_code = UploadJobStatus::STATUS_UNKNOWN_DATA; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); + + $status->status_code = UploadJobStatus::STATUS_UNRECOVERABLE_VALIDATION_ERROR; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); + + $status->status_code = UploadJobStatus::STATUS_WAITING_CONFIRMATION_TO_INSERT; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); + + $status->status_code = UploadJobStatus::STATUS_INSERTING_RECORDS; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); + + $status->status_code = UploadJobStatus::STATUS_UNRECOVERABLE_INSERT_ERROR; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); + + $status->status_code = UploadJobStatus::STATUS_DONE; + $job->setStatus($status->toArray())->save(); + $this->get(route('upload-status', ['api_token' => $user->api_token, 'job' => $job->getId()])) + ->seeJsonContains([ + 'Error' => false, + 'Message' => 'Job found', + 'Status' => $status->toApiArray(), + ]); } /** * @test */ - public function it_maps_a_venue() + public function it_maps_a_team() { - $this->markTestIncomplete(); + // Missing api token + $this->post(route('loading-map-team'))->seeStatusCode(302); + + /** @var User $user */ + $user = $this->getFakeUser(); + + // Missing job field + $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token]) + ->seeJsonContains([ + 'job' => ['The job field is required.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + // Invalid job + $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => 1]) + ->seeJsonContains([ + 'job' => ['The selected job is invalid.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + // Missing name field + $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => $job->getId()]) + ->seeJsonContains([ + 'name' => ['The name field is required.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + $name = str_random(); + // Missing newName field + $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name]) + ->seeJsonContains([ + 'newName' => ['The new name field is required.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + /** @var Team $team */ + $team = factory(Team::class)->create(); + $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name, 'newName' => $team->getName()]) + ->seeJsonContains([ + 'success' => true, + ]) + ->seeInDatabase('mapped_teams', [ + 'upload_job_id' => $job->getId(), + 'mapped_team' => $name, + 'team_id' => $team->getId(), + ]); } /** * @test */ - public function it_adds_a_venue() + public function it_maps_a_venue() { - $this->markTestIncomplete(); + // Missing api token + $this->post(route('loading-map-venue'))->seeStatusCode(302); + + /** @var User $user */ + $user = $this->getFakeUser(); + + // Missing job field + $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token]) + ->seeJsonContains([ + 'job' => ['The job field is required.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + // Invalid job + $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => 1]) + ->seeJsonContains([ + 'job' => ['The selected job is invalid.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + /** @var UploadJob $job */ + $job = factory(UploadJob::class)->create(); + + // Missing name field + $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => $job->getId()]) + ->seeJsonContains([ + 'name' => ['The name field is required.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + $name = str_random(); + // Missing newName field + $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name]) + ->seeJsonContains([ + 'newName' => ['The new name field is required.'], + ]) + ->dontSeeJson([ + 'success' => true, + ]); + + /** @var Venue $venue */ + $venue = factory(Venue::class)->create(); + $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name, 'newName' => $venue->getName()]) + ->seeJsonContains([ + 'success' => true, + ]) + ->seeInDatabase('mapped_venues', [ + 'upload_job_id' => $job->getId(), + 'mapped_venue' => $name, + 'venue_id' => $venue->getId(), + ]); } } From 8fbe18a87d23de00f3df71cf47ecd0984183428c Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 20 Mar 2017 19:25:01 +0000 Subject: [PATCH 57/62] lva-22: refactor the API tests --- tests/unit/Api/v1/UploadApiTest.php | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/unit/Api/v1/UploadApiTest.php b/tests/unit/Api/v1/UploadApiTest.php index d98002a7..1116e43b 100644 --- a/tests/unit/Api/v1/UploadApiTest.php +++ b/tests/unit/Api/v1/UploadApiTest.php @@ -309,13 +309,15 @@ public function it_gets_the_job_status() public function it_maps_a_team() { // Missing api token - $this->post(route('loading-map-team'))->seeStatusCode(302); + $data = []; + $this->post(route('loading-map-team'), $data)->seeStatusCode(302); /** @var User $user */ - $user = $this->getFakeUser(); + $user = factory(User::class)->create(); // Missing job field - $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token]) + $data['api_token'] = $user->api_token; + $this->json('POST', route('loading-map-team'), $data) ->seeJsonContains([ 'job' => ['The job field is required.'], ]) @@ -324,7 +326,8 @@ public function it_maps_a_team() ]); // Invalid job - $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => 1]) + $data['job'] = 1; + $this->json('POST', route('loading-map-team'), $data) ->seeJsonContains([ 'job' => ['The selected job is invalid.'], ]) @@ -336,7 +339,8 @@ public function it_maps_a_team() $job = factory(UploadJob::class)->create(); // Missing name field - $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => $job->getId()]) + $data['job'] = $job->getId(); + $this->json('POST', route('loading-map-team'), $data) ->seeJsonContains([ 'name' => ['The name field is required.'], ]) @@ -346,7 +350,8 @@ public function it_maps_a_team() $name = str_random(); // Missing newName field - $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name]) + $data['name'] = $name; + $this->json('POST', route('loading-map-team'), $data) ->seeJsonContains([ 'newName' => ['The new name field is required.'], ]) @@ -356,7 +361,8 @@ public function it_maps_a_team() /** @var Team $team */ $team = factory(Team::class)->create(); - $this->json('POST', route('loading-map-team'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name, 'newName' => $team->getName()]) + $data['newName'] = $team->getName(); + $this->json('POST', route('loading-map-team'), $data) ->seeJsonContains([ 'success' => true, ]) @@ -373,13 +379,15 @@ public function it_maps_a_team() public function it_maps_a_venue() { // Missing api token - $this->post(route('loading-map-venue'))->seeStatusCode(302); + $data = []; + $this->post(route('loading-map-venue'), $data)->seeStatusCode(302); /** @var User $user */ - $user = $this->getFakeUser(); + $user = factory(User::class)->create(); // Missing job field - $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token]) + $data['api_token'] = $user->api_token; + $this->json('POST', route('loading-map-venue'), $data) ->seeJsonContains([ 'job' => ['The job field is required.'], ]) @@ -388,7 +396,8 @@ public function it_maps_a_venue() ]); // Invalid job - $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => 1]) + $data['job'] = 1; + $this->json('POST', route('loading-map-venue'), $data) ->seeJsonContains([ 'job' => ['The selected job is invalid.'], ]) @@ -400,7 +409,8 @@ public function it_maps_a_venue() $job = factory(UploadJob::class)->create(); // Missing name field - $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => $job->getId()]) + $data['job'] = $job->getId(); + $this->json('POST', route('loading-map-venue'), $data) ->seeJsonContains([ 'name' => ['The name field is required.'], ]) @@ -410,7 +420,8 @@ public function it_maps_a_venue() $name = str_random(); // Missing newName field - $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name]) + $data['name'] = $name; + $this->json('POST', route('loading-map-venue'), $data) ->seeJsonContains([ 'newName' => ['The new name field is required.'], ]) @@ -420,7 +431,8 @@ public function it_maps_a_venue() /** @var Venue $venue */ $venue = factory(Venue::class)->create(); - $this->json('POST', route('loading-map-venue'), ['api_token' => $user->api_token, 'job' => $job->getId(), 'name' => $name, 'newName' => $venue->getName()]) + $data['newName'] = $venue->getName(); + $this->json('POST', route('loading-map-venue'), $data) ->seeJsonContains([ 'success' => true, ]) From 624a15da4b718ec4694a030c44455d85414b9769 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Mon, 20 Mar 2017 19:25:28 +0000 Subject: [PATCH 58/62] dev: removed the getFakeUser method from TestCase --- tests/TestCase.php | 31 -------- .../AvailableAppointmentResourceTest.php | 21 ++++-- .../Admin/DataManagement/ClubResourceTest.php | 21 ++++-- .../DataManagement/DivisionResourceTest.php | 21 ++++-- .../DataManagement/FixtureResourceTest.php | 21 ++++-- .../Admin/DataManagement/RoleResourceTest.php | 21 ++++-- .../DataManagement/SeasonResourceTest.php | 21 ++++-- .../Admin/DataManagement/TeamResourceTest.php | 21 ++++-- .../DataManagement/VenueResourceTest.php | 21 ++++-- tests/unit/Admin/DataManagementTest.php | 37 +++++++--- tests/unit/Authentication/LoginLogoutTest.php | 73 ++++++++++++------- .../unit/Authentication/PasswordResetTest.php | 20 +++-- .../unit/Authentication/RegistrationTest.php | 17 ++--- tests/unit/HomePageTest.php | 12 +-- 14 files changed, 226 insertions(+), 132 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index ff03d9c4..0227236f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -29,7 +29,6 @@ class TestCase extends \Illuminate\Foundation\Testing\TestCase { protected static $refreshDatabase = true; - protected $users = []; /** @var Generator */ protected $faker; /** @@ -120,36 +119,6 @@ protected function uploadJobTestFactory($overrides = []) return UploadJobStatus::factory(array_merge($defaults, $overrides)); } - /** - * @param int|null $userId - * - * @return mixed - */ - protected function getFakeUser($userId = null) - { - if (is_null($userId)) { - $password = str_random(10); - $user = factory(User::class) - ->create([ - 'password' => bcrypt($password), - ]); - $user->clearPassword = $password; - $userId = $user->id; - $this->users[$userId] = $user; - } elseif (!isset($this->users[$userId])) { - $password = str_random(10); - $user = factory(User::class) - ->create([ - 'id' => $userId, - 'password' => bcrypt($password), - ]); - $user->clearPassword = $password; - $this->users[$userId] = $user; - } - - return $this->users[$userId]; - } - /** * @param string $routeName * @param string $breadcrumb diff --git a/tests/unit/Admin/DataManagement/AvailableAppointmentResourceTest.php b/tests/unit/Admin/DataManagement/AvailableAppointmentResourceTest.php index 2cb1c063..dcceb7a2 100644 --- a/tests/unit/Admin/DataManagement/AvailableAppointmentResourceTest.php +++ b/tests/unit/Admin/DataManagement/AvailableAppointmentResourceTest.php @@ -8,6 +8,7 @@ namespace Admin\DataManagement; +use LVA\User; use Tests\TestCase; use LVA\Models\AvailableAppointment; use LVA\Models\Fixture; @@ -43,13 +44,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Available appointments'); } public function testAddAvailableAppointment() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var AvailableAppointment $appointment */ $appointment = factory(AvailableAppointment::class)->make(); @@ -107,7 +112,9 @@ public function testAddAvailableAppointment() public function testEditAvailableAppointment() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var AvailableAppointment $appointment */ $appointment = factory(AvailableAppointment::class)->create(); @@ -212,7 +219,9 @@ public function testEditAvailableAppointment() public function testShowAvailableAppointment() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var AvailableAppointment $appointment */ $appointment = factory(AvailableAppointment::class)->create(); @@ -225,7 +234,9 @@ public function testShowAvailableAppointment() public function testDeleteAvailableAppointment() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var AvailableAppointment $appointment */ $appointment = factory(AvailableAppointment::class)->create(); diff --git a/tests/unit/Admin/DataManagement/ClubResourceTest.php b/tests/unit/Admin/DataManagement/ClubResourceTest.php index 608b3bea..4fb79d5b 100644 --- a/tests/unit/Admin/DataManagement/ClubResourceTest.php +++ b/tests/unit/Admin/DataManagement/ClubResourceTest.php @@ -9,6 +9,7 @@ namespace Admin\DataManagement; use LVA\Models\Team; +use LVA\User; use Tests\TestCase; use LVA\Models\Club; @@ -42,13 +43,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Clubs'); } public function testAddClub() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Club $club */ $club = factory(Club::class)->make(); @@ -76,7 +81,9 @@ public function testAddClub() public function testEditClub() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Club $club */ $club = factory(Club::class)->create(); @@ -135,7 +142,9 @@ public function testEditClub() public function testShowClub() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Club $club */ $club = factory(Club::class)->create(); @@ -147,7 +156,9 @@ public function testShowClub() public function testDeleteClub() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Club $club */ $club = factory(Club::class)->create(); diff --git a/tests/unit/Admin/DataManagement/DivisionResourceTest.php b/tests/unit/Admin/DataManagement/DivisionResourceTest.php index 9518570c..b823918f 100644 --- a/tests/unit/Admin/DataManagement/DivisionResourceTest.php +++ b/tests/unit/Admin/DataManagement/DivisionResourceTest.php @@ -9,6 +9,7 @@ namespace Admin\DataManagement; use LVA\Models\Fixture; +use LVA\User; use Tests\TestCase; use LVA\Models\Division; use LVA\Models\Season; @@ -43,13 +44,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Divisions'); } public function testAddDivision() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Division $division */ $division = factory(Division::class)->make(); @@ -81,7 +86,9 @@ public function testAddDivision() public function testEditDivision() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Division $division */ $division = factory(Division::class)->create(); @@ -168,7 +175,9 @@ public function testEditDivision() public function testShowDivision() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Division $division */ $division = factory(Division::class)->create(); @@ -181,7 +190,9 @@ public function testShowDivision() public function testDeleteDivision() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Division $division */ $division = factory(Division::class)->create(); diff --git a/tests/unit/Admin/DataManagement/FixtureResourceTest.php b/tests/unit/Admin/DataManagement/FixtureResourceTest.php index ca762695..8ee6758f 100644 --- a/tests/unit/Admin/DataManagement/FixtureResourceTest.php +++ b/tests/unit/Admin/DataManagement/FixtureResourceTest.php @@ -9,6 +9,7 @@ namespace Admin\DataManagement; use LVA\Models\AvailableAppointment; +use LVA\User; use Tests\TestCase; use LVA\Models\Fixture; @@ -42,13 +43,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Fixtures'); } public function testAddFixture() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->make(); @@ -125,7 +130,9 @@ public function testAddFixture() public function testEditFixture() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(); @@ -235,7 +242,9 @@ public function testEditFixture() public function testShowFixture() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(); @@ -254,7 +263,9 @@ public function testShowFixture() public function testDeleteFixture() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(); diff --git a/tests/unit/Admin/DataManagement/RoleResourceTest.php b/tests/unit/Admin/DataManagement/RoleResourceTest.php index 93973989..fbded3e5 100644 --- a/tests/unit/Admin/DataManagement/RoleResourceTest.php +++ b/tests/unit/Admin/DataManagement/RoleResourceTest.php @@ -9,6 +9,7 @@ namespace Admin\DataManagement; use LVA\Models\AvailableAppointment; +use LVA\User; use Tests\TestCase; use LVA\Models\Role; @@ -42,13 +43,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Roles'); } public function testAddRole() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Role $role */ $role = factory(Role::class)->make(); @@ -76,7 +81,9 @@ public function testAddRole() public function testEditRole() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Role $role */ $role = factory(Role::class)->create(); @@ -134,7 +141,9 @@ public function testEditRole() public function testShowRole() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Role $role */ $role = factory(Role::class)->create(); @@ -146,7 +155,9 @@ public function testShowRole() public function testDeleteRole() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Role $role */ $role = factory(Role::class)->create(); diff --git a/tests/unit/Admin/DataManagement/SeasonResourceTest.php b/tests/unit/Admin/DataManagement/SeasonResourceTest.php index 8750d2aa..c54d40f9 100644 --- a/tests/unit/Admin/DataManagement/SeasonResourceTest.php +++ b/tests/unit/Admin/DataManagement/SeasonResourceTest.php @@ -9,6 +9,7 @@ namespace Admin\DataManagement; use LVA\Models\Division; +use LVA\User; use PhpParser\Node\Expr\AssignOp\Div; use Tests\TestCase; use LVA\Models\Season; @@ -43,13 +44,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Seasons'); } public function testAddSeason() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Season $season */ $season = factory(Season::class)->make(); @@ -77,7 +82,9 @@ public function testAddSeason() public function testEditSeason() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Season $season */ $season = factory(Season::class)->create(); @@ -136,7 +143,9 @@ public function testEditSeason() public function testShowSeason() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Season $season */ $season = factory(Season::class)->create(); @@ -148,7 +157,9 @@ public function testShowSeason() public function testDeleteSeason() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Season $season */ $season = factory(Season::class)->create(); diff --git a/tests/unit/Admin/DataManagement/TeamResourceTest.php b/tests/unit/Admin/DataManagement/TeamResourceTest.php index fc384a5e..a76afec6 100644 --- a/tests/unit/Admin/DataManagement/TeamResourceTest.php +++ b/tests/unit/Admin/DataManagement/TeamResourceTest.php @@ -9,6 +9,7 @@ namespace Admin\DataManagement; use LVA\Models\Fixture; +use LVA\User; use Tests\TestCase; use LVA\Models\Team; use LVA\Models\Club; @@ -43,13 +44,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Teams'); } public function testAddTeam() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Team $team */ $team = factory(Team::class)->make(); @@ -81,7 +86,9 @@ public function testAddTeam() public function testEditTeam() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Team $team */ $team = factory(Team::class)->create(); @@ -166,7 +173,9 @@ public function testEditTeam() public function testShowTeam() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Team $team */ $team = factory(Team::class)->create(); @@ -179,7 +188,9 @@ public function testShowTeam() public function testDeleteTeam() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Team $team */ $team = factory(Team::class)->create(); diff --git a/tests/unit/Admin/DataManagement/VenueResourceTest.php b/tests/unit/Admin/DataManagement/VenueResourceTest.php index 4b4c40f9..8d221474 100644 --- a/tests/unit/Admin/DataManagement/VenueResourceTest.php +++ b/tests/unit/Admin/DataManagement/VenueResourceTest.php @@ -9,6 +9,7 @@ namespace Admin\DataManagement; use LVA\Models\Fixture; +use LVA\User; use Tests\TestCase; use LVA\Models\Venue; @@ -42,13 +43,17 @@ public function testRedirectIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests(self::BASE_ROUTE . '.index', 'Venues'); } public function testAddVenue() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Venue $venue */ $venue = factory(Venue::class)->make(); @@ -76,7 +81,9 @@ public function testAddVenue() public function testEditVenue() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Venue $venue */ $venue = factory(Venue::class)->create(); @@ -135,7 +142,9 @@ public function testEditVenue() public function testShowVenue() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Venue $venue */ $venue = factory(Venue::class)->create(); @@ -147,7 +156,9 @@ public function testShowVenue() public function testDeleteVenue() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); /** @var Venue $venue */ $venue = factory(Venue::class)->create(); diff --git a/tests/unit/Admin/DataManagementTest.php b/tests/unit/Admin/DataManagementTest.php index 0b681aeb..bbdb5741 100644 --- a/tests/unit/Admin/DataManagementTest.php +++ b/tests/unit/Admin/DataManagementTest.php @@ -8,6 +8,7 @@ namespace Admin; +use LVA\User; use Tests\TestCase; class DataManagementTest extends TestCase @@ -20,14 +21,18 @@ public function testRedirectToLoginIfNotAdmin() public function testBreadcrumbs() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->breadcrumbsTests('admin::dataManagement', 'Data Management'); } public function testSeasonsTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Seasons', route('admin.data-management.seasons.index')); @@ -35,7 +40,9 @@ public function testSeasonsTableButton() public function testDivisionsTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Divisions', route('admin.data-management.divisions.index')); @@ -43,7 +50,9 @@ public function testDivisionsTableButton() public function testVenuesTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Venues', route('admin.data-management.venues.index')); @@ -51,7 +60,9 @@ public function testVenuesTableButton() public function testClubsTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Clubs', route('admin.data-management.clubs.index')); @@ -59,7 +70,9 @@ public function testClubsTableButton() public function testTeamsTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Teams', route('admin.data-management.teams.index')); @@ -67,7 +80,9 @@ public function testTeamsTableButton() public function testRolesTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Roles', route('admin.data-management.roles.index')); @@ -75,7 +90,9 @@ public function testRolesTableButton() public function testFixturesTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Fixtures', route('admin.data-management.fixtures.index')); @@ -83,7 +100,9 @@ public function testFixturesTableButton() public function testAvailableAppointmentsTableButton() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('admin::dataManagement')) ->seeLink('Available appointments', route('admin.data-management.available-appointments.index')); diff --git a/tests/unit/Authentication/LoginLogoutTest.php b/tests/unit/Authentication/LoginLogoutTest.php index 5bbbcf84..1a9e130b 100644 --- a/tests/unit/Authentication/LoginLogoutTest.php +++ b/tests/unit/Authentication/LoginLogoutTest.php @@ -2,19 +2,11 @@ namespace Authentication; +use LVA\User; use Tests\TestCase; class LoginLogoutTest extends TestCase { - private $admin; - - protected function setUp() - { - parent::setUp(); - - $this->admin = $this->getFakeUser(); - } - public function testLoginLinkExists() { $this->visit(route('home')) @@ -28,7 +20,9 @@ public function testBreadcrumbs() public function testCannotLoginWhenAlreadyLoggedIn() { - $this->be($this->admin); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('login')) ->seePageIs(route('home')); @@ -46,19 +40,27 @@ public function testLoginPageExists() public function testSuccessfulLogin() { + $password = $this->faker->unique()->password; + /** @var User $user */ + $user = factory(User::class)->create(['password' => bcrypt($password)]); + $this->visit(route('login')) - ->type($this->admin->email, 'email') - ->type($this->admin->clearPassword, 'password') + ->type($user->email, 'email') + ->type($password, 'password') ->press('Login') ->seePageIs(route('home')) - ->seeInElement('nav .navbar-right li.dropdown a', $this->admin->name); + ->seeInElement('nav .navbar-right li.dropdown a', $user->name); } public function testWrongPassword() { + $password = $this->faker->unique()->password; + /** @var User $user */ + $user = factory(User::class)->create(['password' => bcrypt($password)]); + $this->visit(route('login')) - ->type($this->admin->email, 'email') - ->type($this->admin->clearPassword . 'abc', 'password') + ->type($user->email, 'email') + ->type($password . 'abc', 'password') ->press('Login') ->seeInElement('span.help-block', 'These credentials do not match our records.') ->seePageIs(route('login')); @@ -67,9 +69,13 @@ public function testWrongPassword() public function testWrongEmail() { + $password = $this->faker->unique()->password; + /** @var User $user */ + $user = factory(User::class)->create(['password' => bcrypt($password)]); + $this->visit(route('login')) - ->type($this->admin->email . '.com', 'email') - ->type($this->admin->clearPassword, 'password') + ->type($user->email . '.com', 'email') + ->type($password, 'password') ->press('Login') ->seeInElement('span.help-block', 'These credentials do not match our records.') ->seePageIs(route('login')); @@ -78,9 +84,13 @@ public function testWrongEmail() public function testWrongEmailAndPassword() { + $password = $this->faker->unique()->password; + /** @var User $user */ + $user = factory(User::class)->create(['password' => bcrypt($password)]); + $this->visit(route('login')) - ->type($this->admin->email . '.com', 'email') - ->type($this->admin->clearPassword . 'abc', 'password') + ->type($user->email . '.com', 'email') + ->type($password . 'abc', 'password') ->press('Login') ->seeInElement('span.help-block', 'These credentials do not match our records.') ->seePageIs(route('login')); @@ -88,8 +98,12 @@ public function testWrongEmailAndPassword() public function testMissingEmail() { + $password = $this->faker->unique()->password; + /** @var User $user */ + $user = factory(User::class)->create(['password' => bcrypt($password)]); + $this->visit(route('login')) - ->type($this->admin->clearPassword . 'abc', 'password') + ->type($password, 'password') ->press('Login') ->seeInElement('span.help-block', 'The email field is required.') ->seePageIs(route('login')); @@ -97,8 +111,12 @@ public function testMissingEmail() public function testMissingPassword() { + $password = $this->faker->unique()->password; + /** @var User $user */ + $user = factory(User::class)->create(['password' => bcrypt($password)]); + $this->visit(route('login')) - ->type($this->admin->email . '.com', 'email') + ->type($user->email, 'email') ->press('Login') ->seeInElement('span.help-block', 'The password field is required.') ->seePageIs(route('login')); @@ -115,7 +133,10 @@ public function testMissingEmailAndPassword() public function testLogoutLinkExist() { - $this->be($this->admin); + /** @var User $user */ + $user = factory(User::class)->create(); + + $this->be($user); $this->visit(route('home')) ->seeLink('Logout', route('logout')); @@ -123,9 +144,11 @@ public function testLogoutLinkExist() public function testSuccessfulLogout() { - unset($this->admin->clearPassword); - $this->be($this->admin); - + /** @var User $user */ + $user = factory(User::class)->create(); + + $this->be($user); + $this->visit(route('home')) ->click('Logout') ->seePageIs(route('home')); diff --git a/tests/unit/Authentication/PasswordResetTest.php b/tests/unit/Authentication/PasswordResetTest.php index 2a29cd03..a6e3c267 100644 --- a/tests/unit/Authentication/PasswordResetTest.php +++ b/tests/unit/Authentication/PasswordResetTest.php @@ -8,19 +8,11 @@ namespace Authentication; +use LVA\User; use Tests\TestCase; class PasswordResetTest extends TestCase { - private $admin; - - protected function setUp() - { - parent::setUp(); - - $this->admin = $this->getFakeUser(); - } - public function testBreadcrumbs() { $this->breadcrumbsTests('passwordReset', 'Reset Password'); @@ -41,8 +33,11 @@ public function testPasswordResetPageExists() public function testSuccessfulPasswordReset() { + /** @var User $user */ + $user = factory(User::class)->create(); + $this->visit(route('passwordReset')) - ->type($this->admin->email, 'email') + ->type($user->email, 'email') ->press('Send Password Reset Link') ->seeInElement('.alert', 'We have e-mailed your password reset link!') ->seeInField('email', ''); @@ -66,8 +61,11 @@ public function testInvalidEmail() public function testNonExistingEmail() { + /** @var User $user */ + $user = factory(User::class)->create(); + $this->visit(route('passwordReset')) - ->type($this->admin->email . '.com', 'email') + ->type($user->email . '.com', 'email') ->press('Send Password Reset Link') ->seeInElement('span.help-block', 'We can\'t find a user with that e-mail address.') ->seeInField('email', ''); diff --git a/tests/unit/Authentication/RegistrationTest.php b/tests/unit/Authentication/RegistrationTest.php index 39846d99..38762e54 100644 --- a/tests/unit/Authentication/RegistrationTest.php +++ b/tests/unit/Authentication/RegistrationTest.php @@ -8,19 +8,11 @@ namespace Authentication; +use LVA\User; use Tests\TestCase; class RegistrationTest extends TestCase { - private $admin; - - protected function setUp() - { - parent::setUp(); - - $this->admin = $this->getFakeUser(); - } - public function testRegistrationLinkExists() { $this->visit(route('home')) @@ -45,7 +37,10 @@ public function testRegistrationPageExists() public function testCannotRegisterWhenAlreadyLoggedIn() { - $this->be($this->admin); + /** @var User $user */ + $user = factory(User::class)->create(); + + $this->be($user); $this->visit(route('register')) ->seePageIs(route('home')); @@ -113,7 +108,7 @@ public function testInvalidEmail() public function testAlreadyUsedEmail() { - // Register one user + // Register one user $this->visit(route('register')) ->type('Test user 1', 'name') ->type('test1@example.com', 'email') diff --git a/tests/unit/HomePageTest.php b/tests/unit/HomePageTest.php index d51a45fc..54e6381f 100644 --- a/tests/unit/HomePageTest.php +++ b/tests/unit/HomePageTest.php @@ -2,6 +2,8 @@ namespace Tests; +use LVA\User; + class HomePageTest extends TestCase { public function testLandingPage() @@ -14,7 +16,7 @@ public function testBreadcrumbs() $page = $this->visit(route('home')); $this->assertEquals(0, $page->crawler->filter('#breadcrumbs')->count()); } - + public function testLoginAndRegisterLinksExist() { $this->visit(route('home')) @@ -28,18 +30,18 @@ public function testPanelsForNonAdminUser() $this->visit(route('home')) //->seeLink('Available matches', route('availableMatches')) ->seeLink('Available matches') - //->dontSeeLink('Data management', route('admin::dataManagement')); ->dontSeeLink('Data management'); } public function testPanelForAdmin() { - $this->be($this->getFakeUser()); + /** @var User $user */ + $user = factory(User::class)->create(); + $this->be($user); $this->visit(route('home')) //->seeLink('Available matches', route('availableMatches')) ->seeLink('Available matches') - //->seeLink('Data management', route('admin::dataManagement')); - ->seeLink('Data management'); + ->seeLink('Data management', route('admin::dataManagement')); } } From f805f8f41e4fa0ed4ec993f965c4ca42d7ff2933 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Fri, 14 Apr 2017 15:49:20 +0100 Subject: [PATCH 59/62] lva-22: removed commented line --- app/Services/InteractiveFixturesUploadService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Services/InteractiveFixturesUploadService.php b/app/Services/InteractiveFixturesUploadService.php index 36b7413c..6dbfdd7c 100644 --- a/app/Services/InteractiveFixturesUploadService.php +++ b/app/Services/InteractiveFixturesUploadService.php @@ -287,7 +287,6 @@ public function processJob(UploadJob $job) /** @var Model $model */ $model = unserialize($row->model_data); $model->save(); - //$model->save(json_decode($row->model_data, true)); unset($model); } } catch (\Exception $e) { From 0c91a582c7396126ea92d72a64330001fceaaa4c Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Fri, 14 Apr 2017 16:00:44 +0100 Subject: [PATCH 60/62] dev: remove the lva-22-interactive-loading branch from .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f50aecc2..78f52577 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ branches: only: - master - dev - - lva-22-interactive-loading notifications: email: on_success: always From a01c23fc755ad8882b9cd1648ae923fde6e4577f Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Fri, 14 Apr 2017 16:02:20 +0100 Subject: [PATCH 61/62] dev: renamed env.travis to .env.travis --- .gitignore | 1 + .travis.yml | 2 +- env.travis | 12 ------------ 3 files changed, 2 insertions(+), 13 deletions(-) delete mode 100644 env.travis diff --git a/.gitignore b/.gitignore index df398aa2..43cc445b 100755 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ storage/ .env .env.* !.env.example +!.env.travis _ide_helper.php _ide_helper_models.php /Vagrantfile diff --git a/.travis.yml b/.travis.yml index 78f52577..3770b446 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_script: - npm install - composer install --no-interaction - export DISABLE_NOTIFIER=true; node_modules/gulp/bin/gulp.js - - cp env.travis .env + - cp .env.travis .env - php artisan key:generate - mysql -e 'create database lva_testing;' script: diff --git a/env.travis b/env.travis deleted file mode 100644 index 0a6f4555..00000000 --- a/env.travis +++ /dev/null @@ -1,12 +0,0 @@ -APP_ENV=travis -APP_DEBUG=true -APP_KEY=SomeRandomString - -DB_USERNAME=root -DB_PASSWORD= - -CACHE_DRIVER=array -SESSION_DRIVER=array -QUEUE_DRIVER=sync - -MAIL_DRIVER=log From d22f5a66254688f65856f78a037cf1c80c752728 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli Date: Fri, 14 Apr 2017 16:13:00 +0100 Subject: [PATCH 62/62] dev: undo commit a01c23f (renamed env.travis to .env.travis) --- .gitignore | 1 - .travis.yml | 2 +- env.travis | 12 ++++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 env.travis diff --git a/.gitignore b/.gitignore index 43cc445b..df398aa2 100755 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ storage/ .env .env.* !.env.example -!.env.travis _ide_helper.php _ide_helper_models.php /Vagrantfile diff --git a/.travis.yml b/.travis.yml index 3770b446..78f52577 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_script: - npm install - composer install --no-interaction - export DISABLE_NOTIFIER=true; node_modules/gulp/bin/gulp.js - - cp .env.travis .env + - cp env.travis .env - php artisan key:generate - mysql -e 'create database lva_testing;' script: diff --git a/env.travis b/env.travis new file mode 100644 index 00000000..0a6f4555 --- /dev/null +++ b/env.travis @@ -0,0 +1,12 @@ +APP_ENV=travis +APP_DEBUG=true +APP_KEY=SomeRandomString + +DB_USERNAME=root +DB_PASSWORD= + +CACHE_DRIVER=array +SESSION_DRIVER=array +QUEUE_DRIVER=sync + +MAIL_DRIVER=log