From f70ccc7b98db497f84aaaed95306b843f4a24ad0 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Wed, 8 Jun 2022 13:06:03 +0100 Subject: [PATCH 01/10] Add branch name to split GA Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- .github/workflows/split.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/split.yml b/.github/workflows/split.yml index df39d5b3f4..72c1f0b620 100644 --- a/.github/workflows/split.yml +++ b/.github/workflows/split.yml @@ -34,6 +34,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} with: + branch: ${GITHUB_REF#refs/heads/} + package-directory: 'app/${{ matrix.package.path }}' split-repository-organization: 'tastyigniter' split-repository-name: '${{ matrix.package.repository }}' From aeb055b7d8aaa332308e9a74c3d4b59f3f388a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A1i=20Thi=C3=AAn=20V=C5=A9?= Date: Sun, 12 Jun 2022 05:56:51 +0700 Subject: [PATCH 02/10] New admin.list.extendRecords event (#989) --- app/admin/actions/ListController.php | 4 ++++ app/admin/traits/ListExtendable.php | 9 +++++++++ app/admin/widgets/Lists.php | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/app/admin/actions/ListController.php b/app/admin/actions/ListController.php index bb085d49ac..1a5dd81a40 100644 --- a/app/admin/actions/ListController.php +++ b/app/admin/actions/ListController.php @@ -199,6 +199,10 @@ public function makeList($alias) $this->controller->listExtendQuery($query, $alias); }); + $widget->bindEvent('list.extendRecords', function ($records) use ($alias) { + return $this->controller->listExtendRecords($records, $alias); + }); + $widget->bindEvent('list.overrideColumnValue', function ($record, $column, $value) use ($alias) { return $this->controller->listOverrideColumnValue($record, $column, $alias); }); diff --git a/app/admin/traits/ListExtendable.php b/app/admin/traits/ListExtendable.php index 0225542354..1f0038da20 100644 --- a/app/admin/traits/ListExtendable.php +++ b/app/admin/traits/ListExtendable.php @@ -51,6 +51,15 @@ public function listExtendQuery($query, $alias = null) { } + /** + * listExtendRecords controller override: Extend the records used for populating the list + * after the query is processed. + * @param Illuminate\Contracts\Pagination\LengthAwarePaginator|Illuminate\Database\Eloquent\Collection $records + */ + public function listExtendRecords($records, $alias = null) + { + } + /** * Controller override: Extend the query used for populating the filter * options before the default query is processed. diff --git a/app/admin/widgets/Lists.php b/app/admin/widgets/Lists.php index 1ff3107953..4847b54d62 100644 --- a/app/admin/widgets/Lists.php +++ b/app/admin/widgets/Lists.php @@ -410,6 +410,10 @@ protected function getRecords() $records = $model->get(); } + if ($event = $this->fireSystemEvent('admin.list.extendRecords', [&$records])) { + $records = $event; + } + return $this->records = $records; } From f49963529869512b42b4f831d1c904f955431be5 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Mon, 13 Jun 2022 23:50:27 +0100 Subject: [PATCH 03/10] Minor fix Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/admin/models/LocationOption.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/admin/models/LocationOption.php b/app/admin/models/LocationOption.php index 70e6dcf23f..a815a3e18a 100644 --- a/app/admin/models/LocationOption.php +++ b/app/admin/models/LocationOption.php @@ -177,20 +177,16 @@ protected function updateOptions() if (!$location = $this->locationContext) return false; - $records = $this->getAll(); - - collect($this->itemsToSaveCache) - ->filter(function ($value, $key) use ($records) { - return $value != array_get($records, $key); - }) - ->each(function ($value, $key) use ($location) { - self::updateOrCreate([ + self::upsert(collect($this->itemsToSaveCache) + ->map(function ($value, $key) use ($location) { + return [ 'location_id' => $location->location_id, 'item' => $key, - ], ['value' => $value]); - }); + 'value' => json_encode($value), + ]; + })->values()->all(), ['location_id', 'item'], ['value']); - static::$cache[$location->location_id] = null; + unset(static::$cache[$location->location_id]); return true; } From 3f5303e61fd89cbf5b24d0953ed42c470575e7bf Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Tue, 14 Jun 2022 23:44:27 +0100 Subject: [PATCH 04/10] Use locale dates formats in order and reservation emails fixes tastyigniter/ti-ext-reservation#30 Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/admin/models/Orders_model.php | 12 +++++------- app/admin/models/Reservations_model.php | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/admin/models/Orders_model.php b/app/admin/models/Orders_model.php index 532a20bc36..c1a1345323 100644 --- a/app/admin/models/Orders_model.php +++ b/app/admin/models/Orders_model.php @@ -361,17 +361,15 @@ public function mailGetData() $data['order_comment'] = $model->comment; $data['order_type'] = $model->order_type_name; - $data['order_time'] = Carbon::createFromTimeString($model->order_time)->format(lang('system::lang.php.time_format')); - $data['order_date'] = $model->order_date->format(lang('system::lang.php.date_format')); - $data['order_added'] = $model->created_at->format(lang('system::lang.php.date_time_format')); + $data['order_time'] = Carbon::createFromTimeString($model->order_time)->isoFormat(lang('system::lang.moment.time_format')); + $data['order_date'] = $model->order_date->isoFormat(lang('system::lang.moment.date_format')); + $data['order_added'] = $model->created_at->isoFormat(lang('system::lang.moment.date_time_format')); $data['invoice_id'] = $model->invoice_number; $data['invoice_number'] = $model->invoice_number; - $data['invoice_date'] = $model->invoice_date ? $model->invoice_date->format(lang('system::lang.php.date_format')) : null; + $data['invoice_date'] = $model->invoice_date ? $model->invoice_date->isoFormat(lang('system::lang.moment.date_format')) : null; - $data['order_payment'] = ($model->payment_method) - ? $model->payment_method->name - : lang('admin::lang.orders.text_no_payment'); + $data['order_payment'] = $model->payment_method->name ?? lang('admin::lang.orders.text_no_payment'); $data['order_menus'] = []; $menus = $model->getOrderMenusWithOptions(); diff --git a/app/admin/models/Reservations_model.php b/app/admin/models/Reservations_model.php index 01ad621344..3765793eec 100644 --- a/app/admin/models/Reservations_model.php +++ b/app/admin/models/Reservations_model.php @@ -435,8 +435,8 @@ public function mailGetData() $data['reservation'] = $model; $data['reservation_number'] = $model->reservation_id; $data['reservation_id'] = $model->reservation_id; - $data['reservation_time'] = Carbon::createFromTimeString($model->reserve_time)->format(lang('system::lang.php.time_format')); - $data['reservation_date'] = $model->reserve_date->format(lang('system::lang.php.date_format_long')); + $data['reservation_time'] = Carbon::createFromTimeString($model->reserve_time)->isoFormat(lang('system::lang.moment.time_format')); + $data['reservation_date'] = $model->reserve_date->isoFormat(lang('system::lang.moment.date_format_long')); $data['reservation_guest_no'] = $model->guest_num; $data['first_name'] = $model->first_name; $data['last_name'] = $model->last_name; From d5fd36cc216ff3f2e087642eeac776e5c2f1f0b9 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Wed, 15 Jun 2022 15:06:25 +0100 Subject: [PATCH 05/10] Minor refactor to assignables Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/admin/traits/Assignable.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/admin/traits/Assignable.php b/app/admin/traits/Assignable.php index e638ae1f31..e653c532ae 100644 --- a/app/admin/traits/Assignable.php +++ b/app/admin/traits/Assignable.php @@ -5,6 +5,7 @@ use Admin\Facades\AdminAuth; use Admin\Models\Assignable_logs_model; use Admin\Models\Staff_groups_model; +use Admin\Models\Staffs_model; use Illuminate\Database\Eloquent\Builder; trait Assignable @@ -63,12 +64,16 @@ public function assignToGroup($group) return $this->updateAssignTo($group); } - public function updateAssignTo($group = null, $assignee = null) + public function updateAssignTo(Staff_groups_model $group = null, Staffs_model $assignee = null) { if (is_null($group)) $group = $this->assignee_group; - $this->assignee_group()->associate($group); + if (is_null($group) && !is_null($assignee)) + $group = $assignee->groups()->first(); + + if (!is_null($group)) + $this->assignee_group()->associate($group); $oldAssignee = $this->assignee; if (!is_null($assignee)) @@ -78,8 +83,7 @@ public function updateAssignTo($group = null, $assignee = null) $this->save(); - if (!$log = Assignable_logs_model::createLog($this)) - return false; + $log = Assignable_logs_model::createLog($this); $this->fireSystemEvent('admin.assignable.assigned', [$log]); From d91683e927f7c11252cdf16ef9907cf947cc0d6a Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Wed, 15 Jun 2022 15:13:55 +0100 Subject: [PATCH 06/10] Add location logo mail variables Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/admin/models/Orders_model.php | 1 + app/admin/models/Reservations_model.php | 1 + app/system/language/en/lang.php | 1 + app/system/models/config/mail_variables.php | 2 ++ 4 files changed, 5 insertions(+) diff --git a/app/admin/models/Orders_model.php b/app/admin/models/Orders_model.php index c1a1345323..b16299b8d4 100644 --- a/app/admin/models/Orders_model.php +++ b/app/admin/models/Orders_model.php @@ -411,6 +411,7 @@ public function mailGetData() $data['order_address'] = format_address($model->address->toArray(), false); if ($model->location) { + $data['location_logo'] = $model->location->thumb; $data['location_name'] = $model->location->location_name; $data['location_email'] = $model->location->location_email; $data['location_telephone'] = $model->location->location_telephone; diff --git a/app/admin/models/Reservations_model.php b/app/admin/models/Reservations_model.php index 3765793eec..ea7e6079de 100644 --- a/app/admin/models/Reservations_model.php +++ b/app/admin/models/Reservations_model.php @@ -445,6 +445,7 @@ public function mailGetData() $data['reservation_comment'] = $model->comment; if ($model->location) { + $data['location_logo'] = $model->location->thumb; $data['location_name'] = $model->location->location_name; $data['location_email'] = $model->location->location_email; $data['location_telephone'] = $model->location->location_telephone; diff --git a/app/system/language/en/lang.php b/app/system/language/en/lang.php index 4d774063e3..7faf08f430 100644 --- a/app/system/language/en/lang.php +++ b/app/system/language/en/lang.php @@ -287,6 +287,7 @@ 'text_invoice_date' => 'Customer telephone address', 'text_order_menus' => 'Array of order menu items', 'text_order_comment' => 'Order comment', + 'text_location_logo' => 'Location logo', 'text_location_name' => 'Location name', 'text_location_email' => 'Location email', 'text_location_address' => 'Location address', diff --git a/app/system/models/config/mail_variables.php b/app/system/models/config/mail_variables.php index 1616eb5ec6..6c3b618a12 100644 --- a/app/system/models/config/mail_variables.php +++ b/app/system/models/config/mail_variables.php @@ -37,6 +37,7 @@ '{{ $invoice_number }}' => 'system::lang.mail_variables.text_invoice_number', '{{ $invoice_date }}' => 'system::lang.mail_variables.text_invoice_date', '{{ $order_comment }}' => 'system::lang.mail_variables.text_order_comment', + '{{ $location_logo }}' => 'system::lang.mail_variables.text_location_logo', '{{ $location_name }}' => 'system::lang.mail_variables.text_location_name', '{{ $location_email }}' => 'system::lang.mail_variables.text_location_email', '{{ $location_telephone }}' => 'system::lang.mail_variables.text_location_telephone', @@ -67,6 +68,7 @@ '{{ $email }}' => 'system::lang.mail_variables.text_email', '{{ $telephone }}' => 'system::lang.mail_variables.text_telephone', '{{ $reservation_comment }}' => 'system::lang.mail_variables.text_reservation_comment', + '{{ $location_logo }}' => 'system::lang.mail_variables.text_location_logo', '{{ $location_name }}' => 'system::lang.mail_variables.text_location_name', '{{ $location_email }}' => 'system::lang.mail_variables.text_location_email', '{{ $location_address }}' => 'system::lang.mail_variables.text_location_address', From a4530bdd93a0e6f08311cacfeba217e161b03da6 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:06:31 +0100 Subject: [PATCH 07/10] Move allocate table logic from booking manager to reservation model Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/admin/models/Reservations_model.php | 33 +++++++++++++++++++++++++ app/admin/models/config/menus_model.php | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/admin/models/Reservations_model.php b/app/admin/models/Reservations_model.php index ea7e6079de..9959b41810 100644 --- a/app/admin/models/Reservations_model.php +++ b/app/admin/models/Reservations_model.php @@ -64,6 +64,7 @@ class Reservations_model extends Model public $relation = [ 'belongsTo' => [ + 'customer' => 'Admin\Models\Customers_model', 'related_table' => ['Admin\Models\Tables_model', 'foreignKey' => 'table_id'], 'location' => 'Admin\Models\Locations_model', ], @@ -100,6 +101,10 @@ protected function afterSave() if (array_key_exists('tables', $this->attributes)) { $this->addReservationTables((array)$this->attributes['tables']); } + + if ($this->location->getOption('auto_allocate_table', 1) && !$this->tables()->count()) { + $this->addReservationTables($this->getNextBookableTable()->pluck('table_id')->all()); + } } // @@ -395,6 +400,34 @@ public function addReservationTables(array $tableIds = []) $this->tables()->sync($tableIds); } + /** + * @return \Illuminate\Support\Collection|null + */ + public function getNextBookableTable() + { + $tables = $this->location->tables->where('table_status', 1); + + $reserved = static::findReservedTables($this->location, $this->reservation_datetime); + + $tables = $tables->diff($reserved)->sortBy('priority'); + + $result = collect(); + $unseatedGuests = $this->guest_num; + foreach ($tables as $table) { + if ($table->min_capacity <= $this->guest_num && $table->max_capacity >= $this->guest_num) + return collect([$table]); + + if ($table->is_joinable && $unseatedGuests >= $table->min_capacity) { + $result->push($table); + $unseatedGuests -= $table->max_capacity; + if ($unseatedGuests <= 0) + break; + } + } + + return $unseatedGuests > 0 ? collect() : $result; + } + // // Mail // diff --git a/app/admin/models/config/menus_model.php b/app/admin/models/config/menus_model.php index 7936832a42..7fdc5bfb5d 100644 --- a/app/admin/models/config/menus_model.php +++ b/app/admin/models/config/menus_model.php @@ -261,7 +261,7 @@ 'modelClass' => 'Admin\Models\Menu_options_model', 'placeholder' => 'lang:admin::lang.menus.help_menu_option', 'formName' => 'lang:admin::lang.menu_options.text_option', - 'popupSize' => 'modal-lg', + 'popupSize' => 'modal-xl', 'addonRight' => [ 'label' => ' Add to Menu', 'tag' => 'button', From 4d9bdeb87334fe3bb944d0b470b9d75279d1b146 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:10:30 +0100 Subject: [PATCH 08/10] Minor fix Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/system/classes/UpdateManager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/system/classes/UpdateManager.php b/app/system/classes/UpdateManager.php index 48968ceef0..9bfe693226 100644 --- a/app/system/classes/UpdateManager.php +++ b/app/system/classes/UpdateManager.php @@ -408,6 +408,10 @@ public function requestUpdateList($force = false) $result['items'] = $items; $result['ignoredItems'] = $ignoredItems; + foreach ($ignoredItems as $item) { + $this->extensionManager->updateInstalledExtensions($item['code'], false); + } + return $result; } From ec0542bde084717d04f6bc8b7b9026bfab65eba7 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Thu, 30 Jun 2022 12:48:07 +0100 Subject: [PATCH 09/10] Add migration to drop all foreign keys due to irritating foreign key errors Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- ..._add_foreign_key_constraints_to_tables.php | 23 +-- ..._foreign_key_constraints_on_all_tables.php | 160 ++++++++++++++++++ ..._add_foreign_key_constraints_to_tables.php | 22 +-- ..._foreign_key_constraints_on_all_tables.php | 60 +++++++ 4 files changed, 245 insertions(+), 20 deletions(-) create mode 100644 app/admin/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php create mode 100644 app/system/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php diff --git a/app/admin/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php b/app/admin/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php index e8556e04ba..0526706f9d 100644 --- a/app/admin/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php +++ b/app/admin/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php @@ -13,22 +13,25 @@ public function up() { Schema::disableForeignKeyConstraints(); - foreach ($this->getForeignConstraints() as $tableName => $constraints) { - foreach ($constraints as $options) { - $this->addForeignKey($tableName, $options); - } - } + // Commented out so foreign keys are not added on new installations. + // For existing installations, another migration has been added to drop all foreign keys. + +// foreach ($this->getForeignConstraints() as $tableName => $constraints) { +// foreach ($constraints as $options) { +// $this->addForeignKey($tableName, $options); +// } +// } Schema::enableForeignKeyConstraints(); } public function down() { - foreach ($this->getForeignConstraints() as $tableName => $constraints) { - foreach ($constraints as $options) { - $this->dropForeignKey($tableName, $options); - } - } +// foreach ($this->getForeignConstraints() as $tableName => $constraints) { +// foreach ($constraints as $options) { +// $this->dropForeignKey($tableName, $options); +// } +// } } protected function addForeignKey($tableName, $options) diff --git a/app/admin/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php b/app/admin/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php new file mode 100644 index 0000000000..0342878460 --- /dev/null +++ b/app/admin/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php @@ -0,0 +1,160 @@ +getForeignConstraints() as $tableName => $constraints) { + foreach ($constraints as $options) { + $this->dropForeignKey($tableName, $options); + } + } + + Schema::enableForeignKeyConstraints(); + } + + public function down() + { + } + + protected function dropForeignKey($tableName, $options) + { + try { + Schema::table($tableName, function (Blueprint $table) use ($tableName, $options) { + $keys = (array)$options[1]; + $foreignKey = $keys[0]; + + $table->dropForeign([$foreignKey]); + $table->dropIndex(sprintf('%s%s_%s_foreign', DB::getTablePrefix(), $tableName, $foreignKey)); + }); + } + catch (\Exception $ex) { + Log::error($ex); + } + } + + protected function getForeignConstraints(): array + { + return [ + 'addresses' => [ + ['customers', 'customer_id', 'nullOnDelete' => true], + ['countries', 'country_id', 'nullOnDelete' => true], + ], + 'allergenables' => [ + ['allergens', 'allergen_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'assignable_logs' => [ + ['staffs', ['assignee_id', 'staff_id'], 'nullable' => false, 'nullOnDelete' => true], + ['staff_groups', ['assignee_group_id', 'staff_group_id'], 'nullable' => false, 'nullOnDelete' => true], + ['statuses', ['status_id', 'status_id'], 'nullable' => false, 'nullOnDelete' => true], + ], + 'categories' => [ + ['categories', ['parent_id', 'category_id'], 'nullOnDelete' => true], + ], + 'customers' => [ + ['addresses', 'address_id', 'nullOnDelete' => true], + ['customer_groups', 'customer_group_id', 'nullOnDelete' => true], + ], + 'location_areas' => [ + ['locations', 'location_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'locationables' => [ + ['locations', 'location_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'locations' => [ + ['countries', ['location_country_id', 'country_id'], 'cascadeOnDelete' => true], + ], + 'menu_categories' => [ + ['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['categories', 'category_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'menu_item_option_values' => [ + ['menu_item_options', 'menu_option_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['menu_option_values', 'option_value_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'menu_item_options' => [ + ['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['menu_options', 'option_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'menu_mealtimes' => [ + ['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['mealtimes', 'mealtime_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'menu_option_values' => [ + ['menu_options', 'option_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'menus_specials' => [ + ['menus', 'menu_id', 'cascadeOnDelete' => true], + ], + 'order_menu_options' => [ + ['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['order_menus', 'order_menu_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'order_menus' => [ + ['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'order_totals' => [ + ['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'orders' => [ + ['customers', 'customer_id', 'nullOnDelete' => true], + ['locations', 'location_id', 'nullOnDelete' => true], + ['addresses', 'address_id', 'nullOnDelete' => true], + ['statuses', 'status_id', 'nullOnDelete' => true], + ['staffs', ['assignee_id', 'staff_id'], 'nullOnDelete' => true], + ['staff_groups', ['assignee_group_id', 'staff_group_id'], 'nullOnDelete' => true], + ], + 'payment_logs' => [ + ['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'payment_profiles' => [ + ['customers', 'customer_id', 'cascadeOnDelete' => true], + ['payments', 'payment_id', 'cascadeOnDelete' => true], + ], + 'reservation_tables' => [ + ['reservations', 'reservation_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['tables', 'table_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'reservations' => [ + ['tables', 'table_id', 'nullOnDelete' => true], + ['customers', 'customer_id', 'nullOnDelete' => true], + ['locations', 'location_id', 'nullOnDelete' => true], + ['statuses', 'status_id', 'nullOnDelete' => true], + ['staffs', ['assignee_id', 'staff_id'], 'nullOnDelete' => true], + ['staff_groups', ['assignee_group_id', 'staff_group_id'], 'nullOnDelete' => true], + ], + 'staffs' => [ + ['staff_roles', 'staff_role_id', 'nullOnDelete' => true], + ['languages', 'language_id', 'nullOnDelete' => true], + ], + 'staffs_groups' => [ + ['staffs', 'staff_id', 'nullable' => false, 'cascadeOnDelete' => true], + ['staff_groups', 'staff_group_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'status_history' => [ + ['staffs', 'staff_id', 'nullOnDelete' => true], + ['statuses', 'status_id', 'nullOnDelete' => true], + ], + 'user_preferences' => [ + ['users', 'user_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'users' => [ + ['staffs', 'staff_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + 'working_hours' => [ + ['locations', 'location_id', 'nullable' => false, 'cascadeOnDelete' => true], + ], + ]; + } +} diff --git a/app/system/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php b/app/system/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php index 887c516a8c..e2f0747569 100644 --- a/app/system/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php +++ b/app/system/database/migrations/2021_10_25_010000_add_foreign_key_constraints_to_tables.php @@ -13,22 +13,24 @@ public function up() { Schema::disableForeignKeyConstraints(); - foreach ($this->getForeignConstraints() as $tableName => $constraints) { - foreach ($constraints as $options) { - $this->addForeignKey($tableName, $options); - } - } + // Commented out so foreign keys are not added on new installations. + // For existing installations, another migration has been added to drop all foreign keys. +// foreach ($this->getForeignConstraints() as $tableName => $constraints) { +// foreach ($constraints as $options) { +// $this->addForeignKey($tableName, $options); +// } +// } Schema::enableForeignKeyConstraints(); } public function down() { - foreach ($this->getForeignConstraints() as $tableName => $constraints) { - foreach ($constraints as $options) { - $this->dropForeignKey($tableName, $options); - } - } +// foreach ($this->getForeignConstraints() as $tableName => $constraints) { +// foreach ($constraints as $options) { +// $this->dropForeignKey($tableName, $options); +// } +// } } protected function addForeignKey($tableName, $options) diff --git a/app/system/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php b/app/system/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php new file mode 100644 index 0000000000..4d47508820 --- /dev/null +++ b/app/system/database/migrations/2022_06_30_010000_drop_foreign_key_constraints_on_all_tables.php @@ -0,0 +1,60 @@ +getForeignConstraints() as $tableName => $constraints) { + foreach ($constraints as $options) { + $this->dropForeignKey($tableName, $options); + } + } + + Schema::enableForeignKeyConstraints(); + } + + public function down() + { + } + + protected function dropForeignKey($tableName, $options) + { + try { + Schema::table($tableName, function (Blueprint $table) use ($options, $tableName) { + $keys = (array)$options[1]; + $foreignKey = $keys[0]; + + $table->dropForeign([$foreignKey]); + $table->dropIndex(sprintf('%s%s_%s_foreign', DB::getTablePrefix(), $tableName, $foreignKey)); + }); + } + catch (\Exception $ex) { + Log::error($ex); + } + } + + protected function getForeignConstraints(): array + { + return [ + 'currencies' => [ + ['countries', 'country_id', 'nullOnDelete' => true], + ], + 'mail_layouts' => [ + ['languages', 'language_id', 'nullOnDelete' => true], + ], + 'mail_templates' => [ + ['mail_layouts', 'layout_id', 'nullOnDelete' => true], + ], + ]; + } +} From 5e84a71261f1e42df0561c47efa226b94705b644 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Thu, 30 Jun 2022 15:41:58 +0100 Subject: [PATCH 10/10] Ensure list column names do not much model relation name Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/admin/models/config/categories_model.php | 5 +++-- app/admin/models/config/mealtimes_model.php | 3 ++- app/admin/models/config/menus_model.php | 3 ++- app/admin/models/config/status_history_model.php | 3 ++- app/admin/models/config/tables_model.php | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/admin/models/config/categories_model.php b/app/admin/models/config/categories_model.php index 40044c280a..13775e311c 100644 --- a/app/admin/models/config/categories_model.php +++ b/app/admin/models/config/categories_model.php @@ -1,4 +1,5 @@ [ 'prompt' => 'lang:admin::lang.categories.text_filter_search', @@ -70,13 +71,13 @@ 'label' => 'lang:admin::lang.label_name', 'type' => 'text', ], - 'parent_cat' => [ + 'parent' => [ 'label' => 'lang:admin::lang.categories.column_parent', 'type' => 'text', 'relation' => 'parent_cat', 'select' => 'name', ], - 'locations' => [ + 'location_name' => [ 'label' => 'lang:admin::lang.column_location', 'type' => 'text', 'relation' => 'locations', diff --git a/app/admin/models/config/mealtimes_model.php b/app/admin/models/config/mealtimes_model.php index 830f1336d1..1a639a6601 100644 --- a/app/admin/models/config/mealtimes_model.php +++ b/app/admin/models/config/mealtimes_model.php @@ -1,4 +1,5 @@ [ 'location' => [ @@ -82,7 +83,7 @@ 'label' => 'lang:admin::lang.column_id', 'invisible' => true, ], - 'locations' => [ + 'location_name' => [ 'label' => 'lang:admin::lang.column_location', 'type' => 'text', 'relation' => 'locations', diff --git a/app/admin/models/config/menus_model.php b/app/admin/models/config/menus_model.php index 7fdc5bfb5d..19bd9ead1b 100644 --- a/app/admin/models/config/menus_model.php +++ b/app/admin/models/config/menus_model.php @@ -1,4 +1,5 @@ [ 'prompt' => 'lang:admin::lang.menus.text_filter_search', @@ -89,7 +90,7 @@ 'relation' => 'categories', 'select' => 'name', ], - 'locations' => [ + 'location_name' => [ 'label' => 'lang:admin::lang.column_location', 'type' => 'text', 'relation' => 'locations', diff --git a/app/admin/models/config/status_history_model.php b/app/admin/models/config/status_history_model.php index 278a0e79f2..1ecb97af56 100644 --- a/app/admin/models/config/status_history_model.php +++ b/app/admin/models/config/status_history_model.php @@ -1,4 +1,5 @@ [ 'label' => 'lang:admin::lang.statuses.column_time_date', @@ -9,7 +10,7 @@ 'relation' => 'staff', 'select' => 'staff_name', ], - 'status' => [ + 'status_name' => [ 'label' => 'lang:admin::lang.label_status', 'relation' => 'status', 'select' => 'status_name', diff --git a/app/admin/models/config/tables_model.php b/app/admin/models/config/tables_model.php index b61de97800..c3d3fb1dbb 100644 --- a/app/admin/models/config/tables_model.php +++ b/app/admin/models/config/tables_model.php @@ -1,4 +1,5 @@ [ 'prompt' => 'lang:admin::lang.tables.text_filter_search', @@ -90,7 +91,7 @@ 'type' => 'number', 'invisible' => true, ], - 'locations' => [ + 'location_name' => [ 'label' => 'lang:admin::lang.column_location', 'type' => 'text', 'relation' => 'locations',