record id generator
This commit is contained in:
@@ -208,9 +208,14 @@ class DefaultBinding implements BindingProcessor
|
||||
'Espo\\Core\\WebSocket\\ZeroMQSubscriber'
|
||||
);
|
||||
|
||||
$binder->bindImplementation(
|
||||
$binder->bindImplementation(
|
||||
'Espo\\Core\\Acl\\Table\\TableFactory',
|
||||
'Espo\\Core\\Acl\\Table\\DefaultTableFactory'
|
||||
);
|
||||
|
||||
$binder->bindImplementation(
|
||||
'Espo\\Core\\Utils\\Id\\RecordIdGenerator',
|
||||
'Espo\\Core\\Utils\\Id\\DefaultRecordIdGenerator'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,16 +32,13 @@ namespace Espo\Core\ORM\Repositories;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\EntityFactory;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Core\Interfaces\Injectable;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Metadata,
|
||||
Utils\Config,
|
||||
Utils\FieldManagerUtil,
|
||||
HookManager,
|
||||
ApplicationState,
|
||||
Utils\Id\RecordIdGenerator,
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
@@ -98,9 +95,18 @@ class RDB extends \Espo\Core\Repositories\Database implements Injectable
|
||||
EntityFactory $entityFactory,
|
||||
Metadata $metadata,
|
||||
HookManager $hookManager,
|
||||
ApplicationState $applicationState
|
||||
ApplicationState $applicationState,
|
||||
RecordIdGenerator $recordIdGenerator
|
||||
) {
|
||||
parent::__construct($entityType, $entityManager, $entityFactory, $metadata, $hookManager, $applicationState);
|
||||
parent::__construct(
|
||||
$entityType,
|
||||
$entityManager,
|
||||
$entityFactory,
|
||||
$metadata,
|
||||
$hookManager,
|
||||
$applicationState,
|
||||
$recordIdGenerator
|
||||
);
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ use Espo\Core\ORM\{
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Metadata,
|
||||
Utils\Util,
|
||||
HookManager,
|
||||
ApplicationState,
|
||||
Utils\DateTime as DateTimeUtil,
|
||||
Utils\Id\RecordIdGenerator,
|
||||
};
|
||||
|
||||
class Database extends RDBRepository
|
||||
@@ -72,17 +72,21 @@ class Database extends RDBRepository
|
||||
|
||||
protected $applicationState;
|
||||
|
||||
protected $recordIdGenerator;
|
||||
|
||||
public function __construct(
|
||||
string $entityType,
|
||||
EntityManager $entityManager,
|
||||
EntityFactory $entityFactory,
|
||||
Metadata $metadata,
|
||||
HookManager $hookManager,
|
||||
ApplicationState $applicationState
|
||||
ApplicationState $applicationState,
|
||||
RecordIdGenerator $recordIdGenerator
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->hookManager = $hookManager;
|
||||
$this->applicationState = $applicationState;
|
||||
$this->recordIdGenerator = $recordIdGenerator;
|
||||
|
||||
$hookMediator = null;
|
||||
|
||||
@@ -115,7 +119,7 @@ class Database extends RDBRepository
|
||||
!$entity->has('id') &&
|
||||
!$entity->getAttributeParam('id', 'autoincrement')
|
||||
) {
|
||||
$entity->set('id', Util::generateId());
|
||||
$entity->set('id', $this->recordIdGenerator->generate());
|
||||
}
|
||||
|
||||
if (empty($options['skipAll'])) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2021 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Id;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class DefaultRecordIdGenerator implements RecordIdGenerator
|
||||
{
|
||||
public function generate(): string
|
||||
{
|
||||
return Util::generateId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2021 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Id;
|
||||
|
||||
interface RecordIdGenerator
|
||||
{
|
||||
public function generate(): string;
|
||||
}
|
||||
Reference in New Issue
Block a user