Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
rratsun committed Jul 13, 2023
1 parent 9ed1cd8 commit bae44b8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/Resources/i18n/de_DE/Settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"fields": {
"attachmentDuplicates": "Asset-Duplikat",
"fileNameRegexPattern": "Dateiname Regex Pattern"
},
"tooltips": {
Expand Down
1 change: 1 addition & 0 deletions app/Resources/i18n/en_US/Settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"fields": {
"attachmentDuplicates": "Asset Duplicates",
"fileNameRegexPattern": "Filename Regex Pattern"
},
"tooltips": {
Expand Down
1 change: 1 addition & 0 deletions app/Resources/i18n/ru_RU/Settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"fields": {
"attachmentDuplicates": "Дубликаты ресурсов",
"fileNameRegexPattern": "Шаблон для имени файла"
},
"tooltips": {
Expand Down
1 change: 1 addition & 0 deletions app/Resources/i18n/uk_UA/Settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"fields": {
"attachmentDuplicates": "Дублікати ресурсів",
"fileNameRegexPattern": "Шаблон для імені файлу"
},
"tooltips": {
Expand Down
6 changes: 6 additions & 0 deletions app/Resources/layouts/Settings/damSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
{
"label": "File Settings",
"rows": [
[
{
"name": "attachmentDuplicates"
},
false
],
[
{
"name": "fileNameRegexPattern"
Expand Down
16 changes: 16 additions & 0 deletions app/Resources/metadata/entityDefs/Settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"fields": {
"attachmentDuplicates": {
"type": "enum",
"default": "notAllowByContentAndName",
"optionsIds": [
"notAllowByContentAndName",
"notAllowByContent",
"notAllowByName",
"allow"
],
"options": [
"notAllowByContentAndName",
"notAllowByContent",
"notAllowByName",
"allow"
]
},
"fileNameRegexPattern": {
"type": "varchar",
"default": "/^[^\\\\\\/:\\*\\\"\\?<>%|\\s,]{1,64}/",
Expand Down
24 changes: 24 additions & 0 deletions app/Services/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ public function createEntity($attachment)
return $entity;
}

public function findAttachmentDuplicate(\stdClass $attachment): ?Entity
{
// skip duplicates checking for stream attachments
if (property_exists($attachment, 'relatedType') && $attachment->relatedType === 'Note') {
return null;
}

$duplicateParam = $this->getConfig()->get('attachmentDuplicates', 'notAllowByContentAndName');

if ($duplicateParam == 'notAllowByContent' && property_exists($attachment, 'md5')) {
return $this->getRepository()->where(['md5' => $attachment->md5])->findOne();
}

if ($duplicateParam == 'notAllowByName' && property_exists($attachment, 'name')) {
return $this->getRepository()->where(['name' => $attachment->name])->findOne();
}

if ($duplicateParam == 'notAllowByContentAndName' && property_exists($attachment, 'md5') && property_exists($attachment, 'name')) {
return $this->getRepository()->where(['md5' => $attachment->md5, 'name' => $attachment->name])->findOne();
}

return null;
}

public function attachmentHasAsset(\stdClass $input = null): bool
{
if (!empty($input) && property_exists($input, 'relatedType') && $input->relatedType === 'Note') {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "AtroDAM. Open source DAM application.",
"require": {
"ext-fileinfo": "*",
"atrocore/core": ">1.4.146 <1.7.0"
"atrocore/core": "~1.6.15"
},
"conflict": {
"atrocore/pim": "<1.8.0"
Expand Down

0 comments on commit bae44b8

Please sign in to comment.