getStatus(); } $endTime = $this->getEndTime(); while ((!empty($entries)) && ($endTime > time())) { $this->continueImport($entries); } return $this->getStatus(); } /** * Returns the current status as JSON. * * @return string JSON status */ private function getStatus() { if (empty($entries)) { if (isset($_SESSION[Importer::SESSION_KEY_ENTRIES])) { unset($_SESSION[Importer::SESSION_KEY_ENTRIES]); } $status = array( Importer::STATUS => 'done' ); return json_encode($status); } $progress = (sizeof($_SESSION[Importer::SESSION_KEY_ENTRIES]) / $_SESSION[Importer::SESSION_KEY_COUNT]) * 100.0; $progress = floor(100 - $progress); $status = array( Importer::STATUS => 'inProgress', Importer::PROGRESS => $progress, Importer::DATA => '' ); return json_encode($status); } /** * Returns the time when processing should end. * * @return number end time as Unix timestamp */ private function getEndTime() { $startTime = time(); $maxTime = get_cfg_var('max_execution_time') - 10; if ($maxTime > Importer::TIME_LIMIT) { $maxTime = Importer::TIME_LIMIT; } if ($maxTime <= 0) { $maxTime = Importer::TIME_LIMIT; } return $startTime + $maxTime; } /** * Continues the import with processing of a single entry. * * @param array[] $entries import entries */ private function continueImport(&$entries) { $entry = array_shift($entries); } } ?>