private function uploadBulkFile() { $newLimit = ceil(((filesize($_FILES['BulkImportRedirectsFile']['tmp_name']) / 1024 / 1024)*2) + 8); $oldLimit = (int)str_replace('M', '', @ini_get('memory_limit')); if($newLimit > $oldLimit) { @ini_set('memory_limit', $newLimit . 'M'); } GetLib('class.urls'); GetLib('class.redirects'); if(substr(isc_strtolower($_FILES['BulkImportRedirectsFile']['name']), -4) == '.xml') { $xml = new SimpleXMLElement($_FILES['BulkImportRedirectsFile']['tmp_name'], null, true); $urls = $xml->children(); foreach($urls as $thisUrl) { $url = (string)$thisUrl->loc; $url = ISC_REDIRECTS::normalizeURLForDatabase($url); if ($url === false) { continue; } $InsertData = array( 'redirectassoctype' => ISC_REDIRECTS::REDIRECT_TYPE_NOREDIRECT, 'redirectassocid'=> 0, 'redirectpath' => '', 'redirectmanual' => '', 'redirectpath' => $url, ); $GLOBALS['ISC_CLASS_DB']->InsertQuery('redirects', $InsertData); } } else { // must be a CSV $importer = new ISC_ADMIN_CSVPARSER(); $importer->OpenCSVFile($_FILES['BulkImportRedirectsFile']['tmp_name'], 0); // skip header line if required if (isset($_POST['Headers'])) { $importer->FetchNextRecord(); } while(($record = $importer->FetchNextRecord()) !== false) { $redirectPath = ISC_REDIRECTS::normalizeURLForDatabase($record[0]); if ($redirectPath === false) { continue; } $InsertData = array( 'redirectassoctype' => ISC_REDIRECTS::REDIRECT_TYPE_NOREDIRECT, 'redirectassocid'=> 0, 'redirectpath' => '', 'redirectmanual' => '', 'redirectpath' => $redirectPath, ); if(!empty($record[2])) { $label = ISC_REDIRECTS::getTypeFromLabel($record[1]); if (is_numeric($record[2]) && $label !== false) { $InsertData['redirectassocid'] = (int)$record[2]; $InsertData['redirectassoctype'] = $label; } } elseif (!empty($record[1])) { $InsertData['redirectmanual'] = ISC_REDIRECTS::normalizeNewURLForDatabase($record[1]); $InsertData['redirectassoctype'] = ISC_REDIRECTS::REDIRECT_TYPE_MANUAL; } $GLOBALS['ISC_CLASS_DB']->InsertQuery('redirects', $InsertData); } } ISC_JSON::$useTextarea = true; ISC_JSON::output(GetLang('ImportSuccessful'), true); }
/** * Performs the actual import - imports the current chunk from the data file. */ private function _Import() { $TypeLang = "Import".ucfirst($this->type); //$current_file = @array_shift($this->ImportSession['ChunkList']); if(!isset($this->ImportSession['DoneCount'])) { $this->ImportSession['DoneCount'] = 0; } if(!isset($this->ImportSession['StartTime'])) { $this->ImportSession['StartTime'] = time(); } $done = 0; $percent = 0; if (isset($this->ImportSession['DoneCount'])) { $done = $this->ImportSession['DoneCount']; //$percent = ceil(($done/$this->ImportSession['TotalItems']) * 100); $percent = ceil(($this->ImportSession['LastPosition']/$this->ImportSession['TotalFileSize'])*100); } $importer = new ISC_ADMIN_CSVPARSER; if(isset($this->ImportSession['FieldSeparator']) && $this->ImportSession['FieldSeparator'] != "") { $importer->FieldSeparator = $this->ImportSession['FieldSeparator']; } if(isset($this->ImportSession['FieldEnclosure']) && $this->ImportSession['FieldEnclosure'] != "") { $importer->FieldEnclosure = $this->ImportSession['FieldEnclosure']; } $importer->SetRecordFields($this->ImportSession['FieldList']); $importer->OpenCSVFile($this->ImportSession['ImportFile'], $this->ImportSession['LastPosition'], 20); if ($this->ImportSession['LastPosition'] < $this->ImportSession['TotalFileSize']) { // This is our first iteration of the import, headers are enabled so skip past the first row if(isset($this->ImportSession['Headers']) && $this->ImportSession['Headers'] == 1 && !isset($this->ImportSession['InImport'])) { $importer->FetchNextRecord(); } $this->ImportSession['InImport'] = 1; while(($record = $importer->FetchNextRecord(true)) !== false) { // Call the function to handle the record $this->_ImportRecord($record); $currentPosition = $importer->GetCurrentPosition(); //$newPercent = ceil(($done/$this->ImportSession['TotalItems']* 100)); $newPercent = ceil(($currentPosition/$this->ImportSession['TotalFileSize'])*100); if($newPercent > $percent) { $percent = $newPercent; $report = $this->_FetchInlineReport(); // Update the status echo "<script type='text/javascript'>\n"; echo sprintf("self.parent.UpdateImportStatusReport('%s');", str_replace(array("\n", "\r", "'"), array(" ", "", "\\'"), $report)); $GLOBALS['ISC_LANG']['ImportInProgressDesc'] = sprintf(GetLang('ImportInProgressDesc'), $this->ImportSession['DoneCount']+$importer->GetRecordNum()); echo sprintf("self.parent.UpdateImportStatus('%s', %d);", str_replace(array("\n", "\r", "'"), array(" ", "", "\\'"), GetLang('ImportInProgressDesc')), $percent); echo "</script>\n"; flush(); } $this->ImportSession['DoneCount']++; } $this->ImportSession['LastPosition'] = $importer->GetCurrentPosition(); //$this->ImportSession['DoneCount'] += $importer->GetRecordNum(); } $GLOBALS['ImportSession'] = $_REQUEST['ImportSession']; $this->SaveImportSession(); // Nothing left to import, redirect to the finish page if($this->ImportSession['LastPosition'] === false || $this->ImportSession['LastPosition'] >= $this->ImportSession['TotalFileSize']) { $locationUrl = "index.php?ToDo=Import".ucfirst($this->type)."&Step=5&ImportSession=".urlencode($GLOBALS['ImportSession']); ?> <script type="text/javascript"> window.onload = function() { self.parent.parent.location= '<?php echo $locationUrl; ?>'; } </script> <?php exit; } // Still importing, jump to next page else { $locationUrl = "index.php?ToDo=Import".ucfirst($this->type)."&Step=4&x=".rand(1, 50)."&ImportSession=".$GLOBALS['ImportSession']; ?> <script type="text/javascript"> window.onload = function() { setTimeout('window.location="<?php echo $locationUrl; ?>"', 10); } </script> <?php exit; } }