2 // $Id: versioncontrol_git.admin.inc,v 1.13 2007/11/09 20:37:13 jpetso Exp $
4 define('VERSIONCONTROL_GIT_MIN_PASSWORD_LENGTH', 5);
7 * Implementation of hook_form_alter(): Add elements to various
8 * administrative forms that the Version Control API provides.
10 function versioncontrol_git_form_alter($form_id, &$form) {
11 if ($form['#id'] == 'versioncontrol-repository-form' && $form['#vcs'] == 'git') {
12 versioncontrol_git_repository_admin_form_alter($form_id, $form);
14 else if ($form['#id'] == 'versioncontrol-account-form' && $form['#vcs'] == 'git') {
15 versioncontrol_git_account_form_alter($form_id, $form);
21 * Add GIT specific elements to the add/edit repository form.
23 function versioncontrol_git_repository_admin_form_alter($form_id, &$form) {
24 $repository = $form['#repository'];
26 $form['versioncontrol_git'] = array(
30 $form['updated'] = array(
32 '#value' => isset($repository) ? $repository['git_specific']['updated'] : 0,
35 $form['repository_information']['root']['#description'] = t(
36 'The GITROOT of this repository. Examples: /path or :pserver:user:password@server:/path.'
38 $form['repository_information']['modules'] = array(
39 '#type' => 'textfield',
40 '#title' => t('Modules'),
41 '#description' => t('Separate multiple GIT modules with spaces.'),
42 '#default_value' => isset($repository) ? implode(' ', $repository['git_specific']['modules']) : '',
47 $form['repository_information']['update_method'] = array(
49 '#title' => t('Update method'),
50 '#description' => t('Automatic log retrieval requires cron.'),
51 '#default_value' => isset($repository)
52 ? $repository['git_specific']['update_method']
53 : VERSIONCONTROL_GIT_UPDATE_XGIT,
56 // log retrieval is not yet ported from git.module
57 // VERSIONCONTROL_GIT_UPDATE_CRON => t('Automatic log retrieval.'),
58 VERSIONCONTROL_GIT_UPDATE_XGIT => t('Use external script to insert data.'),
62 $form['git_export_information'] = array(
63 '#type' => 'fieldset',
64 '#title' => t('Account export information'),
65 '#collapsible' => TRUE,
69 $form['git_export_information']['run_as_user'] = array(
70 '#type' => 'textfield',
71 '#title' => t('Run as different system user'),
72 '#description' => t('If this is empty, the exported account data will cause server-side GIT to be run with the system user corresponding to the authenticated GIT account name. If this field is not empty and you specify a different system username here, the exported account data will cause GIT to run as this user instead.'),
73 '#default_value' => isset($repository)
74 ? $repository['git_specific']['run_as_user']
83 * Implementation of hook_versioncontrol_extract_repository_data():
84 * Extract GIT specific repository additions from the repository
85 * editing/adding form's submitted values.
87 function versioncontrol_git_versioncontrol_extract_repository_data($form_values) {
88 if (!isset($form_values['versioncontrol_git'])) {
91 $modules = trim($form_values['modules']);
92 $modules = empty($modules) ? array() : explode(' ', $modules);
95 'git_specific' => array(
96 'modules' => $modules,
97 'update_method' => $form_values['update_method'],
98 'updated' => $form_values['updated'],
99 'run_as_user' => $form_values['run_as_user'],
105 * Implementation of hook_versioncontrol_alter_repository_list():
106 * Add GIT specific columns into the list of GIT repositories.
107 * By changing the @p $header and @p $rows_by_repo_id arguments,
108 * the repository list can be customized accordingly.
111 * The unique string identifier for the version control system that
112 * the passed repository list covers.
113 * @param $repositories
114 * An array of repositories of the given version control system.
115 * Array keys are the repository ids, and array values are the
116 * repository arrays like returned from versioncontrol_get_repository().
118 * A list of columns that will be passed to theme('table').
119 * @param $rows_by_repo_id
120 * An array of existing table rows, with repository ids as array keys.
121 * Each row already includes the generic column values, and for each row
122 * there is a repository with the same repository id given in the
123 * @p $repositories parameter.
125 function versioncontrol_git_versioncontrol_alter_repository_list($vcs, $repositories, &$header, &$rows_by_repo_id) {
129 $header[] = t('Modules');
130 $header[] = t('Update method');
131 $header[] = t('Last updated');
133 foreach ($rows_by_repo_id as $repo_id => $row) {
135 foreach ($repositories[$repo_id]['git_specific']['modules'] as $module) {
136 $modules[] = check_plain($module);
138 $rows_by_repo_id[$repo_id][] = theme('item_list', $modules);
140 if ($repositories[$repo_id]['git_specific']['update_method'] == VERSIONCONTROL_GIT_UPDATE_XGIT) {
141 $rows_by_repo_id[$repo_id][] = t('external script');
142 $rows_by_repo_id[$repo_id][] = t('n/a');
144 else if ($repositories[$repo_id]['git_specific']['update_method'] == VERSIONCONTROL_GIT_UPDATE_CRON) {
145 $rows_by_repo_id[$repo_id][] = t('logs (!fetch)', array(
146 '!fetch' => l(t('fetch now'), 'admin/project/versioncontrol-repositories/update/'. $repo_id)
148 $rows_by_repo_id[$repo_id][] = $repositories[$repo_id]['git_specific']['updated']
149 ? format_date($repositories[$repo_id]['git_specific']['updated'])
157 * Add GIT specific elements to the edit/register user account form.
159 function versioncontrol_git_account_form_alter($form_id, &$form) {
160 $form['versioncontrol_git'] = array(
165 if (empty($form['original_username']['#value'])) { // creating the account
166 $description = t('Choose a password to access the GIT repository with.');
168 else { // editing the account
169 $description = t('To change the current GIT password, enter the new password in both fields.');
171 $form['account']['account_password'] = array(
172 '#type' => 'password_confirm',
173 '#title' => t('GIT password'),
174 '#description' => $description,
177 $form['#validate']['versioncontrol_git_account_form_validate'] = array();
181 * Additional validation for the edit/register user account form.
183 function versioncontrol_git_account_form_validate($form_id, $form_values) {
184 if (!empty($form_values['original_username']) && empty($form_values['account_password'])) {
185 return; // The (existing) user didn't change the password.
187 else if (strlen($form_values['account_password']) < VERSIONCONTROL_GIT_MIN_PASSWORD_LENGTH) {
188 form_set_error('account_password', t('The GIT password you have chosen is too short (it must be at least !min characters long).', array('!min' => VERSIONCONTROL_GIT_MIN_PASSWORD_LENGTH)));
193 * Implementation of hook_versioncontrol_extract_account_data():
194 * Extract GIT specific user account additions (say: the password)
195 * from the edit/register user account form's submitted values.
197 function versioncontrol_git_versioncontrol_extract_account_data($form_values) {
198 if (!isset($form_values['versioncontrol_git']) || empty($form_values['account_password'])) {
202 'git_specific' => array(
203 'password' => crypt($form_values['account_password']),