### Eclipse Workspace Patch 1.0
#P shuri
Index: sites/all/modules/3rdparty/install_profile_api/core/filter.inc
===================================================================
--- sites/all/modules/3rdparty/install_profile_api/core/filter.inc	(revision 67)
+++ sites/all/modules/3rdparty/install_profile_api/core/filter.inc	(working copy)
@@ -29,8 +29,12 @@
  *   The new format ID.
  */
 function install_add_format($name, $cache = 1) {
-  db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('%s', '', %d)", $name, $cache);
-  return db_last_insert_id('filter_formats', 'format');
+  if ($format = db_result(db_query('SELECT format FROM {filter_formats} WHERE name="%s"', $name))) {
+    return $format;
+  } else {
+    db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('%s', '', %d)", $name, $cache);
+    return db_last_insert_id('filter_formats', 'format');
+  }
 }
 
 /**
@@ -44,7 +48,7 @@
  *
  * NOTE: the module name + the delta is what uniquely identifies a filter
  */
-function install_remove_filter($format_id, $module, $delta) {	
+function install_remove_filter($format_id, $module, $delta) {
   db_query("DELETE FROM {filters} WHERE format = %d AND module = '%s' AND delta = %d", $format_id, $module, $delta);
 }
 
Index: sites/all/modules/3rdparty/install_profile_api/core/user.inc
===================================================================
--- sites/all/modules/3rdparty/install_profile_api/core/user.inc	(revision 67)
+++ sites/all/modules/3rdparty/install_profile_api/core/user.inc	(working copy)
@@ -26,16 +26,18 @@
     }
   }
 
-  user_save(
+  $user = user_save(
     new stdClass(),
     array(
-      'name' => $username, 
+      'name' => $username,
       'pass' => $password,
       'mail' => $email,
       'roles' => $role_assignments,
       'status' => $status
     )
-  );	
+  );
+
+  return $user->uid;
 }
 
 /**
@@ -63,7 +65,7 @@
   if (!$rid) {
     db_query("INSERT INTO {role} (name) VALUES ('%s')", $name);
   }
-  
+
   return ($rid) ? $rid : install_get_rid($name);
 }
 
@@ -89,7 +91,7 @@
     $existing_perms += explode(', ', $row->perm);
   }
   // If this role already has permissions, merge them with the new permissions being set.
-  if (count($existing_perms) > 0) { 
+  if (count($existing_perms) > 0) {
     $perms = array_unique(array_merge($perms, (array)$existing_perms));
   }
 
@@ -109,7 +111,7 @@
     $existing_perms += explode(', ', $row->perm);
   }
   $new_perms = array_diff($existing_perms, $perms);
- 
+
   // Update the permissions.
   db_query('DELETE FROM {permission} WHERE rid = %d', $rid);
   db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', $new_perms));
Index: sites/all/modules/3rdparty/install_profile_api/core/block.inc
===================================================================
--- sites/all/modules/3rdparty/install_profile_api/core/block.inc	(revision 67)
+++ sites/all/modules/3rdparty/install_profile_api/core/block.inc	(working copy)
@@ -8,16 +8,44 @@
 }
 
 /**
+ * Add a block entry, or update if exists
+ */
+
+function install_create_block($block) {
+  if (is_array($block)) {
+    $block = (object) $block;
+  }
+  $exists = db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block->module, $block->delta, $block->theme));
+  if ($exists) {
+    install_set_block($block->module, $block->delta, $block->theme, $block->region, $block->weight, $block->visibility, $block->pages, $block->custom, $block->throttle, $block->title);
+  } else {
+    install_add_block($block->module, $block->delta, $block->theme, TRUE, $block->weight, $block->region, $block->visibility, $block->pages, $block->custom, $block->throttle, $block->title);
+    if (!$block->status) {
+      install_add_block($block->module, $block->delta, $block->theme, FALSE);
+    }
+    if ($block->box) {
+      install_create_custom_block($block->box->body, $block->box->info, $block->box->format);
+    }
+    if (is_array($block->roles)) {
+      foreach ($block->roles as $rid) {
+        install_add_block_role($block->module, $block->delta, $rid);
+      }
+    }
+  }
+  return db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block->module, $block->delta, $block->theme));
+}
+
+/**
  * Add a new plain block provided by block module.
  */
 function install_add_block($module, $delta, $theme, $status, $weight = 0, $region = '', $visibility = 0, $pages = '', $custom = 0, $throttle = 0, $title = '') {
   if ($status) {
-    db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, title) 
-       VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')", 
+    db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, title)
+       VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')",
        $module, $delta, $theme, $status, $weight, $region, $visibility, $pages, $custom, $throttle, $title);
   }
   else {
-    db_query("UPDATE {blocks} SET status = 0 WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme); 
+    db_query("UPDATE {blocks} SET status = 0 WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme);
   }
 }
 
@@ -83,7 +111,7 @@
  * Creates a new block role.
  */
 function install_add_block_role($module, $delta, $rid) {
-  db_query("INSERT INTO {blocks_roles} (module,delta,rid) VALUES ('%s', '%s', %d)", $module, $delta, $rid);
+  db_query("INSERT INTO {blocks_roles} (module, delta, rid) VALUES ('%s', '%s', %d) ON DUPLICATE KEY UPDATE rid=rid", $module, $delta, $rid);
 }
 
 /**
@@ -101,8 +129,14 @@
  *
  * @see block_add_block_form_submit()
  */
-function install_create_custom_block($body, $description, $format = FILTER_FORMAT_DEFAULT) {
-  db_query("INSERT INTO {boxes} (body, info, format) VALUES ('%s', '%s', %d)", $body, $description, $format);
-  return db_last_insert_id('boxes', 'bid');
+function install_create_custom_block($body, $info, $format = FILTER_FORMAT_DEFAULT) {
+  if ($bid = db_result(db_query('SELECT bid FROM {boxes} WHERE info="%s"', $info))) {
+    db_query("UPDATE {boxes} SET body='%s' WHERE bid=%d", $body, $bid);
+  }
+  else {
+    db_query("INSERT INTO {boxes} (body, info, format) VALUES ('%s', '%s', %d)", $body, $info, $format);
+    $bid = db_last_insert_id('boxes', 'bid');
+  }
+  return $bid;
 }
 
Index: sites/all/modules/3rdparty/install_profile_api/core/profile.inc
===================================================================
--- sites/all/modules/3rdparty/install_profile_api/core/profile.inc	(revision 67)
+++ sites/all/modules/3rdparty/install_profile_api/core/profile.inc	(working copy)
@@ -13,8 +13,8 @@
   $data['register'] = ($data['register']) ? $data['register'] : '0';
   $data['visibility'] = ($data['visibility']) ? $data['visibility'] : '0';
   $data['explanation'] = ($data['explanation']) ? $data['explanation'] : '';
-  $data['options'] = ($data['options']) ? implode("\n", $data['options']) : ''; 
- 
+  $data['options'] = ($data['options']) ? implode("\n", $data['options']) : '';
+
   $fields = array_keys($data);
 
   // Prepare the query:
@@ -29,3 +29,12 @@
 
   return db_last_insert_id('profile_fields', 'fid');
 }
+
+function install_profile_value_add($fid, $uid, $value) {
+  $exists = db_result(db_query('SELECT COUNT(*) FROM {profile_values} WHERE fid=%d AND uid=%d', $fid, $uid));
+  if ($exists) {
+    db_query("UPDATE {profile_values} SET value='%s' WHERE fid=%d AND uid=%d", $value, $fid, $uid);
+  } else {
+    db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $fid, $uid, $value);
+  }
+}