function importDataFromDumpFile($sid, DatabaseHandler $dbHandler, $userId, $filePath, $my_pligg_base_no_slash) { $ktrExeDao = new KTRExecutorDAO(); $tableNames = $dbHandler->loadTables(); $logIds = array(); foreach ($tableNames as $tableName) { $logIds[$tableName] = $ktrExeDao->addExecutionInfoTuple($sid, $tableName, $userId); } try { $dbImporter = DatabaseImporterFactory::createDatabaseImporter($dbHandler->getDriver(), $sid, $my_pligg_base_no_slash); $dbImporter->importDbData($filePath); foreach ($logIds as $logId) { $ktrExeDao->updateExecutionInfoStatus($logId, 'success'); } } catch (Exception $e) { foreach ($logIds as $logId) { $ktrExeDao->updateExecutionInfoStatus($logId, 'error'); $ktrExeDao->updateExecutionInfoErrorMessage($logId, $e->getMessage()); } } $queryEngine = new QueryEngine(); foreach ($logIds as $tableName => $logId) { $numProcessed = $queryEngine->GetTotalNumberTuplesInTableBySidAndNameFromExternalDB($sid, $tableName); $ktrExeDao->updateExecutionInfoTupleAfterPanTerminated($logId, 0, '', $numProcessed, 'success'); } }
/** * Returns execution status with additional information like how many records were processed. * @param $sid sid of the story * @return stdClass info about the status */ public static function getExecutionStatus($sid) { $ktrExecutorDAO = new KTRExecutorDAO(); $tuplesFromExecuteInfoTable = $ktrExecutorDAO->getTuplesBySid($sid); $queryEngine = new QueryEngine(); if (!isset($tuplesFromExecuteInfoTable) || count($tuplesFromExecuteInfoTable) == 0) { $tuplesFromExecuteInfoTable = array(); $tables = $queryEngine->GetTablesList($sid); // Add table into exec info. foreach ($tables as $key => $tableName) { $rec = new stdClass(); $rec->tableName = $tableName; $rec->status = "success"; $rec->Eid = "NA"; $rec->ErrorMessage = ""; $rec->RecordsProcessed = $queryEngine->GetTotalNumberTuplesInTableBySidAndName($sid, "[{$tableName}]"); $rec->Sid = $sid; $rec->TimeEnd = "2013-08-18 12:21:19"; //FIXME $rec->TimeStart = "2013-08-18 12:21:19"; $rec->UserId = "NA"; $tuplesFromExecuteInfoTable[] = $rec; } } $result = array(); foreach ($tuplesFromExecuteInfoTable as $i => $tupleFromExecuteInfoTable) { if ($tupleFromExecuteInfoTable->status == 'success' || $tupleFromExecuteInfoTable->status == 'error') { $tupleFromExecuteInfoTable->numberProcessRecords = $queryEngine->GetTotalNumberTuplesInTableBySidAndName($sid, "[{$value->tableName}]"); //$tupleFromExecuteInfoTable->numberProcessRecords = $tupleFromExecuteInfoTable->RecordsProcessed; } else { //TODO FIXME: table name should not be wrapped into [] at this spet. Need global refactoring to move wrapping table into brackets closer to the query execution $tupleFromExecuteInfoTable->numberProcessRecords = $queryEngine->GetTotalNumberTuplesInTableBySidAndName($sid, "[{$value->tableName}]"); } $result[] = $tupleFromExecuteInfoTable; } return $result; }
/** * Create a table for given table name if it does not exist yet. The columns of the created table are given by the columns array. * @param string $tableName name of the table * @param array $columns array of stdClass which come all the way from generate ktr file. TODO need to use special class. * @return nothing nothing * @throws PDOException If there are error runing the sql statement. */ public function createTableIfNotExist($tableName, $columns) { $query = "CREATE TABLE IF NOT EXISTS `{$tableName}` ("; // will hold the complete create table statement. $columnsDefinition = array(); foreach ($columns as $key => $column) { //FIXME: for now all columns are varchars, actually we could use the info provided by user abotu each column $columnsDefinition[] = " `{$column['originalDname']}` TEXT "; } $query .= implode(", ", $columnsDefinition) . " ); "; $ktrExecutorDAO = new KTRExecutorDAO(); $ktrExecutorDAO->updateExecutionInfoTupleStatus(1, $query); try { $pdo = $this->GetConnection(); $pdo->exec($query); } catch (PDOException $e) { throw new Exception("Error Processing Request " . $e->getMessage(), 1); } }
function importDataFromDumpFile($sid, DatabaseHandler $dbHandler, $userId, $filePath) { $ktrExeDao = new KTRExecutorDAO(); $tables = $dbHandler->loadTables(); $logIds = array(); foreach ($tables as $table) { $logIds[] = $ktrExeDao->addExecutionInfoTuple($sid, $table, $userId); } try { $dbImporter = DatabaseImporterFactory::createDatabaseImporter($dbHandler->getDriver(), $sid, "colfusion"); $dbImporter->importDbData($filePath); foreach ($logIds as $logId) { $ktrExeDao->updateExecutionInfoTimeEnd($logId); $ktrExeDao->updateExecutionInfoStatus($logId, 'success'); } } catch (Exception $e) { foreach ($logIds as $logId) { $ktrExeDao->updateExecutionInfoStatus($logId, 'error'); $ktrExeDao->updateExecutionInfoErrorMessage($logId, $e->getMessage()); } } }