0

When I edit something on a product, Magento always ask, reindex 'Product Flat Data' and refresh cache 'Blocks HTML output'

I manually process those whenever I edit but it's very annoying when I have to edit my product often. I give up to those two task since I have to do it later again

Is there any way automatically reindex 'Product Flat Data' and refresh cache 'Blocks HTML output' every few hours? like using cronjob (then how to setup?)

3 Answers 3

4

Magento has a class that specifically handles command line scripts. The Magento bootstrap can be handled via the Shell Abstract script inside of your shell/ folder.

<?php

include_once 'abstract.php';

class JohnG_Shell_Cron extends Mage_Shell_Abstract {

    public function run() {
        $this->_clearindex();
        $this->_clearCache();
    }

    protected function _clearindex() {
        $process = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_flat');
        $process->reindexAll();
    }

    protected function _clearCache() {
        Mage::app()->getCacheInstance()->clean('block_html');
    }
}

Now setup your cron like this:

0 0-23/2 * * * php -f /path/to/your/magento/shell/johngscript.php
2
  • The script above won't do anything unless you load the class and run it. You need to add $shell = new JohnG_Shell_Cron(); $shell->run();
    – paj
    Commented May 18, 2015 at 10:48
  • I had to use Mage::app()->getCacheInstance()->cleanType('block_html');
    – Seb
    Commented Mar 11, 2016 at 10:30
1

You can do something like this:

Create a php file called "refresh.php".

<?php
require dirname(__FILE__).'/app/Mage.php'; // It's good to pull the entire path for a cron.
Mage::app();
$process = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_flat')->reindexAll(); // Run Flat Product reindex
Mage::app()->getCacheInstance()->clean('block_html'); // Flush Block cache

You can then call this file in crontab whenever you want.

1

You can do this by create shell script.

At first line you need add magento bootrap file Mage.php.then set store as admin

<?php
require_once "YOUR_MAGENTODIR/app/Mage.php"
Mage::app("admin"); //set store as admin
umask();

/* reindex */
$process = Mage::getModel('index/indexer')->getProcessByCode('atalog_product_flat');
$process->reindexAll();
/* Clear Catch */

Mage::app()->getCacheInstance()->clean('block_html');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.