• Main Page
  • Modules
  • Classes
  • Files
  • File List

tools/mergeUsers.php

00001 <?php
00002 
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 "OMP 2 merge users tool\n"
00048          . "Use this tool to merge two OMP 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       $roleDao =& DAORegistry::getDAO('RoleDAO');
00062       $userDao =& DAORegistry::getDAO('UserDAO');
00063 
00064       $oldUser =& $userDao->getByUsername($this->username2);
00065       $newUser =& $userDao->getByUsername($this->username1);
00066 
00067       $oldUserId = isset($oldUser) ? $oldUser->getId() : null;
00068       $newUserId = isset($newUser) ? $newUser->getId() : null;
00069 
00070       if (empty($oldUserId)) {
00071          printf("Error: '%s' is not a valid username.\n",
00072             $this->username2);
00073          exit;
00074       }
00075 
00076       if (empty($newUserId)) {
00077          printf("Error: '%s' is not a valid username.\n",
00078             $this->username1);
00079          exit;
00080       }
00081 
00082       // Both user IDs are valid. Merge the accounts.
00083       import('classes.user.UserAction');
00084       $userAction = new UserAction();
00085       $userAction->mergeUsers($oldUserId, $newUserId);
00086 
00087       printf("Merge completed: '%s' merged into '%s'.\n",
00088          $this->username2,
00089          $this->username1
00090       );
00091    }
00092 }
00093 
00094 $tool = new mergeUsers(isset($argv) ? $argv : array());
00095 $tool->execute();
00096 ?>

Generated on Mon Sep 17 2012 13:58:56 for Open Monograph Press by  doxygen 1.7.1