diff --git a/election.module b/election.module index 7f90abe2a8e437e3d90ae1c649539b8ce6bf8b23..a3538a363528676ad7fecc068c1c1f1d01083ddb 100644 --- a/election.module +++ b/election.module @@ -393,8 +393,8 @@ function _election_uninstall_code_electorates() { } $assigned = db_query_range( 'SELECT 1 FROM {election_post_electorate} WHERE electorate_id = :eid', - array(':eid', $db_electorate['electorate_id']), - 0, 1 + 0, 1, + array(':eid' => $db_electorate['electorate_id']) ); if ($assigned->rowCount()) { continue; @@ -426,19 +426,26 @@ function _election_uninstall_code_electorates() { * @return void */ function _election_install_code_electorates() { - foreach (_election_get_code_electorates() as $electorate_mn => $electorate) { - $record = array( - 'machine_name' => $electorate_mn, - 'name' => empty($electorate['name'])? $electorate_mn : $electorate['name'], - 'description' => @$electorate['description'], - 'locked' => 1, - 'changed' => REQUEST_TIME, - ); - db_merge('election_electorate') - ->key(array('machine_name' => $electorate_mn)) - ->updateFields($record) - ->insertFields($record + array('created' => REQUEST_TIME)) - ->execute(); + $transaction = db_transaction(); + try { + foreach (_election_get_code_electorates() as $electorate_mn => $electorate) { + $record = array( + 'machine_name' => $electorate_mn, + 'name' => empty($electorate['name'])? $electorate_mn : $electorate['name'], + 'description' => @$electorate['description'], + 'locked' => 1, + 'changed' => REQUEST_TIME, + ); + db_merge('election_electorate') + ->key(array('machine_name' => $electorate_mn)) + ->updateFields($record) + ->insertFields($record + array('created' => REQUEST_TIME)) + ->execute(); + } + } + catch (Exception $e) { + $transaction->rollback(); + watchdog_exception('election', $e, NULL, WATCHDOG_ERROR); } } @@ -657,18 +664,6 @@ function election_menu() { 'weight' => 0, ); - $items['election/%election/nomination'] = array( - 'title' => 'Nomination form', - 'page callback' => 'election_page_nomination', - 'page arguments' => array(1), - 'access callback' => 'election_access', - 'access arguments' => array('view', 1), - 'file' => 'election-candidate.pages.inc', - 'type' => MENU_LOCAL_TASK, - 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, - 'weight' => 1, - ); - $items['election/%election/posts'] = array( 'title callback' => 'election_page_postlist_title', 'title arguments' => array(1), @@ -677,7 +672,7 @@ function election_menu() { 'file' => 'election-post.admin.inc', 'access callback' => 'election_access', 'access arguments' => array('update', 2), - 'weight' => 2, + 'weight' => 1, 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, ); @@ -689,7 +684,7 @@ function election_menu() { 'page arguments' => array(1), 'access callback' => 'election_access', 'access arguments' => array('update', 1), - 'weight' => 3, + 'weight' => 2, 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, ); @@ -701,11 +696,21 @@ function election_menu() { 'access callback' => 'election_access', 'access arguments' => array('delete', 1), 'file' => 'election.admin.inc', - 'weight' => 4, + 'weight' => 3, 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_INLINE, ); + $items['election/%election/nomination'] = array( + 'title' => 'Nomination form', + 'page callback' => 'election_page_nomination', + 'page arguments' => array(1), + 'access callback' => 'election_access', + 'access arguments' => array('view', 1), + 'file' => 'election-candidate.pages.inc', + 'type' => MENU_CALLBACK, + ); + $items['election/%election/posts/add'] = array( 'title' => 'Add new', 'page callback' => 'election_post_page_add',