Only in /var/aegir/platforms/newsnw-dev/sites/townhub.org/files/coder_upgrade/old/bakery-7.x-2.x-dev: .git
diff -up -r bakery.install bakery.install
--- bakery.install	2011-03-29 22:21:34.000000000 +0000
+++ bakery.install	2011-03-29 22:33:22.000000000 +0000
@@ -1,5 +1,15 @@
 <?php
+/**
+ * @file
+ * Install, update and uninstall functions for the bakery module.
+ *
+ */
+
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function bakery_schema() {
   return array(
     'bakery_user' => array(
@@ -29,12 +39,22 @@ function bakery_schema() {
   );
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function bakery_install() {
-  drupal_install_schema('bakery');
+  // TODO The drupal_(un)install_schema functions are called automatically in D7.
+  // drupal_install_schema('bakery')
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function bakery_uninstall() {
-  drupal_uninstall_schema('bakery');
+  // TODO The drupal_(un)install_schema functions are called automatically in D7.
+  // drupal_uninstall_schema('bakery')
 }
 
 /**
@@ -44,10 +64,17 @@ function bakery_update_6001() {
   $ret = array();
 
   if (module_exists('path')) {
-    db_query("DELETE FROM {url_alias} WHERE src = 'bakery' AND dst IN ('user/login', 'user/register')");
+    // TODO Please review the conversion of this statement to the D7 database API syntax.
+    /* db_query("DELETE FROM {url_alias} WHERE src = 'bakery' AND dst IN ('user/login', 'user/register')") */
+    db_delete('url_alias')
+    ->where('src = ' bakery ' AND dst IN (' user / login ', ' user / register ')',  )
+  ->execute();
   }
 
-  return $ret;
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
 }
 
 /**
@@ -57,10 +84,17 @@ function bakery_update_6002() {
   $ret = array();
 
   if (module_exists('path')) {
-    db_query("DELETE FROM {url_alias} WHERE src = 'bakery' AND dst IN ('user/login', 'user/register')");
+    // TODO Please review the conversion of this statement to the D7 database API syntax.
+    /* db_query("DELETE FROM {url_alias} WHERE src = 'bakery' AND dst IN ('user/login', 'user/register')") */
+    db_delete('url_alias')
+    ->where('src = ' bakery ' AND dst IN (' user / login ', ' user / register ')',  )
+  ->execute();
   }
 
-  return $ret;
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
 }
 
 /**
@@ -69,7 +103,7 @@ function bakery_update_6002() {
 function bakery_update_6003() {
   $return = array();
 
-  db_create_table($return, 'bakery_user', array(
+  db_create_table('bakery_user', array(
     'description' => 'Keep track of UID on subsites, master only.',
     'fields' => array(
       'uid' => array(
@@ -94,7 +128,10 @@ function bakery_update_6003() {
     'primary key' => array('uid', 'slave'),
   ));
 
-  return $return;
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $return */;
 }
 
 /**
@@ -103,10 +140,13 @@ function bakery_update_6003() {
 function bakery_update_6004() {
   $return = array();
 
-  $result = db_query("SELECT uid FROM {users} WHERE init LIKE 'bakery_temp/%' AND access = 0");
+  $result = db_query("SELECT uid FROM {users} WHERE init LIKE 'bakery_temp/%' AND access = :access", array(':access' => 0));
   while ($account = db_fetch_object($result)) {
-    user_delete(array(), $account->uid);
+    user_cancel(array(), $account->uid, $method = 'user_cancel_block' /* TODO Set this variable */);
   }
 
-  return $return;
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $return */;
 }
diff -up -r bakery.module bakery.module
--- bakery.module	2011-03-29 22:21:34.000000000 +0000
+++ bakery.module	2011-03-29 22:33:24.000000000 +0000
@@ -1,12 +1,12 @@
 <?php
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function bakery_menu() {
   $items = array();
 
-  $items['admin/settings/bakery'] = array(
+  $items['admin/config/bakery'] = array(
     'title' => 'Bakery',
     'access arguments' => array('administer bakery'),
     'page callback' => 'drupal_get_form',
@@ -79,7 +79,7 @@ function bakery_menu() {
 }
 
 /**
- * Implementation of hook_translated_menu_link_alter().
+ * Implements hook_translated_menu_link_alter().
  */
 function bakery_translated_menu_link_alter(&$item) {
   if ($item['href'] == 'bakery') {
@@ -88,30 +88,45 @@ function bakery_translated_menu_link_alt
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_perm().
  */
 function bakery_permission() {
   return array('administer bakery');
 }
 
 /**
- * Implementation of hook_user().
+ * Implements hook_user_login().
  */
-function bakery_user($op, &$array, &$account, $category = NULL) {
-  if ($op == 'login') {
+function bakery_user_login(&$edit, $account) {
+  if (TRUE) {
     if (variable_get('bakery_is_master', 0)) {
       _bakery_bake_chocolatechip_cookie($account->name, $account->mail, url("user/$account->uid/edit", array('absolute' => TRUE)));
     }
   }
-  else if ($op == 'logout') {
+}
+
+/**
+ * Implements hook_user_logout().
+ */
+function bakery_user_logout($account) {
+  if (TRUE) {
     // eat SSO cookie
     _bakery_eat_cookie();
     // eat session cookie
     _bakery_eat_cookie(session_name());
   }
-  else if ($op == 'update' && variable_get('bakery_is_master', 0)) {
+}
+
+/**
+ * Implements hook_user_presave().
+ */
+function bakery_user_presave(&$edit, $account, $category) {
+  if (TRUE && variable_get('bakery_is_master', 0)) {
     // We store email/name if they changed. We want to wait with doing
     // anything else until the changes are saved locally.
+    // TODO Convert "user_load" to "user_load_multiple" if "$account->uid" is other than a uid.
+    // To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent.
+    // Example: array_shift(user_load_multiple(array(), $account->uid))
     $newly_saved_user = user_load($account->uid);
     foreach (variable_get('bakery_supported_fields', array('mail' => 'mail', 'name' => 'name')) as $type => $enabled) {
       // Profile fields are unset by this point so we have to get them from the DB and use whichever is populated.
@@ -121,25 +136,33 @@ function bakery_user($op, &$array, &$acc
       }
     }
   }
-  // We need to push changes.
-  else if ($op == 'after_update' && variable_get('bakery_is_master', 0) && isset($_SESSION['bakery'])) {
+}
+
+/**
+ * Implements hook_user_update().
+ */
+function bakery_user_update(&$edit, $account, $category) {
+  if (TRUE && variable_get('bakery_is_master', 0) && isset($_SESSION['bakery'])) {
     $key = variable_get('bakery_key', '');
     $payload['data'] = serialize($_SESSION['bakery']);
     $payload['timestamp'] = $_SERVER['REQUEST_TIME'];
     $payload['uid'] = $account->uid;
     $payload['category'] = $category;
-    $payload['signature'] = hash_hmac('sha256', $payload['data'] . '/' . $payload['uid'] .'/'. $payload['timestamp'], $key);
+    $payload['signature'] = hash_hmac('sha256', $payload['data'] . '/' . $payload['uid'] . '/' . $payload['timestamp'], $key);
     $payload = drupal_query_string_encode(array('stroopwafel' => bakery_mix(serialize($payload), 1)));
     unset($_SESSION['bakery']);
 
     // Now update the slaves.
     $slaves = variable_get('bakery_slaves', array());
     foreach ($slaves as $slave) {
-      $result = drupal_http_request($slave .'bakery/update', array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'), 'POST', $payload);
+      $result = drupal_http_request($slave . 'bakery/update', array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'), 'method' => 'POST', 'data' => $payload));
       if ($result->code != 200) {
         // Warning, warning.
         $message = 'Error %error for site at %url';
-        $substitutions = array('%error' => $result->code .' '. $result->error, '%url' => $slave);
+        $substitutions = array(
+          '%error' => $result->code . ' ' . $result->error,
+          '%url' => $slave,
+        );
         watchdog('bakery', $message, $substitutions, WATCHDOG_ERROR);
         // Only inform administrators about the error.
         if (user_access('administer users')) {
@@ -162,7 +185,13 @@ function bakery_user($op, &$array, &$acc
       }
     }
   }
-  else if ($op == 'view' && !variable_get('bakery_is_master', 0)) {
+}
+
+/**
+ * Implements hook_user_view().
+ */
+function bakery_user_view($account, $view_mode) {
+  if (TRUE && !variable_get('bakery_is_master', 0)) {
     if (substr($account->init, 0, strlen(variable_get('bakery_master', 'http://drupal.org/'))) == variable_get('bakery_master', 'http://drupal.org/')) {
       $account->content['summary']['master_profile'] = array(
         '#type' => 'item',
@@ -176,14 +205,22 @@ function bakery_user($op, &$array, &$acc
 }
 
 /**
- * Implementation of hook_boot().
+ * Implements hook_user().
+ */
+function bakery_user_OLD($op, &$array, &$account, $category = NULL) {
+  // TODO Remaining code in this function needs to be moved to the appropriate new hook function.
+  // We need to push changes.
+}
+
+/**
+ * Implements hook_boot().
  */
 function bakery_boot() {
   _bakery_taste_chocolatechip_cookie();
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  *
  * Hide username and password options.
  */
@@ -202,7 +239,7 @@ function bakery_form_alter(&$form, $form
         }
         foreach (variable_get('bakery_supported_fields', array('mail' => 'mail', 'name' => 'name')) as $type => $value) {
           if ($value) {
-            switch($type) {
+            switch ($type) {
               case 'mail':
               case 'name':
                 break;
@@ -210,19 +247,19 @@ function bakery_form_alter(&$form, $form
                 if (isset($form['picture'])) {
                   $form['picture']['picture_delete']['#access'] = FALSE;
                   $form['picture']['picture_upload']['#access'] = FALSE;
-                  $form['picture']['#description'] .= ' '. t('You can change the image at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init)));
+                  $form['picture']['#description'] .= ' ' . t('You can change the image at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init)));
                 }
                 break;
               case 'language':
                 if (isset($form['locale'][$type])) {
                   $form['locale'][$type]['#disabled'] = TRUE;
-                  $form['locale'][$type]['#description'] .= ' '. t('You can change the language setting at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
+                  $form['locale'][$type]['#description'] .= ' ' . t('You can change the language setting at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
                 }
                 break;
               case 'signature':
                 if (isset($form['signature_settings'][$type])) {
                   $form['signature_settings'][$type]['#disabled'] = TRUE;
-                  $form['signature_settings'][$type]['#description'] .= ' '. t('You can change the signature at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
+                  $form['signature_settings'][$type]['#description'] .= ' ' . t('You can change the signature at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
                 }
                 break;
               default:
@@ -231,12 +268,12 @@ function bakery_form_alter(&$form, $form
                 }
                 if (isset($form[$type][$type])) {
                   $form[$type][$type]['#disabled'] = TRUE;
-                  $form[$type][$type]['#description'] .= ' '. t('You can change this setting at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
+                  $form[$type][$type]['#description'] .= ' ' . t('You can change this setting at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
                 }
                 // profile fields
                 if ($form[$index]['#type'] == 'fieldset' && isset($form[$index][$type])) {
                   $form[$index][$type]['#disabled'] = TRUE;
-                  $form[$index][$type]['#description'] .= ' '. t('You can change this setting at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
+                  $form[$index][$type]['#description'] .= ' ' . t('You can change this setting at <a href="!url">@master</a>.', array('!url' => check_url($form['_account']['#value']->init), '@master' => variable_get('bakery_master', 'http://drupal.org')));
                 }
                 break;
             }
@@ -317,10 +354,10 @@ function _bakery_pass_validate($form, &$
   // and use our helpful functions to create their account on the slave site.
   $name = trim($form_state['values']['name']);
 
-  $account = user_load(array('mail' => $name));
+  $account = array_shift(user_load_multiple(array(), array('mail' => $name)));
   if (!$account) {
     // No success, try to load by name.
-    $account = user_load(array('name' => $name));
+    $account = array_shift(user_load_multiple(array(), array('name' => $name)));
   }
   if (!$account) {
     // Attempt to copy account from master.
@@ -340,7 +377,7 @@ function _bakery_reset_submit($form, &$f
   // It's safe to use arg(2) here to load the user and log in because the
   // callback has validated the request and Drupal's Form API protects us
   // against forgery.
-  $account = user_load(array('uid' => arg(2)));
+  $account = user_load(arg(2));
   // If they have not logged in before we need to update the master site.
   if ($account->login == 0) {
     $payload = array();
@@ -351,7 +388,7 @@ function _bakery_reset_submit($form, &$f
     $payload['signature'] = hash_hmac('sha256', $payload['name'] . '/' . $payload['timestamp'], $key);
     $payload = drupal_query_string_encode(array('thinmint' => bakery_mix(serialize($payload), 1)));
     // Push validation to master.
-    $result = drupal_http_request($master . 'bakery/validate', array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'), 'POST', $payload);
+    $result = drupal_http_request($master . 'bakery/validate', array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'), 'method' => 'POST', 'data' => $payload));
   }
 
   // If they have logged in before or the master updated correctly, log them in.
@@ -364,7 +401,7 @@ function _bakery_reset_submit($form, &$f
     bakery_user_authenticate_finalize($edit);
     // Inform them that they need to reset their password.
     drupal_set_message(t('You have just used your one-time login link. It is no longer necessary to use this link to login. Please change your password at <a href="!url">@master</a>.', array('!url' => check_url($user->init), '@master' => variable_get('bakery_master', ''))));
-    drupal_goto('user/'. $user->uid);
+    drupal_goto('user/' . $user->uid);
   }
   else {
     drupal_goto('user/login');
@@ -379,7 +416,7 @@ function _bakery_register_submit($form, 
   $allowed = array('name', 'mail', 'pass', 'timezone');
   if (module_exists('profile')) {
     // Now figure out profile field names that are visible on the registration form.
-    $field_names = db_query("SELECT name FROM {profile_fields} WHERE register = 1");
+    $field_names = db_query("SELECT name FROM {profile_fields} WHERE register = :register", array(':register' => 1));
     while ($field_name = db_fetch_object($field_names)) {
       $allowed[] = $field_name->name;
     }
@@ -427,14 +464,14 @@ function _bakery_login_submit($form, &$f
   }
   // Create cookie and redirect to master.
   bakery_bake_oatmeal_cookie($data['name'], $data);
-  unset($_REQUEST['destination']);
+  unset($_GET['destination']);
   drupal_goto(variable_get('bakery_master', 'http://drupal.org/') . 'bakery/login');
 }
 
 /**
  * Admin settings, see INSTALL.txt
  */
-function bakery_settings() {
+function bakery_settings($form, &$form_state) {
   $form = array(
     '#submit' => array('bakery_settings_submit'),
   );
@@ -488,7 +525,15 @@ function bakery_settings() {
   $default = variable_get('bakery_supported_fields', array('mail' => 'mail', 'name' => 'name'));
   $default['mail'] = 'mail';
   $default['name'] = 'name';
-  $options = array('name' => t('username'), 'mail' => t('e-mail'), 'status' => t('status'), 'picture' => t('user picture'), 'language' => t('language'), 'signature' => t('signature'), 'timezone' => t('timezone'));
+  $options = array(
+    'name' => t('username'),
+    'mail' => t('e-mail'),
+    'status' => t('status'),
+    'picture' => t('user picture'),
+    'language' => t('language'),
+    'signature' => t('signature'),
+    'timezone' => t('timezone'),
+  );
   if (module_exists('profile')) {
     $result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight');
     while ($field = db_fetch_object($result)) {
@@ -506,6 +551,10 @@ function bakery_settings() {
   return system_settings_form($form);
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function bakery_settings_submit($form, &$form_state) {
   // Rebuild the menu because the router items are based on the selection of
   // the master site.
@@ -513,7 +562,7 @@ function bakery_settings_submit($form, &
 
   // Updating of data on slave sites will not work unless the url of the master site has a trailing slash.
   // We now remove the trailing slash (if present) and concatenate with a new trailing slash.
-  $form_state['values']['bakery_master'] = trim($form_state['values']['bakery_master'], '/') .'/';
+  $form_state['values']['bakery_master'] = trim($form_state['values']['bakery_master'], '/') . '/';
 
   // The list of slave sites needs transforming from a text string into array for storage.
   // Also, redirection after login will only work if there is a trailing slash after each entry.
@@ -522,7 +571,7 @@ function bakery_settings_submit($form, &
     $form_state['values']['bakery_slaves'] = explode("\n", trim(str_replace("\r", '', $form_state['values']['bakery_slaves'])));
     // For each entry, remove the trailing slash (if present) and concatenate with a new trailing slash.
     foreach ($form_state['values']['bakery_slaves'] as &$slave) {
-      $slave = trim($slave, '/') .'/';
+      $slave = trim($slave, '/') . '/';
     }
   }
   else {
@@ -539,7 +588,7 @@ function bakery_settings_submit($form, &
 function bakery_user_page() {
   global $user;
   if ($user->uid) {
-    menu_set_active_item('user/'. $user->uid);
+    menu_set_active_item('user/' . $user->uid);
     return menu_execute_active_handler();
   }
 }
@@ -571,13 +620,13 @@ function bakery_register() {
       }
 
       // Check if user exists with same email.
-      $account = user_load(array('mail' => $mail));
+      $account = array_shift(user_load_multiple(array(), array('mail' => $mail)));
       if ($account) {
         $errors['mail'] = 1;
       }
       else {
         // Check username.
-        $account = user_load(array('name' => $name));
+        $account = array_shift(user_load_multiple(array(), array('name' => $name)));
         if ($account) {
           $errors['name'] = 1;
         }
@@ -609,7 +658,7 @@ function bakery_register() {
       // Set some info to return to the slave.
       $data['uid'] = $account->uid;
       $data['mail'] = $mail;
-      watchdog('user', 'New external user: %name using module bakery from slave !slave.', array('%name' => $account->name, '!slave' => $cookie['slave']), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit'));
+      watchdog('user', 'New external user: %name using module bakery from slave !slave.', array('%name' => $account->name, '!slave' => $cookie['slave']), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));
 
       // Redirect to slave.
       if (!variable_get('user_email_verification', TRUE)) {
@@ -666,12 +715,12 @@ function bakery_register_return() {
         // If the user must validate their email then we need to create an
         // account for them on the slave site.
         $new = array(
-            'name' => $cookie['name'],
-            'mail' => $cookie['data']['mail'],
-            'init' => variable_get('bakery_master', '') . 'user/' . $cookie['data']['uid'] . '/edit',
-            'status' => 1,
-            'pass' => user_password(),
-          );
+          'name' => $cookie['name'],
+          'mail' => $cookie['data']['mail'],
+          'init' => variable_get('bakery_master', '') . 'user/' . $cookie['data']['uid'] . '/edit',
+          'status' => 1,
+          'pass' => user_password(),
+        );
         $account = user_save(new stdClass(), $new);
         // Notify the user that they need to validate their email.
         _user_mail_notify('register_no_approval_required', $account);
@@ -713,12 +762,12 @@ function bakery_login() {
     // Execute the login form.
     $form_state = array();
     $form_state['values'] = $cookie['data'];
-    drupal_execute('user_login', $form_state);
+    drupal_form_submit('user_login', $form_state);
     $errors = form_get_errors();
 
     if (empty($errors)) {
       // Check if account credentials are correct.
-      $account = user_load(array('name' => $name, 'pass' => $pass));
+      $account = array_shift(user_load_multiple(array(), array('name' => $name, 'pass' => $pass)));
       if ($account->uid) {
         // Check if the mail is denied.
         if (drupal_is_denied('user', $account->mail)) {
@@ -741,7 +790,7 @@ function bakery_login() {
     if (!empty($errors)) {
       // Report failed login.
       watchdog('user', 'Login attempt failed for %user.', array('%user' => $name));
-     // Clear the messages on the master's session, since they were set during
+      // Clear the messages on the master's session, since they were set during
       // drupal_execute() and will be displayed out of context.
       drupal_get_messages();
     }
@@ -783,7 +832,7 @@ function bakery_login_return() {
       drupal_goto('user');
     }
     else {
-      $_REQUEST['destination'] = $cookie['data']['destination'];
+      $_GET['destination'] = $cookie['data']['destination'];
       drupal_goto();
     }
   }
@@ -840,22 +889,22 @@ function _bakery_taste_chocolatechip_coo
       // User is anonymous. If they do not have an account we'll create one by
       // requesting their information from the master site. If they do have an
       // account we may need to correct some disparant information.
-      $account = user_load(array('name' => $cookie['name'], 'mail' => $cookie['mail']));
+      $account = array_shift(user_load_multiple(array(), array('name' => $cookie['name'], 'mail' => $cookie['mail'])));
 
       // Fix out of sync users with valid init.
       if (!$account && !variable_get('bakery_is_master', 0) && $cookie['master']) {
-        $count = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE init = '%s'", $cookie['init']));
+        $count = db_query("SELECT COUNT(*) FROM {users} WHERE init = :init", array(':init' => $cookie['init']))->fetchField();
         if ($count > 1) {
           // Uh oh.
           watchdog('bakery', 'Account uniqueness problem: Multiple users found with init %init.', array('%init' => $cookie['init']), 'error');
-          drupal_set_message(t('Account uniqueness problem detected. <a href="@contact">Please contact the site administrator.</a>', array('@contact' => variable_get('bakery_master', 'http://drupal.org/') .'contact')), 'error');
+          drupal_set_message(t('Account uniqueness problem detected. <a href="@contact">Please contact the site administrator.</a>', array('@contact' => variable_get('bakery_master', 'http://drupal.org/') . 'contact')), 'error');
         }
         if ($count == 1) {
-          $account = user_load(array('init' => $cookie['init']));
+          $account = array_shift(user_load_multiple(array(), array('init' => $cookie['init'])));
           if ($account) {
             watchdog('bakery', 'Fixing out of sync uid %uid. Changed name %name_old to %name_new, mail %mail_old to %mail_new.', array('%uid' => $account->uid, '%name_old' => $account->name, '%name_new' => $cookie['name'], '%mail_old' => $account->mail, '%mail_new' => $cookie['mail']));
             user_save($account, array('name' => $cookie['name'], 'mail' => $cookie['mail']));
-            $account = user_load(array('name' => $cookie['name'], 'mail' => $cookie['mail']));
+            $account = array_shift(user_load_multiple(array(), array('name' => $cookie['name'], 'mail' => $cookie['mail'])));
           }
         }
       }
@@ -863,13 +912,13 @@ function _bakery_taste_chocolatechip_coo
       // Create the account if it doesn't exist.
       if (!$account && !variable_get('bakery_is_master', 0) && $cookie['master']) {
         $checks = TRUE;
-        if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND mail != '' AND LOWER(mail) = LOWER('%s')", $user->uid, $cookie['mail'])) > 0) {
+        if (db_query("SELECT COUNT(*) FROM {users} WHERE uid != :uid AND mail != :mail AND LOWER(mail) = :LOWER(mail)", array(':uid' => $user->uid, ':mail' => '', ':LOWER(mail)' => LOWER('%s'), '' => $cookie['mail']))->fetchField() > 0) {
           $checks = FALSE;
         }
-        if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $user->uid, $cookie['name'])) > 0) {
+        if (db_query("SELECT COUNT(*) FROM {users} WHERE uid != :uid AND LOWER(name) = :LOWER(name)", array(':uid' => $user->uid, ':LOWER(name)' => LOWER('%s'), '' => $cookie['name']))->fetchField() > 0) {
           $checks = FALSE;
         }
-        if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND init = '%s'", $user->uid, $cookie['init'])) > 0) {
+        if (db_query("SELECT COUNT(*) FROM {users} WHERE uid != :uid AND init = :init", array(':uid' => $user->uid, ':init' => $cookie['init']))->fetchField() > 0) {
           $checks = FALSE;
         }
 
@@ -879,6 +928,9 @@ function _bakery_taste_chocolatechip_coo
           // In case the account creation failed we want to make sure the user
           // gets their bad cookie destroyed by not returning too early.
           if ($uid) {
+            // TODO Convert "user_load" to "user_load_multiple" if "$uid" is other than a uid.
+            // To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent.
+            // Example: array_shift(user_load_multiple(array(), $uid))
             $account = user_load($uid);
           }
           else {
@@ -898,8 +950,15 @@ function _bakery_taste_chocolatechip_coo
         // remains in sync.
 
         // Make sure that there aren't any OTHER accounts with this init already.
-        if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE init = '%s'", $cookie['init'])) == 0) {
-          db_query("UPDATE {users} SET init = '%s' WHERE uid = %d", $cookie['init'], $account->uid);
+        if (db_query("SELECT COUNT(*) FROM {users} WHERE init = :init", array(':init' => $cookie['init']))->fetchField() == 0) {
+          // TODO Please review the conversion of this statement to the D7 database API syntax.
+          /* db_query("UPDATE {users} SET init = '%s' WHERE uid = %d", $cookie['init'], $account->uid) */
+          db_update('users')
+  ->fields(array(
+            'init' => $cookie['init'],
+          ))
+  ->condition('uid', $account->uid)
+  ->execute();
           watchdog('bakery', 'uid %uid out of sync. Changed init field from %oldinit to %newinit', array('%oldinit' => $account->init, '%newinit' => $cookie['init'], '%uid' => $account->uid));
         }
         else {
@@ -914,15 +973,16 @@ function _bakery_taste_chocolatechip_coo
         // infinite redirects (with infinite failed login messages).
         $login = bakery_user_external_login($account);
         if ($login) {
-          if (isset($_REQUEST['destination'])) {
-            $destination = $_REQUEST['destination'];
+          if (isset($_GET['destination'])) {
+            $destination = $_GET['destination'];
           }
           else {
             // Use $_GET here to retrieve the original path in source form.
             $destination = isset($_GET['q']) ? $_GET['q'] : '';
             $query = drupal_query_string_encode($_GET, array('q'));
           }
-          drupal_goto($destination, $query);
+          // TODO $query needs to be an array of keys and values instead of a string.
+          drupal_goto($destination, array('query' => $query));
         }
         else {
           $destroy_cookie = TRUE;
@@ -994,6 +1054,10 @@ function _bakery_bake_chocolatechip_cook
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function bakery_taste_oatmeal_cookie() {
   $key = variable_get('bakery_key', '');
 
@@ -1047,16 +1111,16 @@ function bakery_eat_stroopwafel_cookie()
   $stroopwafel = $_SESSION['bakery'];
   unset($_SESSION['bakery']);
 
-  $init = variable_get('bakery_master', 'http://drupal.org/') .'user/'. $stroopwafel['uid'] .'/edit';
+  $init = variable_get('bakery_master', 'http://drupal.org/') . 'user/' . $stroopwafel['uid'] . '/edit';
 
   // check if the user exists.
-  $account = user_load(array('init' => $init));
+  $account = array_shift(user_load_multiple(array(), array('init' => $init)));
   if (!$account) {
     // user not present
     $message = t('Account not found on %slave.', array('%slave' => variable_get('site_name', '')));
   }
   else {
-    drupal_set_header('X-Drupal-bakery-UID: ' . $account->uid);
+    drupal_add_http_header('X-Drupal-bakery-UID', $account->uid);
 
     // If profile field is enabled we manually save profile fields along the way.
     $fields = array();
@@ -1070,8 +1134,21 @@ function bakery_eat_stroopwafel_cookie()
 
           // If it's a profile field, handle differently.
           if (array_key_exists($type, $profile_fields)) {
-            db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $profile_fields[$type], $account->uid);
-            db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $profile_fields[$type], $account->uid, $stroopwafel[$type]);
+            // TODO Please review the conversion of this statement to the D7 database API syntax.
+            /* db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $profile_fields[$type], $account->uid) */
+            db_delete('profile_values')
+  ->condition('fid', $profile_fields[$type])
+  ->condition('uid', $account->uid)
+  ->execute();
+            // TODO Please review the conversion of this statement to the D7 database API syntax.
+            /* db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $profile_fields[$type], $account->uid, $stroopwafel[$type]) */
+            $id = db_insert('profile_values')
+  ->fields(array(
+              'fid' => $profile_fields[$type],
+              'uid' => $account->uid,
+              'value' => $stroopwafel[$type],
+            ))
+  ->execute();
             // Since we've saved it we make sure profile module itself doesn't.
             unset($fields[$type]);
           }
@@ -1150,9 +1227,16 @@ function bakery_eat_thinmint_cookie() {
   $uid = $_SESSION['bakery']['uid'];
   unset($_SESSION['bakery']['uid']);
 
-  $account = user_load(array('name' => $name));
+  $account = array_shift(user_load_multiple(array(), array('name' => $name)));
   if ($account) {
-    db_query("UPDATE {users} SET login = %d WHERE uid = %d", $_SERVER['REQUEST_TIME'], $account->uid);
+    // TODO Please review the conversion of this statement to the D7 database API syntax.
+    /* db_query("UPDATE {users} SET login = %d WHERE uid = %d", $_SERVER['REQUEST_TIME'], $account->uid) */
+    db_update('users')
+  ->fields(array(
+      'login' => $_SERVER['REQUEST_TIME'],
+    ))
+  ->condition('uid', $account->uid)
+  ->execute();
 
     // Save UID provided by slave site.
     _bakery_save_slave_uid($account, $slave, $uid);
@@ -1170,9 +1254,9 @@ function bakery_eat_thinmint_cookie() {
 function bakery_request_account($name, $or_email = FALSE) {
   global $base_url;
 
-  $existing_account = user_load(array('name' => $name));
+  $existing_account = array_shift(user_load_multiple(array(), array('name' => $name)));
   if (!$existing_account && $or_email) {
-    $existing_account = user_load(array('mail' => $name));
+    $existing_account = array_shift(user_load_multiple(array(), array('mail' => $name)));
   }
   // We return FALSE in cases that the account already exists locally or if
   // there was an error along the way of requesting and creating it.
@@ -1206,12 +1290,12 @@ function bakery_request_account($name, $
   $payload['signature'] = hash_hmac('sha256', $payload['name'] . '/' . $payload['timestamp'], $key);
   $payload = drupal_query_string_encode(array('gingerbread' => bakery_mix(serialize($payload), 1)));
   // Make request to master for account information.
-  $result = drupal_http_request($master . 'bakery/create', array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'), 'POST', $payload);
+  $result = drupal_http_request($master . 'bakery/create', array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'), 'method' => 'POST', 'data' => $payload));
   // Parse result and create account.
   if ($result->code != 200) {
     $message = $result->data;
     watchdog('bakery', 'Received response !code from master with message @message', array('!code' => $result->code, '@message' => $message), WATCHDOG_ERROR);
-    user_delete(array(), $stub_uid);
+    user_cancel(array(), $stub_uid, $method = 'user_cancel_block' /* TODO Set this variable */);
     return FALSE;
   }
 
@@ -1223,7 +1307,7 @@ function bakery_request_account($name, $
   if ($signature != $cookie['signature']) {
     // Invalid response.
     watchdog('bakery', 'Invalid response from master when attempting to create local account for @name', array('@name' => $name), WATCHDOG_ERROR);
-    user_delete(array(), $stub_uid);
+    user_cancel(array(), $stub_uid, $method = 'user_cancel_block' /* TODO Set this variable */);
     return FALSE;
   }
 
@@ -1248,7 +1332,7 @@ function bakery_request_account($name, $
   }
 
   watchdog('bakery', 'Unable to create account for @name', array('@name' => $name), WATCHDOG_ERROR);
-  user_delete(array(), $stub_uid);
+  user_cancel(array(), $stub_uid, $method = 'user_cancel_block' /* TODO Set this variable */);
   return FALSE;
 }
 
@@ -1291,9 +1375,9 @@ function bakery_eat_gingerbread_cookie()
   unset($_SESSION['bakery']['uid']);
   $key = variable_get('bakery_key', '');
 
-  $account = user_load(array('name' => $name));
+  $account = array_shift(user_load_multiple(array(), array('name' => $name)));
   if (!$account && $or_email) {
-    $account = user_load(array('mail' => $name));
+    $account = array_shift(user_load_multiple(array(), array('mail' => $name)));
   }
   if ($account) {
     _bakery_save_slave_uid($account, $slave, $slave_uid);
@@ -1347,7 +1431,7 @@ function bakery_mix($text, $crypt) {
 
   mcrypt_generic_init($td, $key, $iv);
 
-  if($crypt) {
+  if ($crypt) {
     $encrypted_data = mcrypt_generic($td, $text);
   }
   else {
@@ -1386,7 +1470,7 @@ function bakery_user_external_login($acc
   }
 
   // Check if user is blocked or denied by access rules.
-  user_login_name_validate($form, $state, (array)$account);
+  user_login_name_validate($form, $state, (array) $account);
   if (form_get_errors()) {
     // Invalid login.
     return FALSE;
@@ -1413,8 +1497,15 @@ function bakery_user_authenticate_finali
   watchdog('user', 'Session opened for %name.', array('%name' => $user->name));
   // Update the user table timestamp noting user has logged in.
   // This is also used to invalidate one-time login links.
-  $user->login = time();
-  db_query("UPDATE {users} SET login = %d WHERE uid = %d", $user->login, $user->uid);
+  $user->login = REQUEST_TIME;
+  // TODO Please review the conversion of this statement to the D7 database API syntax.
+  /* db_query("UPDATE {users} SET login = %d WHERE uid = %d", $user->login, $user->uid) */
+  db_update('users')
+  ->fields(array(
+    'login' => $user->login,
+  ))
+  ->condition('uid', $user->uid)
+  ->execute();
 
   // Regenerate the session ID to prevent against session fixation attacks.
   sess_regenerate();
@@ -1427,7 +1518,7 @@ function bakery_user_authenticate_finali
 function bakery_user_logout() {
   // Include common.inc here because we may be in an early boot phase and we
   // need the url() function.
-  require_once 'includes/common.inc';
+  require_once DRUPAL_ROOT . '/' . 'includes/common.inc';
   global $user;
 
   watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
@@ -1444,7 +1535,7 @@ function bakery_user_logout() {
   $destination = !empty($get['q']) ? $get['q'] : '';
   unset($get['q']);
   // We append a GET parameter so that the browser reloads the page.
-  $get['no_cache'] = time();
+  $get['no_cache'] = REQUEST_TIME;
   // Build the URL we'll redirect to. We set alias to TRUE so as not to try and
   // hit the unavailable database looking for an alias.
   $url = url($destination, array('query' => $get, 'absolute' => TRUE, 'alias' => TRUE));
@@ -1473,13 +1564,13 @@ function bakery_uncrumble_access() {
 /**
  * Form to let users repair minor problems themselves.
  */
-function bakery_uncrumble(&$form_state) {
+function bakery_uncrumble($form, &$form_state) {
   $site_name = variable_get('site_name', 'Drupal');
   $cookie = _bakery_validate_cookie();
 
   // Analyze.
-  $samemail = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE uid != 0 AND mail != '' AND LOWER(mail) = LOWER('%s')", $cookie['mail']));
-  $samename = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE uid != 0 AND LOWER(name) = LOWER('%s')", $cookie['name']));
+  $samemail = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE uid != :uid AND mail != :mail AND LOWER(mail) = :LOWER(mail)", array(':uid' => 0, ':mail' => '', ':LOWER(mail)' => LOWER('%s'), '' => $cookie['mail'])));
+  $samename = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE uid != :uid AND LOWER(name) = :LOWER(name)", array(':uid' => 0, ':LOWER(name)' => LOWER('%s'), '' => $cookie['name'])));
 
 
   $form['name'] = array(
@@ -1504,17 +1595,21 @@ function bakery_uncrumble(&$form_state) 
     '#required' => TRUE,
   );
 
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Repair account'), '#weight' => 2);
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Repair account'),
+    '#weight' => 2,
+  );
 
   $help = '';
 
-  if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE init = '%s'", $cookie['init'])) > 1) {
-    drupal_set_message(t('Multiple accounts are associated with your master account. This must be fixed manually. <a href="@contact">Please contact the site administrator.</a>', array('%email' => $cookie['mail'], '@contact' => variable_get('bakery_master', 'http://drupal.org/') .'contact')));
+  if (db_query("SELECT COUNT(*) FROM {users} WHERE init = :init", array(':init' => $cookie['init']))->fetchField() > 1) {
+    drupal_set_message(t('Multiple accounts are associated with your master account. This must be fixed manually. <a href="@contact">Please contact the site administrator.</a>', array('%email' => $cookie['mail'], '@contact' => variable_get('bakery_master', 'http://drupal.org/') . 'contact')));
     $form['pass']['#disabled'] = TRUE;
     $form['submit']['#disabled'] = TRUE;
   }
   else if ($samename && $samemail && $samename->uid != $samemail->uid) {
-    drupal_set_message(t('Both an account with matching name and an account with matching email address exist, but they are different accounts. This must be fixed manually. <a href="@contact">Please contact the site administrator.</a>', array('%email' => $cookie['mail'], '@contact' => variable_get('bakery_master', 'http://drupal.org/') .'contact')));
+    drupal_set_message(t('Both an account with matching name and an account with matching email address exist, but they are different accounts. This must be fixed manually. <a href="@contact">Please contact the site administrator.</a>', array('%email' => $cookie['mail'], '@contact' => variable_get('bakery_master', 'http://drupal.org/') . 'contact')));
     $form['pass']['#disabled'] = TRUE;
     $form['submit']['#disabled'] = TRUE;
   }
@@ -1531,7 +1626,11 @@ function bakery_uncrumble(&$form_state) 
     $form['name']['#description'] = t('Will change to %new.', array('%new' => $cookie['name']));
   }
 
-  $form['help'] = array('#type' => 'markup', '#weight' => -10, '#value' => $help);
+  $form['help'] = array(
+    '#type' => 'markup',
+    '#weight' => -10,
+    '#value' => $help,
+  );
 
   return $form;
 }
@@ -1541,22 +1640,28 @@ function bakery_uncrumble(&$form_state) 
  */
 function bakery_uncrumble_validate($form, &$form_state) {
   // We are ignoring blocked status on purpose. The user is being repaired, not logged in.
-  $account = user_load(array('name' => $form_state['values']['name'], 'pass' => $form_state['values']['pass']));
+  $account = array_shift(user_load_multiple(array(), array('name' => $form_state['values']['name'], 'pass' => $form_state['values']['pass'])));
   if (!($account && $account->uid)) {
     watchdog('bakery', 'Login attempt failed for %user while running uncrumble.', array('%user' => $form_state['values']['name']));
     // Can't pretend that it was the "username or password" so let's be helpful instead.
-    form_set_error('pass', t('Sorry, unrecognized password. If you have forgotten your %site password, please <a href="@contact">contact the site administrator.</a>', array('%site' => variable_get('site_name', 'Drupal'), '@contact' => variable_get('bakery_master', 'http://drupal.org/') .'contact')), 'error');
+    form_set_error('pass', t('Sorry, unrecognized password. If you have forgotten your %site password, please <a href="@contact">contact the site administrator.</a>', array('%site' => variable_get('site_name', 'Drupal'), '@contact' => variable_get('bakery_master', 'http://drupal.org/') . 'contact')), 'error');
   }
   else {
     $form_state['bakery_uncrumble_account'] = $account;
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function bakery_uncrumble_submit($form, &$form_state) {
   $account = $form_state['bakery_uncrumble_account'];
   unset($form_state['bakery_uncrumble_account']);
   $cookie = _bakery_validate_cookie();
-  db_query("UPDATE {users} set init = '%s' WHERE uid = %d", $account->uid, $cookie['init']);
+  // TODO Please convert this statement to the D7 database API syntax.
+  /* db_query("UPDATE {users} set init = '%s' WHERE uid = %d", $account->uid, $cookie['init']) */
+  NULL;
   watchdog('bakery', 'uncrumble changed init field for uid %uid from %oldinit to %newinit', array('%oldinit' => $account->init, '%newinit' => $cookie['init'], '%uid' => $account->uid));
   user_save($account, array('name' => $cookie['name'], 'mail' => $cookie['mail']));
   watchdog('bakery', 'uncrumble updated name %name_old to %name_new, mail %mail_old to %mail_new on uid %uid.', array('%name_old' => $account->name, '%name_new' => $cookie['name'], '%mail_old' => $account->mail, '%mail_new' => $cookie['mail'], '%uid' => $account->uid));
@@ -1575,20 +1680,20 @@ function bakery_uncrumble_submit($form, 
  *   The corresponding UID on the slave site.
  */
 function _bakery_save_slave_uid($account, $slave, $slave_uid) {
-  if (variable_get('bakery_is_master', 0) && !empty($slave_uid) && in_array($slave, variable_get('bakery_slaves', array())) && !db_result(db_query_range("SELECT 1 FROM {bakery_user} WHERE uid = %d AND slave = '%s'", $account->uid, $slave, 0, 1))) {
+  if (variable_get('bakery_is_master', 0) && !empty($slave_uid) && in_array($slave, variable_get('bakery_slaves', array())) && !db_query_range("SELECT 1 FROM {bakery_user} WHERE uid = :uid AND slave = :slave", array(':uid' => $account->uid, ':slave' => $slave))->fetchField()) {
     $row = array(
       'uid' => $account->uid,
       'slave' => $slave,
       'slave_uid' => $slave_uid,
     );
     drupal_write_record('bakery_user', $row);
-  };
+  }
 }
 
 /**
  * Form for admins to pull accounts.
  */
-function bakery_pull_form() {
+function bakery_pull_form($form, &$form_state) {
   $form = array();
 
   $form['or_email'] = array(
@@ -1616,13 +1721,13 @@ function bakery_pull_form() {
  * Make sure we are not trying to request an existing user.
  */
 function bakery_pull_form_validate($form, &$form_state) {
-  $existing_account = user_load(array('name' => $form_state['values']['name']));
+  $existing_account = array_shift(user_load_multiple(array(), array('name' => $form_state['values']['name'])));
   if (!$existing_account && $form_state['values']['or_email']) {
-    $existing_account = user_load(array('mail' => $form_state['values']['name']));
+    $existing_account = array_shift(user_load_multiple(array(), array('mail' => $form_state['values']['name'])));
   }
   // Raise an error in case the account already exists locally.
   if ($existing_account) {
-    form_set_error('name', t('Account !link exists.', array('!link' => theme('username', $existing_account))));
+    form_set_error('name', t('Account !link exists.', array('!link' => theme('username', array('account' => $existing_account)))));
   }
 }
 
