Пример #1
0
 /**
  * @param Metadata $object
  *
  * @return BaseObject returns the object referenced by the peer
  */
 public static function getObjectFromPeer(Metadata $metadata)
 {
     $objectType = $metadata->getObjectType();
     $peer = self::getObjectPeer($objectType);
     if (!$peer) {
         return null;
     }
     return $peer->retrieveByPK($metadata->getObjectId());
 }
 /**
  * @param Metadata $metadata
  */
 public static function onMetadataChanged(Metadata $metadata, $previousVersion)
 {
     if (!ContentDistributionPlugin::isAllowedPartner($metadata->getPartnerId())) {
         return true;
     }
     if ($metadata->getObjectType() != MetadataObjectType::ENTRY) {
         return true;
     }
     KalturaLog::log("Metadata [" . $metadata->getId() . "] for entry [" . $metadata->getObjectId() . "] changed");
     $syncKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xmlPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     if (!$xmlPath) {
         KalturaLog::log("Entry metadata xml not found");
         return true;
     }
     $xml = new KDOMDocument();
     $xml->load($xmlPath);
     $previousXml = null;
     if ($previousVersion) {
         $syncKey = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA, $previousVersion);
         $xmlPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
         if ($xmlPath) {
             $previousXml = new KDOMDocument();
             $previousXml->load($xmlPath);
         } else {
             KalturaLog::log("Entry metadata previous version xml not found");
         }
     }
     $entryDistributions = EntryDistributionPeer::retrieveByEntryId($metadata->getObjectId());
     foreach ($entryDistributions as $entryDistribution) {
         if ($entryDistribution->getStatus() != EntryDistributionStatus::QUEUED && $entryDistribution->getStatus() != EntryDistributionStatus::PENDING && $entryDistribution->getStatus() != EntryDistributionStatus::READY) {
             continue;
         }
         $distributionProfileId = $entryDistribution->getDistributionProfileId();
         $distributionProfile = DistributionProfilePeer::retrieveByPK($distributionProfileId);
         if (!$distributionProfile) {
             KalturaLog::err("Entry distribution [" . $entryDistribution->getId() . "] profile [{$distributionProfileId}] not found");
             continue;
         }
         $distributionProvider = $distributionProfile->getProvider();
         if (!$distributionProvider) {
             KalturaLog::err("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProfile->getProviderType() . "] not found");
             continue;
         }
         if ($entryDistribution->getStatus() == EntryDistributionStatus::PENDING || $entryDistribution->getStatus() == EntryDistributionStatus::QUEUED) {
             $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::SUBMIT);
             $entryDistribution->setValidationErrorsArray($validationErrors);
             $entryDistribution->save();
             if ($entryDistribution->getStatus() == EntryDistributionStatus::QUEUED) {
                 if ($entryDistribution->getDirtyStatus() != EntryDistributionDirtyStatus::SUBMIT_REQUIRED) {
                     self::submitAddEntryDistribution($entryDistribution, $distributionProfile);
                 }
             }
             continue;
         }
         if ($entryDistribution->getStatus() == EntryDistributionStatus::READY) {
             if ($entryDistribution->getDirtyStatus() == EntryDistributionDirtyStatus::UPDATE_REQUIRED) {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] already flaged for updating");
                 //					continue;
             }
             if (!$distributionProvider->isUpdateEnabled()) {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update");
                 continue;
             }
             $updateRequiredMetadataXPaths = $distributionProvider->getUpdateRequiredMetadataXPaths($distributionProfileId);
             $updateRequired = false;
             foreach ($updateRequiredMetadataXPaths as $updateRequiredMetadataXPath) {
                 $xPath = new DOMXpath($xml);
                 $newElements = $xPath->query($updateRequiredMetadataXPath);
                 $oldElements = null;
                 if ($previousXml) {
                     $xPath = new DOMXpath($previousXml);
                     $oldElements = $xPath->query($updateRequiredMetadataXPath);
                 }
                 if (is_null($newElements) && is_null($oldElements)) {
                     continue;
                 }
                 if (is_null($newElements) xor is_null($oldElements)) {
                     $updateRequired = true;
                 } elseif ($newElements->length == $oldElements->length) {
                     for ($index = 0; $index < $newElements->length; $index++) {
                         $newValue = $newElements->item($index)->textContent;
                         $oldValue = $oldElements->item($index)->textContent;
                         if ($newValue != $oldValue) {
                             $updateRequired = true;
                             break;
                         }
                     }
                 }
                 if ($updateRequired) {
                     break;
                 }
             }
             $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::UPDATE);
             $entryDistribution->setValidationErrorsArray($validationErrors);
             $entryDistribution->save();
             if (!$updateRequired) {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] update not required");
                 continue;
             }
             if (!count($validationErrors) && $distributionProfile->getUpdateEnabled() == DistributionProfileActionStatus::AUTOMATIC) {
                 self::submitUpdateEntryDistribution($entryDistribution, $distributionProfile);
             } else {
                 KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] should not be updated automatically");
                 $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::UPDATE_REQUIRED);
                 $entryDistribution->save();
                 continue;
             }
         }
     }
     return true;
 }
Пример #3
0
 /**
  * @param Metadata $metadata
  * @return int affected records
  */
 protected function deleteOldVersions(Metadata $metadata)
 {
     $c = new Criteria();
     $c->add(MetadataPeer::OBJECT_ID, $metadata->getObjectId());
     $c->add(MetadataPeer::OBJECT_TYPE, $metadata->getObjectType());
     $c->add(MetadataPeer::METADATA_PROFILE_ID, $metadata->getMetadataProfileId());
     $c->add(MetadataPeer::METADATA_PROFILE_VERSION, $metadata->getMetadataProfileVersion(), Criteria::LESS_THAN);
     $c->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED, Criteria::NOT_EQUAL);
     MetadataPeer::setUseCriteriaFilter(false);
     $metadatas = MetadataPeer::doSelect($c);
     MetadataPeer::setUseCriteriaFilter(true);
     foreach ($metadatas as $metadata) {
         kEventsManager::raiseEvent(new kObjectDeletedEvent($metadata));
     }
     $update = new Criteria();
     $update->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED);
     $con = Propel::getConnection(MetadataPeer::DATABASE_NAME);
     $count = BasePeer::doUpdate($c, $update, $con);
     return $count;
 }