コード例 #1
0
 /**
  * Validates that the xml is valid using the XSD
  *@return bool - if the validation is ok
  */
 protected function validate()
 {
     if (!file_exists($this->data->filePath)) {
         throw new KalturaBatchException("File doesn't exist [{$this->data->filePath}]", KalturaBatchJobAppErrors::BULK_FILE_NOT_FOUND);
     }
     libxml_use_internal_errors(true);
     $this->loadXslt();
     $xdoc = new KDOMDocument();
     $this->xslTransformedContent = $this->xslTransform($this->data->filePath);
     KalturaLog::info("Tranformed content: " . $this->xslTransformedContent);
     libxml_clear_errors();
     if (!$xdoc->loadXML($this->xslTransformedContent)) {
         $errorMessage = kXml::getLibXmlErrorDescription($this->xslTransformedContent);
         KalturaLog::debug("Could not load xml");
         throw new KalturaBatchException("Could not load xml [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED);
     }
     //Validate the XML file against the schema
     libxml_clear_errors();
     $xsdURL = KBatchBase::$kClient->schema->serve($this->getSchemaType());
     if (KBatchBase::$taskConfig->params->xmlSchemaVersion) {
         $xsdURL .= "&version=" . KBatchBase::$taskConfig->params->xmlSchemaVersion;
     }
     $xsd = KCurlWrapper::getContent($xsdURL);
     if (!$xdoc->schemaValidateSource($xsd)) {
         $errorMessage = kXml::getLibXmlErrorDescription($this->xslTransformedContent);
         KalturaLog::debug("XML is invalid:\n{$errorMessage}");
         throw new KalturaBatchException("Validate files failed on job [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED);
     }
     return true;
 }
コード例 #2
0
ファイル: kMetadataManager.php プロジェクト: AdiTal/server
 /**
  * Validate the XML against the profile XSD and set the metadata status
  *
  * @param int $metadataProfileId
  * @param string $metadata
  * @param string $errorMessage
  * @param int $compareAgainstPreviousVersion leave it false to use the latest metadata profile version
  *
  * returns bool
  */
 public static function validateMetadata($metadataProfileId, $metadata, &$errorMessage, $compareAgainstPreviousVersion = false)
 {
     KalturaLog::debug("Validating metadata [{$metadata}]");
     $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId);
     if (!$metadataProfile) {
         $errorMessage = "Metadata profile [{$metadataProfileId}] not found";
         KalturaLog::err($errorMessage);
         return false;
     }
     $metadataProfileFSVersion = null;
     if ($compareAgainstPreviousVersion) {
         $metadataProfileFSVersion = $metadataProfile->getPreviousFileSyncVersion();
     }
     $metadataProfileKey = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION, $metadataProfileFSVersion);
     $xsdData = kFileSyncUtils::file_get_contents($metadataProfileKey, true, false);
     if (!$xsdData) {
         $errorMessage = "Metadata profile xsd not found";
         KalturaLog::err($errorMessage);
         return false;
     }
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xml = new KDOMDocument();
     $xml->loadXML($metadata);
     if ($xml->schemaValidateSource($xsdData)) {
         if (!self::validateMetadataObjects($metadataProfileId, $xml, $errorMessage)) {
             KalturaLog::err($errorMessage);
             return false;
         }
         KalturaLog::debug("Metadata is valid");
         return true;
     }
     $errorMessage = kXml::getLibXmlErrorDescription($metadata);
     KalturaLog::err("Metadata is invalid:\n{$errorMessage}");
     return false;
 }