Initial commit

This commit is contained in:
root
2026-01-19 17:44:46 +01:00
commit 823af8b11d
8721 changed files with 1130846 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Field\DateTime;
use Espo\Core\Utils\Config;
use Espo\Entities\AppLogRecord;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\DeleteBuilder;
class AppLog implements Cleanup
{
private const PERIOD = '30 days';
public function __construct(
private EntityManager $entityManager,
private Config $config
) {}
public function process(): void
{
if (!$this->config->get('cleanupAppLog')) {
return;
}
$query = DeleteBuilder::create()
->from(AppLogRecord::ENTITY_TYPE)
->where(['createdAt<' => $this->getBefore()->toString()])
->build();
$this->entityManager->getQueryExecutor()->execute($query);
}
private function getBefore(): DateTime
{
/** @var string $period */
$period = $this->config->get('cleanupAppLogPeriod') ?? self::PERIOD;
return DateTime::createNow()->modify('-' . $period);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Field\DateTime;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Note;
use Espo\ORM\EntityManager;
/**
* @noinspection PhpUnused
*/
class Audit implements Cleanup
{
private const PERIOD = '3 months';
public function __construct(
private Metadata $metadata,
private EntityManager $entityManager,
private Config $config
) {}
public function process(): void
{
if (!$this->config->get('cleanupAudit')) {
return;
}
$entityTypeList = $this->getEntityTypeList();
foreach ($entityTypeList as $scope) {
$this->processEntityType($scope);
}
}
private function processEntityType(string $entityType): void
{
$query = $this->entityManager
->getQueryBuilder()
->delete()
->from(Note::ENTITY_TYPE)
->where([
'parentType' => $entityType,
'createdAt<' => $this->getBefore()->toString(),
'type' => [Note::TYPE_UPDATE],
])
->build();
$this->entityManager->getQueryExecutor()->execute($query);
}
/**
* @return string[]
*/
private function getEntityTypeList(): array
{
/** @var string[] $scopeList */
$scopeList = array_keys($this->metadata->get(['scopes']) ?? []);
$scopeList = array_filter($scopeList, function ($item) {
return $this->metadata->get("scopes.$item.entity") &&
!$this->metadata->get("scopes.$item.preserveAuditLog") &&
!$this->metadata->get("scopes.$item.stream");
});
return array_values($scopeList);
}
private function getBefore(): DateTime
{
/** @var string $period */
$period = $this->config->get('cleanupAuditPeriod') ?? self::PERIOD;
return DateTime::createNow()->modify('-' . $period);
}
}

View File

@@ -0,0 +1,73 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\ORM\EntityManager;
use Espo\Core\Field\DateTime;
use Espo\Entities\Export;
class Exports implements Cleanup
{
private $config;
private $entityManager;
private string $cleanupPeriod = '2 days';
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupExportsPeriod', $this->cleanupPeriod);
$before = DateTime::createNow()
->modify($period)
->toString();
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from(Export::ENTITY_TYPE)
->where([
'createdAt<' => $before,
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,71 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\ORM\EntityManager;
use Espo\Core\Field\DateTime;
class MassActions implements Cleanup
{
private $config;
private $entityManager;
private string $cleanupPeriod = '14 days';
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupMassActionsPeriod', $this->cleanupPeriod);
$before = DateTime::createNow()
->modify($period)
->toString();
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from('MassAction')
->where([
'createdAt<' => $before,
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Field\DateTime;
use Espo\ORM\EntityManager;
use Espo\Entities\PasswordChangeRequest;
class PasswordChangeRequests implements Cleanup
{
private Config $config;
private EntityManager $entityManager;
private string $cleanupPeriod = '30 days';
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupPasswordChangeRequestsPeriod', $this->cleanupPeriod);
$before = DateTime::createNow()
->modify($period)
->toString();
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from(PasswordChangeRequest::ENTITY_TYPE)
->where([
'createdAt<' => $before,
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\Modules\Crm\Entities\Reminder;
use Espo\ORM\EntityManager;
use DateTime;
class Reminders implements Cleanup
{
private string $cleanupRemindersPeriod = '15 days';
private Config $config;
private EntityManager $entityManager;
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupRemindersPeriod', $this->cleanupRemindersPeriod);
$dt = new DateTime();
$dt->modify($period);
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from(Reminder::ENTITY_TYPE)
->where([
'remindAt<' => $dt->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT),
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Acl\UserAclManagerProvider;
use Espo\Entities\StarSubscription;
use Espo\Entities\User;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\DeleteBuilder;
use Espo\Tools\Stars\StarService;
/**
* @noinspection PhpUnused
*/
class Stars implements Cleanup
{
public function __construct(
private EntityManager $entityManager,
private UserAclManagerProvider $userAclManagerProvider,
private StarService $service
) {}
public function process(): void
{
foreach ($this->getEntityTypeList() as $entityType) {
$this->processEntityType($entityType);
}
}
/**
* @return string[]
*/
private function getEntityTypeList(): array
{
$groups = $this->entityManager->getRDBRepositoryByClass(StarSubscription::class)
->group('entityType')
->select('entityType')
->find();
$list = [];
foreach ($groups as $group) {
$list[] = $group->get('entityType');
}
return $list;
}
private function processEntityType(string $entityType): void
{
if (
!$this->service->isEnabled($entityType) ||
!$this->entityManager->hasRepository($entityType)
) {
$deleteQuery = DeleteBuilder::create()
->from(StarSubscription::ENTITY_TYPE)
->where(['entityType' => $entityType])
->build();
$this->entityManager->getQueryExecutor()->execute($deleteQuery);
return;
}
$stars = $this->entityManager
->getRDBRepositoryByClass(StarSubscription::class)
->where(['entityType' => $entityType])
->sth()
->find();
foreach ($stars as $star) {
$entityId = $star->get('entityId');
$userId = $star->get('userId');
if ($userId === null || $entityId === null) {
continue;
}
$entity = $this->entityManager->getEntityById($entityType, $entityId);
$user = $this->entityManager->getRDBRepositoryByClass(User::class)->getById($userId);
if (!$entity || !$user) {
$this->unstar($userId, $entityType, $entityId);
continue;
}
$aclManager = $this->userAclManagerProvider->get($user);
if (!$aclManager->checkEntityRead($user, $entity)) {
$this->unstar($userId, $entityType, $entityId);
}
}
}
private function unstar(string $userId, string $entityType, string $entityId): void
{
$deleteQuery = DeleteBuilder::create()
->from(StarSubscription::ENTITY_TYPE)
->where([
'userId' => $userId,
'entityType' => $entityType,
'entityId' => $entityId,
])
->build();
$this->entityManager->getQueryExecutor()->execute($deleteQuery);
}
}

View File

@@ -0,0 +1,130 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Field\DateTime;
use Espo\Core\Name\Field;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
use Espo\Entities\StreamSubscription;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\Part\Condition as Cond;
class Subscribers implements Cleanup
{
private const PERIOD = '2 months';
public function __construct(
private Metadata $metadata,
private EntityManager $entityManager,
private Config $config
) {}
public function process(): void
{
if (!$this->config->get('cleanupSubscribers')) {
return;
}
/** @var string[] $scopeList */
$scopeList = array_keys($this->metadata->get(['scopes']) ?? []);
/** @var string[] $scopeList */
$scopeList = array_values(array_filter(
$scopeList,
fn ($item) => (bool) $this->metadata->get(['scopes', $item, 'stream'])
));
foreach ($scopeList as $scope) {
$this->processEntityType($scope);
}
}
private function processEntityType(string $entityType): void
{
/** @var ?array<string, mixed> $data */
$data = $this->metadata->get(['streamDefs', $entityType, 'subscribersCleanup']);
if (!($data['enabled'] ?? false)) {
return;
}
/** @var string $dateField */
$dateField = $data['dateField'] ?? Field::CREATED_AT;
/** @var ?string[] $statusList */
$statusList = $data['statusList'] ?? null;
/** @var ?string $statusField */
$statusField = $this->metadata->get(['scopes', $entityType, 'statusField']);
if ($statusList === null || $statusField === null) {
return;
}
/** @var string $period */
$period = $this->metadata->get(['streamDefs', $entityType, 'subscribersCleanup', 'period']) ??
$this->config->get('cleanupSubscribersPeriod') ??
self::PERIOD;
$before = DateTime::createNow()->modify('-' . $period);
$query = $this->entityManager
->getQueryBuilder()
->delete()
->from(StreamSubscription::ENTITY_TYPE, 'subscription')
->join(
$entityType,
'entity',
Cond::equal(
Cond::column('entity.id'),
Cond::column('entityId')
)
)
->where(
Cond::and(
Cond::equal(
Cond::column('entityType'),
$entityType
),
Cond::less(
Cond::column('entity.' . $dateField),
$before->toString()
),
Cond::in(
Cond::column('entity.' . $statusField),
$statusList
)
)
)
->build();
$this->entityManager->getQueryExecutor()->execute($query);
}
}

View File

@@ -0,0 +1,77 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\ORM\EntityManager;
use Espo\Entities\TwoFactorCode;
use DateTime;
class TwoFactorCodes implements Cleanup
{
private const PERIOD = '5 days';
private $config;
private $entityManager;
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupTwoFactorCodesPeriod', self::PERIOD);
$from = (new DateTime())
->modify($period)
->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT);
$query = $this->entityManager
->getQueryBuilder()
->delete()
->from(TwoFactorCode::ENTITY_TYPE)
->where([
'createdAt<' => $from,
])
->build();
$this->entityManager
->getQueryExecutor()
->execute($query);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\Entities\WebhookEventQueueItem;
use Espo\Entities\WebhookQueueItem;
use Espo\ORM\EntityManager;
use DateTime;
use Espo\ORM\Name\Attribute;
/**
* @noinspection PhpUnused
*/
class WebhookQueue implements Cleanup
{
private string $cleanupWebhookQueuePeriod = '10 days';
public function __construct(private Config $config, private EntityManager $entityManager)
{}
public function process(): void
{
$period = '-' . $this->config->get('cleanupWebhookQueuePeriod', $this->cleanupWebhookQueuePeriod);
$datetime = new DateTime();
$datetime->modify($period);
$from = $datetime->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT);
$query1 = $this->entityManager
->getQueryBuilder()
->delete()
->from(WebhookQueueItem::ENTITY_TYPE)
->where([
'DATE:(createdAt)<' => $from,
'OR' => [
'status!=' => WebhookQueueItem::STATUS_PENDING,
Attribute::DELETED => true,
],
])
->build();
$this->entityManager->getQueryExecutor()->execute($query1);
$query2 = $this->entityManager
->getQueryBuilder()
->delete()
->from(WebhookEventQueueItem::ENTITY_TYPE)
->where([
'DATE:(createdAt)<' => $from,
'OR' => [
'isProcessed' => true,
Attribute::DELETED => true,
],
])
->build();
$this->entityManager->getQueryExecutor()->execute($query2);
}
}