From 474c6a0526023d04dd7aa990049c7ddbdecd8143 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Wed, 28 Jul 2021 18:39:38 +0100 Subject: [PATCH 1/4] Disable database strict mode to avoid default value errors --- config/database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/database.php b/config/database.php index 0c070eae84..1564c76589 100644 --- a/config/database.php +++ b/config/database.php @@ -54,7 +54,7 @@ 'collation' => 'utf8mb4_unicode_ci', 'prefix' => env('DB_PREFIX', 'ti_'), 'prefix_indexes' => TRUE, - 'strict' => TRUE, + 'strict' => FALSE, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), From 517736797315f89cec69d0473d38a5a2f32ab2e1 Mon Sep 17 00:00:00 2001 From: BreakSecurity <38836022+BreakSecurity@users.noreply.github.com> Date: Fri, 30 Jul 2021 15:03:06 +0200 Subject: [PATCH 2/4] Remove all hardcoded lang strings in admin (#823) * System * Admin part 1 controllers * AdminController lang fix * BasePaymentGateway lang * FormWidgetLang * formWidget 2 lang * Admin various * Models * Dashboard widget lang * Filter widget lang * List & Form lang * lang in table and menu * Fixes & Adjustments * style ci * refactor Co-authored-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/admin/actions/FormController.php | 2 +- app/admin/classes/AdminController.php | 9 ++-- app/admin/classes/BasePaymentGateway.php | 6 +-- app/admin/controllers/Menus.php | 2 +- app/admin/controllers/Orders.php | 2 +- app/admin/controllers/Payments.php | 4 +- app/admin/controllers/Reservations.php | 2 +- app/admin/formwidgets/Connector.php | 2 +- app/admin/formwidgets/DataTable.php | 2 +- app/admin/formwidgets/MapArea.php | 2 +- app/admin/formwidgets/MediaFinder.php | 4 +- app/admin/formwidgets/RecordEditor.php | 2 +- app/admin/formwidgets/Relation.php | 2 +- app/admin/formwidgets/ScheduleEditor.php | 2 +- app/admin/formwidgets/StatusEditor.php | 4 +- app/admin/jobs/AllocateAssignable.php | 2 +- app/admin/language/en/lang.php | 53 ++++++++++++++++++++- app/admin/models/Customers_model.php | 3 +- app/admin/models/Payments_model.php | 2 +- app/admin/models/User_preferences_model.php | 2 +- app/admin/traits/FormModelWidget.php | 8 ++-- app/admin/traits/HasWorkingHours.php | 10 ++-- app/admin/traits/WidgetMaker.php | 4 +- app/admin/widgets/DashboardContainer.php | 26 +++++----- app/admin/widgets/Filter.php | 6 ++- app/admin/widgets/Form.php | 4 +- app/admin/widgets/Lists.php | 6 +-- app/admin/widgets/Menu.php | 12 ++--- app/admin/widgets/Table.php | 4 +- app/main/language/en/lang.php | 2 + app/system/controllers/MailTemplates.php | 4 +- app/system/controllers/Updates.php | 6 +-- app/system/language/en/lang.php | 6 +++ 33 files changed, 134 insertions(+), 73 deletions(-) diff --git a/app/admin/actions/FormController.php b/app/admin/actions/FormController.php index 2eac71bd89..4544d3165f 100644 --- a/app/admin/actions/FormController.php +++ b/app/admin/actions/FormController.php @@ -533,7 +533,7 @@ protected function validateFormRequest($model) return; if (!class_exists($requestClass)) - throw new ApplicationException("Form Request class ($requestClass) not found"); + throw new ApplicationException(sprintf(lang('admin::lang.form.request_class_not_found'), $requestClass)); $this->resolveFormRequest($requestClass); } diff --git a/app/admin/classes/AdminController.php b/app/admin/classes/AdminController.php index 9a56332543..20f029842d 100644 --- a/app/admin/classes/AdminController.php +++ b/app/admin/classes/AdminController.php @@ -313,7 +313,7 @@ protected function processHandlers() protected function validateHandler($handler) { if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) { - throw new SystemException("Invalid ajax handler name: {$handler}"); + throw new SystemException(sprintf(lang('admin::lang.alert_invalid_ajax_handler_name'), $handler)); } } @@ -326,7 +326,7 @@ protected function validateHandlerPartials() foreach ($partials as $partial) { if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) { - throw new SystemException("Invalid partial name: $partial"); + throw new SystemException(sprintf(lang('admin::lang.alert_invalid_ajax_partial_name'), $partial)); } } @@ -391,10 +391,7 @@ protected function runHandler($handler, $params) $this->pageAction(); if (!isset($this->widgets[$widgetName])) { - throw new Exception(sprintf( - "A widget with class name '%s' has not been bound to the controller", - $widgetName - )); + throw new Exception(sprintf(lang('admin::lang.alert_widget_not_bound_to_controller'), $widgetName)); } if (($widget = $this->widgets[$widgetName]) AND method_exists($widget, $handlerName)) { diff --git a/app/admin/classes/BasePaymentGateway.php b/app/admin/classes/BasePaymentGateway.php index 448ba85c53..d55ac46110 100644 --- a/app/admin/classes/BasePaymentGateway.php +++ b/app/admin/classes/BasePaymentGateway.php @@ -209,7 +209,7 @@ public function supportsPaymentProfiles() */ public function updatePaymentProfile($customer, $data) { - throw new SystemException('The updatePaymentProfile() method is not supported by the payment gateway.'); + throw new SystemException(lang('admin::lang.payments.alert_update_payment_profile')); } /** @@ -219,7 +219,7 @@ public function updatePaymentProfile($customer, $data) */ public function deletePaymentProfile($customer, $profile) { - throw new SystemException('The deletePaymentProfile() method is not supported by the payment gateway.'); + throw new SystemException(lang('admin::lang.payments.alert_delete_payment_profile')); } /** @@ -229,7 +229,7 @@ public function deletePaymentProfile($customer, $profile) */ public function payFromPaymentProfile($order, $data = []) { - throw new SystemException('The payFromPaymentProfile() method is not supported by the payment gateway.'); + throw new SystemException(lang('admin::lang.payments.alert_pay_from_payment_profile')); } // diff --git a/app/admin/controllers/Menus.php b/app/admin/controllers/Menus.php index b9929b9fc5..f6a2eb69aa 100644 --- a/app/admin/controllers/Menus.php +++ b/app/admin/controllers/Menus.php @@ -64,7 +64,7 @@ public function edit_onChooseMenuOption($context, $recordId) { $menuOptionId = post('Menu._options'); if (!$menuOption = Menu_options_model::find($menuOptionId)) - throw new ApplicationException('Please select a menu option to attach'); + throw new ApplicationException(lang('admin::lang.menus.alert_menu_option_not_attached')); $model = $this->asExtension('FormController')->formFindModelObject($recordId); diff --git a/app/admin/controllers/Orders.php b/app/admin/controllers/Orders.php index 6629052c6f..7f3e1af36a 100644 --- a/app/admin/controllers/Orders.php +++ b/app/admin/controllers/Orders.php @@ -77,7 +77,7 @@ public function invoice($context, $recordId = null) $model = $this->formFindModelObject($recordId); if (!$model->hasInvoice()) - throw new ApplicationException('Invoice has not yet been generated'); + throw new ApplicationException(lang('admin::lang.orders.alert_invoice_not_generated')); $this->vars['model'] = $model; diff --git a/app/admin/controllers/Payments.php b/app/admin/controllers/Payments.php index 0122d7b0b4..7f5fcbe955 100644 --- a/app/admin/controllers/Payments.php +++ b/app/admin/controllers/Payments.php @@ -102,7 +102,7 @@ protected function getGateway($code) } if (!$gateway = PaymentGateways::instance()->findGateway($code)) { - throw new Exception('Unable to find payment gateway with code '.$code); + throw new Exception(sprintf(lang('admin::lang.payments.alert_code_not_found'), $code)); } return $this->gateway = $gateway; @@ -133,7 +133,7 @@ public function formExtendFields($form) public function formBeforeCreate($model) { if (!strlen($code = post('Payment.payment'))) - throw new ApplicationException('Invalid payment gateway code selected'); + throw new ApplicationException(lang('admin::lang.payments.alert_invalid_code')); $paymentGateway = PaymentGateways::instance()->findGateway($code); diff --git a/app/admin/controllers/Reservations.php b/app/admin/controllers/Reservations.php index 578a970aec..8133b563d2 100644 --- a/app/admin/controllers/Reservations.php +++ b/app/admin/controllers/Reservations.php @@ -101,7 +101,7 @@ public function calendarGenerateEvents($startAt, $endAt) public function calendarUpdateEvent($eventId, $startAt, $endAt) { if (!$reservation = Reservations_model::find($eventId)) - throw new Exception('No matching reservation found'); + throw new Exception(lang('admin::lang.reservations.alert_no_reservation_found')); $startAt = make_carbon($startAt); $endAt = make_carbon($endAt); diff --git a/app/admin/formwidgets/Connector.php b/app/admin/formwidgets/Connector.php index 857aaa07c2..d2342bd336 100644 --- a/app/admin/formwidgets/Connector.php +++ b/app/admin/formwidgets/Connector.php @@ -132,7 +132,7 @@ public function onLoadRecord() $model = $this->getRelationModel()->find($recordId); if (!$model) - throw new ApplicationException('Record not found'); + throw new ApplicationException(lang('admin::lang.form.record_not_found')); return $this->makePartial('recordeditor/form', [ 'formRecordId' => $recordId, diff --git a/app/admin/formwidgets/DataTable.php b/app/admin/formwidgets/DataTable.php index fa5801c7b7..92c7726077 100644 --- a/app/admin/formwidgets/DataTable.php +++ b/app/admin/formwidgets/DataTable.php @@ -173,7 +173,7 @@ public function getDataTableOptions($field, $data) $methodName = 'get'.studly_case($this->fieldName).'DataTableOptions'; if (!$this->model->methodExists($methodName) AND !$this->model->methodExists('getDataTableOptions')) { - throw new Exception(sprintf('Missing method [%s] in %s', 'getDataTableOptions', get_class($this->model))); + throw new Exception(sprintf(lang('admin::lang.alert_missing_method'), 'getDataTableOptions', get_class($this->model))); } if ($this->model->methodExists($methodName)) { diff --git a/app/admin/formwidgets/MapArea.php b/app/admin/formwidgets/MapArea.php index 3daeace066..978029852b 100644 --- a/app/admin/formwidgets/MapArea.php +++ b/app/admin/formwidgets/MapArea.php @@ -199,7 +199,7 @@ public function onSaveRecord() public function onDeleteArea() { if (!strlen($areaId = post('areaId'))) - throw new ApplicationException('Invalid area selected'); + throw new ApplicationException(lang('admin::lang.locations.alert_invalid_area')); $model = $this->getRelationModel()->find($areaId); if (!$model) diff --git a/app/admin/formwidgets/MediaFinder.php b/app/admin/formwidgets/MediaFinder.php index 3fa1a8bc2d..db34e92ad2 100644 --- a/app/admin/formwidgets/MediaFinder.php +++ b/app/admin/formwidgets/MediaFinder.php @@ -210,11 +210,11 @@ public function onAddAttachment() $items = post('items'); if (!is_array($items)) - throw new ApplicationException('Select an item to attach'); + throw new ApplicationException(lang('main::lang.media_manager.alert_select_item_to_attach')); $model = $this->model; if (!$model->exists) - throw new ApplicationException('You can only attach media to a saved form'); + throw new ApplicationException(lang('main::lang.media_manager.alert_only_attach_to_saved')); $manager = MediaLibrary::instance(); foreach ($items as &$item) { diff --git a/app/admin/formwidgets/RecordEditor.php b/app/admin/formwidgets/RecordEditor.php index ce6ccac4df..1bb1055d1b 100644 --- a/app/admin/formwidgets/RecordEditor.php +++ b/app/admin/formwidgets/RecordEditor.php @@ -201,7 +201,7 @@ protected function getRecordEditorOptions() $methodName = 'get'.studly_case($this->fieldName).'RecordEditorOptions'; if (!$model->methodExists($methodName) AND !$model->methodExists('getRecordEditorOptions')) { - throw new ApplicationException(sprintf('Missing method [%s] in %s', 'getRecordEditorOptions', get_class($model))); + throw new ApplicationException(sprintf(lang('admin::lang.alert_missing_method'), 'getRecordEditorOptions', get_class($model))); } if ($model->methodExists($methodName)) { diff --git a/app/admin/formwidgets/Relation.php b/app/admin/formwidgets/Relation.php index f30209a928..5f79bfe38c 100644 --- a/app/admin/formwidgets/Relation.php +++ b/app/admin/formwidgets/Relation.php @@ -212,7 +212,7 @@ protected function getRelationObject() [$model, $attribute] = $this->resolveModelAttribute($this->valueFrom); if (!$model OR !$model->hasRelation($attribute)) { - throw new Exception(sprintf("Model '%s' does not contain a definition for '%s'.", + throw new Exception(sprintf(lang('admin::lang.alert_missing_model_definition'), get_class($this->model), $this->valueFrom )); diff --git a/app/admin/formwidgets/ScheduleEditor.php b/app/admin/formwidgets/ScheduleEditor.php index 8e288341ec..90fef8c095 100644 --- a/app/admin/formwidgets/ScheduleEditor.php +++ b/app/admin/formwidgets/ScheduleEditor.php @@ -115,7 +115,7 @@ public function onSaveRecord() protected function getSchedule($scheduleCode) { if (!$schedule = array_get($this->listSchedules(), $scheduleCode)) - throw new ApplicationException('Schedule not loaded'); + throw new ApplicationException(lang('admin::lang.locations.alert_schedule_not_loaded')); return $schedule; } diff --git a/app/admin/formwidgets/StatusEditor.php b/app/admin/formwidgets/StatusEditor.php index 965359d4d2..66525432d0 100644 --- a/app/admin/formwidgets/StatusEditor.php +++ b/app/admin/formwidgets/StatusEditor.php @@ -129,7 +129,7 @@ public function onLoadRecord() { $context = post('recordId'); if (!in_array($context, ['load-status', 'load-assignee'])) - throw new ApplicationException('Invalid action'); + throw new ApplicationException(lang('admin::lang.statuses.alert_invalid_action')); $this->setMode(str_after($context, 'load-')); @@ -193,7 +193,7 @@ public function onLoadStatus() throw new ApplicationException(lang('admin::lang.form.missing_id')); if (!$status = Statuses_model::find($statusId)) - throw new Exception('Status ID ['.$statusId.'] not found.'); + throw new Exception(sprintf(lang('admin::lang.statuses.alert_status_not_found'), $statusId)); return $status->toArray(); } diff --git a/app/admin/jobs/AllocateAssignable.php b/app/admin/jobs/AllocateAssignable.php index d58e34fd14..da67fc3cce 100644 --- a/app/admin/jobs/AllocateAssignable.php +++ b/app/admin/jobs/AllocateAssignable.php @@ -49,7 +49,7 @@ public function handle() Allocator::addSlot($this->assignableLog->getKey()); if (!$assignee = $this->assignableLog->assignee_group->findAvailableAssignee()) - throw new Exception('No available assignee'); + throw new Exception(lang('admin::lang.staff_groups.alert_no_available_assignee')); $this->assignableLog->assignable->assignTo($assignee); diff --git a/app/admin/language/en/lang.php b/app/admin/language/en/lang.php index 3b1cb5d5a2..fabc921114 100644 --- a/app/admin/language/en/lang.php +++ b/app/admin/language/en/lang.php @@ -98,6 +98,16 @@ 'alert_warning_locationable_delete' => 'Warning: You do not have the right permission to delete record(s) attached to multiple locations, please contact the system administrator.', 'alert_form_error_message' => 'Sorry but form validation has failed, please check for errors.', 'alert_error_set_default' => '"%s" is disabled and cannot be set as default.', + 'alert_missing_method' => 'Missing method [%s] in %s.', + 'alert_missing_model_definition' => "Model '%s' does not contain a definition for '%s'.", + 'alert_valid_values' => 'Valid values for [locationAware] property are (none,show,hide).', + 'alert_widget_class_name' => "The Widget class name '%s' has not been registered", + 'alert_missing_field_property' => "Missing form field property 'modelClass' in '%s'", + 'alert_invalid_ajax_handler_name' => 'Invalid ajax handler name: %s', + 'alert_invalid_ajax_partial_name' => 'Invalid partial name: %s', + 'alert_widget_not_bound_to_controller' => "A widget with class name '%s' has not been bound to the controller", + 'alert_user_not_logged' => 'User is not logged in', + 'alert_access_denied' => 'Access denied.', 'alert_invalid_csrf_token' => 'Invalid security token, please reload the page and try again.', 'text_settings_title' => 'Settings', 'text_message_title' => 'Your messages', @@ -172,14 +182,19 @@ 'tool' => 'Tools', 'media_manager' => 'Media Manager', 'system' => 'System', + + 'alert_no_definition' => 'No definition for item %s.', + 'alert_invalid_menu' => 'Invalid item specified.', + 'alert_menu_not_found' => 'No main menu item found matching {%s}.', + 'alert_invalid_status' => 'Status message is required.', ], 'list' => [ 'missing_model' => 'List action used in %s does not have a model defined.', 'missing_definitions' => 'List action used in %s does not have definitions.', - 'missing_column' => 'Missing columns in List definitions %s', 'invalid_column_datetime' => 'Column value \'%s\' is not a DateTime object, are you missing a $dates reference in the Model?', 'delete_empty' => 'Nothing selected to delete.', + 'missing_column' => 'List used in %s has no list columns defined.', 'text_empty' => 'Nothing found.', 'text_setup' => 'Setup', 'text_showing' => 'Showing %s-%s of %s records', @@ -189,8 +204,11 @@ 'button_reset_setup' => 'Reset', 'button_cancel_setup' => 'Cancel', 'button_apply_setup' => 'Apply changes', + 'filter_missing_definitions' => "The model class %s must define a method %s returning options for the '%s' filter.", + 'filter_missing_scope_definitions' => 'No definition for scope %s', 'help_visible_columns' => 'Set which columns are visible and in what order to display them', 'help_page_limit' => 'Limit how many records are shown per page', + 'alert_relationship_not_supported' => 'The relationship %s is not supported for list columns.', ], 'calendar' => [ @@ -224,6 +242,9 @@ 'missing_id' => 'Form record ID has not been specified.', 'not_found' => 'Form record with ID [%s] could not be found.', 'mass_assignment_failed' => "Mass assignment failed for Model attribute ':attribute'.", + 'record_not_found' => 'Record not found.', + 'request_class_not_found' => 'Form Request class (%s) not found', + 'record_not_found_in_model' => 'Record ID [%s] not found in model %s.', 'save_actions' => [ 'continue' => 'Continue Editing', @@ -311,6 +332,8 @@ 'alert_login_restricted' => 'Warning: You do not have the right permission to access a customer account, please contact system administrator.', 'alert_impersonate_confirm' => 'Are you sure you want to impersonate this customer? You can revert to your original state by logging out.', 'alert_impersonate_success' => 'You are now impersonating customer: %s', + 'alert_customer_not_active' => "Cannot login user '%s' until activated.", + 'alert_customer_payment_profile_not_found' => 'Customer payment profile not found!', ], 'dashboard' => [ @@ -370,6 +393,15 @@ 'text_select_range' => 'Select date range', 'text_last_version_check' => 'Your last TastyIgniter core version check was more than a week ago. Check for Updates', + 'alert_select_widget_to_update' => 'Please select a widget to update.', + 'alert_select_widget_to_add' => 'Please select a widget to add.', + 'alert_widget_class_not_found' => 'The selected class does not exist.', + 'alert_invalid_widget' => 'The selected class is not a dashboard widget.', + 'alert_invalid_aliases' => 'Invalid aliases string.', + 'alert_invalid_priorities' => "'Invalid priorities string.'", + 'alert_invalid_data_posted' => 'Invalid data posted.', + 'alert_widget_not_found' => 'The specified widget is not found.', + 'onboarding' => [ 'title' => 'Getting started', 'label_settings' => 'Complete required system settings', @@ -527,6 +559,9 @@ 'alert_set_default' => 'Location set as default', 'alert_missing_map_center' => 'Map is missing center coordinates, please enter an address then click save.', 'alert_missing_map_config' => 'Missing Google Maps Javascript Library, please provide your maps api key on the general system settings page.', + 'alert_invalid_area' => 'Invalid area selected.', + 'alert_schedule_not_loaded' => 'Schedule not loaded.', + 'alert_invalid_schedule_type' => "Defined parameter '%s' is not a valid working type.", 'help_permalink_disabled' => 'Permalink is disabled when single location mode is activated.', 'help_image' => 'Select a logo for this location.', @@ -685,6 +720,7 @@ 'help_max_selected' => 'Maximum items to select from these options, leave blank to ignore.', 'help_option_required' => 'Select Enabled if a customer MUST choose this option. If this option is not required, select Disabled.', 'help_specials' => 'Select disable to deactivate Special. Select Enable to activate Special and enter the Start Date, End Date and price of your Special item.', + 'alert_menu_option_not_attached' => 'Please select a menu option to attach.', ], 'orders' => [ @@ -759,6 +795,8 @@ 'activity_event_log_assigned_title' => 'Order assigned', 'activity_event_log' => 'updated order (#:properties.order_id) status to :properties.status_name', 'activity_event_log_assigned' => 'assigned order (#:properties.order_id) to', + + 'alert_invoice_not_generated' => 'Invoice has not yet been generated.', ], 'payments' => [ @@ -774,6 +812,11 @@ 'label_priority' => 'Priority', 'alert_setting_missing_id' => 'Extension setting code has not been specified.', + 'alert_invalid_code' => 'Invalid payment gateway code selected.', + 'alert_code_not_found' => 'Unable to find payment gateway with code %s', + 'alert_update_payment_profile' => 'The updatePaymentProfile() method is not supported by the payment gateway.', + 'alert_delete_payment_profile' => 'The deletePaymentProfile() method is not supported by the payment gateway.', + 'alert_pay_from_payment_profile' => 'The payFromPaymentProfile() method is not supported by the payment gateway.', ], 'permissions' => [ @@ -857,6 +900,8 @@ 'activity_event_log_assigned_title' => 'Reservation assigned', 'activity_event_log' => 'updated reservation (#:properties.reservation_id) status to :properties.status_name', 'activity_event_log_assigned' => 'assigned reservation (#:properties.reservation_id) to', + + 'alert_no_reservation_found' => 'No matching reservation found.', ], 'settings' => [ @@ -881,6 +926,8 @@ 'column_users' => '# Users', + 'alert_no_available_assignee' => 'No available assignee.', + 'help_auto_assign' => 'Allocate and control the number of orders assigned to staff in this group.', 'help_round_robin' => 'Assign orders to the staff who are online in a circular fashion.', 'help_load_balanced' => 'Limit the number of orders a staff can handle simultaneously.', @@ -966,6 +1013,8 @@ 'help_assignee_group' => 'A notification is sent out to all the staff in the selected group', 'alert_already_added' => 'The selected %s must be different from the current %s', + 'alert_invalid_action' => 'Invalid action.', + 'alert_status_not_found' => 'Status ID [%s] not found.', ], 'tables' => [ @@ -990,5 +1039,7 @@ 'help_extra_capacity' => 'Used internally by the staff to determine table convenience/inconvenience.', 'error_capacity' => 'The Maximum capacity value must be greater than minimum capacity value.', + 'error_table_widget_data_not_specified' => 'The Table widget data source is not specified in the configuration.', + 'error_table_widget_data_class_not_found' => 'The Table widget data source class "%s" could not be found.', ], ]; diff --git a/app/admin/models/Customers_model.php b/app/admin/models/Customers_model.php index ac59c8cdd0..130cc51aa2 100644 --- a/app/admin/models/Customers_model.php +++ b/app/admin/models/Customers_model.php @@ -102,8 +102,7 @@ public function beforeLogin() if ($this->is_activated OR $this->status) return; - throw new Exception(sprintf( - 'Cannot login user "%s" until activated.', $this->email + throw new Exception(sprintf(lang('admin::lang.customers.alert_customer_not_active'), $this->email )); } diff --git a/app/admin/models/Payments_model.php b/app/admin/models/Payments_model.php index 6b9a733c14..2ff56ec1c0 100644 --- a/app/admin/models/Payments_model.php +++ b/app/admin/models/Payments_model.php @@ -301,7 +301,7 @@ public function deletePaymentProfile($customer) $profile = $this->findPaymentProfile($customer); if (!$profile) { - throw new ApplicationException('Customer payment profile not found!'); + throw new ApplicationException(lang('admin::lang.customers.alert_customer_payment_profile_not_found')); } $gatewayObj->deletePaymentProfile($customer, $profile); diff --git a/app/admin/models/User_preferences_model.php b/app/admin/models/User_preferences_model.php index 5709509d46..08954c8ed7 100644 --- a/app/admin/models/User_preferences_model.php +++ b/app/admin/models/User_preferences_model.php @@ -44,7 +44,7 @@ public function resolveUser() { $user = AdminAuth::getUser(); if (!$user) { - throw new Exception('User is not logged in'); + throw new Exception(lang('admin::lang.alert_user_not_logged')); } return $user; diff --git a/app/admin/traits/FormModelWidget.php b/app/admin/traits/FormModelWidget.php index e084e6fdcc..e22a08b879 100644 --- a/app/admin/traits/FormModelWidget.php +++ b/app/admin/traits/FormModelWidget.php @@ -19,7 +19,7 @@ trait FormModelWidget public function createFormModel() { if (!$this->modelClass) { - throw new ApplicationException(sprintf("Missing form field property 'modelClass' in '%s'", get_class($this))); + throw new ApplicationException(sprintf(lang('admin::lang.alert_missing_field_property'), get_class($this))); } $class = $this->modelClass; @@ -46,7 +46,7 @@ public function findFormModel($recordId) $result = $query->find($recordId); if (!$result) - throw new Exception('Record ID ['.$recordId.'] not found in model '.get_class($model)); + throw new Exception(sprintf(lang('admin::lang.form.record_not_found_in_model'), $recordId, get_class($model))); return $result; } @@ -83,7 +83,7 @@ protected function getRelationModel() [$model, $attribute] = $this->resolveModelAttribute($this->valueFrom); if (!$model OR !$model->hasRelation($attribute)) { - throw new ApplicationException(sprintf("Model '%s' does not contain a definition for '%s'.", + throw new ApplicationException(sprintf(lang('admin::lang.alert_missing_model_definition'), get_class($this->model), $this->valueFrom )); @@ -97,7 +97,7 @@ protected function getRelationObject() [$model, $attribute] = $this->resolveModelAttribute($this->valueFrom); if (!$model OR !$model->hasRelation($attribute)) { - throw new ApplicationException(sprintf("Model '%s' does not contain a definition for '%s'.", + throw new ApplicationException(sprintf(lang('admin::lang.alert_missing_model_definition'), get_class($this->model), $this->valueFrom )); diff --git a/app/admin/traits/HasWorkingHours.php b/app/admin/traits/HasWorkingHours.php index 9e16de3495..796294c074 100644 --- a/app/admin/traits/HasWorkingHours.php +++ b/app/admin/traits/HasWorkingHours.php @@ -90,8 +90,10 @@ public function getWorkingHourByDateAndType($date, $type) public function getWorkingHours() { if (!$this->hasRelation('working_hours')) - throw new Exception(sprintf("Model '%s' does not contain a definition for 'working_hours'.", - get_class($this))); + throw new Exception(sprintf(lang('admin::lang.alert_missing_model_definition'), + get_class($this), + 'working_hours', + )); if (!$this->working_hours OR $this->working_hours->isEmpty()) { $this->createDefaultWorkingHours(); @@ -109,7 +111,7 @@ public function newWorkingSchedule($type, $days = null) { $types = $this->availableWorkingTypes(); if (is_null($type) OR !in_array($type, $types)) - throw new InvalidArgumentException("Defined parameter '$type' is not a valid working type."); + throw new InvalidArgumentException(sprintf(lang('admin::lang.locations.alert_invalid_schedule_type'), $type)); if (is_null($days)) { $days = $this->hasFutureOrder($type) @@ -135,7 +137,7 @@ public function newWorkingSchedule($type, $days = null) public function createScheduleItem($type) { if (is_null($type) OR !in_array($type, $this->availableWorkingTypes())) - throw new InvalidArgumentException("Defined parameter '$type' is not a valid working type."); + throw new InvalidArgumentException(sprintf(lang('admin::lang.locations.alert_invalid_schedule_type'), $type)); $scheduleData = array_get($this->getOption('hours', []), $type, []); diff --git a/app/admin/traits/WidgetMaker.php b/app/admin/traits/WidgetMaker.php index 2443efa23a..0f7c08534d 100644 --- a/app/admin/traits/WidgetMaker.php +++ b/app/admin/traits/WidgetMaker.php @@ -28,7 +28,7 @@ public function makeWidget($class, $widgetConfig = []) : $this; if (!class_exists($class)) { - throw new Exception(sprintf("The Widget class name '%s' has not been registered", $class)); + throw new Exception(sprintf(lang('admin::lang.alert_widget_class_name'), $class)); } return new $class($controller, $widgetConfig); @@ -51,7 +51,7 @@ public function makeFormWidget($class, $fieldConfig = [], $widgetConfig = []) : $this; if (!class_exists($class)) { - throw new Exception(sprintf("The Widget class name '%s' has not been registered", $class)); + throw new Exception(sprintf(lang('admin::lang.alert_widget_class_name'), $class)); } if (is_string($fieldConfig)) { diff --git a/app/admin/widgets/DashboardContainer.php b/app/admin/widgets/DashboardContainer.php index 6d6ff64dd2..b3bcbfba26 100644 --- a/app/admin/widgets/DashboardContainer.php +++ b/app/admin/widgets/DashboardContainer.php @@ -133,7 +133,7 @@ public function onLoadUpdatePopup() $widgetAlias = trim(post('widgetAlias')); if (!$widgetAlias) - throw new ApplicationException('Please select a widget to update.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_select_widget_to_update')); $this->vars['widgetAlias'] = $widgetAlias; $this->vars['widget'] = $widget = $this->findWidgetByAlias($widgetAlias); @@ -148,14 +148,14 @@ public function onAddWidget() $size = trim(post('size')); if (!$className) - throw new ApplicationException('Please select a widget to add.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_select_widget_to_add')); if (!class_exists($className)) - throw new ApplicationException('The selected class does not exist.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_widget_class_not_found')); $widget = new $className($this->controller); if (!($widget instanceof \Admin\Classes\BaseDashboardWidget)) - throw new ApplicationException('The selected class is not a dashboard widget.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_invalid_widget')); $widgetInfo = $this->addWidget($widget, $size); @@ -171,7 +171,7 @@ public function onAddWidget() public function onResetWidgets() { if (!$this->canManage) { - throw new ApplicationException('Access denied.'); + throw new ApplicationException(lang('admin::lang.alert_access_denied')); } $this->resetWidgets(); @@ -186,7 +186,7 @@ public function onResetWidgets() public function onSetAsDefault() { if (!$this->canSetDefault) { - throw new ApplicationException('Access denied.'); + throw new ApplicationException(lang('admin::lang.alert_access_denied')); } $widgets = $this->getWidgetsFromUserPreferences(); @@ -199,7 +199,7 @@ public function onSetAsDefault() public function onUpdateWidget() { if (!$this->canManage) { - throw new ApplicationException('Access denied.'); + throw new ApplicationException(lang('admin::lang.alert_access_denied')); } $alias = post('alias'); @@ -234,7 +234,7 @@ public function onRemoveWidget() public function addWidget($widget, $size) { if (!$this->canManage) { - throw new ApplicationException('Access denied.'); + throw new ApplicationException(lang('admin::lang.alert_access_denied')); } $widgets = $this->getWidgetsFromUserPreferences(); @@ -270,18 +270,18 @@ public function onSetWidgetPriorities() $priorities = trim(post('priorities')); if (!$aliases) { - throw new ApplicationException('Invalid aliases string.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_invalid_aliases')); } if (!$priorities) { - throw new ApplicationException('Invalid priorities string.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_invalid_priorities')); } $aliases = explode(',', $aliases); $priorities = explode(',', $priorities); if (count($aliases) != count($priorities)) { - throw new ApplicationException('Invalid data posted.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_invalid_data_posted')); } $widgets = $this->getWidgetsFromUserPreferences(); @@ -355,7 +355,7 @@ protected function resetWidgets() protected function removeWidget($alias) { if (!$this->canManage) { - throw new ApplicationException('Access denied.'); + throw new ApplicationException(lang('admin::lang.alert_access_denied')); } $widgets = $this->getWidgetsFromUserPreferences(); @@ -389,7 +389,7 @@ protected function findWidgetByAlias($alias) $widgets = $this->dashboardWidgets; if (!isset($widgets[$alias])) { - throw new ApplicationException('The specified widget is not found.'); + throw new ApplicationException(lang('admin::lang.dashboard.alert_widget_not_found')); } return $widgets[$alias]['widget']; diff --git a/app/admin/widgets/Filter.php b/app/admin/widgets/Filter.php index b5135cafe8..c454952610 100644 --- a/app/admin/widgets/Filter.php +++ b/app/admin/widgets/Filter.php @@ -289,7 +289,7 @@ protected function getOptionsFromArray($scope) $methodName = $options; if (!$model->methodExists($methodName)) { - throw new Exception(sprintf("The model class %s must define a method %s returning options for the '%s' filter.", + throw new Exception(sprintf(lang('admin::lang.list.filter_missing_definitions'), get_class($model), $methodName, $scope->scopeName )); } @@ -572,7 +572,9 @@ public function getScopes() public function getScope($scope) { if (!isset($this->allScopes[$scope])) { - throw new Exception('No definition for scope '.$scope); + throw new Exception(sprintf(lang('admin::lang.list.filter_missing_scope_definitions'), + $scope + )); } return $this->allScopes[$scope]; diff --git a/app/admin/widgets/Form.php b/app/admin/widgets/Form.php index 5827dd5d76..d072373fec 100644 --- a/app/admin/widgets/Form.php +++ b/app/admin/widgets/Form.php @@ -542,7 +542,9 @@ public function makeFormFieldWidget($field) $widgetClass = $this->widgetManager->resolveFormWidget($widgetName); if (!class_exists($widgetClass)) { - throw new Exception(sprintf("The Widget class name '%s' has not been registered", $widgetClass)); + throw new Exception(sprintf( + lang('admin::lang.alert_widget_class_name'), gettype($fieldType) + )); } $widget = $this->makeFormWidget($widgetClass, $field, $widgetConfig); diff --git a/app/admin/widgets/Lists.php b/app/admin/widgets/Lists.php index ee90eb257d..2a6c0365d0 100644 --- a/app/admin/widgets/Lists.php +++ b/app/admin/widgets/Lists.php @@ -328,7 +328,7 @@ public function prepareModel() if (isset($column->relation)) { $relationType = $this->model->getRelationType($column->relation); if ($relationType == 'morphTo') { - throw new Exception('The relationship morphTo is not supported for list columns.'); + throw new Exception(sprintf(lang('admin::lang.list.alert_relationship_not_supported'), 'morphTo')); } $table = $this->model->makeRelation($column->relation)->getTable(); @@ -462,7 +462,7 @@ public function getVisibleColumns() protected function defineListColumns() { if (!isset($this->columns) OR !is_array($this->columns) OR !count($this->columns)) { - throw new Exception(sprintf('List used in %s has no list columns defined.', get_class($this->controller))); + throw new Exception(sprintf(lang('admin::lang.list.missing_column'), get_class($this->controller))); } $this->addColumns($this->columns); @@ -1159,7 +1159,7 @@ protected function isColumnRelated($column, $multi = FALSE) } if (!$this->model->hasRelation($column->relation)) { - throw new Exception(sprintf('Model %s does not contain a definition for %s', get_class($this->model), $column->relation)); + throw new Exception(sprintf(lang('admin::lang.alert_missing_model_definition'), get_class($this->model), $column->relation)); } if (!$multi) { diff --git a/app/admin/widgets/Menu.php b/app/admin/widgets/Menu.php index 8dbea740eb..f1aa8c6cc0 100644 --- a/app/admin/widgets/Menu.php +++ b/app/admin/widgets/Menu.php @@ -180,7 +180,7 @@ public function getItems() public function getItem($item) { if (!isset($this->allItems[$item])) { - throw new ApplicationException('No definition for item '.$item); + throw new ApplicationException(sprintf(lang('admin::lang.side_menu.alert_no_definition'), $item)); } return $this->allItems[$item]; @@ -206,12 +206,12 @@ public function getLoggedUser() public function onGetDropdownOptions() { if (!strlen($itemName = input('item'))) - throw new ApplicationException('Invalid item specified'); + throw new ApplicationException(lang('admin::lang.side_menu.alert_invalid_menu')); $this->defineMenuItems(); if (!$item = $this->getItem($itemName)) - throw new ApplicationException("No main menu item found matching {$itemName}"); + throw new ApplicationException(sprintf(lang('admin::lang.side_menu.alert_menu_not_found'), $itemName)); $itemOptions = $item->options(); @@ -237,12 +237,12 @@ public function onGetDropdownOptions() public function onMarkOptionsAsRead() { if (!strlen($itemName = post('item'))) - throw new ApplicationException('Invalid item specified'); + throw new ApplicationException(lang('admin::lang.side_menu.alert_invalid_menu')); $this->defineMenuItems(); if (!$item = $this->getItem($itemName)) - throw new ApplicationException("No main menu item found matching {$itemName}"); + throw new ApplicationException(sprintf(lang('admin::lang.side_menu.alert_menu_not_found'), $itemName)); $this->resolveMarkAsReadFromModel($item); } @@ -270,7 +270,7 @@ public function onSetUserStatus() $clearAfterMinutes = (int)post('clear_after'); if ($status < 1 AND !strlen($message)) - throw new ApplicationException('Status message is required'); + throw new ApplicationException(lang('admin::lang.side_menu.alert_invalid_status')); $stateData['status'] = $status; $stateData['isAway'] = $status !== 1; diff --git a/app/admin/widgets/Table.php b/app/admin/widgets/Table.php index e7279dcf84..424d183bbf 100644 --- a/app/admin/widgets/Table.php +++ b/app/admin/widgets/Table.php @@ -56,13 +56,13 @@ public function initialize() $dataSourceClass = $this->getConfig('dataSource'); if (!strlen($dataSourceClass)) { - throw new Exception('The Table widget data source is not specified in the configuration.'); + throw new Exception(lang('admin::lang.tables.error_table_widget_data_not_specified')); } $dataSourceClass = $this->dataSourceAliases; if (!class_exists($dataSourceClass)) { - throw new Exception(sprintf('The Table widget data source class "%s" could not be found.', $dataSourceClass)); + throw new Exception(sprintf(lang('admin::lang.tables.error_table_widget_data_class_not_found'), $dataSourceClass)); } $this->dataSource = new $dataSourceClass($this->recordsKeyFrom); diff --git a/app/main/language/en/lang.php b/app/main/language/en/lang.php index 6c07616531..1f55d7acdc 100644 --- a/app/main/language/en/lang.php +++ b/app/main/language/en/lang.php @@ -124,6 +124,8 @@ 'alert_delete_disabled' => 'Deleting file/folder is disabled, check image/media manager settings.', 'alert_select_delete_file' => 'Please select the file/folder you wish to delete.', 'alert_success_delete' => 'File (s) deleted successfully', + 'alert_select_item_to_attach' => 'Select an item to attach.', + 'alert_only_attach_to_saved' => 'You can only attach media to a saved form.', ], 'home' => [ diff --git a/app/system/controllers/MailTemplates.php b/app/system/controllers/MailTemplates.php index af7d6f6340..631a7e5d74 100644 --- a/app/system/controllers/MailTemplates.php +++ b/app/system/controllers/MailTemplates.php @@ -82,10 +82,10 @@ public function formBeforeSave($model) public function onTestTemplate($context, $recordId) { if (!strlen($recordId)) - throw new ApplicationException('Template id not found'); + throw new ApplicationException(lang('system::lang.mail_templates.alert_template_id_not_found')); if (!$model = $this->formFindModelObject($recordId)) - throw new ApplicationException('Template not found'); + throw new ApplicationException(lang('system::lang.mail_templates.alert_template_not_found')); $adminUser = $this->getUser()->staff; diff --git a/app/system/controllers/Updates.php b/app/system/controllers/Updates.php index b78c4c8b7d..30dacfcd1d 100644 --- a/app/system/controllers/Updates.php +++ b/app/system/controllers/Updates.php @@ -148,7 +148,7 @@ public function index_onIgnoreUpdate() { $items = post('items'); if (!$items OR count($items) < 1) - throw new ApplicationException('Select item(s) to ignore.'); + throw new ApplicationException(lang('system::lang.updates.alert_item_to_ignore')); $updateManager = UpdateManager::instance(); @@ -198,7 +198,7 @@ protected function applyCarte() { $carteKey = post('carte_key'); if (!strlen($carteKey)) - throw new ApplicationException('No carte key specified.'); + throw new ApplicationException(lang('system::lang.updates.alert_no_carte_key')); $response = UpdateManager::instance()->applySiteDetail($carteKey); @@ -218,7 +218,7 @@ protected function applyInstallOrUpdate($context) // throw new ApplicationException(lang('system::lang.missing.carte_key')); if (!count($items)) - throw new ApplicationException('No item(s) specified.'); + throw new ApplicationException(lang('system::lang.updates.alert_no_items')); $this->validateItems(); diff --git a/app/system/language/en/lang.php b/app/system/language/en/lang.php index 4a3db96dfc..64c6682b6f 100644 --- a/app/system/language/en/lang.php +++ b/app/system/language/en/lang.php @@ -241,6 +241,8 @@ 'help_variables' => 'Drag these variables into the content area:', 'alert_test_message_sent' => 'Test message successfully sent to %s', + 'alert_template_id_not_found' => 'Template id not found', + 'alert_template_not_found' => ' Template not found', ], 'mail_variables' => [ @@ -639,5 +641,9 @@ 'button_marketplace' => 'Open TastyIgniter Marketplace  ', 'help_carte_key' => 'A Carte key is required to add/update item from the TastyIgniter Marketplace. Get one by creating a site from your TastyIgniter Account, if you haven\'t already.', + 'alert_item_to_ignore' => 'Select item(s) to ignore.', + 'alert_no_carte_key' => 'No carte key specified.', + 'alert_no_items' => 'No item(s) specified.', + ], ]; From d00cf7e69c0dbd3632e5b7a9bee1004c00fc3363 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:11:14 +0100 Subject: [PATCH 3/4] Minor fix --- app/admin/classes/User.php | 4 ++-- app/admin/models/Reservations_model.php | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/admin/classes/User.php b/app/admin/classes/User.php index ee6f30ddcf..0a384fa424 100644 --- a/app/admin/classes/User.php +++ b/app/admin/classes/User.php @@ -30,7 +30,7 @@ public function isSuperUser() */ public function staff() { - return $this->user()->staff; + return optional($this->user())->staff; } /** @@ -38,7 +38,7 @@ public function staff() */ public function locations() { - return $this->user()->staff->locations; + return optional($this->staff())->locations; } // diff --git a/app/admin/models/Reservations_model.php b/app/admin/models/Reservations_model.php index 92c4a43d3d..0dfbd33cef 100644 --- a/app/admin/models/Reservations_model.php +++ b/app/admin/models/Reservations_model.php @@ -228,10 +228,7 @@ public function getReservationDatetimeAttribute($value) public function getReservationEndDatetimeAttribute($value) { - if ($this->duration) - return $this->reservation_datetime->copy()->addMinutes($this->duration); - - return $this->reservation_datetime->copy()->endOfDay(); + return $this->reserve_end_time; } public function getOccasionAttribute() From b23800611e38186e8ea636deda6b8d1c0f6f26cd Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Fri, 30 Jul 2021 19:23:29 +0100 Subject: [PATCH 4/4] Set DB credentials with Config so changes are picked up (#830) * Set db credentials with Config so changes are picked up * Wrap APP_NAME in quotes to ensure spaces are handled * StyleCI * Clean up * Remove trailing comma Co-authored-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- app/system/console/commands/IgniterInstall.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/system/console/commands/IgniterInstall.php b/app/system/console/commands/IgniterInstall.php index 9e77c2dabb..2d32a7c34f 100644 --- a/app/system/console/commands/IgniterInstall.php +++ b/app/system/console/commands/IgniterInstall.php @@ -12,7 +12,6 @@ use Carbon\Carbon; use Config; use DB; -use Igniter\Flame\Foundation\Http\Kernel; use Igniter\Flame\Support\ConfigRewrite; use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputOption; @@ -111,11 +110,13 @@ protected function rewriteEnvFile() $this->replaceInEnv('APP_KEY=', 'APP_KEY='.$this->generateEncryptionKey()); - $this->replaceInEnv('APP_NAME=', 'APP_NAME='.DatabaseSeeder::$siteName); + $this->replaceInEnv('APP_NAME=', 'APP_NAME="'.DatabaseSeeder::$siteName.'"'); $this->replaceInEnv('APP_URL=', 'APP_URL='.DatabaseSeeder::$siteUrl); + $name = Config::get('database.default'); foreach ($this->dbConfig as $key => $value) { $this->replaceInEnv('DB_'.strtoupper($key).'=', 'DB_'.strtoupper($key).'='.$value); + Config::set("database.connections.$name.".strtolower($key), $value); } } @@ -123,8 +124,6 @@ protected function migrateDatabase() { $this->line('Migrating application and extensions...'); - resolve(Kernel::class)->bootstrap(); - DB::purge(); $manager = UpdateManager::instance()->setLogsOutput($this->output); @@ -262,5 +261,7 @@ protected function replaceInEnv(string $search, string $replace) $file, preg_replace('/^'.$search.'(.*)$/m', $replace, file_get_contents($file)) ); + + putenv($replace); } }