Skip to content

Commit

Permalink
Added ability to run upgrades directly from modules grid
Browse files Browse the repository at this point in the history
  • Loading branch information
vovayatsyuk committed Jan 27, 2017
1 parent c26f9bf commit 062369a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ public function getActions(Varien_Object $row)
{
$links = array();

if ($row->getVersionStatus() === TM_Core_Model_Module::VERSION_OUTDATED) {
$links[] = sprintf(
'<a href="%s">%s</a>',
$this->getUrl('*/*/upgrade/', array('_current' => true, 'id' => $row->getId())),
Mage::helper('tmcore')->__('Run Upgrades')
);
}

if ($row->hasUpgradesDir() || $row->getIdentityKeyLink()) {
$links[] = sprintf(
'<a href="%s">%s</a>',
$this->getUrl('*/*/manage/', array('_current' => true, 'id' => $row->getId())),
Mage::helper('tmcore')->__('Open Installer')
);
}

if ($row->getDocsLink()) {
$links[] = sprintf(
'<a href="%s" title="%s" onclick="window.open(this.href); return false;">%s</a>',
Expand Down Expand Up @@ -39,14 +55,6 @@ public function getActions(Varien_Object $row)
);
}

if ($row->hasUpgradesDir() || $row->getIdentityKeyLink()) {
$links[] = sprintf(
'<a href="%s">%s</a>',
$this->getUrl('*/*/manage/', array('_current' => true, 'id' => $row->getId())),
Mage::helper('tmcore')->__('Open Installer')
);
}

return $links;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,44 @@ public function runAction()
$this->_redirect('*/*/');
}

/**
* Run module upgrades
*/
public function upgradeAction()
{
$id = $this->getRequest()->getParam('id');
if (!$id) {
$this->_redirect('*/*/');
}

/**
* @var TM_Core_Model_Module
*/
$module = Mage::getModel('tmcore/module');
$module->load($id);
$module->up();

$groupedErrors = $module->getMessageLogger()->getErrors();
if (count($groupedErrors)) {
foreach ($groupedErrors as $type => $errors) {
foreach ($errors as $error) {
if (is_array($error)) {
$message = $error['message'];
} else {
$message = $error;
}
Mage::getSingleton('adminhtml/session')->addError($message);
}
}
return $this->_redirect('*/*/', array('id' => $module->getId()));
}

Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('tmcore')->__("Module upgrades successfully applied")
);
$this->_redirect('*/*/');
}

protected function _isAllowed()
{
return Mage::getSingleton('admin/session')->isAllowed('templates_master/tmcore_module');
Expand Down

0 comments on commit 062369a

Please sign in to comment.