Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ad3n committed Feb 6, 2025
1 parent 25aec67 commit aaf3a44
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
18 changes: 15 additions & 3 deletions lib/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$io->title('Clear Cache');
$update = $application->find('cache:clear');
$update->run(new ArrayInput([


$input = new ArrayInput([
'command' => 'cache:clear',
]), $output);
]);
$input->setInteractive(false);
$cacheClear = $application->find('cache:clear');
$cacheClear->run($input, $output);

$input = new ArrayInput([
'command' => 'doctrine:schema:update',
'--force' => null,
]);
$input->setInteractive(false);
$schemaUpdater = $application->find('doctrine:schema:update');
$schemaUpdater->run($input, $output);

$io->success('Code generated successfully');

Expand Down
4 changes: 2 additions & 2 deletions lib/Entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use KejawenLab\ApiSkeleton\Repository\GroupRepository;
use KejawenLab\ApiSkeleton\Security\GroupIdGenerator;
use KejawenLab\ApiSkeleton\Security\IdGenerator;
use KejawenLab\ApiSkeleton\Security\Model\GroupInterface;
use KejawenLab\ApiSkeleton\Util\StringUtil;
use OpenApi\Attributes as OA;
Expand All @@ -33,7 +33,7 @@ class Group implements GroupInterface
#[OA\Property(type: 'string')]
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
#[ORM\CustomIdGenerator(class: GroupIdGenerator::class)]
#[ORM\CustomIdGenerator(class: IdGenerator::class)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
private UuidInterface $id;

Expand Down
29 changes: 29 additions & 0 deletions lib/Security/IdGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace KejawenLab\ApiSkeleton\Security;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Id\AbstractIdGenerator;
use KejawenLab\ApiSkeleton\Security\Model\GroupInterface;
use Ramsey\Uuid\Uuid;

/**
* @author Muhamad Surya Iksanudin<[email protected]>
*/
final class IdGenerator extends AbstractIdGenerator
{
public function generateId(EntityManagerInterface $em, object|null $entity): mixed
{
if (!$entity instanceof GroupInterface) {
return Uuid::uuid4();
}

if (GroupInterface::SUPER_ADMIN_CODE !== $entity->getCode()) {
return Uuid::uuid4();
}

return Uuid::fromString(GroupInterface::SUPER_ADMIN_ID);
}
}

0 comments on commit aaf3a44

Please sign in to comment.