/
entry.php
4334 lines (3608 loc) · 133 KB
/
entry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Subclass for representing a row from the 'entry' table.
*
*
*
* @package Core
* @subpackage model
*/
class entry extends Baseentry implements ISyncableFile, IIndexable, IOwnable, IRelatedObject, IElasticIndexable
{
protected $new_categories = '';
protected $new_categories_ids = '';
protected $old_categories;
protected $is_categories_modified = false;
protected $is_categories_names_modified = false;
protected $creator_kuser_id = null;
protected $playsViewsData = null;
protected $playsViewsDataInitialized = false;
const MINIMUM_ID_TO_DISPLAY = 8999;
const ROOTS_FIELD_PREFIX = 'K_Pref';
const ROOTS_FIELD_ENTRY_PREFIX = 'KP_Entry';
const ROOTS_FIELD_PARENT_ENTRY_PREFIX = 'KP_Parent';
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_MANUAL_LIVE_STREAM = 30;
const ENTRY_MEDIA_SOURCE_AKAMAI_UNIVERSAL_LIVE = 31;
const ENTRY_MEDIA_SOURCE_LIVE_STREAM = 32;
const ENTRY_MEDIA_SOURCE_LIVE_CHANNEL = 33;
const ENTRY_MEDIA_SOURCE_RECORDED_LIVE = 34;
const ENTRY_MEDIA_SOURCE_CLIP = 35;
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 MAX_CATEGORIES_PER_ENTRY_DISABLE_LIMIT_FEATURE = 200;
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 FILE_SYNC_ENTRY_SUB_TYPE_LIVE_PRIMARY = 10;
const FILE_SYNC_ENTRY_SUB_TYPE_LIVE_SECONDARY = 11;
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 = ",";
const ENTRY_ID_THAT_DOES_NOT_EXIST = 'nonExistingId';
const CATEGORY_SEARCH_PERFIX = 'c';
const CATEGORY_PARENT_SEARCH_PERFIX = 'p';
const CATEGORY_OR_PARENT_SEARCH_PERFIX = 'pc';
const CATEGORY_SEARCH_STATUS = 's';
const PARTNER_STATUS_FORMAT = 'P%sST%s';
const CATEGORIES_INDEXED_FIELD_PREFIX = 'pid';
const PLAYSVIEWS_CACHE_KEY_PREFIX = 'plays_views_';
const PLAYS_CACHE_KEY = 'plays';
const VIEWS_CACHE_KEY = 'views';
const LAST_PLAYED_AT_CACHE_KEY = 'last_played_at';
const PLAYS_30_DAYS_CACHE_KEY = 'plays_30days';
const VIEWS_30_DAYS_CACHE_KEY = 'views_30days';
const PLAYS_7_DAYS_CACHE_KEY = 'plays_7days';
const VIEWS_7_DAYS_CACHE_KEY = 'views_7days';
const PLAYS_1_DAY_CACHE_KEY = 'plays_1day';
const VIEWS_1_DAY_CACHE_KEY = 'views_1day';
const DEFAULT_IMAGE_HEIGHT = 480;
const DEFAULT_IMAGE_WIDTH = 640;
const CAPABILITIES = "capabilities";
const TEMPLATE_ENTRY_ID = "templateEntryId";
const LIVE_THUMB_PATH = "content/templates/entry/thumbnail/live_thumb.jpg";
private $appears_in = null;
private $m_added_moderation = false;
private $should_call_set_data_content = false;
private $data_content = null;
private $desired_version = null;
//An attribute that contains the rules by which this entry was created, only in case it was created
// via clone operation
private $clone_options = 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::retrieveByPKNoFilter( $id );
if ( ! $existing_object ) return $id;
}
die();
}
public function justSave($con = null)
{
return parent::save( $con );
}
public function save(PropelPDO $con = null, $skipReload = false)
{
$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->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->getDisplayInSearch() != mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM)
{
mySearchUtils::setDisplayInSearch($this);
}
ktagword::updateAdminTags($this);
// same for puserId ...
$this->getPuserId();
// 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, $skipReload);
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, $skipReload);
}
// 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, $skipReload);
}
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 );
}
/**
* will handle the flow in case of need to moderate.
*/
public function setStatusReady ( $force = false )
{
$this->setStatus( entryStatus::READY );
$this->setDefaultModerationStatus();
return $this->getStatus();
}
/* (non-PHPdoc)
* @see Baseentry::setModerationStatus()
*/
public function setModerationStatus($v)
{
if($v == $this->getModerationStatus())
return $this;
if($v == entry::ENTRY_MODERATION_STATUS_PENDING_MODERATION || $v == entry::ENTRY_MODERATION_STATUS_FLAGGED_FOR_REVIEW)
$this->incModerationCount();
parent::setModerationStatus($v);
}
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[] = file_exists($local_file_sync->getFullPath()) ? filemtime ( $local_file_sync->getFullPath()) : false;
// 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 )
{
static::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)
{
static::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 );
}
protected 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;
}
protected 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 )
{
return myContentStorage::getFSContentRootPath() . $this->getDataPath($version);
}
/**
* 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 );
}
$current_version = $this->getVersion();
$entryId = $this->getId();
$media_type = $this->getMediaType();
if ($media_type == self::ENTRY_MEDIA_TYPE_VIDEO || $media_type == self::ENTRY_MEDIA_TYPE_AUDIO)
{
$url = $this->createPlayManifestUrlByFormat("url");
}
else if ($media_type == self::ENTRY_MEDIA_TYPE_IMAGE )
{
$width = self::DEFAULT_IMAGE_WIDTH;
$height = self::DEFAULT_IMAGE_HEIGHT;
$url = myPartnerUtils::getCdnHost($this->getPartnerId());
$url .= myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() );
if (!$version)
$version = $current_version;
$url .= "/thumbnail/entry_id/$entryId/def_height/$height/def_width/$width/version/$version/type/1";
}
else
return null;
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 )
{
if(in_array($this->getMediaType(), array(self::ENTRY_MEDIA_TYPE_VIDEO, self::ENTRY_MEDIA_TYPE_AUDIO )))
{
//Request the soruce flavor to be compaitble to raw action default behavior
return $this->createPlayManifestUrlByFormat("download") . "/flavorParamIds/0";
}
// 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;
}
/**
* The method returns the var_dumpd_options, in case the entry was created via clone operation.
* Otherwise; it returns null
* @return null|array kBaseEntryCloneOptionComponent
*/
public function getCloneOptions()
{
return $this->clone_options;
}
/**
* The method sets the options by which the current entry was cloned.
* @param array $cloneOptionsArray
*/
public function setCloneOptions(array $cloneOptionsArray)
{
$this->clone_options = $cloneOptionsArray;
}
// 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;
$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 && $v == $this->getDataContent())
{
return;
}
// 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 )
{