There is a reason Magento should not support removal / downgrade for modules

Automatic instant rollback is an important feature of enterprise-level deployment mechanisms. This is currently not possible using Magento's built-in installation tools.

Considering that the Magento mechanism core_resourceallows sequential execution of installation scripts for installing or updating modules (via SQL and PHP execution), it seems logical IMHO that it should support the same process in the reverse order.

Now some obvious reasons not to support it:

  • It would be difficult for the rollback scripts to be independent (and possibly idempotent?). I do not see this to be a good reason to avoid this function, it is an excuse at best.

  • Other modules may have dependencies on the installed module. The <depends/>node module flag declaration can be used to indicate these relationships.

  • The developer may want to temporarily disable the module without completely uninstalling it. This may require a new status in the xml <active/>node declaration .

Interested in their thoughts. Jd

+2
source share
3 answers

SQL. , Enterprise Magento . - , , , , . :

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();
}

, //​​ ​​/Mage/Core/Model/Resource/Setup.php, . : _getModifySqlFiles, _rollbackResourceDb _modifyResourceDb.

_modifyResourceDb , $actionType - , PHP .

// 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 .

protected function _getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrFiles)
{
    $arrRes = array();

    switch ($actionType) {
        case 'install':
        case 'data-install':
...
        case 'rollback':
            break;

        case 'uninstall':
            break;
    }
    return $arrRes;
}

, ORM, magento Autoloading, .

, , , , , . , , , , , , , .

, , , /SQL. , Enterprise CMS , .

, , , " ", :

MySQLDump , BASE_URL SQL.

Magento

: Phing.

, "" "", , , .

+3
  • , :

    @ , Magento 2.0 , . , , Zend_Db. Doctrine 2.0 orm , Magento :)

    , Doctrine, , , PHPDoc (, reflection), . . , , , .

    Magento, , , , XML - . , .
    , , , , , , Doctrine . , . ?

  • <depends/> .

  • , .: D

Edit:
. , , Magento , , .

+3

. , Magento.

, : 1. 2. 2.

. / . , " ". , . . , .

, , - . , .

If Magento doesn't support this out of the box, I don't think it would be wise to use it. It seems that the basic requirement is that if you do not plan and code from the very beginning, it will be quite difficult to implement.

+1
source

All Articles