-
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 deletion helper to reduce complexity (#64)
* Dont run vendor fixtures by default, add flag to run vendor fixtures * Trailing slashes! * Change docs formats * Use first class callable syntax * Refactor FixtureTrait * Enable phpstan rule: checkMissingIterableValueType * Enable rule checkGenericClassInNonGenericObjectType in psalm * Add database utils and first method to delete entities * Automatically assign the fixtureHelper to each fixture * Disable error warnings if generics arent provided, since they were added in SW 6.5.something * Update src/FixtureLoader.php It can´t be readonly, because you use a setter and you will set the helper on other classes * Update friendsofphp/php-cs-fixer requirement from 3.57.2 to 3.58.1 (#65) Updates the requirements on [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) to permit the latest version. - [Release notes](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases) - [Changelog](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/CHANGELOG.md) - [Commits](PHP-CS-Fixer/PHP-CS-Fixer@v3.57.2...v3.58.1) --- updated-dependencies: - dependency-name: friendsofphp/php-cs-fixer dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update test trait & harden psalm linting (#63) * Dont run vendor fixtures by default, add flag to run vendor fixtures * Trailing slashes! * Change docs formats * Use first class callable syntax * Refactor FixtureTrait * Enable phpstan rule: checkMissingIterableValueType * Enable rule checkGenericClassInNonGenericObjectType in psalm * Disable error warnings if generics arent provided, since they were added in SW 6.5.something * Remove readonly param --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Robin Valley <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8bff2e9
commit faead55
Showing
5 changed files
with
61 additions
and
2 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
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
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(), | ||
); | ||
} | ||
} |