ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
RevisionARRepository.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
12
19{
20
28 {
29 $new_version_number = $resource->getCurrentRevision()->getVersionNumber() + 1;
30 $revision = new UploadedFileRevision($resource->getIdentification(), $result);
31 $revision->setVersionNumber($new_version_number);
32
33 return $revision;
34 }
35
36
40 public function store(Revision $revision) : void
41 {
42 $ar = $this->getAR($revision);
43 $ar->setVersionNumber($revision->getVersionNumber());
44 $ar->setAvailable($revision->isAvailable());
45 $ar->update();
46 }
47
48
52 public function get(StorableResource $resource) : RevisionCollection
53 {
54 $collection = new RevisionCollection($resource->getIdentification());
55
56 foreach (ARRevision::where(['identification' => $resource->getIdentification()->serialize()])->get() as $ar_revision) {
57 $collection->add($this->getRevisionFromAR($ar_revision));
58 }
59
60 return $collection;
61 }
62
63
67 public function delete(Revision $revision) : void
68 {
69 $primary = $this->getInternalID($revision);
70 $ar = ARRevision::find($primary);
71 if ($ar instanceof ARRevision) {
72 $ar->delete();
73 }
74 }
75
76
82 private function getInternalID(Revision $revision) : string
83 {
84 return $revision->getIdentification()->serialize() . '_' . (string) $revision->getVersionNumber();
85 }
86
87
93 private function getAR(Revision $revision) : ARRevision
94 {
95 $primary = $this->getInternalID($revision);
96 $ar = ARRevision::find($primary);
97 if ($ar === null) {
98 $ar = new ARRevision();
99 $ar->setInternal($primary);
100 $ar->setIdentification($revision->getIdentification()->serialize());
101 $ar->create();
102 }
103
104 return $ar;
105 }
106
107
108 private function getRevisionFromAR(ARRevision $AR_revision) : Revision
109 {
110 $r = new FileRevision(new ResourceIdentification($AR_revision->getIdentification()));
111 $r->setVersionNumber($AR_revision->getVersionNumber());
112
113 return $r;
114 }
115}
$result
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
blank(StorableResource $resource, UploadResult $result)