function drush_patterns_export in Patterns 7
Same name and namespace in other branches
- 7.2 patterns.drush.inc \drush_patterns_export()
Export data from the patterns components to file, zip archive, or database
File
- ./
patterns.drush.inc, line 412 - Drush Patterns module commands
Code
function drush_patterns_export() {
drush_print(dt('Patterns export.'));
if (!patterns_utils_is_module_enabled('patterns_export')) {
drush_set_error(dt('Please enable module patterns_export first'));
return FALSE;
}
$args = func_get_args();
if (empty($args)) {
return drush_set_error(dt('You must specify the export mode and the output file'));
}
$mode = array_shift($args);
if (!patterns_export_is_valid_mode($mode)) {
$modes_string = '[' . PATTERNS_EXPORT_TO_DB;
$modes_string .= '|' . PATTERNS_EXPORT_TO_FILE;
$modes_string .= '|' . PATTERNS_EXPORT_TO_ZIP . ']';
return drush_set_error(dt('You must specify a valid export mode: ' . $modes_string));
}
// out file
$out = array_shift($args);
$format = PATTERNS_FORMAT_UNKNOWN;
if ($mode === PATTERNS_EXPORT_TO_ZIP) {
if (!class_exists('ZipArchive')) {
drush_set_error(dt('Zip extension not found.'));
return FALSE;
}
$format = patterns_io_get_format_from_file(NULL, array_shift($args));
if (!$format) {
return drush_set_error(dt('You must specify the format when exporting to Zip archive.'));
}
}
$format = patterns_io_get_format_from_file($out, $format);
if (!$format) {
return FALSE;
}
patterns_io_load_components(TRUE);
if (empty($args)) {
drush_print(dt('Exporting all components'));
$exports = patterns_moduletags_get_index(NULL, TRUE, TRUE);
}
else {
$exports = patterns_drush_filter_components($args);
}
$result = patterns_export_start_engine($out, $exports, $info, $mode, $format, 'php');
if (!$result) {
drush_set_error(dt('An error occurred while exporting. Export may have failed.'));
}
else {
drush_print(dt('Patterns exported successfully'));
}
//drush_print(print_r($export_functions, true));
}