-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add database utils and first method to delete entities
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Basecom\FixturePlugin\Utils; | ||
|
||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; | ||
|
||
readonly class DatabaseUtils | ||
{ | ||
public function __construct( | ||
private DefinitionInstanceRegistry $definitionInstanceRegistry, | ||
) { | ||
} | ||
|
||
public function deleteEntities(string $entity, Criteria $criteria): void | ||
{ | ||
$repository = $this->definitionInstanceRegistry->getRepository($entity); | ||
|
||
// First load all the ids of the entities | ||
$ids = $repository->searchIds($criteria, Context::createDefaultContext())->getData(); | ||
|
||
// Delete all entities with the IDs | ||
$repository->delete( | ||
array_values($ids), | ||
Context::createDefaultContext(), | ||
); | ||
} | ||
} |