diff -u project.api.php project.api.php --- project.api.php 13 Aug 2010 06:31:37 -0000 +++ project.api.php 13 Aug 2010 17:17:50 -0000 @@ -45,47 +45,30 @@ } /** - * Invoked whenever a project maintainer is added. + * Invoked whenever a project maintainer is added or updated. * * This gives any modules that are providing their own per-project permissions - * a chance to store the data about a given maintainer's permissions. + * a chance to store the data about a maintainer's permissions whenever the + * record for that maintainer is being saved. * * @param $nid - * The Project NID to add the maintainer to. + * The Project NID to save the maintainer information for. * @param $uid - * The user ID of the maintainer to add. + * The user ID of the maintainer to save. * @param array $permissions * Associative array of which project-level permissions the maintainer * should have. The keys are permission names, and the values are if the * permission should be granted or not. * - * @see project_maintainer_add() * @see hook_project_permission_info() */ -function hook_project_maintainer_add($nid, $uid, $permissions) { - // TODO -} - -/** - * Invoked whenever a project maintainer is updated. - * - * This gives any modules that are providing their own per-project permissions - * a chance to store the data about an updated maintainer's permissions. - * - * @param $nid - * The Project NID to update the maintainer for. - * @param $uid - * The user ID of the maintainer to update. - * @param array $permissions - * Associative array of which project-level permissions the maintainer - * should have. The keys are permission names, and the values are if the - * permission should be granted or not. - * - * @see project_maintainer_update() - * @see hook_project_permission_info() - */ -function hook_project_maintainer_update($nid, $uid, $permissions) { - // TODO +function hook_project_maintainer_save($nid, $uid, $permissions) { + // Try to update an existing record for this maintainer for our permission. + db_query("UPDATE {example_project_maintainer} SET some_project_permission = %d WHERE nid = %d AND uid = %d", !empty($permissions['some project permission']), $nid, $uid); + if (!db_affected_rows()) { + // If we didn't have a record to update, add this as a new maintainer. + db_query("INSERT INTO {example_project_maintainer} (nid, uid, some_project_permission) VALUES (%d, %d, %d)", $nid, $uid, !empty($permissions['some project permission'])); + } } /** @@ -101,3 +84,3 @@ function hook_project_maintainer_remove($nid, $uid) { - // TODO + db_query("DELETE FROM {example_project_maintainer} WHERE nid = %d and uid = %d", $nid, $uid); } diff -u project.module project.module --- project.module 13 Aug 2010 06:45:59 -0000 +++ project.module 13 Aug 2010 17:14:08 -0000 @@ -782,28 +782,11 @@ } /** - * Add a maintainer with the specified permissions to a given project. + * Save the permissions associated with a maintainer for a given project. * - * @param $nid - * The Project NID to add the maintainer to. - * @param $uid - * The user ID of the maintainer to add. - * @param array $permissions - * Associative array of which project-level permissions the maintainer - * should have. The keys are permission names, and the values are if the - * permission should be granted or not. - */ -function project_maintainer_add($nid, $uid, $permissions = array()) { - db_query("INSERT INTO {project_maintainer} (nid, uid, administer_project, administer_project_maintainers) VALUES (%d, %d, %d, %d)", $nid, $uid, !empty($permissions['administer project']), !empty($permissions['administer project maintainers'])); - - // Invoke hook_project_maintainer_add() to let other modules know this - // maintainer now exists so they can take any actions or record any data - // they need to. - module_invoke_all('project_maintainer_add', $nid, $uid, $permissions); -} - -/** - * Update the permissions associated with a maintainer for a given project. + * This creates a new maintainer record if none currently exists. Furthermore, + * it invokes hook_project_maintainer_save() to give other modules a chance to + * act on the fact that a maintainer is being saved. * * @param $nid * The Project NID to update the maintainer for. @@ -813,21 +796,22 @@ * Associative array of which project-level permissions the maintainer * should have. The keys are permission names, and the values are if the * permission should be granted or not. + * + * @see hook_project_maintainer_save() + * @see hook_project_permission_info() */ -function project_maintainer_update($nid, $uid, $permissions = array()) { +function project_maintainer_save($nid, $uid, $permissions = array()) { + // Try to update an existing record, if any. db_query("UPDATE {project_maintainer} SET administer_project = %d, administer_project_maintainers = %d WHERE nid = %d AND uid = %d", !empty($permissions['administer project']), !empty($permissions['administer project maintainers']), $nid, $uid); - - // Make sure we actually updated a record for this maintainer. if (!db_affected_rows()) { // Didn't update anything, add this as a new maintainer, instead. - project_maintainer_add($nid, $uid, $permissions); - } - else { - // Invoke hook_project_maintainer_update() to let other modules know this - // maintainer is being updated so they can take any actions or record any - // data they need to. - module_invoke_all('project_maintainer_update', $nid, $uid, $permissions); + db_query("INSERT INTO {project_maintainer} (nid, uid, administer_project, administer_project_maintainers) VALUES (%d, %d, %d, %d)", $nid, $uid, !empty($permissions['administer project']), !empty($permissions['administer project maintainers'])); } + + // Invoke hook_project_maintainer_save() to let other modules know this + // maintainer is being saved so they can take any actions or record any + // data they need to. + module_invoke_all('project_maintainer_save', $nid, $uid, $permissions); } /** diff -u includes/project_maintainers.inc includes/project_maintainers.inc --- includes/project_maintainers.inc 13 Aug 2010 06:50:49 -0000 +++ includes/project_maintainers.inc 13 Aug 2010 17:14:35 -0000 @@ -167,13 +167,13 @@ else { $perms = $maintainer['permissions']; } - project_maintainer_update($project_nid, $uid, $perms); + project_maintainer_save($project_nid, $uid, $perms); } } // See if we need to insert a record for a new maintainer. if (!empty($form_state['values']['new_maintainer']['uid'])) { - project_maintainer_add($project_nid, $form_state['values']['new_maintainer']['uid'], $form_state['values']['new_maintainer']['permissions']); + project_maintainer_save($project_nid, $form_state['values']['new_maintainer']['uid'], $form_state['values']['new_maintainer']['permissions']); } } diff -u release/project_release.module release/project_release.module --- release/project_release.module 13 Aug 2010 06:31:37 -0000 +++ release/project_release.module 13 Aug 2010 17:17:54 -0000 @@ -154,20 +154,13 @@ } /** - * Implement hook_project_maintainer_add() + * Implement hook_project_maintainer_save() */ -function project_release_project_maintainer_add($nid, $uid, $permissions = array()) { - db_query("INSERT INTO {project_release_project_maintainer} (nid, uid, administer_project_releases) VALUES (%d, %d, %d)", $nid, $uid, !empty($permissions['administer project releases'])); -} - -/** - * Implement hook_project_maintainer_update() - */ -function project_release_project_maintainer_update($nid, $uid, $permissions = array()) { +function project_release_project_maintainer_save($nid, $uid, $permissions = array()) { db_query("UPDATE {project_release_project_maintainer} SET administer_project_releases = %d WHERE nid = %d AND uid = %d", !empty($permissions['administer project releases']), $nid, $uid); if (!db_affected_rows()) { - // If we didn't have a record to update, add this as a new maintainer. - project_release_project_maintainer_add($nid, $uid, $permissions); + // If we didn't have a record to update, add this as a new maintainer. + db_query("INSERT INTO {project_release_project_maintainer} (nid, uid, administer_project_releases) VALUES (%d, %d, %d)", $nid, $uid, !empty($permissions['administer project releases'])); } }