Skip to content

Commit

Permalink
Merge pull request #51 from fleetbase/feature/upgrade-laravel-10x
Browse files Browse the repository at this point in the history
Upgraded to work with Laravel 10x
  • Loading branch information
roncodes authored Feb 6, 2024
2 parents 67ca975 + ff8721c commit acbad06
Show file tree
Hide file tree
Showing 29 changed files with 600 additions and 309 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
extensions: mbstring, xml, gd, zip, pdo_mysql, sockets, intl, bcmath, gmp
coverage: xdebug

Expand All @@ -28,6 +28,9 @@ jobs:
sudo apt-get update
sudo apt-get install -y libzip-dev libgd-dev libfreetype6-dev libjpeg-dev libpng-dev imagemagick libmagickwand-dev libmemcached-dev libgeos-dev libgmp-dev default-mysql-client libicu-dev
- name: Configure Composer Auth for Github
run: composer config --global github-oauth.github.com ${{ secrets._GITHUB_AUTH_TOKEN }}

- name: Validate composer.json and composer.lock
run: composer validate

Expand Down
34 changes: 17 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"fleetbase/laravel-mysql-spatial": "^1.0.2",
"illuminate/broadcasting": "^9.0|^10.0",
"illuminate/contracts": "^9.0|^10.0",
"illuminate/database": "^9.0|^10.0",
"illuminate/http": "^9.0|^10.0",
"illuminate/notifications": "^9.0|^10.0",
"illuminate/routing": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"aloha/twilio": "^5.0",
"aws/aws-sdk-php-laravel": "^3.7",
"giggsey/libphonenumber-for-php": "^8.13",
"grimzy/laravel-mysql-spatial": "^5.0",
"guzzlehttp/guzzle": "^7.4",
"hammerstone/fast-paginate": "^1.0",
"illuminate/broadcasting": "^7.0|^8.0|^9.0",
"illuminate/contracts": "^7.0|^8.0|^9.0",
"illuminate/database": "^7.0|^8.0|^9.0",
"illuminate/http": "^7.0|^8.0|^9.0",
"illuminate/notifications": "^7.0|^8.0|^9.0",
"illuminate/routing": "^7.0|^8.0|^9.0",
"illuminate/support": "^7.0|^8.0|^9.0",
"jdorn/sql-formatter": "^1.2",
"laravel/sanctum": "^2.15",
"laravel/sanctum": "^3.2",
"maatwebsite/excel": "^3.1",
"phpoffice/phpspreadsheet": "^1.28",
"phrity/websocket": "^1.7",
"pragmarx/countries": "^0.8.2",
"sentry/sentry-laravel": "*",
"spatie/laravel-activitylog": "^3.17",
"spatie/laravel-permission": "^5.5",
"spatie/laravel-responsecache": "^6.6",
"spatie/laravel-sluggable": "^2.6",
"vinkla/hashids": "^9.1",
"spatie/laravel-activitylog": "^4.7",
"spatie/laravel-permission": "^6.3",
"spatie/laravel-responsecache": "^7.4",
"spatie/laravel-sluggable": "^3.5",
"sqids/sqids": "^0.4.1",
"xantios/mimey": "^2.2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.34.1",
"nunomaduro/collision": "^5.11.0|^6.4.0",
"pestphp/pest": "^1.22.6",
"nunomaduro/collision": "^7.0",
"pestphp/pest": "^2.33.2",
"phpstan/phpstan": "^1.10.38",
"symfony/var-dumper": "^5.4.29"
},
Expand Down
4 changes: 4 additions & 0 deletions config/fleetbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
'connection' => [
'db' => env('DB_CONNECTION', 'mysql'),
'sandbox' => env('SANDBOX_DB_CONNECTION', 'sandbox')
],
'branding' => [
'logo_url' => 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/fleetbase-logo.png',
'icon_url' => 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/fleetbase-icon.png'
]
];
4 changes: 2 additions & 2 deletions migrations/2023_09_04_091906_create_failed_jobs_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFailedJobsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -33,4 +33,4 @@ public function down()
{
Schema::dropIfExists('failed_jobs');
}
}
};
4 changes: 2 additions & 2 deletions migrations/2023_10_18_080950_create_notifications_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateNotificationsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -32,4 +32,4 @@ public function down()
{
Schema::dropIfExists('notifications');
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('personal_access_tokens')) {
Schema::table('personal_access_tokens', function (Blueprint $table) {
if (!Schema::hasColumn('personal_access_tokens', 'expires_at')) {
$table->timestamp('expires_at')->nullable()->after('last_used_at');
}
});
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable('personal_access_tokens')) {
Schema::table('personal_access_tokens', function (Blueprint $table) {
if (Schema::hasColumn('personal_access_tokens', 'expires_at')) {
$table->dropColumn('expires_at');
}
});
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->string('event')->nullable()->after('subject_type');
});
}

public function down()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('event');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->uuid('batch_uuid')->nullable()->after('properties');
});
}

public function down()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('batch_uuid');
});
}
};
58 changes: 47 additions & 11 deletions src/Http/Controllers/Internal/v1/OnboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Fleetbase\Models\CompanyUser;
use Fleetbase\Models\User;
use Fleetbase\Models\VerificationCode;
use Fleetbase\Support\Http;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -40,19 +41,25 @@ public function createAccount(OnboardRequest $request)
$isAdmin = !User::exists();

// Get user properties
$name = $request->input('name');
$email = $request->input('email');
$phone = $request->input('phone');
$username = Str::slug($name . Str::random(3), '_');
$name = $request->input('name');
$email = $request->input('email');
$phone = $request->input('phone');
$timezone = $request->input('timezone', date_default_timezone_get());
$username = Str::slug($name . Str::random(3), '_');

// Prepare user attributes
$attributes = $this->_applyUserInfo([
'name' => $name,
'email' => $email,
'phone' => $phone,
'username' => $username,
'ip_address' => $request->ip(),
'timezone' => $timezone,
'status' => 'active',
], $request);

// create user account
$user = User::create([
'name' => $name,
'email' => $email,
'phone' => $phone,
'username' => $username,
'status' => 'active',
]);
$user = User::create($attributes);

// set the user password
$user->password = $request->input('password');
Expand Down Expand Up @@ -88,6 +95,35 @@ public function createAccount(OnboardRequest $request)
]);
}

private function _applyUserInfo($attributes, $request)
{
// Lookup user default details
try {
$info = Http::lookupIp($request);
} catch (\Exception $e) {
}

if ($info) {
$attributes['country'] = data_get($info, 'country_code');
$attributes['ip_address'] = data_get($info, 'ip', $request->ip());
$tzInfo = data_get($info, 'time_zone.name');
if ($tzInfo) {
$attributes['timezone'] = $tzInfo;
}
$attributes['meta'] = [
'areacode' => data_get($info, 'calling_code'),
'currency' => data_get($info, 'currency.code'),
'language' => data_get($info, 'languages.0'),
'country' => data_get($info, 'country_name'),
'contintent' => data_get($info, 'continent_name'),
'latitude' => data_get($info, 'latitude'),
'longitude' => data_get($info, 'longitude'),
];
}

return $attributes;
}

/**
* Send/Resend verification email.
*
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Controllers/Internal/v1/SettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ public function testMailConfig(Request $request)
config(['mail.default' => $mailer, 'mail.from' => $from, 'mail.mailers.smtp' => array_merge(['transport' => 'smtp'], $smtp)]);

try {
Mail::to($user)->send(new \Fleetbase\Mail\TestEmail());
Mail::send(new \Fleetbase\Mail\TestMail($user));
} catch (\Aws\Ses\Exception\SesException $e) {
$message = $e->getMessage();
$status = 'error';
} catch (\Swift_TransportException $e) {
$message = $e->getMessage();
$status = 'error';
} catch (\Exception $e) {
} catch (\Throwable $e) {
dd($e);
$message = $e->getMessage();
$status = 'error';
}
Expand Down
32 changes: 0 additions & 32 deletions src/Mail/TestEmail.php

This file was deleted.

Loading

0 comments on commit acbad06

Please sign in to comment.