久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Magento 捕獲異常并回滾數(shù)據(jù)庫事務(wù)

Magento catching exceptions and rolling back database transactions(Magento 捕獲異常并回滾數(shù)據(jù)庫事務(wù))
本文介紹了Magento 捕獲異常并回滾數(shù)據(jù)庫事務(wù)的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在研究 Magento 模塊,需要知道是否可以回滾一系列模型保存.基本上,我有五個模型加上我模塊中的幾個模型,我需要一個接一個地保存:

I'm working on a Magento module and need to know if it's possible to roll back a series of model saves. Basically, I have five models plus several from my module that I need to save one after the other:

admin/role
admin/user
core/website
core/store_group
core/store
mymodule/model1
mymodule/model2

我的問題是,每當(dāng)這些模型中的任何一個拋出異常時,我都需要進(jìn)入 MySQL 并手動刪除所有已保存的行.這是非常沒有成效的.

My problem is that whenever any of these models throw an exception, I need to go into MySQL and manually delete all the rows that were saved. This is very unproductive.

我很確定 Magento 沒有我可以在我的上下文中訪問的回滾過程.比如我查看了Mage_Core_Model_Abstract,在save方法中,回滾機(jī)制都是受保護(hù)的.

I'm pretty sure that Magento doesn't have a rollback procedure that I can access in my context. For example, I looked in Mage_Core_Model_Abstract and in the save method, the rollback mechanisms are all protected.

那么,我的問題是,在 Magento 中進(jìn)行數(shù)據(jù)庫事務(wù)是否有一些我應(yīng)該注意的最佳實(shí)踐?

So, my question is, is there some best practice for doing database transactions in Magento that I should be aware of?

推薦答案

我在核心代碼中看到了以下內(nèi)容,看起來正是您訂購的.

I've seen the following used in core code, and it looks like its just what you ordered.

$transactionSave = Mage::getModel('core/resource_transaction');
$transactionSave->addObject($model_one)
$transactionSave->addObject($model_two)
$transactionSave->save();

core/resource_transaction 對象允許您添加 Magento 對象,并對它們執(zhí)行批量保存.試一試,我很想在評論中聽到這對你有用或沒用.

The core/resource_transaction object allows you to add Magento objects, and perform a mass save on them. Give that a try, and I'd love to hear how this does, or doesn't, work for you in the comments.

這篇關(guān)于Magento 捕獲異常并回滾數(shù)據(jù)庫事務(wù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 色偷偷噜噜噜亚洲男人 | 好婷婷网| 中文字幕国产一区 | 国产成人精品久久二区二区91 | 性欧美精品一区二区三区在线播放 | 久久av网站 | 欧美在线一区二区三区四区 | 亚洲性人人天天夜夜摸 | 国产日韩一区二区三免费 | 国产成人亚洲精品 | 色网在线观看 | 美女一级a毛片免费观看97 | 日韩久久精品视频 | 蜜桃视频在线观看免费视频网站www | 国产激情91久久精品导航 | 日韩欧美在线播放 | 国产中文在线观看 | 国产精品综合一区二区 | 91在线影院| 成人网址在线观看 | 99re视频在线 | 99视频在线免费观看 | 免费99精品国产自在在线 | 91在线视频一区 | 亚洲国产精品va在线看黑人 | 亚洲视频在线看 | 亚洲国产视频一区二区 | 日韩欧美在线不卡 | 国产69精品久久99不卡免费版 | 国产a区| 亚洲成人一区二区 | 午夜影院污| 久久一级免费视频 | 午夜丁香视频在线观看 | 亚洲精色 | 精品二| 日本又色又爽又黄又高潮 | 亚洲综合色视频在线观看 | 在线免费观看a级片 | 日韩三级视频 | av影音资源 |