diff --git a/.travis/deploy_script.sh b/.travis/deploy_script.sh index 8da3714f..d9441b09 100755 --- a/.travis/deploy_script.sh +++ b/.travis/deploy_script.sh @@ -55,6 +55,7 @@ if [ "$TRAVIS" = "true" ]; then .sass-cache .idea .travis + docker tests _ide_helper.php .dpl @@ -64,6 +65,7 @@ if [ "$TRAVIS" = "true" ]; then .styleci.yml env.php config.php + docker-compose.yml Makefile phpunit.xml phpvms.iml diff --git a/Makefile b/Makefile index 9f46b63d..f8fdd70e 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ update: build @echo "Done!" .PHONY: reset -reset: cleanapp/Models/Traits/JournalTrait.php +reset: clean @php $(COMPOSER) dump-autoload @make reload-db diff --git a/Procfile b/Procfile index e37f7486..340b8c19 100644 --- a/Procfile +++ b/Procfile @@ -1,5 +1,5 @@ -dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground +#dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground php-fpm: /usr/local/sbin/php-fpm --nodaemonize nginx: /usr/local/bin/nginx -g 'daemon off;' -#mysql: /usr/local/bin/mysqld +mysql: docker-compose --file ~/docker/mysql/docker-compose.yml up #mailhog: /usr/local/bin/mailhog diff --git a/README.md b/README.md index fbc9d536..f8a56265 100755 --- a/README.md +++ b/README.md @@ -2,16 +2,15 @@ [](https://travis-ci.org/nabeelio/phpvms) [](https://www.codacy.com/app/nabeelio/phpvms?utm_source=github.com&utm_medium=referral&utm_content=nabeelio/phpvms&utm_campaign=Badge_Grade) [](https://packagist.org/packages/nabeel/phpvms)  [](https://packagist.org/packages/nabeel/phpvms) -The next phpvms version built on the laravel framework. work in progress. If you're looking for -the old, phpVMS classic, it's [available here](https://github.com/nabeelio/phpvms_v2). +The next phpvms version built on the laravel framework. work in progress. The latest documentation, with installation instructions is available + [on the phpVMS documentation](http://docs.phpvms.net/) page. # installation A full distribution, with all of the composer dependencies, is available at this [GitHub Releases](https://github.com/nabeelio/phpvms/releases) link. -The latest documentation, with installation instructions is available -[on the phpVMS documentation](http://docs.phpvms.net/) page. + ## Requirements @@ -30,6 +29,22 @@ The latest documentation, with installation instructions is available ## Installer 1. Upload to your server -2. Visit the site, and follow the link to the installer +1. Visit the site, and follow the link to the installer [View installation details](http://docs.phpvms.net/setup/installation) + +# development environment + +A full development environment can be brought up using Docker: + +```bash +composer install +npm install +docker-compose up +``` + +Then go to `http://localhost`. If you're using dnsmasq, the `app` container is listening on `phpvms.test`, or you can add to your `/etc/hosts` file: + +``` +127.0.0.1 phpvms.test +``` diff --git a/app/Database/factories/FlightFactory.php b/app/Database/factories/FlightFactory.php index 327ba2f4..412c30df 100644 --- a/app/Database/factories/FlightFactory.php +++ b/app/Database/factories/FlightFactory.php @@ -22,7 +22,7 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) { 'alt_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'distance' => $faker->numberBetween(0, 3000), + 'distance' => $faker->numberBetween(0, 1000), 'route' => null, 'level' => 0, 'dpt_time' => $faker->time(), @@ -35,7 +35,7 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) { 'start_date' => null, 'end_date' => null, 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), - 'updated_at' => function (array $flight) { + 'updated_at' => static function (array $flight) { return $flight['created_at']; }, ]; diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index a27613cf..b67515b7 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -89,31 +89,37 @@ class FlightController extends Controller */ public function search(Request $request) { - $user = Auth::user(); - - try { - $where = [ - 'active' => true, - 'visible' => true, - ]; + $where = [ + 'active' => true, + 'visible' => true, + ]; + // Allow the option to bypass some of these restrictions for the searches + if (!$request->filled('ignore_restrictions') + || $request->get('ignore_restrictions') === '0' + ) { if (setting('pilots.restrict_to_company')) { $where['airline_id'] = Auth::user()->airline_id; } + if (setting('pilots.only_flights_from_current')) { $where['dpt_airport_id'] = Auth::user()->curr_airport_id; } + } + try { + $this->flightRepo->resetCriteria(); $this->flightRepo->searchCriteria($request); - $this->flightRepo->pushCriteria(new RequestCriteria($request)); $this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); + $this->flightRepo->pushCriteria(new RequestCriteria($request)); + $flights = $this->flightRepo->paginate(); } catch (RepositoryException $e) { return response($e, 503); } foreach ($flights as $flight) { - $this->flightSvc->filterSubfleets($user, $flight); + $this->flightSvc->filterSubfleets(Auth::user(), $flight); } return FlightResource::collection($flights); diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index ae5bb966..bb06e139 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -13,6 +13,7 @@ use Flash; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Log; +use Prettus\Repository\Criteria\RequestCriteria; use Prettus\Repository\Exceptions\RepositoryException; /** @@ -68,6 +69,7 @@ class FlightController extends Controller try { $this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); + $this->flightRepo->pushCriteria(new RequestCriteria($request)); } catch (RepositoryException $e) { Log::emergency($e); } @@ -137,6 +139,8 @@ class FlightController extends Controller $where['dpt_airport_id'] = Auth::user()->curr_airport_id; } + $this->flightRepo->resetCriteria(); + try { $this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); } catch (RepositoryException $e) { diff --git a/app/Http/Controllers/Frontend/HomeController.php b/app/Http/Controllers/Frontend/HomeController.php index aba33070..93ae315d 100644 --- a/app/Http/Controllers/Frontend/HomeController.php +++ b/app/Http/Controllers/Frontend/HomeController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Frontend; use App\Interfaces\Controller; use App\Models\User; use Illuminate\Database\QueryException; +use Log; /** * Class HomeController @@ -18,10 +19,21 @@ class HomeController extends Controller { try { $users = User::orderBy('created_at', 'desc')->take(4)->get(); + debug($users); + } catch (\PDOException $e) { + Log::emergency($e); + return view('system/errors/database_error', [ + 'error' => $e->getMessage(), + ]); } catch (QueryException $e) { return view('system/errors/not_installed'); } + // No users + if (!$users) { + return view('system/errors/not_installed'); + } + return view('home', [ 'users' => $users, ]); diff --git a/app/Repositories/Criteria/WhereCriteria.php b/app/Repositories/Criteria/WhereCriteria.php index 97fb2caf..906b4f99 100644 --- a/app/Repositories/Criteria/WhereCriteria.php +++ b/app/Repositories/Criteria/WhereCriteria.php @@ -18,6 +18,12 @@ class WhereCriteria implements CriteriaInterface protected $request; protected $where; + /** + * Create a new Where search. + * + * @param $request + * @param $where + */ public function __construct($request, $where) { $this->request = $request; diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php index ee789744..4850f4aa 100644 --- a/app/Repositories/FlightRepository.php +++ b/app/Repositories/FlightRepository.php @@ -18,15 +18,16 @@ class FlightRepository extends Repository implements CacheableInterface protected $fieldSearchable = [ 'arr_airport_id', + 'distance', 'dpt_airport_id', 'flight_number' => 'like', - 'flight_code' => 'like', - 'flight_leg' => 'like', + 'route_code' => 'like', + 'route_leg' => 'like', 'route' => 'like', 'notes' => 'like', ]; - public function model() + public function model(): string { return Flight::class; } @@ -70,7 +71,7 @@ class FlightRepository extends Repository implements CacheableInterface * * @return $this */ - public function searchCriteria(Request $request, bool $only_active = true) + public function searchCriteria(Request $request, bool $only_active = true): self { $where = []; @@ -103,6 +104,16 @@ class FlightRepository extends Repository implements CacheableInterface $where['arr_airport_id'] = $request->arr_icao; } + // Distance, greater than + if ($request->filled('dgt')) { + $where[] = ['distance', '>=', $request->dgt]; + } + + // Distance, less than + if ($request->filled('dlt')) { + $where[] = ['distance', '<=', $request->dlt]; + } + $this->pushCriteria(new WhereCriteria($request, $where)); return $this; diff --git a/app/helpers.php b/app/helpers.php index c1e5e11b..78d2788f 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,5 +1,8 @@ retrieve($key); - } catch (\App\Exceptions\SettingNotFound $e) { + } catch (SettingNotFound $e) { return $default; } diff --git a/composer.json b/composer.json index 055c9a76..e91e65fe 100755 --- a/composer.json +++ b/composer.json @@ -14,40 +14,41 @@ "ext-pdo": "*", "composer/composer": "1.8.x", "composer/semver": "1.4.x", - "laravel/framework": "5.7.x", - "laravelcollective/html": "5.7.x", - "prettus/l5-repository": "2.6.x", - "nwidart/laravel-modules": "3.3.x", - "santigarcor/laratrust": "5.0.x", - "arrilot/laravel-widgets": "3.13.x", - "sebastiaanluca/laravel-helpers": "1.0.x", - "joshbrw/laravel-module-installer": "0.1.x", - "webpatser/laravel-uuid": "3.x", - "igaster/laravel-theme": "2.0.x", - "irazasyed/laravel-gamp": "1.3.x", - "toin0u/geotools-laravel": "1.0.x", - "spatie/laravel-pjax": "1.3.x", - "myclabs/deep-copy": "1.8.x", - "league/geotools": "0.8.x", - "fzaninotto/faker": "^1.8", - "hashids/hashids": "2.0.x", - "jackiedo/timezonelist": "5.x", - "tivie/php-os-detector": "1.1.x", - "pragmarx/version": "0.2.x", - "guzzlehttp/guzzle": "6.3.x", - "jmikola/geojson": "1.0.x", - "laracasts/flash": "3.0.x", - "nabeel/vacentral": "1.x", - "league/iso3166": "2.1.x", - "theiconic/php-ga-measurement-protocol": "2.7.x", - "vierbergenlars/php-semver": "3.0.x", - "php-units-of-measure/php-units-of-measure": "2.1.x", - "markrogoyski/math-php": "^0.38.0", "akaunting/money": "1.0.x", "anhskohbo/no-captcha": "3.0.x", - "league/csv": "9.2.x", + "arrilot/laravel-widgets": "3.13.x", + "fzaninotto/faker": "^1.8", + "guzzlehttp/guzzle": "6.3.x", + "hashids/hashids": "2.0.x", + "igaster/laravel-theme": "2.0.x", "intervention/image": "2.4.x", - "waavi/sanitizer": "1.0.x" + "irazasyed/laravel-gamp": "1.3.x", + "jackiedo/timezonelist": "5.x", + "jmikola/geojson": "1.0.x", + "joshbrw/laravel-module-installer": "0.1.x", + "laracasts/flash": "3.0.x", + "laravel/framework": "5.7.x", + "laravelcollective/html": "5.7.x", + "league/csv": "9.2.x", + "league/geotools": "0.8.x", + "league/iso3166": "2.1.x", + "markrogoyski/math-php": "^0.38.0", + "myclabs/deep-copy": "1.8.x", + "nabeel/vacentral": "1.x", + "nwidart/laravel-modules": "3.3.x", + "php-units-of-measure/php-units-of-measure": "2.1.x", + "pragmarx/version": "0.2.x", + "prettus/l5-repository": "2.6.x", + "santigarcor/laratrust": "5.0.x", + "sebastiaanluca/laravel-helpers": "1.0.x", + "spatie/laravel-pjax": "1.3.x", + "symfony/polyfill-iconv": "^1.11", + "theiconic/php-ga-measurement-protocol": "2.7.x", + "tivie/php-os-detector": "1.1.x", + "toin0u/geotools-laravel": "1.0.x", + "vierbergenlars/php-semver": "3.0.x", + "waavi/sanitizer": "1.0.x", + "webpatser/laravel-uuid": "3.x" }, "require-dev": { "phpunit/phpunit": "7.5.x", diff --git a/composer.lock b/composer.lock index 4a0321ab..c670bb52 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fb105f6d95ca2218f8e3e03c93371cd3", + "content-hash": "290bc8970d44a12e8546926949d73e20", "packages": [ { "name": "akaunting/money", diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b2ed1ea8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +--- +version: '3' + +services: + app: + build: + context: ./docker/php + environment: + DB_HOST: mysql + volumes: + - ./:/var/www + - ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf + depends_on: + - mysql + + nginx: + image: nginx:1.13.8 + command: /bin/bash -c "exec nginx -g 'daemon off;'" + volumes: + - ./:/var/www + - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf + ports: + - 80:80 + depends_on: + - app + + mysql: + image: mysql:5.7.26 + environment: + MYSQL_DATABASE: phpvms + MYSQL_USER: phpvms + MYSQL_PASSWORD: phpvms + MYSQL_ROOT_PASSWORD: + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + volumes: + - ./docker/data/mysql:/var/lib/mysql + ports: + - 3306:3306 + + # Use this to tail the logs so it's just all in a single window + logs: + image: busybox + command: tail -f -F -n 0 /var/www/storage/logs/laravel.log + restart: always + volumes: + - ./storage:/var/www/storage + depends_on: + - app diff --git a/docker/data/.gitignore b/docker/data/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/docker/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 00000000..ced8c907 --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,27 @@ +server { + listen 80 default_server; + server_name phpvms.test; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + root /var/www/public; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass app:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include /etc/nginx/fastcgi_params; + } + + location ~ /\.ht { + deny all; + } +} diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 00000000..02e28188 --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,12 @@ +FROM php:7.3-fpm + +RUN apt-get update +RUN apt-get install -y libgmp-dev + +RUN ln -sf /dev/stderr /var/log/fpm-error.log + +RUN docker-php-ext-install \ + mysqli \ + pdo \ + pdo_mysql \ + gmp diff --git a/docker/php/www.conf b/docker/php/www.conf new file mode 100644 index 00000000..725d0d2c --- /dev/null +++ b/docker/php/www.conf @@ -0,0 +1,15 @@ +[www] + +user = www-data +group = www-data + +listen = :9000 + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 + +php_flag[display_errors] = on +php_admin_flag[log_errors] = on diff --git a/index.php b/index.php index 3e89c0a5..8886dbb6 100755 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@