Skip to content
Snippets Groups Projects
Verified Commit 565e6a48 authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

fix profile not found when another extension is there

parent 6ca3bd3e
No related branches found
No related tags found
No related merge requests found
......@@ -177,6 +177,7 @@ class ArchiveTransfer extends abstractMessage implements \bundle\medona\Controll
public function validate($message, $archivalAgreement = null)
{
$this->errors = array();
$this->infos = array();
$this->replyCode = null;
$this->loadMessage($message);
......@@ -277,72 +278,46 @@ class ArchiveTransfer extends abstractMessage implements \bundle\medona\Controll
protected function validateProfile($message, $archivalProfileReference)
{
/*if (!isset($message->object->archive[0]->archivalProfile) || $message->object->archive[0]->archivalProfile->value == "") {
$this->sendError("203", "Le profil d'archive n'est pas renseigné");
return;
}*/
$errors = array();
$profileFiles = glob($this->profilesDirectory.DIRECTORY_SEPARATOR.$archivalProfileReference.'.*');
if (count($profileFiles) == 0) {
$this->sendError("203", "Le profil d'archive identifié par '$archivalProfileReference' n'est pas référencé dans le système.");
return;
}
foreach ($profileFiles as $profileFile) {
$extension = pathinfo($profileFile, \PATHINFO_EXTENSION);
$profilePath = $this->profilesDirectory.DIRECTORY_SEPARATOR.$archivalProfileReference;
switch ($extension) {
case 'rng':
//if ($validationMode == 'jing') {
if (true) {
$jing = \laabs::newService('dependency/xml/plugins/jing/jing');
$xmlFile = $this->message->path;
$valid = $jing->validate($profileFile, $xmlFile);
if (!$valid) {
$this->sendError("203");
if (file_exists($profilePath . '.rng')) {
//if ($validationMode == 'jing') {
//if (true) {
$jing = \laabs::newService('dependency/xml/plugins/jing/jing');
$valid = $jing->validate($profilePath.'.rng', $this->message->path);
if (!$valid) {
$this->sendError("203");
foreach ($jing->getErrors() as $errorMessage) {
$this->errors[] = new \core\Error($errorMessage);
}
}
} else {
libxml_use_internal_errors(true);
$valid = $message->xml->relaxNGValidate($profileFile);
if ($valid == false) {
$this->sendError("203");
foreach (libxml_get_errors() as $libxmlError) {
$this->errors[] = new \core\Error($libxmlError->message, null, $libxmlError->code);
}
}
libxml_clear_errors();
libxml_use_internal_errors(false);
foreach ($jing->getErrors() as $errorMessage) {
$this->errors[] = new \core\Error($errorMessage);
}
break;
case 'xsd':
libxml_use_internal_errors(true);
$valid = $message->xml->schemaValidate($profileFile);
if ($valid == false) {
foreach (libxml_get_errors() as $libxmlError) {
$this->errors[] = new \core\Error($libxmlError->message, null, $libxmlError->code);
}
}
libxml_clear_errors();
libxml_use_internal_errors(false);
break;
default:
$path = $this->profilesDirectory.DIRECTORY_SEPARATOR.$archivalprofileReference;
// if a profile were previously saved without extension
if (empty($extension) && (file_exists($path . '.rng') || file_exists($path . '.xsd'))) {
break;
}
/*} else {
libxml_use_internal_errors(true);
$valid = $message->xml->relaxNGValidate($profileFile);
if ($valid == false) {
$this->sendError("203");
foreach (libxml_get_errors() as $libxmlError) {
$this->errors[] = new \core\Error($libxmlError->message, null, $libxmlError->code);
}
$this->sendError("203", "Le profil d'archive identifié par '$archivalProfileReference' est dans un format non géré par le système.");
break;
}
libxml_clear_errors();
libxml_use_internal_errors(false);
}*/
} elseif (file_exists($profilePath . '.xsd')) {
libxml_use_internal_errors(true);
$valid = $message->xml->schemaValidate($profilePath.'.xsd');
if ($valid == false) {
foreach (libxml_get_errors() as $libxmlError) {
$this->errors[] = new \core\Error($libxmlError->message, null, $libxmlError->code);
}
}
libxml_clear_errors();
libxml_use_internal_errors(false);
} else {
$this->sendError("203", "Le fichier de profil d'archive identifié par '$archivalProfileReference' n'existe pas.");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment