mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
cleanupOrphanAttachments fix
This commit is contained in:
@@ -209,25 +209,17 @@ class Cleanup extends \Espo\Core\Jobs\Base
|
||||
}
|
||||
|
||||
if ($this->getConfig()->get('cleanupOrphanAttachments')) {
|
||||
$collection = $this->getEntityManager()->getRepository('Attachment')->where([
|
||||
[
|
||||
'role' => 'Attachment',
|
||||
],
|
||||
'OR' => [
|
||||
[
|
||||
'parentId' => null,
|
||||
'parentType!=' => null,
|
||||
'relatedType=' => null,
|
||||
],
|
||||
[
|
||||
'parentType' => null,
|
||||
'relatedId' => null,
|
||||
'relatedType!=' => null,
|
||||
]
|
||||
],
|
||||
$selectManager = $this->getContainer()->get('selectManagerFactory')->create('Attachment');
|
||||
|
||||
$selectParams = $selectManager->getEmptySelectParams();
|
||||
$selectManager->applyFilter('orphan', $selectParams);
|
||||
|
||||
$selectParams['whereClause'][] = [
|
||||
'createdAt<' => $datetime->format('Y-m-d H:i:s'),
|
||||
'createdAt>' => '2018-01-01 00:00:00',
|
||||
])->limit(0, 5000)->find();
|
||||
];
|
||||
|
||||
$collection = $this->getEntityManager()->getRepository('Attachment')->limit(0, 5000)->find($selectParams);
|
||||
|
||||
foreach ($collection as $e) {
|
||||
$this->getEntityManager()->removeEntity($e);
|
||||
|
||||
@@ -35,19 +35,27 @@ class Attachment extends \Espo\Core\SelectManagers\Base
|
||||
{
|
||||
$result['whereClause'][] = [
|
||||
'role' => ['Attachment', 'Inline Attachment'],
|
||||
'OR' => [
|
||||
[
|
||||
'parentId' => null,
|
||||
'parentType!=' => null,
|
||||
'relatedType=' => null
|
||||
[
|
||||
'OR' => [
|
||||
[
|
||||
'parentId' => null,
|
||||
'parentType!=' => null,
|
||||
'relatedType=' => null,
|
||||
],
|
||||
[
|
||||
'parentType' => null,
|
||||
'relatedId' => null,
|
||||
'relatedType!=' => null,
|
||||
],
|
||||
],
|
||||
[
|
||||
'parentType' => null,
|
||||
'relatedId' => null,
|
||||
'relatedType!=' => null
|
||||
]
|
||||
],
|
||||
'attachmentChild.id' => null
|
||||
[
|
||||
'OR' => [
|
||||
'relatedType!=' => 'Settings',
|
||||
'relatedType=' => null,
|
||||
],
|
||||
],
|
||||
'attachmentChild.id' => null,
|
||||
];
|
||||
|
||||
$this->addLeftJoin(['Attachment', 'attachmentChild', [
|
||||
|
||||
Reference in New Issue
Block a user