3 posts tagged

magento 2

Mark index as invalid or invalidate index in Magento 2

To programmatically mark on of the indexes as invalid you need help of

\Magento\Framework\Indexer\IndexerRegistry

. After receiving the indexer instance, you can call

invalidate()

method.

Example

$this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate();
Aug 12   index   indexer   magento 2

Clear redis cache

redis-cli -h <host> -p <port> flushall

The command will remove all data from client connected (with host and port).

2019   cache   magento 2   redis

Log Debug Backtrace in Magento 2

$obj = \Magento\Framework\App\ObjectManager::getInstance();
$fileHandler = $obj->create(\Magento\Framework\Logger\Handler\Base::class, ['fileName' => 'var/log/debug.log']);
$logger = $obj->create(\Monolog\Logger::class, [
                'name' => 'save',
                'handlers' => ['file' => $fileHandler],
                'processors' => ['process_id' => $obj->get(\Monolog\Processor\ProcessIdProcessor::class)]
            ]);
$logger->info(var_export(\Magento\Framework\Debug::backtrace(1, 0, 1), 1));

Result could be found in var/log/debug.log

2018   debug   log   magento 2