Skip to content

Commit

Permalink
Added controller to apply changes to database
Browse files Browse the repository at this point in the history
  • Loading branch information
rommmka committed Mar 30, 2023
1 parent 2927db7 commit f1201c6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Block/Adminhtml/Config/Form/Field/FixAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,34 @@ class FixAll extends \Magento\Config\Block\System\Config\Form\Field

public function render(AbstractElement $element)
{
$url = $this->_urlBuilder->getUrl('swissup/theme/fixAll');
$cacheUrl = $this->getUrl('adminhtml/cache/index');;
$buttonText = __("Fix All");
return <<<HTML
<tr>
<td colspan="100">
<div class="button-container">
<button id="fix-all-themes" class="button action-configure" type="button"><span>$buttonText</span></button>
</div>
<script type="text/javascript">
<button id="fix-all-themes" class="button action-configure" type="button"
onclick="jQuery.ajax({
url: '{$url}',
method: 'POST',
dataType: 'json',
showLoader: true,
data: {
form_key: window.FORM_KEY
},
success: function(data) {
alert(data.message);
jQuery('#row_swissup_core_troubleshooting_virtualcheck .themes-table table').hide();
jQuery('#fix-all-themes').hide();
jQuery('<tr><td>Please, <a href=&quot;{$cacheUrl}&quot; target=_blank>clear the cache</a></td></tr>').insertAfter('#row_swissup_core_troubleshooting_virtualcheck');
</script>
},
error: function() {
alert('An error occurred while updating theme types.');
}
})"><span>$buttonText</span></button>
</div>
</td>
</tr>
HTML;
Expand Down
24 changes: 24 additions & 0 deletions Controller/Adminhtml/Theme/FixAll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Swissup\Core\Controller\Adminhtml\Theme;

use Magento\Framework\Controller\ResultFactory;

class FixAll extends \Magento\Backend\App\Action
{
const ADMIN_RESOURCE = 'Swissup_Core::theme_fixall';

public function execute()
{
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData(['message' => 'Virtual themes fixed. Please, clear the cache!']);

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$connection = $objectManager->create('\Magento\Framework\App\ResourceConnection')->getConnection();
$tableName = $connection->getTableName('theme');
$connection->update($tableName, ['type' => 0]);

return $resultJson;
}
}

1 comment on commit f1201c6

@ci-swissuplabs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify your commit as it didn't pass some tests

Please sign in to comment.