Index: user_relationships_api/user_relationships_api.api.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/user_relationships/user_relationships_api/Attic/user_relationships_api.api.inc,v retrieving revision 1.1.2.9 diff -u -r1.1.2.9 user_relationships_api.api.inc --- user_relationships_api/user_relationships_api.api.inc 14 Jan 2009 10:58:30 -0000 1.1.2.9 +++ user_relationships_api/user_relationships_api.api.inc 25 Feb 2009 20:04:58 -0000 @@ -199,21 +201,14 @@ ); } } - else { - $relationship->rid = db_result(db_query("SELECT MAX(rid) FROM {user_relationships}")) + 1; - } if ($valid = drupal_write_record('user_relationships', $relationship)) { // if the relationship has been approved and is two-way we need // to do a double entry for DB efficiency $relationship_type = user_relationships_type_load($relationship->rtid); if ($relationship->approved && !$relationship_type->is_oneway) { - $relationship_copy = drupal_clone($relationship); - - $relationship_copy->requester_id = $relationship->requestee_id; - $relationship_copy->requestee_id = $relationship->requester_id; - - $valid = drupal_write_record('user_relationships', $relationship_copy); + //#365623 drupal_write_record will not work because rid is a serial field, and we need to use the same rid + $valid = db_query('INSERT INTO {user_relationships} (rid, requester_id, requestee_id, rtid, approved, created_at, updated_at, flags) SELECT rid, requestee_id, requester_id, rtid, approved, created_at, updated_at, flags from {user_relationships} where rid = %d', $relationship->rid); } // second entry didn't go well. revert the first Index: user_relationships_api/user_relationships_api.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/user_relationships/user_relationships_api/Attic/user_relationships_api.install,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 user_relationships_api.install --- user_relationships_api/user_relationships_api.install 14 Oct 2008 09:14:03 -0000 1.1.2.5 +++ user_relationships_api/user_relationships_api.install 25 Feb 2009 20:04:58 -0000 @@ -1,15 +1,18 @@ array( - 'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'rid' => array('type' => 'serial', 'not null' => TRUE), 'requester_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'requestee_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'rtid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), @@ -18,11 +21,8 @@ 'updated_at' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'flags' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), ), - 'unique keys' => array( - 'relationship' => array('requester_id', 'requestee_id', 'rtid'), - ), + 'primary key' => array('requester_id', 'requestee_id', 'rtid'), 'indexes' => array( - 'rid' => array('rid'), 'requester_id' => array('requester_id'), 'requestee_id' => array('requestee_id'), 'rtid' => array('rtid'), @@ -48,15 +48,38 @@ } /** - * Install + * Implementation of hook_install(). */ function user_relationships_api_install() { drupal_install_schema('user_relationships_api'); } /** - * Uninstall + * Implementation of hook_uninstall(). */ function user_relationships_api_uninstall() { drupal_uninstall_schema('user_relationships_api'); } + +/** + * Implementation of hook_update_N(). + * Update 6100 changes the {user_relationships} rid column from an INT to a SERIAL type. + */ +function user_relationships_api_update_6100() { + $ret = array(); + db_drop_index($ret, 'user_relationships', 'rid'); + db_change_field($ret, 'user_relationships', 'rid', 'rid', array('type' => 'serial', 'not null' => TRUE), array('indexes' => array('rid' => array('rid')))); + return $ret; +}