Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonhattan’s picture

FYI: here's an implementation for node-delete: http://elnoti.xsto.info/~jonhattan/node.drush.inc

and also I leveraged node overview filters (what is at admin/content/node in d6) at http://drupal.org/node/766930#comment-3451732 .. it wasn't shipped in that issue's commit.

msonnabaum’s picture

FileSize
4.49 KB

Awesome. New patch adds the node-delete command from the above comment, plus a node-create command.

Seems to have trouble with date fields so far, but it seems to be working otherwise.

moshe weitzman’s picture

I'd like for us to polish this and commit to Drush5.

greg.1.anderson’s picture

Status: Active » Needs work

Adjusting status...

msonnabaum’s picture

FileSize
5.79 KB

Here's a new version that adds a couple things:

- node-create works with editors now if you don't use STDIN
- node-create and node-edit loosely tested on D7
- Now uses drush_json_encode/decode functions which helps with D7 computability

kotnik’s picture

One really minor thing:

+++ commands/node/node.drush.inc
@@ -0,0 +1,212 @@
+  );  ¶

You've got trailing whitespace here.

Powered by Dreditor.

kotnik’s picture

+++ commands/node/node.drush.inc
@@ -0,0 +1,212 @@
+    foreach ($nids as $nid) {
+      $node = node_load($nid, NULL, TRUE);
+      db_query('DELETE FROM {node} WHERE nid = %d', $nid);
+      db_query('DELETE FROM {node_revisions} WHERE nid = %d', $nid);
+      node_invoke($node, 'delete');
+      node_invoke_nodeapi($node, 'delete');
+      if (function_exists('search_wipe')) {
+        search_wipe($node->nid, 'node');
+      }
+    }
+    cache_clear_all();
+  }

Couldn't you use just:

node_delete($nid);

Instead of copying it into Drush?

Powered by Dreditor.

jonhattan’s picture

node-delete is implemented this way to prevent calling cache_clear_all() for each node.

kotnik’s picture

@jonhattan: makes sense.

msonnabaum’s picture

Here's what I showed at drupalcon.

Starting to move it over to use entities instead of nodes. The only command that I worked on was edit, the rest are still node specific.

moshe weitzman’s picture

Not sure it is needed, but probably wise to assure that temp file gets escapeshellarg(). Something like drush_shell_exec_interactive('$EDITOR %s', $tmpfile);

Mark's demo of these commands at Drupalcon was a big hit. See last 20 mins of our presentation at http://chicago2011.drupal.org/sessions/advanced-drush

moshe weitzman’s picture

Not sure it is needed, but probably wise to assure that temp file gets escapeshellarg(). Something like drush_shell_exec_interactive('$EDITOR %s', $tmpfile);

Mark's demo of these commands at Drupalcon was a big hit. See last 20 mins of our presentation at http://chicago2011.drupal.org/sessions/advanced-drush

moshe weitzman’s picture

Took another look at this. Items to fix up. For testing, the built-in article page type is pretty good. It has body and tags Fields on it.

  1. Convert fully to entity from node
  2. Somehow add line breaks to files that open in the editor. Is there a character that acts like linebreak that we can use and strip out before json_decode()?
  3. entity-create from scratch is needs some help. We probably should add each Field to the array with empty value. For more points, add with default value. I fear though that this goes down the road of re-implementing devel's generate-content.
clemens.tolboom’s picture

+++ commands/entity/entity.drush.inc
@@ -0,0 +1,259 @@
+ * @file
+ *   Drush support for nodes.

This should work for nodes only?

+++ commands/entity/entity.drush.inc
@@ -0,0 +1,259 @@
+    'aliases' => array('ns'),

A weird alias: entity-show versus ns ... I would suggest ens

+++ commands/entity/entity.drush.inc
@@ -0,0 +1,259 @@
+    foreach ($nids as $nid) {
+      $node = node_load($nid, NULL, TRUE);

Add comment about not using node_delete($nid) for D5/6

thimothoeye’s picture

subscribe

moshe weitzman’s picture

Priority: Normal » Major

Anyone available to push this along?

helmo’s picture

I've coded the comment from clemens.tolboom into a branch of my drush sandbox on top of the patch from #10
To better work together I've granted vcs push privileges to clemens.tolboom.

My sandbox branch: http://drupalcode.org/sandbox/helmo/1277350.git/shortlog/refs/heads/mast...

clemens.tolboom’s picture

The commands are not consistent enough:

- entity-show(nids)

- entity-create()

- entity-edit(type, nids)

- entity-delete( nid)

as for D7 we require a type so helmo and clemens suggest to make type required.

For D6 the type is required but only implemented for nodes. At least for now.

So the commands become

- entity-show node 12
- entity-create comment
- entity-edit taxonomy 123
- entity-delete user 12

At least that's the idea for now :)

clemens.tolboom’s picture

My (D7) setup

drush --yes site-install
drush --yes dl devel
drush --yes en devel_generate
drush genc 10 10
drush vocabs 2
drush gent tags 50

The following commands then function (all D7)

drush entity-list
drush entity-show node 1
drush entity-show taxonomy_vocabulary 1
drush entity-show taxonomy_term 1

I'm puzzled with the save flow. This works sometimes :(

drush entity-edit node 1
clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom

[Note: this is output from drush_helmo sandbox]

I'm not sure how to pipe the output to the next drush command.

This example: print entity ids from all available entities drush entity-list | drush enity-list should do the job. Instead I need to run drush el `drush el`.

# removed drush 'trivial' log
drush --verbose @drupal.d7 el `drush @drupal.d7 el`
Available ids for comment                                     [notice]
  1 2 3 4 5 6 7 8 9 10 13 15 16 19 22 23 24 25 26 28 29 11 12 14 17 18 20 21 27
Available ids for node                                        [notice]
  1 2 3 4 5 6 7 8 9 10 12 13 14
Available ids for file                                        [notice]
  1 2 3 4 5 6 7 8
Available ids for taxonomy_term                               [notice]
Undefined index: taxonomy_term entity.drush.inc:115           [notice]
array_keys() expects parameter 1 to be array, null given entity.drush.inc:115   [warning]
join(): Invalid arguments passed entity.drush.inc:115      [warning]
  
Available ids for taxonomy_vocabulary                         [notice]
  1
Available ids for user                                        [notice]
  0 2 3 4 1
helmo’s picture

Status: Needs work » Needs review
FileSize
16.56 KB

After a lot of work and refactoring of clemens.tolboom and myself in the sandbox branch we feel that this is ready for review.

It includes a testcase with 10 assertions that tests the support for working with node entities in D7.

clemens.tolboom’s picture

entity-delete only works on node.

The sandbox http://drupalcode.org/sandbox/helmo/1277350.git/shortlog/refs/heads/mast... is updated.

clemens.tolboom’s picture

Issue summary: View changes

Update to latest implementation.

clemens.tolboom’s picture

If fixed the entity delete. It works now for D7.

There is a warning when deleting entities ... not sure what/why?

array_flip(): Can only flip STRING and INTEGER values! entity.inc:178

This is what I did.

drush site-install --yes

# What is created during install
drush el `drush el`

drush --yes dl devel
drush --yes en devel_generate

drush gent tags 20
drush genc 20 5
drush genu 20 

drush el `drush el`

# Delete some comments
drush el comment
drush ed comment 26 20

# Try delete some files ... no force delete
drush el 'drush el`
drush el file
drush ed file 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
drush el file

drush el comment
drush ed comment 1 2 3 7 9 10 12 13 14 15 16 18 19 23 24 25 27 28 29 4 5 6 8 11 17

drush el `drush el`
drush ed taxonomy_term 9 8 17 4 6 12 3 7 18 10 13 1 16 11 15 5 19 20 14 2

drush el `drush el`
drush ed user 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

drush el `drush el`
drush ed node 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

drush el `drush el`
drush ed taxonomy_vocabulary tags
helmo’s picture

Fixed the array_flip() warning in git, phpunit now runs OK without warnings.

helmo’s picture

Issue summary: View changes

Added sandbox link and rephrased what works.

clemens.tolboom’s picture

Issue summary: View changes

Added h4 testcase section.

clemens.tolboom’s picture

Issue summary: View changes

Added some todos

helmo’s picture

Issue summary: View changes

Added list of current testcases

clemens.tolboom’s picture

Issue summary: View changes

Added link to sandbox issues.

clemens.tolboom’s picture

Title: Drush node support » Drush entity support

We could use some feedback on our sandbox.

helmo’s picture

Here is a patchfile of the sandbox progress.
All tests are passing!

helmo’s picture

Issue summary: View changes

Update proposed solution to current state

clemens.tolboom’s picture

Status: Needs review » Needs work
+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+ */
+function _drush_entity_type_read_list() {
+

Empty function

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+/**
+ *
+ * @param type $entity_type
+ */
+function _drush_entity_read_list($entity_type) {

Missing documentation

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+
+//  if (!drush_get_option('json')) {
+//    drush_die("You must specify --json");
+//  }
+

Remove this code.

Or should we require the --json?

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+// TODO this should be similar as drush_entity_save
+function _drush_entity_load($entity_type, $ids) {

No function documentation.

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+/**
+ * Permanently save an entity - Mostly stolen from entity api.
+ *
+ * In case of failures, an exception is thrown.

This documentation is not current. Code is moved into _drush_entity_op

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+    // D7 operator rename
+    $op_alias = 'deletion';
+    // D6 user_delete requires two arguments

These fixes need more documentation ... especially when adding D8

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+function _drush_entity_delete($entity_type, $ids = array()) {

No function docs

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+function _drush_entity_delete_node($nids) {

No docs.

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+/**
+ * Wrapper for entity_info()
+ *
+ * We wrap entity_info to make D5/6 compatible

Please document the D6 array structure.

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+      // What keys to delete on create
+      $entities_info['node']['drush']['new'] = array('nid', 'vid');
+      $entities_info['user']['drush']['new'] = array('uid');
+      $entities_info['file']['drush']['new'] = array('fid');

Are these settings not derivable from entity_info?

And please check devel_generate.

+++ b/commands/entity/entity.drush.inc
@@ -0,0 +1,767 @@
+      $entities_info['node']['drush']['defaults']['type'] = '';
+      $entities_info['node']['drush']['defaults']['title'] = '';
+      $entities_info['node']['drush']['defaults']['language'] = 'und';

This construct misses for all other (and new) entity types.

Can't we derive default values from somewhere ... field_info_* and friends?

See drush field* commands?

clemens.tolboom’s picture

Issue summary: View changes

Update list of tests and options

clemens.tolboom’s picture

Status: Needs work » Needs review
FileSize
36.86 KB

Patch has some of the comments above.

I'm unsure whether out entity-create workflow is satisfying enough ... we still haven't dive into #13 (devel generate)

I like --fields=**/label which extract all label keys.

clemens.tolboom’s picture

While creating a video I noticed (a forgotten) bug multiple value fields are indexed ... [0] seems to get ignored.

clemens.tolboom’s picture

Issue summary: View changes

Fixed original user.

clemens.tolboom’s picture

Issue summary: View changes

Added link to video.

helmo’s picture

Issue summary: View changes

Updated issue summary. Added link to gitweb diff

clemens.tolboom’s picture

Issue summary: View changes

Reordered some links and added links to video transcript of commands

clemens.tolboom’s picture

The latest patch (it's getting bigger)

Some remarks upfront:
- yaml conversion should be place into a drush-lib
- filter_fields should be made available into a drush-lib too.
Both are awesome to analyse data spit out by any drush command ie views

There are still unanswered questioned and tests reported in the issue summary. Feel free to answer these without reviewing the patch. We _need_ some answers :)

moshe weitzman’s picture

Perhaps msonnabaum can review this, as the original author of this feature. For me, the proposed implementation is a bit too feature rich for core drush.

clemens.tolboom’s picture

@moshe weitzman please specify this 'too feature rich' a little for us as you spend some time reviewing this :_)

msonnabaum’s picture

Status: Needs review » Needs work

I need to dig into this a bit further, but here are some initial comments.

+++ b/commands/entity/entity.drush.incundefined
@@ -0,0 +1,944 @@
+define('DRUSH_ENTITY_SEPARATED_SPACE', 'space-separated');

What is this? Why is it necessary?

+++ b/commands/entity/entity.drush.incundefined
@@ -0,0 +1,944 @@
+  $items['entity-read'] = array(

I don't like the change from "show" change to "read"? I'm ok with arguments against "show", but CRUD is not that intuitive here. Same thing with "update", I'd rather it be "edit".

+++ b/commands/entity/entity.drush.incundefined
@@ -0,0 +1,944 @@
+/**
+ * Filter on the given paths
+ *
+ * Each path may contain forward slashes / to filter subtrees
+ *
+ * A path may contain a star * or ** to wildcard a path
+ *
+ * Example paths (ignore space after *)
+ * - schema_fields_sql
+ * - bundles/* /label
+ * - ** /display
+ *
+ * @param array $value
+ * @param array $paths
+ *   List of paths to filter about.
+ * @return array
+ *   The matching path
+ */
+function _drush_entity_filter_fields(array $value, array $paths, array $delete_path = array()) {

This function makes me sad. The comment sort of says what it does, but not why it's necessary. Also, it's very long and hard to follow. The comments make no sense to me.

+++ b/commands/entity/entity.drush.incundefined
@@ -0,0 +1,944 @@
+    drush_die("You must specify an entity_type");

Use drush_set_error instead of drush_die, and wrap these strings with dt(). Also, for the longer callbacks you should use the _validate hook for validation.

In general, most all of it needs more comments that say "why" and not "what".

Also, remove the YAML stuff. It's not necessary. The --json option should change to --format like cache-get, and it should support the same output formats.

barraponto’s picture

I wouldn't say yaml is not necessary. Instead it might be contributed in a separate patch that takes php objects and turns them into yaml — and we could use it in most of drush commands.

clemens.tolboom’s picture

@barraponto thanks for the feedback :-)

I still have to dive into the --format

As I hope was clear from my video the yaml output is great for learning the internals so this should be a separate patch #1366098: Automatically download Symfony YAML component.

greg.1.anderson’s picture

The variable-set and variable-get commands parse and print different data formats. That code should be factored out and re-used here, so yaml and other enhancements deemed necessary will be usable in a consistent fashion across the different drush commands where they are relevant.

clemens.tolboom’s picture

@greg.1.anderson thanks for the hints.

What this means for this issue is I have to build out the yaml output (and probably more output stuff) as #34 first mentioned the --format switch.

I'm puzzled about the --fields ... it is so darn handy too for querying the entity system. My guess now is it should be in a separate issue. Not sure right now ... need some chewing on it :(

damiankloip’s picture

I have a small extension I wrote recently (couldn't find it mentioned in this issue) for 'entity-list'. Does what you expect really; provides a table of entities with a count, bundles, base table, etc... This has been useful for me. Is it wanted here? and worth providing a patch for?

clemens.tolboom’s picture

@damiankloip sounds like a nice extension but not sure how much overlap there is.

We do not have counts so that sound like a nice addition. The output (and workflow) of

drush entity-read node | wc -w
   16

is ugly. I'm curious about your output :)

We do have the entity-type-read command which provides for the info (bundle, base table, etc) but presentation has it's value too. I'm not sure whether the example below works right now
drush --format=table entity-type-read user node file --fields="*/bundle,*/base table"
but this should be possible when format related issues like #1366098: Automatically download Symfony YAML component and/or #1396178: Add properties output as a --format get fixed together with the table format.

Ie drush entity-type-read node file user --fields="base table,bundles" --format=properties gives

file.base table = file_managed
file.bundles.audio.label = Audio
file.bundles.audio.admin.path = admin/config/media/file-types/manage/%file_type
file.bundles.audio.admin.real path = admin/config/media/file-types/manage/audio
file.bundles.audio.admin.bundle argument = 5

When patching make sure to use the git sandbox http://drupalcode.org/sandbox/helmo/1277350.git/shortlog/refs/heads/mast...

Helmo and I discussed whether move this patch into a separate project so people can install it easiers. What do you think?

I planned to work on this issue again when building a web spider on top of it. That is trying to clone a website though drush-entity :)

damiankloip’s picture

@clemens.tolboom I was thinking something simpler (although I like aspects of the above implementation) like views-list does. So an entity-list command that shows alot of this info, including counts, as a table. I didn't realise about the other thread to add a --format option for the output. I was thinking it would be nice to have commands that are easier to use/type too.

Ha, clone website with drush entity :)

clemens.tolboom’s picture

@damiankloip please provide an example output (or patch :p) ... I did not know views-list so tnx :)

damiankloip’s picture

@clemens.tolboom No problem. Currently it is in it's own module. I will post this for you to see. I think this is the easiesy way for you to see what it does. If we need to we can then make a patch for the appropriate file?

damiankloip’s picture

FileSize
1.37 KB

Here is a small module showing a similar implementation to views-list functionality. I think one of the main benefits is the ease of the command; Just "drush el" or "drush el user,node" for example rather than the current more verbose proposal. I think maybe both have their place?

Let me know what you think!

clemens.tolboom’s picture

@damiankloip tnx for the code.

drush entity-list node,file
Entity count: 2

 Entiteit  Label    Bundles                        Base table    Revision table  Aantal  Fieldable  Entity class  Controller class              
 node      Node     Article (article), Basic page  node          node_revision   2       TRUE       Standaard     NodeController                
                    (page), Hammer (hammer)                                                                                                     
 file      Bestand  Bestand (file)                 file_managed  NULL            2       FALSE      Standaard     DrupalDefaultEntityController
damiankloip’s picture

@clemens.tolboom: Dodgy formatting but yes that is the idea :)

damiankloip’s picture

Issue summary: View changes

Pushed #27 into issue summary
Linked to #1330504: Test the File entity

clemens.tolboom’s picture

Status: Needs work » Postponed

We moved our code to http://drupal.org/project/drush_entity to have better issue management, easy download for interested people and more developers.

Current developers now @helmo @damiankloip @clemens.tolboom ... feel free to join.

I mark this issue postponed (hope it will not hide on the issue overview).

greg.1.anderson’s picture

Title: Drush entity support » Create a new project to develop Drush entity support
Category: feature » task
Status: Postponed » Fixed

I put a pointer to drush_entity on the Resources page of drush.org. If we bring drush_entity back to core, we can do it via another issue.

clemens.tolboom’s picture

@greg.1.anderson tnx

clemens.tolboom’s picture

Issue summary: View changes

Added link to project page.

clemens.tolboom’s picture

Issue summary: View changes

Updated issue summary.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.