-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatures_cleanup.drush.inc
More file actions
executable file
·100 lines (92 loc) · 3.47 KB
/
Copy pathfeatures_cleanup.drush.inc
File metadata and controls
executable file
·100 lines (92 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @file
* Features module drush integration.
*/
/**
* Implements hook_drush_command().
*
* @see drush_parse_command()
* for a list of recognized keys.
*/
function features_cleanup_drush_command() {
$items = array();
$items['features-cleanup-feature'] = array(
'description' => "Attempts to resolve all overrides on a single feature module.",
'arguments' => array(
'feature' => 'The a space-delimited list of features.',
),
'drupal dependencies' => array('features', 'diff', 'features_cleanup'),
'aliases' => array('fcf'),
);
$items['features-cleanup-all'] = array(
'description' => "Cleans out all content types, panel pages, mini panels, vocabularies, and image styles from database based on existing enabled features.",
'drupal dependencies' => array('features', 'diff', 'features_cleanup'),
'aliases' => array('fca'),
);
return $items;
}
/**
* Implements hook_drush_help().
*/
function features_cleanup_drush_help($section) {
switch ($section) {
case 'drush:features-cleanup-feature':
return dt("Attempts to resolve all overrides by removing fields from the database. Requires 1 argument: feature name. For example drush features-cleanup-feature views_feature will attempt to resolve all field overrides for the feature named views_feature.");
case 'drush:features-cleanup-all':
return dt("Cleans out all content types, panel pages, mini panels, vocabularies, and image styles from database based on existing enabled features.");
}
}
/**
* For specified feature modules and resolve all overrides.
*/
function drush_features_cleanup_feature() {
if ($args = func_get_args()) {
drush_print(dt('Fields that are not in the feature - but attached to a content type in the given feature - will PERMANENTLY be deleted: !modules', array('!modules' => implode(', ', $args))));
if (drush_confirm(dt('Do you really want to continue?'))) {
foreach ($args as $module_name) {
if (!module_exists($module_name)) {
drush_log(dt('The !module_name feature does not exist!', array('!module_name' => $module_name)), 'error');
continue;
}
module_load_include('inc', 'features', 'features.export');
$feature = features_get_features($module_name);
try {
features_cleanup_override_perform($feature);
drush_invoke_process('@self', 'features-revert', array($module_name));
drush_print(dt('The !module_name feature was successfully cleaned and reverted.', array('!module_name' => $module_name)));
}
catch (Exception $e) {
watchdog_exception('features_cleanup', $e);
drush_die($e);
}
}
}
else {
drush_die('Aborting.');
}
}
else {
drush_die('Please specify a feature to resolve overrides.');
}
}
/**
* Get a list of all feature modules and resolve all overrides.
*/
function drush_features_cleanup_all() {
drush_print(dt('Running this command will delete content types, panel pages, mini panels, image styles, and vocabularies based on existing ENABLED features. Please enable all desired features before running this command.'));
if (drush_confirm(dt('Do you really want to continue?'))) {
try {
if (features_cleanup_perform()) {
drush_print(dt('All extraneous database components successfully cleaned.'));
}
}
catch (Exception $e) {
watchdog_exception('features_cleanup', $e);
drush_die($e);
}
}
else {
drush_die('Aborting.');
}
}