classes/user/UserAction.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 class UserAction {
00020 
00024    function UserAction() {
00025    }
00026 
00034    function mergeUsers($oldUserId, $newUserId) {
00035       // Need both user ids for merge
00036       if (empty($oldUserId) || empty($newUserId)) {
00037          return false;
00038       }
00039 
00040       $paperDao =& DAORegistry::getDAO('PaperDAO');
00041       foreach ($paperDao->getPapersByUserId($oldUserId) as $paper) {
00042          $paper->setUserId($newUserId);
00043          $paperDao->updatePaper($paper);
00044          unset($paper);
00045       }
00046 
00047       $commentDao =& DAORegistry::getDAO('CommentDAO');
00048       foreach ($commentDao->getCommentsByUserId($oldUserId) as $comment) {
00049          $comment->setUserId($newUserId);
00050          $commentDao->updateComment($comment);
00051          unset($comment);
00052       }
00053 
00054       $paperNoteDao =& DAORegistry::getDAO('PaperNoteDAO');
00055       $paperNotes =& $paperNoteDao->getPaperNotesByUserId($oldUserId);
00056       while ($paperNote =& $paperNotes->next()) {
00057          $paperNote->setUserId($newUserId);
00058          $paperNoteDao->updatePaperNote($paperNote);
00059          unset($paperNote);
00060       }
00061 
00062       $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00063       $editAssignments =& $editAssignmentDao->getEditAssignmentsByUserId($oldUserId);
00064       while ($editAssignment =& $editAssignments->next()) {
00065          $editAssignment->setDirectorId($newUserId);
00066          $editAssignmentDao->updateEditAssignment($editAssignment);
00067          unset($editAssignment);
00068       }
00069 
00070       $directorSubmissionDao =& DAORegistry::getDAO('DirectorSubmissionDAO');
00071       $directorSubmissionDao->transferDirectorDecisions($oldUserId, $newUserId);
00072 
00073       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00074       foreach ($reviewAssignmentDao->getReviewAssignmentsByUserId($oldUserId) as $reviewAssignment) {
00075          $reviewAssignment->setReviewerId($newUserId);
00076          $reviewAssignmentDao->updateReviewAssignment($reviewAssignment);
00077          unset($reviewAssignment);
00078       }
00079 
00080       $paperEmailLogDao =& DAORegistry::getDAO('PaperEmailLogDAO');
00081       $paperEmailLogDao->transferPaperLogEntries($oldUserId, $newUserId);
00082       $paperEventLogDao =& DAORegistry::getDAO('PaperEventLogDAO');
00083       $paperEventLogDao->transferPaperLogEntries($oldUserId, $newUserId);
00084 
00085       $paperCommentDao =& DAORegistry::getDAO('PaperCommentDAO');
00086       foreach ($paperCommentDao->getPaperCommentsByUserId($oldUserId) as $paperComment) {
00087          $paperComment->setAuthorId($newUserId);
00088          $paperCommentDao->updatePaperComment($paperComment);
00089          unset($paperComment);
00090       }
00091 
00092       $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
00093       $accessKeyDao->transferAccessKeys($oldUserId, $newUserId);
00094 
00095       // Transfer old user's valid registrations if new user does not
00096       // have similar registrations of if they're invalid
00097       $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00098       $oldUserRegistrations =& $registrationDao->getRegistrationsByUser($oldUserId);
00099 
00100       while ($oldUserRegistration =& $oldUserRegistrations->next()) {
00101          $schedConfId = $oldUserRegistration->getSchedConfId();
00102          $oldUserValidRegistration = $registrationDao->isValidRegistrationByUser($oldUserId, $schedConfId);
00103 
00104          if ($oldUserValidRegistration) {
00105             // Check if new user has a valid registration for sched conf
00106             $newUserRegistrationId = $registrationDao->getRegistrationIdByUser($newUserId, $schedConfId);
00107 
00108             if (empty($newUserRegistrationId)) {
00109                // New user does not have this registration, transfer old user's
00110                $oldUserRegistration->setUserId($newUserId);
00111                $registrationDao->updateRegistration($oldUserRegistration);
00112             } elseif (!$registrationDao->isValidRegistrationByUser($newUserId, $schedConfId)) {
00113                // New user has a registration but it's invalid. Delete it and
00114                // transfer old user's valid one
00115                $registrationDao->deleteRegistrationByUserIdSchedConf($newUserId, $schedConfId);
00116                $oldUserRegistration->setUserId($newUserId);
00117                $registrationDao->updateRegistration($oldUserRegistration);
00118             }
00119          }
00120       }  
00121 
00122       // Delete any remaining oldUser registrations and associated options 
00123       $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
00124       $oldUserRegistrations =& $registrationDao->getRegistrationsByUser($oldUserId);
00125 
00126       while ($oldUserRegistration =& $oldUserRegistrations->next()) {
00127          $registrationOptionDao->deleteRegistrationOptionAssocByRegistrationId($oldUserRegistration->getRegistrationId());
00128       }
00129       $registrationDao->deleteRegistrationsByUserId($oldUserId);
00130 
00131       // Transfer old user's roles
00132       $roleDao =& DAORegistry::getDAO('RoleDAO');
00133       $userDao =& DAORegistry::getDAO('UserDAO');
00134 
00135       $roles =& $roleDao->getRolesByUserId($oldUserId);
00136       foreach ($roles as $role) {
00137          if (!$roleDao->roleExists($role->getConferenceId(), $role->getSchedConfId(), $newUserId, $role->getRoleId())) {
00138             $role->setUserId($newUserId);
00139             $roleDao->insertRole($role);
00140          }
00141       }
00142       $roleDao->deleteRoleByUserId($oldUserId);
00143 
00144       // Delete the old user and all remaining associated info.
00145       $sessionDao =& DAORegistry::getDAO('SessionDAO');
00146       $sessionDao->deleteSessionsByUserId($oldUserId);
00147       $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
00148       $temporaryFileDao->deleteTemporaryFilesByUserId($oldUserId);
00149       $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO');
00150       $userSettingsDao->deleteSettings($oldUserId);
00151       $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
00152       $groupMembershipDao->deleteMembershipByUserId($oldUserId);
00153       $trackDirectorsDao =& DAORegistry::getDAO('TrackDirectorsDAO');
00154       $trackDirectorsDao->deleteDirectorsByUserId($oldUserId);
00155       $userDao->deleteUserById($oldUserId);
00156 
00157       return true;
00158    }
00159 
00160 }
00161 
00162 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7