function _drush_features_export in Features 7
Same name and namespace in other branches
- 6 features.drush.inc \_drush_features_export()
- 7.2 features.drush.inc \_drush_features_export()
Write a module to the site dir.
Parameters
$requests: An array of the context requested in this export.
$module_name: Optional. The name for the exported module.
2 calls to _drush_features_export()
- drush_features_export in ./
features.drush.inc - Add a component to a features module, or create a new module with the selected components.
- drush_features_update in ./
features.drush.inc - Update an existing feature module.
File
- ./
features.drush.inc, line 519 - Features module drush integration.
Code
function _drush_features_export($stub, $dependencies, $module_name = NULL, $directory = NULL) {
$root = drush_get_option(array(
'r',
'root',
), drush_locate_root());
if ($root) {
$destination = drush_get_option(array(
'destination',
), 'sites/all/modules');
$directory = isset($directory) ? $directory : $destination . '/' . $module_name;
if (is_dir($directory)) {
drush_print(dt('Module appears to already exist in !dir', array(
'!dir' => $directory,
)));
if (!drush_confirm(dt('Do you really want to continue?'))) {
drush_die('Aborting.');
}
}
else {
drush_op('mkdir', $directory);
}
if (is_dir($directory)) {
drupal_flush_all_caches();
module_load_include('inc', 'features', 'features.export');
$export = features_populate($stub, $dependencies, $module_name);
if (!features_load_feature($module_name)) {
$export['name'] = $module_name;
}
// Set the feature version if the --version-set or --version-increment option is passed.
if ($version = drush_get_option(array(
'version-set',
))) {
preg_match('/^(?P<core>\\d+\\.x)-(?P<major>\\d+)\\.(?P<patch>\\d+)-?(?P<extra>\\w+)?$/', $version, $matches);
if (!isset($matches['core'], $matches['major'])) {
drush_die(dt('Please enter a valid version with core and major version number. Example: !example', array(
'!example' => '7.x-1.0',
)));
}
$export['version'] = $version;
}
else {
if ($version = drush_get_option(array(
'version-increment',
))) {
// Determine current version and increment it.
$export_load = features_export_prepare($export, $module_name);
$version = $export_load['version'];
$version_explode = explode('.', $version);
$version_minor = array_pop($version_explode);
// Increment minor version number if numeric or not a dev release.
if (is_numeric($version_minor) || strpos($version_minor, 'dev') !== strlen($version_minor) - 3) {
++$version_minor;
}
array_push($version_explode, $version_minor);
// Rebuild version string.
$version = implode('.', $version_explode);
$export['version'] = $version;
}
}
$files = features_export_render($export, $module_name, TRUE);
foreach ($files as $extension => $file_contents) {
if (!in_array($extension, array(
'module',
'info',
))) {
$extension .= '.inc';
}
drush_op('file_put_contents', "{$directory}/{$module_name}.{$extension}", $file_contents);
}
drush_log(dt("Created module: !module in !directory", array(
'!module' => $module_name,
'!directory' => $directory,
)), 'ok');
}
else {
drush_die(dt('Couldn\'t create directory !directory', array(
'!directory' => $directory,
)));
}
}
else {
drush_die(dt('Couldn\'t locate site root'));
}
}