mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 20:10:55 +01:00
Use transactions in user status Conduit methods
Test Plan: Add status, verify DB. Remove status, verify DB. Reviewers: epriestley Reviewed By: epriestley CC: aran, Koolvin Differential Revision: https://secure.phabricator.com/D2397
This commit is contained in:
parent
ba98089426
commit
70e5ef92cf
2 changed files with 18 additions and 4 deletions
|
@ -58,14 +58,18 @@ final class ConduitAPI_user_addstatus_Method extends ConduitAPI_user_Method {
|
|||
throw new ConduitException('ERR-BAD-EPOCH');
|
||||
}
|
||||
|
||||
// TODO: This SELECT should have LOCK IN SHARE MODE and be in transaction
|
||||
// with the next INSERT.
|
||||
$overlap = id(new PhabricatorUserStatus())->loadAllWhere(
|
||||
$table = new PhabricatorUserStatus();
|
||||
$table->openTransaction();
|
||||
$table->beginWriteLocking();
|
||||
|
||||
$overlap = $table->loadAllWhere(
|
||||
'userPHID = %s AND dateFrom < %d AND dateTo > %d',
|
||||
$user_phid,
|
||||
$to,
|
||||
$from);
|
||||
if ($overlap) {
|
||||
$table->endWriteLocking();
|
||||
$table->killTransaction();
|
||||
throw new ConduitException('ERR-OVERLAP');
|
||||
}
|
||||
|
||||
|
@ -83,6 +87,9 @@ final class ConduitAPI_user_addstatus_Method extends ConduitAPI_user_Method {
|
|||
->setDateTo($to)
|
||||
->setStatus($status)
|
||||
->save();
|
||||
|
||||
$table->endWriteLocking();
|
||||
$table->saveTransaction();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,7 +55,11 @@ final class ConduitAPI_user_removestatus_Method extends ConduitAPI_user_Method {
|
|||
throw new ConduitException('ERR-BAD-EPOCH');
|
||||
}
|
||||
|
||||
$overlap = id(new PhabricatorUserStatus())->loadAllWhere(
|
||||
$table = new PhabricatorUserStatus();
|
||||
$table->openTransaction();
|
||||
$table->beginReadLocking();
|
||||
|
||||
$overlap = $table->loadAllWhere(
|
||||
'userPHID = %s AND dateFrom < %d AND dateTo > %d',
|
||||
$user_phid,
|
||||
$to,
|
||||
|
@ -80,6 +84,9 @@ final class ConduitAPI_user_removestatus_Method extends ConduitAPI_user_Method {
|
|||
$status->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$table->endReadLocking();
|
||||
$table->saveTransaction();
|
||||
return count($overlap);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue