diff --git a/app/modules/api/Controllers/UserGroup/CreateController.php b/app/modules/api/Controllers/UserGroup/CreateController.php
index a4ea9c87..50575b5e 100644
--- a/app/modules/api/Controllers/UserGroup/CreateController.php
+++ b/app/modules/api/Controllers/UserGroup/CreateController.php
@@ -28,10 +28,10 @@ namespace SP\Modules\Api\Controllers\UserGroup;
use Exception;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\DataModel\UserGroupData;
use SP\Domain\Api\Dtos\ApiResponse;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Acl\AclActionsInterface;
+use SP\Domain\User\Models\UserGroup;
/**
* Class CreateController
@@ -71,12 +71,12 @@ final class CreateController extends UserGroupBase
}
/**
- * @return UserGroupData
+ * @return UserGroup
* @throws ServiceException
*/
- private function buildUserGroupData(): UserGroupData
+ private function buildUserGroupData(): UserGroup
{
- $userGroupData = new UserGroupData();
+ $userGroupData = new UserGroup();
$userGroupData->setName($this->apiService->getParamString('name', true));
$userGroupData->setDescription($this->apiService->getParamString('description'));
$userGroupData->setUsers($this->apiService->getParamArray('usersId'));
diff --git a/app/modules/api/Controllers/UserGroup/EditController.php b/app/modules/api/Controllers/UserGroup/EditController.php
index c447930a..6db0f849 100644
--- a/app/modules/api/Controllers/UserGroup/EditController.php
+++ b/app/modules/api/Controllers/UserGroup/EditController.php
@@ -28,10 +28,10 @@ namespace SP\Modules\Api\Controllers\UserGroup;
use Exception;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\DataModel\UserGroupData;
use SP\Domain\Api\Dtos\ApiResponse;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Acl\AclActionsInterface;
+use SP\Domain\User\Models\UserGroup;
/**
* Class EditController
@@ -73,12 +73,12 @@ final class EditController extends UserGroupBase
}
/**
- * @return UserGroupData
+ * @return UserGroup
* @throws ServiceException
*/
- private function buildUserGroupData(): UserGroupData
+ private function buildUserGroupData(): UserGroup
{
- $userGroupData = new UserGroupData();
+ $userGroupData = new UserGroup();
$userGroupData->setId($this->apiService->getParamInt('id', true));
$userGroupData->setName($this->apiService->getParamString('name', true));
$userGroupData->setDescription($this->apiService->getParamString('description'));
diff --git a/app/modules/web/Controllers/ConfigLdap/ImportController.php b/app/modules/web/Controllers/ConfigLdap/ImportController.php
index e251cabb..c3de56d3 100644
--- a/app/modules/web/Controllers/ConfigLdap/ImportController.php
+++ b/app/modules/web/Controllers/ConfigLdap/ImportController.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.
*
@@ -28,7 +28,6 @@ namespace SP\Modules\Web\Controllers\ConfigLdap;
use Exception;
use JsonException;
use Klein\Klein;
-use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
@@ -42,7 +41,7 @@ use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\Exceptions\ValidationException;
use SP\Domain\Core\UI\ThemeInterface;
use SP\Domain\Http\RequestInterface;
-use SP\Domain\Import\Ports\LdapImportServiceInterface;
+use SP\Domain\Import\Ports\LdapImportService;
use SP\Domain\Import\Services\LdapImportParams;
use SP\Http\JsonMessage;
use SP\Modules\Web\Controllers\SimpleControllerBase;
@@ -56,7 +55,7 @@ final class ImportController extends SimpleControllerBase
use ConfigLdapTrait;
use JsonTrait;
- private LdapImportServiceInterface $ldapImportService;
+ private LdapImportService $ldapImportService;
public function __construct(
Application $application,
@@ -65,7 +64,7 @@ final class ImportController extends SimpleControllerBase
AclInterface $acl,
RequestInterface $request,
PhpExtensionChecker $extensionChecker,
- LdapImportServiceInterface $ldapImportService
+ LdapImportService $ldapImportService
) {
parent::__construct($application, $theme);
diff --git a/app/modules/web/Controllers/User/EditPassController.php b/app/modules/web/Controllers/User/EditPassController.php
index 4f23d101..a781cc41 100644
--- a/app/modules/web/Controllers/User/EditPassController.php
+++ b/app/modules/web/Controllers/User/EditPassController.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.
*
@@ -28,7 +28,7 @@ namespace SP\Modules\Web\Controllers\User;
use Exception;
use JsonException;
use SP\Core\Events\Event;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Http\JsonMessage;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
@@ -67,7 +67,7 @@ final class EditPassController extends UserViewBase
$user = $id
? $this->userService->getById($id)
- : new UserData();
+ : new User();
$this->view->assign('user', $user);
diff --git a/app/modules/web/Controllers/User/UserSaveBase.php b/app/modules/web/Controllers/User/UserSaveBase.php
index e2f6fd57..ddd6c98d 100644
--- a/app/modules/web/Controllers/User/UserSaveBase.php
+++ b/app/modules/web/Controllers/User/UserSaveBase.php
@@ -28,7 +28,7 @@ namespace SP\Modules\Web\Controllers\User;
use Defuse\Crypto\Exception\EnvironmentIsBrokenException;
use PHPMailer\PHPMailer\Exception;
use SP\Core\Application;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
@@ -73,7 +73,7 @@ abstract class UserSaveBase extends ControllerBase
/**
* @param int $userId
- * @param UserData $userData
+ * @param User $userData
*
* @throws EnvironmentIsBrokenException
* @throws Exception
@@ -81,7 +81,7 @@ abstract class UserSaveBase extends ControllerBase
* @throws QueryException
* @throws ServiceException
*/
- final protected function checkChangeUserPass(int $userId, UserData $userData): void
+ final protected function checkChangeUserPass(int $userId, User $userData): void
{
if ($userData->isChangePass()) {
$hash = $this->userPassRecoverService->requestForUserId($userId);
diff --git a/app/modules/web/Controllers/User/UserViewBase.php b/app/modules/web/Controllers/User/UserViewBase.php
index e7ddaeaa..5757ea17 100644
--- a/app/modules/web/Controllers/User/UserViewBase.php
+++ b/app/modules/web/Controllers/User/UserViewBase.php
@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\User;
use SP\Core\Acl\Acl;
use SP\Core\Application;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
@@ -88,7 +88,7 @@ abstract class UserViewBase extends ControllerBase
$user = $userId
? $this->userService->getById($userId)
- : new UserData();
+ : new User();
$this->view->assign('user', $user);
$this->view->assign(
diff --git a/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php b/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php
index 488c8660..94bbe09a 100644
--- a/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php
+++ b/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php
@@ -27,13 +27,13 @@ namespace SP\Modules\Web\Controllers\UserGroup;
use SP\Core\Acl\Acl;
use SP\Core\Application;
-use SP\DataModel\UserGroupData;
use SP\Domain\Common\Services\ServiceException;
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\CustomFieldDataService;
+use SP\Domain\User\Models\UserGroup;
use SP\Domain\User\Ports\UserGroupServiceInterface;
use SP\Domain\User\Ports\UserServiceInterface;
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
@@ -86,7 +86,7 @@ abstract class UserGroupViewBase extends ControllerBase
$userGroupData = $userGroupId
? $this->userGroupService->getById($userGroupId)
- : new UserGroupData();
+ : new UserGroup();
$this->view->assign('group', $userGroupData);
diff --git a/app/modules/web/Forms/UserForm.php b/app/modules/web/Forms/UserForm.php
index 4495cd66..490ada6a 100644
--- a/app/modules/web/Forms/UserForm.php
+++ b/app/modules/web/Forms/UserForm.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.
*
@@ -24,7 +24,7 @@
namespace SP\Modules\Web\Forms;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\Exceptions\ValidationException;
@@ -36,8 +36,8 @@ use SP\Domain\Core\Exceptions\ValidationException;
*/
final class UserForm extends FormBase implements FormInterface
{
- protected ?UserData $userData = null;
- protected int $isLdap = 0;
+ protected ?User $userData = null;
+ protected int $isLdap = 0;
/**
* Validar el formulario
@@ -85,7 +85,7 @@ final class UserForm extends FormBase implements FormInterface
{
$this->isLdap = $this->request->analyzeInt('isLdap', 0);
- $this->userData = new UserData();
+ $this->userData = new User();
$this->userData->setId($this->itemId);
$this->userData->setName($this->request->analyzeString('name'));
$this->userData->setLogin($this->request->analyzeString('login'));
@@ -184,7 +184,7 @@ final class UserForm extends FormBase implements FormInterface
/**
* @throws SPException
*/
- public function getItemData(): UserData
+ public function getItemData(): User
{
if (null === $this->userData) {
throw new SPException(__u('User data not set'));
diff --git a/app/modules/web/Forms/UserGroupForm.php b/app/modules/web/Forms/UserGroupForm.php
index b9d9259b..54735de0 100644
--- a/app/modules/web/Forms/UserGroupForm.php
+++ b/app/modules/web/Forms/UserGroupForm.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.
*
@@ -24,10 +24,10 @@
namespace SP\Modules\Web\Forms;
-use SP\DataModel\UserGroupData;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Core\Exceptions\ValidationException;
+use SP\Domain\User\Models\UserGroup;
/**
* Class UserGroupForm
@@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ValidationException;
*/
final class UserGroupForm extends FormBase implements FormInterface
{
- protected ?UserGroupData $groupData = null;
+ protected ?UserGroup $groupData = null;
/**
* Validar el formulario
@@ -71,7 +71,7 @@ final class UserGroupForm extends FormBase implements FormInterface
*/
protected function analyzeRequestData(): void
{
- $this->groupData = new UserGroupData();
+ $this->groupData = new UserGroup();
$this->groupData->setId($this->itemId);
$this->groupData->setName($this->request->analyzeString('name'));
$this->groupData->setDescription($this->request->analyzeString('description'));
@@ -91,7 +91,7 @@ final class UserGroupForm extends FormBase implements FormInterface
/**
* @throws SPException
*/
- public function getItemData(): UserGroupData
+ public function getItemData(): UserGroup
{
if (null === $this->groupData) {
throw new SPException(__u('Group data not set'));
diff --git a/app/modules/web/themes/material-blue/views/itemshow/user.inc b/app/modules/web/themes/material-blue/views/itemshow/user.inc
index 2288a958..6ad49f30 100644
--- a/app/modules/web/themes/material-blue/views/itemshow/user.inc
+++ b/app/modules/web/themes/material-blue/views/itemshow/user.inc
@@ -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.
*
@@ -23,14 +23,14 @@
*/
/**
- * @var UserData $user
- * @var \SP\Domain\Core\UI\ThemeIconsInterface $icons
+ * @var User $user
+ * @var ThemeIconsInterface $icons
* @var ConfigDataInterface $configData
* @var callable $_getvar
* @var TemplateInterface $this
*/
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\UI\ThemeIconsInterface;
use SP\Mvc\View\Components\SelectItem;
diff --git a/app/modules/web/themes/material-blue/views/itemshow/user_group.inc b/app/modules/web/themes/material-blue/views/itemshow/user_group.inc
index 0bf3ca62..1ad9dfc7 100644
--- a/app/modules/web/themes/material-blue/views/itemshow/user_group.inc
+++ b/app/modules/web/themes/material-blue/views/itemshow/user_group.inc
@@ -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.
*
@@ -24,17 +24,17 @@
/**
* @var UserToUserGroupData $groupUsers
- * @var UserGroupData $group
+ * @var UserGroup $group
* @var ThemeIconsInterface $icons
* @var ConfigDataInterface $configData
* @var callable $_getvar
* @var TemplateInterface $this
*/
-use SP\DataModel\UserGroupData;
use SP\DataModel\UserToUserGroupData;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\UI\ThemeIconsInterface;
+use SP\Domain\User\Models\UserGroup;
use SP\Mvc\View\Components\SelectItem;
use SP\Mvc\View\TemplateInterface;
diff --git a/app/modules/web/themes/material-blue/views/itemshow/user_pass.inc b/app/modules/web/themes/material-blue/views/itemshow/user_pass.inc
index 21a30848..602ee8d2 100644
--- a/app/modules/web/themes/material-blue/views/itemshow/user_pass.inc
+++ b/app/modules/web/themes/material-blue/views/itemshow/user_pass.inc
@@ -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.
*
@@ -23,15 +23,16 @@
*/
/**
- * @var UserData $user
- * @var \SP\Domain\Core\UI\ThemeIconsInterface $icons
+ * @var User $user
+ * @var ThemeIconsInterface $icons
* @var ConfigDataInterface $configData
* @var callable $_getvar
* @var TemplateInterface $this
*/
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\Domain\Config\Ports\ConfigDataInterface;
+use SP\Domain\Core\UI\ThemeIconsInterface;
use SP\Mvc\View\TemplateInterface;
$user = $_getvar('user');
diff --git a/lib/SP/DataModel/UserData.php b/lib/SP/DataModel/User.php
similarity index 95%
rename from lib/SP/DataModel/UserData.php
rename to lib/SP/DataModel/User.php
index 42ff8f3a..e65aff0f 100644
--- a/lib/SP/DataModel/UserData.php
+++ b/lib/SP/DataModel/User.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.
*
@@ -26,14 +26,12 @@ namespace SP\DataModel;
use SP\Domain\Common\Adapters\DataModelInterface;
-defined('APP_ROOT') || die();
-
/**
* Class UserBasicData
*
* @package SP\DataModel
*/
-class UserData extends UserPassData implements DataModelInterface
+class User extends UserPassData implements DataModelInterface
{
protected ?string $login = null;
protected ?string $ssoLogin = null;
diff --git a/lib/SP/Domain/Import/Services/FileImportService.php b/lib/SP/Domain/Import/Ports/FileImportService.php
similarity index 97%
rename from lib/SP/Domain/Import/Services/FileImportService.php
rename to lib/SP/Domain/Import/Ports/FileImportService.php
index 8122a4a7..f538ca62 100644
--- a/lib/SP/Domain/Import/Services/FileImportService.php
+++ b/lib/SP/Domain/Import/Ports/FileImportService.php
@@ -22,7 +22,7 @@
* along with sysPass. If not, see .
*/
-namespace SP\Domain\Import\Services;
+namespace SP\Domain\Import\Ports;
use SP\Infrastructure\File\FileException;
use SP\Infrastructure\File\FileHandlerInterface;
diff --git a/lib/SP/Domain/Import/Ports/ImportService.php b/lib/SP/Domain/Import/Ports/ImportService.php
new file mode 100644
index 00000000..d1fddc03
--- /dev/null
+++ b/lib/SP/Domain/Import/Ports/ImportService.php
@@ -0,0 +1,44 @@
+.
+ */
+
+namespace SP\Domain\Import\Ports;
+
+/**
+ * Interface ImportService
+ */
+interface ImportService
+{
+ /**
+ * @param ImportParams $importParams
+ * @return ImportService
+ */
+ public function doImport(ImportParams $importParams): ImportService;
+
+ /**
+ * Devolver el contador de objetos importados
+ *
+ * @return int
+ */
+ public function getCounter(): int;
+}
diff --git a/lib/SP/Domain/Import/Ports/ImportServiceInterface.php b/lib/SP/Domain/Import/Ports/ImportServiceInterface.php
index be1190fd..d63cad60 100644
--- a/lib/SP/Domain/Import/Ports/ImportServiceInterface.php
+++ b/lib/SP/Domain/Import/Ports/ImportServiceInterface.php
@@ -25,7 +25,6 @@
namespace SP\Domain\Import\Ports;
use Exception;
-use SP\Domain\Import\Services\FileImportService;
/**
* Esta clase es la encargada de importar cuentas.
@@ -38,5 +37,5 @@ interface ImportServiceInterface
* @return int Returns the total number of imported items
* @throws Exception
*/
- public function doImport(ImportParams $importParams, FileImportService $fileImport): int;
+ public function doImport(): int;
}
diff --git a/lib/SP/Domain/Import/Ports/LdapImportServiceInterface.php b/lib/SP/Domain/Import/Ports/LdapImportService.php
similarity index 93%
rename from lib/SP/Domain/Import/Ports/LdapImportServiceInterface.php
rename to lib/SP/Domain/Import/Ports/LdapImportService.php
index df382074..3dc5d4e8 100644
--- a/lib/SP/Domain/Import/Ports/LdapImportServiceInterface.php
+++ b/lib/SP/Domain/Import/Ports/LdapImportService.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
- * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
+ * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -33,7 +33,7 @@ use SP\Providers\Auth\Ldap\LdapParams;
*
* @package SP\Domain\User\Services
*/
-interface LdapImportServiceInterface
+interface LdapImportService
{
public function getTotalObjects(): int;
diff --git a/lib/SP/Domain/Import/Services/XmlFileImportInterface.php b/lib/SP/Domain/Import/Ports/XmlFileService.php
similarity index 85%
rename from lib/SP/Domain/Import/Services/XmlFileImportInterface.php
rename to lib/SP/Domain/Import/Ports/XmlFileService.php
index c1959f49..3fd0bcd5 100644
--- a/lib/SP/Domain/Import/Services/XmlFileImportInterface.php
+++ b/lib/SP/Domain/Import/Ports/XmlFileService.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
- * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
+ * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -22,16 +22,17 @@
* along with sysPass. If not, see .
*/
-namespace SP\Domain\Import\Services;
+namespace SP\Domain\Import\Ports;
use DOMDocument;
+use SP\Domain\Import\Services\ImportException;
/**
* Class XmlFileImport
*
* @package Import
*/
-interface XmlFileImportInterface
+interface XmlFileService
{
/**
* Detectar la aplicación que generó el XML.
diff --git a/lib/SP/Domain/Import/Services/XmlImportInterface.php b/lib/SP/Domain/Import/Ports/XmlImportService.php
similarity index 92%
rename from lib/SP/Domain/Import/Services/XmlImportInterface.php
rename to lib/SP/Domain/Import/Ports/XmlImportService.php
index 3ed48643..0eb655bd 100644
--- a/lib/SP/Domain/Import/Services/XmlImportInterface.php
+++ b/lib/SP/Domain/Import/Ports/XmlImportService.php
@@ -22,7 +22,7 @@
* along with sysPass. If not, see .
*/
-namespace SP\Domain\Import\Services;
+namespace SP\Domain\Import\Ports;
/**
* Clase XmlImport para usarla como envoltorio para llamar a la clase que corresponda
@@ -30,6 +30,6 @@ namespace SP\Domain\Import\Services;
*
* @package SP
*/
-interface XmlImportInterface extends Import
+interface XmlImportService extends ImportService
{
}
diff --git a/lib/SP/Domain/Import/Services/CsvImport.php b/lib/SP/Domain/Import/Services/CsvImport.php
index e9e96b6a..3475f1d5 100644
--- a/lib/SP/Domain/Import/Services/CsvImport.php
+++ b/lib/SP/Domain/Import/Services/CsvImport.php
@@ -33,7 +33,9 @@ use SP\Domain\Category\Models\Category;
use SP\Domain\Client\Models\Client;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Import\Dtos\CsvImportParamsDto;
+use SP\Domain\Import\Ports\FileImportService;
use SP\Domain\Import\Ports\ImportParams;
+use SP\Domain\Import\Ports\ImportService;
use SP\Infrastructure\File\FileException;
use function SP\__;
@@ -46,8 +48,6 @@ use function SP\processException;
final class CsvImport extends ImportBase
{
private const NUM_FIELDS = 7;
- protected array $categories = [];
- protected array $clients = [];
public function __construct(
Application $application,
@@ -61,12 +61,12 @@ final class CsvImport extends ImportBase
/**
* Import the data from a CSV file
*
- * @param CsvImportParamsDto|ImportParams $importParamsDto
- * @return Import
+ * @param CsvImportParamsDto|ImportParams $importParams
+ * @return ImportService
* @throws FileException
* @throws ImportException
*/
- public function doImport(CsvImportParamsDto|ImportParams $importParamsDto): Import
+ public function doImport(CsvImportParamsDto|ImportParams $importParams): ImportService
{
$this->eventDispatcher->notify(
'run.import.csv',
@@ -77,7 +77,7 @@ final class CsvImport extends ImportBase
)
);
- $this->processAccounts($importParamsDto);
+ $this->processAccounts($importParams);
return $this;
}
diff --git a/lib/SP/Domain/Import/Services/FileImport.php b/lib/SP/Domain/Import/Services/FileImport.php
index 249ec87e..334d3f8f 100644
--- a/lib/SP/Domain/Import/Services/FileImport.php
+++ b/lib/SP/Domain/Import/Services/FileImport.php
@@ -26,11 +26,13 @@ namespace SP\Domain\Import\Services;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Http\RequestInterface;
+use SP\Domain\Import\Ports\FileImportService;
use SP\Infrastructure\File\FileException;
use SP\Infrastructure\File\FileHandler;
use SP\Infrastructure\File\FileHandlerInterface;
use SP\Util\Util;
+use function SP\__;
use function SP\__u;
use function SP\logger;
@@ -41,16 +43,13 @@ use function SP\logger;
*/
final class FileImport implements FileImportService
{
- private FileHandler $fileHandler;
-
/**
* FileImport constructor.
*
* @param FileHandlerInterface $fileHandler Datos del archivo a importar
*/
- private function __construct(FileHandlerInterface $fileHandler)
+ private function __construct(private readonly FileHandlerInterface $fileHandler)
{
- $this->fileHandler = $fileHandler;
}
/**
@@ -74,9 +73,8 @@ final class FileImport implements FileImportService
private static function checkFile(?array $file): FileHandlerInterface
{
if (!is_array($file)) {
- throw new FileException(
+ throw FileException::error(
__u('File successfully uploaded'),
- SPException::ERROR,
__u('Please check the web server user permissions')
);
}
@@ -85,10 +83,9 @@ final class FileImport implements FileImportService
$fileHandler = new FileHandler($file['tmp_name']);
$fileHandler->checkFileExists();
- if (!in_array($fileHandler->getFileType(), ImportService::ALLOWED_MIME)) {
- throw new ImportException(
+ if (!in_array($fileHandler->getFileType(), Import::ALLOWED_MIME)) {
+ throw ImportException::error(
__u('File type not allowed'),
- SPException::ERROR,
sprintf(__('MIME type: %s'), $fileHandler->getFileType())
);
}
@@ -97,9 +94,8 @@ final class FileImport implements FileImportService
} catch (FileException $e) {
logger(sprintf('Max. upload size: %s', Util::getMaxUpload()));
- throw new FileException(
+ throw FileException::error(
__u('Internal error while reading the file'),
- SPException::ERROR,
__u('Please, check PHP configuration for upload files'),
$e->getCode(),
$e
@@ -115,11 +111,6 @@ final class FileImport implements FileImportService
return $this->fileHandler->getFileType();
}
- public static function fromFilesystem(string $path): FileImportService
- {
- return new self(new FileHandler($path));
- }
-
public function getFilePath(): string
{
return $this->fileHandler->getFile();
diff --git a/lib/SP/Domain/Import/Services/Import.php b/lib/SP/Domain/Import/Services/Import.php
index 227257d8..56381c8a 100644
--- a/lib/SP/Domain/Import/Services/Import.php
+++ b/lib/SP/Domain/Import/Services/Import.php
@@ -1,4 +1,5 @@
repository->transactionAware(fn() => $this->factory()->doImport($importParams), $this);
+ }
+
+ /**
+ * @throws ImportException
+ * @throws FileException
+ */
+ protected function factory(): ImportService
+ {
+ $fileType = $this->fileImport->getFileType();
+
+ switch ($fileType) {
+ case 'text/plain':
+ return new CsvImport($this->application, $this->importHelper, $this->crypt, $this->fileImport);
+ case 'text/xml':
+ case 'application/xml':
+ return new XmlImport(
+ $this->application,
+ $this->importHelper,
+ new XmlFile($this->fileImport->getFileHandler()),
+ $this->crypt
+ );
+ }
+
+ throw ImportException::error(
+ sprintf(__('Mime type not supported ("%s")'), $fileType),
+ __u('Please, check the file format')
+ );
+ }
+
+ /**
+ * @throws ImportException
+ */
+ public function getCounter(): int
+ {
+ throw ImportException::info(__u('Not implemented'));
+ }
}
diff --git a/lib/SP/Domain/Import/Services/ImportBase.php b/lib/SP/Domain/Import/Services/ImportBase.php
index 1ebe2877..3d396a49 100644
--- a/lib/SP/Domain/Import/Services/ImportBase.php
+++ b/lib/SP/Domain/Import/Services/ImportBase.php
@@ -33,6 +33,7 @@ use SP\Domain\Category\Ports\CategoryService;
use SP\Domain\Client\Models\Client;
use SP\Domain\Client\Ports\ClientService;
use SP\Domain\Common\Services\Service;
+use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Config\Ports\ConfigService;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
@@ -41,34 +42,37 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Import\Ports\ImportParams;
+use SP\Domain\Import\Ports\ImportService;
use SP\Domain\Tag\Models\Tag;
use SP\Domain\Tag\Ports\TagServiceInterface;
use SP\Infrastructure\Common\Repositories\DuplicatedItemException;
+use SP\Infrastructure\Common\Repositories\NoSuchItemException;
use function SP\__u;
/**
* Class ImportBase
*/
-abstract class ImportBase extends Service implements Import
+abstract class ImportBase extends Service implements ImportService
{
+ protected const ITEM_CATEGORY = 'category';
+ protected const ITEM_CLIENT = 'client';
+ protected const ITEM_TAG = 'tag';
+ protected const ITEM_MASTER_PASS_HASH = 'masterpasshash';
protected int $version = 0;
- /**
- * @var bool Indica si el hash de la clave suministrada es igual a la actual
- */
- protected bool $mPassValidHash = false;
- protected int $counter = 0;
+ protected int $counter = 0;
protected readonly AccountService $accountService;
protected readonly CategoryService $categoryService;
protected readonly ClientService $clientService;
protected readonly TagServiceInterface $tagService;
protected readonly ConfigService $configService;
private array $items;
+ private array $cache;
public function __construct(
- Application $application,
- ImportHelper $importHelper,
- private readonly CryptInterface $crypt
+ Application $application,
+ ImportHelper $importHelper,
+ protected readonly CryptInterface $crypt
) {
parent::__construct($application);
@@ -77,6 +81,7 @@ abstract class ImportBase extends Service implements Import
$this->clientService = $importHelper->getClientService();
$this->tagService = $importHelper->getTagService();
$this->configService = $importHelper->getConfigService();
+ $this->cache = [];
}
@@ -89,10 +94,6 @@ abstract class ImportBase extends Service implements Import
}
/**
- * Añadir una cuenta desde un archivo importado.
- *
- * @param AccountCreateDto $accountCreateDto
- * @param ImportParams $importParams
* @throws ConstraintException
* @throws ImportException
* @throws NoSuchPropertyException
@@ -100,7 +101,7 @@ abstract class ImportBase extends Service implements Import
* @throws SPException
* @throws CryptException
*/
- protected function addAccount(AccountCreateDto $accountCreateDto, ImportParams $importParams): void
+ final protected function addAccount(AccountCreateDto $accountCreateDto, ImportParams $importParams): void
{
if (empty($accountCreateDto->getCategoryId())) {
throw new ImportException(__u('Category Id not set. Unable to import account.'));
@@ -110,7 +111,11 @@ abstract class ImportBase extends Service implements Import
throw new ImportException(__u('Client Id not set. Unable to import account.'));
}
- $hasValidHash = $this->validateHash($importParams);
+ $hasValidHash = $this->getOrSetCache(
+ self::ITEM_MASTER_PASS_HASH,
+ '',
+ fn() => $this->validateHash($importParams)
+ );
$dto = $accountCreateDto
->set('userId', $importParams->getDefaultUser())
@@ -131,133 +136,85 @@ abstract class ImportBase extends Service implements Import
}
$this->accountService->create($dto);
-
$this->counter++;
}
+ final protected function getOrSetCache(string $type, int|string $key, callable $value = null): mixed
+ {
+ $hash = sha1($type . $key);
+
+ if (isset($this->cache[$hash])) {
+ return $this->cache[$hash];
+ }
+
+ if (null !== $value) {
+ $this->cache[$hash] = $value();
+
+ return $this->cache[$hash];
+ }
+
+ return null;
+ }
+
+ /**
+ * @throws ServiceException
+ */
private function validateHash(ImportParams $importParams): bool
{
if (!empty($importParams->getMasterPassword())) {
- return Hash::checkHashKey(
- $importParams->getMasterPassword(),
- $this->configService->getByParam('masterPwd')
- );
+ try {
+ return Hash::checkHashKey(
+ $importParams->getMasterPassword(),
+ $this->configService->getByParam('masterPwd')
+ );
+ } catch (NoSuchItemException $e) {
+ return false;
+ }
}
return true;
}
/**
- * Añadir una categoría y devolver el Id
- *
- * @param Category $category
- *
- * @return int
* @throws DuplicatedItemException
* @throws SPException
*/
protected function addCategory(Category $category): int
{
- try {
- $categoryId = $this->getWorkingItem('category', $category->getName());
-
- return $categoryId ?? $this->categoryService->create($category);
- } catch (DuplicatedItemException $e) {
- $itemData = $this->categoryService->getByName($category->getName());
-
- if ($itemData === null) {
- throw $e;
- }
-
- return $this->addWorkingItem('category', $itemData->getName(), $itemData->getId());
- }
+ return $this->getOrSetCache(
+ self::ITEM_CATEGORY,
+ $category->getName(),
+ fn(): ?int => $this->categoryService->getByName($category->getName())?->getId()
+ ?: $this->categoryService->create($category)
+ );
}
/**
- * @param string $type
- * @param string|int $value
- *
- * @return int|null
- */
- protected function getWorkingItem(string $type, $value): ?int
- {
- return $this->items[$type][$value] ?? null;
- }
-
- /**
- * @param string $type
- * @param string|int $value
- * @param int $id
- *
- * @return int
- */
- protected function addWorkingItem(string $type, $value, int $id): int
- {
- if (isset($this->items[$type][$value])) {
- return $this->items[$type][$value];
- }
-
- $this->items[$type][$value] = $id;
-
- return $id;
- }
-
- /**
- * Añadir un cliente y devolver el Id
- *
- * @param Client $client
- *
- * @return int
* @throws DuplicatedItemException
* @throws SPException
*/
protected function addClient(Client $client): int
{
- try {
- $clientId = $this->getWorkingItem('client', $client->getName());
+ $clientId = $this->getOrSetCache(
+ self::ITEM_CLIENT,
+ $client->getName(),
+ fn(): ?int => $this->clientService->getByName($client->getName())?->getId()
+ ?: $this->clientService->create($client)
+ );
- return $clientId ?? $this->clientService->create($client);
- } catch (DuplicatedItemException $e) {
- $itemData = $this->clientService->getByName($client->getName());
-
- if ($itemData === null) {
- throw $e;
- }
-
- return $this->addWorkingItem(
- 'client',
- $itemData->getName(),
- $itemData->getId()
- );
- }
+ return $clientId ?? $this->clientService->create($client);
}
/**
- * Añadir una etiqueta y devolver el Id
- *
- * @param Tag $tag
- *
- * @return int
* @throws SPException
*/
protected function addTag(Tag $tag): int
{
- try {
- $tagId = $this->getWorkingItem('tag', $tag->getName());
-
- return $tagId ?? $this->tagService->create($tag);
- } catch (DuplicatedItemException $e) {
- $itemData = $this->tagService->getByName($tag->getName());
-
- if ($itemData === null) {
- throw $e;
- }
-
- return $this->addWorkingItem(
- 'tag',
- $itemData->getName(),
- $itemData->getId()
- );
- }
+ return $this->getOrSetCache(
+ self::ITEM_TAG,
+ $tag->getId(),
+ fn(): ?int => $this->tagService->getByName($tag->getName())?->getId()
+ ?: $this->tagService->create($tag)
+ );
}
}
diff --git a/lib/SP/Domain/Import/Services/ImportService.php b/lib/SP/Domain/Import/Services/ImportService.php
deleted file mode 100644
index a5c5bd16..00000000
--- a/lib/SP/Domain/Import/Services/ImportService.php
+++ /dev/null
@@ -1,130 +0,0 @@
-.
- */
-
-namespace SP\Domain\Import\Services;
-
-use Exception;
-use SP\Core\Application;
-use SP\Domain\Common\Services\Service;
-use SP\Domain\Config\Ports\ConfigService;
-use SP\Domain\Core\Exceptions\SPException;
-use SP\Domain\Import\Dtos\ImportParamsDto;
-use SP\Domain\Import\Ports\ImportParams;
-use SP\Domain\Import\Ports\ImportServiceInterface;
-use SP\Infrastructure\Database\DatabaseInterface;
-use SP\Infrastructure\File\FileException;
-
-defined('APP_ROOT') || die();
-
-/**
- * Esta clase es la encargada de importar cuentas.
- */
-final class ImportService extends Service implements ImportServiceInterface
-{
- public const ALLOWED_MIME = [
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- 'application/vnd.ms-excel',
- 'text/plain',
- 'text/csv',
- 'text/x-csv',
- 'application/xml',
- 'text/xml',
- ];
-
- private ?ImportParamsDto $importParams = null;
- private ?FileImportService $fileImport = null;
- private Application $application;
- private ImportHelper $importHelper;
- private ConfigService $configService;
- private DatabaseInterface $database;
-
- public function __construct(
- Application $application,
- ImportHelper $importHelper,
- ConfigService $configService,
- DatabaseInterface $database
- ) {
- parent::__construct($application);
-
- $this->application = $application;
- $this->importHelper = $importHelper;
- $this->configService = $configService;
- $this->database = $database;
-
- set_time_limit(0);
- }
-
-
- /**
- * Iniciar la importación de cuentas.
- *
- * @return int Returns the total number of imported items
- * @throws Exception
- */
- public function doImport(ImportParams $importParams, FileImportService $fileImport): int
- {
- $this->importParams = $importParams;
- $this->fileImport = $fileImport;
-
- return $this->transactionAware(
- fn() => $this->selectImportType()->doImport()->getCounter(),
- $this->database
- );
- }
-
- /**
- * @throws ImportException
- * @throws FileException
- */
- protected function selectImportType(): Import
- {
- $fileType = $this->fileImport->getFileType();
-
- switch ($fileType) {
- case 'text/plain':
- return new CsvImport(
- $this->application,
- $this->importHelper,
- $this->fileImport,
- $this->importParams
- );
- case 'text/xml':
- case 'application/xml':
- return new XmlImport(
- $this->application,
- $this->importHelper,
- $this->configService,
- new XmlFileImport($this->fileImport),
- $this->importParams
- );
- }
-
- throw new ImportException(
- sprintf(__('Mime type not supported ("%s")'), $fileType),
- SPException::ERROR,
- __u('Please, check the file format')
- );
- }
-}
diff --git a/lib/SP/Domain/Import/Services/KeepassImport.php b/lib/SP/Domain/Import/Services/KeepassImport.php
index eeecb01e..d9998880 100644
--- a/lib/SP/Domain/Import/Services/KeepassImport.php
+++ b/lib/SP/Domain/Import/Services/KeepassImport.php
@@ -24,39 +24,50 @@
namespace SP\Domain\Import\Services;
+use CallbackFilterIterator;
use DOMElement;
use DOMXPath;
use Exception;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Domain\Account\Dtos\AccountRequest;
+use SP\Domain\Account\Dtos\AccountCreateDto;
use SP\Domain\Category\Models\Category;
use SP\Domain\Client\Models\Client;
use SP\Domain\Core\Exceptions\SPException;
+use SP\Domain\Import\Ports\ImportParams;
+use SP\Domain\Import\Ports\ImportService;
+use SP\Infrastructure\Common\Repositories\DuplicatedItemException;
use SP\Util\Filter;
+use SplObjectStorage;
-defined('APP_ROOT') || die();
+use function SP\__u;
+use function SP\processException;
/**
- * Esta clase es la encargada de importar cuentas desde KeePass
+ * Class KeepassImport
*/
-final class KeepassImport extends XmlImportBase implements Import
+final class KeepassImport extends XmlImportBase
{
+ /**
+ * @var SplObjectStorage[] $items
+ */
private array $items = [];
/**
* Iniciar la importación desde KeePass
*
+ * @param ImportParams $importParams
+ * @return ImportService
* @throws SPException
*/
- public function doImport(): Import
+ public function doImport(ImportParams $importParams): ImportService
{
$this->eventDispatcher->notify(
'run.import.keepass',
new Event($this, EventMessage::factory()->addDescription(__u('KeePass XML Import')))
);
- $this->process();
+ $this->process($importParams);
return $this;
}
@@ -66,9 +77,9 @@ final class KeepassImport extends XmlImportBase implements Import
*
* @throws SPException
*/
- private function process(): void
+ private function process(ImportParams $importParamsDto): void
{
- $clientId = $this->addClient(new Client(null, 'KeePass'));
+ $clientId = $this->addClient(new Client(['name' => 'KeePass']));
$this->eventDispatcher->notify(
'run.import.keepass.process.client',
@@ -76,67 +87,71 @@ final class KeepassImport extends XmlImportBase implements Import
);
$this->getGroups();
-
$this->getEntries();
- /** @var AccountRequest[] $group */
- foreach ($this->items as $group => $entry) {
+ foreach ($this->items as $groupName => $accounts) {
try {
- $categoryId = $this->addCategory(new Category(null, $group, 'KeePass'));
+ foreach ($accounts as $account) {
+ $this->addAccount(
+ $account->set('clientId', $clientId),
+ $importParamsDto
+ );
- $this->eventDispatcher->notify(
- 'run.import.keepass.process.category',
- new Event($this, EventMessage::factory()->addDetail(__u('Category imported'), $group))
- );
-
- if (count($entry) > 0) {
- foreach ($entry as $account) {
- $account->categoryId = $categoryId;
- $account->clientId = $clientId;
-
- $this->addAccount($account);
-
- $this->eventDispatcher->notify(
- 'run.import.keepass.process.account',
- new Event(
- $this,
- EventMessage::factory()
- ->addDetail(__u('Account imported'), $account->name)
- ->addDetail(__u('Category'), $group)
- )
- );
- }
+ $this->eventDispatcher->notify(
+ 'run.import.keepass.process.account',
+ new Event(
+ $this,
+ EventMessage::factory()
+ ->addDetail(__u('Account imported'), $account->getName())
+ ->addDetail(__u('Category'), $groupName)
+ )
+ );
}
} catch (Exception $e) {
processException($e);
- $this->eventDispatcher->notify(
- 'exception',
- new Event($e)
- );
+ $this->eventDispatcher->notify('exception', new Event($e));
}
}
}
/**
- * Gets the groups found
+ * @throws DuplicatedItemException
+ * @throws SPException
*/
private function getGroups(): void
{
- $DomXpath = new DOMXPath($this->xmlDOM);
- $tags = $DomXpath->query('/KeePassFile/Root/Group//Group');
+ $DomXpath = new DOMXPath($this->document);
+ $tags = $DomXpath->query('/KeePassFile/Root/Group//Group/Name');
- /** @var DOMElement[] $tags */
- foreach ($tags as $tag) {
- if ($tag->nodeType === 1) {
- $groupName = $DomXpath->query($tag->getNodePath().'/Name')
- ->item(0)
- ->nodeValue;
+ $nodesList = new CallbackFilterIterator(
+ $tags->getIterator(),
+ static fn(DOMElement $node) => $node->nodeType === XML_ELEMENT_NODE
+ );
- if (!isset($groups[$groupName])) {
- $this->items[$groupName] = [];
- }
- }
+ /** @var DOMElement $tag */
+ foreach ($nodesList as $tag) {
+ $this->setItem($tag->childNodes->item(0)->nodeValue);
+ }
+ }
+
+ /**
+ * @throws DuplicatedItemException
+ * @throws SPException
+ */
+ private function setItem(string $groupName): void
+ {
+ $groupName = Filter::getString($groupName);
+
+ if (!isset($this->items[$groupName])) {
+ $this->addCategory(new Category(['name' => $groupName, 'description' => 'KeePass']));
+
+ $this->eventDispatcher->notify(
+ 'run.import.keepass.process.category',
+ new Event($this, EventMessage::factory()->addDetail(__u('Category imported'), $groupName))
+ );
+
+ $this->items[$groupName] = new SplObjectStorage();
}
}
@@ -145,42 +160,51 @@ final class KeepassImport extends XmlImportBase implements Import
*/
private function getEntries(): void
{
- $DomXpath = new DOMXPath($this->xmlDOM);
- $tags = $DomXpath->query('/KeePassFile/Root/Group//Entry[not(parent::History)]');
+ $DomXpath = new DOMXPath($this->document);
+ $entries = $DomXpath->query('/KeePassFile/Root/Group//Entry[not(parent::History)]');
- /** @var DOMElement[] $tags */
- foreach ($tags as $tag) {
- if ($tag->nodeType === 1) {
- $path = $tag->getNodePath();
- $entryData = [];
+ $nodesList = new CallbackFilterIterator(
+ $entries->getIterator(),
+ static fn(DOMElement $node) => $node->nodeType === XML_ELEMENT_NODE
+ );
- /** @var DOMElement $key */
- foreach ($DomXpath->query($path.'/String/Key') as $key) {
- $value = $DomXpath->query($key->getNodePath().'/../Value')
- ->item(0)
- ->nodeValue;
+ /** @var DOMElement $entry */
+ foreach ($nodesList as $entry) {
+ $path = $entry->getNodePath();
+ $entryData = [];
- $entryData[$key->nodeValue] = $value;
- }
+ /** @var DOMElement $string */
+ foreach ($DomXpath->query($path . '/String') as $string) {
+ $key = $string->childNodes->item(0)->nodeValue;
+ $value = $string->childNodes->item(1)->nodeValue;
- $groupName = $DomXpath->query($path.'/../Name')
- ->item(0)
- ->nodeValue;
-
- $this->items[$groupName][] = $this->mapEntryToAccount($entryData);
+ $entryData[$key] = $value;
}
+
+ $groupName = $DomXpath->query($path . '/../Name')->item(0)->nodeValue;
+
+ $this->getItem($groupName)?->attach($this->mapEntryToAccount($entryData, $groupName));
}
}
- private function mapEntryToAccount(array $entry): AccountRequest
+ private function getItem(string $groupName): ?SplObjectStorage
{
- $accountRequest = new AccountRequest();
- $accountRequest->name = isset($entry['Title']) ? Filter::getString($entry['Title']) : '';
- $accountRequest->login = isset($entry['UserName']) ? Filter::getString($entry['UserName']) : '';
- $accountRequest->pass = $entry['Password'] ?? '';
- $accountRequest->url = isset($entry['URL']) ? Filter::getString($entry['URL']) : '';
- $accountRequest->notes = isset($entry['Notes']) ? Filter::getString($entry['Notes']) : '';
+ if (array_key_exists($groupName, $this->items)) {
+ return $this->items[$groupName];
+ }
- return $accountRequest;
+ return null;
+ }
+
+ private function mapEntryToAccount(array $entry, string $groupName): AccountCreateDto
+ {
+ return new AccountCreateDto(
+ name: Filter::getString($entry['Title'] ?? ''),
+ login: Filter::getString($entry['UserName'] ?? ''),
+ categoryId: $this->getOrSetCache(self::ITEM_CATEGORY, $groupName),
+ pass: $entry['Password'] ?? '',
+ url: Filter::getString($entry['URL'] ?? ''),
+ notes: Filter::getString($entry['Notes'] ?? '')
+ );
}
}
diff --git a/lib/SP/Domain/Import/Services/LdapImportService.php b/lib/SP/Domain/Import/Services/LdapImport.php
similarity index 70%
rename from lib/SP/Domain/Import/Services/LdapImportService.php
rename to lib/SP/Domain/Import/Services/LdapImport.php
index 37c39868..4494b8cc 100644
--- a/lib/SP/Domain/Import/Services/LdapImportService.php
+++ b/lib/SP/Domain/Import/Services/LdapImport.php
@@ -28,39 +28,40 @@ use Exception;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\DataModel\UserData;
-use SP\DataModel\UserGroupData;
+use SP\DataModel\User;
+use SP\Domain\Auth\Ports\LdapActionsService;
+use SP\Domain\Auth\Ports\LdapConnectionInterface;
use SP\Domain\Auth\Ports\LdapService;
use SP\Domain\Common\Services\Service;
-use SP\Domain\Import\Ports\LdapImportServiceInterface;
+use SP\Domain\Import\Ports\LdapImportService;
+use SP\Domain\User\Models\UserGroup;
use SP\Domain\User\Ports\UserServiceInterface;
use SP\Domain\User\Services\UserGroupService;
use SP\Providers\Auth\Ldap\LdapBase;
use SP\Providers\Auth\Ldap\LdapException;
use SP\Providers\Auth\Ldap\LdapParams;
+use function SP\__;
+use function SP\__u;
+use function SP\processException;
+
/**
- * Class UserLdapService
- *
- * @package SP\Domain\User\Services
+ * Class LdapImport
*/
-final class LdapImportService extends Service implements LdapImportServiceInterface
+final class LdapImport extends Service implements LdapImportService
{
- protected int $totalObjects = 0;
- protected int $syncedObjects = 0;
- protected int $errorObjects = 0;
- private UserServiceInterface $userService;
- private UserGroupService $userGroupService;
+ protected int $totalObjects = 0;
+ protected int $syncedObjects = 0;
+ protected int $errorObjects = 0;
public function __construct(
- Application $application,
- UserServiceInterface $userService,
- UserGroupService $userGroupService
+ Application $application,
+ private readonly UserServiceInterface $userService,
+ private readonly UserGroupService $userGroupService,
+ private readonly LdapActionsService $ldapActionsService,
+ private readonly LdapConnectionInterface $ldapConnection
) {
parent::__construct($application);
-
- $this->userService = $userService;
- $this->userGroupService = $userGroupService;
}
@@ -84,10 +85,8 @@ final class LdapImportService extends Service implements LdapImportServiceInterf
*
* @throws LdapException
*/
- public function importGroups(
- LdapParams $ldapParams,
- LdapImportParams $ldapImportParams
- ): void {
+ public function importGroups(LdapParams $ldapParams, LdapImportParams $ldapImportParams): void
+ {
$ldap = $this->getLdap($ldapParams);
if (empty($ldapImportParams->filter)) {
@@ -108,31 +107,28 @@ final class LdapImportService extends Service implements LdapImportServiceInterf
if ($numObjects > 0) {
foreach ($objects as $result) {
if (is_array($result)) {
- $userGroupData = new UserGroupData();
+ $userGroup = [];
foreach ($result as $attribute => $values) {
-
$value = $values[0];
if (strtolower($attribute) === $ldapImportParams->userGroupNameAttribute) {
- $userGroupData->setName($value);
+ $userGroup['name'] = $value;
}
}
- if (!empty($userGroupData->getName())) {
+ if (!isset($userGroup['name'])) {
try {
- $userGroupData->setDescription(__('Imported from LDAP'));
+ $userGroup['description'] = __('Imported from LDAP');
- $this->userGroupService->create($userGroupData);
+ $this->userGroupService->create(new UserGroup($userGroup));
$this->eventDispatcher->notify(
'import.ldap.progress.groups',
new Event(
$this,
- EventMessage::factory()->addDetail(
- __u('Group'),
- sprintf('%s', $userGroupData->getName())
- )
+ EventMessage::factory()
+ ->addDetail(__u('Group'), sprintf('%s', $userGroup['name']))
)
);
@@ -156,19 +152,18 @@ final class LdapImportService extends Service implements LdapImportServiceInterf
protected function getLdap(LdapParams $ldapParams): LdapService
{
return LdapBase::factory(
- $ldapParams,
$this->eventDispatcher,
- $this->config->getConfigData()->isDebug()
+ $this->ldapConnection,
+ $this->ldapActionsService,
+ $ldapParams,
);
}
/**
* @throws LdapException
*/
- public function importUsers(
- LdapParams $ldapParams,
- LdapImportParams $ldapImportParams
- ): void {
+ public function importUsers(LdapParams $ldapParams, LdapImportParams $ldapImportParams): void
+ {
$ldap = $this->getLdap($ldapParams);
if (empty($ldapImportParams->filter)) {
@@ -189,35 +184,30 @@ final class LdapImportService extends Service implements LdapImportServiceInterf
if ($numObjects > 0) {
foreach ($objects as $result) {
if (is_array($result)) {
- $userData = new UserData();
+ $user = [];
foreach ($result as $attribute => $values) {
-
- $value = $values[0];
-
switch (strtolower($attribute)) {
case $ldapImportParams->userNameAttribute:
- $userData->setName($value);
+ $user['name'] = $values[0];
break;
case $ldapImportParams->loginAttribute:
- $userData->setLogin($value);
+ $user['login'] = $values[0];
break;
case 'mail':
- $userData->setEmail($value);
+ $user['email'] = $values[0];
break;
}
}
- if (!empty($userData->getName())
- && !empty($userData->getLogin())
- ) {
+ if (!isset($user['name'], $user['login'])) {
try {
- $userData->setNotes(__('Imported from LDAP'));
- $userData->setUserGroupId($ldapImportParams->defaultUserGroup);
- $userData->setUserProfileId($ldapImportParams->defaultUserProfile);
- $userData->setIsLdap(true);
+ $user['notes'] = __('Imported from LDAP');
+ $user['userGroupId'] = $ldapImportParams->defaultUserGroup;
+ $user['userProfileId'] = $ldapImportParams->defaultUserProfile;
+ $user['isLdap'] = true;
- $this->userService->create($userData);
+ $this->userService->create(new User($user));
$this->eventDispatcher->notify(
'import.ldap.progress.users',
@@ -226,7 +216,7 @@ final class LdapImportService extends Service implements LdapImportServiceInterf
EventMessage::factory()
->addDetail(
__u('User'),
- sprintf('%s (%s)', $userData->getName(), $userData->getLogin())
+ sprintf('%s (%s)', $user['name'], $user['login'])
)
)
);
diff --git a/lib/SP/Domain/Import/Services/SyspassImport.php b/lib/SP/Domain/Import/Services/SyspassImport.php
index 02579b60..a10b689a 100644
--- a/lib/SP/Domain/Import/Services/SyspassImport.php
+++ b/lib/SP/Domain/Import/Services/SyspassImport.php
@@ -24,37 +24,42 @@
namespace SP\Domain\Import\Services;
-use Defuse\Crypto\Exception\CryptoException;
+use CallbackFilterIterator;
use DOMDocument;
use DOMElement;
use DOMNodeList;
use DOMXPath;
use Exception;
-use SP\Core\Crypt\Crypt;
use SP\Core\Crypt\Hash;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Domain\Account\Dtos\AccountRequest;
+use SP\Domain\Account\Dtos\AccountCreateDto;
+use SP\Domain\Account\Models\Account;
use SP\Domain\Category\Models\Category;
use SP\Domain\Client\Models\Client;
-use SP\Domain\Core\Exceptions\SPException;
+use SP\Domain\Core\Exceptions\CryptException;
use SP\Domain\Export\Services\XmlVerify;
+use SP\Domain\Import\Ports\ImportParams;
+use SP\Domain\Import\Ports\ImportService;
use SP\Domain\Tag\Models\Tag;
use SP\Util\VersionUtil;
-defined('APP_ROOT') || die();
+use function SP\__u;
+use function SP\processException;
/**
* Esta clase es la encargada de importar cuentas desde sysPass
*/
-final class SyspassImport extends XmlImportBase implements Import
+final class SyspassImport extends XmlImportBase
{
/**
* Iniciar la importación desde sysPass.
*
+ * @param ImportParams $importParams
+ * @return ImportService
* @throws ImportException
*/
- public function doImport(): Import
+ public function doImport(ImportParams $importParams): ImportService
{
try {
$this->eventDispatcher->notify(
@@ -62,24 +67,17 @@ final class SyspassImport extends XmlImportBase implements Import
new Event($this, EventMessage::factory()->addDescription(__u('sysPass XML Import')))
);
- if (!empty($this->importParams->getMasterPassword())) {
- $this->mPassValidHash = Hash::checkHashKey(
- $this->importParams->getMasterPassword(),
- $this->configService->getByParam('masterPwd')
- );
- }
-
$this->version = $this->getXmlVersion();
if ($this->detectEncrypted()) {
- if ($this->importParams->getPassword() === '') {
- throw new ImportException(__u('Encryption password not set'), SPException::INFO);
+ if ($importParams->getPassword() === '') {
+ throw ImportException::error(__u('Encryption password not set'));
}
- $this->processEncrypted();
+ $this->processEncrypted($importParams);
}
- $this->checkIntegrity();
+ $this->checkIntegrity($importParams);
$this->processCategories();
@@ -90,27 +88,23 @@ final class SyspassImport extends XmlImportBase implements Import
}
$this->processTags();
- $this->processAccounts();
+ $this->processAccounts($importParams);
return $this;
} catch (ImportException $e) {
throw $e;
} catch (Exception $e) {
- throw new ImportException(
- $e->getMessage(),
- SPException::CRITICAL
- );
+ throw ImportException::from($e);
}
}
/**
* Obtener la versión del XML
*/
- protected function getXmlVersion()
+ protected function getXmlVersion(): float|int
{
return VersionUtil::versionToInteger(
- (new DOMXPath($this->xmlDOM))
- ->query('/Root/Meta/Version')->item(0)->nodeValue
+ (new DOMXPath($this->document))->query('/Root/Meta/Version')->item(0)?->nodeValue ?? 0
);
}
@@ -119,7 +113,7 @@ final class SyspassImport extends XmlImportBase implements Import
*/
protected function detectEncrypted(): bool
{
- return $this->xmlDOM->getElementsByTagName('Encrypted')->length > 0;
+ return $this->document->getElementsByTagName('Encrypted')->length > 0;
}
/**
@@ -127,40 +121,34 @@ final class SyspassImport extends XmlImportBase implements Import
*
* @throws ImportException
*/
- protected function processEncrypted(): void
+ protected function processEncrypted(ImportParams $importParams): void
{
- $hash = $this->xmlDOM
+ $hash = $this->document
->getElementsByTagName('Encrypted')
->item(0)
- ->getAttribute('hash');
+ ?->getAttribute('hash');
- if (!empty($hash)
- && !Hash::checkHashKey($this->importParams->getPassword(), $hash)
- ) {
- throw new ImportException(__u('Wrong encryption password'));
+ if (!empty($hash) && !Hash::checkHashKey($importParams->getPassword(), $hash)) {
+ throw ImportException::error(__u('Wrong encryption password'));
}
/** @var DOMElement $node */
- foreach ($this->xmlDOM->getElementsByTagName('Data') as $node) {
+ foreach ($this->document->getElementsByTagName('Data') as $node) {
try {
if ($this->version >= 210 && $this->version <= 310) {
- $xmlDecrypted = Crypt::decrypt(
- base64_decode($node->nodeValue),
- $node->getAttribute('key'),
- $this->importParams->getPassword()
- );
+ $encryptedNodeValue = base64_decode($node->nodeValue);
+ } elseif ($this->version >= 320) {
+ $encryptedNodeValue = $node->nodeValue;
} else {
- if ($this->version >= 320) {
- $xmlDecrypted = Crypt::decrypt(
- $node->nodeValue,
- $node->getAttribute('key'),
- $this->importParams->getPassword()
- );
- } else {
- throw new ImportException(__u('The file was exported with an old sysPass version (<= 2.10).'));
- }
+ throw ImportException::error(__u('The file was exported with an old sysPass version (<= 2.10).'));
}
- } catch (CryptoException $e) {
+
+ $xmlDecrypted = $this->crypt->decrypt(
+ $encryptedNodeValue,
+ $node->getAttribute('key'),
+ $importParams->getPassword()
+ );
+ } catch (CryptException $e) {
processException($e);
$this->eventDispatcher->notify('exception', new Event($e));
@@ -168,21 +156,21 @@ final class SyspassImport extends XmlImportBase implements Import
continue;
}
- $newXmlData = new DOMDocument();
+ $document = new DOMDocument();
- if ($newXmlData->loadXML($xmlDecrypted) === false) {
- throw new ImportException(__u('Wrong encryption password'));
+ if ($document->loadXML($xmlDecrypted) === false) {
+ throw ImportException::error(__u('Wrong encryption password'));
}
- $this->xmlDOM->documentElement
+ $this->document->documentElement
->appendChild(
- $this->xmlDOM->importNode($newXmlData->documentElement, true)
+ $this->document->importNode($document->documentElement, true)
);
}
// Eliminar los datos encriptados tras desencriptar los mismos
- if ($this->xmlDOM->getElementsByTagName('Data')->length > 0) {
- $nodeData = $this->xmlDOM
+ if ($this->document->getElementsByTagName('Data')->length > 0) {
+ $nodeData = $this->document
->getElementsByTagName('Encrypted')
->item(0);
$nodeData->parentNode->removeChild($nodeData);
@@ -197,11 +185,11 @@ final class SyspassImport extends XmlImportBase implements Import
/**
* Checks XML file's data integrity using the signed hash
*/
- protected function checkIntegrity(): void
+ protected function checkIntegrity(ImportParams $importParams): void
{
- $key = $this->importParams->getPassword() ?: sha1($this->configData->getPasswordSalt());
+ $key = $importParams->getPassword() ?? sha1($this->configData->getPasswordSalt());
- if (!XmlVerify::checkXmlHash($this->xmlDOM, $key)) {
+ if (!XmlVerify::checkXmlHash($this->document, $key)) {
$this->eventDispatcher->notify(
'run.import.syspass.process.verify',
new Event(
@@ -229,34 +217,27 @@ final class SyspassImport extends XmlImportBase implements Import
'Categories',
'Category',
function (DOMElement $category) {
- $categoryData = new Category();
+ $nodesIterator = new CallbackFilterIterator(
+ $category->childNodes->getIterator(),
+ static fn(DOMElement $element) => isset($element->tagName)
+ );
- foreach ($category->childNodes as $node) {
- if (isset($node->tagName)) {
- switch ($node->tagName) {
- case 'name':
- $categoryData->setName($node->nodeValue);
- break;
- case 'description':
- $categoryData->setDescription($node->nodeValue);
- break;
- }
- }
+ $data = [];
+
+ /** @var DOMElement $node */
+ foreach ($nodesIterator as $node) {
+ $data[$node->tagName] = $node->nodeValue;
}
try {
- $this->addWorkingItem(
- 'category',
- (int)$category->getAttribute('id'),
- $this->addCategory($categoryData)
- );
+ $this->addCategory(new Category($data));
$this->eventDispatcher->notify(
'run.import.syspass.process.category',
new Event(
$this,
EventMessage::factory()
- ->addDetail(__u('Category imported'), $categoryData->getName())
+ ->addDetail(__u('Category imported'), $data['name'])
)
);
} catch (Exception $e) {
@@ -279,34 +260,27 @@ final class SyspassImport extends XmlImportBase implements Import
'Clients',
'Client',
function (DOMElement $client) {
- $clientData = new Client();
+ $nodesIterator = new CallbackFilterIterator(
+ $client->childNodes->getIterator(),
+ static fn(DOMElement $element) => isset($element->tagName)
+ );
- foreach ($client->childNodes as $node) {
- if (isset($node->tagName)) {
- switch ($node->tagName) {
- case 'name':
- $clientData->setName($node->nodeValue);
- break;
- case 'description':
- $clientData->setDescription($node->nodeValue);
- break;
- }
- }
+ $data = [];
+
+ /** @var DOMElement $node */
+ foreach ($nodesIterator as $node) {
+ $data[$node->tagName] = $node->nodeValue;
}
try {
- $this->addWorkingItem(
- 'client',
- (int)$client->getAttribute('id'),
- $this->addClient($clientData)
- );
+ $this->addClient(new Client($data));
$this->eventDispatcher->notify(
'run.import.syspass.process.client',
new Event(
$this,
EventMessage::factory()
- ->addDetail(__u('Client imported'), $clientData->getName())
+ ->addDetail(__u('Client imported'), $data['name'])
)
);
} catch (Exception $e) {
@@ -330,33 +304,26 @@ final class SyspassImport extends XmlImportBase implements Import
'Customers',
'Customer',
function (DOMElement $client) {
- $clientData = new Client();
+ $nodesIterator = new CallbackFilterIterator(
+ $client->childNodes->getIterator(),
+ static fn(DOMElement $element) => isset($element->tagName)
+ );
- foreach ($client->childNodes as $node) {
- if (isset($node->tagName)) {
- switch ($node->tagName) {
- case 'name':
- $clientData->setName($node->nodeValue);
- break;
- case 'description':
- $clientData->setDescription($node->nodeValue);
- break;
- }
- }
+ $data = [];
+
+ /** @var DOMElement $node */
+ foreach ($nodesIterator as $node) {
+ $data[$node->tagName] = $node->nodeValue;
}
try {
- $this->addWorkingItem(
- 'client',
- (int)$client->getAttribute('id'),
- $this->addClient($clientData)
- );
+ $this->addClient(new Client($data));
$this->eventDispatcher->notify(
'run.import.syspass.process.customer',
new Event(
$this,
- EventMessage::factory()->addDetail(__u('Client imported'), $clientData->getName())
+ EventMessage::factory()->addDetail(__u('Client imported'), $data['name'])
)
);
} catch (Exception $e) {
@@ -379,26 +346,29 @@ final class SyspassImport extends XmlImportBase implements Import
'Tags',
'Tag',
function (DOMElement $tag) {
- $tagData = new Tag();
+ $nodesIterator = new CallbackFilterIterator(
+ $tag->childNodes->getIterator(),
+ static fn(DOMElement $element) => isset($element->tagName)
+ );
- foreach ($tag->childNodes as $node) {
- if (isset($node->tagName) && $node->tagName === 'name') {
- $tagData->setName($node->nodeValue);
+ $data = [];
+
+ /** @var DOMElement $node */
+ foreach ($nodesIterator as $node) {
+ if ($node->tagName === 'name') {
+ $data['name'] = $node->nodeValue;
+ $data['id'] = $node->getAttribute('id');
}
}
try {
- $this->addWorkingItem(
- 'tag',
- (int)$tag->getAttribute('id'),
- $this->addTag($tagData)
- );
+ $this->addTag(new Tag($data));
$this->eventDispatcher->notify(
'run.import.syspass.process.tag',
new Event(
$this,
- EventMessage::factory()->addDetail(__u('Tag imported'), $tagData->getName())
+ EventMessage::factory()->addDetail(__u('Tag imported'), $data['name'])
)
);
} catch (Exception $e) {
@@ -416,59 +386,47 @@ final class SyspassImport extends XmlImportBase implements Import
*
* @throws ImportException
*/
- protected function processAccounts(): void
+ protected function processAccounts(ImportParams $importParams): void
{
$this->getNodesData(
'Accounts',
'Account',
- function (DOMElement $account) {
- $accountRequest = new AccountRequest();
+ function (DOMElement $account) use ($importParams) {
+ $data = [];
+
+ $nodesIterator = new CallbackFilterIterator(
+ $account->childNodes->getIterator(),
+ static fn(DOMElement $element) => isset($element->tagName)
+ );
/** @var DOMElement $node */
- foreach ($account->childNodes as $node) {
- if (isset($node->tagName)) {
- switch ($node->tagName) {
- case 'name';
- $accountRequest->name = $node->nodeValue;
- break;
- case 'login';
- $accountRequest->login = $node->nodeValue;
- break;
- case 'categoryId';
- $accountRequest->categoryId =
- $this->getWorkingItem('category', (int)$node->nodeValue);
- break;
- case 'clientId';
- case 'customerId';
- $accountRequest->clientId =
- $this->getWorkingItem('client', (int)$node->nodeValue);
- break;
- case 'url';
- $accountRequest->url = $node->nodeValue;
- break;
- case 'pass';
- $accountRequest->pass = $node->nodeValue;
- break;
- case 'key';
- $accountRequest->key = $node->nodeValue;
- break;
- case 'notes';
- $accountRequest->notes = $node->nodeValue;
- break;
- case 'tags':
- $accountRequest->tags = $this->processAccountTags($node->childNodes);
- }
+ foreach ($nodesIterator as $node) {
+ switch ($node->tagName) {
+ case 'categoryId':
+ $data['categoryId'] =
+ $this->getOrSetCache(self::ITEM_CATEGORY, (int)$node->nodeValue);
+ break;
+ case 'clientId':
+ case 'customerId':
+ $data['clientId'] =
+ $this->getOrSetCache(self::ITEM_CLIENT, (int)$node->nodeValue);
+ break;
+ case 'tags':
+ $data['tags'] = $this->processAccountTags($node->childNodes);
+ break;
+ default:
+ $data[$node->tagName] = $node->nodeValue;
}
}
try {
- $this->addAccount($accountRequest);
+ $this->addAccount(AccountCreateDto::fromAccount(new Account($data)), $importParams);
$this->eventDispatcher->notify(
'run.import.syspass.process.account',
new Event(
$this,
- EventMessage::factory()->addDetail(__u('Account imported'), $accountRequest->name)
+ EventMessage::factory()->addDetail(__u('Account imported'), $data['name'])
)
);
} catch (Exception $e) {
@@ -487,13 +445,14 @@ final class SyspassImport extends XmlImportBase implements Import
{
$tags = [];
- if ($nodes->length > 0) {
- /** @var DOMElement $node */
- foreach ($nodes as $node) {
- if (isset($node->tagName)) {
- $tags[] = $this->getWorkingItem('tag', (int)$node->getAttribute('id'));
- }
- }
+ $nodesIterator = new CallbackFilterIterator(
+ $nodes->getIterator(),
+ static fn(DOMElement $element) => isset($element->tagName)
+ );
+
+ /** @var DOMElement $node */
+ foreach ($nodesIterator as $node) {
+ $tags[] = $this->getOrSetCache(self::ITEM_TAG, (int)$node->getAttribute('id'));
}
return $tags;
diff --git a/lib/SP/Domain/Import/Services/XmlFileImport.php b/lib/SP/Domain/Import/Services/XmlFile.php
similarity index 61%
rename from lib/SP/Domain/Import/Services/XmlFileImport.php
rename to lib/SP/Domain/Import/Services/XmlFile.php
index db231f63..e1504b70 100644
--- a/lib/SP/Domain/Import/Services/XmlFileImport.php
+++ b/lib/SP/Domain/Import/Services/XmlFile.php
@@ -25,31 +25,28 @@
namespace SP\Domain\Import\Services;
use DOMDocument;
-use SP\Domain\Core\Exceptions\SPException;
+use SP\Domain\Import\Ports\XmlFileService;
use SP\Infrastructure\File\FileException;
+use SP\Infrastructure\File\FileHandlerInterface;
+
+use function SP\__u;
+use function SP\logger;
/**
* Class XmlFileImport
*
* @package Import
*/
-final class XmlFileImport implements XmlFileImportInterface
+final class XmlFile implements XmlFileService
{
- protected FileImport $fileImport;
protected ?DOMDocument $xmlDOM = null;
/**
- * XmlFileImport constructor.
- *
- * @param FileImportService $fileImport
- *
* @throws ImportException
* @throws FileException
*/
- public function __construct(FileImportService $fileImport)
+ public function __construct(protected readonly FileHandlerInterface $fileHandler)
{
- $this->fileImport = $fileImport;
-
$this->readXMLFile();
}
@@ -61,6 +58,8 @@ final class XmlFileImport implements XmlFileImportInterface
*/
protected function readXMLFile(): void
{
+ $this->fileHandler->checkIsReadable();
+
libxml_use_internal_errors(true);
// Cargar el XML con DOM
@@ -68,12 +67,12 @@ final class XmlFileImport implements XmlFileImportInterface
$this->xmlDOM->formatOutput = false;
$this->xmlDOM->preserveWhiteSpace = false;
- if ($this->xmlDOM->loadXML($this->fileImport->readFileToString(), LIBXML_PARSEHUGE) === false) {
+ if ($this->xmlDOM->load($this->fileHandler->getFile(), LIBXML_PARSEHUGE) === false) {
foreach (libxml_get_errors() as $error) {
- logger(__METHOD__.' - '.$error->message);
+ logger(__METHOD__ . ' - ' . $error->message);
}
- throw new ImportException(__u('Internal error'), SPException::ERROR, __u('Unable to process the XML file'));
+ throw ImportException::error(__u('Internal error'), __u('Unable to process the XML file'));
}
}
@@ -94,9 +93,8 @@ final class XmlFileImport implements XmlFileImportInterface
}
}
- throw new ImportException(
+ throw ImportException::error(
__u('XML file not supported'),
- SPException::ERROR,
__u('Unable to guess the application which data was exported from')
);
}
@@ -105,29 +103,4 @@ final class XmlFileImport implements XmlFileImportInterface
{
return $this->xmlDOM;
}
-
- /**
- * Leer la cabecera del archivo XML y obtener patrones de aplicaciones conocidas.
- */
- protected function parseFileHeader(): ?string
- {
- if (($handle = @fopen($this->fileImport->getFilePath(), 'rb')) !== false) {
- // No. de líneas a leer como máximo
- $maxLines = 5;
- $count = 0;
-
- while (($buffer = fgets($handle, 4096)) !== false && $count <= $maxLines) {
- if (preg_match('/(?PKEEPASSX_DATABASE|revelationdata)/i', $buffer, $matches)) {
- fclose($handle);
-
- return strtolower($matches['header']);
- }
- $count++;
- }
-
- fclose($handle);
- }
-
- return null;
- }
}
diff --git a/lib/SP/Domain/Import/Services/XmlImport.php b/lib/SP/Domain/Import/Services/XmlImport.php
index c628d360..09e06865 100644
--- a/lib/SP/Domain/Import/Services/XmlImport.php
+++ b/lib/SP/Domain/Import/Services/XmlImport.php
@@ -25,12 +25,14 @@
namespace SP\Domain\Import\Services;
use SP\Core\Application;
-use SP\Domain\Config\Ports\ConfigService;
+use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Core\Exceptions\SPException;
-use SP\Domain\Import\Dtos\ImportParamsDto;
use SP\Domain\Import\Ports\ImportParams;
+use SP\Domain\Import\Ports\ImportService;
+use SP\Domain\Import\Ports\XmlFileService;
+use SP\Domain\Import\Ports\XmlImportService;
-defined('APP_ROOT') || die();
+use function SP\__u;
/**
* Clase XmlImport para usarla como envoltorio para llamar a la clase que corresponda
@@ -38,29 +40,17 @@ defined('APP_ROOT') || die();
*
* @package SP
*/
-final class XmlImport implements XmlImportInterface
+final class XmlImport implements XmlImportService
{
- private XmlFileImport $xmlFileImport;
- private ImportParamsDto $importParams;
- private ImportHelper $importHelper;
- private ConfigService $configService;
- private Application $application;
-
/**
* XmlImport constructor.
*/
public function __construct(
- Application $application,
- ImportHelper $importHelper,
- ConfigService $configService,
- XmlFileImportInterface $xmlFileImport,
- ImportParams $importParams
+ private readonly Application $application,
+ private readonly ImportHelper $importHelper,
+ private readonly XmlFileService $xmlFileService,
+ private readonly CryptInterface $crypt
) {
- $this->application = $application;
- $this->importHelper = $importHelper;
- $this->configService = $configService;
- $this->xmlFileImport = $xmlFileImport;
- $this->importParams = $importParams;
}
/**
@@ -69,41 +59,33 @@ final class XmlImport implements XmlImportInterface
* @throws ImportException
* @throws SPException
*/
- public function doImport(): Import
+ public function doImport(ImportParams $importParams): ImportService
{
- $format = $this->xmlFileImport->detectXMLFormat();
+ $format = $this->xmlFileService->detectXMLFormat();
- return $this->selectImportType($format)->doImport();
+ return $this->factory($format)->doImport($importParams);
}
- /**
- * @param string $format
- *
- * @return KeepassImport|SyspassImport
- * @throws ImportException
- */
- protected function selectImportType(string $format)
+ protected function factory(string $format): ImportService
{
switch ($format) {
case 'syspass':
return new SyspassImport(
$this->application,
$this->importHelper,
- $this->configService,
- $this->xmlFileImport,
- $this->importParams
+ $this->crypt,
+ $this->xmlFileService
);
case 'keepass':
return new KeepassImport(
$this->application,
$this->importHelper,
- $this->configService,
- $this->xmlFileImport,
- $this->importParams
+ $this->crypt,
+ $this->xmlFileService
);
}
- throw new ImportException(__u('Format not detected'));
+ throw ImportException::error(__u('Format not detected'));
}
/**
@@ -111,6 +93,6 @@ final class XmlImport implements XmlImportInterface
*/
public function getCounter(): int
{
- throw new ImportException(__u('Not implemented'));
+ throw ImportException::error(__u('Not implemented'));
}
}
diff --git a/lib/SP/Domain/Import/Services/XmlImportBase.php b/lib/SP/Domain/Import/Services/XmlImportBase.php
index 6d458eae..827e7356 100644
--- a/lib/SP/Domain/Import/Services/XmlImportBase.php
+++ b/lib/SP/Domain/Import/Services/XmlImportBase.php
@@ -29,8 +29,10 @@ use DOMElement;
use SP\Core\Application;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Core\Crypt\CryptInterface;
-use SP\Domain\Core\Exceptions\SPException;
-use SP\Domain\Import\Ports\ImportParams;
+use SP\Domain\Import\Ports\XmlFileService;
+
+use function SP\__;
+use function SP\__u;
/**
* Class XmlImportBase
@@ -39,26 +41,21 @@ use SP\Domain\Import\Ports\ImportParams;
*/
abstract class XmlImportBase extends ImportBase
{
- protected readonly XmlFileImportInterface $xmlFileImport;
- protected readonly DOMDocument $xmlDOM;
- protected readonly ConfigDataInterface $configData;
- protected readonly ImportParams $importParams;
+ protected readonly DOMDocument $document;
+ protected readonly ConfigDataInterface $configData;
/**
* ImportBase constructor.
*/
public function __construct(
- Application $application,
- ImportHelper $importHelper,
- CryptInterface $crypt,
- XmlFileImportInterface $xmlFileImport,
- ImportParams $importParams
+ Application $application,
+ ImportHelper $importHelper,
+ CryptInterface $crypt,
+ protected readonly XmlFileService $xmlFileImport
) {
parent::__construct($application, $importHelper, $crypt);
- $this->xmlFileImport = $xmlFileImport;
- $this->importParams = $importParams;
$this->configData = $application->getConfig()->getConfigData();
- $this->xmlDOM = $xmlFileImport->getXmlDOM();
+ $this->document = $xmlFileImport->getXmlDOM();
}
/**
@@ -77,11 +74,11 @@ abstract class XmlImportBase extends ImportBase
callable $callback,
bool $required = true
): void {
- $nodeList = $this->xmlDOM->getElementsByTagName($nodeName);
+ $nodeList = $this->document->getElementsByTagName($nodeName);
if ($nodeList->length > 0) {
if (!is_callable($callback)) {
- throw new ImportException(__u('Invalid Method'), SPException::WARNING);
+ throw ImportException::warning(__u('Invalid Method'), $callback);
}
/** @var DOMElement $nodes */
@@ -92,9 +89,8 @@ abstract class XmlImportBase extends ImportBase
}
}
} elseif ($required === true) {
- throw new ImportException(
+ throw ImportException::warning(
__u('Invalid XML format'),
- SPException::WARNING,
sprintf(__('"%s" node doesn\'t exist'), $nodeName)
);
}
diff --git a/lib/SP/Domain/Install/Services/InstallerService.php b/lib/SP/Domain/Install/Services/InstallerService.php
index c1f97353..e80f911f 100644
--- a/lib/SP/Domain/Install/Services/InstallerService.php
+++ b/lib/SP/Domain/Install/Services/InstallerService.php
@@ -28,8 +28,7 @@ namespace SP\Domain\Install\Services;
use Exception;
use SP\Core\Crypt\Hash;
use SP\DataModel\ProfileData;
-use SP\DataModel\UserData;
-use SP\DataModel\UserGroupData;
+use SP\DataModel\User;
use SP\DataModel\UserProfileData;
use SP\Domain\Config\Models\Config;
use SP\Domain\Config\Ports\ConfigDataInterface;
@@ -42,6 +41,7 @@ use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Http\RequestInterface;
use SP\Domain\Install\Adapters\InstallData;
use SP\Domain\Install\Ports\InstallerServiceInterface;
+use SP\Domain\User\Models\UserGroup;
use SP\Domain\User\Ports\UserGroupServiceInterface;
use SP\Domain\User\Ports\UserProfileServiceInterface;
use SP\Domain\User\Ports\UserServiceInterface;
@@ -351,13 +351,13 @@ final class InstallerService implements InstallerServiceInterface
private function createAdminAccount(): void
{
try {
- $userGroupData = new UserGroupData();
+ $userGroupData = new UserGroup();
$userGroupData->setName('Admins');
$userGroupData->setDescription('sysPass Admins');
$userProfileData = new UserProfileData(['name' => 'Admin', 'profile' => new ProfileData()]);
- $userData = new UserData([
+ $userData = new User([
'userGroupId' => $this->userGroupService->create($userGroupData),
'userProfileId' => $this->userProfileService->create($userProfileData),
'login' => $this->installData->getAdminLogin(),
diff --git a/lib/SP/DataModel/UserGroupData.php b/lib/SP/Domain/User/Models/UserGroup.php
similarity index 59%
rename from lib/SP/DataModel/UserGroupData.php
rename to lib/SP/Domain/User/Models/UserGroup.php
index 9df6ada4..255e620c 100644
--- a/lib/SP/DataModel/UserGroupData.php
+++ b/lib/SP/Domain/User/Models/UserGroup.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
- * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
+ * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -22,62 +22,39 @@
* along with sysPass. If not, see .
*/
-namespace SP\DataModel;
+namespace SP\Domain\User\Models;
use SP\Domain\Common\Adapters\DataModelInterface;
use SP\Domain\Common\Models\Model;
-defined('APP_ROOT') || die();
-
/**
* Class GroupData
- *
- * @package SP\DataModel
*/
-class UserGroupData extends Model implements DataModelInterface
+class UserGroup extends Model implements DataModelInterface
{
- public int $id = 0;
- public ?string $name = null;
- public ?string $description = null;
- public ?array $users = null;
+ protected ?int $id = null;
+ protected ?string $name = null;
+ protected ?string $description = null;
+ protected ?array $users = null;
- public function getId(): int
+ public function getId(): ?int
{
return $this->id;
}
- public function setId(int $id): void
- {
- $this->id = $id;
- }
public function getName(): ?string
{
return $this->name;
}
- public function setName(string $name): void
- {
- $this->name = $name;
- }
-
public function getDescription(): ?string
{
return $this->description;
}
- public function setDescription(?string $description): void
- {
- $this->description = $description;
- }
-
public function getUsers(): ?array
{
return $this->users;
}
-
- public function setUsers(?array $users): void
- {
- $this->users = $users;
- }
}
diff --git a/lib/SP/Domain/User/Ports/UserGroupServiceInterface.php b/lib/SP/Domain/User/Ports/UserGroupServiceInterface.php
index 5abf6b56..116f4cb0 100644
--- a/lib/SP/Domain/User/Ports/UserGroupServiceInterface.php
+++ b/lib/SP/Domain/User/Ports/UserGroupServiceInterface.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
- * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
+ * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -25,10 +25,10 @@
namespace SP\Domain\User\Ports;
use SP\DataModel\ItemSearchData;
-use SP\DataModel\UserGroupData;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
+use SP\Domain\User\Models\UserGroup;
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
use SP\Infrastructure\Database\QueryResult;
@@ -50,7 +50,7 @@ interface UserGroupServiceInterface
* @throws QueryException
* @throws NoSuchItemException
*/
- public function getById(int $id): UserGroupData;
+ public function getById(int $id): UserGroup;
/**
* @throws ConstraintException
@@ -71,17 +71,17 @@ interface UserGroupServiceInterface
/**
* @throws ServiceException
*/
- public function create(UserGroupData $itemData): int;
+ public function create(UserGroup $itemData): int;
/**
* @throws ServiceException
*/
- public function update(UserGroupData $itemData): void;
+ public function update(UserGroup $itemData): void;
/**
* Get all items from the service's repository
*
- * @return UserGroupData[]
+ * @return UserGroup[]
* @throws ConstraintException
* @throws QueryException
*/
@@ -94,7 +94,7 @@ interface UserGroupServiceInterface
* @throws ConstraintException
* @throws QueryException
*/
- public function getByName(string $name): UserGroupData;
+ public function getByName(string $name): UserGroup;
/**
* Returns the users that are using the given group id
diff --git a/lib/SP/Domain/User/Ports/UserRepository.php b/lib/SP/Domain/User/Ports/UserRepository.php
index 16ae0905..dcf344f8 100644
--- a/lib/SP/Domain/User/Ports/UserRepository.php
+++ b/lib/SP/Domain/User/Ports/UserRepository.php
@@ -24,7 +24,7 @@
namespace SP\Domain\User\Ports;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\DataModel\UserPreferencesData;
use SP\Domain\Common\Ports\Repository;
use SP\Domain\Core\Exceptions\ConstraintException;
@@ -103,13 +103,13 @@ interface UserRepository extends Repository
public function checkExistsByLogin(string $login): bool;
/**
- * @param UserData $itemData
+ * @param User $itemData
*
* @return int
* @throws ConstraintException
* @throws QueryException
*/
- public function updateOnLogin(UserData $itemData): int;
+ public function updateOnLogin(User $itemData): int;
/**
* Updates an user's pass
diff --git a/lib/SP/Domain/User/Ports/UserServiceInterface.php b/lib/SP/Domain/User/Ports/UserServiceInterface.php
index 17804820..831fc832 100644
--- a/lib/SP/Domain/User/Ports/UserServiceInterface.php
+++ b/lib/SP/Domain/User/Ports/UserServiceInterface.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
- * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
+ * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -26,7 +26,7 @@ namespace SP\Domain\User\Ports;
use Defuse\Crypto\Exception\CryptoException;
use SP\DataModel\ItemSearchData;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\DataModel\UserPreferencesData;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Exceptions\ConstraintException;
@@ -65,7 +65,7 @@ interface UserServiceInterface
*
* @throws SPException
*/
- public function getById(int $id): UserData;
+ public function getById(int $id): User;
/**
* Returns the item for given id
@@ -74,7 +74,7 @@ interface UserServiceInterface
* @throws QueryException
* @throws NoSuchItemException
*/
- public function getByLogin(string $login): UserData;
+ public function getByLogin(string $login): User;
/**
* Deletes an item
@@ -106,7 +106,7 @@ interface UserServiceInterface
*
* @throws SPException
*/
- public function create(UserData $itemData): int;
+ public function create(User $itemData): int;
/**
* Creates an item
@@ -114,7 +114,7 @@ interface UserServiceInterface
* @throws SPException
* @throws CryptoException
*/
- public function createWithMasterPass(UserData $itemData, string $userPass, string $masterPass): int;
+ public function createWithMasterPass(User $itemData, string $userPass, string $masterPass): int;
/**
* Searches for items by a given filter
@@ -132,7 +132,7 @@ interface UserServiceInterface
* @throws DuplicatedItemException
* @throws ServiceException
*/
- public function update(UserData $userData): void;
+ public function update(User $userData): void;
/**
* Updates a user's pass
@@ -158,7 +158,7 @@ interface UserServiceInterface
/**
* Get all items from the service's repository
*
- * @return UserData[]
+ * @return User[]
* @throws ConstraintException
* @throws QueryException
*/
diff --git a/lib/SP/Domain/User/Services/UserGroupService.php b/lib/SP/Domain/User/Services/UserGroupService.php
index 90eff42c..a0810daf 100644
--- a/lib/SP/Domain/User/Services/UserGroupService.php
+++ b/lib/SP/Domain/User/Services/UserGroupService.php
@@ -27,13 +27,13 @@ namespace SP\Domain\User\Services;
use SP\Core\Application;
use SP\DataModel\ItemSearchData;
-use SP\DataModel\UserGroupData;
use SP\Domain\Common\Services\Service;
use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Common\Services\ServiceItemTrait;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
+use SP\Domain\User\Models\UserGroup;
use SP\Domain\User\Ports\UserGroupRepository;
use SP\Domain\User\Ports\UserGroupServiceInterface;
use SP\Domain\User\Ports\UserToUserGroupServiceInterface;
@@ -82,7 +82,7 @@ final class UserGroupService extends Service implements UserGroupServiceInterfac
* @throws QueryException
* @throws NoSuchItemException
*/
- public function getById(int $id): UserGroupData
+ public function getById(int $id): UserGroup
{
$result = $this->userGroupRepository->getById($id);
@@ -136,7 +136,7 @@ final class UserGroupService extends Service implements UserGroupServiceInterfac
/**
* @throws ServiceException
*/
- public function create(UserGroupData $itemData): int
+ public function create(UserGroup $itemData): int
{
return $this->transactionAware(
function () use ($itemData) {
@@ -157,7 +157,7 @@ final class UserGroupService extends Service implements UserGroupServiceInterfac
/**
* @throws ServiceException
*/
- public function update(UserGroupData $itemData): void
+ public function update(UserGroup $itemData): void
{
$this->transactionAware(
function () use ($itemData) {
@@ -176,7 +176,7 @@ final class UserGroupService extends Service implements UserGroupServiceInterfac
/**
* Get all items from the service's repository
*
- * @return UserGroupData[]
+ * @return UserGroup[]
* @throws ConstraintException
* @throws QueryException
*/
@@ -192,7 +192,7 @@ final class UserGroupService extends Service implements UserGroupServiceInterfac
* @throws ConstraintException
* @throws QueryException
*/
- public function getByName(string $name): UserGroupData
+ public function getByName(string $name): UserGroup
{
$result = $this->userGroupRepository->getByName($name);
diff --git a/lib/SP/Domain/User/Services/UserService.php b/lib/SP/Domain/User/Services/UserService.php
index 2d65559c..39a1a7a3 100644
--- a/lib/SP/Domain/User/Services/UserService.php
+++ b/lib/SP/Domain/User/Services/UserService.php
@@ -28,7 +28,7 @@ use Defuse\Crypto\Exception\CryptoException;
use SP\Core\Application;
use SP\Core\Crypt\Hash;
use SP\DataModel\ItemSearchData;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\DataModel\UserPreferencesData;
use SP\Domain\Common\Services\Service;
use SP\Domain\Common\Services\ServiceException;
@@ -69,7 +69,7 @@ final class UserService extends Service implements UserServiceInterface
}
public static function mapUserLoginResponse(
- UserData $userData
+ User $userData
): UserLoginResponse {
return (new UserLoginResponse())->setId($userData->getId())
->setName($userData->getName())
@@ -139,7 +139,7 @@ final class UserService extends Service implements UserServiceInterface
*
* @throws SPException
*/
- public function getById(int $id): UserData
+ public function getById(int $id): User
{
$result = $this->userRepository->getById($id);
@@ -157,7 +157,7 @@ final class UserService extends Service implements UserServiceInterface
* @throws QueryException
* @throws NoSuchItemException
*/
- public function getByLogin(string $login): UserData
+ public function getByLogin(string $login): User
{
$result = $this->userRepository->getByLogin($login);
@@ -212,7 +212,7 @@ final class UserService extends Service implements UserServiceInterface
*/
public function createOnLogin(UserLoginRequest $userLoginRequest): int
{
- $userData = new UserData();
+ $userData = new User();
$userData->setLogin($userLoginRequest->getLogin());
$userData->setName($userLoginRequest->getName());
$userData->setEmail($userLoginRequest->getEmail());
@@ -237,7 +237,7 @@ final class UserService extends Service implements UserServiceInterface
*
* @throws SPException
*/
- public function create(UserData $itemData): int
+ public function create(User $itemData): int
{
$itemData->setPass(Hash::hashKey($itemData->getPass()));
@@ -250,7 +250,7 @@ final class UserService extends Service implements UserServiceInterface
* @throws SPException
* @throws CryptoException
*/
- public function createWithMasterPass(UserData $itemData, string $userPass, string $masterPass): int
+ public function createWithMasterPass(User $itemData, string $userPass, string $masterPass): int
{
$response = $this->userPassService->createMasterPass(
$masterPass,
@@ -285,7 +285,7 @@ final class UserService extends Service implements UserServiceInterface
* @throws DuplicatedItemException
* @throws ServiceException
*/
- public function update(UserData $userData): void
+ public function update(User $userData): void
{
$update = $this->userRepository->update($userData);
@@ -335,7 +335,7 @@ final class UserService extends Service implements UserServiceInterface
*/
public function updateOnLogin(UserLoginRequest $userLoginRequest): int
{
- $userData = new UserData();
+ $userData = new User();
$userData->setLogin($userLoginRequest->getLogin());
$userData->setName($userLoginRequest->getName());
$userData->setEmail($userLoginRequest->getEmail());
@@ -348,7 +348,7 @@ final class UserService extends Service implements UserServiceInterface
/**
* Get all items from the service's repository
*
- * @return UserData[]
+ * @return User[]
* @throws ConstraintException
* @throws QueryException
*/
diff --git a/lib/SP/Infrastructure/User/Repositories/UserBaseRepository.php b/lib/SP/Infrastructure/User/Repositories/UserBaseRepository.php
index f97b8e75..97b73193 100644
--- a/lib/SP/Infrastructure/User/Repositories/UserBaseRepository.php
+++ b/lib/SP/Infrastructure/User/Repositories/UserBaseRepository.php
@@ -26,7 +26,7 @@ namespace SP\Infrastructure\User\Repositories;
use RuntimeException;
use SP\DataModel\ItemSearchData;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\DataModel\UserPreferencesData;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
@@ -51,7 +51,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
/**
* Updates an item
*
- * @param UserData $itemData
+ * @param User $itemData
*
* @return int
* @throws ConstraintException
@@ -106,7 +106,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
/**
* Checks whether the item is duplicated on updating
*
- * @param UserData $itemData
+ * @param User $itemData
*
* @return bool
* @throws ConstraintException
@@ -231,7 +231,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
WHERE U.id = ? LIMIT 1';
$queryData = new QueryData();
- $queryData->setMapClassName(UserData::class);
+ $queryData->setMapClassName(User::class);
$queryData->setQuery($query);
$queryData->addParam($id);
$queryData->setOnErrorMessage(__u('Error while retrieving the user\'s data'));
@@ -242,7 +242,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
/**
* Returns all the items
*
- * @return UserData[]
+ * @return User[]
* @throws QueryException
* @throws ConstraintException
*/
@@ -276,7 +276,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
FROM User U';
$queryData = new QueryData();
- $queryData->setMapClassName(UserData::class);
+ $queryData->setMapClassName(User::class);
$queryData->setQuery($query);
return $this->db->doSelect($queryData)->getDataAsArray();
@@ -328,7 +328,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
WHERE U.id IN ('.$this->buildParamsFromArray($ids).')';
$queryData = new QueryData();
- $queryData->setMapClassName(UserData::class);
+ $queryData->setMapClassName(User::class);
$queryData->setQuery($query);
$queryData->setParams($ids);
@@ -428,7 +428,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
/**
* Creates an item
*
- * @param UserData $itemData
+ * @param User $itemData
*
* @return int
* @throws SPException
@@ -488,7 +488,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
/**
* Checks whether the item is duplicated on adding
*
- * @param UserData $itemData
+ * @param User $itemData
*
* @return bool
* @throws ConstraintException
@@ -554,7 +554,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
WHERE U.login = ? OR U.ssoLogin = ? LIMIT 1';
$queryData = new QueryData();
- $queryData->setMapClassName(UserData::class);
+ $queryData->setMapClassName(User::class);
$queryData->setQuery($query);
$queryData->setParams([$login, $login]);
$queryData->setOnErrorMessage(__u('Error while retrieving the user\'s data'));
@@ -585,7 +585,7 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
FROM User U';
$queryData = new QueryData();
- $queryData->setMapClassName(UserData::class);
+ $queryData->setMapClassName(User::class);
$queryData->setQuery($query);
return $this->db->doSelect($queryData);
@@ -658,13 +658,13 @@ final class UserBaseRepository extends BaseRepository implements UserRepository
}
/**
- * @param UserData $itemData
+ * @param User $itemData
*
* @return int
* @throws ConstraintException
* @throws QueryException
*/
- public function updateOnLogin(UserData $itemData): int
+ public function updateOnLogin(User $itemData): int
{
$query = 'UPDATE User SET
pass = ?,
diff --git a/lib/SP/Infrastructure/User/Repositories/UserGroupBaseRepository.php b/lib/SP/Infrastructure/User/Repositories/UserGroupBaseRepository.php
index 9afcc620..95ec572d 100644
--- a/lib/SP/Infrastructure/User/Repositories/UserGroupBaseRepository.php
+++ b/lib/SP/Infrastructure/User/Repositories/UserGroupBaseRepository.php
@@ -25,10 +25,10 @@
namespace SP\Infrastructure\User\Repositories;
use SP\DataModel\ItemSearchData;
-use SP\DataModel\UserGroupData;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
+use SP\Domain\User\Models\UserGroup;
use SP\Domain\User\Ports\UserGroupRepository;
use SP\Infrastructure\Common\Repositories\BaseRepository;
use SP\Infrastructure\Common\Repositories\DuplicatedItemException;
@@ -167,7 +167,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
public function getById(int $id): QueryResult
{
$queryData = new QueryData();
- $queryData->setMapClassName(UserGroupData::class);
+ $queryData->setMapClassName(UserGroup::class);
$queryData->setQuery('SELECT id, `name`, description FROM UserGroup WHERE id = ? LIMIT 1');
$queryData->addParam($id);
@@ -186,7 +186,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
public function getByName(string $name): QueryResult
{
$queryData = new QueryData();
- $queryData->setMapClassName(UserGroupData::class);
+ $queryData->setMapClassName(UserGroup::class);
$queryData->setQuery('SELECT id, `name`, description FROM UserGroup WHERE name = ? LIMIT 1');
$queryData->addParam($name);
@@ -203,7 +203,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
public function getAll(): QueryResult
{
$queryData = new QueryData();
- $queryData->setMapClassName(UserGroupData::class);
+ $queryData->setMapClassName(UserGroup::class);
$queryData->setQuery('SELECT id, `name`, description FROM UserGroup ORDER BY name');
return $this->db->doSelect($queryData);
@@ -228,7 +228,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
'SELECT id, name, description FROM UserGroup WHERE id IN ('.$this->buildParamsFromArray($ids).')';
$queryData = new QueryData();
- $queryData->setMapClassName(UserGroupData::class);
+ $queryData->setMapClassName(UserGroup::class);
$queryData->setQuery($query);
$queryData->setParams($ids);
@@ -269,7 +269,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
public function search(ItemSearchData $itemSearchData): QueryResult
{
$queryData = new QueryData();
- $queryData->setMapClassName(UserGroupData::class);
+ $queryData->setMapClassName(UserGroup::class);
$queryData->setSelect('id, name, description');
$queryData->setFrom('UserGroup');
$queryData->setOrder('name');
@@ -293,7 +293,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
/**
* Creates an item
*
- * @param UserGroupData $itemData
+ * @param UserGroup $itemData
*
* @return int
* @throws SPException
@@ -320,7 +320,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
/**
* Checks whether the item is duplicated on adding
*
- * @param UserGroupData $itemData
+ * @param UserGroup $itemData
*
* @return bool
* @throws ConstraintException
@@ -338,7 +338,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
/**
* Updates an item
*
- * @param UserGroupData $itemData
+ * @param UserGroup $itemData
*
* @return int
* @throws ConstraintException
@@ -366,7 +366,7 @@ final class UserGroupBaseRepository extends BaseRepository implements UserGroupR
/**
* Checks whether the item is duplicated on updating
*
- * @param UserGroupData $itemData
+ * @param UserGroup $itemData
*
* @return bool
* @throws ConstraintException
diff --git a/tests/SPT/Domain/Account/Services/AccountSearchTest.php b/tests/SPT/Domain/Account/Services/AccountSearchTest.php
index 830f25de..eff2116e 100644
--- a/tests/SPT/Domain/Account/Services/AccountSearchTest.php
+++ b/tests/SPT/Domain/Account/Services/AccountSearchTest.php
@@ -27,8 +27,7 @@ namespace SPT\Domain\Account\Services;
use PHPUnit\Framework\MockObject\Builder\InvocationStubber;
use PHPUnit\Framework\MockObject\MockObject;
use RuntimeException;
-use SP\DataModel\UserData;
-use SP\DataModel\UserGroupData;
+use SP\DataModel\User;
use SP\Domain\Account\Dtos\AccountSearchFilterDto;
use SP\Domain\Account\Ports\AccountSearchConstants;
use SP\Domain\Account\Ports\AccountSearchDataBuilder;
@@ -37,6 +36,7 @@ use SP\Domain\Account\Services\AccountSearch;
use SP\Domain\Core\Exceptions\ConstraintException;
use SP\Domain\Core\Exceptions\QueryException;
use SP\Domain\Core\Exceptions\SPException;
+use SP\Domain\User\Models\UserGroup;
use SP\Domain\User\Ports\UserGroupServiceInterface;
use SP\Domain\User\Ports\UserServiceInterface;
use SP\Infrastructure\Database\QueryResult;
@@ -242,7 +242,7 @@ class AccountSearchTest extends UnitaryTestCase
$userService
->method('getByLogin')
->willReturn(
- new UserData([
+ new User([
'id' => self::$faker->randomNumber(),
'userGroupId' => self::$faker->randomNumber(),
])
@@ -252,7 +252,7 @@ class AccountSearchTest extends UnitaryTestCase
$userGroupService
->method('getByName')
->willReturn(
- new UserGroupData([
+ new UserGroup([
'id' => self::$faker->randomNumber(),
])
);
diff --git a/tests/SPT/Domain/Import/Services/CsvImportTest.php b/tests/SPT/Domain/Import/Services/CsvImportTest.php
index cfcbcfa3..b1733c04 100644
--- a/tests/SPT/Domain/Import/Services/CsvImportTest.php
+++ b/tests/SPT/Domain/Import/Services/CsvImportTest.php
@@ -35,8 +35,8 @@ use SP\Domain\Client\Ports\ClientService;
use SP\Domain\Config\Ports\ConfigService;
use SP\Domain\Core\Crypt\CryptInterface;
use SP\Domain\Import\Dtos\CsvImportParamsDto;
+use SP\Domain\Import\Ports\FileImportService;
use SP\Domain\Import\Services\CsvImport;
-use SP\Domain\Import\Services\FileImportService;
use SP\Domain\Import\Services\ImportException;
use SP\Domain\Import\Services\ImportHelper;
use SP\Domain\Tag\Ports\TagServiceInterface;
diff --git a/tests/SPT/Generators/UserDataGenerator.php b/tests/SPT/Generators/UserDataGenerator.php
index 2fb02c87..9d97426e 100644
--- a/tests/SPT/Generators/UserDataGenerator.php
+++ b/tests/SPT/Generators/UserDataGenerator.php
@@ -24,7 +24,7 @@
namespace SPT\Generators;
-use SP\DataModel\UserData;
+use SP\DataModel\User;
use SP\DataModel\UserPassData;
use SP\DataModel\UserPreferencesData;
@@ -33,9 +33,9 @@ use SP\DataModel\UserPreferencesData;
*/
final class UserDataGenerator extends DataGenerator
{
- public function buildUserData(): UserData
+ public function buildUserData(): User
{
- return new UserData(array_merge($this->getUserProperties(), $this->getUserPassProperties()));
+ return new User(array_merge($this->getUserProperties(), $this->getUserPassProperties()));
}
/**