public static function handleBulkDownloadFinished(BatchJob $dbBatchJob, kBulkDownloadJobData $data, BatchJob $twinJob = null) { if ($dbBatchJob->getAbort()) { return $dbBatchJob; } $partner = PartnerPeer::retrieveByPK($dbBatchJob->getPartnerId()); if (!$partner) { KalturaLog::err("Partner id [" . $dbBatchJob->getPartnerId() . "] not found, not sending mail"); return $dbBatchJob; } $adminName = $partner->getAdminName(); $entryIds = explode(",", $data->getEntryIds()); $flavorParamsId = $data->getFlavorParamsId(); $links = array(); foreach ($entryIds as $entryId) { $entry = entryPeer::retrieveByPK($entryId); if (is_null($entry)) { continue; } $link = $entry->getDownloadAssetUrl($flavorParamsId); if (is_null($link)) { $link = "Failed to prepare"; } else { $link = '<a href="' . $link . '">Download</a>'; } $links[] = $entry->getName() . " - " . $link; } $linksHtml = implode("<br />", $links); // add mail job $jobData = new kMailJobData(); $jobData->setIsHtml(true); $jobData->setMailPriority(kMailJobData::MAIL_PRIORITY_NORMAL); $jobData->setStatus(kMailJobData::MAIL_STATUS_PENDING); if (count($links) <= 1) { $jobData->setMailType(62); } else { $jobData->setMailType(63); } $jobData->setBodyParamsArray(array($adminName, $linksHtml)); $jobData->setFromEmail(kConf::get("batch_download_video_sender_email")); $jobData->setFromName(kConf::get("batch_download_video_sender_name")); $kuser = kuserPeer::getKuserByPartnerAndUid($dbBatchJob->getPartnerId(), $data->getPuserId()); if ($kuser) { $recipientEmail = $kuser->getEmail(); } else { KalturaLog::err('Cannot find kuser with puserId [' . $dbBatchJob->getPartnerId() . '] and partnerId [' . $data->getPuserId() . ']. Sending mail to admin user instead.'); $recipientEmail = $partner->getAdminEmail(); } $jobData->setRecipientEmail($recipientEmail); $jobData->setSubjectParamsArray(array()); kJobsManager::addJob($dbBatchJob->createChild(), $jobData, BatchJobType::MAIL, $jobData->getMailType()); return $dbBatchJob; }
public static function handleBulkDownloadFinished(BatchJob $dbBatchJob, kBulkDownloadJobData $data) { if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) { return $dbBatchJob; } $partner = PartnerPeer::retrieveByPK($dbBatchJob->getPartnerId()); if (!$partner) { KalturaLog::err("Partner id [" . $dbBatchJob->getPartnerId() . "] not found, not sending mail"); return $dbBatchJob; } $entryIds = explode(",", $data->getEntryIds()); $flavorParamsId = $data->getFlavorParamsId(); $links = array(); foreach ($entryIds as $entryId) { $entry = entryPeer::retrieveByPK($entryId); if (is_null($entry)) { continue; } if ($entry->getType() != entryType::MEDIA_CLIP) { KalturaLog::info("This entry cannot be downloaded {$entryId}"); continue; } $link = $entry->getDownloadAssetUrl($flavorParamsId); if (is_null($link)) { $link = "Failed to prepare"; } else { $link = '<a href="' . $link . '">Download</a>'; } $links[] = $entry->getName() . " - " . $link; } $linksHtml = implode("<br />", $links); // add mail job $jobData = new kMailJobData(); $jobData->setIsHtml(true); $jobData->setMailPriority(kMailJobData::MAIL_PRIORITY_NORMAL); $jobData->setStatus(kMailJobData::MAIL_STATUS_PENDING); if (count($links) <= 1) { $jobData->setMailType(62); } else { $jobData->setMailType(63); } $jobData->setFromEmail(kConf::get("batch_download_video_sender_email")); $jobData->setFromName(kConf::get("batch_download_video_sender_name")); $adminName = $partner->getAdminName(); $recipientEmail = $partner->getAdminEmail(); $kuser = kuserPeer::getKuserByPartnerAndUid($dbBatchJob->getPartnerId(), $data->getPuserId()); if ($kuser) { $recipientEmail = $kuser->getEmail(); $adminName = $kuser->getFullName(); } if (!$adminName) { $adminName = $recipientEmail; } $jobData->setSeparator(self::BULK_DOWNLOAD_EMAIL_PARAMS_SEPARATOR); $jobData->setBodyParamsArray(array($adminName, $linksHtml)); $jobData->setRecipientEmail($recipientEmail); $jobData->setSubjectParamsArray(array()); kJobsManager::addJob($dbBatchJob->createChild(BatchJobType::MAIL, $jobData->getMailType()), $jobData, BatchJobType::MAIL, $jobData->getMailType()); return $dbBatchJob; }
public static function addBulkDownloadJob($partnerId, $puserId, $entryIds, $flavorParamsId) { $entryIds = explode(",", $entryIds); if (count($entryIds) > self::BULK_DOWNLOAD_TOTAL_ENTRIES_AMOUNT_RESTRICTION) { throw new APIException(APIErrors::ENTRIES_AMOUNT_EXCEEDED); } foreach ($entryIds as $entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new APIException(APIErrors::INVALID_ENTRY_ID, $entryId); } } $chunksOfEntries = array_chunk($entryIds, self::BULK_DOWLOAD_SINGLE_JOB_ENTRIES_AMOUNT); KalturaLog::debug("about to create " . count($chunksOfEntries) . " jobs"); $jobs = array(); foreach ($chunksOfEntries as $chunk) { $jobDb = new BatchJob(); $jobDb->setPartnerId($partnerId); $data = new kBulkDownloadJobData(); $data->setEntryIds(implode(",", $chunk)); $data->setFlavorParamsId($flavorParamsId); $data->setPuserId($puserId); $jobs[] = self::addJob($jobDb, $data, BatchJobType::BULKDOWNLOAD); } return $jobs; }
public static function addBulkDownloadJob($partnerId, $puserId, $entryIds, $flavorParamsId) { $entryIds = explode(",", $entryIds); foreach ($entryIds as $entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new APIException(APIErrors::INVALID_ENTRY_ID, $entryId); } } $jobDb = new BatchJob(); $jobDb->setPartnerId($partnerId); $data = new kBulkDownloadJobData(); $data->setEntryIds(implode(",", $entryIds)); $data->setFlavorParamsId($flavorParamsId); $data->setPuserId($puserId); return self::addJob($jobDb, $data, BatchJobType::BULKDOWNLOAD); }