When implementing the sanitize operation, I introduced a bootstrap to the local site to allow enabled modules to participate in the sanitize operation. The problem is that I did a bootstrap_max, and if there is a local site that has a Drupal root and a valid settings.php file, but no database (as is the case if you've just rsync'ed the files over, and are now about to sql-sync the db over), then bootstrap_max will fail and the operation will not work.

Not sure how to best fix this; skipping the bootstrap if --create-db is specified would be a quick fix. Subverting the bootstrap when there is no local db is a better option, but I don't think that making this change to bootstrap_max for the general case would be a good idea...

Comments

greg.1.anderson’s picture

I realized after writing that that bootstrap_max should never fail; if the database is not present, then it should stop at DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION. I must have broken something. I'll look into it.

greg.1.anderson’s picture

Component: Code » PM (dl, en, up ...)

The correct fix would be to get rid of drush_bootstrap_max_to_local_sitealias(array($source_settings, $destination_settings)); in drush_sql_sync_init and instead re-implement the sanitization operation as a hidden command that returns the sanitization script. Then, sql-sync could simply call sanitize on the source system, and then later execute the resulting script on the target system. This would even work when the target database has not been created yet, and the source system is remote.

I'm going to code it up to work like this.

greg.1.anderson’s picture

Status: Active » Needs review
StatusFileSize
new15.98 KB

I decided that a separate command was not the way to go, as that would require drush to be present on the remote machine for sanitizations to work right when the source db is remote, which I feel is a common case.

The enclosed patch will bootstrap to the source site in the sql sync init hook, but if the source is remote, then sanitization is deferred until after the database is copied to the destination. If the destination db is local and we did not bootstrap to the source, then we will bootstrap to the destination after the db is imported in the main sql sync command hook. This implies that we can no longer consistently collect sanitization operations in the pre-sql-sync hook function. A new sanitization hook is introduced in this patch to provide the same capabilities.

The documentation in drush.api has been updated to the new conventions. Finally, there is also a new option called --confirm-sanitizations. If this option is specified, then drush will ask the user to confirm the sanitizations before they are executed. If this option is not specified, then drush will simply print out the sanitization operations that are being done, and do them without confirmation. In this later step, the user is warned before confirming the sql sync operation that the sanitization operations will be done without review, and that the --confirm-sanitizations flag can be used to change this behavior.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Sounds like an honorable goal (avoid requiring drush on remote side).

Code looks good. Just found a typo: operatins

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new17.13 KB

Add --confirm-sanitizations to sql-sync help, and make it work even if sanitizations are confirmed upfront (for local source sites).

greg.1.anderson’s picture

Status: Needs review » Reviewed & tested by the community

Status reset accidentally; will fix typo and commit.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

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