/[drupal]/contributions/modules/versioncontrol_cvs/versioncontrol_cvs.admin.inc
ViewVC logotype

Contents of /contributions/modules/versioncontrol_cvs/versioncontrol_cvs.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.19 - (show annotations) (download) (as text)
Fri Mar 27 15:01:26 2009 UTC (8 months ago) by jpetso
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC1, HEAD
Changes since 1.18: +11 -6 lines
File MIME type: text/x-php
Avoid excessively wide tables by cutting off ":pserver:[user]:[password]"
from the Root column in the admin repository overview.
1 <?php
2 // $Id: versioncontrol_cvs.admin.inc,v 1.18 2009/01/25 20:48:48 jpetso Exp $
3 /**
4 * @file
5 * CVS backend for Version Control API - Provides CVS commit information and
6 * account management as a pluggable backend.
7 *
8 * This file contains the administrative user interface customizations
9 * for accounts and repositories.
10 *
11 * Copyright 2006, 2007 Derek Wright ("dww" , http://drupal.org/user/46549)
12 * Copyright 2007 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
13 */
14
15 define('VERSIONCONTROL_CVS_MIN_PASSWORD_LENGTH', 5);
16
17 /**
18 * Implementation of hook_form_alter(): Add elements to various
19 * administrative forms that the Version Control API provides.
20 */
21 function versioncontrol_cvs_form_alter(&$form, $form_state, $form_id) {
22 if ($form['#id'] == 'versioncontrol-repository-form' && $form['#vcs'] == 'cvs') {
23 versioncontrol_cvs_repository_admin_form_alter($form, $form_state, $form_id);
24 }
25 else if ($form['#id'] == 'versioncontrol-account-form' && $form['#vcs'] == 'cvs') {
26 versioncontrol_cvs_account_form_alter($form, $form_state, $form_id);
27 }
28 }
29
30
31 /**
32 * Add CVS specific elements to the add/edit repository form.
33 */
34 function versioncontrol_cvs_repository_admin_form_alter(&$form, $form_state, $form_id) {
35 $repository = $form['#repository'];
36
37 $form['#versioncontrol_cvs'] = TRUE;
38 $form['#updated'] = isset($repository) ? $repository['cvs_specific']['updated'] : 0;
39
40 $form['repository_information']['root']['#description'] = t(
41 'The CVSROOT of this repository. Examples: /path or :pserver:user:password@server:/path.'
42 );
43 $form['repository_information']['modules'] = array(
44 '#type' => 'textfield',
45 '#title' => t('Modules'),
46 '#description' => t('Separate multiple CVS modules with spaces. If the "Automatic log retrieval" update method is enabled, only commits in these modules will be recorded. (Leave empty to record all commits, including those in CVSROOT.)'),
47 '#default_value' => isset($repository) ? implode(' ', $repository['cvs_specific']['modules']) : '',
48 '#weight' => 7,
49 '#size' => 40,
50 '#maxlength' => 255,
51 );
52 $form['repository_information']['update_method'] = array(
53 '#type' => 'radios',
54 '#title' => t('Update method'),
55 '#description' => t('Automatic log retrieval requires cron.'),
56 '#default_value' => isset($repository)
57 ? $repository['cvs_specific']['update_method']
58 : VERSIONCONTROL_CVS_UPDATE_CRON,
59 '#weight' => 10,
60 '#options' => array(
61 VERSIONCONTROL_CVS_UPDATE_CRON => t('Automatic log retrieval.'),
62 VERSIONCONTROL_CVS_UPDATE_XCVS => t('Use external script to insert data.'),
63 ),
64 );
65
66 $form['cvs_export_information'] = array(
67 '#type' => 'fieldset',
68 '#title' => t('Account export information'),
69 '#collapsible' => TRUE,
70 '#collapsed' => TRUE,
71 '#weight' => 2,
72 );
73 $form['cvs_export_information']['run_as_user'] = array(
74 '#type' => 'textfield',
75 '#title' => t('Run as different system user'),
76 '#description' => t('If this is empty, the exported account data will cause server-side CVS to be run with the system user corresponding to the authenticated CVS account name. If this field is not empty and you specify a different system username here, the exported account data will cause CVS to run as this user instead.'),
77 '#default_value' => isset($repository)
78 ? $repository['cvs_specific']['run_as_user']
79 : 'drupal-cvs',
80 '#weight' => 0,
81 '#size' => 40,
82 '#maxlength' => 255,
83 );
84 }
85
86 /**
87 * Implementation of hook_versioncontrol_repository_submit():
88 * Extract repository data from the repository editing/adding form's
89 * submitted values, and add it to the @p $repository array. Later, that array
90 * will be passed to hook_versioncontrol_repository() as part of the repository
91 * insert/update procedure.
92 */
93 function versioncontrol_cvs_versioncontrol_repository_submit(&$repository, $form, $form_state) {
94 if (!isset($form['#versioncontrol_cvs'])) {
95 return;
96 }
97 $modules = trim($form_state['values']['modules']);
98 $modules = empty($modules) ? array() : explode(' ', $modules);
99
100 $repository['cvs_specific'] = array(
101 'modules' => $modules,
102 'updated' => $form['#updated'],
103 'update_method' => $form_state['values']['update_method'],
104 'run_as_user' => $form_state['values']['run_as_user'],
105 );
106 }
107
108 /**
109 * Implementation of hook_versioncontrol_alter_repository_list():
110 * Add CVS specific columns into the list of CVS repositories.
111 * By changing the @p $header and @p $rows_by_repo_id arguments,
112 * the repository list can be customized accordingly.
113 *
114 * @param $vcs
115 * The unique string identifier for the version control system that
116 * the passed repository list covers.
117 * @param $repositories
118 * An array of repositories of the given version control system.
119 * Array keys are the repository ids, and array values are the
120 * repository arrays like returned from versioncontrol_get_repository().
121 * @param $header
122 * A list of columns that will be passed to theme('table').
123 * @param $rows_by_repo_id
124 * An array of existing table rows, with repository ids as array keys.
125 * Each row already includes the generic column values, and for each row
126 * there is a repository with the same repository id given in the
127 * @p $repositories parameter.
128 */
129 function versioncontrol_cvs_versioncontrol_alter_repository_list($vcs, $repositories, &$header, &$rows_by_repo_id) {
130 if ($vcs != 'cvs') {
131 return;
132 }
133 $header[] = t('Modules');
134 $header[] = t('Update method');
135 $header[] = t('Last updated');
136
137 foreach ($rows_by_repo_id as $repo_id => &$row) {
138 if (strpos($repositories[$repo_id]['root'], ':pserver:') !== FALSE) {
139 $host_start_index = strpos($repositories[$repo_id]['root'], '@') + 1;
140 $row['root'] = check_plain(substr($repositories[$repo_id]['root'], $host_start_index));
141 }
142
143 $modules = array();
144 foreach ($repositories[$repo_id]['cvs_specific']['modules'] as $module) {
145 $modules[] = check_plain($module);
146 }
147 $row['modules'] = theme('item_list', $modules);
148
149 if ($repositories[$repo_id]['cvs_specific']['update_method'] == VERSIONCONTROL_CVS_UPDATE_XCVS) {
150 $row['update_method'] = t('external script');
151 }
152 else if ($repositories[$repo_id]['cvs_specific']['update_method'] == VERSIONCONTROL_CVS_UPDATE_CRON) {
153 $row['update_method'] = t('logs (!fetch)', array(
154 '!fetch' => l(t('fetch now'), 'admin/project/versioncontrol-repositories/update/cvs/'. $repo_id)
155 ));
156 }
157 $row['updated'] = $repositories[$repo_id]['cvs_specific']['updated']
158 ? format_date($repositories[$repo_id]['cvs_specific']['updated'], 'small')
159 : t('never');
160 }
161 }
162
163
164 /**
165 * Add CVS specific elements to the edit/register user account form.
166 */
167 function versioncontrol_cvs_account_form_alter(&$form, $form_state, $form_id) {
168 $form['#versioncontrol_cvs'] = TRUE;
169
170 if (empty($form['#original_username'])) { // creating the account
171 $description = t('Choose a password to access the CVS repository with.');
172 }
173 else { // editing the account
174 $description = t('To change the current CVS password, enter the new password in both fields.');
175 }
176 $form['account']['account_password'] = array(
177 '#type' => 'password_confirm',
178 '#title' => t('CVS password'),
179 '#description' => $description,
180 '#weight' => 10,
181 );
182 $form['#validate'][] = 'versioncontrol_cvs_account_form_validate';
183 }
184
185 /**
186 * Additional validation for the edit/register user account form.
187 */
188 function versioncontrol_cvs_account_form_validate($form, &$form_state) {
189 if (!empty($form['#original_username']) && empty($form_state['values']['account_password'])) {
190 return; // The (existing) user didn't change the password.
191 }
192 else if (drupal_strlen($form_state['values']['account_password']) < VERSIONCONTROL_CVS_MIN_PASSWORD_LENGTH) {
193 form_set_error('account_password', t('The CVS password you have chosen is too short (it must be at least !min characters long).', array('!min' => VERSIONCONTROL_CVS_MIN_PASSWORD_LENGTH)));
194 }
195 }
196
197 /**
198 * Implementation of hook_versioncontrol_account_submit():
199 * Extract account data from the account edit/register form's submitted
200 * values, and add it to the @p $additional_data array. Later, that array
201 * will be passed to hook_versioncontrol_account() as part of the account
202 * insert/update procedure.
203 */
204 function versioncontrol_cvs_versioncontrol_account_submit(&$additional_data, $form, $form_state) {
205 if (!isset($form['#versioncontrol_cvs']) || empty($form_state['values']['account_password'])) {
206 return;
207 }
208 $additional_data['cvs_specific']['password'] = crypt($form_state['values']['account_password']);
209 }

  ViewVC Help
Powered by ViewVC 1.1.2