/
Version.php
2094 lines (1892 loc) · 67.9 KB
/
Version.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
namespace Concrete\Core\Entity\File;
use Concrete\Core\Attribute\AttributeKeyInterface;
use Concrete\Core\Attribute\Category\FileCategory;
use Concrete\Core\Attribute\ObjectInterface;
use Concrete\Core\Attribute\ObjectTrait;
use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Database\Connection\Connection;
use Concrete\Core\Entity\Attribute\Value\FileValue;
use Concrete\Core\Entity\File\StorageLocation\StorageLocation;
use Concrete\Core\Events\EventDispatcher;
use Concrete\Core\File\Command\GenerateThumbnailAsyncCommand;
use Concrete\Core\File\Command\RescanFileAsyncCommand;
use Concrete\Core\File\Event\FileVersion as FileVersionEvent;
use Concrete\Core\File\Exception\InvalidDimensionException;
use Concrete\Core\File\Image\BitmapFormat;
use Concrete\Core\File\Image\Thumbnail\Path\Resolver;
use Concrete\Core\File\Image\Thumbnail\Thumbnail;
use Concrete\Core\File\Image\Thumbnail\ThumbnailFormatService;
use Concrete\Core\File\Image\Thumbnail\ThumbnailPlaceholderService;
use Concrete\Core\File\Image\Thumbnail\Type\Type as ThumbnailType;
use Concrete\Core\File\Image\Thumbnail\Type\Version as ThumbnailTypeVersion;
use Concrete\Core\File\Importer;
use Concrete\Core\File\Menu;
use Concrete\Core\File\Type\Type as FileType;
use Concrete\Core\File\Type\TypeList as FileTypeList;
use Concrete\Core\Http\FlysystemFileResponse;
use Concrete\Core\Http\Request;
use Concrete\Core\Logging\Channels;
use Concrete\Core\Logging\LoggerFactory;
use Concrete\Core\Notification\Events\MercureService;
use Concrete\Core\Notification\Events\ServerEvent\ThumbnailGenerated;
use Concrete\Core\Notification\Events\ServerEvent\ThumbnailGeneratedEvent;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface;
use Concrete\Core\User\UserInfoRepository;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Imagine\Exception\NotSupportedException;
use Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use Imagine\Image\ImagineInterface;
use Imagine\Image\Metadata\ExifMetadataReader;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\FileNotFoundException;
use League\Flysystem\MountManager;
use League\Flysystem\Util;
use Page;
use Permissions;
use stdClass;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Throwable;
use Concrete\Core\User\User;
/**
* Represents a version of a file.
*
* @ORM\Entity
* @ORM\Table(
* name="FileVersions",
* indexes={
* @ORM\Index(name="fvFilename", columns={"fvFilename"}),
* @ORM\Index(name="fvExtension", columns={"fvExtension"}),
* @ORM\Index(name="fvType", columns={"fvType"})
* }
* )
*/
class Version implements ObjectInterface
{
use ObjectTrait;
/**
* Update type: file replaced.
*
* @var int
*/
const UT_REPLACE_FILE = 1;
/**
* Update type: title updated.
*
* @var int
*/
const UT_TITLE = 2;
/**
* Update type: description updated.
*
* @var int
*/
const UT_DESCRIPTION = 3;
/**
* Update type: tags modified.
*
* @var int
*/
const UT_TAGS = 4;
/**
* Update type: extended attributes changed.
*
* @var int
*/
const UT_EXTENDED_ATTRIBUTE = 5;
/**
* Update type: contents changed.
*
* @var int
*/
const UT_CONTENTS = 6;
/**
* Update type: file version renamed.
*
* @var int
*/
const UT_RENAME = 7;
/**
* The associated File instance.
*
* @ORM\Id
* @ORM\ManyToOne(targetEntity="File", inversedBy="versions")
* @ORM\JoinColumn(name="fID", referencedColumnName="fID")
*
* @var \Concrete\Core\Entity\File\File
*/
protected $file;
/**
* The progressive file version identifier.
*
* @ORM\Id
* @ORM\Column(type="integer")
*
* @var int
*/
protected $fvID = 0;
/**
* The name of the file.
*
* @ORM\Column(type="string")
*
* @var string
*/
protected $fvFilename = null;
/**
* The path prefix used to store the file in the file system.
*
* @ORM\Column(type="string", nullable=true)
*
* @var string
*/
protected $fvPrefix;
/**
* The date/time when the file version has been added.
*
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
protected $fvDateAdded;
/**
* The date/time when the file version has been approved.
*
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
protected $fvActivateDateTime;
/**
* Is this version the approved one for the associated file?
*
* @ORM\Column(type="boolean")
*
* @var bool
*/
protected $fvIsApproved = false;
/**
* The ID of the user that created the file version.
*
* @ORM\Column(type="integer")
*
* @var int
*/
protected $fvAuthorUID = 0;
/**
* The ID of the user that approved the file version.
*
* @ORM\Column(type="integer")
*
* @var int
*/
protected $fvApproverUID = 0;
/**
* The size (in bytes) of the file version.
*
* @ORM\Column(type="bigint")
*
* @var int
*/
protected $fvSize = 0;
/**
* The title of the file version.
*
* @ORM\Column(type="string", nullable=true)
*
* @var string|null
*/
protected $fvTitle = null;
/**
* The description of the file version.
*
* @ORM\Column(type="text", nullable=true)
*
* @var string|null
*/
protected $fvDescription = null;
/**
* The extension of the file version.
*
* @ORM\Column(type="string", nullable=true)
*
* @var string|null
*/
protected $fvExtension = null;
/**
* The tags assigned to the file version (separated by a newline character - '\n').
*
* @ORM\Column(type="text", nullable=true)
*
* @var string|null
*/
protected $fvTags = null;
/**
* The type of the file version.
*
* @ORM\Column(type="integer")
*
* @var int
*/
protected $fvType = 0;
/**
* Does this file version has a thumbnail to be used for file listing?
*
* @ORM\Column(type="boolean")
*
* @var bool
*/
protected $fvHasListingThumbnail = false;
/**
* Does this file version has a thumbnail to be used used for details?
*
* @ORM\Column(type="boolean")
*
* @var bool
*/
protected $fvHasDetailThumbnail = false;
/**
* The currently loaded Image instance.
*
* @var \Imagine\Image\ImageInterface|false|null null: still not loaded; false: load failed; ImageInterface otherwise
*/
private $imagineImage = null;
/**
* Initialize the instance.
*/
public function __construct()
{
$this->fvDateAdded = new DateTime();
$this->fvActivateDateTime = new DateTime();
}
/**
* Add a new file version.
* You should call refreshAttributes in order to update the size, extension, type and other attributes.
*
* @param \Concrete\Core\Entity\File\File $file the File instance associated to this version
* @param string $filename The name of the file
* @param string $prefix the path prefix used to store the file in the file system
* @param array $data Valid array keys are {
*
* @var int|null $uID the ID of the user that creates the file version (if not specified or empty: we'll assume the currently user logged in user)
* @var string $fvTitle the title of the file version
* @var string $fvDescription the description of the file version
* @var string $fvTags the tags to be assigned to the file version (separated by newlines and/or commas)
* @var bool $fvIsApproved Is this version the approved one for the associated file? (default: true)
* }
*
* @return static
*/
public static function add(File $file, $filename, $prefix, $data = [])
{
$data += [
'uID' => 0,
'fvTitle' => '',
'fvDescription' => '',
'fvTags' => '',
'fvIsApproved' => true,
];
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$dh = $app->make('date');
$date = new DateTime($dh->getOverridableNow());
$uID = (int) $data['uID'];
if ($uID < 1) {
$u = $app->make(User::class);
if ($u->isRegistered()) {
$uID = (int) $u->getUserID();
} else {
$uID = 0;
}
}
$fv = new static();
$fv->file = $file;
$fv->fvID = 1;
$fv->fvFilename = (string) $filename;
$fv->fvPrefix = $prefix;
$fv->fvDateAdded = $date;
$fv->fvActivateDateTime = $date;
$fv->fvIsApproved = (bool) $data['fvIsApproved'];
$fv->fvAuthorUID = $uID;
$fv->fvApproverUID = $uID;
$fv->fvTitle = (string) $data['fvTitle'];
$fv->fvDescription = (string) $data['fvDescription'];
$fv->fvTags = self::cleanTags((string) $data['fvTags']);
$em->persist($fv);
$em->flush();
$fve = new FileVersionEvent($fv);
$app->make(EventDispatcher::class)->dispatch('on_file_version_add', $fve);
return $fv;
}
/**
* Normalize the tags separator, remove empty tags.
*
* @param string $tagsStr The list of tags, delimited by '\n', '\r' or ','
*
* @return string
*/
public static function cleanTags($tagsStr)
{
$tagsArray = explode("\n", str_replace(["\r", ','], "\n", $tagsStr));
$cleanTags = [];
foreach ($tagsArray as $tag) {
$tag = trim($tag);
if ($tag !== '') {
$cleanTags[] = $tag;
}
}
//the leading and trailing line break char is for searching: fvTag like %\ntag\n%
return isset($cleanTags[0]) ? "\n" . implode("\n", $cleanTags) . "\n" : '';
}
/**
* Set the associated File instance.
*
* @param \Concrete\Core\Entity\File\File $file
*/
public function setFile(File $file)
{
$this->file = $file;
}
/**
* Get the associated File instance.
*
* @return \Concrete\Core\Entity\File\File
*/
public function getFile()
{
return $this->file;
}
/**
* Get the ID of the associated file instance.
*
* @return int
*/
public function getFileID()
{
return $this->file->getFileID();
}
/**
* Get the ID of the associated file instance.
*
* @return string
*/
public function getFileUUID()
{
return $this->file->getFileUUID();
}
/**
*
* @return bool
*/
public function hasFileUUID()
{
return $this->file->hasFileUUID();
}
/**
* Set the progressive file version identifier.
*
* @param int $fvID
*/
public function setFileVersionID($fvID)
{
$this->fvID = (int) $fvID;
}
/**
* Get the progressive file version identifier.
*
* @return int
*/
public function getFileVersionID()
{
return $this->fvID;
}
/**
* Rename the file.
*
* @param string $filename
*/
public function rename($filename)
{
$storage = $this->getFile()->getFileStorageLocationObject();
if ($storage !== null) {
$filename = (string) $filename;
$app = Application::getFacadeApplication();
$cf = $app->make('helper/concrete/file');
$oldFilename = $this->fvFilename;
$path = $cf->prefix($this->fvPrefix, $oldFilename);
$newPath = $cf->prefix($this->fvPrefix, $filename);
$filesystem = $storage->getFileSystemObject();
if ($filesystem->has($path)) {
$filesystem->rename($path, $newPath);
}
$this->fvFilename = $filename;
if ($this->fvTitle == $oldFilename) {
$this->fvTitle = $filename;
}
$this->logVersionUpdate(self::UT_RENAME);
$this->save();
$fve = new FileVersionEvent($this);
$app->make(EventDispatcher::class)->dispatch('on_file_version_rename', $fve);
}
}
/**
* Update the filename and the path prefix of the file.
*
* @param string $filename The new name of file
* @param string $prefix The new path prefix
*/
public function updateFile($filename, $prefix)
{
$this->fvFilename = $filename;
$this->fvPrefix = $prefix;
$this->save();
$this->logVersionUpdate(self::UT_REPLACE_FILE);
}
/**
* Set the name of the file.
*
* @param string $filename
*/
public function setFilename($filename)
{
$this->fvFilename = $filename;
}
/**
* Get the name of the file.
*
* @return string
*/
public function getFileName()
{
return $this->fvFilename;
}
/**
* Get the path prefix used to store the file in the file system.
*
* @return string
*/
public function getPrefix()
{
return $this->fvPrefix;
}
/**
* Get the date/time when the file version has been added.
*
* @return \DateTime
*/
public function getDateAdded()
{
return $this->fvDateAdded;
}
/**
* Get the date/time when the file version has been activated (or NULL if the file version is not approved).
*
* @return \DateTime|null
*/
public function getActivateDateTime()
{
return $this->fvIsApproved ? $this->fvActivateDateTime : null;
}
/**
* Mark this file version as approved (and disapprove all the other versions of the file).
* The currently logged in user (if any) will be stored as the approver.
*/
public function approve()
{
$app = Application::getFacadeApplication();
foreach ($this->file->getFileVersions() as $fv) {
$fv->fvIsApproved = false;
$fv->save(false);
}
$this->fvIsApproved = true;
$this->fvActivateDateTime = new DateTime();
$u = $app->make(User::class);
if ($u->isRegistered()) {
$this->fvApproverUID = (int) $u->getUserID();
}
$this->save();
$fve = new FileVersionEvent($this);
$app->make(EventDispatcher::class)->dispatch('on_file_version_approve', $fve);
$fo = $this->getFile();
$fo->reindex();
$app->make('cache/request')->delete('file/version/approved/' . $this->getFileID());
}
/**
* Mark this file version as not approved.
*/
public function deny()
{
$app = Application::getFacadeApplication();
$this->fvIsApproved = false;
$this->save();
$fve = new FileVersionEvent($this);
$app->make(EventDispatcher::class)->dispatch('on_file_version_deny', $fve);
$app->make('cache/request')->delete('file/version/approved/' . $this->getFileID());
}
/**
* Is this version the approved one for the associated file?
*
* @return bool
*/
public function isApproved()
{
return $this->fvIsApproved;
}
/**
* Get the ID of the user that created the file version.
*
* @return int
*/
public function getAuthorUserID()
{
return $this->fvAuthorUID;
}
/**
* Get the username of the user that created the file version (or "Unknown").
*
* @return string
*/
public function getAuthorName()
{
if ($this->fvAuthorUID) {
$app = Application::getFacadeApplication();
$ui = $app->make(UserInfoRepository::class)->getByID($this->fvAuthorUID);
} else {
$ui = null;
}
return $ui === null ? t('(Unknown)') : $ui->getUserDisplayName();
}
/**
* Get the ID of the user that approved the file version.
*
* @return int
*/
public function getApproverUserID()
{
return $this->fvApproverUID;
}
/**
* Get the username of the user that approved the file version (or "Unknown").
*
* @return string
*/
public function getApproverName()
{
if ($this->fvApproverUID) {
$app = Application::getFacadeApplication();
$ui = $app->make(UserInfoRepository::class)->getByID($this->fvApproverUID);
} else {
$ui = null;
}
return $ui === null ? t('(Unknown)') : $ui->getUserDisplayName();
}
/**
* Get the file size of the file (in bytes).
*
* @return int
*/
public function getFullSize()
{
return $this->fvSize;
}
/**
* Get the formatted file size.
*
* @return string
*
* @example 123 KB
*/
public function getSize()
{
$app = Application::getFacadeApplication();
return $app->make('helper/number')->formatSize($this->fvSize, 'KB');
}
/**
* Update the title of the file.
*
* @param string $title
*/
public function updateTitle($title)
{
$app = Application::getFacadeApplication();
$this->fvTitle = $title;
$this->save();
$this->logVersionUpdate(self::UT_TITLE);
$fve = new FileVersionEvent($this);
$app->make(EventDispatcher::class)->dispatch('on_file_version_update_title', $fve);
}
/**
* Get the title of the file version.
*
* @return null|string
*/
public function getTitle()
{
return $this->fvTitle;
}
/**
* Update the description of the file.
*
* @param string $descr
*/
public function updateDescription($descr)
{
$app = Application::getFacadeApplication();
$this->fvDescription = $descr;
$this->save();
$this->logVersionUpdate(self::UT_DESCRIPTION);
$fve = new FileVersionEvent($this);
$app->make(EventDispatcher::class)->dispatch('on_file_version_update_description', $fve);
}
/**
* Get the description of the file version.
*
* @return null|string
*/
public function getDescription()
{
return $this->fvDescription;
}
/**
* Get the extension of the file version.
*
* @return null|string
*/
public function getExtension()
{
return $this->fvExtension;
}
/**
* Update the tags associated to the file.
*
* @param string $tags List of tags separated by newlines and/or commas
*/
public function updateTags($tags)
{
$app = Application::getFacadeApplication();
$tags = self::cleanTags($tags);
$this->fvTags = $tags;
$this->save();
$this->logVersionUpdate(self::UT_TAGS);
$fve = new FileVersionEvent($this);
$app->make(EventDispatcher::class)->dispatch('on_file_version_update_tags', $fve);
}
/**
* Get the tags assigned to the file version (as a list of strings).
*
* @return string[]
*/
public function getTagsList()
{
$tags = explode("\n", str_replace("\r", "\n", trim($this->getTags())));
$clean_tags = [];
foreach ($tags as $tag) {
$tag = trim($tag);
if ($tag !== '') {
$clean_tags[] = $tag;
}
}
return $clean_tags;
}
/**
* Get the tags assigned to the file version (one tag per line - lines are separated by '\n').
*
* @return null|string
*/
public function getTags()
{
return $this->fvTags;
}
/**
* Get the mime type of the file if known.
*
* @return string|false
*/
public function getMimeType()
{
try {
$fre = $this->getFileResource();
$result = $fre->getMimetype();
} catch (FileNotFoundException $x) {
$result = false;
}
return $result;
}
/**
* Get the type of the file.
*
* @return \Concrete\Core\File\Type\Type
*/
public function getTypeObject()
{
$app = Application::getFacadeApplication();
$fh = $app->make('helper/file');
$ext = $fh->getExtension($this->fvFilename);
$ftl = FileTypeList::getType($ext);
return $ftl;
}
/**
* Get the name of the file type.
*
* @return string
*/
public function getType()
{
$ftl = $this->getTypeObject();
return $ftl->getName();
}
/**
* Get the localized name of the file type.
*
* @return string
*/
public function getDisplayType()
{
$ftl = $this->getTypeObject();
return $ftl->getDisplayName();
}
/**
* Get the localized name of the generic category type.
*
* @return string
*/
public function getGenericTypeText($includeExtension = false)
{
$to = $this->getTypeObject();
if ($includeExtension) {
$extension = $this->getExtension();
if ($extension) {
return tc(
/* i18n: %1$s is a file extension (eg 'JPG'), %2$s is a file type (eg 'Image') */
'FileExtensionAndType',
'%1$s %2$s',
strtoupper($extension),
$to->getGenericDisplayType()
);
}
} else if ($to) {
return $to->getGenericDisplayType();
}
return t('Unknown');
}
/**
* Log updates to files.
*
* @param int $updateTypeID One of the Version::UT_... constants
* @param int $updateTypeAttributeID the ID of the attribute that has been updated (if any - useful when $updateTypeID is UT_EXTENDED_ATTRIBUTE)
*/
public function logVersionUpdate($updateTypeID, $updateTypeAttributeID = 0)
{
$app = Application::getFacadeApplication();
$db = $app->make(Connection::class);
$db->executeQuery(
'INSERT INTO FileVersionLog (fID, fvID, fvUpdateTypeID, fvUpdateTypeAttributeID) VALUES (?, ?, ?, ?)',
[
$this->getFileID(),
$this->getFileVersionID(),
$updateTypeID,
$updateTypeAttributeID,
]
);
}
/**
* Get an array containing human-readable descriptions of everything that happened to this file version.
*
* @return string[]
*/
public function getVersionLogComments()
{
$app = Application::getFacadeApplication();
$db = $app->make(Connection::class);
$updates = [];
$ga = $db->fetchAll(
'SELECT fvUpdateTypeID, fvUpdateTypeAttributeID FROM FileVersionLog WHERE fID = ? AND fvID = ? ORDER BY fvlID ASC',
[$this->getFileID(), $this->getFileVersionID()]
);
foreach ($ga as $a) {
switch ($a['fvUpdateTypeID']) {
case self::UT_REPLACE_FILE:
$updates[] = t('File');
break;
case self::UT_TITLE:
$updates[] = t('Title');
break;
case self::UT_DESCRIPTION:
$updates[] = t('Description');
break;
case self::UT_TAGS:
$updates[] = t('Tags');
break;
case self::UT_CONTENTS:
$updates[] = t('File Content');
break;
case self::UT_RENAME:
$updates[] = t('File Name');
break;
case self::UT_EXTENDED_ATTRIBUTE:
$val = $db->fetchColumn(
'SELECT akName FROM AttributeKeys WHERE akID = ?',
[$a['fvUpdateTypeAttributeID']]
);
if ($val !== false) {
$updates[] = $val;
}
break;
}
}
return array_values(array_unique($updates));
}
/**
* Get the path to the file relative to the webroot (may not exist).
* Return NULL if the file storage location is invalid.
* If the storage location does not support relative paths, you'll get the URL to the file (or the download URL if the file is not directly accessible).
*
* @return string|null
*
* @example /application/files/0000/0000/0000/file.png
*/
public function getRelativePath()
{
$url = null;
$fsl = $this->getFile()->getFileStorageLocationObject();
if ($fsl !== null) {
$app = Application::getFacadeApplication();
$cf = $app->make('helper/concrete/file');
$configuration = $fsl->getConfigurationObject();
if ($configuration->hasRelativePath()) {
$url = $configuration->getRelativePathToFile($cf->prefix($this->fvPrefix, $this->fvFilename));
}
if ($configuration->hasPublicURL() && !$url) {
$url = $configuration->getPublicURLToFile($cf->prefix($this->fvPrefix, $this->fvFilename));
}
if (!$url) {
$url = (string) $this->getDownloadURL();
}
}
return $url;
}
/**
* Get an URL that points to the file on disk (if not available, you'll get the result of the getDownloadURL method).
* Return NULL if the file storage location is invalid.
* If the file is not directly accessible, you'll get the download URL.
*
* @return string|null
*/
public function getURL()
{
$url = null;
$app = Application::getFacadeApplication();
$cf = $app->make('helper/concrete/file');
$configuration = $this->getFileStorageLocationConfiguration();
if ($this->hasPublicURL() && $configuration !== null) {
$url = $configuration->getPublicURLToFile($cf->prefix($this->fvPrefix, $this->fvFilename));
}
if (!$url) {
$url = (string) $this->getDownloadURL();
}
return $url;
}
/**
* Get File Storage Location Configuration object of this file.
*
* @return \Concrete\Core\File\StorageLocation\Configuration\ConfigurationInterface|null
*/
protected function getFileStorageLocationConfiguration()
{
$configuration = null;
$fsl = $this->getFile()->getFileStorageLocationObject();
if ($fsl !== null) {
$configuration = $fsl->getConfigurationObject();
}
return $configuration;