Comments

DjebbZ’s picture

Great idea. I would like it too. But I don't understand the --all argument. How can it create separate files since files are created in the command line (> [view_name].view.php) ?

According to you, should the export from the drush command also produces lines like (I'm not exactly sure of the syntax) :

/**
 * Implements hook_views_default_views().
 */
function [something]_views_default_views([params ?]) {
[export result here]
}
dww’s picture

--all would be instead of printing to stdout and redirecting to a file. In fact, by default it could attempt to create [view_name].view.php in the current directory. If that already exists, it'd prompt you if it should overwrite. And/or you could specify a path for the output as a different arg.

And no, it doesn't need to include a hook_views_default_views() implementation. That'd look something like this:

/**
 * Implement hook_views_default_views().
 */
function project_views_default_views() {
  // Search the "default_views" subdirectory for files ending in .view.php.
  $files = file_scan_directory(drupal_get_path('module', 'project'). '/views/default_views', 'view\.php$');
  foreach ($files as $absolute => $file) {
    // This is not require_once because it's possible that
    // hook_views_default_views() gets called more than once.
    require $absolute;
    if (isset($view)) {
      // $file->name has the ".php" stripped off, but still has the ".view".
      $view_name = substr($file->name, 0, strrpos($file->name, '.'));
      $views[$view_name] = $view;
    }
  }
  return $views;
}

So, any file ending in .view.php in the appropriate directory (up to the module using this) would be considered a default view.

Cheers,
-Derek

greggles’s picture

There is also a separate module - http://drupal.org/project/drush_views

I would personally like for that to be integrated into views itself. Most modules provide their own drush commands rather than having to have a separate module for them (I know Views isn't "most modules").

DjebbZ’s picture

I posted in its issue queue (#1165992: Conflicts with latest Views enhancements) about deprecating drush_views and integrating/adjusting the commands provided into Views.

manuel garcia’s picture

That project has been a year without any activity... shame.

I agree with #2

effulgentsia’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Active » Needs review
StatusFileSize
new8.16 KB

Here's a start at a 'views-export' and a 'views-import' command. It's based on the code in http://drupal.org/project/drush_views (6.x-3.x), with the following changes:

  • Arguments are a space-separated list of view names instead of comma-separated, for consistency with the enable and disable commands already in Views.
  • For export, I renamed --target-path to --destination.
  • For import, I renamed --target-path to --source.
  • There is no default for either --destination or --source. It must be specified.
  • Explicit arguments (view names) are required. There's no default of exporting or importing all views.
  • I changed an assumed file naming convention from [view-name].view to [view-name].view.inc.
  • Miscellaneous code cleanup.
effulgentsia’s picture

Title: Add drush views-export command » Add drush views-export and views-import commands

Marked #1096668: Add drush views-import command (or maybe just views-convert) a duplicate. I think it makes sense to review these together, but if I'm mistaken, please say so, and reopen the other issue.

merlinofchaos’s picture

Since we're powered by CTools, shouldn't we be using CTools import/export drush commands?

effulgentsia’s picture

Do those exist already, or do they need to be written?

merlinofchaos’s picture

some, maybe not all of the ones you wrote.

dawehner’s picture

Currently there is just export: #1385772: Add Drush Bulk export command

manuel garcia’s picture

There's also #1084062: Drush command to revert overridden ctools exported objects which I suppose is the way we should be working in the future.

tim.plunkett’s picture

Triggering the testbot.

Status: Needs review » Needs work

The last submitted patch, views-drush-expimp.patch, failed testing.

pescetti’s picture

For the record, I just made a new version (3.0) of Drush Views available at http://drupal.org/project/drush_views

It includes all improvements that had been proposed to the import/export functionality (like exporting by tag, or by status, exporting to individual .inc files suitable for inclusion by hook_views_default_views(), bulk-exporting to stdout in a format suitable for inclusion in a .module file), as well as several functions that are out of scope in this issue (listing displays in a view, or theme functions applying to a particular display, or copy settings between views).

Feel free to take everything worth including in Views.

As explained in the module page, no further development of Drush Views as an independent module is planned: I agree it's best to move this functionality into Views itself.

merlinofchaos’s picture

If you would like co-maintainership of Views for the purposes of facilitating this transfer, we can probably arrange that.

drzraf’s picture

ctools related, anyway:
This fixes a warning and bad option titles at the "Select exportables." stage (when we chose to only export "some" of the available views, eg using drush ctools-export --tables=views_view then Make selection [2] then Views (views_view) [1].

Before:

Select exportables.
[...]
[11]  :  Object (selected)
[12]  :  Done

After:

Select exportables.
[...]
[11]  :  calendar (selected)
[12]  :  Done
drzraf’s picture

ping ?

manuel garcia’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1096648-fix-views-partial-export-warning.patch, failed testing.

drzraf’s picture

last patch applies cleanly against latest ctools

nagba’s picture

StatusFileSize
new8.23 KB

rerolling http://drupal.org/files/views-drush-expimp.patch so it applies to views 3.6 cleanly

drzraf’s picture

Status: Needs work » Needs review
helmo’s picture

Just tried the patch from #22 on views 7.x-3.7 .. applies and works as expected!

The only thing I notices was a typo in an error message:

+++ b/drush/views.drush.inc
@@ -434,30 +466,157 @@ function drush_views_analyze() {
+    return drush_set_error(dt('Please specify a space delimited list of view names to export.'));

should state 'import'

liza’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

#22 works beautifully in 3.7. could the mods please, please, please commit. thanks!

helmo’s picture

homoludens’s picture

Issue summary: View changes
StatusFileSize
new6.93 KB

Here is patch from #22 rerolled for current dev version.

dawehner’s picture

Doesn't ctools now provide the necessary drush code, so views would not have to add it?

manuel garcia’s picture

Ctools includes ctools-export and ctools-export-revert commands. Not sure if there's a usecase for importing though.

manuel garcia’s picture

Status: Reviewed & tested by the community » Needs work

After consulting my wise pillow, I agree with @dawehner here, ctools-export should do the trick. At the very most we could should just add a wrapper command (as in views-export would call ctools export), to make it easier for users to export views if they don't know what ctools is. We certainly don't want to add more code to maintain if ctools is already providing this.

As for the import command, I don't see myself using it too much, but who knows, perhaps some people could use both to move views around - I'm thinking drush @prod views-export viewname | drush views-import or something like that...

yan’s picture

Patch from #27 works perfectly for me importing and exporting views. Thanks a lot! I spent some time trying to figure this out.

I can't really say anything about ctools.

nileshlohar’s picture

Status: Needs work » Needs review
StatusFileSize
new6.91 KB

Straight reroll with latest dev release.

chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 2 year old patch in #32 to views.drush.inc does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.

Checking patch drush/views.drush.inc...
error: while searching for:
      return dt('Enable the specified views. Follow the command with a space delimited list of view names');
    case 'drush:views-disable':
      return dt('Disable the specified views. Follow the command with a space delimited list of view names');
  }
}

error: patch failed: drush/views.drush.inc:24
error: drush/views.drush.inc: patch does not apply
andrew answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new6.8 KB

Patch rerolled.