forked from Islandora/tuque
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Datastream.php
1755 lines (1564 loc) · 46.7 KB
/
Datastream.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
/**
* @file
* This file defines all the classes used to manipulate datastreams in the
* repository.
*/
require_once 'MagicProperty.php';
require_once 'FedoraDate.php';
/**
* This abstract class can be overriden by anything implementing a datastream.
*/
abstract class AbstractDatastream extends MagicProperty {
/**
* This will set the state of the datastream to deleted.
*/
abstract public function delete();
/**
* Set the contents of the datastream from a file.
*
* @param string $file
* The full path of the file to set to the contents of the datastream.
*/
abstract public function setContentFromFile($file);
/**
* Set the contents of the datastream from a URL. The contents of this
* URL will be fetched, and the datastream will be updated to contain the
* contents of the URL.
*
* @param string $url
* The full URL to fetch.
*/
abstract public function setContentFromUrl($url);
/**
* Set the contents of the datastream from a string.
*
* @param string $string
* The string whose contents will become the contents of the datastream.
*/
abstract public function setContentFromString($string);
/**
* Get the contents of a datastream and output it to the file provided.
*
* @param string $file
* The path of the file to output the contents of the datastream to.
*
* @return
* TRUE on success or FALSE on failure.
*/
abstract public function getContent($file);
/**
* The identifier of the datastream. This is a read-only property.
*
* @var string
*/
public $id;
/**
* The label of the datastream. Fedora limits the label to be 255 characters.
* Anything after this amount is truncated.
*
* @var string
*/
public $label;
/**
* the location of consists of a combination of
* datastream id and datastream version id
* @var type
*/
public $location;
/**
* The control group of the datastream. This property is read-only. This will
* return one of: "X", "M", "R", or "E" (Inline *X*ML, *M*anaged Content,
* *R*edirect, or *E*xternal Referenced). Defaults to "M".
* @var string
*/
public $controlGroup;
/**
* This defines if the datastream will be versioned or not.
* @var boolean
*/
public $versionable;
/**
* The state of the datastream. This will be one of: "A", "I", "D". When
* setting the property you can use: A, I, D or Active, Inactive, Deleted.
* @var string
*/
public $state;
/**
* The mimetype of the datastrem.
* @var string
*/
public $mimetype;
/**
* The format of the datastream.
* @var string
*/
public $format;
/**
* The size in bytes of the datastream. This is only valid once a datastream
* has been ingested.
*
* @var int
*/
public $size;
/**
* The base64 encoded checksum string.
*
* @var string
*/
public $checksum;
/**
* The type of checksum that will be done on this datastream. Defaults to
* DISABLED. One of: DISABLED, MD5, SHA-1, SHA-256, SHA-384, SHA-512.
*
* @var string
*/
public $checksumType;
/**
* The date the datastream was created.
*
* @var FedoraDate
*/
public $createdDate;
/**
* The contents of the datastream as a string. This can only be set for
* M and X datastreams. For R and E datastreams the URL property needs to be
* set which will change the contents of this property. This should only be
* used for small files, as it loads the contents into PHP memory. Otherwise
* you should use the getContent function.
*
* @var string
*/
public $content;
/**
* This is only valid for R and E datastreams. This is the URL that the
* datastream references.
*
* @var string
*/
public $url;
/**
* This is the log message that will be associated with the action in the
* Fedora audit datastream.
*
* @var string
*/
public $logMessage;
/**
* Unsets public members.
*
* We only define the public members of the object for Doxygen, they aren't actually accessed or used,
* and if they are not unset, they can cause problems after unserialization.
*/
public function __construct() {
$this->unset_members();
}
/**
* Upon unserialization unset any public members.
*/
public function __wakeup() {
$this->unset_members();
}
/**
* Unsets public members, required for child classes to funciton properly with MagicProperties.
*/
private function unset_members() {
unset($this->id);
unset($this->label);
unset($this->controlGroup);
unset($this->versionable);
unset($this->state);
unset($this->mimetype);
unset($this->format);
unset($this->size);
unset($this->checksum);
unset($this->checksumType);
unset($this->createdDate);
unset($this->content);
unset($this->url);
unset($this->location);
unset($this->logMessage);
}
}
/**
* Abstract base class implementing a datastream in Fedora.
*/
abstract class AbstractFedoraDatastream extends AbstractDatastream {
/**
* The repository this object belongs to.
* @var FedoraRepository
*/
public $repository;
/**
* The fedora object this datastream belongs to.
* @var AbstractFedoraObject
*/
public $parent;
/**
* An object for manipulating the fedora relationships related to this DS.
* @var FedoraRelsInt
*/
public $relationships;
/**
* The read only ID of the datastream.
*
* @var string
*/
protected $datastreamId = NULL;
/**
* The array defining what is in the datastream.
*
* @var array
* @see FedoraApiM::getDatastream
*/
protected $datastreamInfo = NULL;
protected $fedoraRelsIntClass = 'FedoraRelsInt';
protected $fedoraDatastreamVersionClass = 'FedoraDatastreamVersion';
/**
* The constructor for the datastream.
*
* @param string $id
* The identifier of the datastream.
*/
public function __construct($id, AbstractFedoraObject $object, FedoraRepository $repository) {
parent::__construct();
$this->datastreamId = $id;
$this->parent = $object;
$this->repository = $repository;
$this->relationships = new $this->fedoraRelsIntClass($this);
}
/**
* @see AbstractDatastream::id
*/
protected function idMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamId;
break;
case 'isset':
return TRUE;
break;
case 'set':
case 'unset':
trigger_error("Cannot $function the readonly datastream->id property.", E_USER_WARNING);
break;
}
}
/**
* @see AbstractDatastream::delete()
*/
public function delete() {
$this->state = 'd';
}
/**
* This is a replacement for isset when things can't be unset. So we define
* a default value, then return TRUE or FALSE based on if it is set.
*
* @param anything $actual
* The value we are testing.
* @param anything $unsetval
* The value it would be if it was unset.
*
* @return boolean
* TRUE or FALSE
*/
protected function isDatastreamProperySet($actual, $unsetval) {
if ($actual === $unsetval) {
return FALSE;
}
else {
return TRUE;
}
}
/**
* Validates a mimetype using a regular expression.
*
* @param string $mime
* A string representing a mimetype
*
* @return boolean
* TRUE if the string looks like a mimetype.
*
* @todo test if this covers all cases.
*/
protected function validateMimetype($mime) {
if (preg_match('#^[-\w]+/[-\w\.+]+$#', $mime)) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Validates and normalizes the datastream state.
*
* @param string $state
* The input state
*
* @return string
* Returns FALSE if validation fails, otherwise it returns the normalized
* datastream state.
*/
protected function validateState($state) {
switch (strtolower($state)) {
case 'd':
case 'deleted':
return 'D';
break;
case 'a':
case 'active':
return 'A';
break;
case 'i':
case 'inactive':
return 'I';
break;
default:
return FALSE;
break;
}
}
/**
* Validates the versionable setting of a datastream.
*
* @param mixed $versionable
* The input versionable arguement.
*
* @return boolean
* Returns TRUE if the arguement is a boolean, FALSE otherwise.
*/
protected function validateVersionable($versionable) {
return is_bool($versionable);
}
/**
* Validates and normalizes the checksumType arguement.
*
* @param string $type
* The input string
*
* @return mixed
* FALSE if validation fails. The checksumType string otherwise.
*/
protected function validateChecksumType($type) {
switch ($type) {
case 'DEFAULT':
case 'DISABLED':
case 'MD5':
case 'SHA-1':
case 'SHA-256':
case 'SHA-384':
case 'SHA-512':
return $type;
break;
default:
return FALSE;
break;
}
}
/**
* @see AbstractDatastream::controlGroup
*/
protected function controlGroupMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsControlGroup'];
break;
case 'isset':
return TRUE;
break;
case 'set':
case 'unset':
trigger_error("Cannot $function the readonly datastream->controlGroup property.", E_USER_WARNING);
break;
}
}
}
/**
* This defines a new fedora datastream. This is the class used to contain the
* inforamtion for a new fedora datastream before it is ingested.
*/
class NewFedoraDatastream extends AbstractFedoraDatastream {
/**
* Used to determine if we should delete the contents of this datastream when
* this class is destoryed.
*
* @var boolean
*/
protected $copied = FALSE;
/**
* The constructor for a new fedora datastream.
*
* @param string $id
* The unique identifier of the DS.
* @param FedoraObject $object
* The FedoraObject that this DS belongs to.
* @param FedoraRepository $repository
* The FedoraRepository that this DS belongs to.
* @param string $control_group
* The control group this DS will belong to.
*
* @todo test for valid identifiers. it can't start with a number etc.
*/
public function __construct($id, $control_group, AbstractFedoraObject $object, FedoraRepository $repository) {
parent::__construct($id, $object, $repository);
$group = $this->validateControlGroup($control_group);
if ($group === FALSE) {
trigger_error("Invalid control group \"$control_group\", using managed instead.", E_USER_WARNING);
$group = 'M';
}
// Set defaults!
$this->datastreamInfo['dsControlGroup'] = $group;
$this->datastreamInfo['dsState'] = 'A';
$this->datastreamInfo['dsLabel'] = '';
$this->datastreamInfo['dsVersionable'] = TRUE;
$this->datastreamInfo['dsMIME'] = 'text/xml';
$this->datastreamInfo['dsFormatURI'] = '';
$this->datastreamInfo['dsChecksumType'] = 'DISABLED';
$this->datastreamInfo['dsChecksum'] = 'none';
$this->datastreamInfo['dsLogMessage'] = '';
$this->datastreamInfo['content'] = array('type' => 'string', 'content' => ' ');
}
/**
* Validates and normalizes the control group.
*
* @param string $value
* The passed in control group.
*
* @return mixed
* The stirng for hte controlgroup or FALSE if validation fails.
*/
protected function validateControlGroup($value) {
switch (strtolower($value)) {
case 'x':
case 'inline':
case 'inline xml':
return 'X';
break;
case 'm':
case 'managed':
case 'managed content':
return 'M';
break;
case 'r':
case 'redirect':
return 'R';
break;
case 'e':
case 'external':
case 'external referenced':
return 'E';
break;
default:
return FALSE;
break;
}
}
/**
* Validates and normalizes the contentType.
*
* @param string $type
* The passed in value for type.
*
* @return mixed
* The stirng for the type or FALSE if validation fails.
*/
protected function validateType($type) {
switch (strtolower($type)) {
case 'string':
return 'string';
break;
case 'url':
return 'url';
break;
case 'file':
return 'file';
break;
default:
return FALSE;
break;
}
}
/**
* @see AbstractDatastream::controlGroup
*/
protected function controlGroupMagicProperty($function, $value) {
return parent::controlGroupMagicProperty($function, $value);
}
/**
* @see AbstractDatastream::state
*/
protected function stateMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsState'];
break;
case 'isset':
return TRUE;
break;
case 'set':
$state = $this->validateState($value);
if ($state !== FALSE) {
$this->datastreamInfo['dsState'] = $state;
}
else {
trigger_error("$value is not a valid value for the datastream->state property.", E_USER_WARNING);
}
break;
case 'unset':
trigger_error("Cannot unset the required datastream->state property.", E_USER_WARNING);
break;
}
}
/**
* @see AbstractDatastream::label
*/
protected function labelMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsLabel'];
break;
case 'isset':
return $this->isDatastreamProperySet($this->datastreamInfo['dsLabel'], '');
break;
case 'set':
$this->datastreamInfo['dsLabel'] = function_exists('mb_substr') ? mb_substr($value, 0, 255) : substr($value, 0, 255);
break;
case 'unset':
$this->datastreamInfo['dsLabel'] = '';
break;
}
}
/**
* @see AbstractDatastream::versionable
*/
protected function versionableMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsVersionable'];
break;
case 'isset':
return TRUE;
break;
case 'set':
if ($this->validateVersionable($value)) {
$this->datastreamInfo['dsVersionable'] = $value;
}
else {
trigger_error("Datastream->versionable must be a boolean.", E_USER_WARNING);
}
break;
case 'unset':
trigger_error("Cannot unset the required datastream->versionable property.", E_USER_WARNING);
break;
}
}
/**
* @see AbstractDatastream::mimetype
*/
protected function mimetypeMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsMIME'];
break;
case 'isset':
return TRUE;
break;
case 'set':
if ($this->validateMimetype($value)) {
$this->datastreamInfo['dsMIME'] = $value;
}
else {
trigger_error("Invalid mimetype.", E_USER_WARNING);
}
break;
case 'unset':
trigger_error("Cannot unset the required datastream->mimetype property.", E_USER_WARNING);
break;
}
}
/**
* @see AbstractDatastream::format
*/
protected function formatMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsFormatURI'];
break;
case 'isset':
return $this->isDatastreamProperySet($this->datastreamInfo['dsFormatURI'], '');
break;
case 'set':
$this->datastreamInfo['dsFormatURI'] = $value;
break;
case 'unset':
$this->datastreamInfo['dsFormatURI'] = '';
break;
}
}
/**
* @see AbstractDatastream::checksum
* @todo this should be refined a bit
*/
protected function checksumMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsChecksum'];
break;
case 'isset':
return $this->isDatastreamProperySet($this->datastreamInfo['dsChecksum'], 'none');
break;
case 'set':
$this->datastreamInfo['dsChecksum'] = $value;
case 'unset':
$this->datastreamInfo['dsChecksum'] = 'none';
break;
}
}
/**
* @see AbstractDatastream::checksumType
*/
protected function checksumTypeMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsChecksumType'];
break;
case 'isset':
return $this->isDatastreamProperySet($this->datastreamInfo['dsChecksumType'], 'DISABLED');
break;
case 'set':
$type = $this->validateChecksumType($value);
if ($type !== FALSE) {
$this->datastreamInfo['dsChecksumType'] = $type;
}
else {
trigger_error("$value is not a valid value for the datastream->checksumType property.", E_USER_WARNING);
}
break;
case 'unset':
$this->datastreamInfo['dsChecksumType'] = 'DISABLED';
break;
}
}
/**
* @see AbstractDatastream::content
*/
protected function contentMagicProperty($function, $value) {
switch ($function) {
case 'get':
switch ($this->datastreamInfo['content']['type']) {
case 'string':
case 'url':
return $this->datastreamInfo['content']['content'];
case 'file':
return file_get_contents($this->datastreamInfo['content']['content']);
}
break;
case 'isset':
return $this->isDatastreamProperySet($this->datastreamInfo['content']['content'], ' ');
break;
case 'set':
if ($this->controlGroup == 'M' || $this->controlGroup == 'X') {
$this->deleteTempFile();
$this->datastreamInfo['content']['type'] = 'string';
$this->datastreamInfo['content']['content'] = $value;
}
else {
trigger_error("Cannot set content of a {$this->controlGroup} datastream, please use datastream->url.", E_USER_WARNING);
}
break;
case 'unset':
if ($this->controlGroup == 'M' || $this->controlGroup == 'X') {
$this->datastreamInfo['content']['type'] = 'string';
$this->datastreamInfo['content']['content'] = ' ';
}
else {
trigger_error("Cannot unset content of a {$this->controlGroup} datastream, please use datastream->url.", E_USER_WARNING);
}
break;
}
}
/**
* @see AbstractDatastream::url
*/
protected function urlMagicProperty($function, $value) {
switch ($function) {
case 'get':
if ($this->controlGroup == 'E' || $this->controlGroup == 'R') {
return $this->datastreamInfo['content']['content'];
}
else {
trigger_error("Datastream->url property is undefined for a {$this->controlGroup} datastream.", E_USER_WARNING);
return NULL;
}
break;
case 'isset':
if ($this->controlGroup == 'E' || $this->controlGroup == 'R') {
return TRUE;
}
else {
return FALSE;
}
break;
case 'set':
if ($this->controlGroup == 'E' || $this->controlGroup == 'R') {
$this->datastreamInfo['content']['type'] = 'url';
$this->datastreamInfo['content']['content'] = $value;
}
else {
trigger_error("Cannot set url of a {$this->controlGroup} datastream, please use datastream->content.", E_USER_WARNING);
}
break;
case 'unset':
trigger_error("Cannot unset the required datastream->url property.", E_USER_WARNING);
break;
}
}
/**
* @see AbstractDatastream::logMessage
*/
protected function logMessageMagicProperty($function, $value) {
switch ($function) {
case 'get':
return $this->datastreamInfo['dsLogMessage'];
break;
case 'isset':
return $this->isDatastreamProperySet($this->datastreamInfo['dsLogMessage'], '');
break;
case 'set':
$this->datastreamInfo['dsLogMessage'] = $value;
break;
case 'unset':
$this->datastreamInfo['dsLogMessage'] = '';
break;
}
}
/**
* @see AbstractDatastream::setContentFromFile
*
* @param boolean $copy
* If TRUE this object will copy and manage the given file, if FALSE the management of the files is up to the caller.
*/
public function setContentFromFile($file, $copy = TRUE) {
if ($this->controlGroup == 'E' || $this->controlGroup == 'R') {
trigger_error("Function cannot be called on a {$this->controlGroup} datastream. Please use datastream->url.", E_USER_WARNING);
return;
}
$this->deleteTempFile();
$this->copied = $copy;
if ($copy) {
$tmpfile = tempnam(sys_get_temp_dir(), 'tuque');
copy($file, $tmpfile);
$file = $tmpfile;
}
$this->datastreamInfo['content']['type'] = 'file';
$this->datastreamInfo['content']['content'] = $file;
}
/**
* @see AbstractDatastream::setContentFromUrl
*
* @param string $url
* Https (SSL) URL's will cause this to fail.
*/
public function setContentFromUrl($url) {
if ($this->controlGroup == 'E' || $this->controlGroup == 'R') {
trigger_error("Function cannot be called on a {$this->controlGroup} datastream. Please use datastream->url.", E_USER_WARNING);
return;
}
$this->deleteTempFile();
$this->datastreamInfo['content']['type'] = 'url';
$this->datastreamInfo['content']['content'] = $url;
}
/**
* @see AbstractDatastream::setContentFromString
*/
public function setContentFromString($string) {
if ($this->controlGroup == 'E' || $this->controlGroup == 'R') {
trigger_error("Function cannot be called on a {$this->controlGroup} datastream. Please use datastream->url.", E_USER_WARNING);
return;
}
$this->deleteTempFile();
$this->datastreamInfo['content']['type'] = 'string';
$this->datastreamInfo['content']['content'] = $string;
}
/**
* @see AbstractDatastream::getContent
*/
public function getContent($file) {
if ($this->controlGroup == 'E' || $this->controlGroup == 'R') {
trigger_error("Function cannot be called on a {$this->controlGroup} datastream. Please use datastream->url.", E_USER_WARNING);
return;
}
switch ($this->datastreamInfo['content']['type']) {
case 'file':
copy($this->datastreamInfo['content']['content'], $file);
return TRUE;
case 'string':
file_put_contents($file, $this->datastreamInfo['content']['content']);
return TRUE;
case 'url':
return FALSE;
}
}
public function __destruct() {
$this->deleteTempFile();
}
/**
* Deletes any temp files that may be present such that we do not 'leak'
* over any files.
*/
private function deleteTempFile() {
if ($this->datastreamInfo['content']['type'] == 'file' && $this->copied == TRUE) {
unlink($this->datastreamInfo['content']['content']);
}
}
}
/**
* This abstract class defines some shared functionality between all classes
* that implement exising fedora datastreams.
*/
abstract class AbstractExistingFedoraDatastream extends AbstractFedoraDatastream {
/**
* Class constructor.
*
* @param string $id
* Unique identifier for the DS.
* @param FedoraObject $object
* The FedoraObject that this DS belongs to.
* @param FedoraRepository $repository
* The FedoraRepository that this DS belongs to.
*/
public function __construct($id, FedoraObject $object, FedoraRepository $repository) {
parent::__construct($id, $object, $repository);
}
/**
* Wrapper for the APIA getDatastreamDissemination function.
*
* @param string $version
* The version of the content to retreve.
* @param string $file
* The file to put the content into.
*
* @return string
* String containing the content.
*/
protected function getDatastreamContent($version = NULL, $file = NULL) {
return $this->repository->api->a->getDatastreamDissemination($this->parent->id, $this->id, $version, $file);
}
/**
* Wrapper around the APIM getDatastreamHistory function.
*
* @return array
* Array containing datastream history.
*/
protected function getDatastreamHistory() {
return $this->repository->api->m->getDatastreamHistory($this->parent->id, $this->id);
}
/**
* Wrapper around the APIM modifyDatastream function.
*
* @param array $args
* Args to pass to the function.
*
* @return array
* Datastream history array.
*/
protected function modifyDatastream(array $args) {
return $this->repository->api->m->modifyDatastream($this->parent->id, $this->id, $args);
}
/**
* Wrapper around the APIM Purge function.
*
* @param string $version
* The version to purge.
*
* @return array
* The versions purged.
*/
protected function purgeDatastream($version) {
return $this->repository->api->m->purgeDatastream($this->parent->id, $this->id, array('startDT' => $version, 'endDT' => $version));
}
}
/**
* This class implements an old version of a fedora datastream. Its properties
* are the same of a normal fedora datastream, except since its an older verion
* everything is read only.
*/
class FedoraDatastreamVersion extends AbstractExistingFedoraDatastream {
/**
* The parent datastream.
* @var FedoraDatastream
*/
public $parent;
/**
* The Constructor! Sounds like a superhero doesn't it. Constructor away!
*/
public function __construct($id, array $datastream_info, FedoraDatastream $datastream, FedoraObject $object, FedoraRepository $repository) {
parent::__construct($id, $object, $repository);