如何在Typo3中编写extbase repository方法以进行更新



我已经在Typo3中编写了一个更新查询,现在我需要将其更改为Query-Object repository方法。如何更改下面的代码?

public function updatePaymentDetails($uid, $txnID, $amt, $stats)
{
    $itemUID = $uid;
    $transID = $txnID;
    $amountPaid = $amt;
    $txStatus = $stats;
    $tableName = 'tx_paypalpayment_domain_model_transactions AS tpp';
    $whereCondition = 'tpp.uid=' . '"' . $itemUID . '"';
    $setValues = ['transactionid' => $transID, 'amount' => $amountPaid, 'txnstatus' => $txStatus];
    $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tableName, $whereCondition, $setValues);
    return $result;
}

我用自己的想法创建了很多(不知道它是正确的(,剩下的部分应该是什么?

public function paymentUpdate($uid, $txnID, $amt, $stats) {
   $query = $this->createQuery();
   $query->matching(
      $query->logicalAnd(
         $query->equals("transactionid", $txnID),
         $query->equals("amount", $amt),
         $query->equals("txnstatus", $stats)
      )
   );
   /*---   Update Code   ---*/
   return $query->execute();
}

有什么方法可以做到吗?

typo3/extbase方法是首先从持久性层获取交易,然后将更改应用于域对象,然后在您的存储库中进行更新。

在您的控制器操作中类似下面的东西:

$transaction = $this->transactionRepository->findByIdentifier($itemUid);
$transaction->setTransactionId($transID);
$transaction->setAmount($amountPaid);
$transaction->setStatus($txStatus);
$this->transactionRepository->update($transaction);

如果您想进行直接更新而不是先获取记录,请查看TYPO3CMSCoreDatabaseQueryQueryBuilder(仅在Qypo3-8.7及以上的较新版本中存在(。在Typo3的较旧版本中,您可以看一下$GLOBALS['TYPO3_DB']->exec_*

相关内容

最新更新