$save = true; // allows to limit number of processed tokens (put 0 to process all) $limit = 0; // path to the XML file describing schema $schemaPath = '../sample_data/foo/foo-schema.xml'; // path to the XML file with data $dataPath = '../sample_data/foo/foo10000.xml'; // path to the directory where imported XMLs are stored $saveDir = 'docStorage'; //$schemaPath = '../sample_data/testtext-schema.xml'; //$dataPath = '../sample_data/testtext.xml'; //$schemaPath = '../sample_data/testcases-rm-toks-schema.xml'; //$dataPath = '../sample_data/testcases-rm-toks.xml'; //$schemaPath = '../sample_data/SwissProt-schema.xml'; //$dataPath = '../sample_data/SwissProt.xml'; //$schemaPath = '../sample_data/baffleLex_v_0.2_zmorge_20151002-schema.xml'; //$dataPath = '../sample_data/baffleLex.xml'; ########################################################### $PDO = new \PDO($CONFIG['dbConn'], $CONFIG['dbUser'], $CONFIG['dbPasswd']); $PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $PDO->beginTransaction(); $name = explode('/', $dataPath); $name = array_pop($name); $pb = new utils\ProgressBar(null, 10); $doc = new import\Document($PDO); $doc->loadFile($dataPath, $schemaPath, $name, $iterator); $doc->save($saveDir, $limit, $pb); if ($save) { $PDO->commit(); } $pb->finish();
if (!isset($_FILES['document']) || !isset($_FILES['schema'])) { throw new RuntimeException('document or schema not uploaded'); } $zip = new ZipArchive(); if ($zip->open($_FILES['document']['tmp_name']) === true) { $name = $zip->getNameIndex(0); $dir = 'tmp/' . time() . rand(); mkdir($dir); $zip->extractTo($dir, $name); $zip->close(); $file = $dir . '/' . $name; $_FILES['document']['tmp_name'] = $file; } $PDO->beginTransaction(); $doc = new import\Document($PDO); $doc->loadFile($_FILES['document']['tmp_name'], $_FILES['schema']['tmp_name'], filter_input(INPUT_POST, 'name')); $n = $doc->save($CONFIG['storageDir']); $query = $PDO->prepare("SELECT count(*) FROM users WHERE user_id = ?"); $query->execute(array(filter_input(INPUT_SERVER, $CONFIG['userid']))); if ($query->fetch(PDO::FETCH_COLUMN) == 0) { $query = $PDO->prepare("INSERT INTO users (user_id) VALUES (?)"); $query->execute(array(filter_input(INPUT_SERVER, $CONFIG['userid']))); } $query = $PDO->prepare("INSERT INTO documents_users (document_id, user_id) VALUES (?, ?)"); $query->execute(array($doc->getId(), filter_input(INPUT_SERVER, $CONFIG['userid']))); header('Content-type: application/json'); if ($n > 0) { $PDO->commit(); if (1 == $PDO->query("SELECT count(*) FROM documents")->fetch(PDO::FETCH_COLUMN)) { $PDO->query("VACUUM ANALYZE"); }