I know there isn't one here currently but it might be cool to have a replicate drush plugin so that you could quickly replicate items via command line. I maintain the replicate UI module and so I know that UI items are not in scope of replicate as its an API for developers so before I added drush plugins (would take all of like an hour probably) I was seeing if that would be something that would have a chance of being added here or if I should just author a replicate_drush or even add it to the replicate_ui project namespace.

Ideas for capabilities would be along the lines of:
drush replicate {entity type} {id number}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jgalletta’s picture

Sorry for the delay but yes, that would be added here, feel free to submit a patch :)

mmilutinovic1313’s picture

Currently working on this as a patch. Updates to come soon!

mmilutinovic1313’s picture

Hi all,

Here is the code's status. I'm just working on some error checking so that users will get friendly error messages if they enter something invalid. I'll be posting the patch soon after I finish that process. Here is the github link to my work:

https://github.com/mmilutinovic1313/replicate

mmilutinovic1313’s picture

FileSize
2.71 KB

Here is the patch. Let me know if it needs any changes!

-Mark

btopro’s picture

Status: Active » Needs work

Some critique. account for not including argument 2. If no entityID is supplied then we need to make sure it's accounted for. Shouldn't throw a warning it should throw a message

Missing argument 2 for drush_replicate_drush_entity_by_id() replicate.drush.inc:36                 [warning]
array_flip(): Can only flip STRING and INTEGER values! entitycache.module:69                       [warning]

are both thrown when no ID is supplied

ALso the usage examples when you type drep --help is different then the actual command. Says drush rep node 1 but drep appears to be the call. Make it replicate and maybe rep as the shorthand if you want to use one.

mmilutinovic1313’s picture

Here is a new patch, I think this one handles the errors better.

Command: drush replicate
Shorthand: drush rep

Requires 2 params

Let me know if you need anything else added!

btopro’s picture

drush_replicate_drush_help is still a placeholder. other then that looking good

mmilutinovic1313’s picture

This invokes replicate_drush_help properly

btopro’s picture

See like 47:

This should be a call to replicate_entity_by_id then you don't need the last two functions.

Also comment / document each function in the

/**
 * Impelements hook_name().
 */

style

mmilutinovic1313’s picture

THIS PATCH DID NOT DIFF PROPERLY. NEW PATCH COMING IN 5 MIN

mmilutinovic1313’s picture

Okay this should have the correct simplified formatting and code with proper hook references.

btopro’s picture

Status: Needs work » Needs review

Looks good to me, could use some testing by a third party since in full disclosure mark works for me.

jgalletta’s picture

Quick code review:

  • typo in 'description' => 'Replicate an Enitity via Drush!',
  • misplaced blank space in if (!is_null($entity_type) && !is_null($id) ){
  • use simple quote for all strings
mmilutinovic1313’s picture

Fixed the formatting listed above! Please let me know if you have any other fixes!

vbouchet’s picture

Hi @mmilutinovic1313,
I updated your patch with various standard fixes but also updated the drush command to accept a list of entity IDs instead of only one. It's of course accepting only one ID if you want to replicate only one entity.

btopro’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed, looks good to me!

  • vbouchet committed 8827eff on 7.x-1.x
    Issue #2338345 by mmilutinovic1313, vbouchet, btopro: integrate drush...

vbouchet’s picture

Status: Reviewed & tested by the community » Closed (fixed)

This had been merged, will be available in the next release.

chefnelone’s picture

Is there a way to replicate a node several times with Drush?
Let say I want to create 5 copies of a node which ID is 174.
Can I do it with Drush?

btopro’s picture

I mean you could call the drush command 5 times w/ the same ID. Or you could use dev of this to get the replicate drush plugin then write a recipe via http://drupal.org/project/drush_recipes to chain build the item X number of times. this would be pretty easy to do with the looping part of the spec

chefnelone’s picture

ok, which is the command to replicate a node?

btopro’s picture

drush replicate node 1,2,3