/**
  * @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());
         if ($toObject instanceof Partner) {
             $newMetadata->setPartnerId($toObject->getId());
         } else {
             $newMetadata->setPartnerId($toObject->getPartnerId());
         }
         $metadataProfileId = kObjectCopyHandler::getMappedId('MetadataProfile', $metadata->getMetadataProfileId());
         if ($metadataProfileId) {
             $metadataProfile = MetadataProfilePeer::retrieveByPK($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));
     }
 }
 /**
  * @param int $objectType
  * @param string $objectId
  */
 protected function deleteMetadataObjects($objectType, $objectId)
 {
     $c = new Criteria();
     $c->add(MetadataPeer::OBJECT_TYPE, $objectType);
     $c->add(MetadataPeer::OBJECT_ID, $objectId);
     $c->add(MetadataPeer::STATUS, Metadata::STATUS_DELETED, Criteria::NOT_EQUAL);
     $peer = null;
     MetadataPeer::setUseCriteriaFilter(false);
     $metadatas = MetadataPeer::doSelect($c);
     foreach ($metadatas as $metadata) {
         kEventsManager::raiseEvent(new kObjectDeletedEvent($metadata));
     }
     $update = new Criteria();
     $update->add(MetadataPeer::STATUS, Metadata::STATUS_DELETED);
     $con = Propel::getConnection(MetadataPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     BasePeer::doUpdate($c, $update, $con);
 }
 /**
  * batch getTransformMetadataObjects action retrieve all metadata objects that requires upgrade and the total count 
  * 
  * @action getTransformMetadataObjects
  * @param int $metadataProfileId The id of the metadata profile
  * @param int $srcVersion The old metadata profile version
  * @param int $destVersion The new metadata profile version
  * @param KalturaFilterPager $pager
  * @return KalturaTransformMetadataResponse
  */
 function getTransformMetadataObjectsAction($metadataProfileId, $srcVersion, $destVersion, KalturaFilterPager $pager = null)
 {
     $response = new KalturaTransformMetadataResponse();
     $c = new Criteria();
     $c->add(MetadataPeer::METADATA_PROFILE_ID, $metadataProfileId);
     $c->add(MetadataPeer::METADATA_PROFILE_VERSION, $srcVersion, Criteria::LESS_THAN);
     $c->add(MetadataPeer::STATUS, KalturaMetadataStatus::VALID);
     $response->lowerVersionCount = MetadataPeer::doCount($c);
     $c = new Criteria();
     $c->add(MetadataPeer::METADATA_PROFILE_ID, $metadataProfileId);
     $c->add(MetadataPeer::METADATA_PROFILE_VERSION, $srcVersion);
     $c->add(MetadataPeer::STATUS, KalturaMetadataStatus::VALID);
     $response->totalCount = MetadataPeer::doCount($c);
     if ($pager) {
         $pager->attachToCriteria($c);
     }
     $list = MetadataPeer::doSelect($c);
     $response->objects = KalturaMetadataArray::fromDbArray($list);
     return $response;
 }
예제 #4
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;
 }
예제 #5
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(MetadataPeer::DATABASE_NAME);
         $criteria->add(MetadataPeer::ID, $pks, Criteria::IN);
         $objs = MetadataPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #6
0
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if (kEntitlementUtils::getEntitlementEnforcement() && (is_null($this->objectIdIn) && is_null($this->objectIdEqual))) {
         throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_ID);
     }
     if (!$this->metadataObjectTypeEqual) {
         throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_TYPE);
     }
     if ($this->metadataObjectTypeEqual == MetadataObjectType::CATEGORY) {
         if ($this->objectIdEqual) {
             $categoryIds = array($this->objectIdEqual);
         } else {
             if ($this->objectIdIn) {
                 $categoryIds = explode(',', $this->objectIdIn);
             }
         }
         if ($categoryIds) {
             $categories = categoryPeer::retrieveByPKs($categoryIds);
             if (!count($categories)) {
                 KalturaLog::debug("No categories found");
                 $response = new KalturaMetadataListResponse();
                 $response->objects = new KalturaMetadataArray();
                 $response->totalCount = 0;
                 return $response;
             }
             $categoryIds = array();
             foreach ($categories as $category) {
                 $categoryIds[] = $category->getId();
             }
             $this->objectIdEqual = null;
             $this->objectIdIn = implode(',', $categoryIds);
         }
     }
     $metadataFilter = $this->toObject();
     $c = KalturaCriteria::create(MetadataPeer::OM_CLASS);
     $metadataFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $list = MetadataPeer::doSelect($c);
     $response = new KalturaMetadataListResponse();
     $response->objects = KalturaMetadataArray::fromDbArray($list, $responseProfile);
     if ($c instanceof SphinxMetadataCriteria) {
         $response->totalCount = $c->getRecordsCount();
     } elseif ($pager->pageIndex == 1 && count($response->objects) < $pager->pageSize) {
         $response->totalCount = count($response->objects);
     } else {
         $pager->detachFromCriteria($c);
         $response->totalCount = MetadataPeer::doCount($c);
     }
     return $response;
 }
예제 #7
0
 /**
  * Delete an existing metadata profile
  *
  * @action delete
  * @param int $id
  * @throws MetadataErrors::METADATA_PROFILE_NOT_FOUND
  */
 function deleteAction($id)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $id);
     }
     // if this profile is a dynamic object, check for references in other profiles
     if ($dbMetadataProfile->getObjectType() == MetadataObjectType::DYNAMIC_OBJECT) {
         $referencedFields = MetadataProfileFieldPeer::retrieveByPartnerAndRelatedMetadataProfileId(kCurrentContext::getCurrentPartnerId(), $dbMetadataProfile->getId());
         if (count($referencedFields)) {
             /** @var MetadataProfileField $referencedField */
             $referencedField = $referencedFields[0];
             throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_REFERENCE_EXISTS, $referencedField->getMetadataProfileId(), $referencedField->getKey());
         }
     }
     $dbMetadataProfile->setStatus(KalturaMetadataProfileStatus::DEPRECATED);
     $dbMetadataProfile->save();
     $c = new Criteria();
     $c->add(MetadataProfileFieldPeer::METADATA_PROFILE_ID, $id);
     $c->add(MetadataProfileFieldPeer::STATUS, MetadataProfileField::STATUS_DEPRECATED, Criteria::NOT_EQUAL);
     $MetadataProfileFields = MetadataProfileFieldPeer::doSelect($c);
     foreach ($MetadataProfileFields as $MetadataProfileField) {
         $MetadataProfileField->setStatus(MetadataProfileField::STATUS_DEPRECATED);
         $MetadataProfileField->save();
     }
     $c = new Criteria();
     $c->add(MetadataPeer::METADATA_PROFILE_ID, $id);
     $c->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED, Criteria::NOT_EQUAL);
     $peer = null;
     MetadataPeer::setUseCriteriaFilter(false);
     $metadatas = MetadataPeer::doSelect($c);
     foreach ($metadatas as $metadata) {
         kEventsManager::raiseEvent(new kObjectDeletedEvent($metadata));
     }
     $update = new Criteria();
     $update->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED);
     $con = Propel::getConnection(MetadataPeer::DATABASE_NAME);
     BasePeer::doUpdate($c, $update, $con);
 }
예제 #8
0
 /**
  * Delete an existing metadata profile
  * 
  * @action delete
  * @param int $id
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 function deleteAction($id)
 {
     $dbMetadataProfile = MetadataProfilePeer::retrieveByPK($id);
     if (!$dbMetadataProfile) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     $dbMetadataProfile->setStatus(KalturaMetadataProfileStatus::DEPRECATED);
     $dbMetadataProfile->save();
     $c = new Criteria();
     $c->add(MetadataPeer::METADATA_PROFILE_ID, $id);
     $c->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED, Criteria::NOT_EQUAL);
     $peer = null;
     MetadataPeer::setUseCriteriaFilter(false);
     $metadatas = MetadataPeer::doSelect($c);
     foreach ($metadatas as $metadata) {
         kEventsManager::raiseEvent(new kObjectDeletedEvent($metadata));
     }
     $update = new Criteria();
     $update->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED);
     $con = Propel::getConnection(MetadataPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     BasePeer::doUpdate($c, $update, $con);
 }
예제 #9
0
 /**
  * Retrieve all metadta objects of object ids and type.
  *
  * @param      int $objectType
  * @param      array $objectIds
  * @param      PropelPDO $con the connection to use
  * @return     array<Metadata>
  */
 public static function retrieveAllByObjectIds($objectType, array $objectIds, PropelPDO $con = null)
 {
     $criteria = new Criteria();
     $criteria->add(MetadataPeer::OBJECT_TYPE, $objectType);
     $criteria->add(MetadataPeer::OBJECT_ID, $objectIds, Criteria::IN);
     return MetadataPeer::doSelect($criteria, $con);
 }
예제 #10
0
if ($argc > 3 && is_numeric($argv[3])) {
    $c->add(MetadataPeer::ID, $argv[3], Criteria::GREATER_EQUAL);
}
if ($argc > 4) {
    MetadataPeer::setUseCriteriaFilter((bool) $argv[4]);
}
// only dynamic objects are saved to sphinx for now
$c->addAnd(MetadataPeer::OBJECT_TYPE, MetadataObjectType::DYNAMIC_OBJECT);
$c->addAscendingOrderByColumn(MetadataPeer::UPDATED_AT);
$c->addAscendingOrderByColumn(MetadataPeer::ID);
$c->setLimit(10000);
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
$metadatas = MetadataPeer::doSelect($c, $con);
$sphinx = new kSphinxSearchManager();
while (count($metadatas)) {
    foreach ($metadatas as $metadata) {
        /* @var $metadata Metadata */
        KalturaLog::log('metadata id ' . $metadata->getId() . ' updated at ' . $metadata->getUpdatedAt(null));
        try {
            $ret = $sphinx->saveToSphinx($metadata, true);
        } catch (Exception $e) {
            KalturaLog::err($e->getMessage());
            exit - 1;
        }
    }
    $c->setOffset($c->getOffset() + count($metadatas));
    kMemoryManager::clearMemory();
    $metadatas = MetadataPeer::doSelect($c, $con);
}
KalturaLog::log('Done. Curent time: ' . time());
exit(0);