Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed May 11, 2017
0 parents commit 46d6261
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Controller/Adminhtml/Indexer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2017 MagePal, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace MagePal\Reindex\Controller\Adminhtml;

abstract class Indexer extends \Magento\Backend\App\Action
{
/**
* Check ACL permissions
*
* @return bool
*/
protected function _isAllowed()
{
switch ($this->_request->getActionName()) {
case 'reindexOnTheFly':
return $this->_authorization->isAllowed('Magento_Indexer::changeMode');
}

return false;
}
}
60 changes: 60 additions & 0 deletions Controller/Adminhtml/Indexer/ReindexOnTheFly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © 2017 MagePal, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace MagePal\Reindex\Controller\Adminhtml\Indexer;

use Magento\Backend\App\Action\Context;

class ReindexOnTheFly extends \MagePal\Reindex\Controller\Adminhtml\Indexer
{

/** @var \Magento\Framework\Indexer\IndexerInterface */
protected $indexerFactory;

/**
* Index constructor.
* @param Context $context
* @param \Magento\Indexer\Model\IndexerFactory $indexerFactory
*/
public function __construct(
Context $context,
\Magento\Indexer\Model\IndexerFactory $indexerFactory
) {
$this->indexerFactory = $indexerFactory;
parent::__construct($context);
}

/**
* @return void
*/
public function execute()
{
$indexerIds = $this->getRequest()->getParam('indexer_ids');
if (!is_array($indexerIds)) {
$this->messageManager->addError(__('Please select indexers.'));
} else {
try {

foreach ($indexerIds as $indexerId) {
$indexer = $this->indexerFactory->create();
$indexer->load($indexerId)->reindexAll();

}

$this->messageManager->addSuccess(__('Reindex %1 indexer(s).', count($indexerIds))
);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException(
$e,
__("We couldn't reindex because of an error.")
);
}
}

$this->_redirect('*/*/list');
}
}
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Reindex Magento 2 from Admin


Reindex your Magento 2 store quickly and easily from backend/admin. Ideal for project managers or QA department during site development.

#### 1 - Installation
##### Manually
* Download the extension
* Unzip the file
* Create a folder {Magento 2 root}/app/code/MagePal/Reindex
* Copy the content from the unzip folder

##### Using Composer

```
composer require magepal/magento2-reindex
```

#### 2 - Enable Reindex (from {Magento root} folder)
* php -f bin/magento module:enable --clear-static-content MagePal_Reindex
* php -f bin/magento setup:upgrade
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "magepal/magento2-reindex",
"description": "Reindex Magento 2 from Admin",
"keywords": [
"magento 2",
"magento2",
"reindex",
"backend reindex",
"admin reindex"
],
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",

"magento/magento-composer-installer": "*"
},
"suggest": {

},
"type": "magento2-module",
"version": "1.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"MagePal\\Reindex\\": ""
}
}
}
14 changes: 14 additions & 0 deletions etc/adminhtml/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2017 MagePal. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="indexer">
<module name="MagePal_Reindex" after="Magento_Indexer" />
</route>
</router>
</config>
12 changes: 12 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2017 MagePal. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MagePal_Reindex" setup_version="1.0.0">
<module name="Magento_Indexer"/>
</module>
</config>
10 changes: 10 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © 2017 MagePal, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MagePal_Reindex',
__DIR__
);
21 changes: 21 additions & 0 deletions view/adminhtml/layout/indexer_indexer_list_grid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2017 MagePal. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="adminhtml.indexer.grid.grid.massaction">
<arguments>
<argument name="options" xsi:type="array">
<item name="change_mode_admin_reindex" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Reindex</item>
<item name="url" xsi:type="string">*/indexer/reindexOnTheFly</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>

0 comments on commit 46d6261

Please sign in to comment.