mirror of
https://github.com/grocy/grocy.git
synced 2025-08-15 02:04:38 +00:00
Upgraded PHP-CS-Fixer / applied optimized rules
This commit is contained in:
@@ -4,8 +4,7 @@ $finder = PhpCsFixer\Finder::create()
|
|||||||
->exclude(['packages'])
|
->exclude(['packages'])
|
||||||
->ignoreVCSIgnored(true)
|
->ignoreVCSIgnored(true)
|
||||||
->files()->name('*.php')
|
->files()->name('*.php')
|
||||||
->in(__DIR__)
|
->in(__DIR__);
|
||||||
;
|
|
||||||
|
|
||||||
$cfg = new PhpCsFixer\Config();
|
$cfg = new PhpCsFixer\Config();
|
||||||
return $cfg
|
return $cfg
|
||||||
@@ -15,81 +14,41 @@ return $cfg
|
|||||||
'array_syntax' => ['syntax' => 'short'],
|
'array_syntax' => ['syntax' => 'short'],
|
||||||
'combine_consecutive_unsets' => true,
|
'combine_consecutive_unsets' => true,
|
||||||
'class_attributes_separation' => true,
|
'class_attributes_separation' => true,
|
||||||
|
'class_attributes_separation' => ['elements' => ['const' => 'none', 'property' => 'none']],
|
||||||
'multiline_whitespace_before_semicolons' => false,
|
'multiline_whitespace_before_semicolons' => false,
|
||||||
'single_quote' => true,
|
'single_quote' => true,
|
||||||
// 'blank_line_after_opening_tag' => true,
|
'blank_line_after_opening_tag' => true,
|
||||||
// 'blank_line_before_return' => true,
|
'curly_braces_position' => [
|
||||||
'braces' => [
|
'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end',
|
||||||
'allow_single_line_closure' => true,
|
'anonymous_functions_opening_brace' => 'next_line_unless_newline_at_signature_end'
|
||||||
'position_after_anonymous_constructs' => 'same',
|
],
|
||||||
'position_after_control_structures' => 'next',
|
'control_structure_continuation_position' => [
|
||||||
'position_after_functions_and_oop_constructs' => 'next',
|
'position' => 'next_line'
|
||||||
|
],
|
||||||
|
'cast_spaces' => [
|
||||||
|
'space' => 'none'
|
||||||
],
|
],
|
||||||
// 'cast_spaces' => true,
|
|
||||||
// 'class_definition' => array('singleLine' => true),
|
|
||||||
'concat_space' => ['spacing' => 'one'],
|
'concat_space' => ['spacing' => 'one'],
|
||||||
'declare_equal_normalize' => true,
|
'declare_equal_normalize' => true,
|
||||||
'function_typehint_space' => true,
|
'type_declaration_spaces' => true,
|
||||||
'single_line_comment_style' => ['comment_types' => ['hash']],
|
'single_line_comment_style' => ['comment_types' => ['hash']],
|
||||||
'include' => true,
|
'include' => true,
|
||||||
'lowercase_cast' => 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_import_slash' => true,
|
||||||
'no_leading_namespace_whitespace' => true,
|
'no_leading_namespace_whitespace' => true,
|
||||||
// 'no_mixed_echo_print' => array('use' => 'echo'),
|
|
||||||
'no_multiline_whitespace_around_double_arrow' => true,
|
'no_multiline_whitespace_around_double_arrow' => true,
|
||||||
// 'no_short_bool_cast' => true,
|
|
||||||
// 'no_singleline_whitespace_before_semicolons' => true,
|
|
||||||
'no_spaces_around_offset' => 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_before_comma_in_array' => true,
|
||||||
'no_whitespace_in_blank_line' => true,
|
'no_whitespace_in_blank_line' => true,
|
||||||
// 'normalize_index_brace' => true,
|
|
||||||
'object_operator_without_whitespace' => true,
|
'object_operator_without_whitespace' => true,
|
||||||
// 'php_unit_fqcn_annotation' => true,
|
'blank_lines_before_namespace' => 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,
|
'ternary_operator_spaces' => true,
|
||||||
// 'trailing_comma_in_multiline_array' => true,
|
|
||||||
'trim_array_spaces' => true,
|
'trim_array_spaces' => true,
|
||||||
'unary_operator_spaces' => true,
|
'unary_operator_spaces' => true,
|
||||||
'whitespace_after_comma_in_array' => true,
|
'whitespace_after_comma_in_array' => true,
|
||||||
|
'no_trailing_comma_in_singleline' => true
|
||||||
])
|
])
|
||||||
->setIndent("\t")
|
->setIndent("\t")
|
||||||
->setLineEnding("\n")
|
->setLineEnding("\n")
|
||||||
->setUsingCache(false)
|
->setUsingCache(false)
|
||||||
->setFinder($finder)
|
->setFinder($finder);
|
||||||
;
|
|
||||||
|
9
app.php
9
app.php
@@ -62,15 +62,18 @@ AppFactory::setContainer(new DI\Container());
|
|||||||
$app = AppFactory::create();
|
$app = AppFactory::create();
|
||||||
|
|
||||||
$container = $app->getContainer();
|
$container = $app->getContainer();
|
||||||
$container->set('view', function (Container $container) {
|
$container->set('view', function (Container $container)
|
||||||
|
{
|
||||||
return new Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache');
|
return new Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache');
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->set('UrlManager', function (Container $container) {
|
$container->set('UrlManager', function (Container $container)
|
||||||
|
{
|
||||||
return new UrlManager(GROCY_BASE_URL);
|
return new UrlManager(GROCY_BASE_URL);
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->set('ApiKeyHeaderName', function (Container $container) {
|
$container->set('ApiKeyHeaderName', function (Container $container)
|
||||||
|
{
|
||||||
return 'GROCY-API-KEY';
|
return 'GROCY-API-KEY';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -8,9 +8,7 @@ use Psr\Http\Message\ResponseInterface as Response;
|
|||||||
class BaseApiController extends BaseController
|
class BaseApiController extends BaseController
|
||||||
{
|
{
|
||||||
const PATTERN_FIELD = '[A-Za-z_][A-Za-z0-9_]+';
|
const PATTERN_FIELD = '[A-Za-z_][A-Za-z0-9_]+';
|
||||||
|
|
||||||
const PATTERN_OPERATOR = '!?((>=)|(<=)|=|~|<|>|(§))';
|
const PATTERN_OPERATOR = '!?((>=)|(<=)|=|~|<|>|(§))';
|
||||||
|
|
||||||
const PATTERN_VALUE = '[A-Za-z\p{L}\p{M}0-9*_.$#^| -\\\]+';
|
const PATTERN_VALUE = '[A-Za-z\p{L}\p{M}0-9*_.$#^| -\\\]+';
|
||||||
|
|
||||||
protected $OpenApiSpec = null;
|
protected $OpenApiSpec = null;
|
||||||
|
@@ -29,7 +29,6 @@ class BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected $AppContainer;
|
protected $AppContainer;
|
||||||
|
|
||||||
private $View;
|
private $View;
|
||||||
|
|
||||||
protected function getApiKeyService()
|
protected function getApiKeyService()
|
||||||
@@ -125,10 +124,12 @@ class BaseController
|
|||||||
$this->View->set('version', $versionInfo->Version);
|
$this->View->set('version', $versionInfo->Version);
|
||||||
|
|
||||||
$localizationService = $this->getLocalizationService();
|
$localizationService = $this->getLocalizationService();
|
||||||
$this->View->set('__t', function (string $text, ...$placeholderValues) use ($localizationService) {
|
$this->View->set('__t', function (string $text, ...$placeholderValues) use ($localizationService)
|
||||||
|
{
|
||||||
return $localizationService->__t($text, $placeholderValues);
|
return $localizationService->__t($text, $placeholderValues);
|
||||||
});
|
});
|
||||||
$this->View->set('__n', function ($number, $singularForm, $pluralForm, $isQu = false) use ($localizationService) {
|
$this->View->set('__n', function ($number, $singularForm, $pluralForm, $isQu = false) use ($localizationService)
|
||||||
|
{
|
||||||
return $localizationService->__n($number, $singularForm, $pluralForm, $isQu);
|
return $localizationService->__n($number, $singularForm, $pluralForm, $isQu);
|
||||||
});
|
});
|
||||||
$this->View->set('LocalizationStrings', $localizationService->GetPoAsJsonString());
|
$this->View->set('LocalizationStrings', $localizationService->GetPoAsJsonString());
|
||||||
@@ -142,7 +143,8 @@ class BaseController
|
|||||||
}
|
}
|
||||||
$this->View->set('dir', $dir);
|
$this->View->set('dir', $dir);
|
||||||
|
|
||||||
$this->View->set('U', function ($relativePath, $isResource = false) use ($container) {
|
$this->View->set('U', function ($relativePath, $isResource = false) use ($container)
|
||||||
|
{
|
||||||
return $container->get('UrlManager')->ConstructUrl($relativePath, $isResource);
|
return $container->get('UrlManager')->ConstructUrl($relativePath, $isResource);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -16,11 +16,11 @@ trait GrocycodeTrait
|
|||||||
|
|
||||||
if (GROCY_GROCYCODE_TYPE == '2D')
|
if (GROCY_GROCYCODE_TYPE == '2D')
|
||||||
{
|
{
|
||||||
$png = (new DatamatrixFactory())->setCode((string) $grocycode)->setSize($size)->getDatamatrixPngData();
|
$png = (new DatamatrixFactory())->setCode((string)$grocycode)->setSize($size)->getDatamatrixPngData();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$png = (new BarcodeFactory())->setType('C128')->setCode((string) $grocycode)->setHeight($size)->getBarcodePngData();
|
$png = (new BarcodeFactory())->setType('C128')->setCode((string)$grocycode)->setHeight($size)->getBarcodePngData();
|
||||||
}
|
}
|
||||||
|
|
||||||
$isDownload = $request->getQueryParam('download', false);
|
$isDownload = $request->getQueryParam('download', false);
|
||||||
|
@@ -8,63 +8,34 @@ use LessQL\Result;
|
|||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
const PERMISSION_ADMIN = 'ADMIN';
|
const PERMISSION_ADMIN = 'ADMIN';
|
||||||
|
|
||||||
const PERMISSION_BATTERIES = 'BATTERIES';
|
const PERMISSION_BATTERIES = 'BATTERIES';
|
||||||
|
|
||||||
const PERMISSION_BATTERIES_TRACK_CHARGE_CYCLE = 'BATTERIES_TRACK_CHARGE_CYCLE';
|
const PERMISSION_BATTERIES_TRACK_CHARGE_CYCLE = 'BATTERIES_TRACK_CHARGE_CYCLE';
|
||||||
|
|
||||||
const PERMISSION_BATTERIES_UNDO_CHARGE_CYCLE = 'BATTERIES_UNDO_CHARGE_CYCLE';
|
const PERMISSION_BATTERIES_UNDO_CHARGE_CYCLE = 'BATTERIES_UNDO_CHARGE_CYCLE';
|
||||||
|
|
||||||
const PERMISSION_CALENDAR = 'CALENDAR';
|
const PERMISSION_CALENDAR = 'CALENDAR';
|
||||||
|
|
||||||
const PERMISSION_CHORES = 'CHORES';
|
const PERMISSION_CHORES = 'CHORES';
|
||||||
|
|
||||||
const PERMISSION_CHORE_TRACK_EXECUTION = 'CHORE_TRACK_EXECUTION';
|
const PERMISSION_CHORE_TRACK_EXECUTION = 'CHORE_TRACK_EXECUTION';
|
||||||
|
|
||||||
const PERMISSION_CHORE_UNDO_EXECUTION = 'CHORE_UNDO_EXECUTION';
|
const PERMISSION_CHORE_UNDO_EXECUTION = 'CHORE_UNDO_EXECUTION';
|
||||||
|
|
||||||
const PERMISSION_EQUIPMENT = 'EQUIPMENT';
|
const PERMISSION_EQUIPMENT = 'EQUIPMENT';
|
||||||
|
|
||||||
const PERMISSION_MASTER_DATA_EDIT = 'MASTER_DATA_EDIT';
|
const PERMISSION_MASTER_DATA_EDIT = 'MASTER_DATA_EDIT';
|
||||||
|
|
||||||
const PERMISSION_RECIPES = 'RECIPES';
|
const PERMISSION_RECIPES = 'RECIPES';
|
||||||
|
|
||||||
const PERMISSION_RECIPES_MEALPLAN = 'RECIPES_MEALPLAN';
|
const PERMISSION_RECIPES_MEALPLAN = 'RECIPES_MEALPLAN';
|
||||||
|
|
||||||
const PERMISSION_SHOPPINGLIST = 'SHOPPINGLIST';
|
const PERMISSION_SHOPPINGLIST = 'SHOPPINGLIST';
|
||||||
|
|
||||||
const PERMISSION_SHOPPINGLIST_ITEMS_ADD = 'SHOPPINGLIST_ITEMS_ADD';
|
const PERMISSION_SHOPPINGLIST_ITEMS_ADD = 'SHOPPINGLIST_ITEMS_ADD';
|
||||||
|
|
||||||
const PERMISSION_SHOPPINGLIST_ITEMS_DELETE = 'SHOPPINGLIST_ITEMS_DELETE';
|
const PERMISSION_SHOPPINGLIST_ITEMS_DELETE = 'SHOPPINGLIST_ITEMS_DELETE';
|
||||||
|
|
||||||
const PERMISSION_STOCK = 'STOCK';
|
const PERMISSION_STOCK = 'STOCK';
|
||||||
|
|
||||||
const PERMISSION_STOCK_CONSUME = 'STOCK_CONSUME';
|
const PERMISSION_STOCK_CONSUME = 'STOCK_CONSUME';
|
||||||
|
|
||||||
const PERMISSION_STOCK_EDIT = 'STOCK_EDIT';
|
const PERMISSION_STOCK_EDIT = 'STOCK_EDIT';
|
||||||
|
|
||||||
const PERMISSION_STOCK_INVENTORY = 'STOCK_INVENTORY';
|
const PERMISSION_STOCK_INVENTORY = 'STOCK_INVENTORY';
|
||||||
|
|
||||||
const PERMISSION_STOCK_OPEN = 'STOCK_OPEN';
|
const PERMISSION_STOCK_OPEN = 'STOCK_OPEN';
|
||||||
|
|
||||||
const PERMISSION_STOCK_PURCHASE = 'STOCK_PURCHASE';
|
const PERMISSION_STOCK_PURCHASE = 'STOCK_PURCHASE';
|
||||||
|
|
||||||
const PERMISSION_STOCK_TRANSFER = 'STOCK_TRANSFER';
|
const PERMISSION_STOCK_TRANSFER = 'STOCK_TRANSFER';
|
||||||
|
|
||||||
const PERMISSION_TASKS = 'TASKS';
|
const PERMISSION_TASKS = 'TASKS';
|
||||||
|
|
||||||
const PERMISSION_TASKS_MARK_COMPLETED = 'TASKS_MARK_COMPLETED';
|
const PERMISSION_TASKS_MARK_COMPLETED = 'TASKS_MARK_COMPLETED';
|
||||||
|
|
||||||
const PERMISSION_TASKS_UNDO_EXECUTION = 'TASKS_UNDO_EXECUTION';
|
const PERMISSION_TASKS_UNDO_EXECUTION = 'TASKS_UNDO_EXECUTION';
|
||||||
|
|
||||||
const PERMISSION_USERS = 'USERS';
|
const PERMISSION_USERS = 'USERS';
|
||||||
|
|
||||||
const PERMISSION_USERS_CREATE = 'USERS_CREATE';
|
const PERMISSION_USERS_CREATE = 'USERS_CREATE';
|
||||||
|
|
||||||
const PERMISSION_USERS_EDIT = 'USERS_EDIT';
|
const PERMISSION_USERS_EDIT = 'USERS_EDIT';
|
||||||
|
|
||||||
const PERMISSION_USERS_EDIT_SELF = 'USERS_EDIT_SELF';
|
const PERMISSION_USERS_EDIT_SELF = 'USERS_EDIT_SELF';
|
||||||
|
|
||||||
const PERMISSION_USERS_READ = 'USERS_READ';
|
const PERMISSION_USERS_READ = 'USERS_READ';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
@@ -51,7 +51,8 @@ class UsersController extends BaseController
|
|||||||
public function UserSettings(Request $request, Response $response, array $args)
|
public function UserSettings(Request $request, Response $response, array $args)
|
||||||
{
|
{
|
||||||
return $this->renderPage($response, 'usersettings', [
|
return $this->renderPage($response, 'usersettings', [
|
||||||
'languages' => array_filter(scandir(__DIR__ . '/../localization'), function ($item) {
|
'languages' => array_filter(scandir(__DIR__ . '/../localization'), function ($item)
|
||||||
|
{
|
||||||
if ($item == '.' || $item == '..')
|
if ($item == '.' || $item == '..')
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@@ -11,7 +11,6 @@ abstract class BaseBarcodeLookupPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected $Locations;
|
protected $Locations;
|
||||||
|
|
||||||
protected $QuantityUnits;
|
protected $QuantityUnits;
|
||||||
|
|
||||||
final public function Lookup($barcode)
|
final public function Lookup($barcode)
|
||||||
|
@@ -18,13 +18,9 @@ namespace Grocy\Helpers;
|
|||||||
class Grocycode
|
class Grocycode
|
||||||
{
|
{
|
||||||
public const PRODUCT = 'p';
|
public const PRODUCT = 'p';
|
||||||
|
|
||||||
public const BATTERY = 'b';
|
public const BATTERY = 'b';
|
||||||
|
|
||||||
public const CHORE = 'c';
|
public const CHORE = 'c';
|
||||||
|
|
||||||
public const RECIPE = 'r';
|
public const RECIPE = 'r';
|
||||||
|
|
||||||
public const MAGIC = 'grcy';
|
public const MAGIC = 'grcy';
|
||||||
|
|
||||||
public function __construct(...$args)
|
public function __construct(...$args)
|
||||||
@@ -49,11 +45,8 @@ class Grocycode
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static $Items = [self::PRODUCT, self::BATTERY, self::CHORE, self::RECIPE];
|
public static $Items = [self::PRODUCT, self::BATTERY, self::CHORE, self::RECIPE];
|
||||||
|
|
||||||
private $type;
|
private $type;
|
||||||
|
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
private $extra_data = [];
|
private $extra_data = [];
|
||||||
|
|
||||||
public static function Validate(string $code)
|
public static function Validate(string $code)
|
||||||
|
@@ -8,7 +8,6 @@ use DI\Container;
|
|||||||
class BaseMiddleware
|
class BaseMiddleware
|
||||||
{
|
{
|
||||||
protected $AppContainer;
|
protected $AppContainer;
|
||||||
|
|
||||||
protected $ApplicationService;
|
protected $ApplicationService;
|
||||||
|
|
||||||
public function __construct(Container $container)
|
public function __construct(Container $container)
|
||||||
|
@@ -35,9 +35,10 @@ class LocaleMiddleware extends BaseMiddleware
|
|||||||
// Src: https://gist.github.com/spolischook/0cde9c6286415cddc088
|
// Src: https://gist.github.com/spolischook/0cde9c6286415cddc088
|
||||||
$prefLocales = array_reduce(
|
$prefLocales = array_reduce(
|
||||||
explode(',', $langs),
|
explode(',', $langs),
|
||||||
function ($res, $el) {
|
function ($res, $el)
|
||||||
|
{
|
||||||
list($l, $q) = array_merge(explode(';q=', $el), [1]);
|
list($l, $q) = array_merge(explode(';q=', $el), [1]);
|
||||||
$res[$l] = (float) $q;
|
$res[$l] = (float)$q;
|
||||||
return $res;
|
return $res;
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
|
@@ -5,7 +5,8 @@ use Psr\Http\Message\ResponseInterface as Response;
|
|||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Slim\Routing\RouteCollectorProxy;
|
use Slim\Routing\RouteCollectorProxy;
|
||||||
|
|
||||||
$app->group('', function (RouteCollectorProxy $group) {
|
$app->group('', function (RouteCollectorProxy $group)
|
||||||
|
{
|
||||||
// System routes
|
// System routes
|
||||||
$group->get('/', '\Grocy\Controllers\SystemController:Root')->setName('root');
|
$group->get('/', '\Grocy\Controllers\SystemController:Root')->setName('root');
|
||||||
$group->get('/about', '\Grocy\Controllers\SystemController:About');
|
$group->get('/about', '\Grocy\Controllers\SystemController:About');
|
||||||
@@ -124,7 +125,8 @@ $app->group('', function (RouteCollectorProxy $group) {
|
|||||||
$group->get('/manageapikeys/new', '\Grocy\Controllers\OpenApiController:CreateNewApiKey');
|
$group->get('/manageapikeys/new', '\Grocy\Controllers\OpenApiController:CreateNewApiKey');
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->group('/api', function (RouteCollectorProxy $group) {
|
$app->group('/api', function (RouteCollectorProxy $group)
|
||||||
|
{
|
||||||
// OpenAPI
|
// OpenAPI
|
||||||
$group->get('/openapi/specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec');
|
$group->get('/openapi/specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec');
|
||||||
|
|
||||||
@@ -243,6 +245,7 @@ $app->group('/api', function (RouteCollectorProxy $group) {
|
|||||||
})->add(JsonMiddleware::class);
|
})->add(JsonMiddleware::class);
|
||||||
|
|
||||||
// Handle CORS preflight OPTIONS requests
|
// Handle CORS preflight OPTIONS requests
|
||||||
$app->options('/api/{routes:.+}', function (Request $request, Response $response): Response {
|
$app->options('/api/{routes:.+}', function (Request $request, Response $response): Response
|
||||||
|
{
|
||||||
return $response->withStatus(204);
|
return $response->withStatus(204);
|
||||||
});
|
});
|
||||||
|
@@ -5,7 +5,6 @@ namespace Grocy\Services;
|
|||||||
class ApiKeyService extends BaseService
|
class ApiKeyService extends BaseService
|
||||||
{
|
{
|
||||||
const API_KEY_TYPE_DEFAULT = 'default';
|
const API_KEY_TYPE_DEFAULT = 'default';
|
||||||
|
|
||||||
const API_KEY_TYPE_SPECIAL_PURPOSE_CALENDAR_ICAL = 'special-purpose-calendar-ical';
|
const API_KEY_TYPE_SPECIAL_PURPOSE_CALENDAR_ICAL = 'special-purpose-calendar-ical';
|
||||||
|
|
||||||
public function CreateApiKey(string $keyType = self::API_KEY_TYPE_DEFAULT, string $description = null)
|
public function CreateApiKey(string $keyType = self::API_KEY_TYPE_DEFAULT, string $description = null)
|
||||||
|
@@ -33,7 +33,8 @@ class ApplicationService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort changelog items to have the changelog descending by newest version
|
// Sort changelog items to have the changelog descending by newest version
|
||||||
usort($changelogItems, function ($a, $b) {
|
usort($changelogItems, function ($a, $b)
|
||||||
|
{
|
||||||
if ($a['release_number'] == $b['release_number'])
|
if ($a['release_number'] == $b['release_number'])
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -5,25 +5,15 @@ namespace Grocy\Services;
|
|||||||
class ChoresService extends BaseService
|
class ChoresService extends BaseService
|
||||||
{
|
{
|
||||||
const CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER = 'in-alphabetical-order';
|
const CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER = 'in-alphabetical-order';
|
||||||
|
|
||||||
const CHORE_ASSIGNMENT_TYPE_NO_ASSIGNMENT = 'no-assignment';
|
const CHORE_ASSIGNMENT_TYPE_NO_ASSIGNMENT = 'no-assignment';
|
||||||
|
|
||||||
const CHORE_ASSIGNMENT_TYPE_RANDOM = 'random';
|
const CHORE_ASSIGNMENT_TYPE_RANDOM = 'random';
|
||||||
|
|
||||||
const CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST = 'who-least-did-first';
|
const CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST = 'who-least-did-first';
|
||||||
|
|
||||||
const CHORE_PERIOD_TYPE_HOURLY = 'hourly';
|
const CHORE_PERIOD_TYPE_HOURLY = 'hourly';
|
||||||
|
|
||||||
const CHORE_PERIOD_TYPE_DAILY = 'daily';
|
const CHORE_PERIOD_TYPE_DAILY = 'daily';
|
||||||
|
|
||||||
const CHORE_PERIOD_TYPE_MANUALLY = 'manually';
|
const CHORE_PERIOD_TYPE_MANUALLY = 'manually';
|
||||||
|
|
||||||
const CHORE_PERIOD_TYPE_MONTHLY = 'monthly';
|
const CHORE_PERIOD_TYPE_MONTHLY = 'monthly';
|
||||||
|
|
||||||
const CHORE_PERIOD_TYPE_WEEKLY = 'weekly';
|
const CHORE_PERIOD_TYPE_WEEKLY = 'weekly';
|
||||||
|
|
||||||
const CHORE_PERIOD_TYPE_YEARLY = 'yearly';
|
const CHORE_PERIOD_TYPE_YEARLY = 'yearly';
|
||||||
|
|
||||||
const CHORE_PERIOD_TYPE_ADAPTIVE = 'adaptive';
|
const CHORE_PERIOD_TYPE_ADAPTIVE = 'adaptive';
|
||||||
|
|
||||||
public function CalculateNextExecutionAssignment($choreId)
|
public function CalculateNextExecutionAssignment($choreId)
|
||||||
@@ -70,7 +60,8 @@ class ChoresService extends BaseService
|
|||||||
}
|
}
|
||||||
elseif ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER)
|
elseif ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER)
|
||||||
{
|
{
|
||||||
usort($assignedUsers, function ($a, $b) {
|
usort($assignedUsers, function ($a, $b)
|
||||||
|
{
|
||||||
return strcmp($a->display_name, $b->display_name);
|
return strcmp($a->display_name, $b->display_name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -8,9 +8,7 @@ use LessQL\Database;
|
|||||||
class DatabaseService
|
class DatabaseService
|
||||||
{
|
{
|
||||||
private static $DbConnection = null;
|
private static $DbConnection = null;
|
||||||
|
|
||||||
private static $DbConnectionRaw = null;
|
private static $DbConnectionRaw = null;
|
||||||
|
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
public function ExecuteDbQuery(string $sql)
|
public function ExecuteDbQuery(string $sql)
|
||||||
@@ -63,7 +61,8 @@ class DatabaseService
|
|||||||
$logFilePath = GROCY_DATAPATH . '/sql.log';
|
$logFilePath = GROCY_DATAPATH . '/sql.log';
|
||||||
if (file_exists($logFilePath))
|
if (file_exists($logFilePath))
|
||||||
{
|
{
|
||||||
self::$DbConnection->setQueryCallback(function ($query, $params) use ($logFilePath) {
|
self::$DbConnection->setQueryCallback(function ($query, $params) use ($logFilePath)
|
||||||
|
{
|
||||||
file_put_contents($logFilePath, $query . ' #### ' . implode(';', $params) . PHP_EOL, FILE_APPEND);
|
file_put_contents($logFilePath, $query . ' #### ' . implode(';', $params) . PHP_EOL, FILE_APPEND);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -80,12 +79,14 @@ class DatabaseService
|
|||||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
$pdo->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_EMPTY_STRING);
|
$pdo->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_EMPTY_STRING);
|
||||||
|
|
||||||
$pdo->sqliteCreateFunction('regexp', function ($pattern, $value) {
|
$pdo->sqliteCreateFunction('regexp', function ($pattern, $value)
|
||||||
|
{
|
||||||
mb_regex_encoding('UTF-8');
|
mb_regex_encoding('UTF-8');
|
||||||
return (false !== mb_ereg($pattern, $value)) ? 1 : 0;
|
return (false !== mb_ereg($pattern, $value)) ? 1 : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
$pdo->sqliteCreateFunction('grocy_user_setting', function ($value) {
|
$pdo->sqliteCreateFunction('grocy_user_setting', function ($value)
|
||||||
|
{
|
||||||
$usersService = new UsersService();
|
$usersService = new UsersService();
|
||||||
return $usersService->GetUserSetting(GROCY_USER_ID, $value);
|
return $usersService->GetUserSetting(GROCY_USER_ID, $value);
|
||||||
});
|
});
|
||||||
|
@@ -10,7 +10,6 @@ class DemoDataGeneratorService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected $LocalizationService;
|
protected $LocalizationService;
|
||||||
|
|
||||||
private $LastSupermarketId = 1;
|
private $LastSupermarketId = 1;
|
||||||
|
|
||||||
public function PopulateDemoData()
|
public function PopulateDemoData()
|
||||||
|
@@ -16,19 +16,12 @@ class LocalizationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected $Po;
|
protected $Po;
|
||||||
|
|
||||||
protected $PoQu;
|
protected $PoQu;
|
||||||
|
|
||||||
protected $Pot;
|
protected $Pot;
|
||||||
|
|
||||||
protected $PotMain;
|
protected $PotMain;
|
||||||
|
|
||||||
protected $Translator;
|
protected $Translator;
|
||||||
|
|
||||||
protected $TranslatorQu;
|
protected $TranslatorQu;
|
||||||
|
|
||||||
protected $Culture;
|
protected $Culture;
|
||||||
|
|
||||||
private static $instanceMap = [];
|
private static $instanceMap = [];
|
||||||
|
|
||||||
public function CheckAndAddMissingTranslationToPot($text)
|
public function CheckAndAddMissingTranslationToPot($text)
|
||||||
|
@@ -7,11 +7,8 @@ use LessQL\Result;
|
|||||||
class RecipesService extends BaseService
|
class RecipesService extends BaseService
|
||||||
{
|
{
|
||||||
const RECIPE_TYPE_MEALPLAN_DAY = 'mealplan-day'; // A recipe per meal plan day => name = YYYY-MM-DD
|
const RECIPE_TYPE_MEALPLAN_DAY = 'mealplan-day'; // A recipe per meal plan day => name = YYYY-MM-DD
|
||||||
|
|
||||||
const RECIPE_TYPE_MEALPLAN_WEEK = 'mealplan-week'; // A recipe per meal plan week => name = YYYY-WW (week number)
|
const RECIPE_TYPE_MEALPLAN_WEEK = 'mealplan-week'; // A recipe per meal plan week => name = YYYY-WW (week number)
|
||||||
|
|
||||||
const RECIPE_TYPE_MEALPLAN_SHADOW = 'mealplan-shadow'; // A recipe per meal plan recipe (for separated stock fulfillment checking) => name = YYYY-MM-DD#<meal_plan.id>
|
const RECIPE_TYPE_MEALPLAN_SHADOW = 'mealplan-shadow'; // A recipe per meal plan recipe (for separated stock fulfillment checking) => name = YYYY-MM-DD#<meal_plan.id>
|
||||||
|
|
||||||
const RECIPE_TYPE_NORMAL = 'normal'; // Normal / manually created recipes
|
const RECIPE_TYPE_NORMAL = 'normal'; // Normal / manually created recipes
|
||||||
|
|
||||||
public function AddNotFulfilledProductsToShoppingList($recipeId, $excludedProductIds = null)
|
public function AddNotFulfilledProductsToShoppingList($recipeId, $excludedProductIds = null)
|
||||||
|
@@ -8,21 +8,13 @@ use Grocy\Helpers\WebhookRunner;
|
|||||||
class StockService extends BaseService
|
class StockService extends BaseService
|
||||||
{
|
{
|
||||||
const TRANSACTION_TYPE_CONSUME = 'consume';
|
const TRANSACTION_TYPE_CONSUME = 'consume';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction';
|
const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_PRODUCT_OPENED = 'product-opened';
|
const TRANSACTION_TYPE_PRODUCT_OPENED = 'product-opened';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_PURCHASE = 'purchase';
|
const TRANSACTION_TYPE_PURCHASE = 'purchase';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_SELF_PRODUCTION = 'self-production';
|
const TRANSACTION_TYPE_SELF_PRODUCTION = 'self-production';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_STOCK_EDIT_NEW = 'stock-edit-new';
|
const TRANSACTION_TYPE_STOCK_EDIT_NEW = 'stock-edit-new';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_STOCK_EDIT_OLD = 'stock-edit-old';
|
const TRANSACTION_TYPE_STOCK_EDIT_OLD = 'stock-edit-old';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_TRANSFER_FROM = 'transfer_from';
|
const TRANSACTION_TYPE_TRANSFER_FROM = 'transfer_from';
|
||||||
|
|
||||||
const TRANSACTION_TYPE_TRANSFER_TO = 'transfer_to';
|
const TRANSACTION_TYPE_TRANSFER_TO = 'transfer_to';
|
||||||
|
|
||||||
public function AddMissingProductsToShoppingList($listId = 1)
|
public function AddMissingProductsToShoppingList($listId = 1)
|
||||||
@@ -121,7 +113,7 @@ class StockService extends BaseService
|
|||||||
throw new \Exception('Product does not exist or is inactive');
|
throw new \Exception('Product does not exist or is inactive');
|
||||||
}
|
}
|
||||||
|
|
||||||
$productDetails = (object) $this->GetProductDetails($productId);
|
$productDetails = (object)$this->GetProductDetails($productId);
|
||||||
|
|
||||||
// Tare weight handling
|
// Tare weight handling
|
||||||
// The given amount is the new total amount including the container weight (gross)
|
// The given amount is the new total amount including the container weight (gross)
|
||||||
@@ -369,7 +361,7 @@ class StockService extends BaseService
|
|||||||
throw new \Exception('Location does not exist');
|
throw new \Exception('Location does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
$productDetails = (object) $this->GetProductDetails($productId);
|
$productDetails = (object)$this->GetProductDetails($productId);
|
||||||
|
|
||||||
// Tare weight handling
|
// Tare weight handling
|
||||||
// The given amount is the new total amount including the container weight (gross)
|
// The given amount is the new total amount including the container weight (gross)
|
||||||
@@ -915,7 +907,7 @@ class StockService extends BaseService
|
|||||||
throw new \Exception('Product does not exist or is inactive');
|
throw new \Exception('Product does not exist or is inactive');
|
||||||
}
|
}
|
||||||
|
|
||||||
$productDetails = (object) $this->GetProductDetails($productId);
|
$productDetails = (object)$this->GetProductDetails($productId);
|
||||||
|
|
||||||
if ($price === null)
|
if ($price === null)
|
||||||
{
|
{
|
||||||
@@ -979,7 +971,7 @@ class StockService extends BaseService
|
|||||||
throw new \Exception('Product does not exist or is inactive');
|
throw new \Exception('Product does not exist or is inactive');
|
||||||
}
|
}
|
||||||
|
|
||||||
$productDetails = (object) $this->GetProductDetails($productId);
|
$productDetails = (object)$this->GetProductDetails($productId);
|
||||||
$productStockAmountUnopened = $productDetails->stock_amount_aggregated - $productDetails->stock_amount_opened_aggregated;
|
$productStockAmountUnopened = $productDetails->stock_amount_aggregated - $productDetails->stock_amount_opened_aggregated;
|
||||||
$potentialStockEntries = $this->GetProductStockEntries($productId, true, $allowSubproductSubstitution);
|
$potentialStockEntries = $this->GetProductStockEntries($productId, true, $allowSubproductSubstitution);
|
||||||
$product = $this->getDatabase()->products($productId);
|
$product = $this->getDatabase()->products($productId);
|
||||||
@@ -1270,7 +1262,7 @@ class StockService extends BaseService
|
|||||||
// Tare weight handling
|
// Tare weight handling
|
||||||
// The given amount is the new total amount including the container weight (gross)
|
// The given amount is the new total amount including the container weight (gross)
|
||||||
// The amount to be posted needs to be the absolute value of the given amount - stock amount - tare weight
|
// The amount to be posted needs to be the absolute value of the given amount - stock amount - tare weight
|
||||||
$productDetails = (object) $this->GetProductDetails($productId);
|
$productDetails = (object)$this->GetProductDetails($productId);
|
||||||
|
|
||||||
if ($productDetails->product->enable_tare_weight_handling == 1)
|
if ($productDetails->product->enable_tare_weight_handling == 1)
|
||||||
{
|
{
|
||||||
|
@@ -5,29 +5,17 @@ namespace Grocy\Services;
|
|||||||
class UserfieldsService extends BaseService
|
class UserfieldsService extends BaseService
|
||||||
{
|
{
|
||||||
const USERFIELD_TYPE_CHECKBOX = 'checkbox';
|
const USERFIELD_TYPE_CHECKBOX = 'checkbox';
|
||||||
|
|
||||||
const USERFIELD_TYPE_DATE = 'date';
|
const USERFIELD_TYPE_DATE = 'date';
|
||||||
|
|
||||||
const USERFIELD_TYPE_DATETIME = 'datetime';
|
const USERFIELD_TYPE_DATETIME = 'datetime';
|
||||||
|
|
||||||
const USERFIELD_TYPE_DECIMAL_NUMBER = 'number-decimal';
|
const USERFIELD_TYPE_DECIMAL_NUMBER = 'number-decimal';
|
||||||
|
|
||||||
const USERFIELD_TYPE_FILE = 'file';
|
const USERFIELD_TYPE_FILE = 'file';
|
||||||
|
|
||||||
const USERFIELD_TYPE_IMAGE = 'image';
|
const USERFIELD_TYPE_IMAGE = 'image';
|
||||||
|
|
||||||
const USERFIELD_TYPE_INTEGRAL_NUMBER = 'number-integral';
|
const USERFIELD_TYPE_INTEGRAL_NUMBER = 'number-integral';
|
||||||
|
|
||||||
const USERFIELD_TYPE_LINK = 'link';
|
const USERFIELD_TYPE_LINK = 'link';
|
||||||
|
|
||||||
const USERFIELD_TYPE_LINK_WITH_TITLE = 'link-with-title';
|
const USERFIELD_TYPE_LINK_WITH_TITLE = 'link-with-title';
|
||||||
|
|
||||||
const USERFIELD_TYPE_PRESET_CHECKLIST = 'preset-checklist';
|
const USERFIELD_TYPE_PRESET_CHECKLIST = 'preset-checklist';
|
||||||
|
|
||||||
const USERFIELD_TYPE_PRESET_LIST = 'preset-list';
|
const USERFIELD_TYPE_PRESET_LIST = 'preset-list';
|
||||||
|
|
||||||
const USERFIELD_TYPE_SINGLE_LINE_TEXT = 'text-single-line';
|
const USERFIELD_TYPE_SINGLE_LINE_TEXT = 'text-single-line';
|
||||||
|
|
||||||
const USERFIELD_TYPE_SINGLE_MULTILINE_TEXT = 'text-multi-line';
|
const USERFIELD_TYPE_SINGLE_MULTILINE_TEXT = 'text-multi-line';
|
||||||
|
|
||||||
protected $OpenApiSpec = null;
|
protected $OpenApiSpec = null;
|
||||||
|
Reference in New Issue
Block a user