From 0f88eed08c1857c2f412b4273bef3b0cb77c417c Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 3 Jul 2021 17:46:47 +0200 Subject: [PATCH] Upgraded to PHP-CS-Fixer v3 --- .php-cs-fixer.php | 95 ++++++++++++++++++ .php_cs | 97 ------------------- config-dist.php | 6 +- controllers/BaseApiController.php | 2 + controllers/FilesApiController.php | 8 +- controllers/PrintApiController.php | 13 +-- controllers/RecipesApiController.php | 140 +++++++++++++-------------- controllers/StockController.php | 1 - controllers/Users/User.php | 19 ++++ helpers/Grocycode.php | 4 + middleware/LdapAuthMiddleware.php | 8 +- migrations/0027.php | 8 +- migrations/0031.php | 15 +-- migrations/0063.php | 7 +- services/BaseService.php | 1 - services/ChoresService.php | 8 ++ services/DatabaseService.php | 2 + services/FilesService.php | 6 +- services/PrintService.php | 18 ++-- services/StockService.php | 8 ++ services/UserfieldsService.php | 12 +++ 21 files changed, 267 insertions(+), 211 deletions(-) create mode 100644 .php-cs-fixer.php delete mode 100644 .php_cs diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 00000000..eb465d8e --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,95 @@ +exclude(['vendor']) + ->ignoreVCSIgnored(true) + ->files()->name('*.php') + ->in(__DIR__) +; + +$cfg = new PhpCsFixer\Config(); +return $cfg + ->setRules([ + '@PSR2' => true, + 'array_indentation' => true, + 'array_syntax' => ['syntax' => 'short'], + 'combine_consecutive_unsets' => true, + 'class_attributes_separation' => true, + 'multiline_whitespace_before_semicolons' => false, + 'single_quote' => true, + // 'blank_line_after_opening_tag' => true, + // 'blank_line_before_return' => true, + 'braces' => [ + 'allow_single_line_closure' => true, + 'position_after_anonymous_constructs' => 'same', + 'position_after_control_structures' => 'next', + 'position_after_functions_and_oop_constructs' => 'next', + ], + // 'cast_spaces' => true, + // 'class_definition' => array('singleLine' => true), + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => true, + 'function_typehint_space' => true, + 'single_line_comment_style' => ['comment_types' => ['hash']], + 'include' => true, + 'lowercase_cast' => true, + // 'native_function_casing' => true, + // 'new_with_braces' => true, + // 'no_blank_lines_after_class_opening' => true, + // 'no_blank_lines_after_phpdoc' => true, + // 'no_empty_comment' => true, + // 'no_empty_phpdoc' => true, + // 'no_empty_statement' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + // 'no_mixed_echo_print' => array('use' => 'echo'), + 'no_multiline_whitespace_around_double_arrow' => true, + // 'no_short_bool_cast' => true, + // 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_around_offset' => true, + // 'no_trailing_comma_in_list_call' => true, + // 'no_trailing_comma_in_singleline_array' => true, + // 'no_unneeded_control_parentheses' => true, + // 'no_unused_imports' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + // 'normalize_index_brace' => true, + 'object_operator_without_whitespace' => true, + // 'php_unit_fqcn_annotation' => true, + // 'phpdoc_align' => true, + // 'phpdoc_annotation_without_dot' => true, + // 'phpdoc_indent' => true, + // 'phpdoc_inline_tag' => true, + // 'phpdoc_no_access' => true, + // 'phpdoc_no_alias_tag' => true, + // 'phpdoc_no_empty_return' => true, + // 'phpdoc_no_package' => true, + // 'phpdoc_no_useless_inheritdoc' => true, + // 'phpdoc_return_self_reference' => true, + // 'phpdoc_scalar' => true, + // 'phpdoc_separation' => true, + // 'phpdoc_single_line_var_spacing' => true, + // 'phpdoc_summary' => true, + // 'phpdoc_to_comment' => true, + // 'phpdoc_trim' => true, + // 'phpdoc_types' => true, + // 'phpdoc_var_without_name' => true, + // 'pre_increment' => true, + // 'return_type_declaration' => true, + // 'self_accessor' => true, + // 'short_scalar_cast' => true, + 'single_blank_line_before_namespace' => true, + // 'single_class_element_per_statement' => true, + // 'space_after_semicolon' => true, + // 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + // 'trailing_comma_in_multiline_array' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true, + ]) + ->setIndent("\t") + ->setLineEnding("\n") + ->setUsingCache(false) + ->setFinder($finder) +; diff --git a/.php_cs b/.php_cs deleted file mode 100644 index e9abf35f..00000000 --- a/.php_cs +++ /dev/null @@ -1,97 +0,0 @@ -setRules(array( - '@PSR2' => true, - 'array_indentation' => true, - 'array_syntax' => array('syntax' => 'short'), - 'combine_consecutive_unsets' => true, - 'method_separation' => true, - 'no_multiline_whitespace_before_semicolons' => true, - 'single_quote' => true, - - 'binary_operator_spaces' => array( - 'align_double_arrow' => false, - 'align_equals' => false, - ), - // 'blank_line_after_opening_tag' => true, - // 'blank_line_before_return' => true, - 'braces' => array( - 'allow_single_line_closure' => true, - 'position_after_anonymous_constructs' => 'same', - 'position_after_control_structures' => 'next', - 'position_after_functions_and_oop_constructs' => 'next', - ), - // 'cast_spaces' => true, - // 'class_definition' => array('singleLine' => true), - 'concat_space' => array('spacing' => 'one'), - 'declare_equal_normalize' => true, - 'function_typehint_space' => true, - 'hash_to_slash_comment' => true, - 'include' => true, - 'lowercase_cast' => true, - // 'native_function_casing' => true, - // 'new_with_braces' => true, - // 'no_blank_lines_after_class_opening' => true, - // 'no_blank_lines_after_phpdoc' => true, - // 'no_empty_comment' => true, - // 'no_empty_phpdoc' => true, - // 'no_empty_statement' => true, - 'no_extra_consecutive_blank_lines' => array( - 'extra', - 'parenthesis_brace_block', - 'square_brace_block', - 'throw', - 'use', - ), - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - // 'no_mixed_echo_print' => array('use' => 'echo'), - 'no_multiline_whitespace_around_double_arrow' => true, - // 'no_short_bool_cast' => true, - // 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_around_offset' => true, - // 'no_trailing_comma_in_list_call' => true, - // 'no_trailing_comma_in_singleline_array' => true, - // 'no_unneeded_control_parentheses' => true, - // 'no_unused_imports' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - // 'normalize_index_brace' => true, - 'object_operator_without_whitespace' => true, - // 'php_unit_fqcn_annotation' => true, - // 'phpdoc_align' => true, - // 'phpdoc_annotation_without_dot' => true, - // 'phpdoc_indent' => true, - // 'phpdoc_inline_tag' => true, - // 'phpdoc_no_access' => true, - // 'phpdoc_no_alias_tag' => true, - // 'phpdoc_no_empty_return' => true, - // 'phpdoc_no_package' => true, - // 'phpdoc_no_useless_inheritdoc' => true, - // 'phpdoc_return_self_reference' => true, - // 'phpdoc_scalar' => true, - // 'phpdoc_separation' => true, - // 'phpdoc_single_line_var_spacing' => true, - // 'phpdoc_summary' => true, - // 'phpdoc_to_comment' => true, - // 'phpdoc_trim' => true, - // 'phpdoc_types' => true, - // 'phpdoc_var_without_name' => true, - // 'pre_increment' => true, - // 'return_type_declaration' => true, - // 'self_accessor' => true, - // 'short_scalar_cast' => true, - 'single_blank_line_before_namespace' => true, - // 'single_class_element_per_statement' => true, - // 'space_after_semicolon' => true, - // 'standardize_not_equals' => true, - 'ternary_operator_spaces' => true, - // 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'whitespace_after_comma_in_array' => true, - )) - ->setIndent("\t") - ->setLineEnding("\n") -; diff --git a/config-dist.php b/config-dist.php index e2d1ebc1..9b6a0faa 100644 --- a/config-dist.php +++ b/config-dist.php @@ -109,9 +109,9 @@ Setting('TPRINTER_IP', '127.0.0.1'); // IP of the network printer Setting('TPRINTER_PORT', 9100); // Port of printer, eg. 9100 //Configuration below if you are using a USB or serial printer Setting('TPRINTER_CONNECTOR', '/dev/usb/lp0'); // Location of printer. For USB on Linux this is often '/dev/usb/lp0', - // for serial printers it could be similar to '/dev/ttyS0' - // Make sure that the user that runs the webserver has permissions to write to the printer! - // On Linux add your webserver user to the LP group with usermod -a -G lp www-data + // for serial printers it could be similar to '/dev/ttyS0' + // Make sure that the user that runs the webserver has permissions to write to the printer! + // On Linux add your webserver user to the LP group with usermod -a -G lp www-data // Default user settings diff --git a/controllers/BaseApiController.php b/controllers/BaseApiController.php index c0ff0963..98dd1fb8 100644 --- a/controllers/BaseApiController.php +++ b/controllers/BaseApiController.php @@ -9,7 +9,9 @@ class BaseApiController extends BaseController protected $OpenApiSpec = null; const PATTERN_FIELD = '[A-Za-z_][A-Za-z0-9_]+'; + const PATTERN_OPERATOR = '!?(=|~|<|>|(>=)|(<=)|(ยง))'; + const PATTERN_VALUE = '[A-Za-z_0-9.$#^|]+'; public function __construct(\DI\Container $container) diff --git a/controllers/FilesApiController.php b/controllers/FilesApiController.php index 131d02df..66b8d934 100644 --- a/controllers/FilesApiController.php +++ b/controllers/FilesApiController.php @@ -11,7 +11,7 @@ class FilesApiController extends BaseApiController { try { - if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) + if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) { throw new \Exception('Invalid file group'); } @@ -39,7 +39,7 @@ class FilesApiController extends BaseApiController { try { - if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) + if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) { throw new \Exception('Invalid file group'); } @@ -69,7 +69,7 @@ class FilesApiController extends BaseApiController { try { - if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) + if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) { throw new \Exception('Invalid file group'); } @@ -100,7 +100,7 @@ class FilesApiController extends BaseApiController { try { - if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) + if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum)) { throw new \Exception('Invalid file group'); } diff --git a/controllers/PrintApiController.php b/controllers/PrintApiController.php index 7664300e..d419be8d 100644 --- a/controllers/PrintApiController.php +++ b/controllers/PrintApiController.php @@ -7,9 +7,8 @@ use Grocy\Services\StockService; class PrintApiController extends BaseApiController { - - public function PrintShoppingListThermal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) { - + public function PrintShoppingListThermal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) + { try { User::checkPermission($request, User::PERMISSION_SHOPPINGLIST); @@ -17,13 +16,15 @@ class PrintApiController extends BaseApiController $params = $request->getQueryParams(); $listId = 1; - if (isset($params['list'])) { + if (isset($params['list'])) + { $listId = $params['list']; } $printHeader = true; - if (isset($params['printHeader'])) { - $printHeader = ($params['printHeader'] === "true"); + if (isset($params['printHeader'])) + { + $printHeader = ($params['printHeader'] === 'true'); } $items = $this->getStockService()->GetShoppinglistInPrintableStrings($listId); return $this->ApiResponse($response, $this->getPrintService()->printShoppingList($printHeader, $items)); diff --git a/controllers/RecipesApiController.php b/controllers/RecipesApiController.php index 502bb1b3..cc89b57a 100644 --- a/controllers/RecipesApiController.php +++ b/controllers/RecipesApiController.php @@ -1,70 +1,70 @@ -GetParsedAndFilteredRequestBody($request); - $excludedProductIds = null; - - if ($requestBody !== null && array_key_exists('excludedProductIds', $requestBody)) - { - $excludedProductIds = $requestBody['excludedProductIds']; - } - - $this->getRecipesService()->AddNotFulfilledProductsToShoppingList($args['recipeId'], $excludedProductIds); - return $this->EmptyApiResponse($response); - } - - public function ConsumeRecipe(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) - { - User::checkPermission($request, User::PERMISSION_STOCK_CONSUME); - - try - { - $this->getRecipesService()->ConsumeRecipe($args['recipeId']); - return $this->EmptyApiResponse($response); - } - catch (\Exception $ex) - { - return $this->GenericErrorResponse($response, $ex->getMessage()); - } - } - - public function GetRecipeFulfillment(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) - { - try - { - if (!isset($args['recipeId'])) - { - return $this->FilteredApiResponse($response, $this->getRecipesService()->GetRecipesResolved(), $request->getQueryParams()); - } - - $recipeResolved = FindObjectInArrayByPropertyValue($this->getRecipesService()->GetRecipesResolved(), 'recipe_id', $args['recipeId']); - - if (!$recipeResolved) - { - throw new \Exception('Recipe does not exist'); - } - else - { - return $this->ApiResponse($response, $recipeResolved); - } - } - catch (\Exception $ex) - { - return $this->GenericErrorResponse($response, $ex->getMessage()); - } - } - - public function __construct(\DI\Container $container) - { - parent::__construct($container); - } -} +GetParsedAndFilteredRequestBody($request); + $excludedProductIds = null; + + if ($requestBody !== null && array_key_exists('excludedProductIds', $requestBody)) + { + $excludedProductIds = $requestBody['excludedProductIds']; + } + + $this->getRecipesService()->AddNotFulfilledProductsToShoppingList($args['recipeId'], $excludedProductIds); + return $this->EmptyApiResponse($response); + } + + public function ConsumeRecipe(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) + { + User::checkPermission($request, User::PERMISSION_STOCK_CONSUME); + + try + { + $this->getRecipesService()->ConsumeRecipe($args['recipeId']); + return $this->EmptyApiResponse($response); + } + catch (\Exception $ex) + { + return $this->GenericErrorResponse($response, $ex->getMessage()); + } + } + + public function GetRecipeFulfillment(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) + { + try + { + if (!isset($args['recipeId'])) + { + return $this->FilteredApiResponse($response, $this->getRecipesService()->GetRecipesResolved(), $request->getQueryParams()); + } + + $recipeResolved = FindObjectInArrayByPropertyValue($this->getRecipesService()->GetRecipesResolved(), 'recipe_id', $args['recipeId']); + + if (!$recipeResolved) + { + throw new \Exception('Recipe does not exist'); + } + else + { + return $this->ApiResponse($response, $recipeResolved); + } + } + catch (\Exception $ex) + { + return $this->GenericErrorResponse($response, $ex->getMessage()); + } + } + + public function __construct(\DI\Container $container) + { + parent::__construct($container); + } +} diff --git a/controllers/StockController.php b/controllers/StockController.php index 25a5c2af..c64125f1 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -512,7 +512,6 @@ class StockController extends BaseController ]); } - public function Stockentries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) { $usersService = $this->getUsersService(); diff --git a/controllers/Users/User.php b/controllers/Users/User.php index 771e5c0a..4979c144 100644 --- a/controllers/Users/User.php +++ b/controllers/Users/User.php @@ -10,13 +10,17 @@ class User const PERMISSION_ADMIN = 'ADMIN'; const PERMISSION_BATTERIES = 'BATTERIES'; + const PERMISSION_BATTERIES_TRACK_CHARGE_CYCLE = 'BATTERIES_TRACK_CHARGE_CYCLE'; + const PERMISSION_BATTERIES_UNDO_CHARGE_CYCLE = 'BATTERIES_UNDO_CHARGE_CYCLE'; const PERMISSION_CALENDAR = 'CALENDAR'; const PERMISSION_CHORES = 'CHORES'; + const PERMISSION_CHORE_TRACK_EXECUTION = 'CHORE_TRACK_EXECUTION'; + const PERMISSION_CHORE_UNDO_EXECUTION = 'CHORE_UNDO_EXECUTION'; const PERMISSION_EQUIPMENT = 'EQUIPMENT'; @@ -24,28 +28,43 @@ class User const PERMISSION_MASTER_DATA_EDIT = 'MASTER_DATA_EDIT'; const PERMISSION_RECIPES = 'RECIPES'; + const PERMISSION_RECIPES_MEALPLAN = 'RECIPES_MEALPLAN'; const PERMISSION_SHOPPINGLIST = 'SHOPPINGLIST'; + const PERMISSION_SHOPPINGLIST_ITEMS_ADD = 'SHOPPINGLIST_ITEMS_ADD'; + const PERMISSION_SHOPPINGLIST_ITEMS_DELETE = 'SHOPPINGLIST_ITEMS_DELETE'; const PERMISSION_STOCK = 'STOCK'; + const PERMISSION_STOCK_CONSUME = 'STOCK_CONSUME'; + const PERMISSION_STOCK_EDIT = 'STOCK_EDIT'; + const PERMISSION_STOCK_INVENTORY = 'STOCK_INVENTORY'; + const PERMISSION_STOCK_OPEN = 'STOCK_OPEN'; + const PERMISSION_STOCK_PURCHASE = 'STOCK_PURCHASE'; + const PERMISSION_STOCK_TRANSFER = 'STOCK_TRANSFER'; const PERMISSION_TASKS = 'TASKS'; + const PERMISSION_TASKS_MARK_COMPLETED = 'TASKS_MARK_COMPLETED'; + const PERMISSION_TASKS_UNDO_EXECUTION = 'TASKS_UNDO_EXECUTION'; const PERMISSION_USERS = 'USERS'; + const PERMISSION_USERS_CREATE = 'USERS_CREATE'; + const PERMISSION_USERS_EDIT = 'USERS_EDIT'; + const PERMISSION_USERS_EDIT_SELF = 'USERS_EDIT_SELF'; + const PERMISSION_USERS_READ = 'USERS_READ'; /** diff --git a/helpers/Grocycode.php b/helpers/Grocycode.php index bee3190e..5f8a9907 100644 --- a/helpers/Grocycode.php +++ b/helpers/Grocycode.php @@ -18,7 +18,9 @@ namespace Grocy\Helpers; class Grocycode { public const PRODUCT = 'p'; + public const BATTERY = 'b'; + public const CHORE = 'c'; public const MAGIC = 'grcy'; @@ -29,7 +31,9 @@ class Grocycode public static $Items = [self::PRODUCT, self::BATTERY, self::CHORE]; private $type; + private $id; + private $extra_data = []; /** diff --git a/middleware/LdapAuthMiddleware.php b/middleware/LdapAuthMiddleware.php index 67e6551c..0e401d54 100644 --- a/middleware/LdapAuthMiddleware.php +++ b/middleware/LdapAuthMiddleware.php @@ -45,7 +45,7 @@ class LdapAuthMiddleware extends AuthMiddleware $ldapFirstName = $result[0]['givenname'][0]; $ldapLastName = $result[0]['sn'][0]; $ldapDistinguishedName = $result[0]['dn']; - + if (is_null($ldapDistinguishedName)) { // User not found @@ -57,7 +57,7 @@ class LdapAuthMiddleware extends AuthMiddleware // Bind authentication failed return false; } - + // bind with user account to validate password if ($bind = ldap_bind($connect, $ldapDistinguishedName, $postParams['password'])) { @@ -78,7 +78,7 @@ class LdapAuthMiddleware extends AuthMiddleware else { ldap_close($connect); - + // User authentication failed return false; } @@ -89,4 +89,4 @@ class LdapAuthMiddleware extends AuthMiddleware return false; } } -} \ No newline at end of file +} diff --git a/migrations/0027.php b/migrations/0027.php index 8d9079f1..db745475 100644 --- a/migrations/0027.php +++ b/migrations/0027.php @@ -7,18 +7,18 @@ $db = $this->getDatabaseService()->GetDbConnection(); if (defined('GROCY_HTTP_USER')) { // Migrate old user defined in config file to database - $newUserRow = $db->users()->createRow(array( + $newUserRow = $db->users()->createRow([ 'username' => GROCY_HTTP_USER, 'password' => password_hash(GROCY_HTTP_PASSWORD, PASSWORD_DEFAULT) - )); + ]); $newUserRow->save(); } else { // Create default user "admin" with password "admin" - $newUserRow = $db->users()->createRow(array( + $newUserRow = $db->users()->createRow([ 'username' => 'admin', 'password' => password_hash('admin', PASSWORD_DEFAULT) - )); + ]); $newUserRow->save(); } diff --git a/migrations/0031.php b/migrations/0031.php index 03dfcd18..27a562a8 100644 --- a/migrations/0031.php +++ b/migrations/0031.php @@ -2,7 +2,8 @@ // This is executed inside DatabaseMigrationService class/context -use \Grocy\Services\LocalizationService; +use Grocy\Services\LocalizationService; + $localizationService = $this->getLocalizationService(); $db = $this->getDatabaseService()->GetDbConnection(); @@ -10,23 +11,23 @@ $db = $this->getDatabaseService()->GetDbConnection(); if ($db->quantity_units()->count() === 0) { // Create 2 default quantity units - $newRow = $db->quantity_units()->createRow(array( + $newRow = $db->quantity_units()->createRow([ 'name' => $localizationService->__n(1, 'Piece', 'Pieces'), 'name_plural' => $localizationService->__n(2, 'Piece', 'Pieces') - )); + ]); $newRow->save(); - $newRow = $db->quantity_units()->createRow(array( + $newRow = $db->quantity_units()->createRow([ 'name' => $localizationService->__n(1, 'Pack', 'Packs'), 'name_plural' => $localizationService->__n(2, 'Pack', 'Packs') - )); + ]); $newRow->save(); } if ($db->locations()->count() === 0) { // Create a default location - $newRow = $db->locations()->createRow(array( + $newRow = $db->locations()->createRow([ 'name' => $localizationService->__t('Fridge') - )); + ]); $newRow->save(); } diff --git a/migrations/0063.php b/migrations/0063.php index 6aaac16d..06c6b0fd 100644 --- a/migrations/0063.php +++ b/migrations/0063.php @@ -2,12 +2,13 @@ // This is executed inside DatabaseMigrationService class/context -use \Grocy\Services\LocalizationService; +use Grocy\Services\LocalizationService; + $localizationService = $this->getLocalizationService(); $db = $this->getDatabaseService()->GetDbConnection(); $defaultShoppingList = $db->shopping_lists()->where('id = 1')->fetch(); -$defaultShoppingList->update(array( +$defaultShoppingList->update([ 'name' => $localizationService->__t('Shopping list') -)); +]); diff --git a/services/BaseService.php b/services/BaseService.php index ef04ec81..0dc60297 100644 --- a/services/BaseService.php +++ b/services/BaseService.php @@ -71,5 +71,4 @@ class BaseService { return PrintService::getInstance(); } - } diff --git a/services/ChoresService.php b/services/ChoresService.php index b3e6c881..61c9e7c5 100644 --- a/services/ChoresService.php +++ b/services/ChoresService.php @@ -5,15 +5,23 @@ namespace Grocy\Services; class ChoresService extends BaseService { const CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER = 'in-alphabetical-order'; + const CHORE_ASSIGNMENT_TYPE_NO_ASSIGNMENT = 'no-assignment'; + const CHORE_ASSIGNMENT_TYPE_RANDOM = 'random'; + const CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST = 'who-least-did-first'; const CHORE_PERIOD_TYPE_DAILY = 'daily'; + const CHORE_PERIOD_TYPE_DYNAMIC_REGULAR = 'dynamic-regular'; + const CHORE_PERIOD_TYPE_MANUALLY = 'manually'; + const CHORE_PERIOD_TYPE_MONTHLY = 'monthly'; + const CHORE_PERIOD_TYPE_WEEKLY = 'weekly'; + const CHORE_PERIOD_TYPE_YEARLY = 'yearly'; public function CalculateNextExecutionAssignment($choreId) diff --git a/services/DatabaseService.php b/services/DatabaseService.php index d1080b04..dfcd5d4b 100644 --- a/services/DatabaseService.php +++ b/services/DatabaseService.php @@ -5,7 +5,9 @@ namespace Grocy\Services; class DatabaseService { private static $DbConnection = null; + private static $DbConnectionRaw = null; + private static $instance = null; /** diff --git a/services/FilesService.php b/services/FilesService.php index 86aad2a0..053dd034 100644 --- a/services/FilesService.php +++ b/services/FilesService.php @@ -58,12 +58,12 @@ class FilesService extends BaseService $fileNameWithoutExtension = pathinfo($filePath, PATHINFO_FILENAME); $fileExtension = pathinfo($filePath, PATHINFO_EXTENSION); - if (getimagesize($filePath) !== false) // Then the file is an image - { + if (getimagesize($filePath) !== false) + { // Then the file is an image // Also delete all corresponding "__downscaledto" files when deleting an image $groupFolderPath = $this->StoragePath . '/' . $group; $files = scandir($groupFolderPath); - foreach($files as $file) + foreach ($files as $file) { if (string_starts_with($file, $fileNameWithoutExtension . '__downscaledto')) { diff --git a/services/PrintService.php b/services/PrintService.php index b3b1a826..c6f1053b 100644 --- a/services/PrintService.php +++ b/services/PrintService.php @@ -10,8 +10,6 @@ use Mike42\Escpos\Printer; class PrintService extends BaseService { - - /** * Initialises the printer * @return Printer Printer handle @@ -19,15 +17,17 @@ class PrintService extends BaseService */ private static function getPrinterHandle() { - if (GROCY_TPRINTER_IS_NETWORK_PRINTER) { + if (GROCY_TPRINTER_IS_NETWORK_PRINTER) + { $connector = new NetworkPrintConnector(GROCY_TPRINTER_IP, GROCY_TPRINTER_PORT); - } else { + } + else + { $connector = new FilePrintConnector(GROCY_TPRINTER_CONNECTOR); } return new Printer($connector); } - /** * Prints the grocy logo and date * @param Printer $printer Printer handle @@ -41,7 +41,7 @@ class PrintService extends BaseService $printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH); $printer->setTextSize(4, 4); $printer->setReverseColors(true); - $printer->text("grocy"); + $printer->text('grocy'); $printer->setJustification(); $printer->setTextSize(1, 1); $printer->setReverseColors(false); @@ -61,7 +61,9 @@ class PrintService extends BaseService { $printer = self::getPrinterHandle(); if ($printer === false) - throw new Exception("Unable to connect to printer"); + { + throw new Exception('Unable to connect to printer'); + } if ($printHeader) { @@ -78,7 +80,7 @@ class PrintService extends BaseService $printer->cut(); $printer->close(); return [ - 'result' => "OK" + 'result' => 'OK' ]; } } diff --git a/services/StockService.php b/services/StockService.php index 4bc952f8..f7777371 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -8,13 +8,21 @@ use Grocy\Helpers\WebhookRunner; class StockService extends BaseService { const TRANSACTION_TYPE_CONSUME = 'consume'; + const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction'; + const TRANSACTION_TYPE_PRODUCT_OPENED = 'product-opened'; + const TRANSACTION_TYPE_PURCHASE = 'purchase'; + const TRANSACTION_TYPE_SELF_PRODUCTION = 'self-production'; + const TRANSACTION_TYPE_STOCK_EDIT_NEW = 'stock-edit-new'; + const TRANSACTION_TYPE_STOCK_EDIT_OLD = 'stock-edit-old'; + const TRANSACTION_TYPE_TRANSFER_FROM = 'transfer_from'; + const TRANSACTION_TYPE_TRANSFER_TO = 'transfer_to'; public function AddMissingProductsToShoppingList($listId = 1) diff --git a/services/UserfieldsService.php b/services/UserfieldsService.php index 6e892777..53ac2ac0 100644 --- a/services/UserfieldsService.php +++ b/services/UserfieldsService.php @@ -5,17 +5,29 @@ namespace Grocy\Services; class UserfieldsService extends BaseService { const USERFIELD_TYPE_CHECKBOX = 'checkbox'; + const USERFIELD_TYPE_DATE = 'date'; + const USERFIELD_TYPE_DATETIME = 'datetime'; + const USERFIELD_TYPE_DECIMAL_NUMBER = 'number-decimal'; + const USERFIELD_TYPE_FILE = 'file'; + const USERFIELD_TYPE_IMAGE = 'image'; + const USERFIELD_TYPE_INTEGRAL_NUMBER = 'number-integral'; + const USERFIELD_TYPE_LINK = 'link'; + const USERFIELD_TYPE_LINK_WITH_TITLE = 'link-with-title'; + const USERFIELD_TYPE_PRESET_CHECKLIST = 'preset-checklist'; + const USERFIELD_TYPE_PRESET_LIST = 'preset-list'; + const USERFIELD_TYPE_SINGLE_LINE_TEXT = 'text-single-line'; + const USERFIELD_TYPE_SINGLE_MULTILINE_TEXT = 'text-multi-line'; protected $OpenApiSpec = null;