Commit c5eea4a5 authored by catch's avatar catch
Browse files

Issue #1372122 by klausi, sun, beejeebus, juampy, mradcliffe: Fixed STOP the...

Issue #1372122 by klausi, sun, beejeebus, juampy, mradcliffe: Fixed STOP the registry integrity constraint violation nightmare.
parent 789ab2a3
...@@ -2941,11 +2941,30 @@ function registry_rebuild() { ...@@ -2941,11 +2941,30 @@ function registry_rebuild() {
* to be called, because it is already known that the list of files in the * to be called, because it is already known that the list of files in the
* {system} table matches those in the file system. * {system} table matches those in the file system.
* *
* @return
* TRUE if the registry was rebuilt, FALSE if another thread was rebuilding
* in parallel and the current thread just waited for completion.
*
* @see registry_rebuild() * @see registry_rebuild()
*/ */
function registry_update() { function registry_update() {
// install_system_module() calls module_enable() which calls into this
// function during initial system installation, so the lock system is neither
// loaded nor does its storage exist yet.
$in_installer = drupal_installation_attempted();
if (!$in_installer && !lock_acquire(__FUNCTION__)) {
// Another request got the lock, wait for it to finish.
lock_wait(__FUNCTION__);
return FALSE;
}
require_once DRUPAL_ROOT . '/core/includes/registry.inc'; require_once DRUPAL_ROOT . '/core/includes/registry.inc';
_registry_update(); _registry_update();
if (!$in_installer) {
lock_release(__FUNCTION__);
}
return TRUE;
} }
/** /**
......
...@@ -124,10 +124,6 @@ function _registry_parse_files($files) { ...@@ -124,10 +124,6 @@ function _registry_parse_files($files) {
if (file_exists($filename)) { if (file_exists($filename)) {
$hash = hash_file('sha256', $filename); $hash = hash_file('sha256', $filename);
if (empty($file['hash']) || $file['hash'] != $hash) { if (empty($file['hash']) || $file['hash'] != $hash) {
// Delete registry entries for this file, so we can insert the new resources.
db_delete('registry')
->condition('filename', $filename)
->execute();
$file['hash'] = $hash; $file['hash'] = $hash;
$parsed_files[$filename] = $file; $parsed_files[$filename] = $file;
} }
...@@ -149,9 +145,9 @@ function _registry_parse_files($files) { ...@@ -149,9 +145,9 @@ function _registry_parse_files($files) {
* Parse a file and save its function and class listings. * Parse a file and save its function and class listings.
* *
* @param $filename * @param $filename
* Name of the file we are going to parse. * Name of the file we are going to parse.
* @param $contents * @param $contents
* Contents of the file we are going to parse as a string. * Contents of the file we are going to parse as a string.
* @param $module * @param $module
* (optional) Name of the module this file belongs to. * (optional) Name of the module this file belongs to.
* @param $weight * @param $weight
...@@ -159,17 +155,25 @@ function _registry_parse_files($files) { ...@@ -159,17 +155,25 @@ function _registry_parse_files($files) {
*/ */
function _registry_parse_file($filename, $contents, $module = '', $weight = 0) { function _registry_parse_file($filename, $contents, $module = '', $weight = 0) {
if (preg_match_all('/^\s*(?:abstract|final)?\s*(class|interface)\s+([a-zA-Z0-9_]+)/m', $contents, $matches)) { if (preg_match_all('/^\s*(?:abstract|final)?\s*(class|interface)\s+([a-zA-Z0-9_]+)/m', $contents, $matches)) {
$query = db_insert('registry')->fields(array('name', 'type', 'filename', 'module', 'weight'));
foreach ($matches[2] as $key => $name) { foreach ($matches[2] as $key => $name) {
$query->values(array( db_merge('registry')
'name' => $name, ->key(array(
'type' => $matches[1][$key], 'name' => $name,
'filename' => $filename, 'type' => $matches[1][$key],
'module' => $module, ))
'weight' => $weight, ->fields(array(
)); 'filename' => $filename,
'module' => $module,
'weight' => $weight,
))
->execute();
} }
$query->execute(); // Delete any resources for this file where the name is not in the list
// we just merged in.
db_delete('registry')
->condition('filename', $filename)
->condition('name', $matches[2], 'NOT IN')
->execute();
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment