delete unique key from db

This commit is contained in:
Torsten Dittmann
2020-08-28 20:53:19 +02:00
parent 7484bdc347
commit edde41e50f
5 changed files with 62 additions and 1 deletions
+4
View File
@@ -209,6 +209,10 @@ $utopia->delete('/v1/users/:userId')
throw new Exception('Failed to remove user from DB', 500);
}
if (!$projectDB->deleteUniqueKey(md5('users:email='.$user->getAttribute('email', null)))) {
throw new Exception('Failed to remove unique key from DB', 500);
}
$reservedId = $projectDB->createDocument([
'$collection' => Database::SYSTEM_COLLECTION_RESERVED,
'$id' => $userId,
+9
View File
@@ -88,6 +88,15 @@ abstract class Adapter
*/
abstract public function deleteDocument($id);
/**
* Delete Unique Key.
*
* @param int $key
*
* @return array
*/
abstract public function deleteUniqueKey($key);
/**
* Create Namespace.
*
+21 -1
View File
@@ -191,7 +191,7 @@ class MySQL extends Adapter
$st = $this->getPDO()->prepare('INSERT INTO `'.$this->getNamespace().'.database.unique`
SET `key` = :key;
');
$st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR);
if (!$st->execute()) {
@@ -366,6 +366,26 @@ class MySQL extends Adapter
return [];
}
/**
* Delete Unique Key.
*
* @param int $id
*
* @return array
*
* @throws Exception
*/
public function deleteUniqueKey($key)
{
$st1 = $this->getPDO()->prepare('DELETE FROM `'.$this->getNamespace().'.database.unique` WHERE `key` = :key');
$st1->bindValue(':key', $key, PDO::PARAM_STR);
$st1->execute();
return [];
}
/**
* Create Relation.
*
+16
View File
@@ -153,6 +153,22 @@ class Redis extends Adapter
return $data;
}
/**
* Delete Unique Key.
*
* @param $key
*
* @return array
*
* @throws Exception
*/
public function deleteUniqueKey($key)
{
$data = $this->adapter->deleteUniqueKey($key);
return $data;
}
/**
* Create Namespace.
*
+12
View File
@@ -298,6 +298,18 @@ class Database
return new Document($this->adapter->deleteDocument($id));
}
/**
* @param int $key
*
* @return Document|false
*
* @throws AuthorizationException
*/
public function deleteUniqueKey($key)
{
return new Document($this->adapter->deleteUniqueKey($key));
}
/**
* @return array
*/