Projet

Général

Profil

Paste
Télécharger (5,25 ko) Statistiques
| Branche: | Révision:

root / .drush / drush_make / drush_make.generate.inc @ 0ef18d70

1
<?php
2
// $Id: drush_make.generate.inc,v 1.1.2.10 2010/09/03 02:58:49 dmitrig01 Exp $
3

    
4
include_once 'includes/install.inc';
5
include_once drupal_get_path('module', 'system') . '/system.install';
6

    
7
/**
8
 * Drush callback; generate makefile from the current build.
9
 */
10
function _drush_generate_makefile($file) {
11
  $projects = array();
12

    
13
  $system_requirements = system_requirements('runtime');
14
  $core_project = strtolower($system_requirements['drupal']['title']); 
15
  $projects[$core_project] = array('_type' => 'core');
16
  if ($core_project != 'drupal') {
17
    $projects[$core_project]['custom_download'] = TRUE;
18
    $projects[$core_project]['type'] = 'core';
19
  }
20

    
21
  // Non-default profiles section.
22
  $install_profile = variable_get('install_profile', '');
23
  if ($install_profile != 'default' && $install_profile != '') {
24
    $projects[$install_profile]['type'] =
25
    $projects[$install_profile]['_type'] = 'profile';
26
    if (_drush_generate_makefile_updatexml($install_profile, 'profile')) {
27
      $projects[$install_profile]['custom_download'] = TRUE;
28
    }
29
  }
30

    
31
  // Re-build theme and module data to be sure we have the most current information.
32
  $project_info = drush_get_projects();
33
  foreach ($project_info as $item) {
34
    $name = $item->name;
35
    $type = $item->type;
36
    if ($item->info['project'] != 'drupal' && $item->info['project'] == $name) {
37
      if (($item->type == 'module') && (!$item->status)) {
38
        continue;
39
      }
40
      $updatexml = _drush_generate_makefile_updatexml($name, $type, $item->info);
41
      $projects[$name] = array('_type' => $type);
42
      if ($updatexml) {
43
        $projects[$name]['type'] = $type;
44
        $projects[$name]['custom_download'] = TRUE;
45
      }
46
      $projects[$name] += _drush_generate_makefile_check_location($name, $type);
47
    }
48
  }
49

    
50
  if (function_exists('libraries_get_libraries')) {
51
    $libraries = libraries_get_libraries();
52
    foreach ($libraries as $library_name => $library_path) {
53
      $path = explode('/', $library_path);
54
      $projects[$library_name] = array(
55
        'directory_name' => $path[(count($path) - 1)],
56
        'custom_download' => TRUE,
57
        'type' => 'library',
58
        '_type' => 'librarie', // For plural.
59
      );
60
    }
61
  }
62

    
63
  $contents = _drush_make_generate_makefile_contents($projects);
64
  if (file_put_contents($file, $contents)) {
65
    drush_log(dt("Wrote .make file %file", array('%file' => $file)), 'ok');
66
  }
67
  else {
68
    drush_make_error('FILE_ERROR', dt("Unable to write .make file %file", array('%file' => $file)));
69
  }
70
}
71

    
72
/**
73
 * Helper function to check if a detected project lives on drupal.org or not.
74
 */
75
function _drush_generate_makefile_updatexml($name, $type, $info = array()) {
76
  // First we set up the project information array.
77
  $project = array(
78
    'name' => $name,
79
    'location' => (isset($info['location']) ? $info['location'] : drush_get_option('drush-make-update-default-url')),
80
    'core' => DRUPAL_CORE_COMPATIBILITY,
81
    'version' => DRUSH_MAKE_VERSION_BEST,
82
  );
83

    
84
  // Now we get the project information.
85
  $update_check = drush_make_updatexml($project, NULL);
86
  return $update_check === TRUE && $type == $update_check['type'];
87
}
88

    
89
/**
90
 * Helper function to check for a non-default installation location.
91
 */
92
function _drush_generate_makefile_check_location($name, $type) {
93
  // Check for non-default installation location.
94
  $path = drupal_get_path($type, $name);
95
  $default_location = 'sites/all/' . $type . 's';
96
  $info = array();
97
  if ($path != $default_location . '/' . $name) {
98
    if (substr($path, 0, strlen($default_location)) != $default_location) {
99
      $info['contrib_destination'] = $path;
100
    }
101
    else {
102
      // If it's in a subdir of sites/all/modules, set the subdir.
103
      $subdir = preg_replace(array('@^sites/all/' . $type . 's/@', "@/$name" . '$@'), '', $path);
104
      $info['subdir'] = $subdir;
105
    }
106
  }
107
  return $info;
108
}
109

    
110
function _drush_make_generate_makefile_contents($projects) {
111
  $output = array();
112
  $custom = FALSE;
113
  $output[] = '; This file was auto-generated by drush_make';
114
  $output['core'] = DRUPAL_CORE_COMPATIBILITY;
115
  $output[] = '';
116
  $previous_type = 'core';
117
  foreach ($projects as $name => $project) {
118
    $type = ($project['type'] == 'library' ? 'libraries' : 'projects');
119
    if ($previous_type != $project['_type']) {
120
      $previous_type = $project['_type'];
121
      $output[] = '; ' . ucfirst($previous_type) . 's';
122
    }
123
    unset($project['_type']);
124
    if (!$project && is_string($name)) {
125
      $output[] = $type . '[] = "' . $name . '"';
126
      continue;
127
    }
128
    $base = $type . '[' . $name . ']';
129
    if (isset($project['custom_download'])) {
130
      $custom = TRUE;
131
      $output[] = '; Please fill the following out.';
132
      $output[$base . '[download][type]'] = '""; One of get, cvs, git, bzr or svn';
133
      $output[$base . '[download][url]'] = '""; The url of the download';
134
      unset($project['custom_download']);
135
    }
136
    foreach ($project as $key => $value) {
137
      $output[$base . '[' . $key . ']'] = '"' . $value . '"';
138
    }
139
    $output[] = '';
140
  }
141
  $string = '';
142
  foreach ($output as $k => $v) {
143
    if (!is_numeric($k)) {
144
      $string .= $k . ' = ' . $v;
145
    }
146
    else {
147
      $string .= $v;
148
    }
149
    $string .= "\n";
150
  }
151
  if ($custom) {
152
    drush_log(dt('Some of the properties in your makefile will have to be manually edited. Please do that now.'), 'error');
153
  }
154
  return $string;
155
}