public function convert(kConversionCommand $conv_cmd, kConversionResult $conv_result, $start_params_index = 0, $end_params_index = -1) { if (!file_exists($conv_cmd->source_file)) { TRACE("File [{$conv_cmd->source_file} does not exist"); return array(false, 0); } // make sure all the output directories exist - if not create kFile::fullMkdir($conv_cmd->target_file); kFile::fullMkdir($conv_cmd->log_file); self::fixConvParams($conv_cmd); $conv_params_list = $conv_cmd->conversion_params_list; if ($end_params_index == -1) { $end_params_index = count($conv_params_list); } $start_i = max($start_params_index, 0); $end_i = min($end_params_index, count($conv_params_list)); for ($i = $start_i; $i < $end_i; ++$i) { $conv_res_info = new kConvResInfo(); $conv_res_info->engine = $this->getName(); $conv_res_info->index = $i; $conv_params = @$conv_cmd->conversion_params_list[$i]; if ($conv_params) { $conv_res_info->conv_params_name = $conv_params->name; } $log_file = $conv_cmd->getLogFileWithSuffix($i); $conv_res_info->target = $conv_cmd->getTargetFileWithSuffix($i); list($execution_command_str, $conversion_str) = $this->getExecutionCommandAndConversionString($conv_cmd, $i); $conv_res_info->conv_str = $conversion_str; // assume there always will be this index self::logMediaInfo($conv_cmd->source_file); self::addToLogFile($log_file, $execution_command_str); self::addToLogFile($log_file, $conversion_str); $return_value = ""; $conv_result->appendResult($this->getName() . ": " . $execution_command_str); TRACE($execution_command_str); $start = microtime(true); exec($execution_command_str, $output, $return_value); $end = microtime(true); TRACE($this->getName() . ": [{$return_value}]"); // $return_value == 0 is success. if not - return the index of the failed conversion $conv_result->appendResult($this->getName() . ": [{$return_value}]"); $conv_res_info->duration = $end - $start; $conv_res_info->res = $return_value; $conv_result->appendResInfo($conv_res_info); if ($return_value != 0) { return array(false, $i); } self::logMediaInfo($conv_cmd->getTargetFileWithSuffix($i)); } return array(true, -1); // indicate all was converted properly }
private function pollConverted($write_to_log = true) { list($full_conv_res_path, $file_name, $in_proc) = $this->getFileFromConvertion($write_to_log); if (!$full_conv_res_path) { return; } $entry_id = self::getEntryIdFromFileName($file_name); KalturaLog::debug("Updating entry [" . $entry_id . "]"); entryPeer::setUseCriteriaFilter(false); // update the entry even if it's deleted // $c = new Criteria(); // $c->add(entryPeer::ID, $entry_id); // $entry = entryPeer::doSelectOne( $c ); $entry = entryPeer::retrieveByPK($entry_id); // fetch file from the conversion server and store it in the correct place - content/entry/data/... // using the ame logic as in contribute/insertEntryAction & myContentStorage... $this->removeInProc($in_proc); if ($entry == NULL) { // TODO - entry does not exist in DB - what to do ? // move file to some directory return; } // the target of the entry was already set at time of sentToCenversion $conv_res = kConversionResult::fromFile($full_conv_res_path); KalturaLog::debug(print_r($conv_res, true)); // sleep a while for synching data on the disk sleep(3); $this->markFileSyncAsReady($entry); $this->updateConvertedEntry($conv_res->status_ok, $entry, $conv_res); // flag a success to break the row of faliures (is any) self::succeeded(); }
protected function updateConversionInDb(entry $entry, kConversionResult $conv_res) { try { $c = new Criteria(); $entry_id = $entry->getId(); $c->add(conversionPeer::ENTRY_ID, $entry_id); // theoretically there can be more than one entry - fetch the last one which is in a non-complet status // assuming only one can be in such a status per entry $c->add(conversionPeer::STATUS, conversion::CONVERSION_STATUS_COMPLETED, Criteria::NOT_EQUAL); $c->addDescendingOrderByColumn(conversionPeer::ID); $conversion = conversionPeer::doSelectOne($c); if ($conversion) { $end = time(); //$tParsedTime = strtotime($sGMTMySqlString . " GMT"); $start = $conversion->getCreatedAt(null); //$start = (int)strtotime($raw_start . " GMT"); $conversion->setTotalProcessTime($end - $start); $info = $conv_res->getResultInfo(); if ($info) { $params = ""; $time = 0; foreach ($info as $info_for_conversion) { $params .= "[" . $info_for_conversion->engine . "] : " . $info_for_conversion->conv_params_name . " | " . $info_for_conversion->conv_str . " | "; if (is_numeric($info_for_conversion->duration)) { $time += $info_for_conversion->duration; } // increment the duration } list($name1, $size1) = $this->getNameAndSizeFromInfo($info, 0); @(list($name2, $size2) = $this->getNameAndSizeFromInfo($info, 1)); $conversion->setOutFileName($name1); $conversion->setOutFileSize($size1); $conversion->setOutFileName2($name2); $conversion->setOutFileSize2($size2); $conversion->setConversionParams($params); $conversion->setConversionTime($time); } if ($conv_res->status_ok == true) { $conversion->setStatus(conversion::CONVERSION_STATUS_COMPLETED); } else { $conversion->setStatus(conversion::CONVERSION_STATUS_ERROR); } $conversion->save(); } else { KalturaLog::debug("Cannot find conversion details for entry {$entry_id}"); } } catch (Exception $ex) { KalturaLog::debug("Error reporting conversion details to DB (part II) " . $ex->getTraceAsString()); } }