Skip to content
Browse files

fixes, fixes: starting on Item and oop some functions

- oop Item::insertSourceRevision()
- fix op::_fill() correct use of repo
- fix op::hasWriteAccess, two-level array is not recognized by ArrayAccess
- move versioncontrol_get_account_uid_for_username() to
repo::getAccountUidForUsername()
- move versioncontrol_get_account_username_for_uid() to
repo::getAccountUsernameForUid()
- move versioncontrol_is_account_authorized() to repo::isAccountAuthorized()
- some oop on commitlog
  • Loading branch information...
1 parent 561d861 commit 4d3c60a84413a102434f44d881222e4e3b09fb1e @marvil07 committed
View
6 commitlog/commitlog.module
@@ -1010,11 +1010,11 @@ function theme_commitlog_operation_items($operation, $operation_items, $format =
continue;
}
- if (isset($item['line_changes'])) {
+ if (!empty($item->line_changes)) {
$action_string = t('!action, lines: +!added -!removed', array(
'!action' => $action_string,
- '!added' => $item['line_changes']['added'],
- '!removed' => $item['line_changes']['removed'],
+ '!added' => $item->line_changes['added'],
+ '!removed' => $item->line_changes['removed'],
));
}
}
View
22 includes/VersioncontrolItem.php
@@ -832,22 +832,23 @@ public function sanitize() {
*/
public function insertSourceRevision($source_item, $action) {
if ($action == VERSIONCONTROL_ACTION_ADDED && $source_item === 0) {
- $source_item = array('item_revision_id' => 0);
+ $source_item = new stdClass();
+ $source_item->item_revision_id = 0;
}
// Before inserting that item entry, make sure it doesn't exist already.
db_query("DELETE FROM {versioncontrol_source_items}
WHERE item_revision_id = %d AND source_item_revision_id = %d",
- $this->item_revision_id, $source_item['item_revision_id']);
+ $this->item_revision_id, $source_item->item_revision_id);
- $line_changes = !empty($item['line_changes']);
+ $line_changes = !empty($this->line_changes);
db_query("INSERT INTO {versioncontrol_source_items}
(item_revision_id, source_item_revision_id, action,
line_changes_recorded, line_changes_added, line_changes_removed)
VALUES (%d, %d, %d, %d, %d, %d)",
- $this->item_revision_id, $source_item['item_revision_id'],
+ $this->item_revision_id, $source_item->item_revision_id,
$action, ($line_changes ? 1 : 0),
- ($line_changes ? $item['line_changes']['added'] : 0),
- ($line_changes ? $item['line_changes']['removed'] : 0));
+ ($line_changes ? $this->line_changes['added'] : 0),
+ ($line_changes ? $this->line_changes['removed'] : 0));
}
/**
@@ -857,10 +858,10 @@ public function insertSourceRevision($source_item, $action) {
public function ensure() {
$result = db_query(
"SELECT item_revision_id, type
- FROM {versioncontrol_item_revisions}
- WHERE repo_id = %d AND path = '%s' AND revision = '%s'",
- $this->repository->repo_id, $this->path, $this->revision
- );
+ FROM {versioncontrol_item_revisions}
+ WHERE repo_id = %d AND path = '%s' AND revision = '%s'",
+ $this->repository->repo_id, $this->path, $this->revision
+ );
while ($item_revision = db_fetch_object($result)) {
// Replace / fill in properties that were not in the WHERE condition.
$this->item_revision_id = $item_revision->item_revision_id;
@@ -875,7 +876,6 @@ public function ensure() {
/**
* Insert an item revision entry into the {versioncontrol_items_revisions} table.
- * FIXME: ?
*/
public function insert() {
$this->repo_id = $this->repository->repo_id; // for drupal_write_record() only
View
18 includes/VersioncontrolOperation.php
@@ -827,15 +827,15 @@ private static function _constraintInfo() {
private function _fill($include_unauthorized = FALSE) {
// If not already there, retrieve the full repository object.
// FIXME: take one always set member, not sure if root is one | set other condition here
- if (!isset($this->repository->root) && isset($this->repository->repo_id)) {
- $this->repository = VersioncontrolRepository::getRepository($this->repository->repo_id);
- unset($this->repository->repo_id);
+ if (!isset($this->repository->root) && isset($this->repo_id)) {
+ $this->repository = VersioncontrolRepositoryCache::getInstance()->getRepository($this->repository->repo_id);
+ unset($this->repo_id);
}
// If not already there, retrieve the Drupal user id of the committer.
if (!isset($this->author)) {
- $uid = versioncontrol_get_account_uid_for_username(
- $this->repository->repo_id, $this->author, $include_unauthorized
+ $uid = $this->repository->getAccountUidForUsername(
+ $this->author, $include_unauthorized
);
// If no uid could be retrieved, blame the commit on user 0 (anonymous).
$this->author = isset($this->author) ? $this->author : 0;
@@ -961,7 +961,7 @@ protected function getAccessErrors() {
* by calling versioncontrol_get_access_errors().
*/
protected function hasWriteAccess($operation, $operation_items) {
- $operation = _versioncontrol_fill_operation($operation);
+ $operation->_fill();
// If we can't determine this operation's repository,
// we can't really allow the operation in the first place.
@@ -986,14 +986,14 @@ protected function hasWriteAccess($operation, $operation_items) {
}
// If the user doesn't have commit access at all, we can't allow this as well.
- $repo_data = $operation['repository']['data']['versioncontrol'];
+ $repo_data = $operation->repository->data['versioncontrol'];
if (!$repo_data['allow_unauthorized_access']) {
- if (!versioncontrol_is_account_authorized($operation['repository'], $operation['uid'])) {
+ if (!$operation->repository->isAccountAuthorized($operation->uid)) {
$this->_accessErrors(array(t(
'** ERROR: !user does not have commit access to this repository.',
- array('!user' => $operation['username'])
+ array('!user' => $operation->committer)
)));
return FALSE;
}
View
69 includes/VersioncontrolRepository.php
@@ -477,6 +477,75 @@ public function getUrlHandler() {
return $this->data['versioncontrol']['url_handler'];
}
+ /**
+ * Retrieve the VCS username for a given Drupal user id in a specific
+ * repository. If you need more detailed querying functionality than
+ * this function provides, use
+ * VersioncontrolAccountCache::getInstance()->getAccounts() instead.
+ *
+ * @param $username
+ * The VCS specific username (a string) corresponding to the Drupal
+ * user.
+ * @param $include_unauthorized
+ * If FALSE (which is the default), this function does not return
+ * accounts that are pending, queued, disabled, blocked, or otherwise
+ * non-approved. If TRUE, all accounts are returned, regardless of
+ * their status.
+ *
+ * @return
+ * The Drupal user id that corresponds to the given username and
+ * repository, or NULL if no Drupal user could be associated to
+ * those.
+ */
+ public function getAccountUidForUsername($username, $include_unauthorized = FALSE) {
+ $result = db_query("SELECT uid, repo_id
+ FROM {versioncontrol_accounts}
+ WHERE username = '%s' AND repo_id = %d",
+ $username, $this->repo_id);
+
+ while ($account = db_fetch_object($result)) {
+ // Only include approved accounts, except in case the caller said otherwise.
+ if ($include_unauthorized || $this->isAccountAuthorized($account->uid)) {
+ return $account->uid;
+ }
+ }
+ return NULL;
+ }
+
+ /**
+ * Retrieve the Drupal user id for a given VCS username in a specific
+ * repository. If you need more detailed querying functionality than
+ * this function provides, use
+ * VersioncontrolAccountCache::getInstance()->getAccounts() instead.
+ *
+ * @param $uid
+ * The Drupal user id corresponding to the VCS account.
+ * @param $include_unauthorized
+ * If FALSE (which is the default), this function does not return
+ * accounts that are pending, queued, disabled, blocked, or otherwise
+ * non-approved. If TRUE, all accounts are returned, regardless of
+ * their status.
+ *
+ * @return
+ * The VCS username (a string) that corresponds to the given Drupal
+ * user and repository, or NULL if no VCS account could be associated
+ * to those.
+ */
+ function getAccountUsernameForUid($uid, $include_unauthorized = FALSE) {
+ $result = db_query('SELECT uid, username, repo_id
+ FROM {versioncontrol_accounts}
+ WHERE uid = %d AND repo_id = %d',
+ $uid, $this->repo_id);
+
+ while ($account = db_fetch_object($result)) {
+ // Only include approved accounts, except in case the caller said otherwise.
+ if ($include_unauthorized || $this->isAccountAuthorized($account->uid)) {
+ return $account->username;
+ }
+ }
+ return NULL;
+ }
+
//ArrayAccess interface implementation
public function offsetExists($offset) {
return isset($this->$offset);
View
70 versioncontrol.module
@@ -1178,74 +1178,6 @@ function versioncontrol_fetch_successor_items($repository, &$items) {
}
/**
- * Retrieve the VCS username for a given Drupal user id in a specific
- * repository. If you need more detailed querying functionality than this
- * function provides, use VersioncontrolAccountCache::getInstance()->getAccounts() instead.
- *
- * @param $repo_id
- * The repository id of the repository where the user has its VCS account.
- * @param $username
- * The VCS specific username (a string) corresponding to the Drupal user.
- * @param $include_unauthorized
- * If FALSE (which is the default), this function does not return accounts
- * that are pending, queued, disabled, blocked, or otherwise non-approved.
- * If TRUE, all accounts are returned, regardless of their status.
- *
- * @return
- * The Drupal user id that corresponds to the given username and repository,
- * or NULL if no Drupal user could be associated to those.
- */
-function versioncontrol_get_account_uid_for_username($repo_id, $username, $include_unauthorized = FALSE) {
- $result = db_query("SELECT uid, repo_id
- FROM {versioncontrol_accounts}
- WHERE username = '%s' AND repo_id = %d",
- $username, $repo_id);
-
- while ($account = db_fetch_object($result)) {
- $repository = VersioncontrolRepositoryCache::getInstance()->getRepository($account->repo_id);
- // Only include approved accounts, except in case the caller said otherwise.
- if ($include_unauthorized || versioncontrol_is_account_authorized($repository, $account->uid)) {
- return $account->uid;
- }
- }
- return NULL;
-}
-
-/**
- * Retrieve the Drupal user id for a given VCS username in a specific
- * repository. If you need more detailed querying functionality than this
- * function provides, use VersioncontrolAccountCache::getInstance()->getAccounts() instead.
- *
- * @param $repo_id
- * The repository id of the repository where the user has its VCS account.
- * @param $uid
- * The Drupal user id corresponding to the VCS account.
- * @param $include_unauthorized
- * If FALSE (which is the default), this function does not return accounts
- * that are pending, queued, disabled, blocked, or otherwise non-approved.
- * If TRUE, all accounts are returned, regardless of their status.
- *
- * @return
- * The VCS username (a string) that corresponds to the given Drupal user
- * and repository, or NULL if no VCS account could be associated to those.
- */
-function versioncontrol_get_account_username_for_uid($repo_id, $uid, $include_unauthorized = FALSE) {
- $result = db_query('SELECT uid, username, repo_id
- FROM {versioncontrol_accounts}
- WHERE uid = %d AND repo_id = %d',
- $uid, $repo_id);
-
- while ($account = db_fetch_object($result)) {
- $repository = VersioncontrolRepositoryCache::getInstance()->getRepository($account->repo_id);
- // Only include approved accounts, except in case the caller said otherwise.
- if ($include_unauthorized || versioncontrol_is_account_authorized($repository, $account->uid)) {
- return $account->username;
- }
- }
- return NULL;
-}
-
-/**
* Get the user-visible version of a commit identifier a.k.a. 'revision',
* as plaintext. By default, this function returns the operation's revision
* if that property exists, or its vc_op_id identifier as fallback.
@@ -1600,7 +1532,7 @@ function versioncontrol_user_autocomplete($repo_id, $string = '') {
if (!isset($repository)) {
$repository = VersioncontrolRepositoryCache::getInstance()->getRepository($repo_id);
}
- if (versioncontrol_is_account_authorized($repository, $user->uid)) {
+ if ($repository->isAccountAuthorized($user->uid)) {
$matches[$user->name] = check_plain($user->name);
}
}
View
2 versioncontrol.pages.inc
@@ -490,7 +490,7 @@ function versioncontrol_account_edit_form_validate($form, &$form_state) {
$form_state['values']['account_name'] = $username;
// Check for duplicates.
- $existing_uid = versioncontrol_get_account_uid_for_username($repository['repo_id'], $username, TRUE);
+ $existing_uid = $repository->getAccountUidForUsername($username, TRUE);
if ($existing_uid && $uid != $existing_uid) {
if ($existing_user = user_load(array('uid' => $existing_uid))) {
$existing_username = theme('username', $existing_user);
View
2 versioncontrol_fakevcs/versioncontrol_fakevcs.module
@@ -372,7 +372,7 @@ function versioncontrol_fakevcs_import_accounts($repository, $data) {
'fakevcs_specific' => array('password' => $password),
);
$username = $account['username'];
- $uid = versioncontrol_get_account_uid_for_username($repository['repo_id'], $username, TRUE);
+ $uid = $repository->getAccountUidForUsername($username, TRUE);
if (isset($uid)) {
versioncontrol_update_account($repository, $uid, $username, $additional_data);

0 comments on commit 4d3c60a

Please sign in to comment.
Something went wrong with that request. Please try again.