Introduction

This module is meant for individual field data manipulation from commandline to add, delete or modify values in fields. It uses Drush commandline interface. Aim is to be able add, delete, modify and list data in all core field types and most contributed field types.

I'm not aware of any similar projects.

I have 20 years of programming experience and 5 year with Drupal and have one active community site. I have built dozens Drupal sites and dozens modules for my own use.

Examples:

Add a file to a file field:
drush fields-file-add node 1 field_myfilefield --file=/tmp/icon-flag.pdf

Delete an element from file field:
drush fields-file-del node 1 field_myfilefield 1

Project page:
https://drupal.org/sandbox/ragnarkurm/2274189

Direct git repository:

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/ragnarkurm/2274189.git drush_fields
cd drush_fields

PAReview
http://pareview.sh/pareview/httpgitdrupalorgsandboxragnarkurm2274189git
Note that it gives false positives Variable $xxx is undefined. since it cannot understand extract().

Reviews of other projects

  1. https://drupal.org/node/2273577#comment-8857027
  2. https://drupal.org/node/2176689#comment-8853441
  3. https://drupal.org/node/2208357#comment-8852765
CommentFileSizeAuthor
#14 pareview_results.txt13.61 KBmpdonadio

Comments

ragnarkurm’s picture

Issue summary: View changes
ragnarkurm’s picture

Issue summary: View changes
PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

ragnarkurm’s picture

Issue summary: View changes
Issue tags: +PAreview: review bonus
dbcollies’s picture

Status: Needs review » Needs work

In the files in drush/fields, I believe that you should be wrapping the argument help text in calls to dt().

Otherwise, looks really good to me.

ragnarkurm’s picture

Status: Needs work » Needs review

I believe that ...

Belief or fact?

Can you be more specific, where?

If you mean content of extensions of hook_drush_command(), namely drush_fields_file_cmd() and drush_fields_node_title_cmd() then it has to be untranslated. You can check from drush installation that drush itself has hook_drupal_command() untranslated. For example in: drush/commands/core/archive.drush.inc. If you have any source to quote or reference for translating hook_drush_command() then it would be helpful.

The reason is that drush caches command info and if it caches translated stuff and then drush command results gets funny (mixed language). Sometimes when you install a module and all its strings get into database in translated form and later no matter what, you cannot get admin interface into English anymore.

If there is any other string you see untranslated, then please point out. As I live in non-English environment I always write translatable code. So I have been quite careful making all possible strings translatable. The only exception in this code is hook_drush_command() extension functions.

So currently there is nothing to do about the translations.

mpdonadio’s picture

For reference, total disregard for using t() and dt() is a blocking issue (falls under the Major API issue category). A few missing strings when good faith has been made to catch them should be pointed out, but does not warrant going back to Needs Work.

dbcollies’s picture

Status: Needs review » Reviewed & tested by the community

Given the followup comments, I rescind my earlier objection, and, rather than pushing this to the bottom of the queue for my mistake, I'll go ahead and mark it as RTBC.

ragnarkurm’s picture

Issue summary: View changes
mpdonadio’s picture

Issue summary: View changes

Updated git link to public one.

mpdonadio’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
Duplication
This sounds like a feature that should live in the existing Drush Entity project. Module duplication and fragmentation is a huge problem on drupal.org and we prefer collaboration over competition. Please open an issue in the Drush Entity issue queue to discuss what you need. You should also get in contact with the maintainer(s) to offer your help to move the project forward. If you cannot reach the maintainer(s) please follow the abandoned project process.

If that fails for whatever reason please get back to us and set this back to "needs review".

ragnarkurm’s picture

Thank you for refering Drush Entity project, which went unnoticed for me.
My project is not duplication, but it is closely related.
Drupal Entity is around reporting Entity metadata.
My project is around changing (and reading) specific field data.

Just for the record, here is project merge issue:
https://www.drupal.org/node/2290005

mpdonadio’s picture

This is currently Postponed, but here is my review.

Automated Review

There is still a master branch, make sure to set the correct default branch: http://drupal.org/node/1659588 . Then remove the master branch, see also step 6 and 7 in http://drupal.org/node/1127732

Review of the 7.x-1.x branch:

  • Coder Sniffer has found some issues with your code (please check the Drupal coding standards). See attachment.
  • DrupalPractice has found some issues with your code, but could be false positives, and may be duplicate results from Coder Sniffer. See attachment.

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.

Fix the long lines. Unused variables seem to be accounted for via the comments before the extract().

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No multiple applications
Yes
No duplication
Maybe? Please comment on whether this should be part of https://www.drupal.org/project/drush_entity
Master Branch
No: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements
3rd party code
Yes: Follows the guidelines for 3rd party code.
README.txt
Yes: Follows the guidelines for in-project documentation and the README.txt Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes/No. If "no", list security issues identified.
Coding style & Drupal API usage
Place code review here using this format:

(+) Get rid of the master branch from the repo.

README has private git link. Use the public one.

How would a module that implements a entity_metadata_wrapper() field go about making it compatible with this module?

The chown() / chmod() / chgrp() will require elevated permissions on the server, and have these been tested on Windows? May need to
document this behavior.

(+) In general, db_select() against the node table should have the node_access() tag. This is an interesting case. In a module, this
would be a security problem. With a drush command, you bypass just about all security. However, if you run
drush with the -u option (to get it to run as a user), you may end up in a weird situation where a hook_node_update() runs
on a node that the user doesn't really have access to. I would add the tag, and document some of the weirdness that may result
because of hooks / rules running as the user that drush is run as (which defaults to the anonymous user). Some of the same
general concerns pop up in drush_fields_target(). Maybe an explicit entity_access() instead? Maybe warn/prompt users in drush_fields_target()
when the drush user don't have update access to the entity?

I concur about the dt() usage in hook_drush_command entries. I am not seeing any in the code drush files.

Can't drush_fields_target() just use entity_load() instead of building up the load funciton name?

This is just a note to myself and other reviewers that drush_exit() got removed a while ago. However, I am not 100% certain
that calling exit() is appropriate. Double check this.

I think drush_fields_file_add() will need 'description' set on the file object for it to work properly with entity_metadata_wrapper() (I have had
problems with this in the past).

Comments about files also apply to images.

Not a huge fan of extract(), but I think you documented it well enough.

Will the file add work with remote files? Look into system_retrieve_file(), this may work with local files, too.

Seems to me that some refactoring could be used to share / simplify things, eg float / int / text share a lot in common, other than validaton.

You may want to look into whether using field_attach_update() is an option rather than a full blown save.

There is a way to package drush-only "modules". I am pretty sure you get rid of the .module file and the core= from the .info file.
Look at drush_extras to see how it works.

Do the file/image functions work when File Entity is enabled? I can't recall if entity_metadata_wrapper() behaves differenly when
they are.

I'm seeing escaped text when I do a 'drush fields-text-add'.

I think that these operations should be logged via watchdog(), as normal content updates are.

(+) I also think that these should propmt the user before updating, unless the -y option is present.

A couple of these are fairly big (the + ones), but I am not seeing any blocking issues (other than the duplication issue mentioned above).
If this gets committed to drush_entity, and other admins concur, I don't see a problem giving vetted access based on this code.
Whether or not this gets folded into drush_entity, I see this as a very useful addition to the module space. I have a lot of
one-off drush scr scripts for altering data, and this would simplify my life.

mpdonadio’s picture

StatusFileSize
new13.61 KB

Grrr.

ragnarkurm’s picture

Thank you for review!
Asking for help on removing master branch. I just get:
! [remote rejected] master (deletion of the current branch prohibited)

EDIT: solved.

ragnarkurm’s picture

Fixed first portion of things.

There is still a master branch, make sure to set the correct default branch: http://drupal.org/node/1659588 . Then remove the master branch, see also step 6 and 7 in http://drupal.org/node/1127732

(+) Get rid of the master branch from the repo.

Need help doing it. See #15.

Fix the long lines. Unused variables seem to be accounted for via the comments before the extract().

Not a huge fan of extract(), but I think you documented it well enough.

Long lines fixed.
extract() removed.

README has private git link. Use the public one.

Fixed.

How would a module that implements a entity_metadata_wrapper() field go about making it compatible with this module?

Didnt get it, can you rephrase?

The chown() / chmod() / chgrp() will require elevated permissions on the server, and have these been tested on Windows? May need to document this behavior.

Added relevant notices to drush commandline command and option descriptions.

(+) In general, db_select() against the node table should have the node_access() tag. This is an interesting case. In a module, this would be a security problem. With a drush command, you bypass just about all security. However, if you run drush with the -u option (to get it to run as a user), you may end up in a weird situation where a hook_node_update() runs on a node that the user doesn't really have access to. I would add the tag, and document some of the weirdness that may result because of hooks / rules running as the user that drush is run as (which defaults to the anonymous user). Some of the same general concerns pop up in drush_fields_target(). Maybe an explicit entity_access() instead? Maybe warn/prompt users in drush_fields_target() when the drush user don't have update access to the entity?

Added permission checking and documented it.
Users 0 and 1 can do all operations for practical reasons.
Other users are checked properly against system access settings.

Can't drush_fields_target() just use entity_load() instead of building up the load funciton name?

Done.

This is just a note to myself and other reviewers that drush_exit() got removed a while ago. However, I am not 100% certain that calling exit() is appropriate. Double check this.

Removed all exit() functions. Drush commands actually return FALSE rather then exit().

ragnarkurm’s picture

I think drush_fields_file_add() will need 'description' set on the file object for it to work properly with entity_metadata_wrapper() (I have had problems with this in the past).

Description element and respective commandline argument added.

Comments about files also apply to images.

Can you be more specific?
Images use alt and title, file use description.

I'm seeing escaped text when I do a 'drush fields-text-add'.

This is drush problem and I cannot do much about it, except bug report. You can verify by typing drush cache-set and see what happens.

ragnarkurm’s picture

Will the file add work with remote files? Look into system_retrieve_file(), this may work with local files, too.

Good idea! Feature request implemented. Files/Images can now be added by url directly.

ragnarkurm’s picture

(+) Get rid of the master branch from the repo.

Done.

You may want to look into whether using field_attach_update() is an option rather than a full blown save.

Why? Only reason using it is to optimize for speed - if there are a lot changes. Currently the module works one entity change per execution. Also, field_attach_update() would prevent Rules and save hooks etc not to be run. If there is a use-case which needs field_attach_update() then it will b implemented.

mpdonadio’s picture

The field_attach_update() was just a suggestion to investigate. You are correct that a proper node_save() will invoke hooks so things like Rules run, which is best. I frequently run into situations where I need to do touchup on data (esp after a import) where I don't necessarily want the Rules to run.

ragnarkurm’s picture

Seems to me that some refactoring could be used to share / simplify things, eg float / int / text share a lot in common, other than validaton.

Done.

There is a way to package drush-only "modules". I am pretty sure you get rid of the .module file and the core= from the .info file. Look at drush_extras to see how it works.

Done.
Seems that drush-only modules download-only.
No manual/automated updating?

Do the file/image functions work when File Entity is enabled? I can't recall if entity_metadata_wrapper() behaves differently when they are.

It works. File Entity adds to retrieved array ($wrapper->field_file->value()) only few additional (possibly autogenerated) elements. Otherwise the format and functionality seems to be same.

I think that these operations should be logged via watchdog(), as normal content updates are.

Done.

I also think that these should prompt the user before updating, unless the -y option is present.

Done.

The field_attach_update() was just a suggestion to investigate. You are correct that a proper node_save() will invoke hooks so things like Rules run, which is best. I frequently run into situations where I need to do touchup on data (esp after a import) where I don't necessarily want the Rules to run.

Fair enough. Added option to choose saving method. The field_attach_update() method involves entity cache clearing.

Now, all points in review are corrected.

helmo’s picture

One quick remark:
You have a lot of create_function calls, about which the php.net documentation warns ...

This function internally performs an eval() and as such has the same security issues as eval().
clemens.tolboom’s picture

I would opt for a duplicate project which is motivated below.
---
Drush core has a command set field

$ drush @drupal.d7 help | grep field
All commands in field: (field)
 field-clone           Clone a field and all its instances.
 field-create          Create fields and instances. Returns urls for field editing.
 field-delete          Delete a field and its instances.
 field-info            View information about fields, field_types, and widgets.
 field-update          Return URL for field editing web page.

Drush Entity project has a command set entity. It can read entity type and CRUD on entities. It's update can filter on (list of) field(s).

$ drush @drupal.d7 help | grep entity
All commands in entity: (entity)
 entity-create (ec)    Create an entity from a json object
 entity-delete (ed)    Delete entities.
 entity-list (el)      Get a list of entity type information in a summary table.
 entity-read (er)      Print entity contents
 entity-type-read      List details of entity types
 entity-update (eu)    Update an entity as json in the default editor

As an example let's update node/53 only it's title (starts default editor)

drush @drupal.d7 entity-update node 53 --fields=title
drush @drupal.d7 entity-read node 53 --fields=title

Or even through STDIN

echo '{"title":"XXX"}' | drush --pipe @drupal.d7 entity-update node 53 --fields=title --json-input=-
drush @drupal.d7 entity-read node 53 --fields=title

@ragnarkurm Sorry for the long delay :-/

I'll review the code through the sandbox issue queue.

I will update the project page https://www.drupal.org/project/drush_entity with these example.

Next process issue #2290005: Merge Drush Fields into Drush Entities?

mpdonadio’s picture

@clemens.tolboom, I'm confused. Do you want to merge this into Drush Entities or do you think this should stay a separate project?

clemens.tolboom’s picture

@mpdonadio sorry for the confusing text.

I think the project is a duplicate (Closed (duplicate)) of drush_entity only different in drush commands and arguments.

I've invited @ragnarkurm to join drush_entity per #2290005-5: Merge Drush Fields into Drush Entities?

Hope that helps.

ragnarkurm’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Closing this application as duplicate.
Working towards merge with Drush Entity.

ragnarkurm’s picture

Status: Closed (duplicate) » Needs review

Is it possible to use this sandbox project to earn "Create Full Projects" permission?
Despite that is merged into Drupal Entity.
(Though the process is called Project Application, but should be titled as Status Application, hence the confusion).
I have learned all basic rules for creating a project and went through this months-long trial,
not sure if I would like to go through this barrier again or keep future developments to my own.

mpdonadio’s picture

Status: Needs review » Postponed (maintainer needs more info)

Yes, we can do that. We just need to determine what the review will be against. Is the patch against Drupal Entity mostly standalone that we could evaluate that? Or, is the sandbox version essentially what got committed?

ragnarkurm’s picture

My suggestion is to currently evaluate sandbox version.

There are two branches of code: sandbox and merge.

Sandbox version is constantly refined, polished, doc added, new features added, bugfixed etc. It is stable and consistent. As Drush Entity owner did code review in separate issue, it is not directly visible here. All points are answered / corrected.

I dont have any permissions in Drush Entity, I upload (possibly unstable) tarballs to merge issue. It is too early to evaluate anything there yet. Currently seems that merge is going to be slow process.

ragnarkurm’s picture

Status: Postponed (maintainer needs more info) » Needs review
klausi’s picture

Status: Needs review » Needs work

Since you don't have any other sandboxes to promote currently I think that we can wait until your changes to drush_entity land.

You should start to provide smaller patches against drush_entity so that it is easier for the maintainers to accept them. Once there is enough of your stuff in drush_entity let's review that and proceed here. I think it would be a waste of time to review the sandbox code now which will soon be obsolete. Thank you for your yonsideration and your contribution!

clemens.tolboom’s picture

So I guess I must work harder on drush_entity besides oter projects :-p

PA robot’s picture

Status: Needs work » Closed (won't fix)

Closing due to lack of activity. If you are still working on this application, you should fix all known problems and then set the status to "Needs review". (See also the project application workflow).

I'm a robot and this is an automated message from Project Applications Scraper.

ragnarkurm’s picture

Status: Closed (won't fix) » Needs review

Apparently the merge does not happen.
Lack of interest.

In Changes to the project application review process it is said:

Applications will not be blocked for minor coding standards violations, bugs, or project duplication.

So, is there anything else blocking?

ragnarkurm’s picture

Status: Needs review » Reviewed & tested by the community
avpaderno’s picture

Status: Reviewed & tested by the community » Needs review

The user who is applying should not set the status to Reviewed & tested by the community.

ragnarkurm’s picture

Sorry, I have probably missed or forgot something during years of the application, but the question still stands.

In Changes to the project application review process it is said:

Applications will not be blocked for minor coding standards violations, bugs, or project duplication.

So, is there anything else blocking?

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Fixed

I will update your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thank you, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks go the dedicated reviewer(s) as well.

Status: Fixed » Closed (fixed)

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