00001 <?php
00002
00015
00016
00017
00018 require(dirname(__FILE__) . '/includes/cliTool.inc.php');
00019
00020 class mergeUsers extends CommandLineTool {
00021
00023 var $username1;
00024
00026 var $username2;
00027
00032 function mergeUsers($argv = array()) {
00033 parent::CommandLineTool($argv);
00034
00035 if (!isset($this->argv[0]) || !isset($this->argv[1]) ) {
00036 $this->usage();
00037 exit(1);
00038 }
00039
00040 $this->username1 = $this->argv[0];
00041 $this->username2 = $this->argv[1];
00042 }
00043
00047 function usage() {
00048 echo "OJS 2 merge users tool\n"
00049 . "Use this tool to merge two OJS 2 user accounts.\n\n"
00050 . "Usage: {$this->scriptName} [username1] [username2]\n"
00051 . "username1 The first user to merge.\n"
00052 . "username2 The second user to merge. All roles and content associated\n"
00053 . " with this user account will be transferred to the user account\n"
00054 . " that corresponds to username1. The user account that corresponds\n"
00055 . " to username2 will be deleted.\n";
00056 }
00057
00061 function execute() {
00062 $roleDao =& DAORegistry::getDAO('RoleDAO');
00063 $userDao =& DAORegistry::getDAO('UserDAO');
00064
00065 $oldUser =& $userDao->getUserbyUsername($this->username2);
00066 $newUser =& $userDao->getUserbyUsername($this->username1);
00067
00068 $oldUserId = isset($oldUser) ? $oldUser->getUserId() : null;
00069 $newUserId = isset($newUser) ? $newUser->getUserId() : null;
00070
00071 if (empty($oldUserId)) {
00072 printf("Error: '%s' is not a valid username.\n",
00073 $this->username2);
00074 exit;
00075 }
00076
00077 if (empty($newUserId)) {
00078 printf("Error: '%s' is not a valid username.\n",
00079 $this->username1);
00080 exit;
00081 }
00082
00083
00084 $articleDao =& DAORegistry::getDAO('ArticleDAO');
00085 foreach ($articleDao->getArticlesByUserId($oldUserId) as $article) {
00086 $article->setUserId($newUserId);
00087 $articleDao->updateArticle($article);
00088 unset($article);
00089 }
00090
00091 $commentDao =& DAORegistry::getDAO('CommentDAO');
00092 foreach ($commentDao->getCommentsByUserId($oldUserId) as $comment) {
00093 $comment->setUserId($newUserId);
00094 $commentDao->updateComment($comment);
00095 unset($comment);
00096 }
00097
00098 $articleNoteDao =& DAORegistry::getDAO('ArticleNoteDAO');
00099 $articleNotes =& $articleNoteDao->getArticleNotesByUserId($oldUserId);
00100 while ($articleNote =& $articleNotes->next()) {
00101 $articleNote->setUserId($newUserId);
00102 $articleNoteDao->updateArticleNote($articleNote);
00103 unset($articleNote);
00104 }
00105
00106 $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00107 $editAssignments =& $editAssignmentDao->getEditAssignmentsByUserId($oldUserId);
00108 while ($editAssignment =& $editAssignments->next()) {
00109 $editAssignment->setEditorId($newUserId);
00110 $editAssignmentDao->updateEditAssignment($editAssignment);
00111 unset($editAssignment);
00112 }
00113
00114 $editorSubmissionDao =& DAORegistry::getDAO('EditorSubmissionDAO');
00115 $editorSubmissionDao->transferEditorDecisions($oldUserId, $newUserId);
00116
00117 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00118 foreach ($reviewAssignmentDao->getReviewAssignmentsByUserId($oldUserId) as $reviewAssignment) {
00119 $reviewAssignment->setReviewerId($newUserId);
00120 $reviewAssignmentDao->updateReviewAssignment($reviewAssignment);
00121 unset($reviewAssignment);
00122 }
00123
00124 $copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
00125 $copyeditorSubmissions =& $copyeditorSubmissionDao->getCopyeditorSubmissionsByCopyeditorId($oldUserId);
00126 while ($copyeditorSubmission =& $copyeditorSubmissions->next()) {
00127 $copyeditorSubmission->setCopyeditorId($newUserId);
00128 $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
00129 unset($copyeditorSubmission);
00130 }
00131
00132 $layoutEditorSubmissionDao =& DAORegistry::getDAO('LayoutEditorSubmissionDAO');
00133 $layoutEditorSubmissions =& $layoutEditorSubmissionDao->getSubmissions($oldUserId);
00134 while ($layoutEditorSubmission =& $layoutEditorSubmissions->next()) {
00135 $layoutAssignment =& $layoutEditorSubmission->getLayoutAssignment();
00136 $layoutAssignment->setEditorId($newUserId);
00137 $layoutEditorSubmissionDao->updateSubmission($layoutEditorSubmission);
00138 unset($layoutAssignment);
00139 unset($layoutEditorSubmission);
00140 }
00141
00142 $proofreaderSubmissionDao =& DAORegistry::getDAO('ProofreaderSubmissionDAO');
00143 $proofreaderSubmissions =& $proofreaderSubmissionDao->getSubmissions($oldUserId);
00144 while ($proofreaderSubmission =& $proofreaderSubmissions->next()) {
00145 $proofAssignment =& $proofreaderSubmission->getProofAssignment();
00146 $proofAssignment->setProofreaderId($newUserId);
00147 $proofreaderSubmissionDao->updateSubmission($proofreaderSubmission);
00148 unset($proofAssignment);
00149 unset($proofreaderSubmission);
00150 }
00151
00152 $articleEmailLogDao =& DAORegistry::getDAO('ArticleEmailLogDAO');
00153 $articleEmailLogDao->transferArticleLogEntries($oldUserId, $newUserId);
00154 $articleEventLogDao =& DAORegistry::getDAO('ArticleEventLogDAO');
00155 $articleEventLogDao->transferArticleLogEntries($oldUserId, $newUserId);
00156
00157 $articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
00158 foreach ($articleCommentDao->getArticleCommentsByUserId($oldUserId) as $articleComment) {
00159 $articleComment->setAuthorId($newUserId);
00160 $articleCommentDao->updateArticleComment($articleComment);
00161 unset($articleComment);
00162 }
00163
00164 $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
00165 $accessKeyDao->transferAccessKeys($oldUserId, $newUserId);
00166
00167
00168 $sessionDao =& DAORegistry::getDAO('SessionDAO');
00169 $sessionDao->deleteSessionsByUserId($oldUserId);
00170 $subscriptionDao =& DAORegistry::getDAO('SubscriptionDAO');
00171 $subscriptionDao->deleteSubscriptionsByUserId($oldUserId);
00172 $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
00173 $temporaryFileDao->deleteTemporaryFilesByUserId($oldUserId);
00174 $notificationStatusDao =& DAORegistry::getDAO('NotificationStatusDAO');
00175 $notificationStatusDao->deleteNotificationStatusByUserId($oldUserId);
00176 $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO');
00177 $userSettingsDao->deleteSettings($oldUserId);
00178 $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
00179 $groupMembershipDao->deleteMembershipByUserId($oldUserId);
00180 $sectionEditorsDao =& DAORegistry::getDAO('SectionEditorsDAO');
00181 $sectionEditorsDao->deleteEditorsByUserId($oldUserId);
00182
00183
00184 $roles =& $roleDao->getRolesByUserId($oldUserId);
00185 foreach ($roles as $role) {
00186 if (!$roleDao->roleExists($role->getJournalId(), $newUserId, $role->getRoleId())) {
00187 $role->setUserId($newUserId);
00188 $roleDao->insertRole($role);
00189 }
00190 }
00191 $roleDao->deleteRoleByUserId($oldUserId);
00192
00193 $userDao->deleteUserById($oldUserId);
00194
00195 printf("Merge completed: '%s' merged into '%s'.\n",
00196 $this->username2,
00197 $this->username1
00198 );
00199 }
00200 }
00201
00202 $tool = &new mergeUsers(isset($argv) ? $argv : array());
00203 $tool->execute();
00204 ?>