Skip to content

Commit

Permalink
let account status update work
Browse files Browse the repository at this point in the history
make VersioncontrolAccount::update() OO and change form stuff to call it in the
right way
  • Loading branch information
marvil07 committed Jul 12, 2009
1 parent 0933b30 commit 7050a40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
39 changes: 19 additions & 20 deletions includes/VersioncontrolAccount.php
Expand Up @@ -222,60 +222,59 @@ public function isUsernameValid(&$username) {

/**
* Update a VCS user account in the database, and call the necessary
* module hooks. The @p $repository and @p $uid parameters must stay the same
* values as the one given on account creation, whereas @p $username and
* module hooks. The account repository and uid must stay the same values as
* the one given on account creation, whereas vcs_username and
* @p $additional_data may change.
*
* @param $uid
* The Drupal user id corresponding to the VCS username.
* @param $username
* The VCS specific username (a string).
* @param $repository
* The repository where the user has its VCS account.
* The VCS specific username (a string). Here we are using an explicit
* parameter instead of taking the vcs_username data member to be able to
* verify is it changed, there would be lots of operations, so we do not
* want to update them if it's not necessary.
* @param $additional_data
* An array of additional author information. Modules can fill this array
* by implementing hook_versioncontrol_account_submit().
*/
public function update($repository, $uid, $username, $additional_data = array()) {
$old_username = versioncontrol_get_account_username_for_uid($repository['repo_id'], $uid, TRUE);
$username_changed = ($username != $old_username);
public function update($username, $additional_data = array()) {
$repo_id = $this->repository->repo_id;
$username_changed = ($username != $this->vcs_username);

if ($username_changed) {
$this->vcs_username = $username;
db_query("UPDATE {versioncontrol_accounts}
SET username = '%s'
WHERE uid = %d AND repo_id = %d",
$username, $uid, $repository['repo_id']
$this->vcs_username, $this->uid, $repo_id
);
}

// Provide an opportunity for the backend to add its own stuff.
if (versioncontrol_backend_implements($repository['vcs'], 'account')) {
if (versioncontrol_backend_implements($this->repository->vcs, 'account')) {
_versioncontrol_call_backend(
$repository['vcs'], 'account',
array('update', $uid, $username, $repository, $additional_data)
$this->repository->vcs, 'account',
array('update', $this->uid, $this->vcs_username, $this->repository, $additional_data)
);
}

// Update the operations table.
if ($username_changed) {
db_query("UPDATE {versioncontrol_operations}
SET uid = 0
WHERE uid = %d AND repo_id = %d",
$uid, $repository['repo_id']);
$this->uid, $repo_id);
db_query("UPDATE {versioncontrol_operations}
SET uid = %d
WHERE username = '%s' AND repo_id = %d",
$uid, $username, $repository['repo_id']);
WHERE committer = '%s' AND repo_id = %d",
$this->uid, $this->vcs_username, $repo_id);
}

// Everything's done, let the world know about it!
module_invoke_all('versioncontrol_account',
'update', $uid, $username, $repository, $additional_data
'update', $this->uid, $this->vcs_username, $this->repository, $additional_data
);

watchdog('special',
'Version Control API: updated @username account in repository @repository',
array('@username' => $username, '@repository' => $repository['name']),
array('@username' => $this->vcs_username, '@repository' => $this->repository->name),
WATCHDOG_NOTICE, l('view', 'admin/project/versioncontrol-accounts')
);
}
Expand Down
14 changes: 9 additions & 5 deletions versioncontrol.pages.inc
Expand Up @@ -378,8 +378,8 @@ function versioncontrol_account_edit_form(&$form_state, $uid, $repository, $vcs_
$form['#submit'] = array('versioncontrol_account_edit_form_submit');

if ($create_account) {
$registration_message = isset($repository['data']['versioncontrol']['registration_message'])
? $repository['data']['versioncontrol']['registration_message']
$registration_message = isset($repository->data['versioncontrol']['registration_message'])
? $repository->data['versioncontrol']['registration_message']
: '';

if (!empty($registration_message)) {
Expand Down Expand Up @@ -535,14 +535,18 @@ function versioncontrol_account_edit_form_submit($form, &$form_state) {
));
}
else {
//FIXME why username are a required constraint?
// uid and repo_id are the PK on the table getAccounts query
$constraints = array(
'uids' => array($uid),
'repo_ids' => array($repository->repo_id),
'usernames' => array($form['#original_username'])
);
$vcs_accounts = VersioncontrolAccount::getAccounts($constraints);
//FIXME actually update
versioncontrol_update_account($repository, $uid, $username, $additional_data);
$vcs_accounts = VersioncontrolAccount::getAccounts($constraints, TRUE);
// if we got an original_username we can trust on getting a value
$vcs_account = array_shift(array_shift($vcs_accounts));

$vcs_account->update($username, $additional_data);

// Regular users cannot change the username, and will probably get
// a message for each of the other actions that hook into the form.
Expand Down

0 comments on commit 7050a40

Please sign in to comment.