protected function execute(ConduitAPIRequest $request) { $user_phid = $request->getUser()->getPHID(); $from = $request->getValue('fromEpoch'); $to = $request->getValue('toEpoch'); if ($to <= $from) { throw new ConduitException('ERR-BAD-EPOCH'); } $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'); } id(new PhabricatorUserStatus())->setUserPHID($user_phid)->setDateFrom($from)->setDateTo($to)->setTextStatus($request->getValue('status'))->save(); $table->endWriteLocking(); $table->saveTransaction(); }