Showing posts with label Cache Files. Show all posts
Showing posts with label Cache Files. Show all posts

Thursday 26 April 2018

How to reindex | Upgrade | static-content:deploy | Cache flush | Cache clean | Important commands in Magento 2

You need to put this command on CMD | Terminal


For Upgrade data in Magento 2
php -dmemory_limit=5G bin/magento setup:upgrade 
For code compile
php bin/magento setup:di:compile
For Reindex data in Magento 2
php -dmemory_limit=5G bin/magento indexer:reindex
For Static Content Deploy data  in Magento 2
php -dmemory_limit=5G bin/magento setup:static-content:deploy -f
For Flush Cache in Magento 2
php -dmemory_limit=5G bin/magento cache:flush
For Clean Cache in Magento 2
php -dmemory_limit=5G bin/magento cache:clean
For generate a new image cache
bin/magento catalog:image:resize 
For Files and Directory Permission
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find var pub/static pub/media  generated/ app/etc -type f -exec chmod g+w {} \;
find var pub/static pub/media generated/ app/etc -type d -exec chmod g+ws {} \;
chown -R ubuntu:www-data .
chmod u+x bin/magento
chmod -R 777 . 

Tuesday 9 January 2018

Clear configurable Swatches, Images, Flush Magento ALL Cache and cache files

ini_set('display_errors', 1);
require_once('../app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
/* Clear Cache */
try {
    $allTypes = Mage::app()->useCache();
    foreach($allTypes as $type => $cache) {
        Mage::app()->getCacheInstance()->cleanType($type);
    }
   
    /**
     * Flush cache storage
     */
    Mage::dispatchEvent('adminhtml_cache_flush_all');
    Mage::app()->getCacheInstance()->flush();
   
    /**
     * Flush all magento cache
     */
    Mage::app()->cleanCache();
    Mage::dispatchEvent('adminhtml_cache_flush_system');
   
   
} catch (Exception $e) {
    Mage::logException($e->getMessage());
}
try {
    /* cleanImages */
    Mage::getModel('catalog/product_image')->clearCache();
    Mage::dispatchEvent('clean_catalog_images_cache_after');
   
    /* cleanSwatches */
    Mage::helper('configurableswatches/productimg')->clearSwatchesCache();
    Mage::dispatchEvent('clean_configurable_swatches_cache_after');
   
    clearCstoreCacheDir('../var/cache');
   
    echo 'Success';
   
} catch (Mage_Core_Exception $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo Mage::helper('adminhtml')->__('An error occurred while clearing the configurable swatches image cache.');
}
function clearCstoreCacheDir($dirPath) {
    if (!is_dir($dirPath)) {
        throw new InvalidArgumentException("$dirPath must be a directory");
    }
    if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
        $dirPath .= '/';
    }
    $files = glob($dirPath . '*', GLOB_MARK);
    foreach ($files as $file) {
        if (is_dir($file)) {
            self::deleteDir($file);
        } else {
            unlink($file);
        }
    }
    rmdir($dirPath);
}