00001 <?php
00002
00015
00016
00017 require(dirname(__FILE__) . '/bootstrap.inc.php');
00018
00019 class mergeUsers extends CommandLineTool {
00020
00022 var $username1;
00023
00025 var $username2;
00026
00031 function mergeUsers($argv = array()) {
00032 parent::CommandLineTool($argv);
00033
00034 if (!isset($this->argv[0]) || !isset($this->argv[1]) ) {
00035 $this->usage();
00036 exit(1);
00037 }
00038
00039 $this->username1 = $this->argv[0];
00040 $this->username2 = $this->argv[1];
00041 }
00042
00046 function usage() {
00047 echo "OCS 2 merge users tool\n"
00048 . "Use this tool to merge two OCS 2 user accounts.\n\n"
00049 . "Usage: {$this->scriptName} [username1] [username2]\n"
00050 . "username1 The first user to merge.\n"
00051 . "username2 The second user to merge. All roles and content associated\n"
00052 . " with this user account will be transferred to the user account\n"
00053 . " that corresponds to username1. The user account that corresponds\n"
00054 . " to username2 will be deleted.\n";
00055 }
00056
00060 function execute() {
00061 $userDao =& DAORegistry::getDAO('UserDAO');
00062
00063 $oldUser =& $userDao->getUserbyUsername($this->username2);
00064 $newUser =& $userDao->getUserbyUsername($this->username1);
00065
00066 $oldUserId = isset($oldUser) ? $oldUser->getId() : null;
00067 $newUserId = isset($newUser) ? $newUser->getId() : null;
00068
00069 if (empty($oldUserId)) {
00070 printf("Error: '%s' is not a valid username.\n",
00071 $this->username2);
00072 exit;
00073 }
00074
00075 if (empty($newUserId)) {
00076 printf("Error: '%s' is not a valid username.\n",
00077 $this->username1);
00078 exit;
00079 }
00080
00081
00082 import('user.UserAction');
00083 UserAction::mergeUsers($oldUserId, $newUserId);
00084
00085 printf("Merge completed: '%s' merged into '%s'.\n",
00086 $this->username2,
00087 $this->username1
00088 );
00089 }
00090 }
00091
00092 $tool = new mergeUsers(isset($argv) ? $argv : array());
00093 $tool->execute();
00094
00095 ?>