X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Fsrc%2FDrupal%2FCommands%2Fsql%2FSanitizeCommentsCommands.php;fp=vendor%2Fdrush%2Fdrush%2Fsrc%2FDrupal%2FCommands%2Fsql%2FSanitizeCommentsCommands.php;h=6e1344c857358608b9179444e3a31e9bbdf1c740;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/drush/drush/src/Drupal/Commands/sql/SanitizeCommentsCommands.php b/vendor/drush/drush/src/Drupal/Commands/sql/SanitizeCommentsCommands.php new file mode 100644 index 000000000..6e1344c85 --- /dev/null +++ b/vendor/drush/drush/src/Drupal/Commands/sql/SanitizeCommentsCommands.php @@ -0,0 +1,77 @@ +database = $database; + $this->moduleHandler = $moduleHandler; + } + + /** + * Sanitize comment names from the DB. + * + * @hook post-command sql-sanitize + * + * @inheritdoc + */ + public function sanitize($result, CommandData $commandData) + { + if ($this->applies()) { + //Update anon. + $this->database->update('comment_field_data') + ->fields([ + 'name' => 'Anonymous', + 'mail' => '', + 'homepage' => 'http://example.com' + ]) + ->condition('uid', 0) + ->execute(); + + // Update auth. + $this->database->update('comment_field_data') + ->expression('name', "CONCAT('User', `uid`)") + ->expression('mail', "CONCAT('user+', `uid`, '@example.com')") + ->fields(['homepage' => 'http://example.com']) + ->condition('uid', 1, '>=') + ->execute(); + $this->logger()->success(dt('Comment display names and emails removed.')); + } + } + + /** + * @hook on-event sql-sanitize-confirms + * + * @inheritdoc + */ + public function messages(&$messages, InputInterface $input) + { + if ($this->applies()) { + $messages[] = dt('Remove comment display names and emails.'); + } + } + + protected function applies() + { + Drush::bootstrapManager()->doBootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL); + return $this->moduleHandler->moduleExists('comment'); + } +}