getUnusedKeyByOperatorId($operatorId); if ($record) { $this->status = 'invalidated'; $this->save(); } $this->reset(); $this->renew_key = $this->getPseudoRandomString(32); $this->operator_id = $operatorId; $this->email = $email; $this->status = 'unused'; $this->save(); } public function getUnusedKeyByOperatorId(int $operatorId): self|null|false { return $this->load( ['"operator_id"=? AND "status"=?', $operatorId, 'unused'], ); } public function getByRenewKey(string $key): self|null|false { return $this->load( ['"renew_key"=? AND "status"=?', $key, 'unused'], ); } public function deactivate(): void { if ($this->loaded()) { $this->status = 'used'; $this->save(); } } }