From a7f11cdcff86b987b7bda51e55e0f2fcf1292877 Mon Sep 17 00:00:00 2001
From: Xiaodan Wang <bala@ciandt.com>
Date: Thu, 24 Mar 2016 13:56:32 +0800
Subject: Modified .info.yml file to remove scripts and change order of
 properties

---
 move_user.info.yml | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/move_user.info.yml b/move_user.info.yml
index ee55e52..e657d76 100644
--- a/move_user.info.yml
+++ b/move_user.info.yml
@@ -1,10 +1,6 @@
 name: 'Move user'
 description: 'Cancel user accounts and reassign content to another user'
-core: 8.x
 package: Other
-scripts:
-  - move-user.js
-version: 7.x-1.x-dev
-project: move_user
-datestamp: '1394178807'
+
 type: module
+core: 8.x
-- 
1.9.1


From 004e0f5c018c000b650d47936eb550dea3f69a5d Mon Sep 17 00:00:00 2001
From: Xiaodan Wang <bala@ciandt.com>
Date: Thu, 24 Mar 2016 15:17:58 +0800
Subject: Add README.txt

---
 README.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
 create mode 100644 README.txt

diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..78b6bc4
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,8 @@
+This module adds a new method for cancelling user accounts. 
+It is based on the user_cancel_reassign cancel method from Drupal core, 
+but adds the option to select which user the content is reassigned to, 
+rather than just assigning content to the anonymous user.
+
+To use simply install and enable the module, then when an administrator (or 
+user with "administer users" permission) cancels a user account they will be 
+given the extra option to select which user the content is reassigned to.
-- 
1.9.1


From b09e3835f9b83fd35f7662612c96c24abeddc67f Mon Sep 17 00:00:00 2001
From: Kevin <Kevin@ciandt.com>
Date: Thu, 24 Mar 2016 15:29:38 +0800
Subject: Upgrade hook_form_alter and hook_user_cancel_methods_alter

---
 move_user.module | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/move_user.module b/move_user.module
index 622f1e9..03bd597 100644
--- a/move_user.module
+++ b/move_user.module
@@ -1,7 +1,11 @@
 <?php 
 
+/**
+ * Implement of hook_user_cancel_menthods_alter().
+ */
 function move_user_user_cancel_methods_alter(&$methods) {
   unset($methods['user_cancel_reassign']);
+  // Add a custom move user reassign method.
   $methods['move_user_reassign'] = array(
     'title' => t('Disable the account and make its content belong to another user.'),
     'description' => t('All your content will be removed and assigned to a different user'),
@@ -10,26 +14,21 @@ function move_user_user_cancel_methods_alter(&$methods) {
 }
 
 function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
-  if ($form_id == 'user_cancel_confirm_form' || $form_id == 'user_multiple_cancel_confirm_form') { 
-    // @FIXME
-// // @FIXME
-// // This looks like another module's variable. You'll need to rewrite this call
-// // to ensure that it uses the correct configuration object.
-// $form['reassign_user'] = array(
-//       '#type' => 'textfield',
-//       '#title' => t('Reassign content to:'),
-//       '#maxlength' => 60,
-//       '#autocomplete_path' => 'user/autocomplete',
-//       '#weight' => 10,
-//       '#description' => t('Leave blank for %anonymous.',
-//         array('%anonymous' => variable_get('anonymous', t('Anonymous')))),
-//     );
-
+  if ($form_id == 'user_cancel_form' || $form_id == 'user_multiple_cancel_confirm') {
+    $form['move_user_reassign'] = array(
+      '#type' => 'entity_autocomplete',
+      '#target_type' => 'user',
+      '#title' => t('Reassign content to:'),
+      '#maxlength' => 60,
+      '#weight' => 10,
+      '#description' => t('Leave blank for %anonymous.',
+        array('%anonymous' => \Drupal::config('user.settings')->get('anonymous'))),
+    );
   }
 }
 
 function move_user_user_cancel($edit, $account, $method) {
-  $new_account = user_load_by_name($edit['reassign_user']);
+  $new_account = \Drupal\user\Entity\User::load();
   $new_uid = !empty($new_account->uid) ? $new_account->uid : 0;
   switch ($method) {
     case 'move_user_reassign':
@@ -49,4 +48,4 @@ function move_user_user_cancel($edit, $account, $method) {
 
       break;
   }
-}
\ No newline at end of file
+}
-- 
1.9.1


From 77783ea58b0171a7063e96072bad3b4472911abc Mon Sep 17 00:00:00 2001
From: Xiaodan Wang <bala@ciandt.com>
Date: Thu, 24 Mar 2016 15:54:27 +0800
Subject: Initial a WebTest for move_user module

---
 src/Tests/MoveUserTest.php | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 src/Tests/MoveUserTest.php

diff --git a/src/Tests/MoveUserTest.php b/src/Tests/MoveUserTest.php
new file mode 100644
index 0000000..cc9eb8f
--- /dev/null
+++ b/src/Tests/MoveUserTest.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * @file
+ * Test case for testing the move_user module.
+ *
+ * This file contains the test cases to check if move user is performing correctly.
+ */
+
+namespace Drupal\move_user\Tests;
+
+use Drupal\Simpletest\WebTestBase;
+
+/**
+ * Create two users and use one user to create few nodes, 
+ * then use the administrator user to delete the nodes created,
+ * reassign the nodes to the second user.
+ *
+ * @group move_user
+ */
+class MoveUserTest extends WebTestBase {
+
+  /**
+   * Tests the assign the new user when move user.
+   */
+  public function testMoveUser() {
+  }
+}
-- 
1.9.1


From 32984f2b25f6d140abab97d3d9d0b8d879554153 Mon Sep 17 00:00:00 2001
From: "qing@ciandt.com" <qing@ciandt.com>
Date: Thu, 24 Mar 2016 16:29:06 +0800
Subject: move_user ugrade

---
 move-user.js            |  9 +++------
 move_user.info.yml      |  2 +-
 move_user.libraries.yml |  4 ++++
 move_user.module        | 20 +++++++++++---------
 4 files changed, 19 insertions(+), 16 deletions(-)
 create mode 100644 move_user.libraries.yml

diff --git a/move-user.js b/move-user.js
index d5f1168..09d9bc4 100644
--- a/move-user.js
+++ b/move-user.js
@@ -1,26 +1,23 @@
 (function ($) {
 
   Drupal.behaviors.moveUserAdmin = {
-    attach: function (context, settings) {
 
+    attach: function (context, settings) {
       var formItemReassignUser = $('.form-item-reassign-user', context);
       var cancelMethodsWrapper = $("#edit-user-cancel-method", context);
-
       if ($('[value=move_user_reassign]').is(':checked')){
          formItemReassignUser.appendTo(cancelMethodsWrapper).show();
       } else {
         formItemReassignUser.hide();
       }
-
-      $(cancelMethodsWrapper).find('input').once('move-user-admin', function () {
-        $(this).change(function (e) {
+      $("#edit-user-cancel-method input").off().on("change", function (e) {
           if ($(e.target).val() == 'move_user_reassign') {
             formItemReassignUser.appendTo(cancelMethodsWrapper).fadeIn(200);
           } else {
             formItemReassignUser.hide();
           }
         });
-      }, context);
+
 
     }
   };
diff --git a/move_user.info.yml b/move_user.info.yml
index e657d76..6e04882 100644
--- a/move_user.info.yml
+++ b/move_user.info.yml
@@ -3,4 +3,4 @@ description: 'Cancel user accounts and reassign content to another user'
 package: Other
 
 type: module
-core: 8.x
+core: 8.x
\ No newline at end of file
diff --git a/move_user.libraries.yml b/move_user.libraries.yml
new file mode 100644
index 0000000..2e96473
--- /dev/null
+++ b/move_user.libraries.yml
@@ -0,0 +1,4 @@
+move_user:
+  version: VERSION
+  js: 
+    move-user.js: {}
\ No newline at end of file
diff --git a/move_user.module b/move_user.module
index 03bd597..3bd5e89 100644
--- a/move_user.module
+++ b/move_user.module
@@ -15,7 +15,8 @@ function move_user_user_cancel_methods_alter(&$methods) {
 
 function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
   if ($form_id == 'user_cancel_form' || $form_id == 'user_multiple_cancel_confirm') {
-    $form['move_user_reassign'] = array(
+    $form['#attached']['library'][] = 'move_user/move_user';
+    $form['reassign_user'] = array(
       '#type' => 'entity_autocomplete',
       '#target_type' => 'user',
       '#title' => t('Reassign content to:'),
@@ -30,20 +31,21 @@ function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$for
 function move_user_user_cancel($edit, $account, $method) {
   $new_account = \Drupal\user\Entity\User::load();
   $new_uid = !empty($new_account->uid) ? $new_account->uid : 0;
+  $new_uid = $edit['reassign_user'];
   switch ($method) {
     case 'move_user_reassign':
 
       module_load_include('inc', 'node', 'node.admin');
-      $nodes = db_select('node', 'n')
-        ->fields('n', array('nid'))
-        ->condition('uid', $account->uid)
-        ->execute()
-        ->fetchCol();
-      node_mass_update($nodes, array('uid' => $new_uid));
 
-      db_update('node_revision')
+      $nodes = \Drupal::entityQuery('node')
+        ->condition('uid', $account->id())
+        ->execute();
+        
+      node_mass_update($nodes, array('uid' => $new_uid), NULL, TRUE);
+
+      db_update('node_field_revision')
         ->fields(array('uid' => $new_uid))
-        ->condition('uid', $account->uid)
+        ->condition('uid', $account->id())
         ->execute();
 
       break;
-- 
1.9.1


From bb199037c44f1cbbd74e61f9084a078a332ce954 Mon Sep 17 00:00:00 2001
From: jieyyal <jieyyal@ciandt.com>
Date: Thu, 24 Mar 2016 16:34:13 +0800
Subject: Add comment for each hook

---
 move_user.module | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/move_user.module b/move_user.module
index 3bd5e89..f31ba2b 100644
--- a/move_user.module
+++ b/move_user.module
@@ -1,4 +1,8 @@
 <?php 
+/**
+ * @file
+ * Adds a new method for cancelling user accounts.
+ */
 
 /**
  * Implement of hook_user_cancel_menthods_alter().
@@ -13,6 +17,9 @@ function move_user_user_cancel_methods_alter(&$methods) {
   );
 }
 
+/**
+ * Implement of hook_form_alter().
+ */
 function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
   if ($form_id == 'user_cancel_form' || $form_id == 'user_multiple_cancel_confirm') {
     $form['#attached']['library'][] = 'move_user/move_user';
@@ -28,6 +35,9 @@ function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$for
   }
 }
 
+/**
+ * Implement of hook_user_cancel().
+ */
 function move_user_user_cancel($edit, $account, $method) {
   $new_account = \Drupal\user\Entity\User::load();
   $new_uid = !empty($new_account->uid) ? $new_account->uid : 0;
@@ -40,7 +50,6 @@ function move_user_user_cancel($edit, $account, $method) {
       $nodes = \Drupal::entityQuery('node')
         ->condition('uid', $account->id())
         ->execute();
-        
       node_mass_update($nodes, array('uid' => $new_uid), NULL, TRUE);
 
       db_update('node_field_revision')
-- 
1.9.1


From f4d577251695df37dc671c246e32806170d28333 Mon Sep 17 00:00:00 2001
From: Xiaodan Wang <bala@ciandt.com>
Date: Thu, 24 Mar 2016 20:51:47 +0800
Subject: Remove buggy code from hook_user_cancel

---
 move_user.module | 2 --
 1 file changed, 2 deletions(-)

diff --git a/move_user.module b/move_user.module
index f31ba2b..bc6d679 100644
--- a/move_user.module
+++ b/move_user.module
@@ -39,8 +39,6 @@ function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$for
  * Implement of hook_user_cancel().
  */
 function move_user_user_cancel($edit, $account, $method) {
-  $new_account = \Drupal\user\Entity\User::load();
-  $new_uid = !empty($new_account->uid) ? $new_account->uid : 0;
   $new_uid = $edit['reassign_user'];
   switch ($method) {
     case 'move_user_reassign':
-- 
1.9.1


From cac139c671f79e31aa8441ebacd96274f92d387b Mon Sep 17 00:00:00 2001
From: Xiaodan Wang <bala@ciandt.com>
Date: Thu, 24 Mar 2016 20:52:00 +0800
Subject: Add webtest for move_user module

---
 src/Tests/MoveUserTest.php | 48 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/Tests/MoveUserTest.php b/src/Tests/MoveUserTest.php
index cc9eb8f..d2d8496 100644
--- a/src/Tests/MoveUserTest.php
+++ b/src/Tests/MoveUserTest.php
@@ -8,7 +8,7 @@
 
 namespace Drupal\move_user\Tests;
 
-use Drupal\Simpletest\WebTestBase;
+use \Drupal\simpletest\WebTestBase;
 
 /**
  * Create two users and use one user to create few nodes, 
@@ -17,11 +17,51 @@ use Drupal\Simpletest\WebTestBase;
  *
  * @group move_user
  */
-class MoveUserTest extends WebTestBase {
+class MoveUserTest extends \Drupal\node\Tests\NodeTestBase {
+
+  protected $originalAuthor;
+
+  protected $newAuthor;
+
+  protected $createdNode;
+
+  public static $modules = array('move_user', 'user');
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->originalAuthor = $this->drupalCreateUser(array('create page content', 'edit own page content'));
+    // Create another admin user for delete the web_user
+    $this->newAuthor = $this->drupalCreateUser(array('create page content', 'edit own page content'));
+
+    // create a page node with current user
+    $this->createdNode = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->originalAuthor->id()));
+
+  }
 
   /**
-   * Tests the assign the new user when move user.
+   * Tests to reassign node to another user.
    */
-  public function testMoveUser() {
+  public function testCancelUserMoveUser() {
+    // Create administrator user and login
+    $admin_user = $this->drupalCreateUser(array('administer nodes', 'administer users'));
+    $this->drupalLogin($admin_user);
+
+    // Cancel the author page
+    $cancel_user_url = 'user/' . $this->originalAuthor->id() . '/cancel';
+    $this->drupalGet($cancel_user_url);
+
+    $edit = array();
+    $edit['user_cancel_method'] = 'move_user_reassign';
+    $edit['reassign_user'] = $this->newAuthor->getUserName() . ' (' . $this->newAuthor->id() . ')';
+    $edit['confirm'] = 1; 
+    $this->drupalPostForm($cancel_user_url, $edit, t('Cancel account'));
+
+    // check if the node's author is changed to newAuthor
+    $node = node_load($this->createdNode->id());
+    $this->assertEqual($node->getOwnerId(), $this->newAuthor->id(), 'Ensure that the node is reassigned to the new user correctly.');
   }
 }
-- 
1.9.1


From 3a05ed4658f39cf20522e213a0c1f8fca1586674 Mon Sep 17 00:00:00 2001
From: Xiaodan Wang <bala@ciandt.com>
Date: Thu, 24 Mar 2016 20:53:35 +0800
Subject: Delete unless file from drupal 7

---
 move_user.info | 13 -------------
 1 file changed, 13 deletions(-)
 delete mode 100644 move_user.info

diff --git a/move_user.info b/move_user.info
deleted file mode 100644
index 7a95af5..0000000
--- a/move_user.info
+++ /dev/null
@@ -1,13 +0,0 @@
-name = Move user
-description = Cancel user accounts and reassign content to another user
-core = 7.x
-package = Other
-files[] = move_user.module
-scripts[] = move-user.js
-
-; Information added by Drupal.org packaging script on 2014-03-07
-version = "7.x-1.x-dev"
-core = "7.x"
-project = "move_user"
-datestamp = "1394178807"
-
-- 
1.9.1


From a4c9340231d058641163a9ea0091f638f79c1a68 Mon Sep 17 00:00:00 2001
From: Xiaodan Wang <bala@ciandt.com>
Date: Fri, 25 Mar 2016 13:47:06 +0800
Subject: Fix code standarings

---
 move-user.js               | 25 +++++++++++++++----------
 move_user.module           |  8 ++++----
 src/Tests/MoveUserTest.php | 21 +++++++++++----------
 3 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/move-user.js b/move-user.js
index 09d9bc4..908543c 100644
--- a/move-user.js
+++ b/move-user.js
@@ -1,3 +1,7 @@
+/**
+ * @file
+ */
+
 (function ($) {
 
   Drupal.behaviors.moveUserAdmin = {
@@ -5,21 +9,22 @@
     attach: function (context, settings) {
       var formItemReassignUser = $('.form-item-reassign-user', context);
       var cancelMethodsWrapper = $("#edit-user-cancel-method", context);
-      if ($('[value=move_user_reassign]').is(':checked')){
+      if ($('[value=move_user_reassign]').is(':checked')) {
          formItemReassignUser.appendTo(cancelMethodsWrapper).show();
-      } else {
+      }
+      else {
         formItemReassignUser.hide();
       }
       $("#edit-user-cancel-method input").off().on("change", function (e) {
-          if ($(e.target).val() == 'move_user_reassign') {
-            formItemReassignUser.appendTo(cancelMethodsWrapper).fadeIn(200);
-          } else {
-            formItemReassignUser.hide();
-          }
-        });
-
+        if ($(e.target).val() == 'move_user_reassign') {
+          formItemReassignUser.appendTo(cancelMethodsWrapper).fadeIn(200);
+        }
+        else {
+          formItemReassignUser.hide();
+        }
+      });
 
     }
   };
 
-})(jQuery);
\ No newline at end of file
+})(jQuery);
diff --git a/move_user.module b/move_user.module
index bc6d679..ccacdb4 100644
--- a/move_user.module
+++ b/move_user.module
@@ -1,11 +1,11 @@
-<?php 
+<?php
 /**
  * @file
  * Adds a new method for cancelling user accounts.
  */
 
 /**
- * Implement of hook_user_cancel_menthods_alter().
+ * Implements hook_user_cancel_menthods_alter().
  */
 function move_user_user_cancel_methods_alter(&$methods) {
   unset($methods['user_cancel_reassign']);
@@ -18,7 +18,7 @@ function move_user_user_cancel_methods_alter(&$methods) {
 }
 
 /**
- * Implement of hook_form_alter().
+ * Implements hook_form_alter().
  */
 function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
   if ($form_id == 'user_cancel_form' || $form_id == 'user_multiple_cancel_confirm') {
@@ -36,7 +36,7 @@ function move_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$for
 }
 
 /**
- * Implement of hook_user_cancel().
+ * Implements hook_user_cancel().
  */
 function move_user_user_cancel($edit, $account, $method) {
   $new_uid = $edit['reassign_user'];
diff --git a/src/Tests/MoveUserTest.php b/src/Tests/MoveUserTest.php
index d2d8496..9462f46 100644
--- a/src/Tests/MoveUserTest.php
+++ b/src/Tests/MoveUserTest.php
@@ -3,15 +3,15 @@
  * @file
  * Test case for testing the move_user module.
  *
- * This file contains the test cases to check if move user is performing correctly.
+ * This file contains the test cases to check if move user is done correctly.
  */
 
 namespace Drupal\move_user\Tests;
 
-use \Drupal\simpletest\WebTestBase;
-
 /**
- * Create two users and use one user to create few nodes, 
+ * Move user test case.
+ *
+ * Create two users and use one user to create few nodes,
  * then use the administrator user to delete the nodes created,
  * reassign the nodes to the second user.
  *
@@ -34,10 +34,10 @@ class MoveUserTest extends \Drupal\node\Tests\NodeTestBase {
     parent::setUp();
 
     $this->originalAuthor = $this->drupalCreateUser(array('create page content', 'edit own page content'));
-    // Create another admin user for delete the web_user
+    // Create another admin user for delete the web_user.
     $this->newAuthor = $this->drupalCreateUser(array('create page content', 'edit own page content'));
 
-    // create a page node with current user
+    // Create a page node with current user.
     $this->createdNode = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->originalAuthor->id()));
 
   }
@@ -46,22 +46,23 @@ class MoveUserTest extends \Drupal\node\Tests\NodeTestBase {
    * Tests to reassign node to another user.
    */
   public function testCancelUserMoveUser() {
-    // Create administrator user and login
+    // Create administrator user and login.
     $admin_user = $this->drupalCreateUser(array('administer nodes', 'administer users'));
     $this->drupalLogin($admin_user);
 
-    // Cancel the author page
+    // Cancel the author page.
     $cancel_user_url = 'user/' . $this->originalAuthor->id() . '/cancel';
     $this->drupalGet($cancel_user_url);
 
     $edit = array();
     $edit['user_cancel_method'] = 'move_user_reassign';
     $edit['reassign_user'] = $this->newAuthor->getUserName() . ' (' . $this->newAuthor->id() . ')';
-    $edit['confirm'] = 1; 
+    $edit['confirm'] = 1;
     $this->drupalPostForm($cancel_user_url, $edit, t('Cancel account'));
 
-    // check if the node's author is changed to newAuthor
+    // Check if the node's author is changed to newAuthor.
     $node = node_load($this->createdNode->id());
     $this->assertEqual($node->getOwnerId(), $this->newAuthor->id(), 'Ensure that the node is reassigned to the new user correctly.');
   }
+
 }
-- 
1.9.1

