/package/app/app/alpha/lib/model/entry.php
PHP | 2584 lines | 1855 code | 412 blank | 317 comment | 353 complexity | ae7c4ee32669c4d8ae9f60b4d74a3fa6 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-3.0, JSON, MPL-2.0-no-copyleft-exception, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Subclass for representing a row from the 'entry' table.
- *
- *
- *
- * @package Core
- * @subpackage model
- */
- class entry extends Baseentry implements ISyncableFile, IIndexable
- {
- private $previous_status ;
- protected $old_categories;
- protected $is_categories_modified = false;
-
- const MINIMUM_ID_TO_DISPLAY = 8999;
-
- const ROOTS_FIELD_PREFIX = 'K_Pref';
- const ROOTS_FIELD_ENTRY_PREFIX = 'KP_Entry';
- const ROOTS_FIELD_BULK_UPLOAD_PREFIX = 'KP_Bulk';
-
- // NOTE - CHANGES MUST BE MADE TO LAYOUT.PHP JS PART AS WELL
- // different sort orders for browsing entries
- const ENTRY_SORT_MOST_VIEWED = 0;
- const ENTRY_SORT_MOST_RECENT = 1;
- const ENTRY_SORT_MOST_COMMENTS = 2;
- const ENTRY_SORT_MOST_FAVORITES = 3;
- const ENTRY_SORT_RANK = 4;
- const ENTRY_SORT_MEDIA_TYPE = 5;
- const ENTRY_SORT_NAME = 6;
- const ENTRY_SORT_KUSER_SCREEN_NAME = 7;
-
- // NOTE - CHANGES MUST BE MADE TO LAYOUT.PHP JS PART AS WELL
- const ENTRY_MEDIA_TYPE_AUTOMATIC = -1;
- const ENTRY_MEDIA_TYPE_ANY = 0;
- const ENTRY_MEDIA_TYPE_VIDEO = 1;
- const ENTRY_MEDIA_TYPE_IMAGE = 2;
- const ENTRY_MEDIA_TYPE_TEXT = 3;
- const ENTRY_MEDIA_TYPE_HTML = 4;
- const ENTRY_MEDIA_TYPE_AUDIO = 5;
- const ENTRY_MEDIA_TYPE_SHOW = 6;
- const ENTRY_MEDIA_TYPE_SHOW_XML = 7; // for the kplayer: the data contains the xml itself and not a url
- const ENTRY_MEDIA_TYPE_BUBBLES = 9;
- const ENTRY_MEDIA_TYPE_XML = 10;
- const ENTRY_MEDIA_TYPE_DOCUMENT = 11;
- const ENTRY_MEDIA_TYPE_SWF = 12;
- const ENTRY_MEDIA_TYPE_PDF = 13;
-
- const ENTRY_MEDIA_TYPE_GENERIC_1= 101; // these types can be used for derived classes - assume this is some kind of TXT file
- const ENTRY_MEDIA_TYPE_GENERIC_2= 102; // these types can be used for derived classes
- const ENTRY_MEDIA_TYPE_GENERIC_3= 103; // these types can be used for derived classes
- const ENTRY_MEDIA_TYPE_GENERIC_4= 104; // these types can be used for derived classes
-
- const ENTRY_MEDIA_TYPE_LIVE_STREAM_FLASH = 201;
- const ENTRY_MEDIA_TYPE_LIVE_STREAM_WINDOWS_MEDIA = 202;
- const ENTRY_MEDIA_TYPE_LIVE_STREAM_REAL_MEDIA = 203;
- const ENTRY_MEDIA_TYPE_LIVE_STREAM_QUICKTIME = 204;
-
- // NOTE - CHANGES MUST BE MADE TO LAYOUT.PHP JS PART AS WELL
- const ENTRY_MEDIA_SOURCE_FILE = 1;
- const ENTRY_MEDIA_SOURCE_WEBCAM = 2;
- const ENTRY_MEDIA_SOURCE_FLICKR = 3;
- const ENTRY_MEDIA_SOURCE_YOUTUBE = 4;
- const ENTRY_MEDIA_SOURCE_URL = 5;
- const ENTRY_MEDIA_SOURCE_TEXT = 6;
- const ENTRY_MEDIA_SOURCE_MYSPACE = 7;
- const ENTRY_MEDIA_SOURCE_PHOTOBUCKET = 8;
- const ENTRY_MEDIA_SOURCE_JAMENDO = 9;
- const ENTRY_MEDIA_SOURCE_CCMIXTER = 10;
- const ENTRY_MEDIA_SOURCE_NYPL = 11;
- const ENTRY_MEDIA_SOURCE_CURRENT = 12;
- const ENTRY_MEDIA_SOURCE_MEDIA_COMMONS = 13;
- const ENTRY_MEDIA_SOURCE_KALTURA = 20;
- const ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS = 21;
- const ENTRY_MEDIA_SOURCE_ARCHIVE_ORG = 22;
- const ENTRY_MEDIA_SOURCE_KALTURA_PARTNER = 23;
- const ENTRY_MEDIA_SOURCE_METACAFE = 24;
- const ENTRY_MEDIA_SOURCE_KALTURA_QA = 25;
- const ENTRY_MEDIA_SOURCE_KALTURA_KSHOW = 26;
- const ENTRY_MEDIA_SOURCE_KALTURA_PARTNER_KSHOW = 27;
- const ENTRY_MEDIA_SOURCE_SEARCH_PROXY = 28;
- const ENTRY_MEDIA_SOURCE_AKAMAI_LIVE = 29;
- const ENTRY_MEDIA_SOURCE_PARTNER_SPECIFIC = 100;
-
- const ENTRY_MODERATION_STATUS_PENDING_MODERATION = 1;
- const ENTRY_MODERATION_STATUS_APPROVED = 2;
- const ENTRY_MODERATION_STATUS_REJECTED = 3;
- const ENTRY_MODERATION_STATUS_FLAGGED_FOR_REVIEW = 5;
- const ENTRY_MODERATION_STATUS_AUTO_APPROVED = 6;
-
- const MAX_NORMALIZED_RANK = 5;
-
- const MAX_CATEGORIES_PER_ENTRY = 32;
-
- const FILE_SYNC_ENTRY_SUB_TYPE_DATA = 1;
- const FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT = 2;
- const FILE_SYNC_ENTRY_SUB_TYPE_THUMB = 3;
- const FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE = 4;
- const FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD = 5;
- const FILE_SYNC_ENTRY_SUB_TYPE_OFFLINE_THUMB = 6;
- const FILE_SYNC_ENTRY_SUB_TYPE_ISM = 7;
- const FILE_SYNC_ENTRY_SUB_TYPE_ISMC = 8;
- const FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG = 9;
-
- const MIX_EDITOR_TYPE_SIMPLE = 1;
- const MIX_EDITOR_TYPE_ADVANCED = 2;
-
- const ENTRY_DURATION_TYPE_NOTAVAILABLE = "notavailable";
- const ENTRY_DURATION_TYPE_SHORT = "short";
- const ENTRY_DURATION_TYPE_MEDIUM = "medium";
- const ENTRY_DURATION_TYPE_LONG = "long";
-
- const ENTRY_CATEGORY_ESCAPE = "_";
- const ENTRY_CATEGORY_SEPARATOR = ",";
-
- private $appears_in = null;
-
- private $m_added_moderation = false;
- private $should_call_set_data_content = false;
- private $data_content = null;
-
- private $desired_version = null;
-
- private $archive_extension = null;
-
- private static $mediaTypeNames = array(
- self::ENTRY_MEDIA_TYPE_AUTOMATIC => 'AUTOMATIC',
- self::ENTRY_MEDIA_TYPE_ANY => 'ANY',
- self::ENTRY_MEDIA_TYPE_VIDEO => 'VIDEO',
- self::ENTRY_MEDIA_TYPE_IMAGE => 'IMAGE',
- self::ENTRY_MEDIA_TYPE_TEXT => 'TEXT',
- self::ENTRY_MEDIA_TYPE_HTML => 'HTML',
- self::ENTRY_MEDIA_TYPE_AUDIO => 'AUDIO',
- self::ENTRY_MEDIA_TYPE_SHOW => 'SHOW',
- self::ENTRY_MEDIA_TYPE_SHOW_XML => 'SHOW_XML',
- self::ENTRY_MEDIA_TYPE_BUBBLES => 'BUBBLES',
- self::ENTRY_MEDIA_TYPE_XML => 'XML',
- self::ENTRY_MEDIA_TYPE_DOCUMENT => 'DOCUMENT',
- self::ENTRY_MEDIA_TYPE_SWF => 'SWF',
- self::ENTRY_MEDIA_TYPE_PDF => 'PDF',
-
- self::ENTRY_MEDIA_TYPE_GENERIC_1 => 'GENERIC_1',
- self::ENTRY_MEDIA_TYPE_GENERIC_2 => 'GENERIC_2',
- self::ENTRY_MEDIA_TYPE_GENERIC_3 => 'GENERIC_3',
- self::ENTRY_MEDIA_TYPE_GENERIC_4 => 'GENERIC_4',
-
- self::ENTRY_MEDIA_TYPE_LIVE_STREAM_FLASH => 'LIVE_STREAM_FLASH',
- self::ENTRY_MEDIA_TYPE_LIVE_STREAM_WINDOWS_MEDIA => 'LIVE_STREAM_WINDOWS_MEDIA',
- self::ENTRY_MEDIA_TYPE_LIVE_STREAM_REAL_MEDIA => 'LIVE_STREAM_REAL_MEDIA',
- self::ENTRY_MEDIA_TYPE_LIVE_STREAM_QUICKTIME => 'LIVE_STREAM_QUICKTIME',
- );
-
-
- /**
- * Applies default values to this object.
- * This method should be called from the object's constructor (or
- * equivalent initialization method).
- * @see __construct()
- */
- public function applyDefaultValues()
- {
- parent::applyDefaultValues();
- $this->setStatus(entryStatus::PENDING);
- $this->setModerationStatus(self::ENTRY_MODERATION_STATUS_AUTO_APPROVED);
- }
-
- // the columns names is a list of all fields that will participate in the search_text
- // TODO - add the admin_tags to the column names
- public static function getColumnNames() { return array ( "name" , "tags" ,"description" , "admin_tags" ); }
- public static function getSearchableColumnName () { return "search_text" ; }
-
- // don't stop until a unique hash is created for this object
- private static function calculateId ( )
- {
- $dc = kDataCenterMgr::getCurrentDc();
- for ( $i = 0 ; $i < 10 ; ++$i)
- {
- $id = $dc["id"].'_'.kString::generateStringId();
- $existing_object = entryPeer::retrieveByPk( $id );
-
- if ( ! $existing_object ) return $id;
- }
-
- die();
- }
-
- public function justSave($con = null)
- {
- return parent::save( $con );
- }
-
- public function save(PropelPDO $con = null)
- {
- $is_new = false;
- if ( $this->isNew() )
- {
- $this->setId(self::calculateId());
-
- // start by setting the modified_at to the current time
- $this->setModifiedAt( time() ) ;
- $this->setModerationCount(0);
-
- if (is_null($this->getAccessControlId()))
- {
- $partner = $this->getPartner();
- if($partner)
- $this->setAccessControlId($partner->getDefaultAccessControlId());
- }
- // only media clips should increments - not roughcuts or backgrounds
- if ( $this->type == entryType::MEDIA_CLIP )
- myStatisticsMgr::addEntry( $this );
-
- $is_new = true;
- }
-
- if ( $this->isColumnModified ( entryPeer::STATUS ) && ( $this->previous_status != $this->getStatus() ) )
- {
- // add a track for when the status changed
- $track_entry = new TrackEntry();
- $track_entry->setEntryId( $this->getId() );
- $track_entry->setTrackEventTypeId( TrackEntry::TRACK_ENTRY_EVENT_TYPE_UPDATE_ENTRY );
- $track_entry->setChangedProperties( "status [{$this->previous_status}]->[{$this->getStatus()}]" );
-
- if ( $this->previous_status != entryStatus::DELETED &&
- $this->getStatus() == entryStatus::DELETED )
- {
- myStatisticsMgr::deleteEntry( $this );
- $track_entry->setTrackEventTypeId( TrackEntry::TRACK_ENTRY_EVENT_TYPE_DELETED_ENTRY );
- }
-
- TrackEntry::addTrackEntry( $track_entry );
- }
-
- if ( $this->type == entryType::MIX )
- {
- // some of the properties should be copied to the kshow
- $kshow = $this->getkshow();
- if ( $kshow )
- {
- $modified = false;
- if ( $kshow->getRank() != $this->getRank() )
- {
- $kshow->setRank( $this->getRank() );
- $modified = true;
- }
- if ( $kshow->getLengthInMsecs() != $this->getLengthInMsecs() )
- {
- $kshow->setLengthInMsecs ( $this->getLengthInMsecs() );
- $modified = true;
- }
-
- if ( $modified ) $kshow->save();
- }
- else
- {
- $this->log( "entry [" . $this->getId() . "] does not have a real kshow with id [" . $this->getKshowId() . "]", Propel::LOG_WARNING );
- }
- }
-
- myPartnerUtils::setPartnerIdForObj( $this );
-
- if ( $this->getType() != entryType::PLAYLIST )
- mySearchUtils::setDisplayInSearch( $this );
-
- mySearchUtils::setSearchTextDiscreteForEntry($this);
-
- // update the admin_tags per partner
- ktagword::updateAdminTags( $this );
-
- // same for puserId ...
- $this->getPuserId( true );
-
- // make sure this entry is saved before calling updateAllMetadataVersionsRelevantForEntry, since fixMetadata retrieves the entry from the DB
- // and checks its data path which was modified above.
- $res = parent::save( $con );
- if ($is_new)
- {
- // when retrieving the entry - ignore thr filter - when in partner has moderate_content =1 - the entry will have status=3 and will fail the retrieveByPk
- entryPeer::setUseCriteriaFilter(false);
- $obj = entryPeer::retrieveByPk($this->getId());
- $this->setIntId($obj->getIntId());
- entryPeer::setUseCriteriaFilter(true);
- }
-
- if ( $this->should_call_set_data_content )
- {
- // calling the funciton with null will cause it to use the $this->data_content
- $this->setDataContent( null );
- $res = parent::save( $con );
- }
-
- // the fix should be done whether the status is READY or ERROR_CONVERTING
- if ( $this->getStatus() == entryStatus::READY || $this->getStatus() == entryStatus::ERROR_CONVERTING )
- {
- // fire some stuff due to the new status
- $version_to_update = $this->getUpdateWhenReady();
-
- if ( $version_to_update )
- {
- try{
- myMetadataUtils::updateAllMetadataVersionsRelevantForEntry ( $this);
- $this->resetUpdateWhenReady();
- $res = parent::save( $con );
- }
- catch(Exception $e)
- {
- KalturaLog::err($e->getMessage());
- }
- }
- }
-
- $this->syncCategories();
-
- return $res;
- }
-
-
- // TODO - PERFORMANCE DB - move to use cache !!
- // will increment the views by 1
- public function incViews ( $should_save = true )
- {
- myStatisticsMgr::incEntryViews( $this );
- }
-
-
-
- private function statusChangedTo ( $new_status )
- {
- return ( $this->previous_status != $new_status &&
- $this->getStatus() == $new_status );
- }
-
-
- public function setStatus ( $v)
- {
- // if we haven't yet set the previous status - remember it now
- if ( is_null ( $this->previous_status ) )
- $this->previous_status = $this->getStatus();
- parent::setStatus( $v );
- }
-
- /**
- * will handle the flow in case of need to moderate.
- */
- public function setStatusReady ( $force = false )
- {
- $this->setStatus( entryStatus::READY );
- $this->setDefaultModerationStatus();
-
- return $this->getStatus();
- }
-
- public function setDefaultModerationStatus()
- {
- $should_moderate = false;
- // in this case no configuration really matters
- if ( $this->getModerate() )
- {
- $should_moderate = true;
- }
- else
- {
- $should_moderate = myPartnerUtils::shouldModerate( $this->getPartnerId(), $this);
- }
-
- if( $should_moderate )
- {
- if ( ! $this->getId() )
- $this->save(); // save to DB so we'll have the id for the moderation list
-
- $this->setModerationStatus( self::ENTRY_MODERATION_STATUS_PENDING_MODERATION );
- if ( !$this->m_added_moderation )
- {
- myModerationMgr::addToModerationList( $this );
- $this->m_added_moderation = true;
- }
- }
- else
- {
- $this->setModerationStatus( self::ENTRY_MODERATION_STATUS_AUTO_APPROVED );
- }
- }
-
- public function isReady()
- {
- return ( $this->getStatus() == entryStatus::READY ) ;
- }
-
- public function getNormalizedRank ()
- {
- $res = round($this->rank / 1000);
-
- if ( $res > self::MAX_NORMALIZED_RANK ) return self::MAX_NORMALIZED_RANK;
-
- return $res;
- }
-
- /*
- * return an array of tuples of the file's version: [name, size, time, version]
- */
- public function getAllVersions ()
- {
- $current_version = $this->getData();
- $c = strstr($current_version, '^') ? '^' : '&';
- $parts = explode($c, $current_version);
-
- if (count($parts) == 2 && strlen($parts[1]))
- {
- return null;
- }
-
- // create an array to hold versions list
- $results = array();
- for ($version = 100000; $version <= $current_version; $version++ )
- {
- $version_sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version);
- $local_file_sync = kFileSyncUtils::getLocalFileSyncForKey($version_sync_key, false);
- if ($local_file_sync)
- {
- $result = array();
- // first - file name (with the full path)
- $result[] = $local_file_sync->getFilePath();
- // second - size
- $result[] = $local_file_sync->getFileSize();
- // third - time
- $result[] = filemtime ( $local_file_sync->getFullPath());
- // forth - version
- $result[] = substr( kFile::getFileNameNoExtension ( $local_file_sync->getFilePath() ) , strlen ($this->getId().'_') );
- $results[] = $result;
- }
- }
-
- return $results;
- }
-
-
- public function getAllVersionsFormatted()
- {
- $res = $this->getAllVersions();
- $formatted = array ();
-
- if ( ! is_array ( $res ) ) return null;
-
- foreach ( $res as $version_info )
- {
- $formatted []= array (
- "version" => $version_info[3] ,
- "rawData" => $version_info[2] ,
- "date" => strftime( "%d/%m/%y %H:%M:%S" , $version_info[2] ) );
- }
- return $formatted;
- }
-
- public function getLastVersion()
- {
- $version = kFile::getFileNameNoExtension ( $this->getData() );
- return $version;
- }
-
- public function getFormattedLengthInMsecs ()
- {
- return dateUtils::formatDuration ( $this->getLengthInMsecs() );
- }
-
-
-
- /**
- * (non-PHPdoc)
- * @see lib/model/ISyncableFile#getSyncKey()
- */
- public function getSyncKey ( $sub_type , $version = null )
- {
- self::validateFileSyncSubType ( $sub_type );
- $key = new FileSyncKey();
- $key->object_type = FileSyncObjectType::ENTRY;
-
- // // remarked by Tan-Tan 13/01/2010
- // if($sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB && $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE)
- // {
- // $key->object_sub_type = self::FILE_SYNC_ENTRY_SUB_TYPE_DATA;
- // }
- // else
- // {
- $key->object_sub_type = $sub_type;
- // }
-
- $key->object_id = $this->getId();
-
- $key->version = $this->getVersionForSubType ( $sub_type, $version );
- $key->partner_id = $this->getPartnerId();
-
- return $key;
- }
-
-
- /**
- * @return string
- */
- public function generateBaseFileName( $sub_type, $version = null)
- {
- if(is_null($version))
- $version = $this->getVersion();
-
- // TODO - remove after Akamai bug fixed and create the file names with sub type
- if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM)
- return "_{$version}";
-
- if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC)
- return "_{$version}";
- // remove till here
-
- return "{$sub_type}_{$version}";
- }
-
- /* (non-PHPdoc)
- * @see lib/model/ISyncableFile#generateFileName()
- */
- public function generateFileName( $sub_type, $version = null)
- {
- if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM)
- return $this->getId() . '_' . $this->generateBaseFileName(0, $version) . '.ism';
-
- if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC)
- return $this->getId() . '_' . $this->generateBaseFileName(0, $version) . '.ismc';
-
- return $this->getId() . '_' . $this->generateBaseFileName($sub_type, $version);
- }
-
-
- /**
- * (non-PHPdoc)
- * @see lib/model/ISyncableFile#generateFilePathArr()
- */
- public function generateFilePathArr( $sub_type, $version = null)
- {
- self::validateFileSyncSubType ( $sub_type );
- if ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA )
- {
- $data = $this->getData();
- if($this->getType() == entryType::MIX && (!$this->getData() || !strpos($this->getData(), 'xml')))
- {
- $data .= ".xml";
- }
- $res = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $data, $version);
- // $res = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData(), $version);
- }
- elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT )
- {
- $res = myContentStorage::getFileNameEdit( myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData(), $version) );
- }
- elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB )
- {
- $res = myContentStorage::getGeneralEntityPath("entry/bigthumbnail", $this->getIntId(), $this->getId(), $this->getThumbnail() , $version);
- }
- elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE )
- {
- $res = null;
- $data_path = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData(), $version);
- // assume the suffix is not the same as the one on the data
- $archive_path = dirname ( str_replace ( "content/entry/" , "archive/" , $data_path ) ) . "/" . $this->getId();
- if ($this->getArchiveExtension())
- {
- $res = $archive_path . "." . $this->getArchiveExtension();
- }
- else
- {
- $archive_pattern = $archive_path . ".*" ;
- $arc_files = glob ( myContentStorage::getFSContentRootPath( ) . $archive_pattern );
- foreach ( $arc_files as $full_path_name )
- {
- // return the first file found
- $res = $full_path_name;
- break;
- }
-
- if ( ! $res )
- $res = $archive_pattern;
- }
- }
- elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD )
- {
- // in this case the $version is used as the format
- $basename = kFile::getFileNameNoExtension ( $this->getData() );
- $path = myContentStorage::getGeneralEntityPath("entry/download", $this->getIntId(), $this->getId(), $basename);
- $download_path = $path.".$version";
- $res = $download_path;
- }
- else
- {
- $path = "entry/data";
- switch($sub_type)
- {
- case self::FILE_SYNC_ENTRY_SUB_TYPE_ISM:
- $basename = $this->generateBaseFileName(0, $this->getIsmVersion());
- $basename .= '.ism';
- break;
-
- case self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC:
- $basename = $this->generateBaseFileName(0, $this->getIsmVersion());
- $basename .= '.ismc';
- break;
-
- case self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG:
- $basename = $this->generateBaseFileName(0, $this->getIsmVersion());
- $basename .= '.log';
- break;
- }
- $res = myContentStorage::getGeneralEntityPath($path, $this->getIntId(), $this->getId(), $basename);
- }
-
- return array ( myContentStorage::getFSContentRootPath( ) , $res );
- }
-
- private function getVersionForSubType ( $sub_type, $version = null )
- {
- if (
- $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ISM
- ||
- $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC
- ||
- $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG
- )
- {
- if(!is_null($version))
- return $version;
-
- return $this->getIsmVersion();
- }
-
- $new_version = "";
- if ( $version )
- {
- if ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD )
- {
- // MUST have A VERSION !
- $new_version = $this->getVersion() . "." . $version;
- }
- else
- {
- $new_version = $version;
- }
- }
- else
- {
- if ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA || $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT )
- $new_version = $this->getVersion();
- elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB )
- $new_version = $this->getThumbnailVersion();
- elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE )
- $new_version = "";
- elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD )
- {
- // MUST have A VERSION !
- $new_version = $this->getVersion();
- }
- }
-
- return $new_version;
- }
-
- /**
- * Enter description here...
- *
- * @var FileSync
- */
- private $m_file_sync;
-
- /**
- * @return FileSync
- */
- public function getFileSync ( )
- {
- return $this->m_file_sync;
- }
-
- public function setFileSync ( FileSync $file_sync )
- {
- $this->m_file_sync = $file_sync;
- }
-
-
- private static function validateFileSyncSubType ( $sub_type )
- {
- if ( $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_DATA &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_ISM &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG &&
- $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_OFFLINE_THUMB
- )
- throw new FileSyncException ( FileSyncObjectType::ENTRY ,
- $sub_type , array (
- self::FILE_SYNC_ENTRY_SUB_TYPE_DATA ,
- self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT,
- self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB ,
- self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE ,
- self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD ,
- self::FILE_SYNC_ENTRY_SUB_TYPE_ISM ,
- self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC ,
- self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG ,
- self::FILE_SYNC_ENTRY_SUB_TYPE_OFFLINE_THUMB ,
- ) );
- }
-
-
- // return the full path on the disk
- public function getFullDataPath( $version = NULL )
- {
- $path = myContentStorage::getFSContentRootPath() . $this->getDataPath();
- if ( file_exists( $path )) return $path;
- return $path;
- }
-
- /**
- * This function returns the file system path for a requested content entity.
- * @return string the content path
- */
- public function getDataPath( $version = NULL )
- {
- if ( $version == NULL || $version == -1 )
- {
- return myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData());
- }
- else
- {
- $ext = pathinfo ($this->getData(), PATHINFO_EXTENSION);
- $file_version = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $version);
- return $file_version . "." . $ext;
- }
- }
-
- public function getDataUrl( $version = NULL )
- {
- if( $this->getType() == entryType::PLAYLIST )
- {
- return myPlaylistUtils::getExecutionUrl( $this );
- }
- //$path = $this->getThumbnailPath ( $version );
- $path = myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . "/flvclipper/entry_id/" . $this->getId() ;
- $current_version = $this->getVersion();
- if ( $version )
- $path .= "/version/$version";
- else
- $path .= "/version/$current_version";
- $url = myPartnerUtils::getCdnHost($this->getPartnerId()) . $path ;
- return $url;
- }
-
- /**
- * This function sets and returns a new path for a requested content entity.
- * @param string $filename = the original fileName from which the extension is cut.
- * @return string the content file name
- */
- public function setData($filename , $force = false )
- {
- if ( $force )
- $data = $filename;
- else
- $data = myContentStorage::generateRandomFileName($filename, $this->getData());
-
- Baseentry::setData( $data );
- return $this->getData();
- }
-
- /**
- *
- * @param $version
- * @param $format
- * @return FileSync
- */
- public function getDownloadFileSyncAndLocal ( $version = NULL , $format = null , $sub_type = null )
- {
- $sync_key = null;
-
- if ( $this->getType() == entryType::MEDIA_CLIP)
- {
- if ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_VIDEO || $this->getMediaType() == self::ENTRY_MEDIA_TYPE_AUDIO)
- {
- $flavor_assets = assetPeer::retrieveBestPlayByEntryId($this->getId()); // uset the format as the extension
- if($flavor_assets)
- $sync_key = $flavor_assets->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
- }
- elseif ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE )
- {
- $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
- }
- }
- elseif ( $this->getType() == entryType::MIX )
- {
- // if roughcut - the version should be used
- $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD , $version );
- }
- else
- {
- // if not roughcut - the format should be used
- $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD , $format );
- }
-
- if(!$sync_key)
- return null;
-
- return kFileSyncUtils::getReadyFileSyncForKey ( $sync_key , true , false );
- }
-
- // return the file
- public function getDownloadPath( $version = NULL , $format = null , $sub_type = null )
- {
-
- // fetch the path (from remote if no local)
- list ( $file_sync , $local ) = $this->getDownloadFileSyncAndLocal( $version , $format , $sub_type );
-
- if ( ! $file_sync )
- return null;
-
- return $file_sync->getFullPath();
- }
-
- public function getDownloadSize( $version = NULL )
- {
- // fetch the path (from remote if no local)
- list ( $file_sync , $local ) = $this->getDownloadFileSyncAndLocal( $version , null );
-
- if ( ! $file_sync )
- return 0;
-
- return $file_sync->getFileSize();
- }
-
- public function getDownloadUrl( $version = NULL )
- {
- // always return the URL for the download - there is enough logic there to fix problems return the correct version/flavor
- return myPartnerUtils::getCdnHost($this->getPartnerId()). myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . "/raw/entry_id/" . $this->getId() . "/version/" . $this->getVersion();
- }
-
-
- public function getDownloadPathForFormat ( $version = NULL , $format )
- {
- // used by ppt-convert flow (downloadPath in addDownload response)
- // and perhaps by other clients as name
- $download_path = $this->getDownloadPath( $version , $format , self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD );
- if($download_path)
- return $download_path;
-
- // if did not return anything, probably due to missing fileSync
- // missing fileSync - if conversion was not done yet
- $key = $this->getSyncKey(self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD, $format);
- return kFileSyncUtils::getLocalFilePathForKey($key);
- }
-
- /*
- * deprecated - was called from myBatchDownloadVideoServer which is no longer used
- // given the path of the converted file (not an FLV file) - create its URL
- public function getConvertedDownoadUrl ( $file_real_path )
- {
- $path = str_replace ( myContentStorage::getFSContentRootPath() , "" , $file_real_path );
- $path = str_replace ( "\\" , "" , $path );
- return myPartnerUtils::getCdnHost($this->getPartnerId()). myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . $path;
- }
- */
-
- public function setDesiredVersion ( $v )
- {
- $this->desired_version = $v;
- }
-
- public function getDesiredVersion ( )
- {
- return $this->desired_version ;
- }
-
- public function setArchiveExtension($v)
- {
- $this->archive_extension = $v;
- }
-
- public function getArchiveExtension()
- {
- return $this->archive_extension;
- }
-
- // will work only for types that the data can be served as an a response to the service
- public function getDataContent ( $from_cache = false )
- {
- if ( $this->getType() == entryType::MIX ||
- $this->getType() == entryType::DATA ||
- $this->getType() == entryType::PLAYLIST ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_XML ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_TEXT ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_GENERIC_1 )
- {
- if ( $from_cache ) return $this->data_content;
- $content_path = myContentStorage::getFSContentRootPath();
- $version = $this->desired_version;
- if ( ! $version || $version == -1 ) $version = null;
-
- $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
- $content = kFileSyncUtils::file_get_contents( $sync_key , true , false ); // don't be strict when fetching this content
-
- if ( $content )
- {
- // patch for fixing old AE roughcuts without cross="0"
- if ($this->getType() == entryType::MIX)
- {
- $data2 = str_replace('<EndTransition type', '<EndTransition cross="0" type', $content);
- return $data2;
- }
-
- return $content;
- }
- }
- return null;
- }
-
- // will work only for types that the data can be served as an a response to the service
- public function setDataContent ( $v , $increment_version = true , $allow_type_roughcut = false )
- {
- // if ( $v === null ) return ;
- // DON'T do this for ENTRY_TYPE_SHOW unless $allow_type_roughcut is true
- // - the metadata is handling is complex and is done in other places in the code
- if ( ($allow_type_roughcut && $this->getType() == entryType::MIX) ||
- $this->getType() == entryType::DATA ||
- $this->getType() == entryType::PLAYLIST ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_XML ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_SHOW ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_TEXT ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_GENERIC_1 )
- {
- if ( $this->getId() == null )
- {
- // come back when there is an ID
- $this->data_content = $v;
- $this->should_call_set_data_content = true;
- return ;
- }
-
- // if increment_version is false - don't be strict
- $strict = false;
- if ( ! $increment_version || $v == $this->data_content )
- {
- // attempting to update the same value
- $strict = false ;
- }
-
- if ( $v == null ) $v = $this->data_content;
- else $this->data_content = $v; // store it so it can be used with getDataContent(true) is called
-
- if ( $v !== null )
- {
- // increment the version
- if ( $increment_version ) $this->setData ( parent::getData() . $this->getFileSuffix() ) ;
- $this->should_call_set_data_content = false;
- $this->save();
-
- $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA );
- kFileSyncUtils::file_put_contents( $sync_key , $v , $strict );
- }
- }
- }
-
- // return the default file suffix according to the entry type
- private function getFileSuffix ( )
- {
- if ( $this->getType() == entryType::MIX ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_SHOW ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_XML )
- {
- return ".xml";
- }
- elseif ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_TEXT ||
- $this->getMediaType() == self::ENTRY_MEDIA_TYPE_GENERIC_1 )
- {
- return ".txt";
- }
- return "";
- }
-
- public function getThumbnail()
- {
- $thumbnail = parent::getThumbnail();
-
- if (!$thumbnail && $this->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)
- $thumbnail = "&audio_thumb.jpg";
-
- return $thumbnail;
- }
-
- /**
- * This function returns the file system path for a requested content entity.
- * @return string the content path
- */
- public function getThumbnailPath( $version = NULL )
- {
- return myContentStorage::getGeneralEntityPath("entry/thumbnail", $this->getIntId(), $this->getId(), $this->getThumbnail() , $version );
- }
-
- public function getThumbnailUrl( $version = NULL )
- {
- if(PermissionPeer::isValidForPartner(PermissionName::FEATURE_DISABLE_KMC_DRILL_DOWN_THUMB_RESIZE, $this->getPartnerId()))
- {
- $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA;
- if($this->getType() == entryType::MEDIA_CLIP && $this->getMediaType() != entry::ENTRY_MEDIA_TYPE_IMAGE)
- $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB;
-
- $syncKey = $this->getSyncKey($subType);
-
- $fileSync = null;
- $serveRemote = false;
- $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
-
- switch($partner->getStorageServePriority())
- {
- case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY:
- $serveRemote = true;
- $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
- if(!$fileSync)
- return null;
-
- break;
-
- case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_FIRST:
- $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
- if($fileSync)
- $serveRemote = true;
-
- break;
-
- case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST:
- $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
- if($fileSync)
- break;
-
- $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
- if(!$fileSync)
- return null;
-
- $serveRemote = true;
- break;
-
- case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY:
- $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
- if(!$fileSync)
- return null;
-
- break;
- }
-
- if($serveRemote && $fileSync)
- return $fileSync->getExternalUrl();
- }
-
- //$path = $this->getThumbnailPath ( $version );
- $path = myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . "/thumbnail/entry_id/" . $this->getId() ;
- $current_version = $this->getThumbnailVersion();
- if ( $version )
- $path .= "/version/$version";
- else
- $path .= "/version/$current_version";
- $url = myPartnerUtils::getCdnHost($this->getPartnerId()) . $path ;
- return $url;
- }
-
- public function getBigThumbnailPath($revertToSmall = false , $version = NULL )
- {
- if ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE )
- {
- // we dont need to make a copy for the big thumbnail - we can use the image itself
- return $this->getDataPath();
- }
-
- $path = myContentStorage::getGeneralEntityPath("entry/bigthumbnail", $this->getIntId(), $this->getId(), $this->getThumbnail() , $version );
- if ($revertToSmall && !file_exists(myContentStorage::getFSContentRootPath().$path))
- $path = $this->getThumbnailPath();
-
- return $path;
- }
-
- public function getBigThumbnailUrl( $version = NULL )
- {
-
- $path = $this->getBigThumbnailPath ( $version );
- $url = requestUtils::getRequestHost() . $path ;
- return $url;
- }
-
- /**
- * This function sets and returns a new path for a requested content entity.
- * @param string $filename = the original fileName from which the extension is cut.
- * @return string the content file name
- */
- public function setThumbnail($filename , $force = false )
- {
- if ( $force )
- $data = $filename;
- else
- $data = myContentStorage::generateRandomFileName($filename, $this->getThumbnail());
-
- parent::setThumbnail($data);
- return $this->getThumbnail();
- }
-
- public function setTags($tags , $update_db = true )
- {
- if ($this->tags !== $tags) {
- $tags = ktagword::updateTags($this->tags, $tags , $update_db );
- parent::setTags( trim($tags));
- }
- }
-
- public function setAdminTags($tags)
- {
- if ( $tags === null ) return ;
-
- if ( $tags == "" || $this->getAdminTags() !== $tags ) {
- parent::setAdminTags(trim(ktagword::fixAdminTags( $tags)));
- }
- }
-
- /**
- * Set the categories (use only the most child categories)
- *
- * @param string $categories
- */
- public function setCategories($newCats)
- {
- $newCats = explode(self::ENTRY_CATEGORY_SEPARATOR, $newCats);
-
- $this->trimCategories($newCats);
-
- if (count($newCats) > self::MAX_CATEGORIES_PER_ENTRY)
- throw new kCoreException("Max number of allowed entries per category was reached", kCoreException::MAX_CATEGORIES_PER_ENTRY);
-
- // remove duplicates
- $newCats = array_unique($newCats);
-
- // leave only the most child categories
- $mostChildCats = array();
- foreach($newCats as $currentCat)
- {
- $unsetI = false;
- $add = true;
- foreach($mostChildCats as $i => $mostChild)
- {
- if (strpos($currentCat, $mostChild.categoryPeer::CATEGORY_SEPARATOR) === 0)
- {
- $unsetI = $i;
- break;
- }
- if (strpos($mostChild, $currentCat.categoryPeer::CATEGORY_SEPARATOR) === 0)
- {
- $add = false;
- }
- }
- if ($unsetI !== false)
- unset($mostChildCats[$unsetI]);
-
- if ($add)
- $mostChildCats[] = $currentCat;
- }
-
- $this->old_categories = $this->categories;
- parent::setCategories(implode(",", $mostChildCats));
- $this->is_categories_modified = true;
- }
-
- public function renameCategory($oldFullName, $newFullName)
- {
- $categories = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->categories);
- foreach($categories as &$category)
- {
- $category = preg_replace("/^".$oldFullName."/", $newFullName, $category);
- }
- $this->categories = implode(self::ENTRY_CATEGORY_SEPARATOR, $categories);
- $this->old_categories = $this->categories; // so the sync won't increment the count on categories
- $this->modifiedColumns[] = entryPeer::CATEGORIES;
- $this->is_categories_modified = true;
- }
-
- public function removeCategory($fullName)
- {
- $this->old_categories = $this->categories;
- $categories = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->categories);
- $newCategories = array();
- foreach($categories as $category)
- {
- if (!preg_match("/^".$fullName."/", $category))
- $newCategories[] = $category;
- }
- $this->categories = implode(self::ENTRY_CATEGORY_SEPARATOR, $newCategories);
- $this->modifiedColumns[] = entryPeer::CATEGORIES;
- $this->is_categories_modified = true;
- }
-
- private function trimCategories(&$categories)
- {
- $trimedCategories = array();
- foreach($categories as &$cat)
- {
- $cat = trim($cat);
- $catExploded = explode(categoryPeer::CATEGORY_SEPARATOR, $cat);
- $fixedCat = array();
-
- foreach($catExploded as $subCat)
- {
- if (strlen($subCat) > 0)
- {
- $fixedCat[] = $subCat;
- }
- }
-
- $cat = implode($fixedCat, categoryPeer::CATEGORY_SEPARATOR);
-
- if (strlen($cat) > 0)
- $trimedCategories[] = $cat;
- }
-
- $categories = $trimedCategories;
- }
-
- public function getCreatedAtAsInt ()
- {
- return $this->getCreatedAt( null );
- }
-
- public function getUpdateAtAsInt ()
- {
- return $this->getUpdatedAt( null );
- }
-
- public function getFormattedCreatedAt( $format = dateUtils::KALTURA_FORMAT )
- {
- return dateUtils::formatKalturaDate( $this , 'getCreatedAt' , $format );
- }
-
- public function getFormattedUpdatedAt( $format = dateUtils::KALTURA_FORMAT )
- {
- return dateUtils::formatKalturaDate( $this , 'getUpdatedAt' , $format );
- }
-
- public function getAppearsIn ( )
- {
- if ( $this->appears_in == NULL )
- {
- if ( $this->getkshow() )
- {
- $this->setAppearsIn ( $this->getkshow()->getName() );
- }
- else
- {
- return ""; // strange - no kshow ! must be a dangling entry
- }
- }
-
- return $this->appears_in;
- }
-
- public function setAppearsIn ( $name )
- {
- $this->appears_in = $name;
- }
-
- public function getWidgetImagePath()
- {
- return myContentStorage::getGeneralEntityPath("entry/widget", $this->getIntId(), $this->getId(), ".gif" );
- }
-
- // when calling duration - use seconds rather than msecs
- public function getDuration ()
- {
- $t = $this->getLengthInMsecs();
- if ( $t == null ) return 0;
- return ( $t / 1000 );
- }
-
- /**
- * returns the duration as int
- * @return int
- */
- public function getDurationInt()
- {
- return (int)round($this->getDuration());
- }
-
- /**
- * @return string
- */
- public function getDurationType()
- {
- return entryPeer::getDurationType($this->getDurationInt());
- }
-
- public function getMetadata( $version = null)
- {
- if ( $this->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW )
- {
- return null;
- }
-
- if ( $version <= 0 ) $version=null;
- $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
- $content = kFileSyncUtils::file_get_contents( $sync_key , true , false ); // don't be strict when fetching metadata
- if ( $content )
- return $content;
- else
- return "<xml></xml>";
- }
-
-
- // will place the metadata in the entry (as long as it's of type show)
- // TODO - maybe change this because entries can change their types - intro of type video can become a show !!
- // by default will override the existing file - this will be starnge because there is not supposed to be a file with that name yet -
- // all the indexes up to this point where smaller then this futurae one.
- /**
- Writes the content of the metadata to a new file.
- Returns the number of bytes written to disk
- */
- // TODO - is this really what should be returned ??
- public function setMetadata ( $kshow , $content , $override_existing=true , $total_duration = null , $specific_version = null )
- {
- if ( $this->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW )
- {
- return null;
- }
-
- // TODO - better to call this with slight modifications
- //myMetadataUtils::setMetadata ($content, $kshow, $this , $override_existing );
- if ( $specific_version == null )
- {
- // increment the counter of the file
- $this->setData ( parent::getData() );
- }
- // check that the file of the desired version really exists
- // $content_dir = myContentStorage::getFSContentRootPath();
- // $file_name = $content_dir . $this->getDataPath( $specific_version ); // replaced__getDataPath
-
- $sync_key = $this->getSyncKey ( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $specific_version );
-
- if ( $override_existing || ! kFileSyncUtils::file_exists( $sync_key ,false ) )
- {
- $duration = $total_duration ? $total_duration : myMetadataUtils::getDuration ( $content );
- $this->setLengthInMsecs ( $duration * 1000 );
- $total_duration = null;
- $editor_type = null;
- $version = myContentStorage::getVersion( kFileSyncUtils::getReadyLocalFilePathForKey ( $sync_key ) );
- $fixed_content = myFlvStreamer::fixMetadata( $content , $version, $total_duration , $editor_type);
-
- $this->setModifiedAt(time()); // update the modified_at date
- $this->save();
-
- $sync_key = $this->getSyncKey ( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
- // TODO: here we assume we are UPDATING an exising version of the file - make sure all the following functions are tolerant.
- kFileSyncUtils::file_put_contents( $sync_key , $fixed_content , false ); // replaced__setFileContent
-
- // update the roughcut_entry table
- if ( $kshow != null ) $kshow_id = $kshow->getId();
- else $kshow_id = $this->getKshowId();
-
- $all_entries_for_roughcut = myMetadataUtils::getAllEntries ( $fixed_content );
- roughcutEntry::updateRoughcut( $this->getId() , $version , $kshow_id , $all_entries_for_roughcut );
-
- return ;
- }
- else
- {
- // no need to save changes - why increment the count if failed ??
- return -1;
- }
- }
-
- public function fixMetadata ( $increment_version = true , $content = null , $total_duration = null , $specific_version = null )
- {
- // check that the file of the desired version really exists
- $content_dir = myContentStorage::getFSContentRootPath();
- if ( !$content ) $content = $this->getMetadata( $specific_version );
-
- if ( $increment_version )
- {
- // increment the counter of the file
- $this->setData ( parent::getData() );
- }
-
- $file_name = kFileSyncUtils::getLocalFilePathForKey($this->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $specific_version)); // replaced__getDataPath
-
- $duration = $total_duration ? $total_duration : myMetadataUtils::getDuration ( $content );
- $this->setLengthInMsecs ( $duration * 1000 );
- $total_duration = null;
- $editor_type = null;
- $version = myContentStorage::getVersion($file_name);
- $fixed_content = myFlvStreamer::fixMetadata( $content , $version, $total_duration , $editor_type);
-
- $this->save();
-
- $sync_key = $this->getSyncKey ( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
- kFileSyncUtils::file_put_contents( $sync_key , $fixed_content , false ); // replaced__setFileContent
-
- return $fixed_content;
- }
-
- public function getVersion()
- {
- $version = parent::getData();
-
- if ($version)
- {
- $c = strstr($version, '^') ? '^' : '&';
- $parts = explode( $c, $version);
- }
- else
- $parts = array('');
-
- if (strlen($parts[0]))
- $current_version = pathinfo($parts[0], PATHINFO_FILENAME) ;
- else
- $current_version = 0;
-
- return $current_version;
- }
-
- public function getThumbnailVersion()
- {
- // For image entry, the data file sync sub type is used as thumbnail
- if($this->getType() == entryType::MEDIA_CLIP && $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE)
- return $this->getVersion();
-
- $version = parent::getThumbnail();
-
- if ($version)
- {
- $c = strstr($version, '^') ? '^' : '&';
- $parts = explode( $c, $version);
- }
- else
- $parts = array('');
-
- if (strlen($parts[0]))
- $current_version = pathinfo($parts[0], PATHINFO_FILENAME) ;
- else
- $current_version = 0;
-
- return $current_version;
- }
- // makes a copy of the desired version from the past as the next coming version of the entry
- // $desired_version = 100003, current_version = 100006 -> will conpy the content of <id>_100003.xxx -> <id>_1000007.xxx and will increment the version
- // so current_version = 100007.xxx now
- public function rollbackVersion( $desired_version )
- {
- // don't duplicate if staying in hte same version
- $current_version = $this->getVersion();
- if ( $desired_version == $current_version)
- return $current_version;
-
- $source_syc_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $desired_version );
- /*
- // check that the file of the desired version really exists
- $content = myContentStorage::getFSContentRootPath();
- $path = $content . $this->getDataPath( $desired_version ); // replaced__getDataPath
-
- if ( ! file_exists( $path ))
- {
- return null;
- }
- */
-
- // increment the counter of the file
- $this->setData ( parent::getData() );
-
- $target_syc_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA );
- /*
- $new_path = $content . $this->getDataPath( ); //replaced__getDataPath
-
- // make a copy
- kFile::moveFile( $path , $new_path , true , true );
- */
- kFileSyncUtils::copy( $source_syc_key , $target_syc_key );
-
- $this->save();
- // return the new version
- return $this->getVersion();
- }
-
- // if has status self::ENTRY_S
- public function getImportInfo ()
- {
- if ( $this->getStatus() == entryStatus::IMPORT )
- {
- $c = new Criteria();
- $c->add ( BatchJobPeer::ENTRY_ID , $this->getId() );
- $c->addDescendingOrderByColumn( BatchJobPeer::ID );
- $import = BatchJobPeer::doSelectOne ( $c );
- return $import;
- }
- return null;
- }
-
-
- public function getDisplayCredit ( )
- {
- if ($this->getCredit())
- return $this->getCredit();
- else if ( $this->getScreenName() )
- {
- return $this->getScreenName();
- }
- else
- {
- $kuser = $this->getkuser();
- return ( $kuser ? $kuser->getScreenName() : "" );
- }
- }
-
- public function moderate ($new_moderation_status , $fix_moderation_objects = false )
- {
- $error_msg = "Moderation status [$new_moderation_status] not supported by entry";
- switch($new_moderation_status)
- {
- case moderation::MODERATION_STATUS_APPROVED:
- // a new notification that is sent when an entry was founc to be ok after moderation
- myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE , $this );
- break;
- case moderation::MODERATION_STATUS_BLOCK:
- myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_BLOCK , $this->getid());
- break;
- case moderation::MODERATION_STATUS_DELETE:
- // physical disk deletion
- myEntryUtils::deleteEntry($this);
- myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_BLOCK , $this->getid());
- break;
- case moderation::MODERATION_STATUS_PENDING:
- // $this->setStatus(entryStatus::MODERATE);
- // throw new Exception($error_msg);
- break;
- case moderation::MODERATION_STATUS_REVIEW:
- // in this case the status of the entry should not change
- // throw new Exception($error_msg);
- break;
- default:
- throw new Exception($error_msg);
- break;
- }
-
- $this->setModerationStatus( $new_moderation_status );
-
- // TODO - fix loop of updating from entry ot moderation back to entry ...
- if ( $fix_moderation_objects )
- {
- myModerationMgr::updateModerationsForObject ( $this , $new_moderation_status );
- }
- $this->save();
- }
-
- public function setEditorType ( $editor_type ) { $this->putInCustomData ( "editor_type" , $editor_type ); }
-
- public function getEditorType ( )
- {
- if ( $this->getType() != entryType::MIX ) return null;
- $res = $this->getFromCustomData( "editor_type" );
- if ( $res == null ) return "Keditor"; // no value means Keditor == advanced
- return $res;
- }
-
- public function setConversionProfileId($conversion_quality)
- {
- $this->setConversionQuality($conversion_quality);
- }
- public function setConversionQuality($conversion_quality)
- {
- parent::setConversionProfileId($conversion…
Large files files are truncated, but you can click here to view the full file