Skip to content

Commit

Permalink
Merge pull request #55 from utopia-php/fix-uid-validation
Browse files Browse the repository at this point in the history
validate UID fix for documents
# Conflicts:
#	composer.lock
  • Loading branch information
abnegate committed Oct 29, 2024
1 parent ce97cdf commit 6379fd1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
68 changes: 34 additions & 34 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ public function importDatabaseResource(Resource $resource, bool $isLast): Resour
*/
protected function createDatabase(Database $resource): bool
{
$resourceId = $resource->getId() == 'unique()'
? ID::unique()
: $resource->getId();
if ($resource->getId() == 'unique()') {
$resource->setId(ID::unique());
}

$validator = new UID();

if (!$validator->isValid($resourceId)) {
if (!$validator->isValid($resource->getId())) {
throw new Exception(
resourceName: $resource->getName(),
resourceGroup: $resource->getGroup(),
Expand All @@ -322,8 +322,6 @@ protected function createDatabase(Database $resource): bool
);
}

$resource->setId($resourceId);

$database = $this->database->createDocument('databases', new UtopiaDocument([
'$id' => $resource->getId(),
'name' => $resource->getDatabaseName(),
Expand Down Expand Up @@ -362,13 +360,13 @@ protected function createDatabase(Database $resource): bool
*/
protected function createCollection(Collection $resource): bool
{
$resourceId = $resource->getId() == 'unique()'
? ID::unique()
: $resource->getId();
if ($resource->getId() == 'unique()') {
$resource->setId(ID::unique());
}

$validator = new UID();

if (!$validator->isValid($resourceId)) {
if (!$validator->isValid($resource->getId())) {
throw new Exception(
resourceName: $resource->getName(),
resourceGroup: $resource->getGroup(),
Expand All @@ -377,8 +375,6 @@ protected function createCollection(Collection $resource): bool
);
}

$resource->setId($resourceId);

$database = $this->database->getDocument(
'databases',
$resource->getDatabase()->getId()
Expand Down Expand Up @@ -893,6 +889,10 @@ protected function createIndex(Index $resource): bool
*/
protected function createDocument(Document $resource, bool $isLast): bool
{
if ($resource->getId() == 'unique()') {
$resource->setId(ID::unique());
}

$validator = new UID();

if (!$validator->isValid($resource->getId())) {
Expand Down

0 comments on commit 6379fd1

Please sign in to comment.