問題描述
自動即時回滾是企業級部署機制的重要特性.目前,使用 Magento 的內置安裝工具無法實現這一點.
Automated instant rollback is an important feature of enterprise-grade deployment mechanisms. Currently, it's not possible to achieve this using Magento's built-in installation tools.
鑒于 Magento 的 core_resource
機制允許順序執行安裝或升級模塊的安裝腳本(通過執行 SQL 和 PHP),恕我直言,它應該支持相同的過程似乎是合乎邏輯的相反.
Given that Magento's core_resource
mechanism allows for the sequential execution of setup scripts for installation or upgrade of modules (via execution of SQL and also PHP), it seems logical IMHO that it should support the same process in reverse.
現在,一些不支持它的明顯原因:
Now, some obvious reasons not to support it:
回滾腳本要獨立(并且可能是冪等的?)將具有挑戰性.我認為這不是避免該功能的正當理由,充其量只是一個借口.
It would be challenging for the rollback scripts to be independent (and possibly idempotent?). I don't see this to be a valid reason to avoid the feature, it's an excuse at best.
其他模塊可能依賴于已安裝的模塊.模塊的 xml 聲明
節點可用于標記這些鏈接.
Other modules might have dependencies on the installed module. The module's xml declaration <depends/>
node could be used to flag these linkages.
開發人員可能想要暫時禁用模塊而不進行完全卸載.這可能需要 xml 聲明 節點中的新狀態.
A developer might want to temporarily disable a module without doing a full uninstall. This could require a new status in the xml declaration <active/>
node.
對您的想法感興趣.
京東
Interested in your thoughts.
JD
推薦答案
我看過一些關于此類的帖子,并且我自己也調查了 SQL 部署的相同場景.我不得不同意企業級 Magento 應該內置這種類型的功能.好消息是,至少在一些形式或時尚方面,我不確定它有多完整.以下是異?;貪L示例:
I have seen some postings in regards to such and have investigated the same scenarios for SQL deployment myself. I would have to agree that being Enterprise grade Magento should have this type of functionality built-in. The good news it IS, at least in SOME form or fashion, how complete it is I'm not really sure. Here's a sample of a rollback upon exception:
try {
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->beginTransaction();
// do stuff here
$write->commit();
} catch (Exception $e) {
mage::log(__METHOD__ . ':' . __LINE__ . ': Rollback happened.');
$write->rollback();
}
現在,如果您查看 app/code/core/Mage/Core/Model/Resource/Setup.php,您會發現很多有趣的方法.特別是:_getModifySqlFiles
、_rollbackResourceDb
和 _modifyResourceDb
.
Now if you take a look at app/code/core/Mage/Core/Model/Resource/Setup.php you'll find quite a bit of interesting methods. In particular: _getModifySqlFiles
, _rollbackResourceDb
and _modifyResourceDb
.
_modifyResourceDb
對我來說是最有趣的,因為這里的 $actionType 也可以回滾和卸載 - 另請注意,您也可以將 PHP 文件用于安裝文件.
_modifyResourceDb
is the most interesting to me, since the $actionType here can be rollback and uninstall as well - also note you can use PHP files for your setup files as well.
// Read resource files
$arrAvailableFiles = array();
$sqlDir = dir($sqlFilesDir);
while (false !== ($sqlFile = $sqlDir->read())) {
$matches = array();
if (preg_match('#^'.$resModel.'-'.$actionType.'-(.*).(sql|php)$#i', $sqlFile, $matches)) {
$arrAvailableFiles[$matches[1]] = $sqlFile;
}
}
這段代碼執行后:
$arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles);
但在這里我假設核心 Magento 開發人員迷失在 EAV 資源模型的內部,只是讓它部分完成.
But heres where I'm assuming core Magento devs got lost in the bowels of the EAV resource model and just left it partially complete.
protected function _getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrFiles)
{
$arrRes = array();
switch ($actionType) {
case 'install':
case 'data-install':
...
case 'rollback':
break;
case 'uninstall':
break;
}
return $arrRes;
}
我還沒有機會真正測試上述內容,但僅從我對 magento 和自動加載的 ORM 的初步調查以及另一位開發人員對他的調查結果的投入來看.
I've not had a chance to really test out the above, but from just my initial investigations of the ORM that is magento and the Autoloading as well as another developer's input on his findings as well.
最終,如果我們可以在版本控制系統中保持所有更改至少模塊明智,那將是理想的.顯然,不應該以這種方式管理需要導入的龐大數據集,但是對于這些小的增量更改,我想推送到暫存、生產測試,如果失敗,則將其拉回一個版本,一切都恢復正常.
Ultimately it would be ideal if we can keep all of our changes at least module wise within a version controlled system. Obviously huge data sets that need to be imported shouldn't be managed this way but for these small incremental changes I want to push to staging, production test and if it fails pull it back one version and everything is back to normal.
顯然沒有一種理想的解決方案可以用于部署具有不同要求和需求的如此多的客戶,但執行此操作的通用方法將有助于代碼/SQL 部署.具有諷刺意味的是,Enterprise 有 CMS 登臺,以及代碼模塊化開發的能力,但 DB 卻沒有得到那么多的愛.
Obviously theres no one ideal solution for deployment with so many clients having different requirements and needs but a general way of doing this would help with code/SQL deployment. It's kind of ironic that Enterprise has CMS staging, and the ability for modular development of code, but the DB has not gotten as much love.
有一個相關的問題是指出我們目前如何使用一些自制"的專門腳本來做到這一點:
There is a related question that is noting how currently we are doing it with some specialized scripts "home-brewed" that essentially do:
執行 MySQLDump 或備份,然后替換 SQL 文件中的 BASE_URL.
Doing a MySQLDump or backup, then doing a replace on the BASE_URLs in the SQL file.
Magento 部署最佳實踐
另一個需要查看的工具是 Phing.
Another tool to look at would be Phing.
如果有人有時間調查似乎實施的回滾"和卸載"過程并報告他們的發現對我也有幫助.
If anyone has time to investigate the "rollback" and "uninstall" processes that seem to be implemented and report their findings would be helpful to me as well.
這篇關于Magento 不支持模塊的卸載/降級有什么原因嗎的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!