updated TODO list
[drupal_versioncontrol_git.git] / versioncontrol_git.admin.inc
blob2e9a95a9ba357f72f27fb84663a1ff771531f9be
1 <?php
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);
6 /**
7  * Implementation of hook_form_alter(): Add elements to various
8  * administrative forms that the Version Control API provides.
9  */
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);
13   }
14   else if ($form['#id'] == 'versioncontrol-account-form' && $form['#vcs'] == 'git') {
15     versioncontrol_git_account_form_alter($form_id, $form);
16   }
20 /**
21  * Add GIT specific elements to the add/edit repository form.
22  */
23 function versioncontrol_git_repository_admin_form_alter($form_id, &$form) {
24   $repository = $form['#repository'];
26   $form['versioncontrol_git'] = array(
27     '#type' => 'value',
28     '#value' => TRUE,
29   );
30   $form['updated'] = array(
31     '#type' => 'value',
32     '#value' => isset($repository) ? $repository['git_specific']['updated'] : 0,
33   );
35   $form['repository_information']['root']['#description'] = t(
36     'The GITROOT of this repository. Examples: /path or :pserver:user:password@server:/path.'
37   );
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']) : '',
43     '#weight' => 7,
44     '#size' => 40,
45     '#maxlength' => 255,
46   );
47   $form['repository_information']['update_method'] = array(
48     '#type' => 'radios',
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,
54     '#weight' => 10,
55     '#options' => array(
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.'),
59     ),
60   );
62   $form['git_export_information'] = array(
63     '#type' => 'fieldset',
64     '#title' => t('Account export information'),
65     '#collapsible' => TRUE,
66     '#collapsed' => TRUE,
67     '#weight' => 2,
68   );
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']
75                         : 'drupal-git',
76     '#weight' => 0,
77     '#size' => 40,
78     '#maxlength' => 255,
79   );
82 /**
83  * Implementation of hook_versioncontrol_extract_repository_data():
84  * Extract GIT specific repository additions from the repository
85  * editing/adding form's submitted values.
86  */
87 function versioncontrol_git_versioncontrol_extract_repository_data($form_values) {
88   if (!isset($form_values['versioncontrol_git'])) {
89     return array();
90   }
91   $modules = trim($form_values['modules']);
92   $modules = empty($modules) ? array() : explode(' ', $modules);
94   return array(
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'],
100     ),
101   );
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.
110  * @param $vcs
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().
117  * @param $header
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.
124  */
125 function versioncontrol_git_versioncontrol_alter_repository_list($vcs, $repositories, &$header, &$rows_by_repo_id) {
126   if ($vcs != 'git') {
127     return;
128   }
129   $header[] = t('Modules');
130   $header[] = t('Update method');
131   $header[] = t('Last updated');
133   foreach ($rows_by_repo_id as $repo_id => $row) {
134     $modules = array();
135     foreach ($repositories[$repo_id]['git_specific']['modules'] as $module) {
136       $modules[] = check_plain($module);
137     }
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');
143     }
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)
147       ));
148       $rows_by_repo_id[$repo_id][] = $repositories[$repo_id]['git_specific']['updated']
149                                      ? format_date($repositories[$repo_id]['git_specific']['updated'])
150                                      : t('never');
151     }
152   }
157  * Add GIT specific elements to the edit/register user account form.
158  */
159 function versioncontrol_git_account_form_alter($form_id, &$form) {
160   $form['versioncontrol_git'] = array(
161     '#type' => 'value',
162     '#value' => TRUE,
163   );
165   if (empty($form['original_username']['#value'])) { // creating the account
166     $description = t('Choose a password to access the GIT repository with.');
167   }
168   else { // editing the account
169     $description = t('To change the current GIT password, enter the new password in both fields.');
170   }
171   $form['account']['account_password'] = array(
172     '#type' => 'password_confirm',
173     '#title' => t('GIT password'),
174     '#description' => $description,
175     '#weight' => 10,
176   );
177   $form['#validate']['versioncontrol_git_account_form_validate'] = array();
181  * Additional validation for the edit/register user account form.
182  */
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.
186   }
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)));
189   }
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.
196  */
197 function versioncontrol_git_versioncontrol_extract_account_data($form_values) {
198   if (!isset($form_values['versioncontrol_git']) || empty($form_values['account_password'])) {
199     return array();
200   }
201   return array(
202     'git_specific' => array(
203       'password' => crypt($form_values['account_password']),
204     ),
205   );