classes/site/ImportOCS1.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('user.User');
00020 import('conference.Conference');
00021 import('conference.Track');
00022 import('security.Role');
00023 import('registration.Registration');
00024 import('registration.RegistrationType');
00025 import('currency.Currency');
00026 import('paper.Paper');
00027 import('paper.PaperComment');
00028 import('paper.PaperFile');
00029 import('paper.PaperGalley');
00030 import('paper.PaperHTMLGalley');
00031 import('paper.PaperNote');
00032 import('paper.Author');
00033 import('paper.PublishedPaper');
00034 import('paper.SuppFile');
00035 import('submission.common/Action');
00036 import('submission.author.AuthorSubmission');
00037 import('submission.reviewer.ReviewerSubmission');
00038 import('submission.editAssignment.EditAssignment');
00039 import('submission.reviewAssignment.ReviewAssignment');
00040 import('comment.Comment');
00041 import('file.PaperFileManager');
00042 import('file.PublicFileManager');
00043 import('search.PaperSearchIndex');
00044 
00045 
00046 class ImportOCS1 {
00047 
00048    //
00049    // Private variables
00050    //
00051 
00052    var $importPath;
00053    var $conferencePath;
00054    var $conference;
00055    var $conferenceId = 0;
00056    var $conferenceIsNew;
00057 
00058    var $dbtable = array();
00059 
00060    var $schedConfMap = array();
00061    var $trackMap = array();
00062    var $paperMap = array();
00063    var $reviewerMap = array();
00064 
00065    var $importDBConn;
00066    var $importDao;
00067 
00068    var $indexUrl;
00069    var $globalConfigInfo;
00070    var $conferenceInfo = array();
00071 
00072    var $userCount = 0;
00073    var $paperCount = 0;
00074 
00075    var $options;
00076    var $error;
00077 
00079    var $conflicts;
00080 
00082    var $errors;
00083 
00087    function ImportOCS1() {
00088       // Note: generally Request's auto-detection won't work correctly
00089       // when run via CLI so use config setting if available
00090       $this->indexUrl = Config::getVar('general', 'base_url');
00091       if ($this->indexUrl)
00092          $this->indexUrl .= '/' . INDEX_SCRIPTNAME;
00093       else
00094          $this->indexUrl = Request::getIndexUrl();
00095 
00096       $this->conflicts = array();
00097       $this->errors = array();
00098    }
00099 
00104    function error($message = null) {
00105       if (isset($message)) {
00106          $this->error = $message;
00107       }
00108       return $this->error;
00109    }
00110 
00116    function hasOption($option) {
00117       return in_array($option, $this->options);
00118    }
00119 
00129    function import($conferencePath, $importPath, $options = array()) {
00130       @set_time_limit(0);
00131       $this->conferencePath = $conferencePath;
00132       $this->importPath = $importPath;
00133       $this->options = $options;
00134 
00135       // Force a new database connection
00136       $dbconn =& DBConnection::getInstance();
00137       $dbconn->reconnect(true);
00138 
00139       // Create a connection to the old database
00140       if (!@include($this->importPath . '/include/db.inc.php')) { // Suppress E_NOTICE messages
00141          $this->error('Failed to load ' . $this->importPath . '/include/db.php');
00142          return false;
00143       }
00144 
00145       // Assumes no character set (not supported by OCS 1.x)
00146       // Forces open a new connection
00147       $this->importDBConn = new DBConnection($db_type, $db_host, $db_login, $db_password, $db_name, false, false, true, false, true);
00148       $dbconn =& $this->importDBConn->getDBConn();
00149 
00150       if (!$this->importDBConn->isConnected()) {
00151          $this->error('Database connection error: ' . $dbconn->errorMsg());
00152          return false;
00153       }
00154 
00155       $this->dbtable = $dbtable;
00156       $this->importDao = new DAO($dbconn);
00157 
00158       if (!$this->loadGlobalConfig()) {
00159          $this->error('Unsupported or unrecognized OCS version');
00160          return false;
00161       }
00162 
00163       $this->importConference();
00164       $this->importSchedConfs();
00165       $this->importTracks();
00166       $this->importPapers();
00167       $this->importReviewers();
00168       $this->importReviews();
00169 
00170       if ($this->hasOption('importRegistrations')) {
00171          $this->importRegistrations();
00172       }
00173 
00174       // Rebuild search index
00175       $this->rebuildSearchIndex();
00176 
00177       return $this->conferenceId;
00178    }
00179 
00184    function loadGlobalConfig() {
00185       $dbtable = $this->dbtable;
00186       // Load global config
00187       $result =& $this->importDao->retrieve("SELECT * FROM $dbtable[conference_global]");
00188       $this->globalConfigInfo =& $result->fields;
00189       $result->Close();
00190 
00191       if (!isset($this->globalConfigInfo['admin_login'])) {
00192          return false;
00193       }
00194 
00195       return true;
00196    }
00197 
00198 
00199    //
00200    // Conference
00201    //
00202 
00203    function importConference() {
00204       // If necessary, create the conference.
00205       $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00206       if (!$conference =& $conferenceDao->getConferenceByPath($this->conferencePath)) {
00207          if ($this->hasOption('verbose')) {
00208             printf("Creating conference\n");
00209          }
00210          unset($conference);
00211          $conference = new Conference();
00212          $conference->setPath($this->conferencePath);
00213          $conference->setPrimaryLocale(AppLocale::getLocale());
00214          $conference->setEnabled(true);
00215          $this->conferenceId = $conferenceDao->insertConference($conference);
00216          $conferenceDao->resequenceConferences();
00217          $conference->updateSetting('title', array(AppLocale::getLocale() => $this->globalConfigInfo['name']), null, true);
00218 
00219          $this->conferenceIsNew = true;
00220       } else {
00221          if ($this->hasOption('verbose')) {
00222             printf("Using existing conference\n");
00223          }
00224          $conference->updateSetting('title', array(AppLocale::getLocale() => $this->globalConfigInfo['name']), null, true);
00225          $this->conferenceId = $conference->getId();
00226          $this->conferenceIsNew = false;
00227       }
00228       $this->conference =& $conference;
00229 
00230       $roleDao =& DAORegistry::getDAO('RoleDAO');
00231       if ($this->conferenceIsNew) {
00232          // All site admins should get a manager role by default
00233          $admins = $roleDao->getUsersByRoleId(ROLE_ID_SITE_ADMIN);
00234          foreach ($admins->toArray() as $admin) {
00235             $role = new Role();
00236             $role->setConferenceId($this->conferenceId);
00237             $role->setUserId($admin->getId());
00238             $role->setRoleId(ROLE_ID_CONFERENCE_MANAGER);
00239             $roleDao->insertRole($role);
00240          }
00241 
00242          // Install the default RT versions.
00243          import('rt.ocs.ConferenceRTAdmin');
00244          $conferenceRtAdmin = new ConferenceRTAdmin($this->conferenceId);
00245          $conferenceRtAdmin->restoreVersions(false);
00246 
00247          $confSettings = array(
00248             'itemsPerPage' => array('int', 25),
00249             'numPageLinks' => array('int', 10),
00250          );
00251 
00252          foreach ($confSettings as $settingName => $settingInfo) {
00253             list($settingType, $settingValue) = $settingInfo;
00254             $this->conference->updateSetting($settingName, $settingValue, $settingType);
00255          }
00256       }
00257 
00258    }
00259 
00260 
00261    //
00262    // Scheduled Conference
00263    //
00264 
00265    function importSchedConfs() {
00266       if ($this->hasOption('verbose')) {
00267          printf("Importing scheduled conferences\n");
00268       }
00269 
00270       $dbtable = $this->dbtable;
00271       $result =& $this->importDao->retrieve("SELECT id FROM $dbtable[conference] ORDER BY id");
00272       $conferenceIds = array();
00273       while (!$result->EOF) {
00274          $conferenceIds[] =& $result->fields[0];
00275          $result->MoveNext();
00276       }
00277       $result->Close();
00278 
00279       foreach ($conferenceIds as $id) {
00280          $this->importSchedConf($id);
00281       }
00282    }
00283 
00288    function importSchedConf($id) {
00289       $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00290       $userDao =& DAORegistry::getDAO('UserDAO');
00291 
00292       if ($this->hasOption('verbose')) {
00293          printf("Importing OCS 1.x conference ID $id\n");
00294       }
00295       $dbtable = $this->dbtable;
00296 
00297       // Load sched conf config
00298       $result =& $this->importDao->retrieve("SELECT * FROM $dbtable[conference] WHERE id = ?", array($id));
00299       $this->conferenceInfo[$id] =& $result->fields;
00300       $result->Close();
00301 
00302       $conferenceInfo =& $this->conferenceInfo[$id];
00303       // Create/fetch scheduled conference
00304       if (!$schedConf =& $schedConfDao->getSchedConfByPath($id, $this->conferenceId)) {
00305          unset($schedConf);
00306          $schedConf = new SchedConf();
00307          $schedConf->setConferenceId($this->conferenceId);
00308          $schedConf->setPath($id);
00309          $schedConfDao->insertSchedConf($schedConf);
00310          $schedConfDao->resequenceSchedConfs($this->conferenceId);
00311          $schedConf->updateSetting('title', array(AppLocale::getLocale() => $conferenceInfo['name']), null, true);
00312       } else {
00313          $schedConf->updateSetting('title', array(AppLocale::getLocale() => $conferenceInfo['name']), null, true);
00314       }
00315 
00316       $this->schedConfMap[$id] =& $schedConf;
00317 
00318       $schedConfSettings = array(
00319          'contactEmail' => array('string', Core::cleanVar($this->conferenceInfo[$id]['contact_email'])),
00320          'contactName' => array('string', Core::cleanVar($this->conferenceInfo[$id]['contact_name']))
00321       );
00322 
00323       foreach ($schedConfSettings as $settingName => $settingInfo) {
00324          list($settingType, $settingValue) = $settingInfo;
00325          $schedConf->updateSetting($settingName, $settingValue, $settingType);
00326       }
00327    }
00328 
00329 
00333    function importRegistrations() {
00334       if ($this->hasOption('verbose')) {
00335          printf("Importing registrations\n");
00336       }
00337 
00338       $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00339       $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00340       $userDao =& DAORegistry::getDAO('UserDAO');
00341 
00342       $registrationTypes = array();
00343 
00344       foreach ($this->conferenceInfo as $conferenceId => $conferenceInfo) {
00345          $levels = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_levels'])));
00346          $fees = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_fees'])));
00347          $levelsLate = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_levels_late'])));
00348          $feesLate = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_fees_late'])));
00349 
00350          $lateDate = Core::cleanVar($conferenceInfo['reg_late_date']);
00351          $schedConf =& $this->schedConfMap[$conferenceId];
00352 
00353          foreach ($levels as $key => $level) {
00354             $fee = $fees[$key];
00355             $registrationType = new RegistrationType();
00356             $registrationType->setSchedConfId($schedConf->getId());
00357             $registrationType->setName($level, AppLocale::getLocale());
00358             $registrationType->setCost($fee);
00359             $registrationType->setCurrencyCodeAlpha('USD'); // FIXME?
00360             $registrationType->setOpeningDate(Core::cleanVar($conferenceInfo['accept_deadline']));
00361             $registrationType->setClosingDate($lateDate);
00362             $registrationType->setAccess(REGISTRATION_TYPE_ACCESS_ONLINE);
00363             $registrationType->setPublic(0);
00364             $registrationType->setInstitutional(0);
00365             $registrationType->setMembership(0);
00366             $registrationType->setSequence($key);
00367             $registrationTypeDao->insertRegistrationType($registrationType);
00368             $registrationTypes[substr($level, 0, 60)] =& $registrationType; // Truncated in 1.x DB
00369             unset($registrationType);
00370          }
00371 
00372          foreach ($levelsLate as $key => $level) {
00373             $fee = $feesLate[$key];
00374             $registrationType = new RegistrationType();
00375             $registrationType->setSchedConfId($schedConf->getId());
00376             $registrationType->setName($level . ' (Late)', AppLocale::getLocale());
00377             $registrationType->setCost($fee);
00378             $registrationType->setCurrencyCodeAlpha('USD'); // FIXME?
00379             $registrationType->setOpeningDate($lateDate);
00380             $registrationType->setClosingDate(Core::cleanVar($conferenceInfo['start_date']));
00381             $registrationType->setAccess(REGISTRATION_TYPE_ACCESS_ONLINE);
00382             $registrationType->setPublic(0);
00383             $registrationType->setInstitutional(0);
00384             $registrationType->setMembership(0);
00385             $registrationType->setSequence($key);
00386             $registrationTypeDao->insertRegistrationType($registrationType);
00387             $registrationTypes[substr($level, 0, 60) . ' (Late)'] =& $registrationType; // Truncated in 1.x DB
00388             unset($registrationType);
00389          }
00390       }
00391 
00392       $result =& $this->importDao->retrieve('SELECT * FROM registrants ORDER BY cf, id');
00393       while (!$result->EOF) {
00394          $row =& $result->fields;
00395          $schedConf =& $this->schedConfMap[$row['cf']];
00396 
00397          $email = Core::cleanVar($row['email']);
00398 
00399          if (!$user =& $userDao->getUserByEmail($email)) {
00400             // The user doesn't exist by email; create one.
00401             $name = Core::cleanVar($row['name']);
00402             $nameParts = split(' ', $name);
00403 
00404             $lastName = array_pop($nameParts);
00405             $firstName = join(' ', $nameParts);
00406 
00407             $user = new User();
00408             $user->setEmail($email);
00409             $user->setFirstName($firstName);
00410             $user->setLastName($lastName);
00411             $user->setPhone(Core::cleanVar($row['phone']));
00412             $user->setFax(Core::cleanVar($row['fax']));
00413             $user->setMailingAddress(Core::cleanVar($row['address']));
00414 
00415             $i = "";
00416             while ($userDao->userExistsByUsername($lastName . $i)) $i++;
00417             $user->setUsername($lastName . $i);
00418 
00419             $user->setDateRegistered($row['date_registered']);
00420             $user->setDateLastLogin(null);
00421             $user->setMustChangePassword(1);
00422 
00423             $password = Validation::generatePassword();
00424             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password));
00425 
00426             $userDao->insertUser($user);
00427 
00428             if ($this->hasOption('emailUsers')) {
00429                import('mail.MailTemplate');
00430                $mail = new MailTemplate('USER_REGISTER');
00431 
00432                $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
00433                $mail->assignParams(array('username' => $user->getUsername(), 'password' => $password, 'conferenceName' => $schedConf->getFullTitle()));
00434                $mail->addRecipient($user->getEmail(), $user->getFullName());
00435                $mail->send();
00436 
00437             }
00438          }
00439 
00440          $regLevel = trim(Core::cleanVar($row['reg_level']));
00441          $regFee = Core::cleanVar($row['reg_fee']);
00442          $conferenceInfo =& $this->conferenceInfo[$row['cf']];
00443          $seekingRegLevel = $regLevel . (strtotime($row['date_registered']) > strtotime($conferenceInfo['reg_late_date']) ? ' (Late)':'');
00444          $registrationType =& $registrationTypes[$seekingRegLevel];
00445          if (!$registrationType || $registrationType->getCost() != $regFee) {
00446             if (!$registrationType) $this->errors[] = "Registration data inconsistency: Registration type \"$seekingRegLevel\" not found for user with email $email.";
00447             else {
00448                $this->errors[] = "Registration data inconsistency: Paid registration fee $regFee does not match registration type cost for \"$seekingRegLevel\" (" . $registrationType->getCost() . ") for user with email $email.";
00449                unset($registrationType);
00450             }
00451 
00452             unset($user);
00453             unset($schedConf);
00454             $result->MoveNext();
00455             continue;
00456          }
00457 
00458          if ($registrationDao->registrationExistsByUser($user->getId(), $schedConf->getId())) {
00459             $this->errors[] = "A duplicate registration (level \"$seekingRegLevel\") was skipped for user with email $email.";
00460          } else {
00461             $registration = new Registration();
00462             $registration->setSchedConfId($schedConf->getId());
00463             $registration->setUserId($user->getId());
00464             $registration->setTypeId($registrationType->getTypeId());
00465             if ($row['has_paid'] == 'paid') $registration->setDatePaid(Core::cleanVar($row['date_paid']));
00466             $registration->setSpecialRequests(Core::cleanVar($row['special_requests']));
00467             $registration->setDateRegistered($row['date_registered']);
00468             $registrationDao->insertRegistration($registration);
00469             unset($registration);
00470          }
00471 
00472          unset($user);
00473          unset($registrationType);
00474          unset($conferenceInfo);
00475          unset($schedConf);
00476 
00477          $result->MoveNext();
00478       }
00479       $result->Close();
00480    }
00481 
00485    function importTracks() {
00486       if ($this->hasOption('verbose')) {
00487          printf("Importing tracks\n");
00488       }
00489 
00490       $trackDao =& DAORegistry::getDAO('TrackDAO');
00491 
00492       $result =& $this->importDao->retrieve('SELECT * FROM tracks ORDER BY cf, track_order');
00493       $oldConferenceId = null;
00494       while (!$result->EOF) {
00495          $row =& $result->fields;
00496          if ($oldConferenceId != $row['cf']) {
00497             $sequence = 0;
00498             $oldConferenceId = $row['cf'];
00499          }
00500 
00501          $track = new Track();
00502          $schedConf =& $this->schedConfMap[$row['cf']];
00503          $track->setSchedConfId($schedConf->getId());
00504          $track->setTitle(Core::cleanVar($row['track']), AppLocale::getLocale());
00505          $track->setSequence(++$sequence);
00506          $track->setDirectorRestricted(0);
00507          $track->setMetaReviewed(1);
00508 
00509          $trackId = $trackDao->insertTrack($track);
00510          $this->trackMap[$row['id']] = $trackId;
00511          $result->MoveNext();
00512          unset($track);
00513          unset($schedConf);
00514       }
00515       $result->Close();
00516    }
00517 
00521    function importReviewers() {
00522       if ($this->hasOption('verbose')) {
00523          printf("Importing reviewers\n");
00524       }
00525 
00526       import('file.PaperFileManager');
00527       import('search.PaperSearchIndex');
00528 
00529       $userDao =& DAORegistry::getDAO('UserDAO');
00530       $roleDao =& DAORegistry::getDAO('RoleDAO');
00531 
00532       $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00533       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00534 
00535       $result =& $this->importDao->retrieve('SELECT * FROM reviewers');
00536       while (!$result->EOF) {
00537          $row =& $result->fields;
00538          $schedConf =& $this->schedConfMap[$row['cf']];
00539          $schedConfId = $schedConf->getId();
00540 
00541          $user = $userDao->getUserByUsername(Core::cleanVar($row['login']));
00542          if (!$user) {
00543             unset($user);
00544             $user = new User();
00545             $user->setUsername(Core::cleanVar($row['login']));
00546 
00547             $nameParts = split(' ', Core::cleanVar($row['name']));
00548             $firstName = array_shift($nameParts);
00549             $lastName = join(' ', $nameParts);
00550 
00551             $user->setFirstName(empty($firstName)?'(NONE)':$firstName);
00552             $user->setLastName(empty($lastName)?'(NONE)':$lastName);
00553             $user->setEmail(Core::cleanVar($row['email']));
00554             $user->setDateRegistered(Core::getCurrentDate());
00555             $user->setDateLastLogin(null);
00556             $user->setMustChangePassword(1);
00557 
00558             $password = Validation::generatePassword();
00559             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password));
00560 
00561             if ($this->hasOption('emailUsers')) {
00562                import('mail.MailTemplate');
00563                $mail = new MailTemplate('USER_REGISTER');
00564 
00565                $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
00566                $mail->assignParams(array('username' => $user->getUsername(), 'password' => $password, 'conferenceName' => $schedConf->getFullTitle()));
00567                $mail->addRecipient($user->getEmail(), $user->getFullName());
00568                $mail->send();
00569 
00570             }
00571             $user->setDisabled(0);
00572 
00573             $otherUser =& $userDao->getUserByEmail(Core::cleanVar($row['email']));
00574             if ($otherUser !== null) {
00575                // User exists with this email -- munge it to make unique
00576                $user->setEmail('ocs-' . Core::cleanVar($row['login']) . '+' . Core::cleanVar($row['email']));
00577                $this->conflicts[] = array(&$otherUser, &$user);
00578             }
00579 
00580             unset($otherUser);
00581 
00582             $userDao->insertUser($user);
00583 
00584             // Make this user a author
00585             $role = new Role();
00586             $role->setSchedConfId($schedConf->getId());
00587             $role->setConferenceId($schedConf->getConferenceId());
00588             $role->setUserId($user->getId());
00589             $role->setRoleId(ROLE_ID_REVIEWER);
00590             $roleDao->insertRole($role);
00591             unset($role);
00592          }
00593          $this->reviewerMap[$row['login']] =& $user;
00594 
00595          unset($schedConf);
00596          unset($user);
00597 
00598          $result->MoveNext();
00599       }
00600       $result->Close();
00601    }
00602 
00606    function importPapers() {
00607       if ($this->hasOption('verbose')) {
00608          printf("Importing papers\n");
00609       }
00610 
00611       import('file.PaperFileManager');
00612       import('search.PaperSearchIndex');
00613 
00614       $userDao =& DAORegistry::getDAO('UserDAO');
00615       $roleDao =& DAORegistry::getDAO('RoleDAO');
00616 
00617       $trackDao =& DAORegistry::getDAO('TrackDAO');
00618       $paperDao =& DAORegistry::getDAO('PaperDAO');
00619       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00620       $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00621 
00622       $unassignedTrackId = null;
00623 
00624       $result =& $this->importDao->retrieve('SELECT * FROM papers ORDER by id');
00625       while (!$result->EOF) {
00626          $row =& $result->fields;
00627          $schedConf =& $this->schedConfMap[$row['cf']];
00628          $schedConfId = $schedConf->getId();
00629 
00630          // Bring in the primary user for this paper.
00631          $user = $userDao->getUserByUsername(Core::cleanVar($row['login']));
00632          if (!$user) {
00633             unset($user);
00634             $user = new User();
00635             $user->setUsername(Core::cleanVar($row['login']));
00636             $user->setFirstName(Core::cleanVar($row['first_name']));
00637             $user->setLastName(Core::cleanVar($row['surname']));
00638             $user->setAffiliation(Core::cleanVar($row['affiliation']));
00639             $user->setEmail(Core::cleanVar($row['email']));
00640             $user->setUrl(Core::cleanVar($row['url']));
00641             $user->setBiography(Core::cleanVar($row['bio']), AppLocale::getLocale());
00642             $user->setLocales(array());
00643             $user->setDateRegistered($row['created']);
00644             $user->setDateLastLogin($row['created']);
00645             $user->setMustChangePassword(1);
00646 
00647             $password = Validation::generatePassword();
00648             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password));
00649 
00650             if ($this->hasOption('emailUsers')) {
00651                import('mail.MailTemplate');
00652                $mail = new MailTemplate('USER_REGISTER');
00653 
00654                $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
00655                $mail->assignParams(array('username' => $user->getUsername(), 'password' => $password, 'conferenceName' => $schedConf->getFullTitle()));
00656                $mail->addRecipient($user->getEmail(), $user->getFullName());
00657                $mail->send();
00658 
00659             }
00660             $user->setDisabled(0);
00661 
00662             $otherUser =& $userDao->getUserByEmail(Core::cleanVar($row['email']));
00663             if ($otherUser !== null) {
00664                // User exists with this email -- munge it to make unique
00665                $user->setEmail('ocs-' . Core::cleanVar($row['login']) . '+' . Core::cleanVar($row['email']));
00666                $this->conflicts[] = array(&$otherUser, &$user);
00667             }
00668 
00669             unset($otherUser);
00670 
00671             $userDao->insertUser($user);
00672 
00673             // Make this user a author
00674             $role = new Role();
00675             $role->setSchedConfId($schedConf->getId());
00676             $role->setConferenceId($schedConf->getConferenceId());
00677             $role->setUserId($user->getId());
00678             $role->setRoleId(ROLE_ID_AUTHOR);
00679             $roleDao->insertRole($role);
00680             unset($role);
00681          }
00682          $userId = $user->getId();
00683 
00684          // Bring in the basic entry for the paper
00685          $paper = new Paper();
00686          $paper->setUserId($userId);
00687          $paper->setSchedConfId($schedConfId);
00688 
00689          $oldTrackId = $row['primary_track_id'];
00690          if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) {
00691             $oldTrackId = $row['secondary_track_id'];
00692          }
00693          if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) {
00694             if (!$unassignedTrackId) {
00695                // Create an "Unassigned" track to use for submissions
00696                // that didn't have a track in OCS 1.x.
00697                $track = new Track();
00698                $track->setSchedConfId($schedConf->getId());
00699                $track->setTitle('UNASSIGNED', AppLocale::getLocale());
00700                $track->setSequence(REALLY_BIG_NUMBER);
00701                $track->setDirectorRestricted(1);
00702                $track->setMetaReviewed(1);
00703 
00704                $unassignedTrackId = $trackDao->insertTrack($track);
00705             }
00706             $newTrackId = $unassignedTrackId;
00707          } else {
00708             $newTrackId = $this->trackMap[$oldTrackId];
00709          }
00710 
00711          $paper->setTrackId($newTrackId);
00712          $paper->setTitle(Core::cleanVar($row['title']), AppLocale::getLocale());
00713          $paper->setAbstract(Core::cleanVar($row['abstract']), AppLocale::getLocale());
00714          $paper->setDiscipline(Core::cleanVar($row['discipline']), AppLocale::getLocale());
00715          $paper->setSponsor(Core::cleanVar($row['sponsor']), AppLocale::getLocale());
00716          $paper->setSubject(Core::cleanVar($row['topic']), AppLocale::getLocale());
00717          $paper->setLanguage(Core::cleanVar($row['language']));
00718 
00719          $paper->setDateSubmitted($row['created']);
00720          $paper->setDateStatusModified($row['timestamp']);
00721 
00722          // $paper->setTypeConst($row['present_format'] == 'multiple' ? SUBMISSION_TYPE_PANEL : SUBMISSION_TYPE_SINGLE); FIXME
00723          $paper->setCurrentStage(REVIEW_STAGE_ABSTRACT);
00724          $paper->setSubmissionProgress(0);
00725          $paper->setPages('');
00726 
00727          // Bring in authors
00728          $firstNames = split("\n", Core::cleanVar($row['first_name'] . "\n" . $row['add_first_names']));
00729          $lastNames = split("\n", Core::cleanVar($row['surname'] . "\n" . $row['add_surnames']));
00730          $emails = split("\n", Core::cleanVar($row['email'] . "\n" . $row['add_emails']));
00731          $affiliations = split("\n", Core::cleanVar($row['affiliation'] . "\n" . $row['add_affiliations']));
00732          $urls = split("\n", Core::cleanVar($row['url'] . "\n" . $row['add_urls']));
00733          foreach ($emails as $key => $email) {
00734             if (empty($email)) continue;
00735 
00736             $author = new Author();
00737 
00738             $author->setEmail($email);
00739             $author->setFirstName($firstNames[$key]);
00740             $author->setLastName($lastNames[$key]);
00741             $author->setAffiliation($affiliations[$key]);
00742             @$author->setUrl($urls[$key]); // Suppress warnings from inconsistent OCS 1.x data
00743             $author->setPrimaryContact($key == 0 ? 1 : 0);
00744 
00745             $paper->addAuthor($author);
00746 
00747             unset($author);
00748          }
00749 
00750          switch ($row['accepted']) {
00751             case 'true':
00752                $paper->setStatus(STATUS_PUBLISHED);
00753                $paperId = $paperDao->insertPaper($paper);
00754                $publishedPaper = new PublishedPaper();
00755                $publishedPaper->setPaperId($paperId);
00756                $publishedPaper->setSchedConfId($schedConfId);
00757                $publishedPaper->setDatePublished(Core::getCurrentDate());
00758                $publishedPaper->setSeq(REALLY_BIG_NUMBER);
00759                $publishedPaper->setViews(0);
00760                $publishedPaperDao->insertPublishedPaper($publishedPaper);
00761                $publishedPaperDao->resequencePublishedPapers($paper->getTrackId(), $schedConfId);
00762                break;
00763             case 'reject':
00764                $paper->setStatus(STATUS_DECLINED);
00765                $paperId = $paperDao->insertPaper($paper);
00766                break;
00767             default:
00768                $paper->setStatus(STATUS_QUEUED);
00769                $paperId = $paperDao->insertPaper($paper);
00770          }
00771 
00772          $this->paperMap[$row['id']] =& $paper;
00773 
00774          $paperFileManager = new PaperFileManager($paperId);
00775          if (!empty($row['paper']) && $row['paper'] != 'PDF') {
00776             $format = 'text/html';
00777             $extension = $paperFileManager->getDocumentExtension($format);
00778 
00779             $fileId = $paperFileManager->writeSubmissionFile('migratedFile' . $extension, $row['paper'], $format);
00780             $paper->setSubmissionFileId($fileId);
00781             $paperDao->updatePaper($paper);
00782 
00783             $fileId = $paperFileManager->writePublicFile('migratedGalley' . $extension, $row['paper'], $format);
00784             PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
00785             if (strstr($format, 'html')) {
00786                $galley = new PaperHTMLGalley();
00787                $galley->setLabel('HTML');
00788             } else {
00789                $galley = new PaperGalley();
00790                switch ($format) {
00791                   case 'application/pdf': $galley->setLabel('PDF'); break;
00792                   case 'application/postscript': $galley->setLabel('PostScript'); break;
00793                   case 'application/msword': $galley->setLabel('Word'); break;
00794                   case 'text/xml': $galley->setLabel('XML'); break;
00795                   case 'application/powerpoint': $galley->setLabel('Slideshow'); break;
00796                   default: $galley->setLabel('Untitled'); break;
00797                }
00798             }
00799 
00800             $galley->setLocale(AppLocale::getLocale());
00801             $galley->setPaperId($paperId);
00802             $galley->setFileId($fileId);
00803             $galleyDao->insertGalley($galley);
00804             unset($galley);
00805          } elseif ($row['paper'] == 'PDF') {
00806             $fileId = $paperFileManager->copySubmissionFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf');
00807             $paper->setSubmissionFileId($fileId);
00808             $paperDao->updatePaper($paper);
00809 
00810             $fileId = $paperFileManager->copyPublicFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf');
00811             PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
00812             $galley = new PaperGalley();
00813             $galley->setLabel('PDF');
00814             $galley->setLocale(AppLocale::getLocale());
00815             $galley->setPaperId($paperId);
00816             $galley->setFileId($fileId);
00817             $galleyDao->insertGalley($galley);
00818             unset($galley);
00819          }
00820 
00821          // FIXME: The following fields from OCS 1.x are UNUSED:
00822          // program_insert approach coverage format relation appendix_names appendix_dates
00823          // appendix appendix_pdf secondary_track_id multiple_* restrict_access paper_email
00824          // delete_paper comment_email
00825 
00826          unset($user);
00827          unset($paper);
00828          unset($schedConf);
00829          unset($paperFileManager);
00830          $result->MoveNext();
00831       }
00832       $result->Close();
00833    }
00834 
00838    function importReviews() {
00839       if ($this->hasOption('verbose')) {
00840          printf("Importing reviews\n");
00841       }
00842 
00843       $userDao =& DAORegistry::getDAO('UserDAO');
00844       $roleDao =& DAORegistry::getDAO('RoleDAO');
00845 
00846       $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00847       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00848       $paperCommentDao =& DAORegistry::getDAO('PaperCommentDAO');
00849 
00850       $unassignedTrackId = null;
00851 
00852       $result =& $this->importDao->retrieve('SELECT * FROM reviews ORDER by timestamp');
00853       while (!$result->EOF) {
00854          $row =& $result->fields;
00855 
00856          $schedConf =& $this->schedConfMap[$row['cf']];
00857          $paper =& $this->paperMap[$row['paper']];
00858          $reviewer =& $this->reviewerMap[$row['reviewer']];
00859 
00860          if (!$schedConf || !$paper || !$reviewer) {
00861             // Database inconsistency! Skip this entry.
00862             if (!$schedConf) $errors[] = "Unknown conference referenced in reviews: $row[cf]";
00863             else unset($schedConf);
00864             if (!$paper) $errors[] = "Unknown paper referenced in reviews: $row[paper]";
00865             else unset($paper);
00866             if (!$reviewer) $errors[] = "Unknown reviewer referenced in reviews: $row[reviewer]";
00867             else unset($reviewer);
00868 
00869             $result->MoveNext();
00870             continue;
00871          }
00872 
00873          $schedConfId = $schedConf->getId();
00874          $paperId = $paper->getId();
00875          $reviewerId = $reviewer->getId();
00876 
00877          $reviewAssignment = new ReviewAssignment();
00878          $reviewAssignment->setReviewerId($reviewerId);
00879          $reviewAssignment->setPaperId($paperId);
00880          $reviewAssignment->setStage(REVIEW_STAGE_ABSTRACT); // Won't always be accurate
00881          $reviewAssignment->setDateAssigned($row['timestamp']);
00882          $reviewAssignment->setDateNotified($row['timestamp']);
00883          $reviewAssignment->setDateConfirmed($row['timestamp']);
00884          $reviewAssignment->setDeclined(0);
00885          switch (trim(strtolower(array_shift(split("[\n\.:]", $row['recommendation']))))) {
00886             case 'accept':
00887                $reviewAssignment->setRecommendation(SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT);
00888                $reviewAssignment->setDateCompleted($row['timestamp']);
00889                break;
00890             case 'revise':
00891             case 'pending revisions':
00892             case 'accept with revisions':
00893                $reviewAssignment->setRecommendation(SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS);
00894                $reviewAssignment->setDateCompleted($row['timestamp']);
00895                break;
00896             case 'decline':
00897             case 'reject':
00898                $reviewAssignment->setRecommendation(SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE);
00899                $reviewAssignment->setDateCompleted($row['timestamp']);
00900                break;
00901             default:
00902                // WARNING: We're not setting a recommendation here at all!
00903                break;
00904          }
00905 
00906          $reviewId = $reviewAssignmentDao->insertReviewAssignment($reviewAssignment);
00907 
00908          $paperComment = new PaperComment();
00909          $paperComment->setCommentType(COMMENT_TYPE_PEER_REVIEW);
00910          $paperComment->setRoleId(ROLE_ID_REVIEWER);
00911          $paperComment->setPaperId($paperId);
00912          $paperComment->setAssocId($reviewId);
00913          $paperComment->setAuthorId($reviewerId);
00914          $paperComment->setCommentTitle('');
00915          $paperComment->setComments(Core::cleanVar($row['comments'] . "\n" . $row['recommendation']));
00916          $paperComment->setDatePosted($row['timestamp']);
00917          $paperComment->setViewable(0);
00918 
00919          $paperCommentDao->insertPaperComment($paperComment);
00920 
00921          unset($schedConf);
00922          unset($paper);
00923          unset($reviewer);
00924          unset($reviewAssignment);
00925          unset($paperComment);
00926          $result->MoveNext();
00927       }
00928       $result->Close();
00929    }
00930 
00931    //
00932    // Helper functions
00933    //
00934 
00940    function rebuildSearchIndex() {
00941       if ($this->hasOption('verbose')) {
00942          printf("Rebuilding search index\n");
00943       }
00944 
00945       PaperSearchIndex::rebuildIndex();
00946    }
00947 
00951    function getConflicts() {
00952       return $this->conflicts;
00953    }
00954 
00958    function getErrors() {
00959       return $this->errors;
00960    }
00961 }
00962 
00963 ?>

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