File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
src/applications/conduit/method/user Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -58,14 +58,18 @@ protected function execute(ConduitAPIRequest $request) {
5858 throw new ConduitException ('ERR-BAD-EPOCH ' );
5959 }
6060
61- // TODO: This SELECT should have LOCK IN SHARE MODE and be in transaction
62- // with the next INSERT.
63- $ overlap = id (new PhabricatorUserStatus ())->loadAllWhere (
61+ $ table = new PhabricatorUserStatus ();
62+ $ table ->openTransaction ();
63+ $ table ->beginWriteLocking ();
64+
65+ $ overlap = $ table ->loadAllWhere (
6466 'userPHID = %s AND dateFrom < %d AND dateTo > %d ' ,
6567 $ user_phid ,
6668 $ to ,
6769 $ from );
6870 if ($ overlap ) {
71+ $ table ->endWriteLocking ();
72+ $ table ->killTransaction ();
6973 throw new ConduitException ('ERR-OVERLAP ' );
7074 }
7175
@@ -83,6 +87,9 @@ protected function execute(ConduitAPIRequest $request) {
8387 ->setDateTo ($ to )
8488 ->setStatus ($ status )
8589 ->save ();
90+
91+ $ table ->endWriteLocking ();
92+ $ table ->saveTransaction ();
8693 }
8794
8895}
Original file line number Diff line number Diff line change @@ -55,7 +55,11 @@ protected function execute(ConduitAPIRequest $request) {
5555 throw new ConduitException ('ERR-BAD-EPOCH ' );
5656 }
5757
58- $ overlap = id (new PhabricatorUserStatus ())->loadAllWhere (
58+ $ table = new PhabricatorUserStatus ();
59+ $ table ->openTransaction ();
60+ $ table ->beginReadLocking ();
61+
62+ $ overlap = $ table ->loadAllWhere (
5963 'userPHID = %s AND dateFrom < %d AND dateTo > %d ' ,
6064 $ user_phid ,
6165 $ to ,
@@ -80,6 +84,9 @@ protected function execute(ConduitAPIRequest $request) {
8084 $ status ->delete ();
8185 }
8286 }
87+
88+ $ table ->endReadLocking ();
89+ $ table ->saveTransaction ();
8390 return count ($ overlap );
8491 }
8592
You can’t perform that action at this time.
0 commit comments