Compare commits

..

2 Commits

Author SHA1 Message Date
Nabeel Shahzad
aa8cda89d6 Change model 2020-10-29 12:06:20 -04:00
Nabeel Shahzad
5ba65cf2d1 Initial pirep fares changes #903 2020-10-28 17:11:05 -04:00
183 changed files with 4374 additions and 20014 deletions

View File

@@ -1,36 +0,0 @@
#!/usr/bin/env bash
if test "$GIT_TAG_NAME"; then
export VERSION=$GIT_TAG_NAME
# Pass in the tag as the version to write out
php artisan phpvms:version --write --write-full-version "${VERSION}"
export FULL_VERSION=$(php artisan phpvms:version)
else
export BRANCH=${GITHUB_REF##*/}
echo "On branch $BRANCH"
# Write the version out but place the branch ID in there
# This is only for the dev branch
export BASE_VERSION=$(php artisan phpvms:version --base-only)
# This now includes the pre-release version, so "-dev" by default
export VERSION=${BASE_VERSION}
# Don't pass in a version here, just write out the latest hash
php artisan phpvms:version --write "${VERSION}"
export FULL_VERSION=$(php artisan phpvms:version)
fi
export FILE_NAME="phpvms-${VERSION}"
export TAR_NAME="$FILE_NAME.tar.gz"
export ZIP_NAME="$FILE_NAME.zip"
export BASE_DIR=`pwd`
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
echo "FILE_NAME=${FILE_NAME}" >> $GITHUB_ENV
echo "TAR_NAME=${TAR_NAME}" >> $GITHUB_ENV
echo "ZIP_NAME=${ZIP_NAME}" >> $GITHUB_ENV
echo "BASE_DIR=${BASE_DIR}" >> $GITHUB_ENV
echo "DISCORD_MSG=Version ${FULL_VERSION} is available, download: [zip](http://downloads.phpvms.net/$ZIP_NAME) | [tar](http://downloads.phpvms.net/$TAR_NAME)" >> $GITHUB_ENV

View File

@@ -1,249 +0,0 @@
name: 'Build'
on: ['push', 'pull_request', 'workflow_dispatch', 'release']
jobs:
build:
runs-on: ubuntu-18.04
if: github.repository == 'nabeelio/phpvms'
strategy:
fail-fast: true
matrix:
php-versions: ['7.3', '7.4']
name: PHP ${{ matrix.php-versions }}
env:
extensions: intl, pcov, mbstring
key: cache-v1
steps:
- name: Checkout
uses: actions/checkout@v2
# Configure Caching
- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
# Configure PHP
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
ini-values: post_max_size=256M, short_open_tag=On
coverage: xdebug
tools: php-cs-fixer, phpunit
- name: Shutdown Ubuntu MySQL
run: sudo service mysql stop
- name: Install MariaDB
uses: getong/mariadb-action@v1.1
with:
character set server: 'utf8'
collation server: 'utf8_general_ci'
mysql database: 'phpvms'
mysql root password: ''
mysql user: ''
mysql password: ''
- name: Configure Environment
run: |
php --version
mysql --version
# Downgrade composer version to 1.x
composer install --dev --no-interaction --verbose
cp .github/scripts/env.php env.php
cp .github/scripts/phpunit.xml phpunit.xml
php artisan database:create --reset
php artisan migrate:refresh --seed
- name: Run Tests
run: |
vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --diff --using-cache=no
vendor/bin/phpunit --debug --verbose
# This runs after all of the tests, run have run. Creates a cleaned up version of the
# distro, and then creates the artifact to push up to S3 or wherever
artifacts:
name: 'Create dev build'
needs: build
runs-on: 'ubuntu-18.04'
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- uses: olegtarasov/get-tag@v2.1
id: tagName
# Configure Caching
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
# Dependencies
- name: 'Install Release Dependencies'
run: |
rm -rf vendor
sudo npm i tar-to-zip -g
composer install --no-dev --prefer-dist --no-interaction --verbose
sudo chmod +x ./.github/scripts/*
- name: Get version
run: .github/scripts/version.sh
- name: Build Distro
run: .github/scripts/build.sh
- name: Upload S3
uses: shallwefootball/s3-upload-action@v1.1.3
with:
aws_key_id: ${{ secrets.S3_BUILD_ARTIFACTS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.S3_BUILD_ARTIFACTS_SECRET_ACCESS_KEY}}
aws_bucket: ${{ secrets.S3_BUCKET_NAME }}
source_dir: 'dist'
destination_dir: ''
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@0.3.0
with:
# DISCORD_MSG is defined in versions.sh
args: '{{ DISCORD_MSG }}'
# This runs after all of the tests, run have run. Creates a cleaned up version of the
# distro, and then creates the artifact to push up to S3 or wherever
# https://github.com/actions/create-release
release:
name: 'Create Release'
needs: build
runs-on: 'ubuntu-18.04'
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- uses: olegtarasov/get-tag@v2.1
id: tagName
# Configure Caching
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
# Dependencies
- name: 'Install Release Dependencies'
run: |
rm -rf vendor
sudo npm i tar-to-zip -g
composer install --no-dev --prefer-dist --no-interaction --verbose
sudo chmod +x ./.github/scripts/*
- name: Get version
run: .github/scripts/version.sh
- name: Build Distro
run: .github/scripts/build.sh
- name: Upload S3
uses: shallwefootball/s3-upload-action@v1.1.3
with:
aws_key_id: ${{ secrets.S3_BUILD_ARTIFACTS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.S3_BUILD_ARTIFACTS_SECRET_ACCESS_KEY}}
aws_bucket: ${{ secrets.S3_BUCKET_NAME }}
source_dir: 'dist'
destination_dir: ''
- name: Checkout code
uses: actions/checkout@v2
- name: Get version
run: .github/scripts/version.sh
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false
# Upload the tar file to the release
- name: Upload Tar Asset
id: upload-tar-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/{{TAR_NAME}}
asset_name: '{{ TAR_NAME }}'
asset_content_type: application/gzip
# upload the zip file to the release
- name: Upload Zip Asset
id: upload-zip-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/{{ZIP_NAME}}
asset_name: '{{ ZIP_NAME }}'
asset_content_type: application/zip
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@0.3.0
with:
# DISCORD_MSG is defined in versions.sh
args: '{{ DISCORD_MSG }}'

160
.travis.yml Normal file
View File

@@ -0,0 +1,160 @@
#
# Travis CI config file
#
language: php
php:
- '7.4'
- '7.3'
#env:
# - DB=mysql
# - DB=mariadb
cache:
# Cache lives for 10 min
# Default of 3m might not be long enough for all the runs
timeout: 600
directories:
- "$HOME/.composer/cache"
- "$HOME/.npm"
services:
- mysql
#addons:
# mariadb: '10.2'
install:
- php --version
- mysql --version
- composer install --dev --no-interaction --verbose
- npm i tar-to-zip -g
- cp .travis/env.travis.php env.php
- cp .travis/phpunit.travis.xml phpunit.xml
before_script:
- php artisan database:create --reset
- php artisan migrate:refresh --seed
script:
- vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --diff --using-cache=no
- vendor/bin/phpunit --debug --verbose
after_failure:
- cat storage/logs/*.log
# Refer to: https://github.com/doctrine/dbal/blob/master/.travis.yml#L39
jobs:
include:
# Different test stages
# - stage: Test
# name: PHP 7.2 + MySQL 5.7
# php: 7.2
# env: DB=mysql
# services:
# - mysql
# - stage: Test
# name: PHP 7.3 + MySQL 5.7
# php: 7.3
# env: DB=mysql
# services:
# - mysql
# - stage: Test
# name: PHP 7.4 + MySQL 5.7
# php: 7.4
# env: DB=mysql
# services:
# - mysql
# - stage: Test
# name: PHP 7.2 + MariaDB 10.1
# php: 7.2
# env: DB=mariadb
# addons:
# mariadb: '10.1'
# - stage: Test
# name: PHP 7.3 + MariaDB 10.1
# php: 7.3
# env: DB=mariadb
# addons:
# mariadb: '10.1'
# - stage: Test
# name: PHP 7.4 + MariaDB 10.1
# php: 7.4
# env: DB=mariadb MARIADB_VERSION=10.1
# addons:
# mariadb: '10.1'
# - stage: Test
# name: PHP 7.2 + MariaDB 10.2
# php: 7.2
# env: DB=mariadb
# addons:
# mariadb: '10.2'
# - stage: Test
# name: PHP 7.3 + MariaDB 10.3
# php: 7.3
# env: DB=mariadb
# addons:
# mariadb: '10.2'
# - stage: Test
# name: PHP 7.4 + MariaDB 10.2
# php: 7.4
# env: DB=mariadb
# addons:
# mariadb: '10.2'
# - stage: Test
# name: PHP 7.2 + MariaDB 10.3
# php: 7.2
# env: DB=mariadb
# addons:
# mariadb: '10.3'
# - stage: Test
# name: PHP 7.3 + MariaDB 10.3
# php: 7.3
# env: DB=mariadb
# addons:
# mariadb: '10.3'
# - stage: Test
# name: PHP 7.4 + MariaDB 10.3
# php: 7.4
# env: DB=mariadb
# addons:
# mariadb: '10.3'
# Just packages up a release
- stage: package
script: skip
before_deploy:
- curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/6b10798/install | bash
# Configure the conditional deployment
# https://docs.travis-ci.com/user/deployment/#examples-of-conditional-deployment
deploy:
- provider: script
skip_cleanup: true
script: ./.travis/deploy_script.sh
on:
all_branches: true
repo: nabeelio/phpvms
php: '7.4'
tags: false
# RELEASE STAGE
# Only runs when there's a tag applied to this release (tag should be the version)
# This uses Github Releases and posts it there (provider: releases)
# https://docs.travis-ci.com/user/deployment/releases
- stage: release
script: skip
before_deploy:
- curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/6b10798/install | bash
- ./.travis/deploy_script.sh
deploy:
provider: releases
skip_cleanup: true
api_key: $GITHUB_TOKEN
file_glob: true
file: build/*
on:
tags: true
repo: nabeelio/phpvms
php: '7.4'

78
.github/scripts/build.sh → .travis/deploy_script.sh Normal file → Executable file
View File

@@ -1,12 +1,52 @@
#!/usr/bin/env bash
if [ "$TRAVIS" != "true" ]; then
exit 0
fi
cd $TRAVIS_BUILD_DIR
if test "$TRAVIS_TAG"; then
VERSION=$TRAVIS_TAG
# Pass in the tag as the version to write out
php artisan phpvms:version --write --write-full-version "${VERSION}"
FULL_VERSION=$(php artisan phpvms:version)
else
echo "On branch $TRAVIS_BRANCH"
if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_BRANCH" != "dev" ]; then
echo "Not on valid branch, exiting"
exit 0
fi
# Write the version out but place the branch ID in there
# This is only for the dev branch
BASE_VERSION=$(php artisan phpvms:version --base-only)
# This now includes the pre-release version, so "-dev" by default
VERSION=${BASE_VERSION}
# Don't pass in a version here, just write out the latest hash
php artisan phpvms:version --write "${VERSION}"
FULL_VERSION=$(php artisan phpvms:version)
fi
FILE_NAME="phpvms-${VERSION}"
TAR_NAME="$FILE_NAME.tar.gz"
ZIP_NAME="$FILE_NAME.zip"
echo "Version: ${VERSION}"
echo "Full Version: ${FULL_VERSION}"
echo "Package name: ${TAR_NAME}"
echo "Current directory: ${BASE_DIR}"
echo "==========================="
echo "Cleaning files"
rm -rf vendor
composer install --no-dev --prefer-dist --no-interaction --verbose
# Leftover individual files to delete
declare -a remove_files=(
.git
@@ -67,20 +107,44 @@ mkdir -p storage/framework/cache
mkdir -p storage/framework/sessions
mkdir -p storage/framework/views
# Regenerate the autoloader and classes
composer dump-autoload
make clean
cd /tmp
ls -al $TRAVIS_BUILD_DIR/../
ls -al $BASE_DIR/../
tar -czf $TAR_NAME -C $BASE_DIR .
tar -czf $TAR_NAME -C $TRAVIS_BUILD_DIR .
sha256sum $TAR_NAME >"$TAR_NAME.sha256"
tar2zip $TAR_NAME
sha256sum $ZIP_NAME >"$ZIP_NAME.sha256"
ls -al /tmp
echo "Moving to dist"
mkdir -p $BASE_DIR/dist
cd $BASE_DIR/dist
echo "Uploading to S3"
mkdir -p $TRAVIS_BUILD_DIR/build
cd $TRAVIS_BUILD_DIR/build
mv "/tmp/$TAR_NAME" "/tmp/$ZIP_NAME" "/tmp/$TAR_NAME.sha256" "/tmp/$ZIP_NAME.sha256" .
artifacts upload --target-paths "/" $ZIP_NAME $TAR_NAME $TRAVIS_BUILD_DIR/VERSION $TAR_NAME.sha256 $ZIP_NAME.sha256
# Upload the version for a tagged release. Move to a version file in different
# tags. Within phpVMS, we have an option of which version to track in the admin
if test "$TRAVIS_TAG"; then
echo "Uploading release version file"
cp "$TRAVIS_BUILD_DIR/VERSION" release_version
artifacts upload --target-paths "/" release_version
else
echo "Uploading ${TRAVIS_BRANCH}_version file"
cp $TRAVIS_BUILD_DIR/VERSION ${TRAVIS_BRANCH}_version
artifacts upload --target-paths "/" ${TRAVIS_BRANCH}_version
fi
#if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_BRANCH" != "dev" ]; then
# echo "Skipping Discord branch update broadcast"
#else
curl -X POST \
--data "{\"content\": \"A new build is available at http://downloads.phpvms.net/$TAR_NAME (${FULL_VERSION})\"}" \
-H "Content-Type: application/json" \
$DISCORD_WEBHOOK_URL
#fi

View File

@@ -1,3 +1,7 @@
<?php
exit();
?>
APP_ENV="dev"
APP_KEY="base64:zdgcDqu9PM8uGWCtMxd74ZqdGJIrnw812oRMmwDF6KY="
APP_URL="http://localhost"

View File

@@ -1,15 +1,18 @@
# phpVMS <sup>7</sup>
# phpvms <sup>7</sup>
[![Build](https://github.com/nabeelio/phpvms/workflows/Build/badge.svg?branch=dev)](https://github.com/nabeelio/phpvms/actions) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d668bebb0a3c46bda381af16ce3d9450)](https://www.codacy.com/app/nabeelio/phpvms?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=nabeelio/phpvms&amp;utm_campaign=Badge_Grade) [![Latest Stable Version](https://poser.pugx.org/nabeel/phpvms/v/stable)](https://packagist.org/packages/nabeel/phpvms) ![StyleCI](https://github.styleci.io/repos/93688482/shield?branch=dev) [![License](https://poser.pugx.org/nabeel/phpvms/license)](https://packagist.org/packages/nabeel/phpvms)
[![Build Status](https://travis-ci.org/nabeelio/phpvms.svg)](https://travis-ci.org/nabeelio/phpvms) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d668bebb0a3c46bda381af16ce3d9450)](https://www.codacy.com/app/nabeelio/phpvms?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=nabeelio/phpvms&amp;utm_campaign=Badge_Grade) [![Latest Stable Version](https://poser.pugx.org/nabeel/phpvms/v/stable)](https://packagist.org/packages/nabeel/phpvms) ![StyleCI](https://github.styleci.io/repos/93688482/shield?branch=dev) [![License](https://poser.pugx.org/nabeel/phpvms/license)](https://packagist.org/packages/nabeel/phpvms)
The next phpvms version built on the laravel framework. work in progress. The latest documentation, with installation instructions is available [on the phpVMS documentation](https://docs.phpvms.net/) page.
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
# installation
A full distribution, with all of the composer dependencies, is available at this
[GitHub Releases](https://github.com/nabeelio/phpvms/releases) link.
### Requirements
## Requirements
- PHP 7.3+, extensions:
- cURL
@@ -21,22 +24,22 @@ A full distribution, with all of the composer dependencies, is available at this
- Database:
- MySQL 5.5+ (or MySQL variant, including MariaDB and Percona)
[View more details on requirements](https://docs.phpvms.net/requirements)
[View more details on requirements](http://docs.phpvms.net/setup/requirements)
### Installer
## Installer
1. Upload to your server
1. Visit the site, and follow the link to the installer
[View installation details](https://docs.phpvms.net/installation/installation)
[View installation details](http://docs.phpvms.net/setup/installation)
## Development Environment
# development environment
A full development environment can be brought up using Docker:
```bash
composer install
npm install
yarn install
docker-compose build
docker-compose up
```
@@ -47,7 +50,7 @@ Then go to `http://localhost`. If you're using dnsmasq, the `app` container is l
127.0.0.1 phpvms.test
```
### Building JS/CSS assets
## Building JS/CSS assets
Yarn is required, run:

View File

@@ -3,7 +3,7 @@
namespace App\Console\Commands;
use App\Contracts\Command;
use App\Services\Installer\ConfigService;
use Modules\Installer\Services\ConfigService;
/**
* Create a fresh development install

View File

@@ -13,11 +13,7 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule. How this works... according to the command
* time, an event gets send out with the appropriate time (e.g, hourly sends an hourly event)
*
* Then the CronServiceProvider has the list of cronjobs which then run according to the events
* and then calls those at the proper times.
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
@@ -31,13 +27,10 @@ class Kernel extends ConsoleKernel
$schedule->command(Hourly::class)->hourly();
// When spatie-backups runs
/*if (config('backup.backup.enabled', false) === true) {
$schedule->command('backup:clean')->daily()->at('01:00');
$schedule->command('backup:run')->daily()->at('02:00');
}*/
$schedule->command('backup:clean')->daily()->at('01:00');
$schedule->command('backup:run')->daily()->at('02:00');
// Update the last time the cron was run
/** @var CronService $cronSvc */
$cronSvc = app(CronService::class);
$cronSvc->updateLastRunTime();
}

View File

@@ -12,24 +12,13 @@ abstract class Metar
{
/**
* Implement retrieving the METAR - return the METAR string. Needs to be protected,
* since this shouldn't be directly called. Call `metar($icao)`. If not implemented,
* return a blank string
* since this shouldn't be directly called. Call `get_metar($icao)` instead
*
* @param $icao
*
* @return mixed
*/
abstract protected function get_metar($icao): string;
/**
* Implement retrieving the TAF - return the string. Call `taf($icao)`. If not implemented,
* return a blank string
*
* @param $icao
*
* @return mixed
*/
abstract protected function get_taf($icao): string;
abstract protected function metar($icao): string;
/**
* Download the METAR, wrap in caching
@@ -38,9 +27,9 @@ abstract class Metar
*
* @return string
*/
public function metar($icao): string
public function get_metar($icao): string
{
$cache = config('cache.keys.METAR_WEATHER_LOOKUP');
$cache = config('cache.keys.WEATHER_LOOKUP');
$key = $cache['key'].$icao;
if (Cache::has($key)) {
@@ -51,7 +40,7 @@ abstract class Metar
}
try {
$raw_metar = $this->get_metar($icao);
$raw_metar = $this->metar($icao);
} catch (\Exception $e) {
Log::error('Error getting METAR: '.$e->getMessage(), $e->getTrace());
return '';
@@ -63,37 +52,4 @@ abstract class Metar
return $raw_metar;
}
/**
* Download the TAF, wrap in caching
*
* @param $icao
*
* @return string
*/
public function taf($icao): string
{
$cache = config('cache.keys.TAF_WEATHER_LOOKUP');
$key = $cache['key'].$icao;
if (Cache::has($key)) {
$taf = Cache::get($key);
if ($taf !== '') {
return $taf;
}
}
try {
$taf = $this->get_taf($icao);
} catch (\Exception $e) {
Log::error('Error getting TAF: '.$e->getMessage(), $e->getTrace());
return '';
}
if ($taf !== '') {
Cache::put($key, $taf, $cache['time']);
}
return $taf;
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Contracts;
use App\Models\Module;
use App\Support\Database;
use Exception;
use Illuminate\Support\Facades\DB;

View File

@@ -1,52 +0,0 @@
<?php
namespace App\Cron\Hourly;
use App\Contracts\Listener;
use App\Events\CronHourly;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Services\PirepService;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
/**
* Remove cancelled/deleted PIREPs. Look for PIREPs that were created before the setting time
* (e.g, 12 hours ago) and are marked with the
*/
class DeletePireps extends Listener
{
/**
* Remove expired bids
*
* @param CronHourly $event
*
* @throws \Exception
*/
public function handle(CronHourly $event): void
{
$this->deletePireps(setting('pireps.delete_rejected_hours'), PirepState::REJECTED);
$this->deletePireps(setting('pireps.delete_cancelled_hours'), PirepState::CANCELLED);
}
/**
* Look for and delete PIREPs which match the criteria
*
* @param int $expire_time_hours The time in hours to look for PIREPs
* @param int $state The PirepState enum value
*/
protected function deletePireps(int $expire_time_hours, int $state)
{
$dt = Carbon::now()->subHours($expire_time_hours);
$pireps = Pirep::whereDate('created_at', '<', $dt)->where(['state' => $state])->get();
/** @var PirepService $pirepSvc */
$pirepSvc = app(PirepService::class);
/** @var Pirep $pirep */
foreach ($pireps as $pirep) {
Log::info('Cron: Deleting PIREP id='.$pirep->id.', state='.PirepState::label($state));
$pirepSvc->delete($pirep);
}
}
}

View File

@@ -6,7 +6,6 @@ use App\Contracts\Listener;
use App\Events\CronMonthly;
use App\Models\Enums\ExpenseType;
use App\Services\Finance\RecurringFinanceService;
use Illuminate\Support\Facades\Log;
/**
* Go through and apply any finances that are daily
@@ -36,7 +35,6 @@ class ApplyExpenses extends Listener
*/
public function handle(CronMonthly $event): void
{
Log::info('Monthly: Applying monthly expenses');
$this->financeSvc->processExpenses(ExpenseType::MONTHLY);
}
}

View File

@@ -6,7 +6,6 @@ use App\Contracts\Listener;
use App\Events\CronNightly;
use App\Models\Enums\ExpenseType;
use App\Services\Finance\RecurringFinanceService;
use Illuminate\Support\Facades\Log;
/**
* Go through and apply any finances that are daily
@@ -36,7 +35,6 @@ class ApplyExpenses extends Listener
*/
public function handle(CronNightly $event): void
{
Log::info('Nightly: Applying daily expenses');
$this->financeSvc->processExpenses(ExpenseType::DAILY);
}
}

View File

@@ -5,7 +5,6 @@ namespace App\Cron\Nightly;
use App\Contracts\Listener;
use App\Events\CronNightly;
use App\Services\SimBriefService;
use Illuminate\Support\Facades\Log;
/**
* Clear any expired SimBrief flight briefs that aren't attached to a PIREP
@@ -24,7 +23,6 @@ class ClearExpiredSimbrief extends Listener
*/
public function handle(CronNightly $event): void
{
Log::info('Nightly: Removing expired Simbrief entries');
$this->simbriefSvc->removeExpiredEntries();
}
}

View File

@@ -5,7 +5,6 @@ namespace App\Cron\Nightly;
use App\Contracts\Listener;
use App\Events\CronNightly;
use App\Services\VersionService;
use Illuminate\Support\Facades\Log;
/**
* Determine if any pilots should be set to ON LEAVE status
@@ -29,7 +28,6 @@ class NewVersionCheck extends Listener
*/
public function handle(CronNightly $event): void
{
Log::info('Nightly: Checking for new version');
$this->versionSvc->isNewVersionAvailable();
}
}

View File

@@ -4,8 +4,10 @@ namespace App\Cron\Nightly;
use App\Contracts\Listener;
use App\Events\CronNightly;
use App\Models\Enums\UserState;
use App\Models\User;
use App\Services\UserService;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
/**
* Determine if any pilots should be set to ON LEAVE status
@@ -16,8 +18,6 @@ class PilotLeave extends Listener
/**
* PilotLeave constructor.
*
* @param UserService $userSvc
*/
public function __construct(UserService $userSvc)
{
@@ -34,9 +34,13 @@ class PilotLeave extends Listener
*/
public function handle(CronNightly $event): void
{
Log::info('Cron: Running pilot leave check');
$users = $this->userSvc->findUsersOnLeave();
Log::info('Found '.count($users).' users on leave');
if (setting('pilots.auto_leave_days') === 0) {
return;
}
$date = Carbon::now()->subDay(setting('pilots.auto_leave_days'));
$users = User::where('status', UserState::ACTIVE)
->whereDate('updated_at', '<', $date);
foreach ($users as $user) {
Log::info('Setting user '.$user->ident.' to ON LEAVE status');

View File

@@ -35,7 +35,7 @@ class RecalculateBalances extends Listener
*/
public function handle(CronNightly $event): void
{
Log::info('Nightly: Recalculating balances');
Log::info('Recalculating balances');
$journals = Journal::all();
foreach ($journals as $journal) {

View File

@@ -32,10 +32,10 @@ class RecalculateStats extends Listener
*/
public function handle(CronNightly $event): void
{
Log::info('Nightly: Recalculating user stats');
Log::info('Recalculating user stats');
$this->userSvc->recalculateAllUserStats();
Log::info('Nightly: Recalcuating aircraft status');
Log::info('Recalcuating aircraft status');
$this->aircraftSvc->recalculateStats();
}
}

View File

@@ -19,8 +19,6 @@ class SetActiveFlights extends Listener
*/
public function handle(CronNightly $event): void
{
Log::info('Nightly: Setting active flights');
$this->checkFlights();
}
@@ -44,18 +42,23 @@ class SetActiveFlights extends Listener
continue;
}
// Set to visible by default
$flight->visible = true;
// dates aren't set, so just save if there were any changes above
// and move onto the next one
if ($flight->start_date === null || $flight->end_date === null) {
if ($flight->days !== null && $flight->days > 0) {
$flight->visible = Days::isToday($flight->days);
if (!$flight->visible) {
Log::info('Today='.date('N').', start=no, mask='.$flight->days.', in='
.Days::in($flight->days, Days::$isoDayMap[(int) date('N')]));
$visible = Days::isToday($flight->days);
if ($flight->visible !== $visible) {
Log::info('Flight '.$flight->ident.' to '.($visible ? 'shown' : 'hidden'));
$flight->visible = $visible;
if ($visible === false) {
Log::info('Today='.date('N').', start=no, mask='.$flight->days.', in='
.Days::in($flight->days, Days::$isoDayMap[(int) date('N')]));
}
}
} else {
Log::info('Toggling flight '.$flight->ident.' to visible');
$flight->visible = true;
}
$flight->save();
@@ -68,11 +71,20 @@ class SetActiveFlights extends Listener
// and then make sure if days of the week are specified, check that too
if ($today->gte($flight->start_date) && $today->lte($flight->end_date)) {
if ($flight->days !== null && $flight->days > 0) {
$flight->visible = Days::isToday($flight->days);
if (!$flight->visible) {
Log::info('Today='.date('N').', start=no, mask='.$flight->days.', in='
$visible = Days::isToday($flight->days);
if ($flight->visible !== $visible) {
Log::info('Toggling flight '.$flight->ident.' to '.($visible ? 'shown' : 'hidden').'');
$flight->visible = $visible;
if ($visible === false) {
Log::info('Today='.date('N').', start='.$flight->start_date
.', end='.$flight->end_date.', mask='.$flight->days.', in='
.Days::in($flight->days, Days::$isoDayMap[(int) date('N')]));
}
}
} else {
Log::info('Toggling flight '.$flight->ident.' to visible');
$flight->visible = true;
}
} else {
$flight->visible = false;

View File

@@ -5,6 +5,11 @@ use Illuminate\Database\Schema\Blueprint;
class RolesPermissionsTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Create table for storing roles
@@ -74,6 +79,11 @@ class RolesPermissionsTables extends Migration
$this->addData('roles', $roles);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permission_user');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
@@ -15,6 +20,11 @@ class CreatePasswordResetsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateSessionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sessions', function (Blueprint $table) {
@@ -18,6 +23,11 @@ class CreateSessionsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sessions');

View File

@@ -5,6 +5,11 @@ use Illuminate\Database\Schema\Blueprint;
class CreateAirlinesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('airlines', function (Blueprint $table) {
@@ -27,6 +32,11 @@ class CreateAirlinesTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('airlines');

View File

@@ -5,6 +5,11 @@ use Illuminate\Database\Schema\Blueprint;
class CreateFaresTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('fares', function (Blueprint $table) {
@@ -20,6 +25,11 @@ class CreateFaresTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('fares');

View File

@@ -7,6 +7,11 @@ use Illuminate\Database\Schema\Blueprint;
class CreateFlightTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('flights', function (Blueprint $table) {

View File

@@ -5,6 +5,11 @@ use Illuminate\Database\Schema\Blueprint;
class CreateRanksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ranks', function (Blueprint $table) {
@@ -25,6 +30,11 @@ class CreateRanksTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ranks');

View File

@@ -3,6 +3,9 @@
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
* Class CreateSubfleetTables
*/
class CreateSubfleetTables extends Migration
{
public function up()
@@ -45,6 +48,11 @@ class CreateSubfleetTables extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('subfleets');

View File

@@ -7,6 +7,11 @@ use Illuminate\Support\Facades\Schema;
class CreateBidsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('bids', function (Blueprint $table) {
@@ -20,6 +25,11 @@ class CreateBidsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('bids');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
@@ -19,6 +24,11 @@ class CreateJobsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateFailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
@@ -18,6 +23,11 @@ class CreateFailedJobsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateNavdataTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
/*
@@ -26,6 +31,11 @@ class CreateNavdataTables extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('navdata');

View File

@@ -7,6 +7,11 @@ use Illuminate\Support\Facades\Schema;
class CreateAcarsTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('acars', function (Blueprint $table) {
@@ -39,6 +44,11 @@ class CreateAcarsTables extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('acars');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateStatsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('stats', function (Blueprint $table) {
@@ -20,6 +25,11 @@ class CreateStatsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('stats');

View File

@@ -17,6 +17,11 @@ class CreateNewsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('news');

View File

@@ -7,6 +7,13 @@ use Modules\Awards\Awards\PilotFlightAwards;
class CreateAwardsTable extends Migration
{
/**
* Run the migrations.
*
* @throws \Illuminate\Validation\ValidationException
*
* @return void
*/
public function up()
{
Schema::create('awards', function (Blueprint $table) {
@@ -47,6 +54,11 @@ class CreateAwardsTable extends Migration
$this->addAward($award);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('awards');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateJournalTransactionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('journal_transactions', function (Blueprint $table) {
@@ -29,6 +34,11 @@ class CreateJournalTransactionsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('journal_transactions');

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateJournalsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('journals', function (Blueprint $table) {
@@ -19,6 +24,11 @@ class CreateJournalsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('journals');

View File

@@ -1,7 +1,6 @@
<?php
use App\Contracts\Migration;
use App\Contracts\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -15,7 +14,7 @@ class CreateFilesTable extends Migration
public function up()
{
Schema::create('files', function (Blueprint $table) {
$table->string('id', Model::ID_MAX_LENGTH);
$table->string('id', \App\Contracts\Model::ID_MAX_LENGTH);
$table->string('name');
$table->string('description')->nullable();
$table->string('disk')->nullable();

View File

@@ -1,12 +1,17 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class AddReadonlyToRoles extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('roles', static function (Blueprint $table) {
@@ -19,6 +24,11 @@ class AddReadonlyToRoles extends Migration
->update(['read_only' => true]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('roles', static function (Blueprint $table) {

View File

@@ -1,19 +1,21 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Kinda of gross operations to change the pilot ID column
* 1. Add an `pilot_id` column, which will get populated with the current ID
* 2. Drop the `id` column, and then recreate it as a string field
* 3. Iterate through all of the users and set their `id` to the `pilot_id`
* 4. Change the other tables column types that reference `user_id`
*/
class UsersAddPilotId extends Migration
{
/**
* Kinda of gross operations to change the pilot ID column
* 1. Add an `pilot_id` column, which will get populated with the current ID
* 2. Drop the `id` column, and then recreate it as a string field
* 3. Iterate through all of the users and set their `id` to the `pilot_id`
* 4. Change the other tables column types that reference `user_id`
*
* @return void
*/
public function up()
{
Schema::table('users', static function (Blueprint $table) {
@@ -27,6 +29,11 @@ class UsersAddPilotId extends Migration
DB::table('users')->update(['pilot_id' => DB::raw('`id`')]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {

View File

@@ -1,11 +1,16 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateNotificationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notifications', function (Blueprint $table) {
@@ -18,6 +23,11 @@ class CreateNotificationsTable extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notifications');

View File

@@ -1,16 +1,18 @@
<?php
use App\Contracts\Migration;
use App\Models\Enums\PirepState;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Change the PIREP state column to be a TINYINT
*/
class PirepsChangeStateType extends Migration
{
/**
* Change the PIREP state column to be a TINYINT
*
* @return void
*/
public function up()
{
// Migrate the old rejected state
@@ -23,4 +25,13 @@ class PirepsChangeStateType extends Migration
$table->unsignedSmallInteger('state')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@@ -5,15 +5,27 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a `flight_id` column to the PIREPs table
*/
class PirepsAddFlightId extends Migration
{
/**
* Add a `flight_id` column to the PIREPs table
*/
public function up()
{
Schema::table('pireps', function (Blueprint $table) {
$table->string('flight_id', Model::ID_MAX_LENGTH)->nullable()->after('aircraft_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('pireps', function (Blueprint $table) {
$table->dropColumn('flight_id');
});
}
}

View File

@@ -4,11 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a `flight_type` column to the expenses table
*/
class ExpensesAddFlightType extends Migration
{
/**
* Add a `flight_type` column to the expenses table
*/
public function up()
{
Schema::table('expenses', function (Blueprint $table) {
@@ -18,6 +18,11 @@ class ExpensesAddFlightType extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('expenses', function (Blueprint $table) {

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
/**
@@ -25,4 +25,13 @@ class ModifyAirportsCoordinates extends Migration
$table->decimal('lon', 11, 5)->change()->default(0.0)->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
/**
@@ -8,10 +8,24 @@ use Illuminate\Support\Facades\Schema;
*/
class FlightFieldNullable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('flight_field_values', function ($table) {
$table->text('value')->change()->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@@ -1,14 +1,14 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a `load_factor` and `load_factor_variance` columns to the expenses table
*/
class FlightsAddLoadFactor extends Migration
{
/**
* Add a `load_factor` and `load_factor_variance` columns to the expenses table
*/
public function up()
{
Schema::table('flights', function (Blueprint $table) {
@@ -22,6 +22,11 @@ class FlightsAddLoadFactor extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('flights', function (Blueprint $table) {

View File

@@ -1,14 +1,14 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a `pilot_pay` column for a fixed amount to pay to a pilot for a flight
*/
class FlightsAddPilotPay extends Migration
{
/**
* Add a `pilot_pay` column for a fixed amount to pay to a pilot for a flight
*/
public function up()
{
Schema::table('flights', function (Blueprint $table) {
@@ -18,6 +18,11 @@ class FlightsAddPilotPay extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('flights', function (Blueprint $table) {

View File

@@ -1,15 +1,15 @@
<?php
use App\Contracts\Migration;
use App\Models\Enums\FareType;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a `pilot_pay` column for a fixed amount to pay to a pilot for a flight
*/
class FaresAddType extends Migration
{
/**
* Add a `pilot_pay` column for a fixed amount to pay to a pilot for a flight
*/
public function up()
{
Schema::table('fares', function (Blueprint $table) {
@@ -19,4 +19,16 @@ class FaresAddType extends Migration
->after('capacity');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('fares', function (Blueprint $table) {
$table->dropColumn('type');
});
}
}

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -33,4 +33,13 @@ class IncreaseIdLengths extends Migration
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -15,4 +15,13 @@ class RemoveSubfleetTypeIndex extends Migration
$table->dropUnique(['type']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

View File

@@ -1,7 +1,7 @@
<?php
use App\Contracts\Migration;
use App\Models\Enums\PageType;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -11,6 +11,11 @@ use Illuminate\Support\Facades\Schema;
*/
class CreatePages extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pages', function (Blueprint $table) {
@@ -28,6 +33,11 @@ class CreatePages extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pages');

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -9,7 +9,11 @@ class AirlineRemoveNullable extends Migration
public function up()
{
Schema::table('airlines', function (Blueprint $table) {
$table->dropUnique(['iata']);
$table->dropUnique('airlines_iata_unique');
});
}
public function down()
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -12,4 +12,8 @@ class PageIconNullable extends Migration
$table->string('icon')->change()->nullable();
});
}
public function down()
{
}
}

View File

@@ -1,15 +1,15 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a `link` column and make the body optional. Also add a "new_window" bool
* which determines if we open this link in a new window or not
*/
class PagesAddLink extends Migration
{
/**
* Add a `link` column and make the body optional. Also add a "new_window" bool
* which determines if we open this link in a new window or not
*/
public function up()
{
Schema::table('pages', function (Blueprint $table) {
@@ -23,6 +23,9 @@ class PagesAddLink extends Migration
});
}
/**
* @return void
*/
public function down()
{
Schema::table('fares', function (Blueprint $table) {

View File

@@ -5,11 +5,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add two tables for holding user fields and the values
*/
class CreateUserFields extends Migration
{
/**
* Add two tables for holding user fields and the values
*/
public function up()
{
/*
@@ -39,4 +39,11 @@ class CreateUserFields extends Migration
$table->index(['user_field_id', 'user_id']);
});
}
/**
* @return void
*/
public function down()
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -19,6 +19,11 @@ class AircraftAddMtow extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('aircraft', function (Blueprint $table) {

View File

@@ -6,6 +6,11 @@ use Illuminate\Support\Facades\Schema;
class CreateModulesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('modules', function (Blueprint $table) {
@@ -22,6 +27,11 @@ class CreateModulesTable extends Migration
$this->addModule(['name' => 'TestModule']);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('modules');

View File

@@ -0,0 +1,52 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ModifyPirepFares extends Migration
{
/**
* Modify the PIREP fares table so that we can save all of the fares for that particular PIREP
* Basically copy all of those fields over, and then use this table directly, instead of the
* relationship to the fares table
*
* @return void
*/
public function up()
{
/*
* Add the columns we need from the fares table so then this is now "fixed" in time
*/
Schema::table('pirep_fares', function (Blueprint $table) {
$table->unsignedInteger('fare_id')->change()->nullable()->default(0);
$table->string('code', 50);
$table->string('name', 50);
// count is already there
$table->unsignedDecimal('price')->nullable()->default(0.00);
$table->unsignedDecimal('cost')->nullable()->default(0.00);
$table->unsignedInteger('capacity')->nullable()->default(0);
});
/**
* Now iterate through the existing table and copy/update everything
* Some fares might already have been removed deleted so just insert some null/errored
* values for those
*/
$parent_fares = [];
$fares = DB::table('pirep_fares')->get();
foreach ($fares as $fare) {
if (empty($parent_fares[$fare->fare_id])) {
$parent_fares[$fare->fare_id] = DB::table('fares')->where('id', $fare->fare_id)->first();
}
}
}
public function down()
{
}
}

View File

@@ -1,18 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Change the pages body column type to a Medium Text, max size of 16MB
*/
class ModifyPagesSize extends Migration
{
public function up()
{
Schema::table('pages', function (Blueprint $table) {
$table->mediumText('body')->change()->nullable();
});
}
}

View File

@@ -1,19 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Change the downloads link size
*/
class ModifyDownloadLinkSize extends Migration
{
public function up()
{
Schema::table('files', function (Blueprint $table) {
$table->mediumText('disk')->change()->nullable();
$table->mediumText('path')->change()->nullable();
});
}
}

View File

@@ -1,20 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a hub to the subfleet is
*/
class AddHubToSubfleets extends Migration
{
public function up()
{
Schema::table('subfleets', function (Blueprint $table) {
$table->string('hub_id', 4)
->nullable()
->after('airline_id');
});
}
}

View File

@@ -1,18 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Change the vertical speed for the acars table to a double
*/
class ChangeAcarsVsType extends Migration
{
public function up()
{
Schema::table('acars', function (Blueprint $table) {
$table->float('vs')->change()->default(0.0)->nullable();
});
}
}

View File

@@ -1,19 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Bring the sessions table in line with the latest
*/
class UpdateSessionsTable extends Migration
{
public function up()
{
Schema::table('sessions', function (Blueprint $table) {
$table->index('user_id');
$table->index('last_activity');
});
}
}

View File

@@ -1,21 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a `fuel_onboard` column for recording what is left in tanks
*/
class AircraftAddFuelonboard extends Migration
{
public function up()
{
Schema::table('aircraft', function (Blueprint $table) {
$table->unsignedDecimal('fuel_onboard')
->nullable()
->default(0.0)
->after('zfw');
});
}
}

View File

@@ -1,20 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a SimBrief Type to subfleet
*/
class AddSbtypeToSubfleets extends Migration
{
public function up()
{
Schema::table('subfleets', function (Blueprint $table) {
$table->string('simbrief_type', 20)
->nullable()
->after('type');
});
}
}

View File

@@ -1,24 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a hub to the subfleet is
*/
class AddAircraftToSimbrief extends Migration
{
public function up()
{
Schema::table('simbrief', function (Blueprint $table) {
$table->unsignedInteger('aircraft_id')
->nullable()
->after('pirep_id');
// Temp column to hold the calculated fare data for the API
// Remove this once the prefile to acars feature is completed
$table->mediumText('fare_data')->nullable()->after('ofp_xml');
});
}
}

View File

@@ -1,19 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Add a hub to the subfleet is
*/
class AddKvpTable extends Migration
{
public function up()
{
Schema::create('kvp', function (Blueprint $table) {
$table->string('key')->index();
$table->string('value');
});
}
}

View File

@@ -119,8 +119,8 @@ aircraft:
-
id: 1
subfleet_id: 1
icao: B744
iata: 744
icao: null
iata: null
airport_id: KJFK
landing_time: '2020-10-23 07:50:16'
name: 'Boeing 747-438'
@@ -136,8 +136,8 @@ aircraft:
-
id: 2
subfleet_id: 2
icao: B777
iata: 777
icao: null
iata: null
airport_id: LGRP
landing_time: null
name: 'Boeing 777-200'
@@ -153,8 +153,8 @@ aircraft:
-
id: 3
subfleet_id: 1
icao: B744
iata: 744
icao: null
iata: null
airport_id: KAUS
landing_time: '2020-10-24 08:50:13'
name: 'Boeing 747-412'
@@ -170,8 +170,8 @@ aircraft:
-
id: 4
subfleet_id: 1
icao: B744
iata: 744
icao: null
iata: null
airport_id: KAUS
landing_time: null
name: 'Boeing 747-436 RETIRED'
@@ -187,7 +187,7 @@ aircraft:
-
id: 5
subfleet_id: 4
icao: 'A320'
icao: A320
iata: '320'
airport_id: EGLL
landing_time: null

View File

@@ -180,12 +180,12 @@
type: number
description: 'How much the load factor can vary per-flight'
- key: simbrief.api_key
name: 'Simbrief API Key'
name: 'SimBrief API Key'
group: simbrief
value: ''
options: ''
type: string
description: 'Your Simbrief API key'
description: 'Your SimBrief API key'
- key: simbrief.only_bids
name: 'Only allow for bids'
group: simbrief
@@ -194,47 +194,12 @@
type: boolean
description: 'Only allow briefs to be created for bidded flights'
- key: simbrief.expire_days
name: 'Simbrief Expire Time'
name: 'SimBrief Expire Time'
group: simbrief
value: 5
options: ''
type: number
description: 'Days after how long to remove unused briefs'
- key: simbrief.noncharter_pax_weight
name: 'Non-Charter Passenger Weight'
group: simbrief
value: 185
options: ''
type: number
description: 'Passenger weight for non-charter flights excluding baggage (lbs)'
- key: simbrief.noncharter_baggage_weight
name: 'Non-Charter Baggage Weight'
group: simbrief
value: 35
options: ''
type: number
description: 'Passenger baggage weight for non-charter flights (lbs)'
- key: simbrief.charter_pax_weight
name: 'Charter Passenger Weight'
group: simbrief
value: 168
options: ''
type: number
description: 'Passenger weight for charter flights excluding baggage (lbs)'
- key: simbrief.charter_baggage_weight
name: 'Charter Baggage Weight'
group: simbrief
value: 28
options: ''
type: number
description: 'Passenger baggage weight for charter flights (lbs)'
- key: simbrief.callsign
name: 'Use ATC Callsign'
group: simbrief
value: false
options: ''
type: boolean
description: 'Use pilot ident as Simbrief ATC Callsign'
- key: pireps.duplicate_check_time
name: 'PIREP duplicate time check'
group: pireps
@@ -263,27 +228,6 @@
options: ''
type: boolean
description: 'When a PIREP is accepted, remove the bid, if it exists'
- key: pireps.advanced_fuel
name: 'Advanced Fuel Calculations'
group: pireps
value: false
options: ''
type: boolean
description: 'Enables remaining fuel amounts to be considered for fuel expenses'
- key: pireps.delete_cancelled_hours
name: 'Delete cancelled PIREPs'
group: pireps
value: 12
options: ''
type: int
description: 'The time in hours to delete a cancelled PIREP'
- key: pireps.delete_rejected_hours
name: 'Delete rejected PIREPs'
group: pireps
value: 12
options: ''
type: int
description: 'The time in hours to delete a rejected PIREP'
- key: pilots.id_length
name: 'Pilot ID Length'
group: pilots
@@ -361,9 +305,3 @@
options: ''
type: 'text'
description: 'Discord public channel ID for broadcasat notifications'
- key: 'cron.random_id'
name: 'Cron Randomized ID'
group: 'cron'
value: ''
type: 'hidden'
description: ''

View File

@@ -18,7 +18,7 @@ class ValidationException extends AbstractHttpException
parent::__construct(
400,
'Validation Error'
'Validation exception'
);
}

View File

@@ -1,37 +0,0 @@
<?php
namespace App\Exceptions;
class CronInvalid extends AbstractHttpException
{
public const MESSAGE = 'Cron ID is disabled or invalid';
public function __construct()
{
parent::__construct(400, static::MESSAGE);
}
/**
* Return the RFC 7807 error type (without the URL root)
*/
public function getErrorType(): string
{
return 'cron-invalid';
}
/**
* Get the detailed error string
*/
public function getErrorDetails(): string
{
return $this->getMessage();
}
/**
* Return an array with the error details, merged with the RFC7807 response
*/
public function getErrorMetadata(): array
{
return [];
}
}

View File

@@ -160,7 +160,6 @@ class AircraftController extends Controller
*/
public function update($id, UpdateAircraftRequest $request)
{
/** @var \App\Models\Aircraft $aircraft */
$aircraft = $this->aircraftRepo->findWithoutFail($id);
if (empty($aircraft)) {
@@ -172,7 +171,7 @@ class AircraftController extends Controller
$this->aircraftRepo->update($attrs, $id);
Flash::success('Aircraft updated successfully.');
return redirect(route('admin.aircraft.index').'?subfleet='.$aircraft->subfleet_id);
return redirect(route('admin.aircraft.index'));
}
/**
@@ -184,7 +183,6 @@ class AircraftController extends Controller
*/
public function destroy($id)
{
/** @var \App\Models\Aircraft $aircraft */
$aircraft = $this->aircraftRepo->findWithoutFail($id);
if (empty($aircraft)) {

View File

@@ -186,13 +186,13 @@ class AwardController extends Controller
{
$award = $this->awardRepository->findWithoutFail($id);
if (empty($award)) {
Flash::error('Award not found');
Flash::error('Fare not found');
return redirect(route('admin.awards.index'));
}
$this->awardRepository->delete($id);
Flash::success('Award deleted successfully.');
Flash::success('Fare deleted successfully.');
return redirect(route('admin.awards.index'));
}

View File

@@ -6,7 +6,6 @@ use App\Contracts\Controller;
use App\Repositories\KvpRepository;
use App\Services\CronService;
use App\Services\VersionService;
use App\Support\Utils;
use Codedge\Updater\UpdaterManager;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
@@ -35,12 +34,7 @@ class MaintenanceController extends Controller
public function index()
{
// Get the cron URL
$cron_id = setting('cron.random_id');
$cron_url = empty($cron_id) ? 'Not enabled' : url(route('api.maintenance.cron', $cron_id));
return view('admin.maintenance.index', [
'cron_url' => $cron_url,
'cron_path' => $this->cronSvc->getCronExecString(),
'cron_problem_exists' => $this->cronSvc->cronProblemExists(),
'new_version' => $this->kvpRepo->get('new_version_available', false),
@@ -123,33 +117,4 @@ class MaintenanceController extends Controller
return redirect('/update/downloader');
}
/**
* Enable the cron, or if it's enabled, change the ID that is used
*
* @param Request $request
*/
public function cron_enable(Request $request)
{
$id = Utils::generateNewId(24);
setting_save('cron.random_id', $id);
Flash::success('Web cron refreshed!');
return redirect(route('admin.maintenance.index'));
}
/**
* Disable the web cron
*
* @param Request $request
*
* @return mixed
*/
public function cron_disable(Request $request)
{
setting_save('cron.random_id', '');
Flash::success('Web cron disabled!');
return redirect(route('admin.maintenance.index'));
}
}

View File

@@ -394,10 +394,10 @@ class PirepController extends Controller
return redirect(route('admin.pireps.index'));
}
$this->pirepSvc->delete($pirep);
$this->pirepRepo->delete($id);
Flash::success('Pirep deleted successfully.');
return redirect()->back();
return redirect(route('admin.pireps.index'));
}
/**

View File

@@ -62,7 +62,7 @@ class SettingsController extends Controller
*/
public function index()
{
$settings = Setting::where('type', '!=', 'hidden')->orderBy('order')->get();
$settings = Setting::orderBy('order', 'asc')->get();
$settings = $settings->groupBy('group');
return view('admin.settings.index', [

View File

@@ -7,7 +7,6 @@ use App\Http\Controllers\Admin\Traits\Importable;
use App\Http\Requests\CreateSubfleetRequest;
use App\Http\Requests\UpdateSubfleetRequest;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\FareType;
use App\Models\Enums\FuelType;
use App\Models\Enums\ImportExportType;
@@ -134,7 +133,6 @@ class SubfleetController extends Controller
{
return view('admin.subfleets.create', [
'airlines' => Airline::all()->pluck('name', 'id'),
'hubs' => Airport::where('hub', 1)->pluck('name', 'id'),
'fuel_types' => FuelType::labels(),
]);
}
@@ -205,7 +203,6 @@ class SubfleetController extends Controller
return view('admin.subfleets.edit', [
'airlines' => Airline::all()->pluck('name', 'id'),
'hubs' => Airport::where('hub', 1)->pluck('name', 'id'),
'fuel_types' => FuelType::labels(),
'avail_fares' => $avail_fares,
'avail_ranks' => $avail_ranks,

View File

@@ -7,7 +7,6 @@ use App\Exceptions\AssetNotFound;
use App\Http\Resources\Flight as FlightResource;
use App\Http\Resources\Navdata as NavdataResource;
use App\Models\SimBrief;
use App\Models\User;
use App\Repositories\Criteria\WhereCriteria;
use App\Repositories\FlightRepository;
use App\Services\FareService;
@@ -153,25 +152,20 @@ class FlightController extends Controller
*
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
*/
public function briefing(string $id)
public function briefing($id)
{
/** @var User $user */
$user = Auth::user();
$w = [
'id' => $id,
'user_id' => $user->id,
'flight_id' => $id,
];
/** @var SimBrief $simbrief */
$simbrief = SimBrief::where($w)->first();
if ($simbrief === null) {
throw new AssetNotFound(new Exception('Flight briefing not found'));
}
/*if ($simbrief->user_id !== $user->id) {
throw new Unauthorized(new Exception('User cannot access another user\'s simbrief'));
}*/
return response($simbrief->acars_xml, 200, [
'Content-Type' => 'application/xml',
]);

View File

@@ -1,35 +0,0 @@
<?php
namespace App\Http\Controllers\Api;
use App\Contracts\Controller;
use App\Exceptions\CronInvalid;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
class MaintenanceController extends Controller
{
/**
* Run the cron job from the web
*
* @param Request $request
* @param string $id The ID passed in for the cron
*
* @return mixed
*/
public function cron(Request $request, string $id)
{
$cron_id = setting('cron.random_id');
if (empty($cron_id) || $id !== $cron_id) {
throw new CronInvalid();
}
$output = '';
Artisan::call('schedule:run');
$output .= trim(Artisan::output());
return response([
'content' => $output,
]);
}
}

View File

@@ -22,6 +22,8 @@ use App\Models\Acars;
use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepFieldSource;
use App\Models\Enums\PirepSource;
use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus;
use App\Models\Pirep;
use App\Models\PirepComment;
use App\Repositories\AcarsRepository;
@@ -36,6 +38,9 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
/**
* Class PirepController
*/
class PirepController extends Controller
{
private $acarsRepo;
@@ -88,10 +93,6 @@ class PirepController extends Controller
$attrs['created_at'] = Carbon::createFromTimeString($attrs['created_at']);
}
if (array_key_exists('submitted_at', $attrs)) {
$attrs['submitted_at'] = Carbon::createFromTimeString($attrs['submitted_at']);
}
if (array_key_exists('updated_at', $attrs)) {
$attrs['updated_at'] = Carbon::createFromTimeString($attrs['updated_at']);
}
@@ -305,8 +306,14 @@ class PirepController extends Controller
}
}
$attrs['state'] = PirepState::PENDING;
$attrs['status'] = PirepStatus::ARRIVED;
$attrs['submitted_at'] = Carbon::now('UTC');
$pirep = $this->pirepRepo->update($attrs, $pirep_id);
try {
$pirep = $this->pirepSvc->file($pirep, $attrs);
$pirep = $this->pirepSvc->create($pirep);
$this->updateFields($pirep, $request);
$this->updateFares($pirep, $request);
} catch (\Exception $e) {

View File

@@ -106,8 +106,7 @@ class UserController extends Controller
*/
public function bids(Request $request)
{
$user_id = $this->getUserId($request);
$user = $this->userSvc->getUser($user_id);
$user = $this->userSvc->getUser($this->getUserId($request));
// Add a bid
if ($request->isMethod('PUT') || $request->isMethod('POST')) {

View File

@@ -28,10 +28,7 @@ class DashboardController extends Controller
*/
public function index()
{
//dd(config('backup'));
$last_pirep = null;
/** @var \App\Models\User $user */
$user = Auth::user();
try {

View File

@@ -42,14 +42,7 @@ class DownloadController extends Controller
$category = explode('\\', $class);
$category = end($category);
if ($category == 'Aircraft') {
$group_name = $category.' > '.$obj->icao.' '.$obj->registration;
} elseif ($category == 'Airport') {
$group_name = $category.' > '.$obj->icao.' : '.$obj->name.' ('.$obj->country.')';
} else {
$group_name = $category.' > '.$obj->name;
}
$group_name = $category.' - '.$obj->name;
$regrouped_files[$group_name] = $files;
}

View File

@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Frontend;
use App\Contracts\Controller;
use App\Models\Bid;
use App\Models\Enums\FlightType;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\Criteria\WhereCriteria;
@@ -106,13 +105,7 @@ class FlightController extends Controller
}
$flights = $this->flightRepo->searchCriteria($request)
->with([
'dpt_airport',
'arr_airport',
'airline',
'simbrief' => function ($query) use ($user) {
$query->where('user_id', $user->id);
}, ])
->with(['dpt_airport', 'arr_airport', 'airline'])
->orderBy('flight_number', 'asc')
->orderBy('route_leg', 'asc')
->paginate();
@@ -121,15 +114,12 @@ class FlightController extends Controller
->pluck('flight_id')->toArray();
return view('flights.index', [
'user' => $user,
'airlines' => $this->airlineRepo->selectBoxList(true),
'airports' => $this->airportRepo->selectBoxList(true),
'flights' => $flights,
'saved' => $saved_flights,
'subfleets' => $this->subfleetRepo->selectBoxList(true),
'flight_number' => $request->input('flight_number'),
'flight_types' => FlightType::select(true),
'flight_type' => $request->input('flight_type'),
'arr_icao' => $request->input('arr_icao'),
'dep_icao' => $request->input('dep_icao'),
'subfleet_id' => $request->input('subfleet_id'),
@@ -154,18 +144,11 @@ class FlightController extends Controller
$flights = collect();
$saved_flights = [];
foreach ($user->bids as $bid) {
// Remove any invalid bids (flight doesn't exist or something)
if (!$bid->flight) {
$bid->delete();
continue;
}
$flights->add($bid->flight);
$saved_flights[] = $bid->flight->id;
}
return view('flights.bids', [
'user' => $user,
'airlines' => $this->airlineRepo->selectBoxList(true),
'airports' => $this->airportRepo->selectBoxList(true),
'flights' => $flights,

View File

@@ -7,7 +7,7 @@ use App\Http\Requests\CreatePirepRequest;
use App\Http\Requests\UpdatePirepRequest;
use App\Models\Enums\PirepSource;
use App\Models\Enums\PirepState;
use App\Models\Fare;
use App\Models\Enums\PirepStatus;
use App\Models\Pirep;
use App\Models\SimBrief;
use App\Models\User;
@@ -253,48 +253,23 @@ class PirepController extends Controller
/**
* They have a SimBrief ID, load that up and figure out the flight that it's from
*/
$fare_values = [];
$simbrief = null;
$simbrief_id = null;
$aircraft = null;
if ($request->has('sb_id')) {
$simbrief_id = $request->input('sb_id');
$simbrief = SimBrief::find($simbrief_id);
$pirep = Pirep::fromSimBrief($simbrief);
$aircraft = $simbrief->aircraft;
$aircraft_list[$aircraft->subfleet->name] = [];
$aircraft_list[$aircraft->subfleet->name][$aircraft->id] = $aircraft->name.' - '.$aircraft->registration;
// Convert the fare data into the expected output format
if (!empty($simbrief->fare_data)) {
$fare_values = json_decode($simbrief->fare_data, true);
$fares = [];
$fare_data = json_decode($simbrief->fare_data, true);
foreach ($fare_data as $fare) {
$fares[] = new Fare($fare);
}
$aircraft->subfleet->fares = collect($fares);
}
// TODO: Set more fields from the Simbrief to the PIREP form
} else {
$aircraft_list = $this->aircraftList(true);
$brief = SimBrief::find($simbrief_id);
$pirep = Pirep::fromSimBrief($brief);
}
return view('pireps.create', [
'aircraft' => $aircraft,
'aircraft' => null,
'pirep' => $pirep,
'read_only' => false,
'airline_list' => $this->airlineRepo->selectBoxList(true),
'aircraft_list' => $aircraft_list,
'aircraft_list' => $this->aircraftList(true),
'airport_list' => $this->airportRepo->selectBoxList(true),
'pirep_fields' => $this->pirepFieldRepo->all(),
'field_values' => [],
'fare_values' => $fare_values,
'simbrief_id' => $simbrief_id,
'simbrief' => $simbrief,
]);
}
@@ -518,8 +493,12 @@ class PirepController extends Controller
$this->pirepSvc->submit($pirep);
Flash::success('PIREP submitted!');
} elseif ($attrs['submit'] === 'delete' || $attrs['submit'] === 'cancel') {
$this->pirepSvc->delete($pirep);
Flash::success('PIREP deleted!');
$this->pirepRepo->update([
'state' => PirepState::CANCELLED,
'status' => PirepStatus::CANCELLED,
], $pirep->id);
Flash::success('PIREP cancelled!');
return redirect(route('frontend.pireps.index'));
}

View File

@@ -52,7 +52,7 @@ class ProfileController extends Controller
{
// Is the ACARS module enabled?
$acars_enabled = false;
$acars = Module::find('VMSAcars');
$acars = Module::find('VMSACARS');
if ($acars) {
$acars_enabled = $acars->isEnabled();
}
@@ -95,7 +95,6 @@ class ProfileController extends Controller
'user' => $user,
'userFields' => $userFields,
'airports' => $airports,
'acars' => $this->acarsEnabled(),
]);
}
@@ -122,7 +121,7 @@ class ProfileController extends Controller
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only'));
$userFields = $this->userRepo->getUserFields($user, true);
$userFields = $this->userRepo->getUserFields($user, false);
return view('profile.edit', [
'user' => $user,
@@ -197,7 +196,6 @@ class ProfileController extends Controller
});
$canvas->insert($image);
Log::info('Uploading avatar into folder '.public_path('uploads/avatars'));
$canvas->save(public_path('uploads/avatars/'.$file_name));
$req_data['avatar'] = $path;

View File

@@ -3,38 +3,22 @@
namespace App\Http\Controllers\Frontend;
use App\Exceptions\AssetNotFound;
use App\Models\Aircraft;
use App\Models\Enums\FareType;
use App\Models\Enums\FlightType;
use App\Models\Fare;
use App\Models\Flight;
use App\Models\SimBrief;
use App\Models\User;
use App\Repositories\FlightRepository;
use App\Services\FareService;
use App\Services\SimBriefService;
use App\Services\UserService;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class SimBriefController
{
private $fareSvc;
private $flightRepo;
private $simBriefSvc;
private $userSvc;
public function __construct(
FareService $fareSvc,
FlightRepository $flightRepo,
SimBriefService $simBriefSvc,
UserService $userSvc
) {
$this->fareSvc = $fareSvc;
public function __construct(FlightRepository $flightRepo, SimBriefService $simBriefSvc)
{
$this->flightRepo = $flightRepo;
$this->simBriefSvc = $simBriefSvc;
$this->userSvc = $userSvc;
}
/**
@@ -48,15 +32,8 @@ class SimBriefController
*/
public function generate(Request $request)
{
/** @var \App\Models\User $user */
$user = Auth::user();
$flight_id = $request->input('flight_id');
$aircraft_id = $request->input('aircraft_id');
/** @var Flight $flight */
$flight = $this->flightRepo->with(['fares', 'subfleets'])->find($flight_id);
$flight = $this->flightRepo->find($flight_id);
if (!$flight) {
flash()->error('Unknown flight');
return redirect(route('frontend.flights.index'));
@@ -68,22 +45,7 @@ class SimBriefController
return redirect(route('frontend.flights.index'));
}
// No aircraft selected, show selection form
if (!$aircraft_id) {
// If no subfleets defined for flight get them from user
if ($flight->subfleets->count() > 0) {
$subfleets = $flight->subfleets;
} else {
$subfleets = $this->userSvc->getAllowableSubfleets($user);
}
return view('flights.simbrief_aircraft', [
'flight' => $flight,
'subfleets' => $subfleets,
]);
}
// Check if a Simbrief profile already exists
$user = Auth::user();
$simbrief = SimBrief::select('id')->where([
'flight_id' => $flight_id,
'user_id' => $user->id,
@@ -93,119 +55,8 @@ class SimBriefController
return redirect(route('frontend.simbrief.briefing', [$simbrief->id]));
}
// SimBrief profile does not exists and everything else is ok
// Select aircraft which will be used for calculations and details
/** @var Aircraft $aircraft */
$aircraft = Aircraft::where('id', $aircraft_id)->first();
// Figure out the proper fares to use for this flight/aircraft
$all_fares = $this->fareSvc->getFareWithOverrides($aircraft->subfleet->fares, $flight->fares);
// TODO: Reconcile the fares for this aircraft w/ proper for the flight/subfleet
// Get passenger and baggage weights with failsafe defaults
if ($flight->flight_type === FlightType::CHARTER_PAX_ONLY) {
$pax_weight = setting('simbrief.charter_pax_weight', 168);
$bag_weight = setting('simbrief.charter_baggage_weight', 28);
} else {
$pax_weight = setting('simbrief.noncharter_pax_weight', 185);
$bag_weight = setting('simbrief.noncharter_baggage_weight', 35);
}
// Get the load factors with failsafe for loadmax if nothing is defined
$lfactor = $flight->load_factor ?? setting('flights.default_load_factor');
$lfactorv = $flight->load_factor_variance ?? setting('flights.load_factor_variance');
$loadmin = $lfactor - $lfactorv;
$loadmin = $loadmin < 0 ? 0 : $loadmin;
$loadmax = $lfactor + $lfactorv;
$loadmax = $loadmax > 100 ? 100 : $loadmax;
if ($loadmax === 0) {
$loadmax = 100;
}
// Load fares for passengers
$loaddist = []; // The load distribution string
$pax_load_sheet = [];
$tpaxfig = 0;
/** @var Fare $fare */
foreach ($all_fares as $fare) {
if ($fare->type !== FareType::PASSENGER || empty($fare->capacity)) {
continue;
}
$count = floor(($fare->capacity * rand($loadmin, $loadmax)) / 100);
$tpaxfig += $count;
$pax_load_sheet[] = [
'id' => $fare->id,
'code' => $fare->code,
'name' => $fare->name,
'type' => $fare->type,
'capacity' => (int) $fare->capacity,
'count' => $count,
];
$loaddist[] = $fare->code.' '.$count;
}
// Calculate total weights
if (setting('units.weight') === 'kg') {
$tpaxload = round(($pax_weight * $tpaxfig) / 2.205);
$tbagload = round(($bag_weight * $tpaxfig) / 2.205);
} else {
$tpaxload = round($pax_weight * $tpaxfig);
$tbagload = round($bag_weight * $tpaxfig);
}
// Load up fares for cargo
$tcargoload = 0;
$cargo_load_sheet = [];
foreach ($all_fares as $fare) {
if ($fare->type !== FareType::CARGO || empty($fare->capacity)) {
continue;
}
$count = ceil((($fare->capacity - $tbagload) * rand($loadmin, $loadmax)) / 100);
$tcargoload += $count;
$cargo_load_sheet[] = [
'id' => $fare->id,
'code' => $fare->code,
'name' => $fare->name,
'type' => $fare->type,
'capacity' => $fare->capacity,
'count' => $count,
];
$loaddist[] = $fare->code.' '.$count;
}
$tpayload = $tpaxload + $tbagload + $tcargoload;
$request->session()->put('simbrief_fares', array_merge($pax_load_sheet, $cargo_load_sheet));
// Show the main simbrief form
return view('flights.simbrief_form', [
'user' => Auth::user(),
'flight' => $flight,
'aircraft' => $aircraft,
'pax_weight' => $pax_weight,
'bag_weight' => $bag_weight,
'loadmin' => $loadmin,
'loadmax' => $loadmax,
'pax_load_sheet' => $pax_load_sheet,
'cargo_load_sheet' => $cargo_load_sheet,
'tpaxfig' => $tpaxfig,
'tpaxload' => $tpaxload,
'tbagload' => $tbagload,
'tpayload' => $tpayload,
'tcargoload' => $tcargoload,
'loaddist' => implode(' ', $loaddist),
'flight' => $flight,
]);
}
@@ -224,53 +75,11 @@ class SimBriefController
return redirect(route('frontend.flights.index'));
}
$str = $simbrief->xml->aircraft->equip;
$wc = stripos($str, '-');
$tr = stripos($str, '/');
$wakecat = substr($str, 0, $wc);
$equipment = substr($str, $wc + 1, $tr - 2);
$transponder = substr($str, $tr + 1);
return view('flights.simbrief_briefing', [
'simbrief' => $simbrief,
'wakecat' => $wakecat,
'equipment' => $equipment,
'transponder' => $transponder,
'simbrief' => $simbrief,
]);
}
/**
* Remove the flight_id from the SimBrief Briefing (to a create a new one)
* or if no pirep_id is attached to the briefing delete it completely
*
* @param \Illuminate\Http\Request $request
*
* @throws \Exception
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function generate_new(Request $request)
{
$simbrief = SimBrief::find($request->id);
// Invalid Simbrief ID/profile, go back to the main flight index
if (!$simbrief) {
return redirect(route('frontend.flights.index'));
}
// Cleanup the current Simbrief entry and redirect to the new generation form
// If there isn't a PIREP ID, then delete the entry, otherwise, remove the flight
$flight_id = $simbrief->flight_id;
if (!$simbrief->pirep_id) {
$simbrief->delete();
} else {
$simbrief->flight_id = null;
$simbrief->save();
}
return redirect(route('frontend.simbrief.generate').'?flight_id='.$flight_id);
}
/**
* Create a prefile of this PIREP with a given OFP. Then redirect the
* user to the newly prefiled PIREP
@@ -310,7 +119,6 @@ class SimBriefController
/**
* Check whether the OFP was generated. Pass in two items, the flight_id and ofp_id
* This does the actual "attachment" of the Simbrief to the flight
*
* @param \Illuminate\Http\Request $request
*
@@ -318,14 +126,10 @@ class SimBriefController
*/
public function check_ofp(Request $request)
{
/** @var User $user */
$user = Auth::user();
$ofp_id = $request->input('ofp_id');
$flight_id = $request->input('flight_id');
$aircraft_id = $request->input('aircraft_id');
$fares = $request->session()->get('simbrief_fares', []);
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares);
$simbrief = $this->simBriefSvc->checkForOfp(Auth::user()->id, $ofp_id, $flight_id);
if ($simbrief === null) {
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
return $error->getResponse();

View File

@@ -39,7 +39,7 @@ class ApiAuth implements Middleware
return $this->unauthorized('User not found with key "'.$api_key.'"');
}
if ($user->state !== UserState::ACTIVE && $user->state !== UserState::ON_LEAVE) {
if ($user->state !== UserState::ACTIVE) {
return $this->unauthorized('User is not ACTIVE, please contact an administrator');
}

View File

@@ -17,7 +17,6 @@ class Fare extends Resource
'name' => $this->name,
'capacity' => $this->capacity,
'cost' => $this->cost,
'count' => $this->count ?? 0,
'price' => $this->price,
'type' => $this->type,
'notes' => $this->notes,

View File

@@ -18,17 +18,17 @@ class Flight extends Resource
private function setFields()
{
/** @var \Illuminate\Support\Collection $field_values */
$return_values = new stdClass();
$field_values = $this->field_values;
if (empty($field_values) || $field_values->count() === 0) {
return $return_values;
return new stdClass();
}
$fields = [];
foreach ($field_values as $field) {
$return_values->{$field->name} = $field->value;
$fields[$field->name] = $field->value;
}
return $return_values;
return $fields;
}
/**

View File

@@ -27,7 +27,6 @@ class Pirep extends Resource
{
$res = parent::toArray($request);
$res['ident'] = $this->ident;
$res['phase'] = $this->status;
$res['status_text'] = PirepStatus::label($this->status);
// Set these to the response units
@@ -38,13 +37,6 @@ class Pirep extends Resource
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
$res['distance'] = $distance->getResponseUnits();
if (!array_key_exists('block_fuel', $res)) {
$res['block_fuel'] = 0;
}
$block_fuel = new Fuel($res['block_fuel'], config('phpvms.internal_units.fuel'));
$res['block_fuel'] = $block_fuel->getResponseUnits();
if (!array_key_exists('fuel_used', $res)) {
$res['fuel_used'] = 0;
}

View File

@@ -11,27 +11,9 @@ class SimBrief extends Resource
{
public function toArray($request)
{
$data = [
return [
'id' => $this->id,
'url' => url(route('api.flights.briefing', ['id' => $this->id])),
'url' => url(route('api.flights.briefing', ['id' => $this->flight_id])),
];
try {
if (!empty($this->fare_data)) {
$fares = [];
$fare_data = json_decode($this->fare_data, true);
foreach ($fare_data as $fare) {
$fares[] = new \App\Models\Fare($fare);
}
$this->aircraft->subfleet->fares = collect($fares);
}
} catch (\Exception $e) {
// Invalid fare data
}
$data['subfleet'] = new Subfleet($this->aircraft->subfleet);
return $data;
}
}

View File

@@ -15,8 +15,8 @@ class User extends Resource
'id' => $this->id,
'pilot_id' => $this->pilot_id,
'ident' => $this->ident,
'name' => $this->name_private,
'name_private' => $this->name_private,
'name' => $this->name,
'email' => $this->email,
'avatar' => $this->resolveAvatarUrl(),
'rank_id' => $this->rank_id,
'home_airport' => $this->home_airport_id,
@@ -24,7 +24,6 @@ class User extends Resource
'last_pirep_id' => $this->last_pirep_id,
'flights' => $this->flights,
'flight_time' => $this->flight_time,
'transfer_time' => $this->transfer_time,
'timezone' => $this->timezone,
'state' => $this->state,
];

View File

@@ -97,11 +97,6 @@ class Airline extends Model
$this->attributes['icao'] = strtoupper($icao);
}
public function subfleets()
{
return $this->hasMany(Subfleet::class, 'airline_id');
}
public function flights()
{
return $this->belongsTo(Flight::class, 'airline_id');

View File

@@ -20,14 +20,12 @@ class Fare extends Model
public $table = 'fares';
protected $fillable = [
'id',
'code',
'name',
'type',
'price',
'cost',
'capacity',
'count',
'notes',
'active',
];
@@ -36,7 +34,6 @@ class Fare extends Model
'price' => 'float',
'cost' => 'float',
'capacity' => 'integer',
'count' => 'integer',
'type' => 'integer',
'active' => 'boolean',
];

Some files were not shown because too many files have changed in this diff Show More