protected function updatedTransformMetadataFailed(BatchJob $dbBatchJob, kTransformMetadataJobData $data, BatchJob $twinJob = null)
 {
     if (!$data->getMetadataProfileId()) {
         return $dbBatchJob;
     }
     $metadataProfile = MetadataProfilePeer::retrieveById($data->getMetadataProfileId());
     if (!$metadataProfile) {
         return $dbBatchJob;
     }
     $metadataProfile->setStatus(MetadataProfile::STATUS_DEPRECATED);
     $metadataProfile->save();
     return $dbBatchJob;
 }
 /**
  * @param KalturaMetadataObjectType $objectType
  * @param BaseObject $fromObject
  * @param BaseObject $toObject
  */
 protected function copyMetadata($objectType, BaseObject $fromObject, BaseObject $toObject)
 {
     KalturaLog::debug("Copy metadata type [{$objectType}] from " . get_class($fromObject) . '[' . $fromObject->getId() . "] to[" . $toObject->getId() . "]");
     $c = new Criteria();
     $c->add(MetadataPeer::OBJECT_TYPE, $objectType);
     $c->add(MetadataPeer::OBJECT_ID, $fromObject->getId());
     $metadatas = MetadataPeer::doSelect($c);
     foreach ($metadatas as $metadata) {
         $newMetadata = $metadata->copy();
         $newMetadata->setObjectId($toObject->getId());
         $newMetadata->setPartnerId($toObject->getPartnerId());
         $metadataProfileId = kObjectCopyHandler::getMappedId('MetadataProfile', $metadata->getMetadataProfileId());
         if ($metadataProfileId) {
             $metadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId);
             if ($metadataProfile) {
                 $newMetadata->setMetadataProfileId($metadataProfileId);
                 $newMetadata->setMetadataProfileVersion($metadataProfile->getVersion());
             }
         }
         $newMetadata->save();
         kFileSyncUtils::createSyncFileLinkForKey($newMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA), $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA), false);
     }
 }
// ---------------------------------------------------------------------------
$xsltFilePath = '';
//TODO: change to valid xslt file path
$metadataProfileId = null;
//TODO: change to a valid metadata profile id
// ---------------------------------------------------------------------------
if (!$xsltFilePath) {
    die('ERROR - Missing parameter [$xsltFilePath]' . PHP_EOL);
}
if (!$metadataProfileId) {
    die('ERROR - Missing parameter [$metadataProfileId]' . PHP_EOL);
}
if (!file_exists($xsltFilePath)) {
    die('ERROR - Cannot find file at [' . $xsltFilePath . ']' . PHP_EOL);
}
require_once dirname(__FILE__) . '/../bootstrap.php';
require_once dirname(__FILE__) . '/../../api_v3/bootstrap.php';
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"));
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "metadata", "*"));
KAutoloader::setClassMapFilePath(kConf::get("cache_root_path") . '/scripts/' . basename(__FILE__) . '.cache');
KAutoloader::register();
KalturaPluginManager::addPlugin('MetadataPlugin');
$dbMetadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId);
if (!$dbMetadataProfile) {
    die('ERROR - Cannot find metadata profile with id [' . $metadataProfileId . ']' . PHP_EOL);
}
$dbMetadataProfile->incrementXsltVersion();
$dbMetadataProfile->save();
$key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT);
kFileSyncUtils::moveFromFile($xsltFilePath, $key, true, true);
echo 'Done' . PHP_EOL;
Beispiel #4
0
 /**
  * @return MetadataProfile
  */
 public function getMetadataProfile()
 {
     if ($this->aMetadataProfile === null && $this->metadata_profile_id) {
         $this->aMetadataProfile = MetadataProfilePeer::retrieveById($this->metadata_profile_id);
     }
     return $this->aMetadataProfile;
 }
Beispiel #5
0
 /**
  * @param string $entryId the new created entry
  * @param array $data key => value pairs
  */
 public static function handleBulkUploadData($entryId, array $data)
 {
     KalturaLog::debug("Handle metadata bulk upload data:\n" . print_r($data, true));
     if (!isset($data[self::BULK_UPLOAD_COLUMN_PROFILE_ID])) {
         return;
     }
     $metadataProfileId = $data[self::BULK_UPLOAD_COLUMN_PROFILE_ID];
     $xmlData = null;
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         return;
     }
     //		$criteriaFilter = FileSyncPeer::getCriteriaFilter();
     //		$criteria = $criteriaFilter->getFilter();
     //		$criteria->add(FileSyncPeer::PARTNER_ID, $entry->getPartnerId());
     $metadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId);
     if (!$metadataProfile) {
         $errorMessage = "Metadata profile [{$metadataProfileId}] not found";
         KalturaLog::err($errorMessage);
         self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
         return;
     }
     if (isset($data[self::BULK_UPLOAD_COLUMN_URL])) {
         try {
             $xmlData = file_get_contents($data[self::BULK_UPLOAD_COLUMN_URL]);
             KalturaLog::debug("Metadata downloaded [" . $data[self::BULK_UPLOAD_COLUMN_URL] . "]");
         } catch (Exception $e) {
             $errorMessage = "Download metadata[" . $data[self::BULK_UPLOAD_COLUMN_URL] . "] error: " . $e->getMessage();
             KalturaLog::err($errorMessage);
             self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
             $xmlData = null;
         }
     } elseif (isset($data[self::BULK_UPLOAD_COLUMN_XML])) {
         $xmlData = $data[self::BULK_UPLOAD_COLUMN_XML];
     } else {
         $metadataProfileFields = array();
         MetadataProfileFieldPeer::setUseCriteriaFilter(false);
         $tmpMetadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfileId);
         MetadataProfileFieldPeer::setUseCriteriaFilter(true);
         foreach ($tmpMetadataProfileFields as $metadataProfileField) {
             $metadataProfileFields[$metadataProfileField->getKey()] = $metadataProfileField;
         }
         KalturaLog::debug("Found fields [" . count($metadataProfileFields) . "] for metadata profile [{$metadataProfileId}]");
         $xml = new DOMDocument();
         $dataFound = false;
         foreach ($data as $key => $value) {
             if (!$value || !strlen($value)) {
                 continue;
             }
             if (!preg_match('/^' . self::BULK_UPLOAD_COLUMN_FIELD_PREFIX . '(.+)$/', $key, $matches)) {
                 continue;
             }
             $key = $matches[1];
             if (!isset($metadataProfileFields[$key])) {
                 $errorMessage = "Field [{$key}] does not exist";
                 KalturaLog::debug($errorMessage);
                 self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
                 continue;
             }
             $metadataProfileField = $metadataProfileFields[$key];
             KalturaLog::debug("Found field [" . $metadataProfileField->getXpath() . "] for value [{$value}]");
             $fieldValues = explode(self::BULK_UPLOAD_MULTI_VALUES_DELIMITER, $value);
             foreach ($fieldValues as $fieldValue) {
                 if ($metadataProfileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE && !is_numeric($fieldValue)) {
                     $value = self::parseFormatedDate($fieldValue);
                     if (!$value || !strlen($value)) {
                         $errorMessage = "Could not parse date format [{$fieldValue}] for field [{$key}]";
                         KalturaLog::debug($errorMessage);
                         self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
                         continue;
                     }
                     $fieldValue = $value;
                 }
                 self::addXpath($xml, $metadataProfileField->getXpath(), $fieldValue);
             }
             $dataFound = true;
         }
         if ($dataFound) {
             $xmlData = $xml->saveXML($xml->firstChild);
             $xmlData = trim($xmlData, " \n\r\t");
         }
     }
     if (!$xmlData) {
         return;
     }
     $dbMetadata = new Metadata();
     $dbMetadata->setPartnerId($entry->getPartnerId());
     $dbMetadata->setMetadataProfileId($metadataProfileId);
     $dbMetadata->setMetadataProfileVersion($metadataProfile->getVersion());
     $dbMetadata->setObjectType(Metadata::TYPE_ENTRY);
     $dbMetadata->setObjectId($entryId);
     $dbMetadata->setStatus(Metadata::STATUS_INVALID);
     $dbMetadata->save();
     KalturaLog::debug("Metadata [" . $dbMetadata->getId() . "] saved [{$xmlData}]");
     $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     kFileSyncUtils::file_put_contents($key, $xmlData);
     $errorMessage = '';
     $status = kMetadataManager::validateMetadata($dbMetadata, $errorMessage);
     if ($status == Metadata::STATUS_VALID) {
         kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata));
     } else {
         self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage);
     }
 }
 /**
  * @param int $metadataProfileId
  * @param BaseObject $object
  * @param array $data
  */
 protected static function addMetadataWithProfileId(BaseObject $object, array $data)
 {
     $metadataProfileId = $data[self::BULK_UPLOAD_COLUMN_PROFILE_ID];
     $metadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId);
     if (!$metadataProfile) {
         $errorMessage = "Metadata profile [{$metadataProfileId}] not found";
         KalturaLog::err($errorMessage);
         self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
         return;
     }
     if ($metadataProfile->getObjectType() != kMetadataManager::getTypeNameFromObject($object)) {
         $errorMessage = "Metadata profile [{$metadataProfileId}] object type [" . $metadataProfile->getObjectType() . "] is not compatible with object type [" . kMetadataManager::getTypeNameFromObject($object) . "]";
         KalturaLog::err($errorMessage);
         self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
         return;
     }
     if (isset($data[self::BULK_UPLOAD_COLUMN_URL])) {
         try {
             $xmlData = file_get_contents($data[self::BULK_UPLOAD_COLUMN_URL]);
             KalturaLog::debug("Metadata downloaded [" . $data[self::BULK_UPLOAD_COLUMN_URL] . "]");
         } catch (Exception $e) {
             $errorMessage = "Download metadata[" . $data[self::BULK_UPLOAD_COLUMN_URL] . "] error: " . $e->getMessage();
             KalturaLog::err($errorMessage);
             self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
             $xmlData = null;
         }
     } elseif (isset($data[self::BULK_UPLOAD_COLUMN_XML])) {
         $xmlData = $data[self::BULK_UPLOAD_COLUMN_XML];
     } else {
         $metadataProfileFields = array();
         MetadataProfileFieldPeer::setUseCriteriaFilter(false);
         $tmpMetadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfileId);
         MetadataProfileFieldPeer::setUseCriteriaFilter(true);
         foreach ($tmpMetadataProfileFields as $metadataProfileField) {
             $metadataProfileFields[$metadataProfileField->getKey()] = $metadataProfileField;
         }
         KalturaLog::debug("Found fields [" . count($metadataProfileFields) . "] for metadata profile [{$metadataProfileId}]");
         $xml = new DOMDocument();
         $dataFound = false;
         foreach ($data as $key => $value) {
             if (!$value || !strlen($value)) {
                 continue;
             }
             if (!preg_match('/^' . self::BULK_UPLOAD_COLUMN_FIELD_PREFIX . '(.+)$/', $key, $matches)) {
                 continue;
             }
             $key = $matches[1];
             if (!isset($metadataProfileFields[$key])) {
                 $errorMessage = "Field [{$key}] does not exist";
                 KalturaLog::err($errorMessage);
                 self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
                 continue;
             }
             $metadataProfileField = $metadataProfileFields[$key];
             KalturaLog::debug("Found field [" . $metadataProfileField->getXpath() . "] for value [{$value}]");
             $fieldValues = explode(self::BULK_UPLOAD_MULTI_VALUES_DELIMITER, $value);
             foreach ($fieldValues as $fieldValue) {
                 if ($fieldValue) {
                     if ($metadataProfileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE && !is_numeric($fieldValue)) {
                         $value = self::parseFormatedDate($fieldValue);
                         if (!$value || !strlen($value)) {
                             $errorMessage = "Could not parse date format [{$fieldValue}] for field [{$key}]";
                             KalturaLog::err($errorMessage);
                             self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
                             continue;
                         }
                         $fieldValue = $value;
                     }
                     if ($metadataProfileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_INT && !is_numeric($fieldValue)) {
                         $errorMessage = "Could not parse int format [{$fieldValue}] for field [{$key}]";
                         KalturaLog::err($errorMessage);
                         self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
                         continue;
                     }
                     self::addXpath($xml, $metadataProfileField->getXpath(), $fieldValue);
                 }
             }
             $dataFound = true;
         }
         if ($dataFound && $xml->hasChildNodes()) {
             $xmlData = $xml->saveXML($xml->firstChild);
             $xmlData = trim($xmlData, " \n\r\t");
         }
     }
     if (!$xmlData) {
         return;
     }
     $errorMessage = '';
     if (!kMetadataManager::validateMetadata($metadataProfileId, $xmlData, $errorMessage)) {
         self::addBulkUploadResultDescription($object, $object->getBulkUploadId(), $errorMessage);
         return;
     }
     $dbMetadata = $dbMetadata = self::createOrFindMetadataObject($object, $metadataProfile);
     KalturaLog::debug("Metadata [" . $dbMetadata->getId() . "] saved [{$xmlData}]");
     $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     kFileSyncUtils::file_put_contents($key, $xmlData);
     kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata));
 }