Index: bakery.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bakery/bakery.module,v retrieving revision 1.52.2.1 diff -u -p -r1.52.2.1 bakery.module --- bakery.module 29 Apr 2010 23:52:19 -0000 1.52.2.1 +++ bakery.module 5 May 2010 21:05:16 -0000 @@ -99,6 +99,11 @@ function bakery_user($op, &$array, &$acc _bakery_eat_cookie(session_name()); } else if ($op == 'update' && variable_get('bakery_is_master', 0)) { + // Invoke implementations of Bakery transmit hook for syncing arbitrary data. + $transmit = module_invoke_all('bakery_transmit', $edit, $account, $category); + if (!empty($transmit)) { + $_SESSION['bakery'] = $transmit; + } // We store email/name if they changed. We want to wait with doing // anything else until the changes are saved locally. foreach (variable_get('bakery_supported_fields', array('mail' => 'mail', 'name' => 'name')) as $type => $enabled) { @@ -124,10 +129,10 @@ function bakery_user($op, &$array, &$acc $result = drupal_http_request($slave .'bakery/update', array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'), 'POST', $payload); if ($result->code != 200) { drupal_set_message(t('Error %error for site at %url', array('%error' => $result->code .' '. $result->error, '%url' => $slave))); + watchdog('bakery', 'Update error %error for user %uid on site %url', array('%error' => $result->code .' '. $result->error, '%uid' => $account->uid, '%url' => $slave), WATCHDOG_ERROR); } else { drupal_set_message($result->data); - // TODO: Roll back the change. } } } @@ -508,7 +513,7 @@ function bakery_taste_stroopwafel_cookie if ($signature == $cookie['signature'] && $cookie['timestamp'] + variable_get('bakery_freshness', '3600') >= $_SERVER['REQUEST_TIME']) { $valid = TRUE; - $_SESSION['bakery'] = unserialize($cookie['data']); + $_SESSION['bakery']['data'] = unserialize($cookie['data']); $_SESSION['bakery']['uid'] = $cookie['uid']; $_SESSION['bakery']['category'] = $cookie['category']; } @@ -577,24 +582,49 @@ function bakery_eat_stroopwafel_cookie() $message = t('Account not found on %slave.', array('%slave' => variable_get('site_name', ''))); } else { - $fields = array(); + $fields = $previous = array(); foreach (variable_get('bakery_supported_fields', array('mail' => 'mail', 'name' => 'name')) as $type => $value) { if ($value) { - $fields[$type] = isset($stroopwafel[$type]) ? $stroopwafel[$type] : $account->$type; + $fields[$type] = isset($stroopwafel['data'][$type]) ? $stroopwafel['data'][$type] : $account->$type; + // Unset this value since we've put it into $fields. + unset($stroopwafel['data'][$type]); + // Hold onto previous values in case we need to roll back. + $previous[$type] = $account->$type; } } $status = user_save($account, $fields, $stroopwafel['category']); if ($status === FALSE) { watchdog('bakery', 'User update from name %name_old to %name_new, mail %mail_old to %mail_new failed.', array('%name_old' => $account->name, '%name_new' => $stroopwafel['name'], '%mail_old' => $account->mail, '%mail_new' => $stroopwafel['mail']), WATCHDOG_ERROR); - $message = t('There was a problem updating your account on %slave. Please contact the administrator.', array('%slave' => variable_get('site_name', ''))); - header('HTTP/1.1 409 Conflict'); + // Roll back. + user_save($account, $previous, $stroopwafel['category']); } else { watchdog('bakery', 'user updated name %name_old to %name_new, mail %mail_old to %mail_new.', array('%name_old' => $account->name, '%name_new' => $stroopwafel['name'], '%mail_old' => $account->mail, '%mail_new' => $stroopwafel['mail'])); - $message = t('Successfully updated account on %slave.', array('%slave' => variable_get('site_name', ''))); + } + if (!empty($stroopwafel['data'])) { + // More data to sync, invoke Bakery receive hook. + foreach (module_implements('bakery_receive') as $module) { + $function = $module .'_'. 'bakery_receive'; + $result = call_user_func($function, $account, $stroopwafel['data']); + if ($result) { + watchdog('bakery', '!module bakery update success for user !uid.', array('!module' => $module, '!uid' => $account->uid)); + } + else { + watchdog('bakery', '!module bakery update failed for user !uid.', array('!module' => $module, '!uid' => $account->uid), WATCHDOG_EMERG); + $status = FALSE; + } + } } } - + + if ($status) { + $message = t('Your account was successfully updated on %slave.', array('%slave' => variable_get('site_name', ''))); + } + else { + $message = t('There was a problem updating your account on %slave. Please contact the administrator.', array('%slave' => variable_get('site_name', ''))); + header('HTTP/1.1 409 Conflict'); + } + module_invoke_all('exit'); print $message; exit();