private function reconvertEntry($entry_id, $conversion_profile_id, $job_priority) { $entry = entryPeer::retrieveByPK($entry_id); $this->error = ""; if (!$entry) { $error = "Cannot reconvert entry [{$entry_id}]. Might be a deleted entry"; return array($entry_id, null, null, $error); } $flavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry_id); if (!$flavorAsset) { $flavorAsset = flavorAssetPeer::retrieveReadyWebByEntryId($entry_id); if (!$flavorAsset) { $flavorAssets = flavorAssetPeer::retrieveByEntryId($entry_id); if (!$flavorAssets) { $error = "Cannot find good enough flavor asset to re-convert from"; return array($entry_id, $entry, null, $error); } $flavorAsset = $flavorAssets[0]; // choose the first one } } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); if (!$filePath) { $error = "Cannot find a fileSync for the flavorAsset [" . $flavorAsset->getId() . "]"; return array($entry_id, $entry, null, $error); } $dbBatchJob = new BatchJob(); $dbBatchJob->setEntryId($entry_id); $dbBatchJob->setPartnerId($entry->getPartnerId()); $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_PENDING); $dbBatchJob->setDc(kDataCenterMgr::getCurrentDcId()); $dbBatchJob->setPriority($job_priority); $dbBatchJob->save(); // creates a convert profile job $convertProfileData = new kConvertProfileJobData(); $convertProfileData->setFlavorAssetId($flavorAsset->getId()); $convertProfileData->setInputFileSyncLocalPath($filePath); kJobsManager::addJob($dbBatchJob, $convertProfileData, BatchJobType::CONVERT_PROFILE); // save again afget the addJob $dbBatchJob->save(); return array($entry_id, $entry, $dbBatchJob, $error); }
/** * batch decideAddEntryFlavor is the decision layer for adding a single flavor conversion to an entry * * @param BatchJob $parentJob * @param int $entryId * @param int $flavorParamsId * @param string $errDescription * @param string $flavorAssetId * @return BatchJob */ public static function decideAddEntryFlavor(BatchJob $parentJob = null, $entryId, $flavorParamsId, &$errDescription) { KalturaLog::log("entryId [{$entryId}], flavorParamsId [{$flavorParamsId}]"); $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId); if (is_null($originalFlavorAsset)) { $errDescription = 'Original flavor asset not found'; KalturaLog::log(__METHOD__ . " - " . $errDescription); return null; } if ($originalFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { $errDescription = 'Original flavor asset not ready'; KalturaLog::log(__METHOD__ . " - " . $errDescription); return null; } $mediaInfoId = null; $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId()); if ($mediaInfo) { $mediaInfoId = $mediaInfo->getId(); } $flavorParams = flavorParamsPeer::retrieveByPK($flavorParamsId); $flavor = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription); if (is_null($flavor)) { KalturaLog::log(__METHOD__ . " - Failed to validate media info [{$errDescription}]"); return null; } if ($parentJob) { // prefer the partner id from the parent job, although it should be the same $partnerId = $parentJob->getPartnerId(); } else { $partnerId = $originalFlavorAsset->getPartnerId(); } $flavorAssetId = null; $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entryId, $flavorParamsId); if ($flavorAsset) { $flavorAssetId = $flavorAsset->getId(); } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $flavor->_force = true; // force to convert the flavor, even if none complied $flavor->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE); // should not be taken in completion rules check $flavorAsset = kBatchManager::createFlavorAsset($flavor, $partnerId, $entryId, $flavorAssetId); if (!$flavorAsset) { KalturaLog::err(__METHOD__ . " - Failed to create flavor asset"); return null; } $flavorAssetId = $flavorAsset->getId(); $collectionTag = $flavor->getCollectionTag(); if ($collectionTag) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { throw new APIException(APIErrors::INVALID_ENTRY, $parentJob, $entryId); } $dbConvertCollectionJob = null; if ($parentJob) { $dbConvertCollectionJob = $parentJob->createChild(false); $dbConvertCollectionJob->setEntryId($entryId); $dbConvertCollectionJob->save(); } $flavorAssets = flavorAssetPeer::retrieveByEntryId($entryId); $flavorAssets = flavorAssetPeer::filterByTag($flavorAssets, $collectionTag); $flavors = array(); foreach ($flavorAssets as $tagedFlavorAsset) { if ($tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE || $tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { continue; } $flavorParamsOutput = flavorParamsOutputPeer::retrieveByFlavorAssetId($tagedFlavorAsset->getId()); if (is_null($flavorParamsOutput)) { KalturaLog::log("Creating flavor params output for asset [" . $tagedFlavorAsset->getId() . "]"); $flavorParams = flavorParamsPeer::retrieveByPK($tagedFlavorAsset->getId()); $flavorParamsOutput = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription); if (is_null($flavorParamsOutput)) { KalturaLog::log(__METHOD__ . " - Failed to validate media info [{$errDescription}]"); continue; } } if ($flavorParamsOutput) { KalturaLog::log("Adding Collection flavor [" . $flavorParamsOutput->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]"); $flavors[$tagedFlavorAsset->getId()] = flavorParamsOutputPeer::retrieveByFlavorAssetId($tagedFlavorAsset->getId()); } } if ($flavorAssetId) { KalturaLog::log("Updating Collection flavor [" . $flavor->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]"); $flavors[$flavorAssetId] = $flavor; } switch ($collectionTag) { case flavorParams::TAG_ISM: KalturaLog::log("Calling addConvertIsmCollectionJob with [" . count($flavors) . "] flavor params"); return kJobsManager::addConvertIsmCollectionJob($collectionTag, $srcSyncKey, $entry, $parentJob, $flavors, $dbConvertCollectionJob); default: KalturaLog::log("Error: Invalid collection tag [{$collectionTag}]"); return null; } } $dbConvertFlavorJob = null; if ($parentJob) { $dbConvertFlavorJob = $parentJob->createChild(false); $dbConvertFlavorJob->setEntryId($entryId); $dbConvertFlavorJob->save(); } return kJobsManager::addFlavorConvertJob($srcSyncKey, $flavor, $flavorAsset->getId(), $mediaInfoId, $parentJob, null, $dbConvertFlavorJob); }
public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false) { KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]"); $newEntry = $entry->copy(); $newEntry->setIntId(null); if ($toPartner instanceof Partner) { $newEntry->setPartnerId($toPartner->getId()); $newEntry->setSubpId($toPartner->getId() * 100); $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId()); $flavorParamsStr = $entry->getFlavorParamsIds(); $flavorParams = explode(',', $flavorParamsStr); $newFlavorParams = array(); foreach ($flavorParams as $flavorParamsId) { $newFlavorParamsId = kObjectCopyHandler::getMappedId('flavorParams', $flavorParamsId); if (is_null($newFlavorParamsId)) { $newFlavorParamsId = $flavorParamsId; } $newFlavorParams[] = $newFlavorParamsId; } $newEntry->setFlavorParamsIds(implode(',', $newFlavorParams)); } $newKuser = null; if (!$dontCopyUsers) { // copy the kuser (if the same puser id exists its kuser will be used) kuserPeer::setUseCriteriaFilter(false); $kuser = $entry->getKuser(); $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId()); $newEntry->setKuserId($newKuser->getId()); kuserPeer::setUseCriteriaFilter(true); } // copy the kshow kshowPeer::setUseCriteriaFilter(false); $kshow = $entry->getKshow(); if ($kshow) { $newKshow = $kshow->copy(); $newKshow->setIntId(null); $newKshow->setPartnerId($toPartner->getId()); $newKshow->setSubpId($toPartner->getId() * 100); if ($newKuser) { $newKshow->setProducerId($newKuser->getId()); } $newKshow->save(); $newEntry->setKshowId($newKshow->getId()); } kshowPeer::setUseCriteriaFilter(true); // reset the statistics myEntryUtils::resetEntryStatistics($newEntry); // set the new partner id into the default category criteria filter $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter(); $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID); $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID); $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId()); // save the entry $newEntry->save(); // restore the original partner id in the default category criteria filter $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID); $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId); KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created"); // for any type that does not require assets: $shouldCopyDataForNonClip = $entry->getType() != entryType::MEDIA_CLIP; $shouldCopyDataForClip = false; // only images get their data copied if ($entry->getType() == entryType::MEDIA_CLIP) { if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) { $shouldCopyDataForClip = true; } } if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) { // copy the data $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); if (kFileSyncUtils::fileSync_exists($ismFrom)) { $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]"); kFileSyncUtils::softCopy($ismFrom, $ismTo); } $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); if (kFileSyncUtils::fileSync_exists($ismcFrom)) { $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]"); kFileSyncUtils::softCopy($ismcFrom, $ismcTo); } $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath $considerCopyThumb = true; // if entry is image - data is thumbnail, and it was copied if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $considerCopyThumb = false; } // if entry is not clip, and there is no file in both DCs - nothing to copy if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) { $considerCopyThumb = false; } if ($considerCopyThumb) { $skipThumb = false; // don't attempt to copy a thumbnail for images - it's the same as the data which was just created if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) { // check if audio entry has real thumb, if not - don't copy thumb. $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false); if (!$originalFileSync) { $skipThumb = true; } } if (!$skipThumb) { $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } } // added by Tan-Tan 12/01/2010 to support falvors copy $sourceFlavorAssets = flavorAssetPeer::retrieveByEntryId($entry->getId()); foreach ($sourceFlavorAssets as $sourceFlavorAsset) { $sourceFlavorAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId()); } }
/** * @param BatchJob $dbBatchJob * @param kConvertCollectionJobData $data * @param int $engineType * @return boolean */ public static function handleConvertCollectionFailed(BatchJob $dbBatchJob, kConvertCollectionJobData $data, $engineType) { $collectionFlavors = array(); foreach ($data->getFlavors() as $flavor) { $collectionFlavors[$flavor->getFlavorAssetId()] = $flavor; } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); $hasIncomplete = false; $shouldFailProfile = false; $flavorAssets = flavorAssetPeer::retrieveByEntryId($dbBatchJob->getEntryId()); foreach ($flavorAssets as $flavorAsset) { if (isset($collectionFlavors[$flavorAsset->getId()])) { $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); if (!$rootBatchJob) { continue; } $flavorData = $collectionFlavors[$flavorAsset->getId()]; if ($flavorData->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { $shouldFailProfile = true; } continue; } if ($flavorAsset->getIsOriginal()) { continue; } if ($flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING) { $hasIncomplete = true; } } if (!$rootBatchJob) { return false; } if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } if ($shouldFailProfile || !$hasIncomplete) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); } return false; }
/** * Will investigate a single entry */ public function execute() { $this->forceSystemAuthentication(); myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2; entryPeer::setUseCriteriaFilter(false); $this->result = NULL; $fast = $this->getRequestParameter("fast", "") != ""; $this->fast = $fast; $kshow_id = $this->getRequestParameter("kshow_id"); $this->kshow_id = $kshow_id; $this->kshow = NULL; $entry_id = $this->getRequestParameter("entry_id"); $this->entry_id = $entry_id; $this->entry = NULL; $this->error = $this->getRequestParameter("error"); $this->bg_entry = NULL; if (!empty($kshow_id)) { $c = new Criteria(); $c->add(kshowPeer::ID, $kshow_id); $kshows = kshowPeer::doSelect($c); $kshow = new kshow(); if (!$kshows) { $this->result = "No kshow [{$kshow_id}] in DB"; return; } $kshow_original = $kshows[0]; $kshow_original->getShowEntry(); // pre fetch $kshow_original->getIntro(); // pre fetch $this->kshow_original = $kshows[0]; $this->kshow = new genericObjectWrapper($this->kshow_original, true); $alredy_exist_entries = array(); $alredy_exist_entries[] = $kshow_original->getShowEntryId(); if ($kshow_original->getIntroId()) { $alredy_exist_entries[] = $kshow_original->getIntroId(); } $skin_obj = $this->kshow_original->getSkinObj(); $bg_entry_id = $skin_obj->get("bg_entry_id"); if ($bg_entry_id) { $alredy_exist_entries[] = $bg_entry_id; $this->bg_entry = new genericObjectWrapper(entryPeer::retrieveByPK($bg_entry_id), true); } $c = new Criteria(); $c->add(entryPeer::ID, $alredy_exist_entries, Criteria::NOT_IN); $c->setLimit(100); $this->kshow_entries = $this->kshow_original->getEntrysJoinKuser($c); return; //return "KshowSuccess"; } if (empty($entry_id)) { return; } entryPeer::setUseCriteriaFilter(false); // from entry table $c = new Criteria(); $c->add(entryPeer::ID, $entry_id); //$entries = entryPeer::doSelectJoinAll ( $c ); $entries = entryPeer::doSelect($c); if (!$entries) { $this->result = "No entry [{$entry_id}] in DB"; return; } $this->entry = new genericObjectWrapper($entries[0], true); // from conversion table $c = new Criteria(); $c->add(conversionPeer::ENTRY_ID, $entry_id); $original_conversions = conversionPeer::doSelect($c); //$this->conversions = array() ; // $this->conversions = $original_conversions; //new genericObjectWrapper( $original_conversions ); // find all relevant batches in DB // from batch_job table $c = new Criteria(); //$c->add ( BatchJobPeer::DATA , "%\"entryId\";i:" . $entry_id . ";%" , Criteria::LIKE ); $c->add(BatchJobPeer::ENTRY_ID, $entry_id); $original_batch_jobs = BatchJobPeer::doSelect($c); $this->batch_jobs = $original_batch_jobs; // new genericObjectWrapper( $original_batch_jobs ); // use this as a refernece of all the directories // myBatchFileConverterServer::init( true ); $entry_patttern = "/" . $entry_id . "\\..*/"; $getFileData_method = array('kFile', 'getFileData'); $getFileDataWithContent_method = array('kFile', 'getFileDataWithContent'); // find all relevant files on disk $c = new Criteria(); $c->add(FileSyncPeer::OBJECT_TYPE, FileSyncObjectType::ENTRY); $c->add(FileSyncPeer::OBJECT_ID, $entry_id); // order by OBJECT SUB TYPE $c->addAscendingOrderByColumn(FileSyncPeer::OBJECT_SUB_TYPE); $this->file_syncs = FileSyncPeer::doSelect($c); $file_sync_links = array(); $flavors = flavorAssetPeer::retrieveByEntryId($entry_id); $flavor_ids = array(); $this->flavors = array(); foreach ($flavors as $f) { $flavor_ids[] = $f->getId(); $f->getflavorParamsOutputs(); $f->getflavorParams(); $f->getmediaInfos(); $this->flavors[] = $f; } // find all relevant files on disk $c = new Criteria(); $c->add(FileSyncPeer::OBJECT_TYPE, FileSyncObjectType::FLAVOR_ASSET); $c->add(FileSyncPeer::OBJECT_ID, $flavor_ids, Criteria::IN); // order by OBJECT SUB TYPE $c->addAscendingOrderByColumn(FileSyncPeer::OBJECT_SUB_TYPE); $flavors_file_syncs = FileSyncPeer::doSelect($c); $this->flavors_file_syncs = array(); foreach ($flavors as $flav) { foreach ($flavors_file_syncs as $f) { if ($f->getLinkedId()) { $file_sync_links[] = $f->getLinkedId(); } if ($f->getObjectId() == $flav->getId()) { $this->flavors_file_syncs[$flav->getId()][] = $f; } } } if ($this->file_syncs) { $this->file_syncs_by_sub_type = array(); foreach ($this->file_syncs as $fs) { if ($fs->getLinkedId()) { $file_sync_links[] = $fs->getLinkedId(); } $sub_type = $fs->getObjectSubType(); if (!isset($this->file_syncs_by_sub_type[$sub_type])) { // create the array $this->file_syncs_by_sub_type[$sub_type] = array(); } $this->file_syncs_by_sub_type[$sub_type][] = $fs; } } else { $this->file_syncs_by_sub_type = array(); } $file_sync_criteria = new Criteria(); $file_sync_criteria->add(FileSyncPeer::ID, $file_sync_links, Criteria::IN); $this->file_sync_links = FileSyncPeer::doSelect($file_sync_criteria); $track_entry_c = new Criteria(); $track_entry_c->add(TrackEntryPeer::ENTRY_ID, $entry_id); $track_entry_list = TrackEntryPeer::doSelect($track_entry_c); $more_interesting_track_entries = array(); foreach ($track_entry_list as $track_entry) { if ($track_entry->getTrackEventTypeId() == TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY) { $more_interesting_track_entries[] = $track_entry->getParam3Str(); } } $track_entry_list2 = array(); //very heavy query, skip this /* // add all the track_entry objects that are related (joined on PARAM_3_STR) $track_entry_c2 = new Criteria(); $track_entry_c2->add ( TrackEntryPeer::TRACK_EVENT_TYPE_ID , TrackEntry::TRACK_ENTRY_EVENT_TYPE_UPLOADED_FILE ); $track_entry_c2->add ( TrackEntryPeer::PARAM_3_STR , $more_interesting_track_entries , Criteria::IN ); $track_entry_list2 = TrackEntryPeer::doSelect ( $track_entry_c2 ); */ // first add the TRACK_ENTRY_EVENT_TYPE_UPLOADED_FILE - they most probably happend before the rest $this->track_entry_list = array_merge($track_entry_list2, $track_entry_list); }