Skip to content

Commit 124d760

Browse files
authored
[Elements] Add new service to return if element is locked (#313)
* add logic for element locking status * add tests * Apply php-cs-fixer changes * move wildcard to query type --------- Co-authored-by: lukmzig <[email protected]>
1 parent e2a1f9b commit 124d760

File tree

20 files changed

+419
-56
lines changed

20 files changed

+419
-56
lines changed

config/pimcore/config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ pimcore_generic_data_index:
8484
type: integer
8585
lock:
8686
type: keyword
87-
isLocked:
88-
type: boolean
8987
hasWorkflowWithPermissions:
9088
type: boolean
9189
dependencies:

config/services/search-index-adapter/default-search.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ services:
3333
arguments:
3434
$client: '@generic-data-index.search-client'
3535

36+
Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\ElementLockServiceInterface:
37+
class: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\ElementLockService
38+
arguments:
39+
$client: '@generic-data-index.search-client'
40+
3641
Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\Search\Pagination\PaginationInfoServiceInterface:
3742
class: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\Search\Pagination\PaginationInfoService
3843

doc/01_Installation/02_Upgrade.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Following steps are necessary during updating to newer versions.
55
## Upgrade to 2.0.0
66
- [Indexing] Added inherited fields indicator to data object indexing
77
- [Indexing] Added functionality to enqueue dependent items
8+
- Added a new method `isElementLocked()` to the `ElementLockService`, which provides functionality to retrieve element locked status based on the index data
89

910
### BC-Breaks
1011
- Removed deprecated alias `generic-data-index.opensearch-client` and replaced it with `generic-data-index.search-client`
@@ -19,6 +20,7 @@ Following steps are necessary during updating to newer versions.
1920
- Add element type to the `getIds` method of `Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\SearchResult\ElementSearchResult`
2021
- Added `getSpecialPermissions` method to `Pimcore\Bundle\GenericDataIndexBundle\Service\Permission\ElementPermissionServiceInterface` to get special permissions workspace language permissions for elements
2122
- Removed layout permission from `Pimcore\Bundle\GenericDataIndexBundle\Permission\DataObjectPermissions` as they are not index relevant
23+
- Removed property `isLocked` from Index for elements as it needs to be dynamically calculated
2224

2325
#### Interface changes
2426
- Added `PermissionTypes $permissionType` parameter with default type `PermissionTypes::LIST` to

src/Enum/SearchIndex/DefaultSearch/QueryType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ enum QueryType: string
2020
{
2121
case BOOL = 'bool';
2222
case TERMS = 'terms';
23+
case WILDCARD = 'wildcard';
2324
}

src/Enum/SearchIndex/FieldCategory/SystemField.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ enum SystemField: string
4848
case USER_OWNER = 'userOwner';
4949
case USER_MODIFICATION = 'userModification';
5050
case LOCKED = 'locked';
51-
case IS_LOCKED = 'isLocked';
5251
case HAS_WORKFLOW_WITH_PERMISSIONS = 'hasWorkflowWithPermissions';
5352
case FILE_SIZE = 'fileSize';
5453
case DEPENDENCIES = 'dependencies';
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\GenericDataIndexBundle\EventSubscriber;
18+
19+
use Exception;
20+
use Pimcore\Bundle\GenericDataIndexBundle\Installer;
21+
use Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\ElementLockServiceInterface;
22+
use Pimcore\Event\ElementEvents;
23+
use Pimcore\Event\Model\ElementEvent;
24+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
25+
26+
/**
27+
* @internal
28+
*/
29+
final readonly class LockElementSubscriber implements EventSubscriberInterface
30+
{
31+
public function __construct(
32+
private Installer $installer,
33+
private ElementLockServiceInterface $lockService,
34+
) {
35+
}
36+
37+
public static function getSubscribedEvents(): array
38+
{
39+
return [
40+
ElementEvents::POST_ELEMENT_UNLOCK_PROPAGATE => 'updateUnlockPropagate',
41+
];
42+
}
43+
44+
/**
45+
* @throws Exception
46+
*/
47+
public function updateUnlockPropagate(ElementEvent $event): void
48+
{
49+
if (!$this->installer->isInstalled()) {
50+
return;
51+
}
52+
53+
$this->lockService->unlockPropagate($event->getElement());
54+
}
55+
}

src/Model/Search/Asset/SearchResult/AssetSearchResultItem.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class AssetSearchResultItem implements ElementSearchResultItemInterface
4545

4646
private ?string $locked;
4747

48-
private bool $isLocked;
49-
5048
/** @var AssetMetaData[] */
5149
private array $metaData;
5250

@@ -205,18 +203,6 @@ public function setLocked(?string $locked): AssetSearchResultItem
205203
return $this;
206204
}
207205

208-
public function isLocked(): bool
209-
{
210-
return $this->isLocked;
211-
}
212-
213-
public function setIsLocked(bool $isLocked): AssetSearchResultItem
214-
{
215-
$this->isLocked = $isLocked;
216-
217-
return $this;
218-
}
219-
220206
/**
221207
* This will deliver searchable metadata only.
222208
* Custom metadata which is not relevant for the asset grid will not be included.

src/Model/Search/DataObject/SearchResult/DataObjectSearchResultItem.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class DataObjectSearchResultItem implements ElementSearchResultItemInterface
5050

5151
private ?string $locked;
5252

53-
private bool $isLocked;
54-
5553
private ?int $creationDate;
5654

5755
private ?int $modificationDate;
@@ -235,18 +233,6 @@ public function setLocked(?string $locked): DataObjectSearchResultItem
235233
return $this;
236234
}
237235

238-
public function isLocked(): bool
239-
{
240-
return $this->isLocked;
241-
}
242-
243-
public function setIsLocked(?bool $isLocked): DataObjectSearchResultItem
244-
{
245-
$this->isLocked = (bool)$isLocked;
246-
247-
return $this;
248-
}
249-
250236
public function getCreationDate(): ?int
251237
{
252238
return $this->creationDate;

src/Model/Search/Document/SearchResult/DocumentSearchResultItem.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ class DocumentSearchResultItem implements ElementSearchResultItemInterface
4343

4444
private ?string $locked;
4545

46-
private bool $isLocked;
47-
4846
private ?int $creationDate;
4947

5048
private ?int $modificationDate;
@@ -186,18 +184,6 @@ public function setLocked(?string $locked): DocumentSearchResultItem
186184
return $this;
187185
}
188186

189-
public function isLocked(): bool
190-
{
191-
return $this->isLocked;
192-
}
193-
194-
public function setIsLocked(?bool $isLocked): DocumentSearchResultItem
195-
{
196-
$this->isLocked = (bool)$isLocked;
197-
198-
return $this;
199-
}
200-
201187
public function getCreationDate(): ?int
202188
{
203189
return $this->creationDate;

src/Model/Search/Interfaces/ElementSearchResultItemInterface.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ public function getLocked(): ?string;
5959

6060
public function setLocked(?string $locked): ElementSearchResultItemInterface;
6161

62-
public function isLocked(): bool;
63-
64-
public function setIsLocked(bool $isLocked): ElementSearchResultItemInterface;
65-
6662
public function getCreationDate(): ?int;
6763

6864
public function setCreationDate(?int $creationDate): ElementSearchResultItemInterface;

0 commit comments

Comments
 (0)