Created
May 29, 2015 14:36
-
-
Save pounard/670042218adf719ded72 to your computer and use it in GitHub Desktop.
Restores all modules version to their latest number (useful if you did a wrong UPDATE in {system} table).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once DRUPAL_ROOT . '/includes/update.inc'; | |
$modules = db_query("SELECT name, 1 FROM {system} WHERE type = 'module'")->fetchAllKeyed(); | |
foreach (array_keys($modules) as $key) { | |
module_load_install($key); | |
$updates = []; | |
// From module.inc/update.inc. | |
$regexp = '/^' . $key . '_update_(?P<version>\d+)$/'; | |
$functions = get_defined_functions(); | |
foreach (preg_grep('/_\d+$/', $functions['user']) as $function) { | |
$matches = []; | |
if (preg_match($regexp, $function, $matches)) { | |
$updates[] = $matches['version']; | |
} | |
} | |
sort($updates, SORT_NUMERIC); | |
// End of from module.inc/update.inc. | |
$modules[$key] = $updates; | |
} | |
foreach ($modules as $module => $updates) { | |
if (empty($updates)) { | |
db_query("UPDATE {system} SET schema_version = 7000 WHERE name = :module", [':module' => $module]); | |
print "Fixed $module to 7000\n"; | |
} else { | |
$max = max($updates); | |
print "Fixed $module to $max\n"; | |
db_query("UPDATE {system} SET schema_version = :max WHERE name = :module", [':module' => $module, ':max' => $max]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment