示例#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 testRemoveHasRightReturn()
 {
     // To test the return values, disable conversion of errors into exceptions
     $warningEnabledOrig = PHPUnit_Framework_Error_Warning::$enabled;
     PHPUnit_Framework_Error_Warning::$enabled = false;
     mkdir(__DIR__ . "/test");
     $this->assertTrue($this->stub->remove(__DIR__ . "/test"));
     $this->assertFalse($this->stub->remove("test"));
     touch(__DIR__ . "/test");
     $this->assertTrue($this->stub->remove(__DIR__ . "/test"));
     PHPUnit_Framework_Error_Warning::$enabled = $warningEnabledOrig;
 }
 /**
  * Remove installed libraries
  *
  * @param string $libSel Library to clear
  *
  * @return void
  */
 function clearLibraries($libSel = null)
 {
     $mbpath = $this->getRootPath();
     $libsDir = $mbpath . "lib";
     /// Clear out all libraries
     if (!$libSel) {
         foreach (glob("{$libsDir}/*") as $libDir) {
             if (strpos($libDir, '.svn') === false) {
                 CMbPath::remove($libDir);
             }
         }
         return;
     }
     // Clear out selected lib
     $library = self::$all[$libSel];
     if ($targetDir = $library->targetDir) {
         @CMbPath::remove("{$libsDir}/{$targetDir}");
     }
 }
 /**
  * Output the content to the standard output
  * 
  * @return void
  */
 static function output($options = array())
 {
     if (self::$_aio) {
         $path = CAppUI::getTmpPath("embed-" . md5(uniqid("", true)));
         if (self::$_aio === "savefile") {
             $str = self::allInOne($path);
             file_put_contents("{$path}/index.html", $str);
             $zip_path = "{$path}.zip";
             CMbPath::zip($path, $zip_path);
             header("Content-Type: application/zip");
             header("Content-Disposition: attachment; filename=\"" . basename($zip_path) . "\";");
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . filesize($zip_path));
             readfile($zip_path);
             unlink($zip_path);
             CMbPath::remove($path);
             CApp::rip();
         } else {
             self::allInOne(null, $options);
         }
     } else {
         // Flush zero-ifies ob_get_length
         self::$flushed_output_length += ob_get_length();
         ob_end_flush();
     }
 }
 * @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);
}