Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/v6.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Omranic committed Aug 22, 2021
2 parents a069083 + e416bbc commit b94ff86
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 129 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "03:00"
open-pull-requests-limit: 10
target-branch: develop
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
preset: recommended
risky: true

enabled:
- dir_constant
Expand Down Expand Up @@ -28,7 +29,6 @@ enabled:
- ternary_to_null_coalescing
- escape_implicit_backslashes
- fully_qualified_strict_types
- phpdoc_return_self_reference
- no_null_property_initialization
- multiline_comment_opening_closing
- not_operator_with_successor_space
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dist: bionic
language: php

php:
- 7.4
- 8.0
- 8.1

env:
global:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](CONTRIBUTING.md).


## [v6.0.0] - 2021-08-22
- Drop PHP v7 support, and upgrade rinvex package dependencies to next major version
- Update composer dependencies
- Upgrade to GitHub-native Dependabot
- Enable StyleCI risky mode
- Merge rules instead of resetting, to allow adequate model override
- Fix constructor initialization order (fill attributes should come next after merging fillables & rules)
- Set validation rules in constructor for consistency & flexibility
- Drop old MySQL versions support that doesn't support json columns
- Define morphMany parameters explicitly

## [v5.0.1] - 2020-12-25
- Add support for PHP v8

Expand Down Expand Up @@ -152,6 +163,7 @@ This project adheres to [Semantic Versioning](CONTRIBUTING.md).
## v0.0.1 - 2017-09-08
- Tag first release

[v6.0.0]: https://github.com/rinvex/laravel-bookings/compare/v5.0.1...v6.0.0
[v5.0.1]: https://github.com/rinvex/laravel-bookings/compare/v5.0.0...v5.0.1
[v5.0.0]: https://github.com/rinvex/laravel-bookings/compare/v4.1.0...v5.0.0
[v4.1.0]: https://github.com/rinvex/laravel-bookings/compare/v4.0.6...v4.1.0
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@
}
],
"require": {
"php": "^7.4.0 || ^8.0.0",
"php": "^8.0.0",
"illuminate/console": "^8.0.0 || ^9.0.0",
"illuminate/database": "^8.0.0 || ^9.0.0",
"illuminate/support": "^8.0.0 || ^9.0.0",
"rinvex/laravel-support": "^5.0.0",
"spatie/eloquent-sortable": "^3.7.0",
"spatie/laravel-schemaless-attributes": "^1.8.0",
"spatie/laravel-sluggable": "^2.2.0",
"spatie/laravel-translatable": "^4.2.0"
"rinvex/laravel-support": "^6.0.0",
"spatie/eloquent-sortable": "^4.0.0",
"spatie/laravel-schemaless-attributes": "^2.0.0",
"spatie/laravel-sluggable": "^3.0.0",
"spatie/laravel-translatable": "^5.0.0"
},
"require-dev": {
"codedungeon/phpunit-result-printer": "^0.30.0",
"codedungeon/phpunit-result-printer": "^0.31.0",
"illuminate/container": "^8.0.0 || ^9.0.0",
"phpunit/phpunit": "^9.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function up(): void
$table->integer('quantity')->unsigned();
$table->decimal('total_paid')->default('0.00');
$table->string('currency', 3);
$table->{$this->jsonable()}('formula')->nullable();
$table->json('formula')->nullable();
$table->schemalessAttributes('options');
$table->text('notes')->nullable();
$table->timestamps();
Expand All @@ -45,18 +45,4 @@ public function down(): void
{
Schema::dropIfExists(config('rinvex.bookings.tables.bookable_bookings'));
}

/**
* Get jsonable column data type.
*
* @return string
*/
protected function jsonable(): string
{
$driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
$dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
$isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');

return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function up()
$table->increments('id');
$table->morphs('ticketable');
$table->string('slug');
$table->{$this->jsonable()}('name');
$table->{$this->jsonable()}('description')->nullable();
$table->json('name');
$table->json('description')->nullable();
$table->boolean('is_active')->default(true);
$table->decimal('price')->default('0.00');
$table->string('currency', 3)->nullable();
Expand All @@ -41,18 +41,4 @@ public function down()
{
Schema::dropIfExists(config('rinvex.bookings.tables.ticketable_tickets'));
}

/**
* Get jsonable column data type.
*
* @return string
*/
protected function jsonable(): string
{
$driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
$dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
$isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');

return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
}
}
46 changes: 29 additions & 17 deletions src/Models/Bookable.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,35 @@ abstract class Bookable extends Model implements Sortable
*
* @var array
*/
protected $rules = [
'slug' => 'required|alpha_dash|max:150',
'name' => 'required|string|strip_tags|max:150',
'description' => 'nullable|string|max:32768',
'is_active' => 'sometimes|boolean',
'base_cost' => 'required|numeric',
'unit_cost' => 'required|numeric',
'currency' => 'required|string|size:3',
'unit' => 'required|in:minute,hour,day,month',
'maximum_units' => 'nullable|integer|max:100000',
'minimum_units' => 'nullable|integer|max:100000',
'is_cancelable' => 'nullable|boolean',
'is_recurring' => 'nullable|boolean',
'sort_order' => 'nullable|integer|max:100000',
'capacity' => 'nullable|integer|max:100000',
'style' => 'nullable|string|strip_tags|max:150',
];
protected $rules = [];

/**
* Create a new Eloquent model instance.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
$this->mergeRules([
'slug' => 'required|alpha_dash|max:150',
'name' => 'required|string|strip_tags|max:150',
'description' => 'nullable|string|max:32768',
'is_active' => 'sometimes|boolean',
'base_cost' => 'required|numeric',
'unit_cost' => 'required|numeric',
'currency' => 'required|string|size:3',
'unit' => 'required|in:minute,hour,day,month',
'maximum_units' => 'nullable|integer|max:100000',
'minimum_units' => 'nullable|integer|max:100000',
'is_cancelable' => 'nullable|boolean',
'is_recurring' => 'nullable|boolean',
'sort_order' => 'nullable|integer|max:100000',
'capacity' => 'nullable|integer|max:100000',
'style' => 'nullable|string|strip_tags|max:150',
]);

parent::__construct($attributes);
}

/**
* Get the active resources.
Expand Down
23 changes: 12 additions & 11 deletions src/Models/BookableAvailability.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ abstract class BookableAvailability extends Model
*
* @var array
*/
protected $rules = [
'bookable_id' => 'required|integer',
'bookable_type' => 'required|string|strip_tags|max:150',
'range' => 'required|in:datetimes,dates,months,weeks,days,times,sunday,monday,tuesday,wednesday,thursday,friday,saturday',
'from' => 'required|string|strip_tags|max:150',
'to' => 'required|string|strip_tags|max:150',
'is_bookable' => 'required|boolean',
'priority' => 'nullable|integer',
];
protected $rules = [];

/**
* Whether the model should throw a
Expand All @@ -76,9 +68,18 @@ abstract class BookableAvailability extends Model
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setTable(config('rinvex.bookings.tables.bookable_availabilities'));
$this->mergeRules([
'bookable_id' => 'required|integer',
'bookable_type' => 'required|string|strip_tags|max:150',
'range' => 'required|in:datetimes,dates,months,weeks,days,times,sunday,monday,tuesday,wednesday,thursday,friday,saturday',
'from' => 'required|string|strip_tags|max:150',
'to' => 'required|string|strip_tags|max:150',
'is_bookable' => 'required|boolean',
'priority' => 'nullable|integer',
]);

parent::__construct($attributes);
}

/**
Expand Down
37 changes: 19 additions & 18 deletions src/Models/BookableBooking.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,7 @@ abstract class BookableBooking extends Model
*
* @var array
*/
protected $rules = [
'bookable_id' => 'required|integer',
'bookable_type' => 'required|string|strip_tags|max:150',
'customer_id' => 'required|integer',
'customer_type' => 'required|string|strip_tags|max:150',
'starts_at' => 'required|date',
'ends_at' => 'required|date',
'price' => 'required|numeric',
'quantity' => 'required|integer',
'total_paid' => 'required|numeric',
'currency' => 'required|alpha|size:3',
'formula' => 'nullable|array',
'canceled_at' => 'nullable|date',
'options' => 'nullable|array',
'notes' => 'nullable|string|strip_tags|max:32768',
];
protected $rules = [];

/**
* Whether the model should throw a
Expand All @@ -100,9 +85,25 @@ abstract class BookableBooking extends Model
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setTable(config('rinvex.bookings.tables.bookable_bookings'));
$this->mergeRules([
'bookable_id' => 'required|integer',
'bookable_type' => 'required|string|strip_tags|max:150',
'customer_id' => 'required|integer',
'customer_type' => 'required|string|strip_tags|max:150',
'starts_at' => 'required|date',
'ends_at' => 'required|date',
'price' => 'required|numeric',
'quantity' => 'required|integer',
'total_paid' => 'required|numeric',
'currency' => 'required|alpha|size:3',
'formula' => 'nullable|array',
'canceled_at' => 'nullable|date',
'options' => 'nullable|array',
'notes' => 'nullable|string|strip_tags|max:32768',
]);

parent::__construct($attributes);
}

/**
Expand Down
25 changes: 13 additions & 12 deletions src/Models/BookableRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,7 @@ abstract class BookableRate extends Model
*
* @var array
*/
protected $rules = [
'bookable_id' => 'required|integer',
'bookable_type' => 'required|string|strip_tags|max:150',
'range' => 'required|in:datetimes,dates,months,weeks,days,times,sunday,monday,tuesday,wednesday,thursday,friday,saturday',
'from' => 'required|string|strip_tags|max:150',
'to' => 'required|string|strip_tags|max:150',
'base_cost' => 'nullable|numeric',
'unit_cost' => 'required|numeric',
'priority' => 'nullable|integer',
];
protected $rules = [];

/**
* Whether the model should throw a
Expand All @@ -79,9 +70,19 @@ abstract class BookableRate extends Model
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setTable(config('rinvex.bookings.tables.bookable_rates'));
$this->mergeRules([
'bookable_id' => 'required|integer',
'bookable_type' => 'required|string|strip_tags|max:150',
'range' => 'required|in:datetimes,dates,months,weeks,days,times,sunday,monday,tuesday,wednesday,thursday,friday,saturday',
'from' => 'required|string|strip_tags|max:150',
'to' => 'required|string|strip_tags|max:150',
'base_cost' => 'nullable|numeric',
'unit_cost' => 'required|numeric',
'priority' => 'nullable|integer',
]);

parent::__construct($attributes);
}

/**
Expand Down
32 changes: 22 additions & 10 deletions src/Models/Ticketable.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,7 @@ abstract class Ticketable extends Model
*
* @var array
*/
protected $rules = [
'slug' => 'required|alpha_dash|max:150',
'name' => 'required|string|strip_tags|max:150',
'description' => 'nullable|string|max:32768',
'is_public' => 'sometimes|boolean',
'starts_at' => 'required|date',
'ends_at' => 'required|date',
'timezone' => 'nullable|string|max:64|timezone',
'location' => 'nullable|string|strip_tags|max:1500',
];
protected $rules = [];

/**
* Whether the model should throw a
Expand All @@ -88,6 +79,27 @@ abstract class Ticketable extends Model
*/
protected $throwValidationExceptions = true;

/**
* Create a new Eloquent model instance.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
$this->mergeRules([
'slug' => 'required|alpha_dash|max:150',
'name' => 'required|string|strip_tags|max:150',
'description' => 'nullable|string|max:32768',
'is_public' => 'sometimes|boolean',
'starts_at' => 'required|date',
'ends_at' => 'required|date',
'timezone' => 'nullable|string|max:64|timezone',
'location' => 'nullable|string|strip_tags|max:1500',
]);

parent::__construct($attributes);
}

/**
* Get the public resources.
*
Expand Down
Loading

0 comments on commit b94ff86

Please sign in to comment.