From 38e84ca1e144ed5f5e66675e993d03f7842aef93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sat, 27 Jan 2024 10:39:53 +0100 Subject: [PATCH] chore(tests): UT for CustomFieldData service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../api/Controllers/Account/AccountBase.php | 6 +- .../Controllers/Account/AccountSaveBase.php | 8 +- .../Account/SaveDeleteController.php | 8 +- .../AccountManager/BulkEditController.php | 8 +- .../AccountManager/DeleteController.php | 8 +- .../AuthToken/AuthTokenSaveBase.php | 8 +- .../AuthToken/AuthTokenViewBase.php | 4 +- .../Controllers/Category/CategorySaveBase.php | 10 +- .../Controllers/Category/CategoryViewBase.php | 8 +- .../web/Controllers/Client/ClientSaveBase.php | 10 +- .../web/Controllers/Client/ClientViewBase.php | 8 +- .../Helpers/Account/AccountHelper.php | 10 +- .../web/Controllers/Tag/TagSaveBase.php | 8 +- .../web/Controllers/User/UserSaveBase.php | 18 +- .../web/Controllers/User/UserViewBase.php | 6 +- .../UserGroup/UserGroupSaveBase.php | 6 +- .../UserGroup/UserGroupViewBase.php | 6 +- .../UserProfile/UserProfileSaveBase.php | 6 +- .../UserProfile/UserProfileViewBase.php | 6 +- .../Account/Adapters/AccountAdapter.php | 8 +- lib/SP/Domain/Category/Adapters/Category.php | 8 +- .../Domain/Client/Adapters/ClientAdapter.php | 4 +- .../Client/Ports/ClientAdapterInterface.php | 4 +- lib/SP/Domain/Core/Exceptions/SPException.php | 24 +- lib/SP/Domain/Core/Exceptions/Type.php | 36 + .../CustomField/Models/CustomFieldData.php | 6 - .../Ports/CustomFieldDataService.php | 91 ++ .../CustomField/Ports/CustomFieldService.php | 129 -- .../CustomField/Services/CustomField.php | 260 ---- .../CustomField/Services/CustomFieldCrypt.php | 19 +- .../CustomField/Services/CustomFieldData.php | 220 +++ .../UpgradeCustomFieldDataService.php | 12 +- .../Infrastructure/Database/QueryResult.php | 75 +- lib/SP/Mvc/Controller/ItemTrait.php | 199 +-- schemas/40024210101.sql | 28 + schemas/dbstructure.sql | 1295 +++++++++-------- .../Account/Adapters/AccountAdapterTest.php | 8 +- .../Domain/Account/Services/AccountTest.php | 39 +- .../Domain/Auth/Services/AuthTokenTest.php | 15 +- .../Domain/Category/Services/CategoryTest.php | 6 +- .../SPT/Domain/Client/Services/ClientTest.php | 6 +- .../Services/CustomFieldCryptTest.php | 8 +- .../Services/CustomFieldDataTest.php | 701 +++++++++ tests/SPT/Generators/AccountDataGenerator.php | 106 +- .../Generators/CustomFieldDataGenerator.php | 1 - .../Account/Repositories/AccountFileTest.php | 5 +- .../Repositories/AccountHistoryTest.php | 10 +- .../Account/Repositories/AccountTest.php | 6 +- .../Repositories/AccountToFavoriteTest.php | 5 +- .../Account/Repositories/AccountToTagTest.php | 5 +- .../Repositories/AccountToUserGroupTest.php | 15 +- .../Repositories/AccountToUserTest.php | 15 +- .../Account/Repositories/PublicLinkTest.php | 5 +- .../Auth/Repositories/AuthTokenTest.php | 3 +- 54 files changed, 2140 insertions(+), 1389 deletions(-) create mode 100644 lib/SP/Domain/Core/Exceptions/Type.php create mode 100644 lib/SP/Domain/CustomField/Ports/CustomFieldDataService.php delete mode 100644 lib/SP/Domain/CustomField/Ports/CustomFieldService.php delete mode 100644 lib/SP/Domain/CustomField/Services/CustomField.php create mode 100644 lib/SP/Domain/CustomField/Services/CustomFieldData.php create mode 100644 schemas/40024210101.sql create mode 100644 tests/SPT/Domain/CustomField/Services/CustomFieldDataTest.php diff --git a/app/modules/api/Controllers/Account/AccountBase.php b/app/modules/api/Controllers/Account/AccountBase.php index bdc02d4b..5d4898b4 100644 --- a/app/modules/api/Controllers/Account/AccountBase.php +++ b/app/modules/api/Controllers/Account/AccountBase.php @@ -33,7 +33,7 @@ use SP\Domain\Account\Ports\AccountService; use SP\Domain\Api\Ports\ApiService; use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Exceptions\InvalidClassException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Modules\Api\Controllers\ControllerBase; use SP\Modules\Api\Controllers\Help\AccountHelp; @@ -44,7 +44,7 @@ abstract class AccountBase extends ControllerBase { protected AccountPresetService $accountPresetService; protected AccountService $accountService; - protected CustomFieldService $customFieldService; + protected CustomFieldDataService $customFieldService; protected AccountAdapterInterface $accountAdapter; /** @@ -57,7 +57,7 @@ abstract class AccountBase extends ControllerBase AclInterface $acl, AccountPresetService $accountPresetService, AccountService $accountService, - CustomFieldService $customFieldService, + CustomFieldDataService $customFieldService, AccountAdapterInterface $accountAdapter ) { parent::__construct($application, $router, $apiService, $acl); diff --git a/app/modules/web/Controllers/Account/AccountSaveBase.php b/app/modules/web/Controllers/Account/AccountSaveBase.php index 4e3ae892..94ee2bf5 100644 --- a/app/modules/web/Controllers/Account/AccountSaveBase.php +++ b/app/modules/web/Controllers/Account/AccountSaveBase.php @@ -28,7 +28,7 @@ namespace SP\Modules\Web\Controllers\Account; use SP\Core\Application; use SP\Domain\Account\Ports\AccountPresetService; use SP\Domain\Account\Ports\AccountService; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Modules\Web\Forms\AccountForm; use SP\Mvc\Controller\ItemTrait; @@ -43,15 +43,15 @@ abstract class AccountSaveBase extends AccountControllerBase use JsonTrait; protected AccountService $accountService; - protected AccountForm $accountForm; - protected CustomFieldService $customFieldService; + protected AccountForm $accountForm; + protected CustomFieldDataService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, AccountPresetService $accountPresetService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct( $application, diff --git a/app/modules/web/Controllers/Account/SaveDeleteController.php b/app/modules/web/Controllers/Account/SaveDeleteController.php index b1089152..7ca5f25e 100644 --- a/app/modules/web/Controllers/Account/SaveDeleteController.php +++ b/app/modules/web/Controllers/Account/SaveDeleteController.php @@ -32,7 +32,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Http\JsonMessage; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; @@ -46,14 +46,14 @@ final class SaveDeleteController extends AccountControllerBase use ItemTrait; use JsonTrait; - private AccountService $accountService; - private CustomFieldService $customFieldService; + private AccountService $accountService; + private CustomFieldDataService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct( $application, diff --git a/app/modules/web/Controllers/AccountManager/BulkEditController.php b/app/modules/web/Controllers/AccountManager/BulkEditController.php index cbff5341..1b82363a 100644 --- a/app/modules/web/Controllers/AccountManager/BulkEditController.php +++ b/app/modules/web/Controllers/AccountManager/BulkEditController.php @@ -35,7 +35,7 @@ use SP\Domain\Account\Ports\AccountService; use SP\Domain\Category\Ports\CategoryService; use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\Tag\Ports\TagServiceInterface; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -60,9 +60,9 @@ final class BulkEditController extends ControllerBase private AccountService $accountService; private AccountSearchService $accountSearchService; private AccountHistoryService $accountHistoryService; - private AccountGrid $accountGrid; - private CustomFieldService $customFieldService; - private CategoryService $categoryService; + private AccountGrid $accountGrid; + private CustomFieldDataService $customFieldService; + private CategoryService $categoryService; private ClientService $clientService; private TagServiceInterface $tagService; private UserServiceInterface $userService; diff --git a/app/modules/web/Controllers/AccountManager/DeleteController.php b/app/modules/web/Controllers/AccountManager/DeleteController.php index 66c4bca7..caad6aef 100644 --- a/app/modules/web/Controllers/AccountManager/DeleteController.php +++ b/app/modules/web/Controllers/AccountManager/DeleteController.php @@ -31,7 +31,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Http\JsonMessage; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; @@ -48,14 +48,14 @@ final class DeleteController extends ControllerBase use ItemTrait; use JsonTrait; - private AccountService $accountService; - private CustomFieldService $customFieldService; + private AccountService $accountService; + private CustomFieldDataService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php b/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php index 7acacb2b..6dc00356 100644 --- a/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php +++ b/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\AuthToken; use SP\Core\Application; use SP\Domain\Auth\Ports\AuthTokenService; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Modules\Web\Forms\AuthTokenForm; @@ -42,15 +42,15 @@ abstract class AuthTokenSaveBase extends ControllerBase use ItemTrait; use JsonTrait; - protected CustomFieldService $customFieldService; - protected AuthTokenService $authTokenService; + protected CustomFieldDataService $customFieldService; + protected AuthTokenService $authTokenService; protected AuthTokenForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AuthTokenService $authTokenService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php b/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php index ffe89d36..955fc1f7 100644 --- a/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php +++ b/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\User\Ports\UserServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; @@ -59,7 +59,7 @@ abstract class AuthTokenViewBase extends ControllerBase public function __construct( Application $application, WebControllerHelper $webControllerHelper, - private readonly CustomFieldService $customFieldService, + private readonly CustomFieldDataService $customFieldService, private readonly UserServiceInterface $userService, private readonly AuthTokenService $authTokenService, private readonly AuthTokenActionInterface $authTokenAction, diff --git a/app/modules/web/Controllers/Category/CategorySaveBase.php b/app/modules/web/Controllers/Category/CategorySaveBase.php index 9c74d57c..24155154 100644 --- a/app/modules/web/Controllers/Category/CategorySaveBase.php +++ b/app/modules/web/Controllers/Category/CategorySaveBase.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\Category; use SP\Core\Application; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Modules\Web\Forms\CategoryForm; @@ -41,15 +41,15 @@ abstract class CategorySaveBase extends ControllerBase use ItemTrait; use JsonTrait; - protected CategoryService $categoryService; - protected CustomFieldService $customFieldService; - protected CategoryForm $form; + protected CategoryService $categoryService; + protected CustomFieldDataService $customFieldService; + protected CategoryForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, CategoryService $categoryService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Category/CategoryViewBase.php b/app/modules/web/Controllers/Category/CategoryViewBase.php index 34ae36e5..84a8dfad 100644 --- a/app/modules/web/Controllers/Category/CategoryViewBase.php +++ b/app/modules/web/Controllers/Category/CategoryViewBase.php @@ -33,7 +33,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; use SP\Mvc\Controller\ItemTrait; @@ -46,14 +46,14 @@ abstract class CategoryViewBase extends ControllerBase { use ItemTrait; - private CategoryService $categoryService; - private CustomFieldService $customFieldService; + private CategoryService $categoryService; + private CustomFieldDataService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, CategoryService $categoryService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Client/ClientSaveBase.php b/app/modules/web/Controllers/Client/ClientSaveBase.php index c0608e3e..a0905ce1 100644 --- a/app/modules/web/Controllers/Client/ClientSaveBase.php +++ b/app/modules/web/Controllers/Client/ClientSaveBase.php @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Client; use SP\Core\Application; use SP\Domain\Client\Ports\ClientService; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\ClientForm; use SP\Mvc\Controller\WebControllerHelper; @@ -37,15 +37,15 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class ClientSaveBase extends ControllerBase { - protected ClientService $clientService; - protected CustomFieldService $customFieldService; - protected ClientForm $form; + protected ClientService $clientService; + protected CustomFieldDataService $customFieldService; + protected ClientForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, ClientService $clientService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Client/ClientViewBase.php b/app/modules/web/Controllers/Client/ClientViewBase.php index ea03ba03..3f598677 100644 --- a/app/modules/web/Controllers/Client/ClientViewBase.php +++ b/app/modules/web/Controllers/Client/ClientViewBase.php @@ -34,7 +34,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; use SP\Mvc\Controller\ItemTrait; @@ -47,14 +47,14 @@ abstract class ClientViewBase extends ControllerBase { use ItemTrait; - private ClientService $clientService; - private CustomFieldService $customFieldService; + private ClientService $clientService; + private CustomFieldDataService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, ClientService $clientService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 8d3b8fe9..91455ab4 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -50,7 +50,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Crypt\Ports\MasterPassService; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\Http\RequestInterface; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; @@ -80,9 +80,9 @@ final class AccountHelper extends AccountHelperBase private MasterPassService $masterPassService; private AccountAclService $accountAclService; private CategoryService $categoryService; - private ClientService $clientService; - private CustomFieldService $customFieldService; - private ?AccountPermission $accountAcl = null; + private ClientService $clientService; + private CustomFieldDataService $customFieldService; + private ?AccountPermission $accountAcl = null; private ?int $accountId = null; private UserServiceInterface $userService; private UserGroupServiceInterface $userGroupService; @@ -102,7 +102,7 @@ final class AccountHelper extends AccountHelperBase AccountAclService $accountAclService, CategoryService $categoryService, ClientService $clientService, - CustomFieldService $customFieldService, + CustomFieldDataService $customFieldService, UserServiceInterface $userService, UserGroupServiceInterface $userGroupService, TagServiceInterface $tagService diff --git a/app/modules/web/Controllers/Tag/TagSaveBase.php b/app/modules/web/Controllers/Tag/TagSaveBase.php index bd6bb817..a3dd0c8d 100644 --- a/app/modules/web/Controllers/Tag/TagSaveBase.php +++ b/app/modules/web/Controllers/Tag/TagSaveBase.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\Tag; use SP\Core\Application; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\Tag\Ports\TagServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\TagForm; @@ -38,14 +38,14 @@ use SP\Mvc\Controller\WebControllerHelper; abstract class TagSaveBase extends ControllerBase { protected TagServiceInterface $tagService; - protected TagForm $form; - protected CustomFieldService $customFieldService; + protected TagForm $form; + protected CustomFieldDataService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, TagServiceInterface $tagService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/User/UserSaveBase.php b/app/modules/web/Controllers/User/UserSaveBase.php index b3e4ee95..e2f6fd57 100644 --- a/app/modules/web/Controllers/User/UserSaveBase.php +++ b/app/modules/web/Controllers/User/UserSaveBase.php @@ -32,7 +32,7 @@ use SP\DataModel\UserData; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\Notification\Ports\MailServiceInterface; use SP\Domain\User\Ports\UserPassRecoverServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -46,18 +46,18 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class UserSaveBase extends ControllerBase { - protected UserServiceInterface $userService; - protected CustomFieldService $customFieldService; - protected UserForm $form; + protected UserServiceInterface $userService; + protected CustomFieldDataService $customFieldService; + protected UserForm $form; private MailServiceInterface $mailService; private UserPassRecoverServiceInterface $userPassRecoverService; public function __construct( - Application $application, - WebControllerHelper $webControllerHelper, - UserServiceInterface $userService, - CustomFieldService $customFieldService, - MailServiceInterface $mailService, + Application $application, + WebControllerHelper $webControllerHelper, + UserServiceInterface $userService, + CustomFieldDataService $customFieldService, + MailServiceInterface $mailService, UserPassRecoverServiceInterface $userPassRecoverService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/User/UserViewBase.php b/app/modules/web/Controllers/User/UserViewBase.php index aaaeac0a..e7ddaeaa 100644 --- a/app/modules/web/Controllers/User/UserViewBase.php +++ b/app/modules/web/Controllers/User/UserViewBase.php @@ -33,7 +33,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -52,7 +52,7 @@ abstract class UserViewBase extends ControllerBase protected UserServiceInterface $userService; private UserGroupServiceInterface $userGroupService; private UserProfileServiceInterface $userProfileService; - private CustomFieldService $customFieldService; + private CustomFieldDataService $customFieldService; public function __construct( Application $application, @@ -60,7 +60,7 @@ abstract class UserViewBase extends ControllerBase UserServiceInterface $userService, UserGroupServiceInterface $userGroupService, UserProfileServiceInterface $userProfileService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php b/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php index ab5bcfe7..cd22f5f7 100644 --- a/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php +++ b/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\UserGroup; use SP\Core\Application; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\UserGroupForm; @@ -38,14 +38,14 @@ use SP\Mvc\Controller\WebControllerHelper; abstract class UserGroupSaveBase extends ControllerBase { protected UserGroupServiceInterface $userGroupService; - protected CustomFieldService $customFieldService; + protected CustomFieldDataService $customFieldService; protected UserGroupForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserGroupServiceInterface $userGroupService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php b/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php index 82e547b4..488c8660 100644 --- a/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php +++ b/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php @@ -33,7 +33,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; use SP\Infrastructure\Common\Repositories\NoSuchItemException; @@ -50,7 +50,7 @@ abstract class UserGroupViewBase extends ControllerBase use ItemTrait; private UserGroupServiceInterface $userGroupService; - private CustomFieldService $customFieldService; + private CustomFieldDataService $customFieldService; private UserServiceInterface $userService; public function __construct( @@ -58,7 +58,7 @@ abstract class UserGroupViewBase extends ControllerBase WebControllerHelper $webControllerHelper, UserGroupServiceInterface $userGroupService, UserServiceInterface $userService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php b/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php index f439337a..3a8ceeef 100644 --- a/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php +++ b/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\UserProfile; use SP\Core\Application; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\UserProfileForm; @@ -38,14 +38,14 @@ use SP\Mvc\Controller\WebControllerHelper; abstract class UserProfileSaveBase extends ControllerBase { protected UserProfileServiceInterface $userProfileService; - protected CustomFieldService $customFieldService; + protected CustomFieldDataService $customFieldService; protected UserProfileForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserProfileServiceInterface $userProfileService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php b/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php index 8844f037..49e374c4 100644 --- a/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php +++ b/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php @@ -34,7 +34,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; @@ -49,13 +49,13 @@ abstract class UserProfileViewBase extends ControllerBase use ItemTrait; private UserProfileServiceInterface $userProfileService; - private CustomFieldService $customFieldService; + private CustomFieldDataService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserProfileServiceInterface $userProfileService, - CustomFieldService $customFieldService + CustomFieldDataService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/lib/SP/Domain/Account/Adapters/AccountAdapter.php b/lib/SP/Domain/Account/Adapters/AccountAdapter.php index 1e469ca3..8fa29997 100644 --- a/lib/SP/Domain/Account/Adapters/AccountAdapter.php +++ b/lib/SP/Domain/Account/Adapters/AccountAdapter.php @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Adapters\CustomFieldAdapter; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Util\Link; @@ -51,9 +51,9 @@ final class AccountAdapter extends Adapter implements AccountAdapterInterface protected array $availableIncludes = ['customFields']; public function __construct( - ConfigDataInterface $configData, - private readonly CustomFieldService $customFieldService, - private readonly ActionsInterface $actions + ConfigDataInterface $configData, + private readonly CustomFieldDataService $customFieldService, + private readonly ActionsInterface $actions ) { parent::__construct($configData); } diff --git a/lib/SP/Domain/Category/Adapters/Category.php b/lib/SP/Domain/Category/Adapters/Category.php index 43369ff6..9dfdd1b2 100644 --- a/lib/SP/Domain/Category/Adapters/Category.php +++ b/lib/SP/Domain/Category/Adapters/Category.php @@ -37,7 +37,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Adapters\CustomFieldAdapter; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Mvc\Controller\ItemTrait; use SP\Util\Link; @@ -53,9 +53,9 @@ final class Category extends Adapter implements CategoryAdapter protected array $availableIncludes = ['customFields']; public function __construct( - ConfigDataInterface $configData, - private readonly CustomFieldService $customFieldService, - private readonly ActionsInterface $actions + ConfigDataInterface $configData, + private readonly CustomFieldDataService $customFieldService, + private readonly ActionsInterface $actions ) { parent::__construct($configData); } diff --git a/lib/SP/Domain/Client/Adapters/ClientAdapter.php b/lib/SP/Domain/Client/Adapters/ClientAdapter.php index 47b2243f..6a60e9e4 100644 --- a/lib/SP/Domain/Client/Adapters/ClientAdapter.php +++ b/lib/SP/Domain/Client/Adapters/ClientAdapter.php @@ -34,7 +34,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Adapters\CustomFieldAdapter; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Mvc\Controller\ItemTrait; use SP\Util\Link; @@ -55,7 +55,7 @@ final class ClientAdapter extends Adapter implements ClientAdapterInterface * @throws SPException * @throws ServiceException */ - public function includeCustomFields(Client $data, CustomFieldService $customFieldService): Collection + public function includeCustomFields(Client $data, CustomFieldDataService $customFieldService): Collection { return $this->collection( $this->getCustomFieldsForItem(AclActionsInterface::CLIENT, $data->id, $customFieldService), diff --git a/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php b/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php index f85ed9c8..1a08d72b 100644 --- a/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php +++ b/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php @@ -30,7 +30,7 @@ use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; /** * Class ClientAdapter @@ -45,7 +45,7 @@ interface ClientAdapterInterface * @throws SPException * @throws ServiceException */ - public function includeCustomFields(Client $data, CustomFieldService $customFieldService): Collection; + public function includeCustomFields(Client $data, CustomFieldDataService $customFieldService): Collection; public function transform(Client $data): array; } diff --git a/lib/SP/Domain/Core/Exceptions/SPException.php b/lib/SP/Domain/Core/Exceptions/SPException.php index 94fb1125..241f9cd4 100644 --- a/lib/SP/Domain/Core/Exceptions/SPException.php +++ b/lib/SP/Domain/Core/Exceptions/SPException.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,6 +25,7 @@ namespace SP\Domain\Core\Exceptions; use Exception; +use Throwable; /** * Extender la clase Exception para mostrar ayuda en los mensajes @@ -36,9 +37,6 @@ class SPException extends Exception public const ERROR = 3; public const INFO = 4; - protected int $type; - protected ?string $hint; - /** * SPException constructor. * @@ -49,18 +47,20 @@ class SPException extends Exception * @param Exception|null $previous */ public function __construct( - string $message, - int $type = self::ERROR, - ?string $hint = null, - int $code = 0, - Exception $previous = null + string $message, + protected int $type = self::ERROR, + protected ?string $hint = null, + int $code = 0, + Exception $previous = null ) { - $this->type = $type; - $this->hint = $hint; - parent::__construct($message, $code, $previous); } + public static function from(Throwable $throwable, Type $type = Type::ERROR): static + { + return new static($throwable->getMessage(), $type->value, null, $throwable->getCode(), $throwable); + } + public static function error( string $message, ?string $hint = null, diff --git a/lib/SP/Domain/Core/Exceptions/Type.php b/lib/SP/Domain/Core/Exceptions/Type.php new file mode 100644 index 00000000..0f409435 --- /dev/null +++ b/lib/SP/Domain/Core/Exceptions/Type.php @@ -0,0 +1,36 @@ +. + */ + +namespace SP\Domain\Core\Exceptions; + +/** + * Enum Type + */ +enum Type: int +{ + case CRITICAL = 1; + case WARNING = 2; + case ERROR = 3; + case INFO = 4; +} diff --git a/lib/SP/Domain/CustomField/Models/CustomFieldData.php b/lib/SP/Domain/CustomField/Models/CustomFieldData.php index 58e6ae36..9a390308 100644 --- a/lib/SP/Domain/CustomField/Models/CustomFieldData.php +++ b/lib/SP/Domain/CustomField/Models/CustomFieldData.php @@ -31,18 +31,12 @@ use SP\Domain\Common\Models\Model; */ class CustomFieldData extends Model { - protected ?int $id = null; protected ?int $moduleId = null; protected ?int $itemId = null; protected ?int $definitionId = null; protected ?string $data = null; protected ?string $key = null; - public function getId(): ?int - { - return $this->id; - } - public function getModuleId(): ?int { return $this->moduleId; diff --git a/lib/SP/Domain/CustomField/Ports/CustomFieldDataService.php b/lib/SP/Domain/CustomField/Ports/CustomFieldDataService.php new file mode 100644 index 00000000..ba1c454a --- /dev/null +++ b/lib/SP/Domain/CustomField/Ports/CustomFieldDataService.php @@ -0,0 +1,91 @@ +. + */ + +namespace SP\Domain\CustomField\Ports; + +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\CustomField\Models\CustomFieldData; +use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; + +/** + * Class CustomFieldService + * + * @template T of CustomFieldDataModel + */ +interface CustomFieldDataService +{ + /** + * Desencriptar y formatear los datos del campo + * + * @throws ServiceException + */ + public function decrypt(string $data, string $key): ?string; + + /** + * Returns the module's item for given id + * + * @throws ServiceException + */ + public function getBy(int $moduleId, ?int $itemId): array; + + /** + * Updates an item + * + * @throws ServiceException + */ + public function updateOrCreate(CustomFieldData $customFieldData): void; + + /** + * Eliminar los datos de los campos personalizados del módulo + * + * @throws ServiceException + */ + public function delete(array $itemsId, int $moduleId): void; + + /** + * Creates an item + * + * @throws ServiceException + */ + public function create(CustomFieldData $customFieldData): void; + + /** + * Update data using the given masterpass + * + * @throws ServiceException + */ + public function updateMasterPass(CustomFieldData $customFieldData, string $masterPass): int; + + /** + * @return array + * @throws ServiceException + */ + public function getAll(): array; + + /** + * @return array + * @throws ServiceException + */ + public function getAllEncrypted(): array; +} diff --git a/lib/SP/Domain/CustomField/Ports/CustomFieldService.php b/lib/SP/Domain/CustomField/Ports/CustomFieldService.php deleted file mode 100644 index 6d973a64..00000000 --- a/lib/SP/Domain/CustomField/Ports/CustomFieldService.php +++ /dev/null @@ -1,129 +0,0 @@ -. - */ - -namespace SP\Domain\CustomField\Ports; - -use Defuse\Crypto\Exception\CryptoException; -use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Core\Exceptions\ConstraintException; -use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Models\CustomFieldData; -use SP\Infrastructure\Common\Repositories\NoSuchItemException; - -/** - * Class CustomFieldService - * - * @package SP\Domain\CustomField\Services - */ -interface CustomFieldService -{ - /** - * Desencriptar y formatear los datos del campo - * - * @throws CryptoException - * @throws ServiceException - */ - public function decryptData(string $data, string $key): string; - - /** - * Returns the module's item for given id - * - * @throws ConstraintException - * @throws QueryException - */ - public function getForModuleAndItemId(int $moduleId, ?int $itemId): array; - - /** - * Updates an item - * - * @throws CryptoException - * @throws QueryException - * @throws ConstraintException - * @throws SPException - */ - public function updateOrCreateData(CustomFieldData $customFieldData): bool; - - /** - * Eliminar los datos de los campos personalizados del módulo - * - * @throws SPException - */ - public function deleteCustomFieldData(int $itemId, int $moduleId, ?int $definitionId = null): int; - - /** - * Creates an item - * - * @throws CryptoException - * @throws QueryException - * @throws ServiceException - * @throws ConstraintException - * @throws NoSuchItemException - */ - public function create(CustomFieldData $customFieldData): bool; - - /** - * Eliminar los datos de los campos personalizados del módulo - * - * @throws QueryException - * @throws ConstraintException - */ - public function deleteCustomFieldDefinitionData(int $definitionId): int; - - /** - * Eliminar los datos de los campos personalizados del módulo - * - * @param int[] $ids - * @param int $moduleId - * - * @return bool - * @throws QueryException - * @throws ConstraintException - */ - public function deleteCustomFieldDataBatch(array $ids, int $moduleId): bool; - - /** - * Updates an item - * - * @throws CryptoException - * @throws ConstraintException - * @throws QueryException - * @throws ServiceException - */ - public function updateMasterPass(CustomFieldData $customFieldData, string $masterPass): int; - - /** - * @return CustomFieldData[] - * @throws QueryException - * @throws ConstraintException - */ - public function getAll(): array; - - /** - * @return CustomFieldData[] - * @throws QueryException - * @throws ConstraintException - */ - public function getAllEncrypted(): array; -} diff --git a/lib/SP/Domain/CustomField/Services/CustomField.php b/lib/SP/Domain/CustomField/Services/CustomField.php deleted file mode 100644 index 7db80b57..00000000 --- a/lib/SP/Domain/CustomField/Services/CustomField.php +++ /dev/null @@ -1,260 +0,0 @@ -. - */ - -namespace SP\Domain\CustomField\Services; - -use Defuse\Crypto\Exception\CryptoException; -use SP\Core\Application; -use SP\Core\Crypt\Crypt; -use SP\Domain\Common\Services\Service; -use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Core\Exceptions\ConstraintException; -use SP\Domain\Core\Exceptions\CryptException; -use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Models\CustomFieldData; -use SP\Domain\CustomField\Ports\CustomFieldDataRepository; -use SP\Domain\CustomField\Ports\CustomFieldDefinitionRepository; -use SP\Domain\CustomField\Ports\CustomFieldService; -use SP\Infrastructure\Common\Repositories\NoSuchItemException; - -/** - * Class CustomFieldService - * - * @package SP\Domain\CustomField\Services - */ -final class CustomField extends Service implements CustomFieldService -{ - - public function __construct( - Application $application, - private readonly CustomFieldDataRepository $customFieldDataRepository, - private readonly CustomFieldDefinitionRepository $customFieldDefRepository - ) { - parent::__construct($application); - } - - /** - * Returns the form Id for a given name - */ - public static function getFormIdForName(string $name): string - { - return sprintf('cf_%s', strtolower(preg_replace('/\W*/', '', $name))); - } - - /** - * Desencriptar y formatear los datos del campo - * - * @param string $data - * @param string $key - * @return string - * @throws ServiceException - * @throws CryptException - */ - public function decryptData(string $data, string $key): string - { - if (!empty($data) && !empty($key)) { - return self::formatValue(Crypt::decrypt($data, $key, $this->getMasterKeyFromContext())); - } - - return ''; - } - - /** - * Formatear el valor del campo - * - * @param $value string El valor del campo - * - * @return string - */ - public static function formatValue(string $value): string - { - if (preg_match('#https?://#', $value)) { - return sprintf('%s', $value, $value); - } - - return $value; - } - - /** - * Returns the module's item for given id - * - * @throws ConstraintException - * @throws QueryException - * @throws SPException - */ - public function getForModuleAndItemId(int $moduleId, ?int $itemId): array - { - return $this->customFieldDataRepository->getForModuleAndItemId($moduleId, $itemId)->getDataAsArray(); - } - - /** - * Updates an item - * - * @throws CryptoException - * @throws QueryException - * @throws ConstraintException - * @throws SPException - */ - public function updateOrCreateData(CustomFieldData $customFieldData): bool - { - $exists = $this->customFieldDataRepository->checkExists($customFieldData); - - // Deletes item's custom field data if value is left blank - if ($exists && empty($customFieldData->getData())) { - return $this->deleteCustomFieldData( - $customFieldData->getId(), - $customFieldData->getModuleId(), - $customFieldData->getDefinitionId() - ) === 1; - } - - // Create item's custom field data if value is set - if (!$exists) { - return $this->create($customFieldData); - } - - if ($this->customFieldDefRepository->getById($customFieldData->getDefinitionId())->getIsEncrypted()) { - $this->setSecureData($customFieldData); - } - - return $this->customFieldDataRepository->update($customFieldData) === 1; - } - - /** - * Eliminar los datos de los campos personalizados del módulo - * - * @throws SPException - */ - public function deleteCustomFieldData(int $itemId, int $moduleId, ?int $definitionId = null): int - { - if ($definitionId === null) { - return $this->customFieldDataRepository->deleteCustomFieldData($itemId, $moduleId); - } - - return $this->customFieldDataRepository->deleteByItemAndModuleAndDefinition($itemId, $moduleId, $definitionId); - } - - /** - * Creates an item - * - * @throws CryptoException - * @throws QueryException - * @throws ServiceException - * @throws ConstraintException - * @throws NoSuchItemException - */ - public function create(CustomFieldData $customFieldData): bool - { - if (empty($customFieldData->getData())) { - return true; - } - - if ($this->customFieldDefRepository->getById($customFieldData->getDefinitionId())->getIsEncrypted()) { - $this->setSecureData($customFieldData); - } - - return $this->customFieldDataRepository->create($customFieldData) > 0; - } - - /** - * @throws CryptoException - * @throws ServiceException - */ - protected function setSecureData(CustomFieldData $customFieldData, ?string $key = null): void - { - $key = $key ?: $this->getMasterKeyFromContext(); - $securedKey = Crypt::makeSecuredKey($key); - - if (strlen($securedKey) > 1000) { - throw new ServiceException(__u('Internal error'), SPException::ERROR); - } - - $customFieldData->setData(Crypt::encrypt($customFieldData->getData(), $securedKey, $key)); - $customFieldData->setKey($securedKey); - } - - /** - * Eliminar los datos de los campos personalizados del módulo - * - * @throws QueryException - * @throws ConstraintException - */ - public function deleteCustomFieldDefinitionData(int $definitionId): int - { - return $this->customFieldDataRepository->deleteByDefinition($definitionId); - } - - /** - * Eliminar los datos de los campos personalizados del módulo - * - * @param int[] $ids - * @param int $moduleId - * - * @return bool - * @throws QueryException - * @throws ConstraintException - */ - public function deleteCustomFieldDataBatch(array $ids, int $moduleId): bool - { - return $this->customFieldDataRepository->deleteBatch($ids, $moduleId); - } - - /** - * Updates an item - * - * @param CustomFieldData $customFieldData - * @param string $masterPass - * - * @return int - * @throws CryptoException - * @throws ServiceException - */ - public function updateMasterPass(CustomFieldData $customFieldData, string $masterPass): int - { - $this->setSecureData($customFieldData, $masterPass); - - return $this->customFieldDataRepository->update($customFieldData); - } - - /** - * @return CustomFieldData[] - * @throws QueryException - * @throws ConstraintException - */ - public function getAll(): array - { - return $this->customFieldDataRepository->getAll()->getDataAsArray(); - } - - /** - * @return CustomFieldData[] - * @throws QueryException - * @throws ConstraintException - */ - public function getAllEncrypted(): array - { - return $this->customFieldDataRepository->getAllEncrypted()->getDataAsArray(); - } -} diff --git a/lib/SP/Domain/CustomField/Services/CustomFieldCrypt.php b/lib/SP/Domain/CustomField/Services/CustomFieldCrypt.php index 9a5b77e2..38ba580e 100644 --- a/lib/SP/Domain/CustomField/Services/CustomFieldCrypt.php +++ b/lib/SP/Domain/CustomField/Services/CustomFieldCrypt.php @@ -31,12 +31,10 @@ use SP\Core\Events\EventMessage; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Crypt\CryptInterface; -use SP\Domain\Core\Exceptions\ConstraintException; -use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; use SP\Domain\CustomField\Ports\CustomFieldCryptService; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\Task\Services\TaskFactory; use function SP\__; @@ -49,9 +47,9 @@ use function SP\processException; final class CustomFieldCrypt extends Service implements CustomFieldCryptService { public function __construct( - Application $application, - private readonly CustomFieldService $customFieldService, - private readonly CryptInterface $crypt + Application $application, + private readonly CustomFieldDataService $customFieldService, + private readonly CryptInterface $crypt ) { parent::__construct($application); } @@ -87,8 +85,9 @@ final class CustomFieldCrypt extends Service implements CustomFieldCryptService } /** - * @throws ConstraintException - * @throws QueryException + * @param UpdateMasterPassRequest $request + * @param callable $decryptor + * @throws ServiceException */ private function processUpdateMasterPassword(UpdateMasterPassRequest $request, callable $decryptor): void { @@ -140,13 +139,13 @@ final class CustomFieldCrypt extends Service implements CustomFieldCryptService $request->getNewMasterPass() ); - $success[] = $customFieldData->getId(); + $success[] = $customFieldData->getItemId(); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); - $errors[] = $customFieldData->getId(); + $errors[] = $customFieldData->getItemId(); } } diff --git a/lib/SP/Domain/CustomField/Services/CustomFieldData.php b/lib/SP/Domain/CustomField/Services/CustomFieldData.php new file mode 100644 index 00000000..3783e1bf --- /dev/null +++ b/lib/SP/Domain/CustomField/Services/CustomFieldData.php @@ -0,0 +1,220 @@ +. + */ + +namespace SP\Domain\CustomField\Services; + +use Exception; +use SP\Core\Application; +use SP\Domain\Common\Services\Service; +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Core\Crypt\CryptInterface; +use SP\Domain\Core\Exceptions\CryptException; +use SP\Domain\Core\Exceptions\SPException; +use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; +use SP\Domain\CustomField\Models\CustomFieldDefinition as CustomFieldDefinitionModel; +use SP\Domain\CustomField\Ports\CustomFieldDataRepository; +use SP\Domain\CustomField\Ports\CustomFieldDataService; +use SP\Domain\CustomField\Ports\CustomFieldDefinitionRepository; + +use function SP\__u; + +/** + * Class CustomFieldService + * + * @template T of CustomFieldDataModel + */ +final class CustomFieldData extends Service implements CustomFieldDataService +{ + + public function __construct( + Application $application, + private readonly CustomFieldDataRepository $customFieldDataRepository, + private readonly CustomFieldDefinitionRepository $customFieldDefinitionRepository, + private readonly CryptInterface $crypt + ) { + parent::__construct($application); + } + + /** + * Decrypt custom field's data + * + * @throws ServiceException + */ + public function decrypt(string $data, string $key): ?string + { + if (!empty($data) && !empty($key)) { + try { + return $this->crypt->decrypt($data, $key, $this->getMasterKeyFromContext()); + } catch (CryptException $e) { + throw ServiceException::from($e); + } + } + + return null; + } + + + /** + * Returns the data given module and item's id + * + * @throws ServiceException + */ + public function getBy(int $moduleId, ?int $itemId): array + { + try { + return $this->customFieldDataRepository->getForModuleAndItemId($moduleId, $itemId)->getDataAsArray(); + } catch (Exception $e) { + throw ServiceException::from($e); + } + } + + /** + * Updates an item + * + * @throws ServiceException + */ + public function updateOrCreate(CustomFieldDataModel $customFieldData): void + { + try { + $exists = $this->customFieldDataRepository->checkExists( + $customFieldData->getItemId(), + $customFieldData->getModuleId(), + $customFieldData->getDefinitionId() + ); + + if (!$exists) { + $this->create($customFieldData); + return; + } + + $data = $this->isEncrypted($customFieldData) ? $this->buildSecureData($customFieldData) : $customFieldData; + + $this->customFieldDataRepository->update($data); + } catch (SPException $e) { + throw ServiceException::from($e); + } + } + + /** + * Creates an item + * + * @throws ServiceException + */ + public function create(CustomFieldDataModel $customFieldData): void + { + try { + $data = $this->isEncrypted($customFieldData) ? $this->buildSecureData($customFieldData) : $customFieldData; + + $this->customFieldDataRepository->create($data)->getLastId(); + } catch (SPException $e) { + throw ServiceException::from($e); + } + } + + /** + * @param CustomFieldDataModel $customFieldData + * @return int|null + */ + private function isEncrypted(CustomFieldDataModel $customFieldData): ?int + { + return $this->customFieldDefinitionRepository + ->getById($customFieldData->getDefinitionId()) + ->getData(CustomFieldDefinitionModel::class) + ->getIsEncrypted(); + } + + /** + * @param CustomFieldDataModel $customFieldData + * @param string|null $key + * @return CustomFieldDataModel + * @throws CryptException + * @throws ServiceException + */ + private function buildSecureData(CustomFieldDataModel $customFieldData, ?string $key = null): CustomFieldDataModel + { + $key = $key ?: $this->getMasterKeyFromContext(); + $securedKey = $this->crypt->makeSecuredKey($key); + + if (strlen($securedKey) > 1000) { + throw ServiceException::error(__u('Internal error')); + } + + return $customFieldData->mutate( + [ + 'data' => $this->crypt->encrypt($customFieldData->getData(), $securedKey, $key), + 'key' => $securedKey + ] + ); + } + + /** + * Delete custom field's data + * + * @param array $itemsId + * @param int $moduleId + * @throws ServiceException + */ + public function delete(array $itemsId, int $moduleId): void + { + try { + $this->customFieldDataRepository->deleteBatch($itemsId, $moduleId); + } catch (SPException $e) { + throw ServiceException::from($e); + } + } + + /** + * Updates an item + * + * @param CustomFieldDataModel $customFieldData + * @param string $masterPass + * + * @return int + * @throws ServiceException + */ + public function updateMasterPass(CustomFieldDataModel $customFieldData, string $masterPass): int + { + try { + return $this->customFieldDataRepository->update($this->buildSecureData($customFieldData, $masterPass)); + } catch (SPException $e) { + throw ServiceException::from($e); + } + } + + /** + * @return array + */ + public function getAll(): array + { + return $this->customFieldDataRepository->getAll()->getDataAsArray(CustomFieldDataModel::class); + } + + /** + * @return array + */ + public function getAllEncrypted(): array + { + return $this->customFieldDataRepository->getAllEncrypted()->getDataAsArray(CustomFieldDataModel::class); + } +} diff --git a/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php b/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php index 5c7d45d6..d9ced2f8 100644 --- a/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php +++ b/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php @@ -31,7 +31,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Common\Services\Service; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\CustomField\Ports\UpgradeCustomFieldDataServiceInterface; use SP\Infrastructure\Database\DatabaseInterface; use SP\Infrastructure\Database\QueryData; @@ -44,13 +44,13 @@ use SP\Infrastructure\Database\QueryData; final class UpgradeCustomFieldDataService extends Service implements UpgradeCustomFieldDataServiceInterface { - private CustomFieldService $customFieldService; - private DatabaseInterface $database; + private CustomFieldDataService $customFieldService; + private DatabaseInterface $database; public function __construct( - Application $application, - CustomFieldService $customFieldService, - DatabaseInterface $database + Application $application, + CustomFieldDataService $customFieldService, + DatabaseInterface $database ) { parent::__construct($application); diff --git a/lib/SP/Infrastructure/Database/QueryResult.php b/lib/SP/Infrastructure/Database/QueryResult.php index db722110..9de0e17d 100644 --- a/lib/SP/Infrastructure/Database/QueryResult.php +++ b/lib/SP/Infrastructure/Database/QueryResult.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,8 @@ namespace SP\Infrastructure\Database; use SP\Domain\Common\Models\Model; -use SP\Domain\Core\Exceptions\SPException; +use SplFixedArray; +use TypeError; use function SP\__u; @@ -36,16 +37,12 @@ use function SP\__u; */ class QueryResult { - private ?array $data = null; - /** - * @var class-string|null $dataType - */ - private ?string $dataType = null; - private int $numRows = 0; - private int $totalNumRows = 0; - private int $affectedNumRows = 0; - private int $statusCode = 0; - private int $lastId = 0; + private readonly SplFixedArray $data; + private readonly int $numRows; + private int $totalNumRows = 0; + private int $affectedNumRows = 0; + private int $statusCode = 0; + private int $lastId = 0; /** * QueryResult constructor. @@ -55,12 +52,11 @@ class QueryResult public function __construct(?array $data = null) { if (null !== $data) { - $this->data = $data; - $this->numRows = count($data); - - if ($this->numRows > 0 && is_object($data[0])) { - $this->dataType = get_class($data[0]); - } + $this->data = SplFixedArray::fromArray($data); + $this->numRows = $this->data->count(); + } else { + $this->data = new SplFixedArray(); + $this->numRows = 0; } } @@ -77,24 +73,29 @@ class QueryResult /** * @param class-string|null $dataType * @return T - * @throws SPException */ public function getData(?string $dataType = null): ?Model { - $this->checkDataType($dataType); + if ($dataType) { + $this->checkDataType($dataType); + } - return $this->numRows === 1 ? $this->data[0] : null; + return $this->numRows === 1 ? $this->data->offsetGet(0) : null; } /** - * @param string|null $dataType + * @param string $dataType * @return void - * @throws SPException */ - private function checkDataType(?string $dataType = null): void + private function checkDataType(string $dataType): void { - if (null !== $dataType && $this->dataType !== null && $dataType !== $this->dataType) { - throw new SPException(sprintf(__u('Invalid data\'s type: %s - Current: %s'), $dataType, $this->dataType)); + if ($this->numRows > 0 + && (!is_object($this->data->offsetGet(0)) + || !is_a($this->data->offsetGet(0), $dataType)) + ) { + throw new TypeError( + sprintf(__u('Invalid data\'s type. Expected: %s'), $dataType) + ); } } @@ -102,13 +103,14 @@ class QueryResult * @param class-string|null $dataType * * @return T[] - * @throws SPException */ public function getDataAsArray(?string $dataType = null): array { - $this->checkDataType($dataType); + if ($dataType) { + $this->checkDataType($dataType); + } - return $this->data ?? []; + return $this->data->toArray(); } public function getNumRows(): int @@ -123,9 +125,10 @@ class QueryResult public function setTotalNumRows(int $totalNumRows): QueryResult { - $this->totalNumRows = $totalNumRows; + $self = clone $this; + $self->totalNumRows = $totalNumRows; - return $this; + return $self; } public function getStatusCode(): int @@ -140,9 +143,10 @@ class QueryResult public function setAffectedNumRows(int $affectedNumRows): QueryResult { - $this->affectedNumRows = $affectedNumRows; + $self = clone $this; + $self->affectedNumRows = $affectedNumRows; - return $this; + return $self; } public function getLastId(): int @@ -152,8 +156,9 @@ class QueryResult public function setLastId(int $lastId): QueryResult { - $this->lastId = $lastId; + $self = clone $this; + $self->lastId = $lastId; - return $this; + return $self; } } diff --git a/lib/SP/Mvc/Controller/ItemTrait.php b/lib/SP/Mvc/Controller/ItemTrait.php index a0526610..dd8510af 100644 --- a/lib/SP/Mvc/Controller/ItemTrait.php +++ b/lib/SP/Mvc/Controller/ItemTrait.php @@ -24,22 +24,15 @@ namespace SP\Mvc\Controller; -use Defuse\Crypto\Exception\CryptoException; use SP\DataModel\ItemSearchData; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Core\Exceptions\ConstraintException; -use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Models\CustomFieldData; -use SP\Domain\CustomField\Ports\CustomFieldService; -use SP\Domain\CustomField\Services\CustomField; +use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\CustomField\Services\CustomFieldItem; use SP\Domain\Http\RequestInterface; -use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Util\Filter; -use function SP\__u; - /** * Trait ItemTrait */ @@ -48,85 +41,103 @@ trait ItemTrait /** * Obtener la lista de campos personalizados y sus valores * - * @throws ConstraintException - * @throws QueryException * @throws SPException * @throws ServiceException */ protected function getCustomFieldsForItem( - int $moduleId, - ?int $itemId, - CustomFieldService $customFieldService + int $moduleId, + ?int $itemId, + CustomFieldDataService $customFieldDataService ): array { $customFields = []; - foreach ($customFieldService->getForModuleAndItemId($moduleId, $itemId) as $item) { - try { - $customField = new CustomFieldItem(); - $customField->required = (bool)$item['required']; - $customField->showInList = (bool)$item['showInList']; - $customField->help = $item['help']; - $customField->definitionId = (int)$item['definitionId']; - $customField->definitionName = $item['definitionName']; - $customField->typeId = (int)$item['typeId']; - $customField->typeName = $item['typeName']; - $customField->typeText = $item['typeText']; - $customField->moduleId = (int)$item['moduleId']; - $customField->formId = CustomField::getFormIdForName($item['definitionName']); - $customField->isEncrypted = (int)$item['isEncrypted']; + foreach ($customFieldDataService->getBy($moduleId, $itemId) as $item) { + $customField = new CustomFieldItem(); + $customField->required = (bool)$item['required']; + $customField->showInList = (bool)$item['showInList']; + $customField->help = $item['help']; + $customField->definitionId = (int)$item['definitionId']; + $customField->definitionName = $item['definitionName']; + $customField->typeId = (int)$item['typeId']; + $customField->typeName = $item['typeName']; + $customField->typeText = $item['typeText']; + $customField->moduleId = (int)$item['moduleId']; + $customField->formId = self::getFormIdForName($item['definitionName']); + $customField->isEncrypted = (int)$item['isEncrypted']; - if (!empty($item['data']) && !empty($item['key'])) { - $customField->isValueEncrypted = true; - $customField->value = $customFieldService->decryptData($item['data'], $item['key']); - } else { - $customField->isValueEncrypted = false; - $customField->value = $item['data']; - } - - $customFields[] = $customField; - } catch (CryptoException $e) { - throw new SPException(__u('Internal error'), SPException::ERROR, null, 0, $e); + if (!empty($item['data']) && !empty($item['key'])) { + $customField->isValueEncrypted = true; + $customField->value = self::formatValue( + $customFieldDataService->decrypt($item['data'], $item['key']) ?? '' + ); + } else { + $customField->isValueEncrypted = false; + $customField->value = $item['data']; } + + $customFields[] = $customField; } return $customFields; } + /** + * Returns the form Id for a given name + */ + private static function getFormIdForName(string $name): string + { + return sprintf('cf_%s', strtolower(preg_replace('/\W*/', '', $name))); + } + + /** + * Formatear el valor del campo + * + * @param $value string El valor del campo + * + * @return string + */ + private static function formatValue(string $value): string + { + if (preg_match('#https?://#', $value)) { + return sprintf('%s', $value, $value); + } + + return $value; + } + /** * Añadir los campos personalizados del elemento * - * @param int $moduleId - * @param int|int[] $itemId + * @param int $moduleId + * @param int|int[] $itemId * @param RequestInterface $request - * @param CustomFieldService $customFieldService + * @param CustomFieldDataService $customFieldDataService * - * @throws ConstraintException - * @throws QueryException * @throws SPException * @throws ServiceException - * @throws NoSuchItemException */ protected function addCustomFieldsForItem( - int $moduleId, - int|array $itemId, - RequestInterface $request, - CustomFieldService $customFieldService + int $moduleId, + int|array $itemId, + RequestInterface $request, + CustomFieldDataService $customFieldDataService ): void { $customFields = self::getCustomFieldsFromRequest($request); if (!empty($customFields)) { - try { - foreach ($customFields as $id => $value) { - $customFieldData = new CustomFieldData(); - $customFieldData->setItemId($itemId); - $customFieldData->setModuleId($moduleId); - $customFieldData->setDefinitionId($id); - $customFieldData->setData($value); + foreach ($customFields as $id => $value) { + $customFieldData = new CustomFieldDataModel( + [ + 'itemId' => $itemId, + 'moduleId' => $moduleId, + 'definitionId' => $id, + 'data' => $value + ] + ); - $customFieldService->create($customFieldData); + if (!empty($customFieldData->getData())) { + $customFieldDataService->create($customFieldData); } - } catch (CryptoException $e) { - throw new SPException(__u('Internal error'), SPException::ERROR, null, 0, $e); } } } @@ -140,68 +151,62 @@ trait ItemTrait { return $request->analyzeArray( 'customfield', - fn($values) => array_map(static fn($value) => Filter::getString($value), $values) + static fn($values) => array_map(static fn($value) => Filter::getString($value), $values) ); } /** * Eliminar los campos personalizados del elemento * - * @param int $moduleId - * @param int|int[] $itemId - * @param CustomFieldService $customFieldService + * @param int $moduleId + * @param int|int[] $itemId + * @param CustomFieldDataService $customFieldService * - * @throws ConstraintException - * @throws QueryException - * @throws SPException + * @throws ServiceException */ protected function deleteCustomFieldsForItem( - int $moduleId, - array|int $itemId, - CustomFieldService $customFieldService + int $moduleId, + array|int $itemId, + CustomFieldDataService $customFieldService ): void { - if (is_array($itemId)) { - $customFieldService->deleteCustomFieldDataBatch($itemId, $moduleId); - } else { - $customFieldService->deleteCustomFieldData($itemId, $moduleId); - } + $customFieldService->delete($itemId, $moduleId); } /** * Actualizar los campos personalizados del elemento * - * @param int $moduleId - * @param int|int[] $itemId + * @param int $moduleId + * @param int|int[] $itemId * @param RequestInterface $request - * @param CustomFieldService $customFieldService + * @param CustomFieldDataService $customFieldDataService * - * @throws ConstraintException - * @throws QueryException + * @throws ServiceException * @throws SPException */ protected function updateCustomFieldsForItem( - int $moduleId, - int|array $itemId, - RequestInterface $request, - CustomFieldService $customFieldService + int $moduleId, + int|array $itemId, + RequestInterface $request, + CustomFieldDataService $customFieldDataService ): void { $customFields = self::getCustomFieldsFromRequest($request); if (!empty($customFields)) { - try { - foreach ($customFields as $id => $value) { - $customFieldData = new CustomFieldData(); - $customFieldData->setItemId($itemId); - $customFieldData->setModuleId($moduleId); - $customFieldData->setDefinitionId($id); - $customFieldData->setData($value); + foreach ($customFields as $id => $value) { + $customFieldData = new CustomFieldDataModel( + [ + 'itemId' => $itemId, + 'moduleId' => $moduleId, + 'definitionId' => $id, + 'data' => $value + ] + ); - if ($customFieldService->updateOrCreateData($customFieldData) === false) { - throw new SPException(__u('Error while updating custom field\'s data')); - } + if (empty($customFieldData->getData())) { + $customFieldDataService->delete([$itemId], $moduleId); + } else { + $customFieldDataService->updateOrCreate($customFieldData); } - } catch (CryptoException $e) { - throw new SPException(__u('Internal error'), SPException::ERROR, null, 0, $e); } } } @@ -222,4 +227,8 @@ trait ItemTrait { return $request->analyzeArray('items'); } + + private function processCustomFields(callable $action) + { + } } diff --git a/schemas/40024210101.sql b/schemas/40024210101.sql new file mode 100644 index 00000000..ebf10ea6 --- /dev/null +++ b/schemas/40024210101.sql @@ -0,0 +1,28 @@ +/* + * sysPass + * + * @author nuxsmin + * @link https://syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org + * + * This file is part of sysPass. + * + * sysPass is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * sysPass is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with sysPass. If not, see . + */ + +alter table CustomFieldData + drop column id; + +alter table CustomFieldData + add primary key (moduleId, itemId, definitionId); diff --git a/schemas/dbstructure.sql b/schemas/dbstructure.sql index ef7ba7ed..e1947fe4 100644 --- a/schemas/dbstructure.sql +++ b/schemas/dbstructure.sql @@ -1,728 +1,823 @@ +/* + * sysPass + * + * @author nuxsmin + * @link https://syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org + * + * This file is part of sysPass. + * + * sysPass is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * sysPass is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with sysPass. If not, see . + */ + /*!40101 SET @OLD_CHARACTER_SET_CLIENT = @@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS = @@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION = @@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; +/*!40101 SET NAMES utf8mb4 */; /*!40103 SET @OLD_TIME_ZONE = @@TIME_ZONE */; /*!40103 SET TIME_ZONE = '+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS = @@UNIQUE_CHECKS, UNIQUE_CHECKS = 0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS = @@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS = 0 */; /*!40101 SET @OLD_SQL_MODE = @@SQL_MODE, SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES = @@SQL_NOTES, SQL_NOTES = 0 */; + +-- +-- Table structure for table `Account` +-- + DROP TABLE IF EXISTS `Account`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Account` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `userGroupId` smallint(5) unsigned NOT NULL, - `userId` smallint(5) unsigned NOT NULL, - `userEditId` smallint(5) unsigned NOT NULL, - `clientId` mediumint(8) unsigned NOT NULL, - `name` varchar(100) NOT NULL, - `categoryId` mediumint(8) unsigned NOT NULL, - `login` varchar(50) DEFAULT NULL, - `url` varchar(255) DEFAULT NULL, - `pass` varbinary(2000) NOT NULL, - `key` varbinary(2000) NOT NULL, - `notes` text DEFAULT NULL, - `countView` int(10) unsigned NOT NULL DEFAULT 0, - `countDecrypt` int(10) unsigned NOT NULL DEFAULT 0, - `dateAdd` datetime NOT NULL, - `dateEdit` datetime DEFAULT NULL, - `otherUserGroupEdit` tinyint(1) DEFAULT 0, - `otherUserEdit` tinyint(1) DEFAULT 0, - `isPrivate` tinyint(1) DEFAULT 0, - `isPrivateGroup` tinyint(1) DEFAULT 0, - `passDate` int(11) unsigned DEFAULT NULL, - `passDateChange` int(11) unsigned DEFAULT NULL, - `parentId` mediumint(8) unsigned DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_Account_01` (`categoryId`), - KEY `idx_Account_02` (`userGroupId`, `userId`), - KEY `idx_Account_03` (`clientId`), - KEY `idx_Account_04` (`parentId`), - KEY `fk_Account_userId` (`userId`), - KEY `fk_Account_userEditId` (`userEditId`), - CONSTRAINT `fk_Account_categoryId` FOREIGN KEY (`categoryId`) REFERENCES `Category` (`id`), - CONSTRAINT `fk_Account_clientId` FOREIGN KEY (`clientId`) REFERENCES `Client` (`id`), - CONSTRAINT `fk_Account_userEditId` FOREIGN KEY (`userEditId`) REFERENCES `User` (`id`), - CONSTRAINT `fk_Account_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`), - CONSTRAINT `fk_Account_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `ItemPreset`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `ItemPreset` -( - `id` int NOT NULL AUTO_INCREMENT, - `type` varchar(25) not null, - `userId` smallint(5) unsigned, - `userGroupId` smallint(5) unsigned, - `userProfileId` smallint(5) unsigned, - `fixed` tinyint(1) unsigned DEFAULT 0 NOT NULL, - `priority` tinyint(3) unsigned DEFAULT 0 NOT NULL, - `data` blob, - `hash` varbinary(40) NOT NULL, - UNIQUE INDEX `uk_ItemPreset_01` (`hash`), - CONSTRAINT `fk_ItemPreset_userId` - FOREIGN KEY (`userId`) REFERENCES `User` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - CONSTRAINT `fk_ItemPreset_userGroupId` - FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - CONSTRAINT `fk_ItemPreset_userProfileId` - FOREIGN KEY (`userProfileId`) REFERENCES `UserProfile` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `userGroupId` smallint(5) unsigned NOT NULL, + `userId` smallint(5) unsigned NOT NULL, + `userEditId` smallint(5) unsigned NOT NULL, + `clientId` mediumint(8) unsigned NOT NULL, + `name` varchar(100) NOT NULL, + `categoryId` mediumint(8) unsigned NOT NULL, + `login` varchar(50) DEFAULT NULL, + `url` varchar(255) DEFAULT NULL, + `pass` varbinary(2000) NOT NULL, + `key` varbinary(2000) NOT NULL, + `notes` text DEFAULT NULL, + `countView` int(10) unsigned NOT NULL DEFAULT 0, + `countDecrypt` int(10) unsigned NOT NULL DEFAULT 0, + `dateAdd` datetime NOT NULL, + `dateEdit` datetime DEFAULT NULL, + `otherUserGroupEdit` tinyint(1) DEFAULT 0, + `otherUserEdit` tinyint(1) DEFAULT 0, + `isPrivate` tinyint(1) DEFAULT 0, + `isPrivateGroup` tinyint(1) DEFAULT 0, + `passDate` int(11) unsigned DEFAULT NULL, + `passDateChange` int(11) unsigned DEFAULT NULL, + `parentId` mediumint(8) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `idx_Account_01` (`categoryId`), + KEY `idx_Account_02` (`userGroupId`, `userId`), + KEY `idx_Account_03` (`clientId`), + KEY `idx_Account_04` (`parentId`), + KEY `fk_Account_userId` (`userId`), + KEY `fk_Account_userEditId` (`userEditId`), + CONSTRAINT `fk_Account_categoryId` FOREIGN KEY (`categoryId`) REFERENCES `Category` (`id`), + CONSTRAINT `fk_Account_clientId` FOREIGN KEY (`clientId`) REFERENCES `Client` (`id`), + CONSTRAINT `fk_Account_userEditId` FOREIGN KEY (`userEditId`) REFERENCES `User` (`id`), + CONSTRAINT `fk_Account_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`), + CONSTRAINT `fk_Account_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `AccountFile` +-- + DROP TABLE IF EXISTS `AccountFile`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `AccountFile` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `accountId` mediumint(5) unsigned NOT NULL, - `name` varchar(100) NOT NULL, - `type` varchar(100) NOT NULL, - `size` int(11) NOT NULL, - `content` mediumblob NOT NULL, - `extension` varchar(10) NOT NULL, - `thumb` mediumblob DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_AccountFile_01` (`accountId`), - CONSTRAINT `fk_AccountFile_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(11) NOT NULL AUTO_INCREMENT, + `accountId` mediumint(5) unsigned NOT NULL, + `name` varchar(100) NOT NULL, + `type` varchar(100) NOT NULL, + `size` int(11) NOT NULL, + `content` mediumblob NOT NULL, + `extension` varchar(10) NOT NULL, + `thumb` mediumblob DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `idx_AccountFile_01` (`accountId`), + CONSTRAINT `fk_AccountFile_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `AccountHistory` +-- + DROP TABLE IF EXISTS `AccountHistory`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `AccountHistory` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `accountId` mediumint(8) unsigned NOT NULL, - `userGroupId` smallint(5) unsigned NOT NULL, - `userId` smallint(5) unsigned NOT NULL, - `userEditId` smallint(5) unsigned NOT NULL, - `clientId` mediumint(8) unsigned NOT NULL, - `name` varchar(255) NOT NULL, - `categoryId` mediumint(8) unsigned NOT NULL, - `login` varchar(50) DEFAULT NULL, - `url` varchar(255) DEFAULT NULL, - `pass` varbinary(2000) NOT NULL, - `key` varbinary(2000) NOT NULL, - `notes` text NOT NULL, - `countView` int(10) unsigned NOT NULL DEFAULT 0, - `countDecrypt` int(10) unsigned NOT NULL DEFAULT 0, - `dateAdd` datetime NOT NULL, - `dateEdit` datetime DEFAULT NULL, - `isModify` tinyint(1) DEFAULT 0, - `isDeleted` tinyint(1) DEFAULT 0, - `mPassHash` varbinary(255) NOT NULL, - `otherUserEdit` tinyint(1) DEFAULT 0, - `otherUserGroupEdit` tinyint(1) DEFAULT 0, - `passDate` int(10) unsigned DEFAULT NULL, - `passDateChange` int(10) unsigned DEFAULT NULL, - `parentId` mediumint(8) unsigned DEFAULT NULL, - `isPrivate` tinyint(1) DEFAULT 0, - `isPrivateGroup` tinyint(1) DEFAULT 0, - PRIMARY KEY (`id`), - KEY `idx_AccountHistory_01` (`accountId`), - KEY `idx_AccountHistory_02` (`parentId`), - KEY `fk_AccountHistory_userGroupId` (`userGroupId`), - KEY `fk_AccountHistory_userId` (`userId`), - KEY `fk_AccountHistory_userEditId` (`userEditId`), - KEY `fk_AccountHistory_clientId` (`clientId`), - KEY `fk_AccountHistory_categoryId` (`categoryId`), - CONSTRAINT `fk_AccountHistory_categoryId` FOREIGN KEY (`categoryId`) REFERENCES `Category` (`id`), - CONSTRAINT `fk_AccountHistory_clientId` FOREIGN KEY (`clientId`) REFERENCES `Client` (`id`), - CONSTRAINT `fk_AccountHistory_userEditId` FOREIGN KEY (`userEditId`) REFERENCES `User` (`id`), - CONSTRAINT `fk_AccountHistory_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`), - CONSTRAINT `fk_AccountHistory_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(11) NOT NULL AUTO_INCREMENT, + `accountId` mediumint(8) unsigned NOT NULL, + `userGroupId` smallint(5) unsigned NOT NULL, + `userId` smallint(5) unsigned NOT NULL, + `userEditId` smallint(5) unsigned NOT NULL, + `clientId` mediumint(8) unsigned NOT NULL, + `name` varchar(255) NOT NULL, + `categoryId` mediumint(8) unsigned NOT NULL, + `login` varchar(50) DEFAULT NULL, + `url` varchar(255) DEFAULT NULL, + `pass` varbinary(2000) NOT NULL, + `key` varbinary(2000) NOT NULL, + `notes` text NOT NULL, + `countView` int(10) unsigned NOT NULL DEFAULT 0, + `countDecrypt` int(10) unsigned NOT NULL DEFAULT 0, + `dateAdd` datetime NOT NULL, + `dateEdit` datetime DEFAULT NULL, + `isModify` tinyint(1) DEFAULT 0, + `isDeleted` tinyint(1) DEFAULT 0, + `mPassHash` varbinary(255) NOT NULL, + `otherUserEdit` tinyint(1) DEFAULT 0, + `otherUserGroupEdit` tinyint(1) DEFAULT 0, + `passDate` int(10) unsigned DEFAULT NULL, + `passDateChange` int(10) unsigned DEFAULT NULL, + `parentId` mediumint(8) unsigned DEFAULT NULL, + `isPrivate` tinyint(1) DEFAULT 0, + `isPrivateGroup` tinyint(1) DEFAULT 0, + PRIMARY KEY (`id`), + KEY `idx_AccountHistory_01` (`accountId`), + KEY `idx_AccountHistory_02` (`parentId`), + KEY `fk_AccountHistory_userGroupId` (`userGroupId`), + KEY `fk_AccountHistory_userId` (`userId`), + KEY `fk_AccountHistory_userEditId` (`userEditId`), + KEY `fk_AccountHistory_clientId` (`clientId`), + KEY `fk_AccountHistory_categoryId` (`categoryId`), + CONSTRAINT `fk_AccountHistory_categoryId` FOREIGN KEY (`categoryId`) REFERENCES `Category` (`id`), + CONSTRAINT `fk_AccountHistory_clientId` FOREIGN KEY (`clientId`) REFERENCES `Client` (`id`), + CONSTRAINT `fk_AccountHistory_userEditId` FOREIGN KEY (`userEditId`) REFERENCES `User` (`id`), + CONSTRAINT `fk_AccountHistory_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`), + CONSTRAINT `fk_AccountHistory_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `AccountToFavorite` +-- + DROP TABLE IF EXISTS `AccountToFavorite`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `AccountToFavorite` ( - `accountId` mediumint(8) unsigned NOT NULL, - `userId` smallint(5) unsigned NOT NULL, - PRIMARY KEY (`accountId`, `userId`), - KEY `idx_AccountToFavorite_01` (`accountId`, `userId`), - KEY `fk_AccountToFavorite_userId` (`userId`), - CONSTRAINT `fk_AccountToFavorite_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - CONSTRAINT `fk_AccountToFavorite_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `accountId` mediumint(8) unsigned NOT NULL, + `userId` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`accountId`, `userId`), + KEY `idx_AccountToFavorite_01` (`accountId`, `userId`), + KEY `fk_AccountToFavorite_userId` (`userId`), + CONSTRAINT `fk_AccountToFavorite_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_AccountToFavorite_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `AccountToTag` +-- + DROP TABLE IF EXISTS `AccountToTag`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `AccountToTag` ( - `accountId` mediumint(8) unsigned NOT NULL, - `tagId` int(10) unsigned NOT NULL, - PRIMARY KEY (`accountId`, `tagId`), - KEY `fk_AccountToTag_accountId` (`accountId`), - KEY `fk_AccountToTag_tagId` (`tagId`), - CONSTRAINT `fk_AccountToTag_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - CONSTRAINT `fk_AccountToTag_tagId` FOREIGN KEY (`tagId`) REFERENCES `Tag` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `accountId` mediumint(8) unsigned NOT NULL, + `tagId` int(10) unsigned NOT NULL, + PRIMARY KEY (`accountId`, `tagId`), + KEY `fk_AccountToTag_accountId` (`accountId`), + KEY `fk_AccountToTag_tagId` (`tagId`), + CONSTRAINT `fk_AccountToTag_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_AccountToTag_tagId` FOREIGN KEY (`tagId`) REFERENCES `Tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `AccountToUser` +-- + DROP TABLE IF EXISTS `AccountToUser`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `AccountToUser` ( - `accountId` mediumint(8) unsigned NOT NULL, - `userId` smallint(5) unsigned NOT NULL, - `isEdit` tinyint(1) unsigned DEFAULT 0 NULL, - PRIMARY KEY (`accountId`, `userId`), - KEY `idx_AccountToUser_01` (`accountId`), - KEY `fk_AccountToUser_userId` (`userId`), - CONSTRAINT `fk_AccountToUser_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - CONSTRAINT `fk_AccountToUser_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `accountId` mediumint(8) unsigned NOT NULL, + `userId` smallint(5) unsigned NOT NULL, + `isEdit` tinyint(1) unsigned DEFAULT 0, + PRIMARY KEY (`accountId`, `userId`), + KEY `idx_AccountToUser_01` (`accountId`), + KEY `fk_AccountToUser_userId` (`userId`), + CONSTRAINT `fk_AccountToUser_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_AccountToUser_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `AccountToUserGroup` +-- + DROP TABLE IF EXISTS `AccountToUserGroup`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `AccountToUserGroup` ( - `accountId` mediumint(8) unsigned NOT NULL, - `userGroupId` smallint(5) unsigned NOT NULL, - `isEdit` tinyint(1) unsigned DEFAULT 0 NULL, - PRIMARY KEY (`accountId`, `userGroupId`), - KEY `idx_AccountToUserGroup_01` (`accountId`), - KEY `fk_AccountToUserGroup_userGroupId` (`userGroupId`), - CONSTRAINT `fk_AccountToUserGroup_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - CONSTRAINT `fk_AccountToUserGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `accountId` mediumint(8) unsigned NOT NULL, + `userGroupId` smallint(5) unsigned NOT NULL, + `isEdit` tinyint(1) unsigned DEFAULT 0, + PRIMARY KEY (`accountId`, `userGroupId`), + KEY `idx_AccountToUserGroup_01` (`accountId`), + KEY `fk_AccountToUserGroup_userGroupId` (`userGroupId`), + CONSTRAINT `fk_AccountToUserGroup_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_AccountToUserGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `AuthToken` +-- + DROP TABLE IF EXISTS `AuthToken`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `AuthToken` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `userId` smallint(5) unsigned NOT NULL, - `token` varbinary(255) NOT NULL, - `actionId` smallint(5) unsigned NOT NULL, - `createdBy` smallint(5) unsigned NOT NULL, - `startDate` int(10) unsigned NOT NULL, - `vault` varbinary(2000) DEFAULT NULL, - `hash` varbinary(500) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_AuthToken_01` (`token`, `actionId`), - KEY `idx_AuthToken_01` (`userId`, `actionId`, `token`), - KEY `fk_AuthToken_actionId` (`actionId`), - CONSTRAINT `fk_AuthToken_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(11) NOT NULL AUTO_INCREMENT, + `userId` smallint(5) unsigned NOT NULL, + `token` varbinary(255) NOT NULL, + `actionId` smallint(5) unsigned NOT NULL, + `createdBy` smallint(5) unsigned NOT NULL, + `startDate` int(10) unsigned NOT NULL, + `vault` varbinary(2000) DEFAULT NULL, + `hash` varbinary(500) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_AuthToken_01` (`token`, `actionId`), + KEY `idx_AuthToken_01` (`userId`, `actionId`, `token`), + KEY `fk_AuthToken_actionId` (`actionId`), + CONSTRAINT `fk_AuthToken_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Category` +-- + DROP TABLE IF EXISTS `Category`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Category` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(50) NOT NULL, - `description` varchar(255) DEFAULT NULL, - `hash` varbinary(40) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_Category_01` (`hash`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `description` varchar(255) DEFAULT NULL, + `hash` varbinary(40) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_Category_01` (`hash`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Client` +-- + DROP TABLE IF EXISTS `Client`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Client` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(100) NOT NULL, - `hash` varbinary(40) NOT NULL, - `description` varchar(255) DEFAULT NULL, - `isGlobal` tinyint(1) DEFAULT 0, - PRIMARY KEY (`id`), - KEY `uk_Client_01` (`hash`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `hash` varbinary(40) NOT NULL, + `description` varchar(255) DEFAULT NULL, + `isGlobal` tinyint(1) DEFAULT 0, + PRIMARY KEY (`id`), + KEY `uk_Client_01` (`hash`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Config` +-- + DROP TABLE IF EXISTS `Config`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Config` ( - `parameter` varchar(50) NOT NULL, - `value` varchar(4000) DEFAULT NULL, - PRIMARY KEY (`parameter`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `parameter` varchar(50) NOT NULL, + `value` varchar(4000) DEFAULT NULL, + PRIMARY KEY (`parameter`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `CustomFieldData` +-- + DROP TABLE IF EXISTS `CustomFieldData`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `CustomFieldData` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `moduleId` smallint(5) unsigned NOT NULL, - `itemId` int(10) unsigned NOT NULL, - `definitionId` int(10) unsigned NOT NULL, - `data` longblob DEFAULT NULL, - `key` varbinary(2000) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_CustomFieldData_01` (`definitionId`), - KEY `idx_CustomFieldData_02` (`itemId`, `moduleId`), - KEY `idx_CustomFieldData_03` (`moduleId`), - KEY `uk_CustomFieldData_01` (`moduleId`, `itemId`, `definitionId`), - CONSTRAINT `fk_CustomFieldData_definitionId` FOREIGN KEY (`definitionId`) REFERENCES `CustomFieldDefinition` (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `moduleId` smallint(5) unsigned NOT NULL, + `itemId` int(10) unsigned NOT NULL, + `definitionId` int(10) unsigned NOT NULL, + `data` longblob DEFAULT NULL, + `key` varbinary(2000) DEFAULT NULL, + PRIMARY KEY (`moduleId`, `itemId`, `definitionId`), + KEY `idx_CustomFieldData_01` (`definitionId`), + KEY `idx_CustomFieldData_02` (`itemId`, `moduleId`), + KEY `idx_CustomFieldData_03` (`moduleId`), + KEY `uk_CustomFieldData_01` (`moduleId`, `itemId`, `definitionId`), + CONSTRAINT `fk_CustomFieldData_definitionId` FOREIGN KEY (`definitionId`) REFERENCES `CustomFieldDefinition` (`id`) ON DELETE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `CustomFieldDefinition` +-- + DROP TABLE IF EXISTS `CustomFieldDefinition`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `CustomFieldDefinition` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(100) NOT NULL, - `moduleId` smallint(5) unsigned NOT NULL, - `required` tinyint(1) unsigned DEFAULT NULL, - `help` varchar(255) DEFAULT NULL, - `showInList` tinyint(1) unsigned DEFAULT NULL, - `typeId` tinyint(3) unsigned NOT NULL, - `isEncrypted` tinyint(1) unsigned DEFAULT 1 NULL, - PRIMARY KEY (`id`), - KEY `fk_CustomFieldDefinition_typeId` (`typeId`), - CONSTRAINT `fk_CustomFieldDefinition_typeId` FOREIGN KEY (`typeId`) REFERENCES `CustomFieldType` (`id`) - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `moduleId` smallint(5) unsigned NOT NULL, + `required` tinyint(1) unsigned DEFAULT NULL, + `help` varchar(255) DEFAULT NULL, + `showInList` tinyint(1) unsigned DEFAULT NULL, + `typeId` tinyint(3) unsigned NOT NULL, + `isEncrypted` tinyint(1) unsigned DEFAULT 1, + PRIMARY KEY (`id`), + KEY `fk_CustomFieldDefinition_typeId` (`typeId`), + CONSTRAINT `fk_CustomFieldDefinition_typeId` FOREIGN KEY (`typeId`) REFERENCES `CustomFieldType` (`id`) ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `CustomFieldType` +-- + DROP TABLE IF EXISTS `CustomFieldType`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `CustomFieldType` ( - `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(50) NOT NULL, - `text` varchar(50) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_CustomFieldType_01` (`name`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `text` varchar(50) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_CustomFieldType_01` (`name`) +) ENGINE = InnoDB + AUTO_INCREMENT = 11 + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `EventLog` +-- + DROP TABLE IF EXISTS `EventLog`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `EventLog` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `date` int(10) unsigned NOT NULL, - `login` varchar(25) DEFAULT NULL, - `userId` smallint(5) unsigned DEFAULT NULL, - `ipAddress` varchar(45) NOT NULL, - `action` varchar(50) NOT NULL, - `description` text DEFAULT NULL, - `level` varchar(20) NOT NULL, - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `date` int(10) unsigned NOT NULL, + `login` varchar(25) DEFAULT NULL, + `userId` smallint(5) unsigned DEFAULT NULL, + `ipAddress` varchar(45) NOT NULL, + `action` varchar(50) NOT NULL, + `description` text DEFAULT NULL, + `level` varchar(20) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -INSERT INTO CustomFieldType (id, name, text) -VALUES (1, 'text', 'Text'), - (2, 'password', 'Password'), - (3, 'date', 'Date'), - (4, 'number', 'Number'), - (5, 'email', 'Email'), - (6, 'telephone', 'Phone'), - (7, 'url', 'URL'), - (8, 'color', 'Color'), - (9, 'wiki', 'Wiki'), - (10, 'textarea', 'Text Area'); + +-- +-- Table structure for table `ItemPreset` +-- + +DROP TABLE IF EXISTS `ItemPreset`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `ItemPreset` +( + `id` int(11) NOT NULL AUTO_INCREMENT, + `type` varchar(25) NOT NULL, + `userId` smallint(5) unsigned DEFAULT NULL, + `userGroupId` smallint(5) unsigned DEFAULT NULL, + `userProfileId` smallint(5) unsigned DEFAULT NULL, + `fixed` tinyint(1) unsigned NOT NULL DEFAULT 0, + `priority` tinyint(3) unsigned NOT NULL DEFAULT 0, + `data` blob DEFAULT NULL, + `hash` varbinary(40) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_ItemPreset_01` (`hash`), + KEY `fk_ItemPreset_userId` (`userId`), + KEY `fk_ItemPreset_userGroupId` (`userGroupId`), + KEY `fk_ItemPreset_userProfileId` (`userProfileId`), + CONSTRAINT `fk_ItemPreset_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_ItemPreset_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_ItemPreset_userProfileId` FOREIGN KEY (`userProfileId`) REFERENCES `UserProfile` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Notification` +-- + DROP TABLE IF EXISTS `Notification`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Notification` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `type` varchar(100) DEFAULT NULL, - `component` varchar(100) NOT NULL, - `description` text NOT NULL, - `date` int(10) unsigned NOT NULL, - `checked` tinyint(1) DEFAULT 0, - `userId` smallint(5) unsigned DEFAULT NULL, - `sticky` tinyint(1) DEFAULT 0, - `onlyAdmin` tinyint(1) DEFAULT 0, - PRIMARY KEY (`id`), - KEY `idx_Notification_01` (`userId`, `checked`, `date`), - KEY `idx_Notification_02` (`component`, `date`, `checked`, `userId`), - KEY `fk_Notification_userId` (`userId`), - CONSTRAINT `fk_Notification_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `type` varchar(100) DEFAULT NULL, + `component` varchar(100) NOT NULL, + `description` text NOT NULL, + `date` int(10) unsigned NOT NULL, + `checked` tinyint(1) DEFAULT 0, + `userId` smallint(5) unsigned DEFAULT NULL, + `sticky` tinyint(1) DEFAULT 0, + `onlyAdmin` tinyint(1) DEFAULT 0, + PRIMARY KEY (`id`), + KEY `idx_Notification_01` (`userId`, `checked`, `date`), + KEY `idx_Notification_02` (`component`, `date`, `checked`, `userId`), + KEY `fk_Notification_userId` (`userId`), + CONSTRAINT `fk_Notification_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Plugin` +-- + DROP TABLE IF EXISTS `Plugin`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Plugin` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(100) NOT NULL, - `data` mediumblob DEFAULT NULL, - `enabled` tinyint(1) NOT NULL DEFAULT 0, - `available` tinyint(1) DEFAULT 0, - `versionLevel` varchar(15) NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_Plugin_01` (`name`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `data` mediumblob DEFAULT NULL, + `enabled` tinyint(1) NOT NULL DEFAULT 0, + `available` tinyint(1) DEFAULT 0, + `versionLevel` varchar(15) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_Plugin_01` (`name`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `PluginData` +-- + +DROP TABLE IF EXISTS `PluginData`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `PluginData` +( + `name` varchar(100) NOT NULL, + `itemId` int(11) NOT NULL, + `data` blob NOT NULL, + `key` varbinary(2000) NOT NULL, + PRIMARY KEY (`name`, `itemId`), + CONSTRAINT `fk_PluginData_name` FOREIGN KEY (`name`) REFERENCES `Plugin` (`name`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `PublicLink` +-- + DROP TABLE IF EXISTS `PublicLink`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `PublicLink` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `itemId` int(10) unsigned NOT NULL, - `hash` varbinary(100) NOT NULL, - `data` mediumblob DEFAULT NULL, - `userId` smallint(5) unsigned NOT NULL, - `typeId` int(10) unsigned NOT NULL, - `notify` tinyint(1) DEFAULT 0, - `dateAdd` int(10) unsigned NOT NULL, - `dateExpire` int(10) unsigned NOT NULL, - `dateUpdate` int(10) unsigned DEFAULT 0, - `countViews` smallint(5) unsigned DEFAULT 0, - `totalCountViews` mediumint(8) unsigned DEFAULT 0, - `maxCountViews` smallint(5) unsigned NOT NULL DEFAULT 0, - `useinfo` blob DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_PublicLink_01` (`hash`), - UNIQUE KEY `uk_PublicLink_02` (`itemId`), - KEY `fk_PublicLink_userId` (`userId`), - CONSTRAINT `fk_PublicLink_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `itemId` int(10) unsigned NOT NULL, + `hash` varbinary(100) NOT NULL, + `data` mediumblob DEFAULT NULL, + `userId` smallint(5) unsigned NOT NULL, + `typeId` int(10) unsigned NOT NULL, + `notify` tinyint(1) DEFAULT 0, + `dateAdd` int(10) unsigned NOT NULL, + `dateExpire` int(10) unsigned NOT NULL, + `dateUpdate` int(10) unsigned DEFAULT 0, + `countViews` smallint(5) unsigned DEFAULT 0, + `totalCountViews` mediumint(8) unsigned DEFAULT 0, + `maxCountViews` smallint(5) unsigned NOT NULL DEFAULT 0, + `useinfo` blob DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_PublicLink_01` (`hash`), + UNIQUE KEY `uk_PublicLink_02` (`itemId`), + KEY `fk_PublicLink_userId` (`userId`), + CONSTRAINT `fk_PublicLink_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Tag` +-- + DROP TABLE IF EXISTS `Tag`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Tag` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - `hash` varbinary(40) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_Tag_01` (`hash`), - KEY `idx_Tag_01` (`name`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `hash` varbinary(40) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_Tag_01` (`hash`), + KEY `idx_Tag_01` (`name`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Track` +-- + DROP TABLE IF EXISTS `Track`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Track` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `userId` smallint(5) unsigned DEFAULT NULL, - `source` varchar(100) NOT NULL, - `time` int(10) unsigned NOT NULL, - `timeUnlock` int(10) unsigned, - `ipv4` binary(4) DEFAULT NULL, - `ipv6` binary(16) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_Track_01` (`userId`), - KEY `idx_Track_02` (`time`, `ipv4`, `ipv6`, `source`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `userId` smallint(5) unsigned DEFAULT NULL, + `source` varchar(100) NOT NULL, + `time` int(10) unsigned NOT NULL, + `timeUnlock` int(10) unsigned DEFAULT NULL, + `ipv4` binary(4) DEFAULT NULL, + `ipv6` binary(16) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `idx_Track_01` (`userId`), + KEY `idx_Track_02` (`time`, `ipv4`, `ipv6`, `source`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `User` +-- + DROP TABLE IF EXISTS `User`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `User` ( - `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(80) NOT NULL, - `userGroupId` smallint(5) unsigned NOT NULL, - `login` varchar(50) NOT NULL, - `ssoLogin` varchar(100) DEFAULT NULL, - `pass` varbinary(500) NOT NULL, - `mPass` varbinary(2000) DEFAULT NULL, - `mKey` varbinary(2000) DEFAULT NULL, - `email` varchar(80) DEFAULT NULL, - `notes` text DEFAULT NULL, - `loginCount` int(10) unsigned NOT NULL DEFAULT 0, - `userProfileId` smallint(5) unsigned NOT NULL, - `lastLogin` datetime DEFAULT NULL, - `lastUpdate` datetime DEFAULT NULL, - `lastUpdateMPass` int(11) unsigned NOT NULL DEFAULT 0, - `isAdminApp` tinyint(1) DEFAULT 0, - `isAdminAcc` tinyint(1) DEFAULT 0, - `isLdap` tinyint(1) DEFAULT 0, - `isDisabled` tinyint(1) DEFAULT 0, - `hashSalt` varbinary(255) NOT NULL, - `isMigrate` tinyint(1) DEFAULT 0, - `isChangePass` tinyint(1) DEFAULT 0, - `isChangedPass` tinyint(1) DEFAULT 0, - `preferences` blob DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_User_01` (`login`, `ssoLogin`), - KEY `idx_User_01` (`pass`), - KEY `fk_User_userGroupId` (`userGroupId`), - KEY `fk_User_userProfileId` (`userProfileId`), - CONSTRAINT `fk_User_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`), - CONSTRAINT `fk_User_userProfileId` FOREIGN KEY (`userProfileId`) REFERENCES `UserProfile` (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(80) NOT NULL, + `userGroupId` smallint(5) unsigned NOT NULL, + `login` varchar(50) NOT NULL, + `ssoLogin` varchar(100) DEFAULT NULL, + `pass` varbinary(500) NOT NULL, + `mPass` varbinary(2000) DEFAULT NULL, + `mKey` varbinary(2000) DEFAULT NULL, + `email` varchar(80) DEFAULT NULL, + `notes` text DEFAULT NULL, + `loginCount` int(10) unsigned NOT NULL DEFAULT 0, + `userProfileId` smallint(5) unsigned NOT NULL, + `lastLogin` datetime DEFAULT NULL, + `lastUpdate` datetime DEFAULT NULL, + `lastUpdateMPass` int(11) unsigned NOT NULL DEFAULT 0, + `isAdminApp` tinyint(1) DEFAULT 0, + `isAdminAcc` tinyint(1) DEFAULT 0, + `isLdap` tinyint(1) DEFAULT 0, + `isDisabled` tinyint(1) DEFAULT 0, + `hashSalt` varbinary(255) NOT NULL, + `isMigrate` tinyint(1) DEFAULT 0, + `isChangePass` tinyint(1) DEFAULT 0, + `isChangedPass` tinyint(1) DEFAULT 0, + `preferences` blob DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_User_01` (`login`, `ssoLogin`), + KEY `idx_User_01` (`pass`), + KEY `fk_User_userGroupId` (`userGroupId`), + KEY `fk_User_userProfileId` (`userProfileId`), + CONSTRAINT `fk_User_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`), + CONSTRAINT `fk_User_userProfileId` FOREIGN KEY (`userProfileId`) REFERENCES `UserProfile` (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `UserGroup` +-- + DROP TABLE IF EXISTS `UserGroup`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `UserGroup` ( - `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(50) NOT NULL, - `description` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `description` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `UserPassRecover` +-- + DROP TABLE IF EXISTS `UserPassRecover`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `UserPassRecover` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `userId` smallint(5) unsigned NOT NULL, - `hash` varbinary(255) NOT NULL, - `date` int(10) unsigned NOT NULL, - `used` tinyint(1) DEFAULT 0, - PRIMARY KEY (`id`), - KEY `idx_UserPassRecover_01` (`userId`, `date`), - CONSTRAINT `fk_UserPassRecover_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `userId` smallint(5) unsigned NOT NULL, + `hash` varbinary(255) NOT NULL, + `date` int(10) unsigned NOT NULL, + `used` tinyint(1) DEFAULT 0, + PRIMARY KEY (`id`), + KEY `idx_UserPassRecover_01` (`userId`, `date`), + CONSTRAINT `fk_UserPassRecover_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `UserProfile` +-- + DROP TABLE IF EXISTS `UserProfile`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `UserProfile` ( - `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - `profile` blob NOT NULL, - PRIMARY KEY (`id`) -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `profile` blob NOT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `UserToUserGroup` +-- + DROP TABLE IF EXISTS `UserToUserGroup`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `UserToUserGroup` ( - `userId` smallint(5) unsigned NOT NULL, - `userGroupId` smallint(5) unsigned NOT NULL, - KEY `idx_UserToUserGroup_01` (`userId`), - KEY `fk_UserToGroup_userGroupId` (`userGroupId`), - UNIQUE KEY `uk_UserToUserGroup_01` (`userId`, `userGroupId`), - CONSTRAINT `fk_UserToGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - CONSTRAINT `fk_UserToGroup_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `PluginData`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -create table PluginData -( - name varchar(100) not null, - itemId int not null, - `data` blob not null, - `key` varbinary(2000) not null, - primary key (name, itemId), - constraint fk_PluginData_name - foreign key (name) references Plugin (name) - on update cascade - on delete cascade -) - ENGINE = InnoDB - DEFAULT CHARSET = utf8 - COLLATE utf8_unicode_ci; + `userId` smallint(5) unsigned NOT NULL, + `userGroupId` smallint(5) unsigned NOT NULL, + UNIQUE KEY `uk_UserToUserGroup_01` (`userId`, `userGroupId`), + KEY `idx_UserToUserGroup_01` (`userId`), + KEY `fk_UserToGroup_userGroupId` (`userGroupId`), + CONSTRAINT `fk_UserToGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_UserToGroup_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb3 + COLLATE = utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `account_data_v` +-- + DROP TABLE IF EXISTS `account_data_v`; /*!50001 DROP VIEW IF EXISTS `account_data_v`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; -/*!50001 CREATE TABLE `account_data_v` -( - `id` tinyint NOT NULL, - `name` tinyint NOT NULL, - `categoryId` tinyint NOT NULL, - `userId` tinyint NOT NULL, - `clientId` tinyint NOT NULL, - `userGroupId` tinyint NOT NULL, - `userEditId` tinyint NOT NULL, - `login` tinyint NOT NULL, - `url` tinyint NOT NULL, - `notes` tinyint NOT NULL, - `countView` tinyint NOT NULL, - `countDecrypt` tinyint NOT NULL, - `dateAdd` tinyint NOT NULL, - `dateEdit` tinyint NOT NULL, - `otherUserEdit` tinyint NOT NULL, - `otherUserGroupEdit` tinyint NOT NULL, - `isPrivate` tinyint NOT NULL, - `isPrivateGroup` tinyint NOT NULL, - `passDate` tinyint NOT NULL, - `passDateChange` tinyint NOT NULL, - `parentId` tinyint NOT NULL, - `categoryName` tinyint NOT NULL, - `clientName` tinyint NOT NULL, - `userGroupName` tinyint NOT NULL, - `userName` tinyint NOT NULL, - `userLogin` tinyint NOT NULL, - `userEditName` tinyint NOT NULL, - `userEditLogin` tinyint NOT NULL, - `publicLinkHash` tinyint NOT NULL -) - ENGINE = MyISAM */; +/*!50001 CREATE VIEW `account_data_v` AS +SELECT 1 AS `id`, + 1 AS `name`, + 1 AS `categoryId`, + 1 AS `userId`, + 1 AS `clientId`, + 1 AS `userGroupId`, + 1 AS `userEditId`, + 1 AS `login`, + 1 AS `url`, + 1 AS `notes`, + 1 AS `countView`, + 1 AS `countDecrypt`, + 1 AS `dateAdd`, + 1 AS `dateEdit`, + 1 AS `otherUserEdit`, + 1 AS `otherUserGroupEdit`, + 1 AS `isPrivate`, + 1 AS `isPrivateGroup`, + 1 AS `passDate`, + 1 AS `passDateChange`, + 1 AS `parentId`, + 1 AS `categoryName`, + 1 AS `clientName`, + 1 AS `userGroupName`, + 1 AS `userName`, + 1 AS `userLogin`, + 1 AS `userEditName`, + 1 AS `userEditLogin`, + 1 AS `publicLinkHash` + */; SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `account_search_v` +-- + DROP TABLE IF EXISTS `account_search_v`; /*!50001 DROP VIEW IF EXISTS `account_search_v`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; -/*!50001 CREATE TABLE `account_search_v` -( - `id` tinyint NOT NULL, - `clientId` tinyint NOT NULL, - `categoryId` tinyint NOT NULL, - `name` tinyint NOT NULL, - `login` tinyint NOT NULL, - `url` tinyint NOT NULL, - `notes` tinyint NOT NULL, - `userId` tinyint NOT NULL, - `userGroupId` tinyint NOT NULL, - `otherUserEdit` tinyint NOT NULL, - `otherUserGroupEdit` tinyint NOT NULL, - `isPrivate` tinyint NOT NULL, - `isPrivateGroup` tinyint NOT NULL, - `passDate` tinyint NOT NULL, - `passDateChange` tinyint NOT NULL, - `parentId` tinyint NOT NULL, - `countView` tinyint NOT NULL, - `dateEdit` tinyint NOT NULL, - `userName` tinyint NOT NULL, - `userLogin` tinyint NOT NULL, - `userGroupName` tinyint NOT NULL, - `categoryName` tinyint NOT NULL, - `clientName` tinyint NOT NULL, - `num_files` tinyint NOT NULL -) - ENGINE = MyISAM */; +/*!50001 CREATE VIEW `account_search_v` AS +SELECT 1 AS `id`, + 1 AS `clientId`, + 1 AS `categoryId`, + 1 AS `name`, + 1 AS `login`, + 1 AS `url`, + 1 AS `notes`, + 1 AS `userId`, + 1 AS `userGroupId`, + 1 AS `otherUserEdit`, + 1 AS `otherUserGroupEdit`, + 1 AS `isPrivate`, + 1 AS `isPrivateGroup`, + 1 AS `passDate`, + 1 AS `passDateChange`, + 1 AS `parentId`, + 1 AS `countView`, + 1 AS `dateEdit`, + 1 AS `userName`, + 1 AS `userLogin`, + 1 AS `userGroupName`, + 1 AS `categoryName`, + 1 AS `clientName`, + 1 AS `num_files`, + 1 AS `publicLinkHash`, + 1 AS `publicLinkDateExpire`, + 1 AS `publicLinkTotalCountViews` + */; SET character_set_client = @saved_cs_client; -/*!50001 DROP TABLE IF EXISTS `account_data_v`*/; + +-- +-- Final view structure for view `account_data_v` +-- + /*!50001 DROP VIEW IF EXISTS `account_data_v`*/; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM = UNDEFINED */ - /*!50013 SQL SECURITY DEFINER */ - /*!50001 VIEW `account_data_v` AS +/*!50001 SET character_set_client = utf8mb3 */; +/*!50001 SET character_set_results = utf8mb3 */; +/*!50001 SET collation_connection = utf8mb3_general_ci */; +/*!50001 CREATE ALGORITHM = UNDEFINED */ /*!50013 SQL SECURITY DEFINER */ /*!50001 VIEW `account_data_v` AS select `Account`.`id` AS `id`, `Account`.`name` AS `name`, `Account`.`categoryId` AS `categoryId`, @@ -752,61 +847,60 @@ select `Account`.`id` AS `id`, `u2`.`name` AS `userEditName`, `u2`.`login` AS `userEditLogin`, `PublicLink`.`hash` AS `publicLinkHash` -from ((((((`Account` - left join `Category` on (`Account`.`categoryId` = `Category`.`id`)) join `UserGroup` `ug` - on (`Account`.`userGroupId` = `ug`.`id`)) join `User` `u1` on (`Account`.`userId` = `u1`.`id`)) join `User` `u2` - on (`Account`.`userEditId` = `u2`.`id`)) left join `Client` on (`Account`.`clientId` = `Client`.`id`)) - left join - `PublicLink` on (`Account`.`id` = `PublicLink`.`itemId`)) */; +from ((((((`Account` left join `Category` on (`Account`.`categoryId` = `Category`.`id`)) join `UserGroup` `ug` + on (`Account`.`userGroupId` = `ug`.`id`)) join `User` `u1` + on (`Account`.`userId` = `u1`.`id`)) join `User` `u2` + on (`Account`.`userEditId` = `u2`.`id`)) left join `Client` + on (`Account`.`clientId` = `Client`.`id`)) left join `PublicLink` on (`Account`.`id` = `PublicLink`.`itemId`)) + */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; -/*!50001 DROP TABLE IF EXISTS `account_search_v`*/; + +-- +-- Final view structure for view `account_search_v` +-- + /*!50001 DROP VIEW IF EXISTS `account_search_v`*/; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM = UNDEFINED */ - /*!50013 SQL SECURITY DEFINER */ - /*!50001 VIEW `account_search_v` AS -SELECT `Account`.`id` AS `id`, - `Account`.`clientId` AS `clientId`, - `Account`.`categoryId` AS `categoryId`, - `Account`.`name` AS `name`, - `Account`.`login` AS `login`, - `Account`.`url` AS `url`, - `Account`.`notes` AS `notes`, - `Account`.`userId` AS `userId`, - `Account`.`userGroupId` AS `userGroupId`, - `Account`.`otherUserEdit` AS `otherUserEdit`, - `Account`.`otherUserGroupEdit` AS `otherUserGroupEdit`, - `Account`.`isPrivate` AS `isPrivate`, - `Account`.`isPrivateGroup` AS `isPrivateGroup`, - `Account`.`passDate` AS `passDate`, - `Account`.`passDateChange` AS `passDateChange`, - `Account`.`parentId` AS `parentId`, - `Account`.`countView` AS `countView`, - `Account`.`dateEdit` AS `dateEdit`, - `User`.`name` AS `userName`, - `User`.`login` AS `userLogin`, - `UserGroup`.`name` AS `userGroupName`, - `Category`.`name` AS `categoryName`, - `Client`.`name` AS `clientName`, - (SELECT count(0) - FROM `AccountFile` - WHERE (`AccountFile`.`accountId` = `Account`.`id`)) AS `num_files`, - `PublicLink`.`hash` AS `publicLinkHash`, - `PublicLink`.`dateExpire` AS `publicLinkDateExpire`, - `PublicLink`.`totalCountViews` AS `publicLinkTotalCountViews` -FROM `Account` - INNER JOIN `Category` ON `Account`.`categoryId` = `Category`.`id` - INNER JOIN `Client` ON `Client`.`id` = `Account`.`clientId` - INNER JOIN `User` ON `Account`.`userId` = `User`.`id` - INNER JOIN `UserGroup` ON `Account`.`userGroupId` = `UserGroup`.`id` - LEFT JOIN `PublicLink` ON `Account`.`id` = `PublicLink`.`itemId` */; +/*!50001 SET character_set_client = utf8mb3 */; +/*!50001 SET character_set_results = utf8mb3 */; +/*!50001 SET collation_connection = utf8mb3_general_ci */; +/*!50001 CREATE ALGORITHM = UNDEFINED */ /*!50013 SQL SECURITY DEFINER */ /*!50001 VIEW `account_search_v` AS +select `Account`.`id` AS `id`, + `Account`.`clientId` AS `clientId`, + `Account`.`categoryId` AS `categoryId`, + `Account`.`name` AS `name`, + `Account`.`login` AS `login`, + `Account`.`url` AS `url`, + `Account`.`notes` AS `notes`, + `Account`.`userId` AS `userId`, + `Account`.`userGroupId` AS `userGroupId`, + `Account`.`otherUserEdit` AS `otherUserEdit`, + `Account`.`otherUserGroupEdit` AS `otherUserGroupEdit`, + `Account`.`isPrivate` AS `isPrivate`, + `Account`.`isPrivateGroup` AS `isPrivateGroup`, + `Account`.`passDate` AS `passDate`, + `Account`.`passDateChange` AS `passDateChange`, + `Account`.`parentId` AS `parentId`, + `Account`.`countView` AS `countView`, + `Account`.`dateEdit` AS `dateEdit`, + `User`.`name` AS `userName`, + `User`.`login` AS `userLogin`, + `UserGroup`.`name` AS `userGroupName`, + `Category`.`name` AS `categoryName`, + `Client`.`name` AS `clientName`, + (select count(0) from `AccountFile` where `AccountFile`.`accountId` = `Account`.`id`) AS `num_files`, + `PublicLink`.`hash` AS `publicLinkHash`, + `PublicLink`.`dateExpire` AS `publicLinkDateExpire`, + `PublicLink`.`totalCountViews` AS `publicLinkTotalCountViews` +from (((((`Account` join `Category` on (`Account`.`categoryId` = `Category`.`id`)) join `Client` + on (`Client`.`id` = `Account`.`clientId`)) join `User` on (`Account`.`userId` = `User`.`id`)) join `UserGroup` + on (`Account`.`userGroupId` = `UserGroup`.`id`)) left join `PublicLink` + on (`Account`.`id` = `PublicLink`.`itemId`)) + */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -819,4 +913,3 @@ FROM `Account` /*!40101 SET CHARACTER_SET_RESULTS = @OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION = @OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES = @OLD_SQL_NOTES */; - diff --git a/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php b/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php index 96f4eed3..cb553b5e 100644 --- a/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php +++ b/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php @@ -32,7 +32,7 @@ use SP\Domain\Account\Adapters\AccountAdapter; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\ActionNotFoundException; use SP\Domain\Core\Acl\ActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Mvc\View\Components\SelectItemAdapter; use SPT\Generators\AccountDataGenerator; use SPT\Generators\CustomFieldGenerator; @@ -67,7 +67,7 @@ class AccountAdapterTest extends UnitaryTestCase $adapter = new AccountAdapter( $this->config->getConfigData(), - $this->createStub(CustomFieldService::class), + $this->createStub(CustomFieldDataService::class), $actions ); $accountData = $dataGenerator->buildAccountEnrichedDto(); @@ -130,9 +130,9 @@ class AccountAdapterTest extends UnitaryTestCase public function testIncludeCustomFields(): void { $customFieldData = CustomFieldGenerator::factory()->buildSimpleModel(); - $customFieldsService = $this->createStub(CustomFieldService::class); + $customFieldsService = $this->createStub(CustomFieldDataService::class); $customFieldsService->expects(self::once()) - ->method('getForModuleAndItemId') + ->method('getBy') ->willReturn([$customFieldData]); $actions = $this->createMock(ActionsInterface::class); diff --git a/tests/SPT/Domain/Account/Services/AccountTest.php b/tests/SPT/Domain/Account/Services/AccountTest.php index 5e6e0051..211f928c 100644 --- a/tests/SPT/Domain/Account/Services/AccountTest.php +++ b/tests/SPT/Domain/Account/Services/AccountTest.php @@ -405,11 +405,10 @@ class AccountTest extends UnitaryTestCase $encryptedPassword = new EncryptedPassword(self::$faker->password, self::$faker->password); $result = new QueryResult(); - $result->setAffectedNumRows(1); $this->accountRepository->expects(self::once())->method('updatePassword') ->with($id, $encryptedPassword) - ->willReturn($result); + ->willReturn($result->setAffectedNumRows(1)); $this->account->updatePasswordMasterPass($id, $encryptedPassword); } @@ -673,10 +672,9 @@ class AccountTest extends UnitaryTestCase ->with($accountHistoryCreateDto); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->accountRepository->expects(self::once())->method('delete') - ->with($id)->willReturn($queryResult); + ->with($id)->willReturn($queryResult->setAffectedNumRows(1)); $this->account->delete($id); } @@ -720,10 +718,9 @@ class AccountTest extends UnitaryTestCase $id = self::$faker->randomNumber(); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->accountRepository->expects(self::once())->method('incrementViewCounter') - ->with($id)->willReturn($queryResult); + ->with($id)->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->account->incrementViewCounter($id)); } @@ -804,7 +801,6 @@ class AccountTest extends UnitaryTestCase $accountHistoryDto = AccountDataGenerator::factory()->buildAccountHistoryDto(); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->accountRepository->expects(self::once())->method('createRemoved') ->with( @@ -813,7 +809,7 @@ class AccountTest extends UnitaryTestCase $this->context->getUserData()->getId() ) ) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->account->restoreRemoved($accountHistoryDto); } @@ -902,7 +898,6 @@ class AccountTest extends UnitaryTestCase ->with($accountHistoryCreateDto); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->accountRepository->expects(self::once())->method('restoreModified') ->with( @@ -912,7 +907,7 @@ class AccountTest extends UnitaryTestCase $this->context->getUserData()->getId() ) ) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->account->restoreModified($accountHistoryDto); } @@ -1010,11 +1005,10 @@ class AccountTest extends UnitaryTestCase ->willReturn(null); $queryResult = new QueryResult(); - $queryResult->setLastId($id); $this->accountRepository->expects(self::once())->method('create') ->with(AccountModel::create($accountCreateDto)) - ->willReturn($queryResult); + ->willReturn($queryResult->setLastId($id)); $this->accountItemsService->expects(self::once())->method('addItems') ->with(true, $id, $accountCreateDto->withEncryptedPassword($encryptedPassword)); @@ -1048,11 +1042,10 @@ class AccountTest extends UnitaryTestCase ->willReturn(null); $queryResult = new QueryResult(); - $queryResult->setLastId($id); $this->accountRepository->expects(self::once())->method('create') ->with(AccountModel::create($accountCreateDto)) - ->willReturn($queryResult); + ->willReturn($queryResult->setLastId($id)); $this->accountItemsService->expects(self::once())->method('addItems') ->with(false, $id, $accountCreateDto->withEncryptedPassword($encryptedPassword)); @@ -1096,7 +1089,6 @@ class AccountTest extends UnitaryTestCase ->willReturn($itemPreset); $queryResult = new QueryResult(); - $queryResult->setLastId($id); $this->accountRepository->expects(self::once())->method('create') ->with( @@ -1104,7 +1096,7 @@ class AccountTest extends UnitaryTestCase return $account->getIsPrivate() === 1 && $account->getIsPrivateGroup() === 0; }), ) - ->willReturn($queryResult); + ->willReturn($queryResult->setLastId($id)); $this->accountItemsService->expects(self::once())->method('addItems') ->with( @@ -1154,7 +1146,6 @@ class AccountTest extends UnitaryTestCase ->willReturn($itemPreset); $queryResult = new QueryResult(); - $queryResult->setLastId($id); $this->accountRepository->expects(self::once())->method('create') ->with( @@ -1162,7 +1153,7 @@ class AccountTest extends UnitaryTestCase return $account->getIsPrivate() === 0 && $account->getIsPrivateGroup() === 1; }), ) - ->willReturn($queryResult); + ->willReturn($queryResult->setLastId($id)); $this->accountItemsService->expects(self::once())->method('addItems') ->with( @@ -1252,10 +1243,9 @@ class AccountTest extends UnitaryTestCase $ids = array_map(fn() => self::$faker->randomNumber(), range(0, 4)); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->accountRepository->expects(self::once())->method('deleteByIdBatch') - ->with($ids)->willReturn($queryResult); + ->with($ids)->willReturn($queryResult->setAffectedNumRows(1)); $this->account->deleteByIdBatch($ids); } @@ -1269,10 +1259,9 @@ class AccountTest extends UnitaryTestCase $ids = array_map(fn() => self::$faker->randomNumber(), range(0, 4)); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(0); $this->accountRepository->expects(self::once())->method('deleteByIdBatch') - ->with($ids)->willReturn($queryResult); + ->with($ids)->willReturn($queryResult->setAffectedNumRows(0)); $this->expectException(ServiceException::class); $this->expectExceptionMessage('Error while deleting the accounts'); @@ -1309,10 +1298,9 @@ class AccountTest extends UnitaryTestCase $id = self::$faker->randomNumber(); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->accountRepository->expects(self::once())->method('incrementDecryptCounter') - ->with($id)->willReturn($queryResult); + ->with($id)->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->account->incrementDecryptCounter($id)); } @@ -1326,10 +1314,9 @@ class AccountTest extends UnitaryTestCase $id = self::$faker->randomNumber(); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(0); $this->accountRepository->expects(self::once())->method('incrementDecryptCounter') - ->with($id)->willReturn($queryResult); + ->with($id)->willReturn($queryResult->setAffectedNumRows(0)); $this->assertFalse($this->account->incrementDecryptCounter($id)); } diff --git a/tests/SPT/Domain/Auth/Services/AuthTokenTest.php b/tests/SPT/Domain/Auth/Services/AuthTokenTest.php index aff66d78..ab879fb8 100644 --- a/tests/SPT/Domain/Auth/Services/AuthTokenTest.php +++ b/tests/SPT/Domain/Auth/Services/AuthTokenTest.php @@ -81,13 +81,12 @@ class AuthTokenTest extends UnitaryTestCase $ids = array_map(fn() => self::$faker->randomNumber(), range(0, 4)); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->authTokenRepository ->expects(self::once()) ->method('deleteByIdBatch') ->with($ids) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->authToken->deleteByIdBatch($ids); } @@ -149,7 +148,6 @@ class AuthTokenTest extends UnitaryTestCase ->willReturn(new QueryResult([$authToken])); $queryResult = new QueryResult([]); - $queryResult->setLastId(100); $this->authTokenRepository ->expects(self::once()) @@ -166,7 +164,7 @@ class AuthTokenTest extends UnitaryTestCase && $current->getCreatedBy() === $this->context->getUserData()->getId(); }) ) - ->willReturn($queryResult); + ->willReturn($queryResult->setLastId(100)); $out = $this->authToken->create($authToken); @@ -191,7 +189,6 @@ class AuthTokenTest extends UnitaryTestCase ->willReturn(new QueryResult([])); $queryResult = new QueryResult([]); - $queryResult->setLastId(100); $this->authTokenRepository ->expects(self::once()) @@ -208,7 +205,7 @@ class AuthTokenTest extends UnitaryTestCase && $current->getCreatedBy() === $this->context->getUserData()->getId(); }) ) - ->willReturn($queryResult); + ->willReturn($queryResult->setLastId(100)); $out = $this->authToken->create($authToken); @@ -238,7 +235,6 @@ class AuthTokenTest extends UnitaryTestCase ->willReturn(new QueryResult([$authToken])); $queryResult = new QueryResult([]); - $queryResult->setLastId(100); $this->authTokenRepository ->expects(self::once()) @@ -255,7 +251,7 @@ class AuthTokenTest extends UnitaryTestCase && $current->getCreatedBy() === $this->context->getUserData()->getId(); }) ) - ->willReturn($queryResult); + ->willReturn($queryResult->setLastId(100)); $password = $authToken->getHash() . $authToken->getToken(); @@ -522,13 +518,12 @@ class AuthTokenTest extends UnitaryTestCase $id = self::$faker->randomNumber(); $queryResult = new QueryResult([1]); - $queryResult->setAffectedNumRows(1); $this->authTokenRepository ->expects(self::once()) ->method('delete') ->with($id) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->authToken->delete($id); } diff --git a/tests/SPT/Domain/Category/Services/CategoryTest.php b/tests/SPT/Domain/Category/Services/CategoryTest.php index 6797d4d2..2b96d916 100644 --- a/tests/SPT/Domain/Category/Services/CategoryTest.php +++ b/tests/SPT/Domain/Category/Services/CategoryTest.php @@ -122,13 +122,12 @@ class CategoryTest extends UnitaryTestCase $id = self::$faker->randomNumber(); $queryResult = new QueryResult([1]); - $queryResult->setAffectedNumRows(1); $this->categoryRepository ->expects(self::once()) ->method('delete') ->with($id) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->category->delete($id); } @@ -251,13 +250,12 @@ class CategoryTest extends UnitaryTestCase $ids = array_map(fn() => self::$faker->randomNumber(), range(0, 4)); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->categoryRepository ->expects(self::once()) ->method('deleteByIdBatch') ->with($ids) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->category->deleteByIdBatch($ids); } diff --git a/tests/SPT/Domain/Client/Services/ClientTest.php b/tests/SPT/Domain/Client/Services/ClientTest.php index ed2a1c48..ce596a21 100644 --- a/tests/SPT/Domain/Client/Services/ClientTest.php +++ b/tests/SPT/Domain/Client/Services/ClientTest.php @@ -124,13 +124,12 @@ class ClientTest extends UnitaryTestCase $id = self::$faker->randomNumber(); $queryResult = new QueryResult([1]); - $queryResult->setAffectedNumRows(1); $this->clientRepository ->expects(self::once()) ->method('delete') ->with($id) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->client->delete($id); } @@ -253,13 +252,12 @@ class ClientTest extends UnitaryTestCase $ids = array_map(fn() => self::$faker->randomNumber(), range(0, 4)); $queryResult = new QueryResult(); - $queryResult->setAffectedNumRows(1); $this->clientRepository ->expects(self::once()) ->method('deleteByIdBatch') ->with($ids) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->client->deleteByIdBatch($ids); } diff --git a/tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php b/tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php index d987193e..0d59c5c3 100644 --- a/tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php +++ b/tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php @@ -32,7 +32,7 @@ use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Crypt\CryptInterface; use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; -use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\CustomField\Services\CustomFieldCrypt; use SP\Domain\Task\Ports\TaskInterface; use SP\Domain\Task\Services\TaskFactory; @@ -48,8 +48,8 @@ use SPT\UnitaryTestCase; class CustomFieldCryptTest extends UnitaryTestCase { - private CustomFieldService|MockObject $customFieldService; - private CryptInterface|MockObject $crypt; + private CustomFieldDataService|MockObject $customFieldService; + private CryptInterface|MockObject $crypt; private CustomFieldCrypt $customFieldCrypt; /** @@ -211,7 +211,7 @@ class CustomFieldCryptTest extends UnitaryTestCase { parent::setUp(); - $this->customFieldService = $this->createMock(CustomFieldService::class); + $this->customFieldService = $this->createMock(CustomFieldDataService::class); $this->crypt = $this->createMock(CryptInterface::class); $this->customFieldCrypt = new CustomFieldCrypt($this->application, $this->customFieldService, $this->crypt); diff --git a/tests/SPT/Domain/CustomField/Services/CustomFieldDataTest.php b/tests/SPT/Domain/CustomField/Services/CustomFieldDataTest.php new file mode 100644 index 00000000..49534e32 --- /dev/null +++ b/tests/SPT/Domain/CustomField/Services/CustomFieldDataTest.php @@ -0,0 +1,701 @@ +. + */ + +namespace SPT\Domain\CustomField\Services; + +use PHPUnit\Framework\Constraint\Callback; +use PHPUnit\Framework\MockObject\Exception; +use PHPUnit\Framework\MockObject\MockObject; +use RuntimeException; +use SP\Core\Context\ContextException; +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Core\Context\ContextInterface; +use SP\Domain\Core\Crypt\CryptInterface; +use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\Core\Exceptions\SPException; +use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; +use SP\Domain\CustomField\Models\CustomFieldDefinition as CustomFieldDefinitionModel; +use SP\Domain\CustomField\Ports\CustomFieldDataRepository; +use SP\Domain\CustomField\Ports\CustomFieldDefinitionRepository; +use SP\Domain\CustomField\Services\CustomFieldData; +use SP\Infrastructure\Database\QueryResult; +use SPT\Generators\CustomFieldDataGenerator; +use SPT\UnitaryTestCase; +use TypeError; + +/** + * Class CustomFieldDataTest + * + * @group unitary + */ +class CustomFieldDataTest extends UnitaryTestCase +{ + + private CustomFieldDataRepository|MockObject $customFieldDataRepository; + private CustomFieldDefinitionRepository|MockObject $customFieldDefinitionRepository; + private CryptInterface|MockObject $crypt; + private CustomFieldData $customFieldData; + + /** + * @throws ServiceException + */ + public function testDelete() + { + $itemsId = array_map(static fn() => self::$faker->randomNumber(), range(0, 5)); + $moduleId = self::$faker->randomNumber(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('deleteBatch') + ->with($itemsId, $moduleId); + + $this->customFieldData->delete($itemsId, $moduleId); + } + + /** + * @throws ServiceException + */ + public function testDeleteWithConstraintError() + { + $itemsId = array_map(static fn() => self::$faker->randomNumber(), range(0, 5)); + $moduleId = self::$faker->randomNumber(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('deleteBatch') + ->willThrowException(ConstraintException::error('test')); + + $this->expectException(ServiceException::class); + + $this->customFieldData->delete($itemsId, $moduleId); + } + + /** + * @throws ServiceException + */ + public function testDeleteWithQueryError() + { + $itemsId = array_map(static fn() => self::$faker->randomNumber(), range(0, 5)); + $moduleId = self::$faker->randomNumber(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('deleteBatch') + ->willThrowException(QueryException::error('test')); + + $this->expectException(ServiceException::class); + + $this->customFieldData->delete($itemsId, $moduleId); + } + + /** + * @throws Exception + * @throws ServiceException + * @throws ContextException + */ + public function testCreateWithEncrypted() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + $customFieldDefinition = $this->createMock(CustomFieldDefinitionModel::class); + $customFieldDefinition->expects(self::once()) + ->method('getIsEncrypted') + ->willReturn(1); + + $this->customFieldDefinitionRepository + ->expects(self::once()) + ->method('getById') + ->with($customFieldData->getDefinitionId()) + ->willReturn(new QueryResult([$customFieldDefinition])); + + $this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret'); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with('secret') + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', 'secret') + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('create') + ->with( + new Callback(static function (CustomFieldDataModel $current) use ($customFieldData) { + return $current->getData() === 'secret_data' + && $current->getKey() === 'secret_key' + && $customFieldData->getDefinitionId() === $current->getDefinitionId() + && $customFieldData->getItemId() === $current->getItemId() + && $customFieldData->getModuleId() === $current->getModuleId(); + }) + ); + + $this->customFieldData->create($customFieldData); + } + + /** + * @throws Exception + * @throws ServiceException + */ + public function testCreateWithNoEncrypted() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + $customFieldDefinition = $this->createMock(CustomFieldDefinitionModel::class); + $customFieldDefinition->expects(self::once()) + ->method('getIsEncrypted') + ->willReturn(0); + + $this->customFieldDefinitionRepository + ->expects(self::once()) + ->method('getById') + ->with($customFieldData->getDefinitionId()) + ->willReturn(new QueryResult([$customFieldDefinition])); + + $this->crypt + ->expects(self::never()) + ->method('makeSecuredKey'); + + $this->crypt + ->expects(self::never()) + ->method('encrypt'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('create') + ->with($customFieldData); + + $this->customFieldData->create($customFieldData); + } + + /** + * @throws Exception + * @throws ServiceException + * @throws ContextException + */ + public function testCreateWithEncryptedWithException() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + $customFieldDefinition = $this->createMock(CustomFieldDefinitionModel::class); + $customFieldDefinition->expects(self::once()) + ->method('getIsEncrypted') + ->willReturn(1); + + $this->customFieldDefinitionRepository + ->expects(self::once()) + ->method('getById') + ->with($customFieldData->getDefinitionId()) + ->willReturn(new QueryResult([$customFieldDefinition])); + + $this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret'); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with('secret') + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', 'secret') + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('create') + ->willThrowException(SPException::error('test')); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('test'); + + $this->customFieldData->create($customFieldData); + } + + /** + * @throws ServiceException + */ + public function testGetBy() + { + $moduleId = self::$faker->randomNumber(); + $itemId = self::$faker->randomNumber(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('getForModuleAndItemId') + ->with($moduleId, $itemId) + ->willReturn(new QueryResult([1])); + + $out = $this->customFieldData->getBy($moduleId, $itemId); + + $this->assertEquals([1], $out); + } + + /** + * @throws ServiceException + */ + public function testGetByWithException() + { + $moduleId = self::$faker->randomNumber(); + $itemId = self::$faker->randomNumber(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('getForModuleAndItemId') + ->with($moduleId, $itemId) + ->willThrowException(new RuntimeException('test')); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('test'); + + $this->customFieldData->getBy($moduleId, $itemId); + } + + /** + * @throws ServiceException + * @throws Exception + * @throws ContextException + */ + public function testUpdateOrCreateWithNonExisting() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('checkExists') + ->with($customFieldData->getItemId(), $customFieldData->getModuleId(), $customFieldData->getDefinitionId()) + ->willReturn(false); + + $customFieldDefinition = $this->createMock(CustomFieldDefinitionModel::class); + $customFieldDefinition->expects(self::once()) + ->method('getIsEncrypted') + ->willReturn(1); + + $this->customFieldDefinitionRepository + ->expects(self::once()) + ->method('getById') + ->with($customFieldData->getDefinitionId()) + ->willReturn(new QueryResult([$customFieldDefinition])); + + $this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret'); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with('secret') + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', 'secret') + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('create') + ->with( + new Callback(static function (CustomFieldDataModel $current) use ($customFieldData) { + return $current->getData() === 'secret_data' + && $current->getKey() === 'secret_key' + && $customFieldData->getDefinitionId() === $current->getDefinitionId() + && $customFieldData->getItemId() === $current->getItemId() + && $customFieldData->getModuleId() === $current->getModuleId(); + }) + ); + + $this->customFieldData->updateOrCreate($customFieldData); + } + + /** + * @throws ServiceException + * @throws Exception + * @throws ContextException + */ + public function testUpdateOrCreateWithNonExistingAndException() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('checkExists') + ->with($customFieldData->getItemId(), $customFieldData->getModuleId(), $customFieldData->getDefinitionId()) + ->willReturn(false); + + $customFieldDefinition = $this->createMock(CustomFieldDefinitionModel::class); + $customFieldDefinition->expects(self::once()) + ->method('getIsEncrypted') + ->willReturn(1); + + $this->customFieldDefinitionRepository + ->expects(self::once()) + ->method('getById') + ->with($customFieldData->getDefinitionId()) + ->willReturn(new QueryResult([$customFieldDefinition])); + + $this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret'); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with('secret') + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', 'secret') + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('create') + ->willThrowException(SPException::error('test')); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('test'); + + $this->customFieldData->updateOrCreate($customFieldData); + } + + /** + * @throws ServiceException + * @throws Exception + * @throws ContextException + */ + public function testUpdateOrCreateWithExisting() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('checkExists') + ->with($customFieldData->getItemId(), $customFieldData->getModuleId(), $customFieldData->getDefinitionId()) + ->willReturn(true); + + $customFieldDefinition = $this->createMock(CustomFieldDefinitionModel::class); + $customFieldDefinition->expects(self::once()) + ->method('getIsEncrypted') + ->willReturn(1); + + $this->customFieldDefinitionRepository + ->expects(self::once()) + ->method('getById') + ->with($customFieldData->getDefinitionId()) + ->willReturn(new QueryResult([$customFieldDefinition])); + + $this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret'); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with('secret') + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', 'secret') + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('update') + ->with( + new Callback(static function (CustomFieldDataModel $current) use ($customFieldData) { + return $current->getData() === 'secret_data' + && $current->getKey() === 'secret_key' + && $customFieldData->getDefinitionId() === $current->getDefinitionId() + && $customFieldData->getItemId() === $current->getItemId() + && $customFieldData->getModuleId() === $current->getModuleId(); + }) + ); + + $this->customFieldData->updateOrCreate($customFieldData); + } + + /** + * @throws ServiceException + * @throws Exception + * @throws ContextException + */ + public function testUpdateOrCreateWithExistingAndException() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('checkExists') + ->with($customFieldData->getItemId(), $customFieldData->getModuleId(), $customFieldData->getDefinitionId()) + ->willReturn(true); + + $customFieldDefinition = $this->createMock(CustomFieldDefinitionModel::class); + $customFieldDefinition->expects(self::once()) + ->method('getIsEncrypted') + ->willReturn(1); + + $this->customFieldDefinitionRepository + ->expects(self::once()) + ->method('getById') + ->with($customFieldData->getDefinitionId()) + ->willReturn(new QueryResult([$customFieldDefinition])); + + $this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret'); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with('secret') + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', 'secret') + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('update') + ->willThrowException(SPException::error('test')); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('test'); + + $this->customFieldData->updateOrCreate($customFieldData); + } + + /** + * @throws ServiceException + * @throws ContextException + */ + public function testDecrypt() + { + $data = self::$faker->text(); + $key = self::$faker->password(); + + $this->context->setTrasientKey(ContextInterface::MASTER_PASSWORD_KEY, 'secret'); + + $this->crypt + ->expects(self::once()) + ->method('decrypt') + ->with($data, $key, 'secret') + ->willReturn('secret_data'); + + $out = $this->customFieldData->decrypt($data, $key); + + $this->assertEquals('secret_data', $out); + } + + /** + * @throws ServiceException + */ + public function testDecryptWithNoData() + { + $key = self::$faker->password(); + + $this->crypt + ->expects(self::never()) + ->method('decrypt'); + + $out = $this->customFieldData->decrypt('', $key); + + $this->assertEquals(null, $out); + } + + /** + * @throws ServiceException + */ + public function testDecryptWithNoKey() + { + $data = self::$faker->text(); + + $this->crypt + ->expects(self::never()) + ->method('decrypt'); + + $out = $this->customFieldData->decrypt($data, ''); + + $this->assertEquals(null, $out); + } + + public function testGetAll() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $queryResult = new QueryResult([$customFieldData]); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('getAll') + ->willReturn($queryResult); + + $out = $this->customFieldData->getAll(); + + $this->assertEquals([$customFieldData], $out); + } + + public function testGetAllWithWrongType() + { + $queryResult = new QueryResult([1]); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('getAll') + ->willReturn($queryResult); + + $this->expectException(TypeError::class); + + $this->customFieldData->getAll(); + } + + public function testGetAllEncrypted() + { + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $queryResult = new QueryResult([$customFieldData]); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('getAllEncrypted') + ->willReturn($queryResult); + + $out = $this->customFieldData->getAllEncrypted(); + + $this->assertEquals([$customFieldData], $out); + } + + public function testGetAllEncryptedWithWrongType() + { + $queryResult = new QueryResult([1]); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('getAllEncrypted') + ->willReturn($queryResult); + + $this->expectException(TypeError::class); + + $this->customFieldData->getAllEncrypted(); + } + + /** + * @throws Exception + * @throws ServiceException + */ + public function testUpdateMasterPass() + { + $password = self::$faker->password(); + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with($password) + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', $password) + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('update') + ->with( + new Callback(static function (CustomFieldDataModel $current) use ($customFieldData) { + return $current->getData() === 'secret_data' + && $current->getKey() === 'secret_key' + && $customFieldData->getDefinitionId() === $current->getDefinitionId() + && $customFieldData->getItemId() === $current->getItemId() + && $customFieldData->getModuleId() === $current->getModuleId(); + }) + ); + + $this->customFieldData->updateMasterPass($customFieldData, $password); + } + + /** + * @throws Exception + * @throws ServiceException + */ + public function testUpdateMasterPassWithException() + { + $password = self::$faker->password(); + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->crypt + ->expects(self::once()) + ->method('makeSecuredKey') + ->with($password) + ->willReturn('secret_key'); + + $this->crypt + ->expects(self::once()) + ->method('encrypt') + ->with($customFieldData->getData(), 'secret_key', $password) + ->willReturn('secret_data'); + + $this->customFieldDataRepository + ->expects(self::once()) + ->method('update') + ->with( + new Callback(static function (CustomFieldDataModel $current) use ($customFieldData) { + return $current->getData() === 'secret_data' + && $current->getKey() === 'secret_key' + && $customFieldData->getDefinitionId() === $current->getDefinitionId() + && $customFieldData->getItemId() === $current->getItemId() + && $customFieldData->getModuleId() === $current->getModuleId(); + }) + ) + ->willThrowException(SPException::error('test')); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('test'); + + $this->customFieldData->updateMasterPass($customFieldData, $password); + } + + protected function setUp(): void + { + parent::setUp(); + + $this->customFieldDataRepository = $this->createMock(CustomFieldDataRepository::class); + $this->customFieldDefinitionRepository = $this->createMock(CustomFieldDefinitionRepository::class); + $this->crypt = $this->createMock(CryptInterface::class); + + $this->customFieldData = new CustomFieldData( + $this->application, + $this->customFieldDataRepository, + $this->customFieldDefinitionRepository, + $this->crypt + ); + } + +} diff --git a/tests/SPT/Generators/AccountDataGenerator.php b/tests/SPT/Generators/AccountDataGenerator.php index 45b252e6..6ad95dee 100644 --- a/tests/SPT/Generators/AccountDataGenerator.php +++ b/tests/SPT/Generators/AccountDataGenerator.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -30,8 +30,8 @@ use SP\Domain\Account\Dtos\AccountEnrichedDto; use SP\Domain\Account\Dtos\AccountHistoryDto; use SP\Domain\Account\Dtos\AccountUpdateDto; use SP\Domain\Account\Models\Account; -use SP\Domain\Account\Models\AccountView; use SP\Domain\Account\Models\AccountSearchView; +use SP\Domain\Account\Models\AccountView; use SP\Domain\Common\Models\Simple; /** @@ -59,18 +59,18 @@ final class AccountDataGenerator extends DataGenerator private function getAccountProperties(): array { return [ - 'id' => $this->faker->randomNumber(), + 'id' => $this->faker->randomNumber(2), 'name' => $this->faker->name, - 'clientId' => $this->faker->randomNumber(), + 'clientId' => $this->faker->randomNumber(2), 'clientName' => $this->faker->name, - 'categoryId' => $this->faker->randomNumber(), + 'categoryId' => $this->faker->randomNumber(2), 'categoryName' => $this->faker->name, - 'userId' => $this->faker->randomNumber(), + 'userId' => $this->faker->randomNumber(2), 'userName' => $this->faker->userName, 'userLogin' => $this->faker->name, - 'userGroupId' => $this->faker->randomNumber(), + 'userGroupId' => $this->faker->randomNumber(2), 'userGroupName' => $this->faker->name, - 'userEditId' => $this->faker->randomNumber(), + 'userEditId' => $this->faker->randomNumber(2), 'userEditName' => $this->faker->userName, 'userEditLogin' => $this->faker->name, 'login' => $this->faker->name, @@ -80,13 +80,13 @@ final class AccountDataGenerator extends DataGenerator 'otherUserGroupEdit' => $this->faker->boolean, 'dateAdd' => $this->faker->unixTime, 'dateEdit' => $this->faker->unixTime, - 'countView' => $this->faker->randomNumber(), - 'countDecrypt' => $this->faker->randomNumber(), + 'countView' => $this->faker->randomNumber(2), + 'countDecrypt' => $this->faker->randomNumber(2), 'isPrivate' => $this->faker->boolean, 'isPrivateGroup' => $this->faker->boolean, 'passDate' => $this->faker->unixTime, 'passDateChange' => $this->faker->unixTime, - 'parentId' => $this->faker->randomNumber(), + 'parentId' => $this->faker->randomNumber(2), 'publicLinkHash' => $this->faker->sha1, 'pass' => $this->faker->password, 'key' => $this->faker->sha1, @@ -99,7 +99,7 @@ final class AccountDataGenerator extends DataGenerator public function buildItemData(): array { return array_map( - fn() => new ItemData(['id' => $this->faker->randomNumber(), 'name' => $this->faker->name]), + fn() => new ItemData(['id' => $this->faker->randomNumber(2), 'name' => $this->faker->name]), range(0, 9) ); } @@ -109,9 +109,9 @@ final class AccountDataGenerator extends DataGenerator return new AccountSearchView( array_merge( [ - 'num_files' => $this->faker->randomNumber(), + 'num_files' => $this->faker->randomNumber(2), 'publicLinkDateExpire' => $this->faker->unixTime, - 'publicLinkTotalCountViews' => $this->faker->randomNumber(), + 'publicLinkTotalCountViews' => $this->faker->randomNumber(2), ], $this->getAccountProperties() ) @@ -126,21 +126,21 @@ final class AccountDataGenerator extends DataGenerator public function buildAccountHistoryData(): Simple { return new Simple([ - 'id' => $this->faker->randomNumber(), - 'accountId' => $this->faker->randomNumber(), + 'id' => $this->faker->randomNumber(2), + 'accountId' => $this->faker->randomNumber(2), 'name' => $this->faker->name, 'login' => $this->faker->userName, 'url' => $this->faker->url, 'notes' => $this->faker->text, - 'userEditId' => $this->faker->randomNumber(), + 'userEditId' => $this->faker->randomNumber(2), 'passDateChange' => $this->faker->unixTime, - 'clientId' => $this->faker->randomNumber(), - 'categoryId' => $this->faker->randomNumber(), + 'clientId' => $this->faker->randomNumber(2), + 'categoryId' => $this->faker->randomNumber(2), 'isPrivate' => $this->faker->numberBetween(0, 1), 'isPrivateGroup' => $this->faker->numberBetween(0, 1), - 'parentId' => $this->faker->randomNumber(), - 'userId' => $this->faker->randomNumber(), - 'userGroupId' => $this->faker->randomNumber(), + 'parentId' => $this->faker->randomNumber(2), + 'userId' => $this->faker->randomNumber(2), + 'userGroupId' => $this->faker->randomNumber(2), 'key' => $this->faker->text, 'pass' => $this->faker->text, ]); @@ -151,26 +151,26 @@ final class AccountDataGenerator extends DataGenerator return new AccountUpdateDto( name : $this->faker->name, login : $this->faker->userName, - clientId : $this->faker->randomNumber(), - categoryId : $this->faker->randomNumber(), + clientId: $this->faker->randomNumber(2), + categoryId: $this->faker->randomNumber(2), pass : $this->faker->password, - userId : $this->faker->randomNumber(), + userId: $this->faker->randomNumber(2), key : $this->faker->password, url : $this->faker->url, notes : $this->faker->text, - userEditId : $this->faker->randomNumber(), + userEditId: $this->faker->randomNumber(2), isPrivate : $this->faker->boolean, isPrivateGroup : $this->faker->boolean, passDateChange : $this->faker->unixTime, - parentId : $this->faker->randomNumber(), - userGroupId : $this->faker->randomNumber(), + parentId: $this->faker->randomNumber(2), + userGroupId: $this->faker->randomNumber(2), otherUserEdit : $this->faker->boolean, otherUserGroupEdit: $this->faker->boolean, - usersView : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - usersEdit : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - userGroupsView : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - userGroupsEdit : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - tags : array_map(fn() => $this->faker->randomNumber(), range(0, 4)) + usersView: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + usersEdit: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + userGroupsView: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + userGroupsEdit: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + tags: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)) ); } @@ -179,54 +179,54 @@ final class AccountDataGenerator extends DataGenerator return new AccountCreateDto( name : $this->faker->name, login : $this->faker->userName, - clientId : $this->faker->randomNumber(), - categoryId : $this->faker->randomNumber(), + clientId: $this->faker->randomNumber(2), + categoryId: $this->faker->randomNumber(2), pass : $this->faker->password, - userId : $this->faker->randomNumber(), + userId: $this->faker->randomNumber(2), url : $this->faker->url, notes : $this->faker->text, - userEditId : $this->faker->randomNumber(), + userEditId: $this->faker->randomNumber(2), isPrivate : $this->faker->boolean, isPrivateGroup : $this->faker->boolean, passDateChange : $this->faker->unixTime, - parentId : $this->faker->randomNumber(), - userGroupId : $this->faker->randomNumber(), + parentId: $this->faker->randomNumber(2), + userGroupId: $this->faker->randomNumber(2), otherUserEdit : $this->faker->boolean, otherUserGroupEdit: $this->faker->boolean, - usersView : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - usersEdit : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - userGroupsView : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - userGroupsEdit : array_map(fn() => $this->faker->randomNumber(), range(0, 4)), - tags : array_map(fn() => $this->faker->randomNumber(), range(0, 4)) + usersView: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + usersEdit: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + userGroupsView: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + userGroupsEdit: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)), + tags: array_map(fn() => $this->faker->randomNumber(2), range(0, 4)) ); } public function buildAccountHistoryDto(): AccountHistoryDto { return new AccountHistoryDto( - accountId : $this->faker->randomNumber(), + accountId: $this->faker->randomNumber(2), isDelete : $this->faker->boolean, isModify : $this->faker->boolean, dateAdd : $this->faker->unixTime, dateEdit : $this->faker->unixTime, passDate : $this->faker->unixTime, - countView : $this->faker->randomNumber(), - countDecrypt : $this->faker->randomNumber(), + countView: $this->faker->randomNumber(2), + countDecrypt: $this->faker->randomNumber(2), name : $this->faker->name, login : $this->faker->userName, - clientId : $this->faker->randomNumber(), - categoryId : $this->faker->randomNumber(), + clientId: $this->faker->randomNumber(2), + categoryId: $this->faker->randomNumber(2), pass : $this->faker->password, - userId : $this->faker->randomNumber(), + userId: $this->faker->randomNumber(2), key : $this->faker->password, url : $this->faker->url, notes : $this->faker->text, - userEditId : $this->faker->randomNumber(), + userEditId: $this->faker->randomNumber(2), isPrivate : $this->faker->boolean, isPrivateGroup : $this->faker->boolean, passDateChange : $this->faker->unixTime, - parentId : $this->faker->randomNumber(), - userGroupId : $this->faker->randomNumber(), + parentId: $this->faker->randomNumber(2), + userGroupId: $this->faker->randomNumber(2), otherUserEdit : $this->faker->boolean, otherUserGroupEdit: $this->faker->boolean, ); diff --git a/tests/SPT/Generators/CustomFieldDataGenerator.php b/tests/SPT/Generators/CustomFieldDataGenerator.php index f3e089fa..ddc27407 100644 --- a/tests/SPT/Generators/CustomFieldDataGenerator.php +++ b/tests/SPT/Generators/CustomFieldDataGenerator.php @@ -45,7 +45,6 @@ final class CustomFieldDataGenerator extends DataGenerator } return [ - 'id' => $this->faker->randomNumber(), 'moduleId' => $this->faker->randomNumber(), 'itemId' => $this->faker->randomNumber(), 'definitionId' => $this->faker->randomNumber(), diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php index e42ef131..3a006eef 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php @@ -157,8 +157,7 @@ class AccountFileTest extends UnitaryTestCase public function testDelete(): void { $id = 1; - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($id) { @@ -173,7 +172,7 @@ class AccountFileTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountFile->delete($id)); } diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountHistoryTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountHistoryTest.php index 1436737d..9a4825e8 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountHistoryTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountHistoryTest.php @@ -139,8 +139,7 @@ class AccountHistoryTest extends UnitaryTestCase $id = self::$faker->randomNumber(); $encryptedPassword = new EncryptedPassword(self::$faker->password, self::$faker->password, self::$faker->sha1); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($id, $encryptedPassword) { @@ -157,7 +156,7 @@ class AccountHistoryTest extends UnitaryTestCase $this->database->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountHistory->updatePassword($id, $encryptedPassword)); } @@ -295,8 +294,7 @@ class AccountHistoryTest extends UnitaryTestCase public function testDelete(): void { $id = 1; - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($id) { @@ -308,7 +306,7 @@ class AccountHistoryTest extends UnitaryTestCase $this->database->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountHistory->delete($id)); } diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountTest.php index 1c2c6bba..347d165f 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountTest.php @@ -570,7 +570,7 @@ class AccountTest extends UnitaryTestCase public function testGetByIdEnriched(): void { - $id = self::$faker->randomNumber(); + $id = self::$faker->randomNumber(2); $callback = new Callback( static function (QueryData $arg) use ($id) { @@ -608,7 +608,7 @@ class AccountTest extends UnitaryTestCase */ public function testDeleteByIdBatch(): void { - $ids = [self::$faker->randomNumber(), self::$faker->randomNumber(), self::$faker->randomNumber()]; + $ids = [self::$faker->randomNumber(2), self::$faker->randomNumber(2), self::$faker->randomNumber(2)]; $callback = new Callback( static function (QueryData $arg) use ($ids) { @@ -749,7 +749,7 @@ class AccountTest extends UnitaryTestCase public function testGetForUser(): void { - $id = self::$faker->randomNumber(); + $id = self::$faker->randomNumber(2); $callback = new Callback( function (QueryData $arg) use ($id) { diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountToFavoriteTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountToFavoriteTest.php index 041d3398..2a0d4aa8 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountToFavoriteTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountToFavoriteTest.php @@ -73,8 +73,7 @@ class AccountToFavoriteTest extends UnitaryTestCase $accountId = self::$faker->randomNumber(); $userId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($accountId, $userId) { @@ -91,7 +90,7 @@ class AccountToFavoriteTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToFavorite->delete($accountId, $userId)); } diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountToTagTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountToTagTest.php index 298dc223..8a671fc8 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountToTagTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountToTagTest.php @@ -79,8 +79,7 @@ class AccountToTagTest extends UnitaryTestCase { $accountId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($accountId) { @@ -96,7 +95,7 @@ class AccountToTagTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToTag->deleteByAccountId($accountId)); } diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php index 6f063ac3..b7a248cf 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php @@ -54,8 +54,7 @@ class AccountToUserGroupTest extends UnitaryTestCase { $accountId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($accountId) { @@ -71,7 +70,7 @@ class AccountToUserGroupTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToUserGroup->deleteByAccountId($accountId)); } @@ -107,8 +106,7 @@ class AccountToUserGroupTest extends UnitaryTestCase { $userGroupId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($userGroupId) { @@ -124,7 +122,7 @@ class AccountToUserGroupTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToUserGroup->deleteByUserGroupId($userGroupId)); } @@ -161,8 +159,7 @@ class AccountToUserGroupTest extends UnitaryTestCase { $accountId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($accountId) { @@ -178,7 +175,7 @@ class AccountToUserGroupTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToUserGroup->deleteByAccountId($accountId)); } diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php index f753db37..b819a469 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php @@ -54,8 +54,7 @@ class AccountToUserTest extends UnitaryTestCase { $accountId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($accountId) { @@ -71,7 +70,7 @@ class AccountToUserTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToUser->deleteByAccountId($accountId)); } @@ -107,8 +106,7 @@ class AccountToUserTest extends UnitaryTestCase { $accountId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($accountId) { @@ -124,7 +122,7 @@ class AccountToUserTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToUser->deleteByAccountId($accountId)); } @@ -161,8 +159,7 @@ class AccountToUserTest extends UnitaryTestCase { $accountId = self::$faker->randomNumber(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($accountId) { @@ -178,7 +175,7 @@ class AccountToUserTest extends UnitaryTestCase ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->accountToUser->deleteByAccountId($accountId)); } diff --git a/tests/SPT/Infrastructure/Account/Repositories/PublicLinkTest.php b/tests/SPT/Infrastructure/Account/Repositories/PublicLinkTest.php index e884146a..ad22b1c3 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/PublicLinkTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/PublicLinkTest.php @@ -150,8 +150,7 @@ class PublicLinkTest extends UnitaryTestCase { $publicLinkData = $this->buildPublicLinkData(); - $expected = new QueryResult(); - $expected->setAffectedNumRows(1); + $queryResult = new QueryResult(); $callback = new Callback( static function (QueryData $arg) use ($publicLinkData) { @@ -167,7 +166,7 @@ class PublicLinkTest extends UnitaryTestCase $this->database->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($expected); + ->willReturn($queryResult->setAffectedNumRows(1)); $this->assertTrue($this->publicLink->addLinkView($publicLinkData)); } diff --git a/tests/SPT/Infrastructure/Auth/Repositories/AuthTokenTest.php b/tests/SPT/Infrastructure/Auth/Repositories/AuthTokenTest.php index 52e8a4e1..29a12d1d 100644 --- a/tests/SPT/Infrastructure/Auth/Repositories/AuthTokenTest.php +++ b/tests/SPT/Infrastructure/Auth/Repositories/AuthTokenTest.php @@ -317,13 +317,12 @@ class AuthTokenTest extends UnitaryTestCase ); $queryResult = new QueryResult([1]); - $queryResult->setAffectedNumRows(10); $this->database ->expects(self::once()) ->method('doQuery') ->with($callback) - ->willReturn($queryResult); + ->willReturn($queryResult->setAffectedNumRows(10)); $out = $this->authToken->refreshVaultByUserId($userId, $vault, $hash);