Skip to content
Snippets Groups Projects
Commit 424990de authored by Neil Drumm's avatar Neil Drumm :wave:
Browse files

Issue #3328663: Remove versioncontrol_project_git & versioncontrol_project_issue submodules

parent 4ff38350
No related branches found
No related tags found
No related merge requests found
name = "Version Control Git / Project"
description = "Provides additional Git-specific integration between the Version Control API suite and the Project suite."
core = 7.x
package = Version Control
dependencies[] = versioncontrol_git
dependencies[] = versioncontrol_project
<?php
/**
* @file
* Provides additional Git-specific integration between the Version Control API
* suite and the Project suite.
*/
/**
* Implements hook_menu().
*/
function versioncontrol_project_git_menu() {
$items['node/%project/edit/default-branch'] = array(
'title' => 'Default branch',
'page callback' => 'drupal_get_form',
'page arguments' => array('versioncontrol_project_git_default_branch_form', 1),
'access callback' => 'versioncontrol_project_git_write_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
'file' => 'versioncontrol_project_git.pages.inc',
);
return $items;
}
/**
* Access callback: Checks for a user's access to a valid Git repository.
*
* @param $project
* The project object that should have an attached repository.
*
* @return
* TRUE if the project has an attached Git repository with at least one
* branch that the user has write access to, FALSE otherwise.
*/
function versioncontrol_project_git_write_access(stdClass $project) {
// Display only on nodes that have a repository attached.
if (!isset($project->versioncontrol_project) || !isset($project->versioncontrol_project['repo'])) {
return FALSE;
}
// Ensure it is a Git repository.
if (!$project->versioncontrol_project['repo'] instanceof VersioncontrolGitRepository) {
return FALSE;
}
// Check the permissions.
return project_user_access($project, 'write to vcs');
}
<?php
/**
* @file
* Page callback and submit handler for the default branch form.
*/
/**
* Form constructor for the default branch form.
*/
function versioncontrol_project_git_default_branch_form($form, $form_state, $project) {
$repo = $project->versioncontrol_project['repo'];
$form['#repo'] = $repo;
$form['#nid'] = $project->nid;
// Add the radios widget for default branch selection.
$form['default_branch'] = array(
'#title' => t('The default repository branch'),
'#description' => t('This branch will be checked out by default when someone clones the project.'),
'#type' => 'radios',
'#options' => array(),
);
// Make all branches available as options.
$branches = $repo->loadBranches();
foreach ($branches as $id => $branch) {
$form['default_branch']['#options'][$id] = check_plain($branch->name);
}
uasort($form['default_branch']['#options'], '_versioncontrol_project_git_inverse_version_compare');
// No branches yet.
if (count($form['default_branch']['#options']) === 0) {
drupal_set_message(t('No branches have been pushed to this repository, so a default branch can not be set. See the <a href="!url">version control instructions</a> for help with <code>git push</code>.', ['!url' => url('node/' . $project->nid . '/git-instructions')]), 'warning');
return $form;
}
// Make the current default branch the default selection.
if ($repo->getDefaultBranch()) {
$default_branch = $repo->loadBranches(NULL, array('name' => $repo->getDefaultBranch()));
foreach ($default_branch as $id => $branch) {
$form['default_branch']['#default_value'] = $id;
}
}
// Add a submit button.
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Form submission handler for versioncontrol_project_git_default_branch_form().
*/
function versioncontrol_project_git_default_branch_form_submit($form, &$form_state) {
$repo = $form['#repo'];
$default_branch = $repo->loadBranch(NULL, $form_state['values']['default_branch']);
if ($default_branch) {
try {
$repo->setDefaultBranch($default_branch->name);
$form_state['redirect'] = 'node/' . $form['#nid'];
drupal_set_message(t('The default branch has been changed to %branch.', array('%branch' => $default_branch->name)));
}
catch (Exception $e) {
drupal_set_message(filter_xss($e->getMessage()), 'error');
}
}
}
/**
* Compares two branch names.
*
* Callback for uasort() within versioncontrol_project_git_default_branch_form().
*
* @param $a
* The first branch name.
* @param $b
* The secound branch name.
*
* @return
* The inverse of version_compare().
*/
function _versioncontrol_project_git_inverse_version_compare($a, $b) {
return version_compare($b, $a);
}
name = "Version Control / Project issue integration"
description = "Expose some functionality that integrates project_issue and Version Control API."
package = Version Control
dependencies[] = versioncontrol_project
dependencies[] = project_issue
core = 7.x
<?php
/**
* @file
* Version Control / Project issue integration
*/
/**
* Implements hook_schema().
*/
function versioncontrol_project_issue_schema() {
$schema['versioncontrol_project_issue_operations'] = array(
'description' => 'This table associates project issue nodes with versioncontrol operations.',
'fields' => array(
'nid' => array(
'description' => 'Foreign key for the project issue nid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'vc_op_id' => array(
'description' => 'Foreign key for the operation({versioncontrol_operations}.vc_op_id).',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('nid', 'vc_op_id'),
);
return $schema;
}
<?php
/**
* @file
* Version Control / Project issue integration.
*/
/**
* Implements ctools hook_ctools_plugin_directory().
*/
function versioncontrol_project_issue_ctools_plugin_directory($module, $plugin_type) {
if ($module == 'versioncontrol') {
return "plugins/$plugin_type";
}
}
/**
* Implements hook_views_api().
*/
function versioncontrol_project_issue_views_api() {
return array('api' => 3);
}
/**
* Implements hook_node_load().
*/
function versioncontrol_project_issue_node_load($nodes, $types) {
$issue_node_types = project_issue_issue_node_types();
$intersection = array_intersect($issue_node_types, $types);
if (empty($intersection)) {
// Nothing to do.
return;
}
$vc_op_ids_by_nid = versioncontrol_project_issue_get_issue_operation_ids(array_keys($nodes));
if (empty($vc_op_ids_by_nid)) {
// Nothing to load.
return;
}
foreach ($vc_op_ids_by_nid as $nid => $vc_op_ids) {
if ($repository = versioncontrol_project_repository_load($nodes[$nid]->field_project[LANGUAGE_NONE][0]['target_id'])) {
$nodes[$nid]->versioncontrol_project_issue['operations'] = $repository->loadCommits($vc_op_ids);
}
}
}
/**
* Implements hook_node_update().
*
* Change the mappings when a project issue is changed of project.
*/
function versioncontrol_project_issue_node_update($node) {
if (!project_issue_node_type_is_issue($node->type)) {
return;
}
$project_id = $node->field_project[LANGUAGE_NONE][0]['target_id'];
$original_project_id = $node->original->field_project[LANGUAGE_NONE][0]['target_id'];
if ($original_project_id == $project_id) {
// Nothing to do.
return;
}
// Project was changed, remove operation associations with the issue.
db_delete('versioncontrol_project_issue_operations')->condition('nid', $node->nid)->execute();
// @todo Search all operations associated with the new project? (if decided,
// use a queue, since it can be time consuming).
}
/**
* Implements hook_node_delete().
*/
function versioncontrol_project_issue_node_delete($node) {
if (!project_issue_node_is_issue($node)) {
// Nothing to do.
return;
}
// Remove mappings on delete.
db_delete('versioncontrol_project_issue_operations')->condition('nid', $node->nid)->execute();
}
/**
* Implements hook_versioncontrol_entity_commit_delete().
*
* Repository synchronization removes commits, event processor plugins are
* executed later, so we cannot react at that time. So we use this hook to
* remove relations from our table.
*/
function versioncontrol_project_issue_versioncontrol_entity_commit_delete(VersioncontrolOperation $operation) {
db_delete('versioncontrol_project_issue_operations')->condition('vc_op_id', $operation->vc_op_id)->execute();
}
/**
* Implements hook_versioncontrol_repository_bypassing_purge().
*
* @todo db_delete seems to not support joins, is that possible to use for the
* generic case? i.e. no mysql(should be more efficient, in case a lot of
* issues are associated).
*/
function versioncontrol_project_issue_versioncontrol_repository_bypassing_purge(VersioncontrolRepository $repository) {
versioncontrol_project_issue_delete_issue_operation_maps($repository);
}
/**
* Deletes all relared issue/operation associations.
*
* @param int|VersioncontrolRepository $repository
* Repository object or its repo_id.
*/
function versioncontrol_project_issue_delete_issue_operation_maps($repository) {
if (!$repository instanceof VersioncontrolRepository) {
// Should be a repo_id.
$repository = versioncontrol_repository_load($repository);
}
if (empty($repository->project_nid)) {
// No project associated.
return;
}
// Load all associated project issue nids.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', project_issue_issue_node_types())
->fieldCondition('field_project', 'target_id', $repository->project_nid);
$result = $query->execute();
if (empty($result['node'])) {
// No issues associated.
return;
}
// Remove related rows from versioncontrol_project_issue_operations table.
$issue_nids = array_keys($result['node']);
// Do it in chunks of 500 items.
foreach (array_chunk($issue_nids, 500) as $chunk) {
db_delete('versioncontrol_project_issue_operations')->condition('nid', array_values($chunk), 'IN')->execute();
}
}
/**
* Helper to get the operation IDs.
*
* @param array $project_issue_nids
* List of project issue nids.
*
* @return array
* List of operation ids keyed by project issue node id.
*/
function versioncontrol_project_issue_get_issue_operation_ids($project_issue_nids) {
if (empty($project_issue_nids)) {
return array();
}
$vc_op_ids = array();
$result = db_query('SELECT nid, vc_op_id FROM {versioncontrol_project_issue_operations} WHERE nid IN (:nids)', array(':nids' => $project_issue_nids));
foreach ($result as $row) {
$vc_op_ids[$row->nid][] = $row->vc_op_id;
}
return $vc_op_ids;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment