GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 7.x-1.x ( 34e25a...94dab8 )
by Devin
03:48
created

modules/df/df_admin/df_admin.enable.inc::df_admin_enable_scenario()   C

Complexity

Conditions 8
Paths 21

Size

Total Lines 47
Code Lines 22

Duplication

Lines 8
Ratio 17.02 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 8
eloc 22
c 1
b 0
f 1
nc 21
nop 1
dl 8
loc 47
rs 5.7377
1
<?php
2
3
/**
4
 * @file
5
 * DF Admin scenario handling functions.
6
 */
7
8
/**
9
 * Page callback; enable a scenario.
10
 */
11
function df_admin_page_enable($module) {
12 View Code Duplication
  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], DRUPAL_ROOT . '/df/enable/' . $module)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    return drupal_access_denied();
14
  }
15
  return df_admin_enable_scenario($module);
16
}
17
18
/**
19
 * Function to enable a scenario.
20
 */
21
function df_admin_enable_scenario($module) {
22
  // If the scenario is already enabled, exit.
23 View Code Duplication
  if (module_exists($module)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    drupal_set_message(t('Scenario @module is already installed.', array('@module' => $module)), 'status');
25
    return FALSE;
26
  }
27
28
  // Check if it appears another scenario is installed.
29
  if (variable_get('df_admin_installed_scenario', FALSE)) {
30
    // Uninstall currently installed scenario, if any is installed.
31
    module_load_include('inc', 'df_admin', 'df_admin.uninstall');
32
    // Passing "$module" tells the uninstall batch to redirect back here when it's finished.
33
    df_admin_uninstall_scenario($module);
34
  }
35
36
  // Load info file to grab dependencies.
37 View Code Duplication
  if (!$info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    drupal_set_message(t('Unable to load Scenario .info file'), 'error');
39
    return FALSE;
40
  }
41
42
  // Enable the scenario feature's DF dependencies.
43
  foreach ($info['dependencies'] as $dependency) {
44
    if (substr($dependency, 0, 2) == 'df_') {
45
      _df_admin_enable_feature($dependency);
46
    }
47
  }
48
49
  // Enable the scenario feature.
50
  if (!_df_admin_enable_feature($module)) {
51
    drupal_set_message(t('Enablement of @module failed.', array('@module' => $module)), 'error');
52
    return FALSE;
53
  }
54
55
  // Change the system variable that tracks what scenario is installed.
56
  variable_set('df_admin_installed_scenario', $module);
57
58
  // Not all DFS require a batch content import, but some need this.
59
  // Resolves to the DF admin page if no reset callback present.
60
  if (!drupal_is_cli()) {
61
    $path = 'admin/df/reset/' . $module;
62
    $token = drupal_get_token(DRUPAL_ROOT . '/df/reset/' . $module);
63
    drupal_goto($path, array('query' => array('token' => $token)));
64
  }
65
66
  return TRUE;
67
}
68
69
/**
70
 * Helper function to enable a Feature properly.
71
 */
72
function _df_admin_enable_feature($module) {
73
  // Enable a disabled Features module.
74
  if (!module_exists($module)) {
75
    if (module_enable(array($module))) {
76
      watchdog('demo framework', 'Enabled module: ' . $module);
77
      drupal_set_message(t('@module enabled.', array('@module' => $module)), 'status');
78
      return TRUE;
79
    }
80
    else {
81
      drupal_set_message(t('@module does not exist or dependencies are missing.', array('@module' => $module)), 'error');
82
      return FALSE;
83
    }
84
  }
85
  drupal_set_message(t('@module is already enabled.', array('@module' => $module)), 'warning');
86
  return FALSE;
87
}
88