Ejemplo n.º 1
0
try {
    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");
Ejemplo n.º 2
0
$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();
Ejemplo n.º 3
0
<?php

/**
 * Sample export script utilizing import\Document class.
 * 
 * To run it:
 * - assure proper database connection settings in config.inc.php
 * - set up configuration variables in lines 13-18
 * - run script from the command line 'php export.php'
 */
require_once 'src/utils/ClassLoader.php';
new utils\ClassLoader();
require_once 'config.inc.php';
// token iterator class; if you do not know it, set to NULL
$iterator = import\Document::XML_READER;
// document id in the tokeneditor database (see the documents table)
$documentId = 742;
// replate properties values in-place or add full <fs> structures
$inPlace = true;
// path to the export file to create
$exportPath = '../sample_data/export.xml';
###########################################################
$PDO = new \PDO($CONFIG['dbConn'], $CONFIG['dbUser'], $CONFIG['dbPasswd']);
$PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pb = new utils\ProgressBar(null, 10);
$doc = new import\Document($PDO);
$doc->loadDb($documentId, $iterator);
$doc->export($inPlace, $exportPath, $pb);
$pb->finish();