/** * @param array $requestData * @param DataIO $dataIO */ protected function initializeDataIO(DataIO $dataIO, array $requestData) { $colOpts = $this->dataFactory->createColOpts($requestData['columnOptions']); $limit = $this->dataFactory->createLimit($requestData['limit']); $filter = $this->dataFactory->createFilter($requestData['filter']); $maxRecordCount = $requestData['max_record_count']; $type = $requestData['type']; $format = $requestData['format']; $username = $this->auth->getIdentity()->username; $dataIO->initialize($colOpts, $limit, $filter, $type, $format, $maxRecordCount); $dataIO->setUsername($username); }
/** * @param $postData * @param $inputFile * @return mixed * @throws \Exception */ public function import($postData, $inputFile) { $tree = json_decode($this->profile->getConfig("tree"), true); if ($postData['format'] === 'xml') { $this->fileIO->setTree($tree); } if ($this->dataIO->getSessionState() == 'new') { $totalCount = $this->fileIO->getTotalCount($inputFile); $this->dataIO->setFileName($postData['importFile']); $this->dataIO->setFileSize(filesize($inputFile)); $this->dataIO->getDataSession()->setTotalCount($totalCount); $this->dataIO->startSession($this->profile); } else { // session has already loaded ids and some position, so we simply activate it $this->dataIO->resumeSession(); } $this->dataIO->usernameSession(); if ($this->dataIO->getSessionState() == 'active') { //get current session position $batchSize = (int) $postData['batchSize']; $position = $this->dataIO->getSessionPosition(); $records = $this->fileIO->readRecords($inputFile, $position, $batchSize); $data = $this->transformerChain->transformBackward($records); $defaultValues = $this->profile->getDefaultValues($tree); //inserts/update data into the database $this->dataIO->write($data, $defaultValues); //writes into database log table $profileName = $this->profile->getName(); $this->dataIO->writeLog($inputFile, $profileName); $this->dataIO->progressSession($batchSize); //gets unprocessed data from the adapter $postData['unprocessedData'] = $this->dataIO->getUnprocessedData(); } if ($this->dataIO->getSessionState() == 'finished') { $this->dataIO->closeSession(); } $postData['position'] = $this->dataIO->getSessionPosition(); if (!$postData['sessionId']) { $postData['sessionId'] = $this->dataIO->getDataSession()->getId(); } return $postData; }