public function retrieveConferencesForPapers()
 {
     $paperDao = new PaperDao();
     // Papers without journal
     $papers = $paperDao->findPapersWithoutConference();
     $recordIds = array();
     $count = 0;
     $flush = false;
     $batchCount = 0;
     foreach ($papers as $paper) {
         $flush = false;
         if ($paper->msaConferenceId > 0) {
             $recordIds[$count] = $paper->msaConferenceId;
             if ($count >= QueryMsa::MAX_RECORDS_PER_QUERY) {
                 $recordIdsUnique = array_unique($recordIds, SORT_NUMERIC);
                 $this->searchConferencesByIds($batchCount, $recordIdsUnique);
                 $count = 0;
                 unset($recordIds);
                 $recordIds = array();
                 $flush = true;
                 $batchCount++;
             } else {
                 $count++;
             }
         }
     }
     if ($flush == false && count($recordIds) > 0) {
         $recordIdsUnique = array_unique($recordIds, SORT_NUMERIC);
         $this->searchConferencesByIds($batchCount, $recordIdsUnique);
     }
     (new ConferenceDao())->fixEraEntryForeignKey();
 }
 public function retrievePapersForReferences(&$paperRefs)
 {
     $paperDao = new PaperDao();
     $papersIds = array();
     $count = 0;
     $flush = false;
     $batchCount = 0;
     $papers = array();
     foreach ($paperRefs as $paperRef) {
         $foundIdForMsaId = $paperDao->findIdByMsaId($paperRef->msaCitationId);
         if (isset($foundIdForMsaId) == false && $paperRef->msaCitationId > 0) {
             $flush = false;
             $papersIds[$count] = $paperRef->msaCitationId;
             if ($count >= QueryMsa::MAX_RECORDS_PER_QUERY) {
                 // Calls method searchPapersByIds initially designed for
                 // author papers but this time using paper references as
                 // both share the same attributes used in this method
                 // The returned papers are already stored to the DB
                 // Remove duplicates
                 $papersIdsUnique = array_unique($papersIds, SORT_NUMERIC);
                 $papersFound = $this->searchPapersByIds($batchCount, $papersIdsUnique);
                 $papers = array_merge($papers, $papersFound);
                 $count = 0;
                 unset($papersIds);
                 $papersIds = array();
                 $flush = true;
                 $batchCount++;
             } else {
                 $count++;
             }
         } else {
             $paperRef->citationId = $foundIdForMsaId;
         }
     }
     if ($flush == false && count($papersIds) > 0) {
         // The returned papers are already stored to the DB
         $papersIdsUnique = array_unique($papersIds, SORT_NUMERIC);
         $papersFound = $this->searchPapersByIds($batchCount, $papersIdsUnique);
         $papers = array_merge($papers, $papersFound);
     }
     // The returned papers are already stored to the DB
     return $papers;
 }
 function savePapers($papers)
 {
     $paperDao = new PaperDao();
     foreach ($papers as $paper) {
         $paperDao->insert($paper);
     }
 }