/** * Update an existing metadata object definition file * * @action revert * @param int $id * @param int $toVersion * @return KalturaMetadataProfile * @throws MetadataErrors::METADATA_PROFILE_NOT_FOUND * @throws MetadataErrors::METADATA_FILE_NOT_FOUND * @throws MetadataErrors::METADATA_UNABLE_TO_TRANSFORM */ function revertAction($id, $toVersion) { $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id); if (!$dbMetadataProfile) { throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $id); } $oldKey = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION, $toVersion); if (!kFileSyncUtils::fileSync_exists($oldKey)) { throw new KalturaAPIException(MetadataErrors::METADATA_FILE_NOT_FOUND, $oldKey); } $dbMetadataProfile->incrementFileSyncVersion(); $dbMetadataProfile->incrementVersion(); $dbMetadataProfile->save(); $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION); kFileSyncUtils::createSyncFileLinkForKey($key, $oldKey); kMetadataManager::parseProfileSearchFields($this->getPartnerId(), $dbMetadataProfile); MetadataPeer::setUseCriteriaFilter(false); $metadatas = MetadataPeer::retrieveByProfile($id, $toVersion); foreach ($metadatas as $metadata) { // validate object exists $object = kMetadataManager::getObjectFromPeer($metadata); if (!$object) { continue; } $metadata->incrementVersion(); $oldKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA, $toVersion); if (!kFileSyncUtils::fileSync_exists($oldKey)) { continue; } $xml = kFileSyncUtils::file_get_contents($oldKey, true, false); if (!$xml) { continue; } $errorMessage = ''; if (!kMetadataManager::validateMetadata($dbMetadataProfile->getId(), $xml, $errorMessage)) { continue; } $metadata->setMetadataProfileVersion($dbMetadataProfile->getVersion()); $metadata->setStatus(Metadata::STATUS_VALID); $metadata->save(); $key = $metadata->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION); kFileSyncUtils::createSyncFileLinkForKey($key, $oldKey); } $metadataProfile = new KalturaMetadataProfile(); $metadataProfile->fromObject($dbMetadataProfile, $this->getResponseProfile()); return $metadataProfile; }