示例#1
0
/**
 * Extract files
 *
 * @param string $schemaDir  Schema directory
 * @param string $schemaFile Schema files
 * @param bool   $delOldDir  Delete old directory
 *
 * @return void
 */
function extractFiles($schemaDir, $schemaFile, $delOldDir = false)
{
    $baseDir = "modules/hprimxml/xsd";
    $destinationDir = "{$baseDir}/{$schemaDir}";
    $archivePath = "{$baseDir}/{$schemaFile}";
    if ($delOldDir && file_exists($destinationDir)) {
        if (CMbPath::remove($destinationDir)) {
            echo "<div class='info'>Suppression de {$destinationDir}</div>";
        } else {
            echo "<div class='error'>Impossible de supprimer le dossier {$destinationDir}</div>";
            return;
        }
    }
    if (false != ($nbFiles = CMbPath::extract($archivePath, $destinationDir))) {
        echo "<div class='info'>Extraction de {$nbFiles} fichiers pour {$schemaDir}</div>";
    } else {
        echo "<div class='error'>Impossible d'extraire l'archive {$schemaFile}</div>";
        return;
    }
    if (CAppUI::conf("hprimxml concatenate_xsd")) {
        $rootFiles = glob("{$destinationDir}/msg*.xsd");
        $includeFiles = array_diff(glob("{$destinationDir}/*.xsd"), $rootFiles);
        foreach ($rootFiles as $rootFile) {
            $xsd = new CHPrimXMLSchema();
            $xsd->loadXML(file_get_contents($rootFile));
            $xpath = new DOMXPath($xsd);
            $importFiles = array();
            foreach ($includeFiles as $includeFile) {
                $include = new DOMDOcument();
                $include->loadXML(file_get_contents($includeFile));
                $isImport = false;
                foreach ($importFiles as $key => $value) {
                    if (strpos($includeFile, $key) !== false) {
                        $isImport = true;
                        break;
                    }
                }
                foreach ($include->documentElement->childNodes as $child) {
                    $impNode = $xsd->importNode($child, true);
                    $existing = false;
                    if (in_array($impNode->nodeName, array("xsd:simpleType", "xsd:complexType"))) {
                        $name = $impNode->getAttribute('name');
                        $existing = $xpath->query("//{$impNode->nodeName}[@name='{$name}']")->length > 0;
                    }
                    if ($isImport) {
                        $xsd->documentElement->setAttribute("xmlns:insee", "http://www.hprim.org/inseeXML");
                    }
                    if (!$existing) {
                        $xsd->documentElement->appendChild($impNode);
                    }
                }
            }
            $xsd->purgeImportedNamespaces();
            $xsd->purgeIncludes();
            file_put_contents(substr($rootFile, 0, -4) . ".xml", $xsd->saveXML());
            echo "<div class='info'>Schéma concatené</div>";
        }
    }
}
示例#2
0
 public function testExtractHasRightReturn()
 {
     // To test the return values, disable conversion of errors into exceptions
     $warningEnabledOrig = PHPUnit_Framework_Error_Warning::$enabled;
     PHPUnit_Framework_Error_Warning::$enabled = false;
     $this->assertFalse($this->stub->extract(__DIR__ . "/notAnArchive", __DIR__ . "/"));
     $file = fopen(__DIR__ . "/archiveTest.tar.gz", "w");
     fclose($file);
     $this->assertEquals(0, $this->stub->extract(__DIR__ . "/archiveTest.tar.gz", __DIR__ . "/"));
     @unlink(__DIR__ . "/archiveTest.tar.gz");
     $file = fopen(__DIR__ . "/archiveTest.zip", "w");
     fclose($file);
     $this->assertEquals(0, $this->stub->extract(__DIR__ . "/archiveTest.zip", __DIR__ . "/"));
     @unlink(__DIR__ . "/archiveTest.zip");
     PHPUnit_Framework_Error_Warning::$enabled = $warningEnabledOrig;
 }
示例#3
0
<?php

/**
 * $Id: httpreq_do_add_insee.php 19219 2013-05-21 12:26:07Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage Patients
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 19219 $
 */
CCanDo::checkAdmin();
$sourcePath = "modules/dPpatients/INSEE/insee.tar.gz";
$targetDir = "tmp/insee";
$targetPath = "tmp/insee/insee.sql";
// Extract the SQL dump
if (null == ($nbFiles = CMbPath::extract($sourcePath, $targetDir))) {
    CAppUI::stepAjax("Erreur, impossible d'extraire l'archive", UI_MSG_ERROR);
}
CAppUI::stepAjax("Extraction de {$nbFiles} fichier(s)", UI_MSG_OK);
$ds = CSQLDataSource::get("INSEE");
if (null == ($lineCount = $ds->queryDump($targetPath, true))) {
    $msg = $ds->error();
    CAppUI::stepAjax("Erreur de requête SQL: {$msg}", UI_MSG_ERROR);
}
CAppUI::stepAjax("import effectué avec succès de {$lineCount} lignes", UI_MSG_OK);
 /**
  * Install the library
  *
  * @return int The number of extracted files
  */
 function install()
 {
     $mbpath = $this->getRootPath();
     $pkgsDir = $mbpath . "libpkg";
     $libsDir = $mbpath . "lib";
     $filePath = "{$pkgsDir}/{$this->fileName}";
     // For libraries archive not contained in directory
     if ($this->extraDir) {
         $libsDir .= "/{$this->extraDir}";
     }
     return CMbPath::extract($filePath, $libsDir);
 }
示例#5
0
$name_canonical = CValue::post("name_canonical");
$name_short = CValue::post("name_short");
$name_long = CValue::post("name_long");
$license = CValue::post("license");
$licenses = array("GNU GPL" => "GNU General Public License, see http://www.gnu.org/licenses/gpl.html", "OXOL" => "OXOL, see http://www.mediboard.org/public/OXOL");
$license = CValue::read($licenses, $license, $licenses["GNU GPL"]);
// Only alphanumeric caracters
$name_canonical = preg_replace("/[^\\w\\s]/", "", $name_canonical);
$name_short = CMbString::purifyHTML($name_short);
$name_long = CMbString::purifyHTML($name_long);
if (is_dir("modules/{$name_canonical}")) {
    CAppui::stepAjax("Module '{$name_canonical}' existe déjà", UI_MSG_ERROR);
}
$zip_path = "dev/sample_module.zip";
$destination = "tmp/sample_module";
if (false == ($files_count = CMbPath::extract($zip_path, $destination))) {
    CAppui::stepAjax("Impossible d'extraire l'archive '{$zip_path}'</div>", UI_MSG_ERROR);
}
rename("{$destination}/sample_module", "{$destination}/{$name_canonical}");
$path = "{$destination}/{$name_canonical}";
$files = array_merge(glob("{$path}/*"), glob("{$path}/classes/*"), glob("{$path}/locales/*"), glob("{$path}/templates/*"));
$translate = array('{NAME_CANONICAL}' => $name_canonical, '{NAME_SHORT}' => $name_short, '{NAME_LONG}' => $name_long, '{LICENSE}' => $license);
foreach ($files as $_file) {
    if (is_dir($_file)) {
        continue;
    }
    file_put_contents($_file, strtr(file_get_contents($_file), $translate));
}
rename("{$destination}/{$name_canonical}", "modules/{$name_canonical}");
CAppUI::setMsg("Module '{$name_canonical}' créé", UI_MSG_OK);
CAppUI::js("location.reload()");
 */
function getNum($value)
{
    return preg_replace("/[^0-9]/", "", $value);
}
CApp::setTimeLimit(3600);
CSessionHandler::writeClose();
if (empty($_FILES["import"]["tmp_name"])) {
    return;
}
$dir = "tmp/import_etab_externe";
CMbPath::forceDir($dir);
$archive = "{$dir}/archive.zip";
move_uploaded_file($_FILES["import"]["tmp_name"], $archive);
// Extract the data files
if (null == ($nbFiles = CMbPath::extract($archive, $dir))) {
    CAppUI::setMsg("Erreur, impossible d'extraire l'archive", UI_MSG_ERROR);
    return;
} else {
    CAppUI::setMsg("{$nbFiles} fichiers extraits", UI_MSG_OK);
}
$files = glob("{$dir}/*.csv");
foreach ($files as $_file) {
    $fp = fopen($_file, "r");
    $csv = new CCSVFile($fp);
    $csv->readLine();
    // first line
    while ($line = $csv->readLine()) {
        if (!isset($line[1])) {
            continue;
        }
 * @version $Revision:$
 * @author SARL OpenXtrem
 * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 */
CCanDo::checkRead();
$version = CValue::get("version");
$check = CValue::get("check");
$extract = CValue::get("extract");
$racine = "modules/hl7/resources";
$lib_hl7 = "lib/hl7";
$specs_name = "hl7v" . str_replace(".", "_", $version);
$destinationDir = "{$lib_hl7}/{$specs_name}";
$archivePath = "{$racine}/{$specs_name}.zip";
if ($extract) {
    if (file_exists($destinationDir)) {
        CMbPath::remove($destinationDir) ? CAppUI::stepAjax("Suppression de {$destinationDir}") : CAppUI::stepAjax("Impossible de supprimer le dossier {$destinationDir}", UI_MSG_ERROR);
    }
    if (false != ($nbFiles = CMbPath::extract($archivePath, $destinationDir))) {
        CAppUI::stepAjax("Extraction de {$nbFiles} fichiers pour {$specs_name}");
        $check = true;
    } else {
        CAppUI::stepAjax("Impossible d'extraire l'archive {$schemaFile}", UI_MSG_ERROR);
    }
}
if ($check) {
    $status = 0;
    if (file_exists($destinationDir)) {
        $status = 1;
    }
    $status ? CAppUI::stepAjax("Fichiers pr�sents") : CAppUI::stepAjax("Fichiers manquants", UI_MSG_ERROR);
}