public function doRun()
 {
     if (!class_exists('MergeUser')) {
         throw new Exception('Extension:UserMerge is not installed');
     }
     $from = $this->params['from'];
     $to = $this->params['to'];
     $this->updateStatus('inprogress');
     $toUser = $this->maybeCreateNewUser($to);
     $renamingUser = $this->getRenameUser();
     foreach ($from as $olduser) {
         // Merge the users in order
         $um = new MergeUser(User::newFromName($olduser), $toUser, new UserMergeLogger(), MergeUser::USE_MULTI_COMMIT);
         $um->merge($renamingUser);
         $um->delete($renamingUser, 'wfMessage');
     }
     $this->done();
     return true;
 }
示例#2
0
        $dialogBox->question($question);
    }
    if ($cmd == 'exMerge') {
        $uidToKeep = $userInput->getMandatory('uidToKeep');
        $uidToRemove = $userInput->getMandatory('uidToRemove');
        if ($uidToKeep == $uidToRemove) {
            throw new Exception(get_lang('Cannot merge one user account with itself'));
        }
        if (!user_get_properties($uidToKeep)) {
            throw new Exception(get_lang('User to keep not found'));
        }
        if (!user_get_properties($uidToRemove)) {
            throw new Exception(get_lang('User to remove not found'));
        }
        $mergeUser = new MergeUser();
        $mergeUser->merge($uidToRemove, $uidToKeep);
        if ($mergeUser->hasError()) {
            $dialogBox->error(get_lang('Some errors have occured while merging those user account, check the log table in the platform main database for more details'));
        } else {
            $dialogBox->success(get_lang('User accounts merged'));
        }
    }
} catch (Exception $e) {
    $dialogBox->error(get_lang('Cannot perform the requested action') . ' : <br />' . $e->getMessage());
    pushClaroMessage('<pre>' . $e->__toString() . '</pre>');
}
ClaroBreadCrumbs::getInstance()->prepend(get_lang('Administration'), get_path('rootAdminWeb'));
ClaroBreadCrumbs::getInstance()->setCurrent(get_lang('Merge user accounts'), php_self());
ClaroBody::getInstance()->appendContent(claro_html_tool_title(get_lang('Merge user accounts')));
ClaroBody::getInstance()->appendContent($dialogBox->render());
echo Claroline::getInstance()->display->render();