| 1 |
<?php
|
| 2 |
// $Id: versioncontrol_git.admin.inc,v 1.11 2009/10/19 15:18:33 marvil07 Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Git backend for Version Control API - Provides Git commit information and
|
| 6 |
* account management as a pluggable backend.
|
| 7 |
*
|
| 8 |
* Copyright 2008 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
|
| 9 |
* Copyright 2009 by Cornelius Riemenschneider ("CorniI", http://drupal.org/user/136353)
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_form_alter(): Add elements to various
|
| 14 |
* administrative forms that the Version Control API provides.
|
| 15 |
*/
|
| 16 |
function versioncontrol_git_form_alter(&$form, $form_state, $form_id) {
|
| 17 |
if ($form['#id'] == 'versioncontrol-repository-form' && $form['#vcs'] == 'git') {
|
| 18 |
versioncontrol_git_repository_admin_form_alter($form, $form_state, $form_id);
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Add Git specific elements to the add/edit repository form.
|
| 24 |
*/
|
| 25 |
function versioncontrol_git_repository_admin_form_alter(&$form, $form_state, $form_id) {
|
| 26 |
$repository = isset($form['#repository'])? $form['#repository']: null;
|
| 27 |
|
| 28 |
$form['versioncontrol_git'] = array(
|
| 29 |
'#type' => 'value',
|
| 30 |
'#value' => TRUE,
|
| 31 |
);
|
| 32 |
$form['repository_information']['update_method'] = array(
|
| 33 |
'#type' => 'radios',
|
| 34 |
'#title' => t('Update method'),
|
| 35 |
'#description' => t('Automatic log retrieval requires cron.'),
|
| 36 |
'#default_value' => !is_null($repository)
|
| 37 |
? $repository->data['versioncontrol_git']['update_method']
|
| 38 |
: VERSIONCONTROL_GIT_UPDATE_CRON,
|
| 39 |
'#weight' => 9,
|
| 40 |
'#options' => array(
|
| 41 |
VERSIONCONTROL_GIT_UPDATE_CRON => t('Automatic log retrieval.'),
|
| 42 |
VERSIONCONTROL_GIT_UPDATE_XGIT => t('Use external script to insert data.'),
|
| 43 |
),
|
| 44 |
);
|
| 45 |
}
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Implementation of hook_versioncontrol_repository_submit():
|
| 49 |
* Extract Git specific repository additions from the repository
|
| 50 |
* editing/adding form's submitted values.
|
| 51 |
*/
|
| 52 |
function versioncontrol_git_versioncontrol_repository_submit(&$repository, $form, $form_state) {
|
| 53 |
if (!isset($form['versioncontrol_git'])) {
|
| 54 |
return array();
|
| 55 |
}
|
| 56 |
|
| 57 |
$update_method = (int)$form_state['values']['update_method'];
|
| 58 |
$repository->data['versioncontrol_git']['update_method'] = $update_method;
|
| 59 |
|
| 60 |
// provide defaulf values on repo create
|
| 61 |
if (!isset($repository->data['versioncontrol_git']['updated'])) {
|
| 62 |
$repository->data['versioncontrol_git']['updated'] = 0;
|
| 63 |
}
|
| 64 |
if (!isset($repository->data['versioncontrol_git']['locked'])) {
|
| 65 |
$repository->data['versioncontrol_git']['locked'] = 0;
|
| 66 |
}
|
| 67 |
}
|
| 68 |
|
| 69 |
/**
|
| 70 |
* Implementation of hook_versioncontrol_alter_repository_list():
|
| 71 |
* Add Git specific columns into the list of Git repositories.
|
| 72 |
* By changing the @p $header and @p $rows_by_repo_id arguments,
|
| 73 |
* the repository list can be customized accordingly.
|
| 74 |
*
|
| 75 |
* @param $vcs
|
| 76 |
* The unique string identifier for the version control system that
|
| 77 |
* the passed repository list covers.
|
| 78 |
* @param $repositories
|
| 79 |
* An array of repositories of the given version control system.
|
| 80 |
* Array keys are the repository ids, and array values are the
|
| 81 |
* repository arrays like returned from versioncontrol_get_repository().
|
| 82 |
* @param $header
|
| 83 |
* A list of columns that will be passed to theme('table').
|
| 84 |
* @param $rows_by_repo_id
|
| 85 |
* An array of existing table rows, with repository ids as array keys.
|
| 86 |
* Each row already includes the generic column values, and for each row
|
| 87 |
* there is a repository with the same repository id given in the
|
| 88 |
* @p $repositories parameter.
|
| 89 |
*/
|
| 90 |
function versioncontrol_git_versioncontrol_alter_repository_list($vcs, $repositories, &$header, &$rows_by_repo_id) {
|
| 91 |
if ($vcs != 'git') {
|
| 92 |
return;
|
| 93 |
}
|
| 94 |
$header[] = t('Update method');
|
| 95 |
$header[] = t('Last updated');
|
| 96 |
$header[] = t('Locking');
|
| 97 |
|
| 98 |
foreach ($rows_by_repo_id as $repo_id => $row) {
|
| 99 |
if ($repositories[$repo_id]->data['versioncontrol_git']['update_method'] == VERSIONCONTROL_GIT_UPDATE_XGIT) {
|
| 100 |
$rows_by_repo_id[$repo_id][] = t('external script');
|
| 101 |
}
|
| 102 |
if ($repositories[$repo_id]->data['versioncontrol_git']['update_method'] == VERSIONCONTROL_GIT_UPDATE_CRON) {
|
| 103 |
$rows_by_repo_id[$repo_id][] = t('logs (!fetch)', array(
|
| 104 |
'!fetch' => l(t('fetch now'), 'admin/project/versioncontrol-repositories/update/git/'. $repo_id)
|
| 105 |
));
|
| 106 |
}
|
| 107 |
$rows_by_repo_id[$repo_id][] = $repositories[$repo_id]->data['versioncontrol_git']['updated']
|
| 108 |
? format_date($repositories[$repo_id]->data['versioncontrol_git']['updated'], 'small')
|
| 109 |
: t('never');
|
| 110 |
$rows_by_repo_id[$repo_id][] = t('Locking (!lock)', array(
|
| 111 |
'!lock' => l(t('Clear lock now'), 'admin/project/versioncontrol-repositories/clearlock/git/'. $repo_id)
|
| 112 |
));
|
| 113 |
}
|
| 114 |
}
|