Permalink
Switch branches/tags
3.x 4.x 5.x 6.x-fulltest 6.x 7.x 8.x 9.5.x Drush-call alias-search-fix annotation-drush7 avoid-header-interaction backend-stdin batch-no-output better-bootstrap-refactor better-site-alias-docs bootstrap-state-isolation cc-bootstrap-errs chmod-settings-8 chmod-settings command-cache commit-sut-aliases compatible-status completion config-alias-repl coveralls dcf-composerjson docs-update drop-symfony2 drupal-core-strict drush9-services-yml dsnopek-mysqli-extension-2 editor ensure-mysql-available environment-inc-cleanup everyone-luvs-global-drush exclude-vendor find-uri-from-cwd fix-6-backport fix-6 fix-defaults fix-double-exec fix-file-alias-path fix-getmultiple fix-max fix-unish-path-repo generic-alias gh-pages guard-service-cache hook-order inflect-alias-manager integration-tests-2 interact-hook isolation-via-test-scenarios luv-4-global-drush master-fulltest master merge-config-paths moar-testability mv-during-pm-download output-filter pass-unknown-to-site-local paths-for-local-redispatch-only php-72-isolation phpunit6 preflight-sitelocator preserve-contrib-dir-backport private-yml-parser process-replacement property-list psr-4 remote-sitespecs remote-unknown-commands remove-annotation-adapter remove-command-inc remove-sitealias rename-drush-service-cache sa-multipart-aliases shippable si-for-ci-drush8 si-for-ci si-profile simplified-site-aliases site-alias-location-filters sitealias-refactor skip-shippable sql-fetch ssh-tty-option support-docs symfony-dispatch-remove-contexts symfony-dispatch-remove-some-preflight tagged-services test-bootstrap-none test-symfony-dispatch unstructured-data-fields update-no-bootstrap use-mysqli useProcess user-check-if-blocked
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (49 sloc) 2.01 KB
<?php
namespace Drush\Drupal\Commands\sql;
use Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface;
use Consolidation\AnnotatedCommand\Events\CustomEventAwareTrait;
use Drush\Commands\DrushCommands;
use Drush\Exceptions\UserAbortException;
class SanitizeCommands extends DrushCommands implements CustomEventAwareInterface
{
use CustomEventAwareTrait;
/**
* Sanitize the database by removing or obfuscating user data.
*
* Commandfiles may add custom operations by implementing:
* - @hook_on-event sql-sanitize-message
* Display summary to user before confirmation.
* - @hook post-command sql-sanitize
* Run queries or call APIs to perform sanitizing
*
* @command sql:sanitize
* @aliases sqlsan,sql-sanitize
* @usage drush sql:sanitize --sanitize-password=no
* Sanitize database without modifying any passwords.
* @usage drush sql:sanitize --whitelist-fields=field_biography,field_phone_number
* Sanitizes database but exempts two user fields from modification.
*/
public function sanitize()
{
/**
* In order to present only one prompt, collect all confirmations from
* commandfiles up front. sql-sanitize plugins are commandfiles that implement
* \Drush\Commands\sql\SanitizePluginInterface
*/
$messages = [];
$input = $this->input();
$handlers = $this->getCustomEventHandlers('sql-sanitize-confirms');
foreach ($handlers as $handler) {
$handler($messages, $input);
}
if (!empty($messages)) {
$this->output()->writeln(dt('The following operations will be performed:'));
$this->io()->listing($messages);
}
if (!$this->io()->confirm(dt('Do you want to sanitize the current database?'))) {
throw new UserAbortException();
}
// All sanitize operations defined in post-command hooks, including Drush
// core sanitize routines. See \Drush\Commands\sql\SanitizePluginInterface.
}
}