Skip to content

Instantly share code, notes, and snippets.

@Alanaktion
Forked from colinmollenhour/cleanCache.php
Last active November 9, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alanaktion/24ae8e3e39c71d39b9fb345688b519a5 to your computer and use it in GitHub Desktop.
Save Alanaktion/24ae8e3e39c71d39b9fb345688b519a5 to your computer and use it in GitHub Desktop.
Safely run Magento 1.x upgrade scripts via CLI
<?php
/**
* Set global/skip_process_modules_updates to '1' in app/etc/local.xml and
* then use this script to apply updates and refresh the config cache without
* causing a stampede on the config cache.
*
* It should be placed in the shell/ directory, and must be run via CLI.
*/
if(strtolower(php_sapi_name()) != 'cli'){
exit;
}
umask(0);
set_time_limit(0);
set_include_path(
get_include_path() . PATH_SEPARATOR .
dirname(dirname(__FILE__))
);
require_once('app/Mage.php');
// Init without cache so we get a fresh version
Mage::app('admin','store', array('global_ban_use_cache' => TRUE));
echo "Applying updates... ";
Mage_Core_Model_Resource_Setup::applyAllUpdates();
Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
echo "done.\n";
// Now enable caching and save
Mage::getConfig()->getOptions()->setData('global_ban_use_cache', FALSE);
Mage::app()->baseInit(array()); // Re-init cache
Mage::getConfig()->loadModules()->loadDb()->saveCache();
echo "Saved config cache. Refresh all caches to finish the upgrade.\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment