Skip to content

Commit

Permalink
Replace Exception by simple console output line. Fixes the issue when…
Browse files Browse the repository at this point in the history
… Magento installation failed when Algolia extension was already added to Magento.
  • Loading branch information
JanPetr committed Feb 9, 2017
1 parent 369d436 commit 56ffac6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 28 deletions.
9 changes: 7 additions & 2 deletions Model/Indexer/AdditionalSection.php
Expand Up @@ -8,6 +8,7 @@
use Magento;
use Magento\Framework\Message\ManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Symfony\Component\Console\Output\ConsoleOutput;

class AdditionalSection implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface
{
Expand All @@ -16,14 +17,16 @@ class AdditionalSection implements Magento\Framework\Indexer\ActionInterface, Ma
private $queue;
private $configHelper;
private $messageManager;
private $output;

public function __construct(StoreManagerInterface $storeManager, Data $helper, Queue $queue, ConfigHelper $configHelper, ManagerInterface $messageManager)
public function __construct(StoreManagerInterface $storeManager, Data $helper, Queue $queue, ConfigHelper $configHelper, ManagerInterface $messageManager, ConsoleOutput $output)
{
$this->fullAction = $helper;
$this->storeManager = $storeManager;
$this->queue = $queue;
$this->configHelper = $configHelper;
$this->messageManager = $messageManager;
$this->output = $output;
}

public function execute($ids)
Expand All @@ -36,7 +39,9 @@ public function executeFull()
$errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';

if (php_sapi_name() === 'cli') {
throw new \Exception($errorMessage);
$this->output->writeln($errorMessage);

return;
}

$this->messageManager->addErrorMessage($errorMessage);
Expand Down
10 changes: 8 additions & 2 deletions Model/Indexer/Category.php
Expand Up @@ -10,6 +10,7 @@
use Magento;
use Magento\Framework\Message\ManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Symfony\Component\Console\Output\ConsoleOutput;

class Category implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface
{
Expand All @@ -20,6 +21,7 @@ class Category implements Magento\Framework\Indexer\ActionInterface, Magento\Fra
private $queue;
private $configHelper;
private $messageManager;
private $output;

public static $affectedProductIds = [];

Expand All @@ -29,7 +31,8 @@ public function __construct(StoreManagerInterface $storeManager,
AlgoliaHelper $algoliaHelper,
Queue $queue,
ConfigHelper $configHelper,
ManagerInterface $messageManager)
ManagerInterface $messageManager,
ConsoleOutput $output)
{
$this->fullAction = $helper;
$this->storeManager = $storeManager;
Expand All @@ -38,6 +41,7 @@ public function __construct(StoreManagerInterface $storeManager,
$this->queue = $queue;
$this->configHelper = $configHelper;
$this->messageManager = $messageManager;
$this->output = $output;
}

public function execute($categoryIds)
Expand All @@ -46,7 +50,9 @@ public function execute($categoryIds)
$errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';

if (php_sapi_name() === 'cli') {
throw new \Exception($errorMessage);
$this->output->writeln($errorMessage);

return;
}

$this->messageManager->addErrorMessage($errorMessage);
Expand Down
10 changes: 8 additions & 2 deletions Model/Indexer/Page.php
Expand Up @@ -10,6 +10,7 @@
use Magento;
use Magento\Framework\Message\ManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Symfony\Component\Console\Output\ConsoleOutput;

class Page implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface
{
Expand All @@ -20,6 +21,7 @@ class Page implements Magento\Framework\Indexer\ActionInterface, Magento\Framewo
private $queue;
private $configHelper;
private $messageManager;
private $output;

public function __construct(
StoreManagerInterface $storeManager,
Expand All @@ -28,7 +30,8 @@ public function __construct(
AlgoliaHelper $algoliaHelper,
Queue $queue,
ConfigHelper $configHelper,
ManagerInterface $messageManager
ManagerInterface $messageManager,
ConsoleOutput $output
) {
$this->fullAction = $helper;
$this->storeManager = $storeManager;
Expand All @@ -37,6 +40,7 @@ public function __construct(
$this->queue = $queue;
$this->configHelper = $configHelper;
$this->messageManager = $messageManager;
$this->output = $output;
}

public function execute($ids)
Expand All @@ -49,7 +53,9 @@ public function executeFull()
$errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';

if (php_sapi_name() === 'cli') {
throw new \Exception($errorMessage);
$this->output->writeln($errorMessage);

return;
}

$this->messageManager->addErrorMessage($errorMessage);
Expand Down
29 changes: 18 additions & 11 deletions Model/Indexer/Product.php
Expand Up @@ -10,6 +10,7 @@
use Magento;
use Magento\Framework\Message\ManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Symfony\Component\Console\Output\ConsoleOutput;

class Product implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface
{
Expand All @@ -20,22 +21,26 @@ class Product implements Magento\Framework\Indexer\ActionInterface, Magento\Fram
private $configHelper;
private $queue;
private $messageManager;

public function __construct(StoreManagerInterface $storeManager,
ProductHelper $productHelper,
Data $helper,
AlgoliaHelper $algoliaHelper,
ConfigHelper $configHelper,
Queue $queue,
ManagerInterface $messageManager)
{
private $output;

public function __construct(
StoreManagerInterface $storeManager,
ProductHelper $productHelper,
Data $helper,
AlgoliaHelper $algoliaHelper,
ConfigHelper $configHelper,
Queue $queue,
ManagerInterface $messageManager,
ConsoleOutput $output
) {
$this->fullAction = $helper;
$this->storeManager = $storeManager;
$this->productHelper = $productHelper;
$this->algoliaHelper = $algoliaHelper;
$this->configHelper = $configHelper;
$this->queue = $queue;
$this->messageManager = $messageManager;
$this->output = $output;
}

public function execute($productIds)
Expand All @@ -44,10 +49,12 @@ public function execute($productIds)
$errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';

if (php_sapi_name() === 'cli') {
throw new \Exception($errorMessage);
$this->output->writeln($errorMessage);

return;
}

$this->messageManager->addErrorMessage($errorMessage);
$this->messageManager->addWarning($errorMessage);

return;
}
Expand Down
9 changes: 7 additions & 2 deletions Model/Indexer/QueueRunner.php
Expand Up @@ -10,18 +10,21 @@
use Algolia\AlgoliaSearch\Model\Queue;
use Magento;
use Magento\Framework\Message\ManagerInterface;
use Symfony\Component\Console\Output\ConsoleOutput;

class QueueRunner implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface
{
private $configHelper;
private $queue;
private $messageManager;
private $output;

public function __construct(ConfigHelper $configHelper, Queue $queue, ManagerInterface $messageManager)
public function __construct(ConfigHelper $configHelper, Queue $queue, ManagerInterface $messageManager, ConsoleOutput $output)
{
$this->configHelper = $configHelper;
$this->queue = $queue;
$this->messageManager = $messageManager;
$this->output = $output;
}

public function execute($ids)
Expand All @@ -34,7 +37,9 @@ public function executeFull()
$errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';

if (php_sapi_name() === 'cli') {
throw new \Exception($errorMessage);
$this->output->writeln($errorMessage);

return;
}

$this->messageManager->addErrorMessage($errorMessage);
Expand Down
25 changes: 16 additions & 9 deletions Model/Indexer/Suggestion.php
Expand Up @@ -10,6 +10,7 @@
use Magento;
use Magento\Framework\Message\ManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Symfony\Component\Console\Output\ConsoleOutput;

class Suggestion implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface
{
Expand All @@ -20,22 +21,26 @@ class Suggestion implements Magento\Framework\Indexer\ActionInterface, Magento\F
private $queue;
private $configHelper;
private $messageManager;
private $output;

public function __construct(StoreManagerInterface $storeManager,
SuggestionHelper $suggestionHelper,
Data $helper,
AlgoliaHelper $algoliaHelper,
Queue $queue,
ConfigHelper $configHelper,
ManagerInterface $messageManager)
{
public function __construct(
StoreManagerInterface $storeManager,
SuggestionHelper $suggestionHelper,
Data $helper,
AlgoliaHelper $algoliaHelper,
Queue $queue,
ConfigHelper $configHelper,
ManagerInterface $messageManager,
ConsoleOutput $output
) {
$this->fullAction = $helper;
$this->storeManager = $storeManager;
$this->suggestionHelper = $suggestionHelper;
$this->algoliaHelper = $algoliaHelper;
$this->queue = $queue;
$this->configHelper = $configHelper;
$this->messageManager = $messageManager;
$this->output = $output;
}

public function execute($ids)
Expand All @@ -48,7 +53,9 @@ public function executeFull()
$errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';

if (php_sapi_name() === 'cli') {
throw new \Exception($errorMessage);
$this->output->writeln($errorMessage);

return;
}

$this->messageManager->addErrorMessage($errorMessage);
Expand Down

0 comments on commit 56ffac6

Please sign in to comment.