@@ -28,56 +28,56 @@ |
||
28 | 28 | use OCP\Diagnostics\IEventLogger; |
29 | 29 | |
30 | 30 | class EventLogger implements IEventLogger { |
31 | - /** |
|
32 | - * @var \OC\Diagnostics\Event[] |
|
33 | - */ |
|
34 | - private $events = []; |
|
31 | + /** |
|
32 | + * @var \OC\Diagnostics\Event[] |
|
33 | + */ |
|
34 | + private $events = []; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var bool - Module needs to be activated by some app |
|
38 | - */ |
|
39 | - private $activated = false; |
|
36 | + /** |
|
37 | + * @var bool - Module needs to be activated by some app |
|
38 | + */ |
|
39 | + private $activated = false; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @inheritdoc |
|
43 | - */ |
|
44 | - public function start($id, $description) { |
|
45 | - if ($this->activated){ |
|
46 | - $this->events[$id] = new Event($id, $description, microtime(true)); |
|
47 | - } |
|
48 | - } |
|
41 | + /** |
|
42 | + * @inheritdoc |
|
43 | + */ |
|
44 | + public function start($id, $description) { |
|
45 | + if ($this->activated){ |
|
46 | + $this->events[$id] = new Event($id, $description, microtime(true)); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function end($id) { |
|
54 | - if ($this->activated && isset($this->events[$id])) { |
|
55 | - $timing = $this->events[$id]; |
|
56 | - $timing->end(microtime(true)); |
|
57 | - } |
|
58 | - } |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function end($id) { |
|
54 | + if ($this->activated && isset($this->events[$id])) { |
|
55 | + $timing = $this->events[$id]; |
|
56 | + $timing->end(microtime(true)); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @inheritdoc |
|
62 | - */ |
|
63 | - public function log($id, $description, $start, $end) { |
|
64 | - if ($this->activated) { |
|
65 | - $this->events[$id] = new Event($id, $description, $start); |
|
66 | - $this->events[$id]->end($end); |
|
67 | - } |
|
68 | - } |
|
60 | + /** |
|
61 | + * @inheritdoc |
|
62 | + */ |
|
63 | + public function log($id, $description, $start, $end) { |
|
64 | + if ($this->activated) { |
|
65 | + $this->events[$id] = new Event($id, $description, $start); |
|
66 | + $this->events[$id]->end($end); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @inheritdoc |
|
72 | - */ |
|
73 | - public function getEvents() { |
|
74 | - return $this->events; |
|
75 | - } |
|
70 | + /** |
|
71 | + * @inheritdoc |
|
72 | + */ |
|
73 | + public function getEvents() { |
|
74 | + return $this->events; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @inheritdoc |
|
79 | - */ |
|
80 | - public function activate() { |
|
81 | - $this->activated = true; |
|
82 | - } |
|
77 | + /** |
|
78 | + * @inheritdoc |
|
79 | + */ |
|
80 | + public function activate() { |
|
81 | + $this->activated = true; |
|
82 | + } |
|
83 | 83 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | * @inheritdoc |
43 | 43 | */ |
44 | 44 | public function start($id, $description) { |
45 | - if ($this->activated){ |
|
45 | + if ($this->activated) { |
|
46 | 46 | $this->events[$id] = new Event($id, $description, microtime(true)); |
47 | 47 | } |
48 | 48 | } |
@@ -26,65 +26,65 @@ |
||
26 | 26 | use OCP\Diagnostics\IQuery; |
27 | 27 | |
28 | 28 | class Query implements IQuery { |
29 | - private $sql; |
|
29 | + private $sql; |
|
30 | 30 | |
31 | - private $params; |
|
31 | + private $params; |
|
32 | 32 | |
33 | - private $start; |
|
33 | + private $start; |
|
34 | 34 | |
35 | - private $end; |
|
35 | + private $end; |
|
36 | 36 | |
37 | - private $stack; |
|
37 | + private $stack; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $sql |
|
41 | - * @param array $params |
|
42 | - * @param int $start |
|
43 | - */ |
|
44 | - public function __construct($sql, $params, $start, array $stack) { |
|
45 | - $this->sql = $sql; |
|
46 | - $this->params = $params; |
|
47 | - $this->start = $start; |
|
48 | - $this->stack = $stack; |
|
49 | - } |
|
39 | + /** |
|
40 | + * @param string $sql |
|
41 | + * @param array $params |
|
42 | + * @param int $start |
|
43 | + */ |
|
44 | + public function __construct($sql, $params, $start, array $stack) { |
|
45 | + $this->sql = $sql; |
|
46 | + $this->params = $params; |
|
47 | + $this->start = $start; |
|
48 | + $this->stack = $stack; |
|
49 | + } |
|
50 | 50 | |
51 | - public function end($time) { |
|
52 | - $this->end = $time; |
|
53 | - } |
|
51 | + public function end($time) { |
|
52 | + $this->end = $time; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getParams() { |
|
59 | - return $this->params; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getParams() { |
|
59 | + return $this->params; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getSql() { |
|
66 | - return $this->sql; |
|
67 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getSql() { |
|
66 | + return $this->sql; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return float |
|
71 | - */ |
|
72 | - public function getStart() { |
|
73 | - return $this->start; |
|
74 | - } |
|
69 | + /** |
|
70 | + * @return float |
|
71 | + */ |
|
72 | + public function getStart() { |
|
73 | + return $this->start; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return float |
|
78 | - */ |
|
79 | - public function getDuration() { |
|
80 | - return $this->end - $this->start; |
|
81 | - } |
|
76 | + /** |
|
77 | + * @return float |
|
78 | + */ |
|
79 | + public function getDuration() { |
|
80 | + return $this->end - $this->start; |
|
81 | + } |
|
82 | 82 | |
83 | - public function getStartTime() { |
|
84 | - return $this->start; |
|
85 | - } |
|
83 | + public function getStartTime() { |
|
84 | + return $this->start; |
|
85 | + } |
|
86 | 86 | |
87 | - public function getStacktrace() { |
|
88 | - return $this->stack; |
|
89 | - } |
|
87 | + public function getStacktrace() { |
|
88 | + return $this->stack; |
|
89 | + } |
|
90 | 90 | } |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | protected function attachListener($mount) { |
119 | 119 | $scanner = $mount->getStorage()->getScanner(); |
120 | 120 | $emitter = $this; |
121 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
122 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
121 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function($path) use ($mount, $emitter) { |
|
122 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint().$path)); |
|
123 | 123 | }); |
124 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
125 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
124 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function($path) use ($mount, $emitter) { |
|
125 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint().$path)); |
|
126 | 126 | }); |
127 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
128 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
127 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function($path) use ($mount, $emitter) { |
|
128 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint().$path)); |
|
129 | 129 | }); |
130 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
131 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
130 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function($path) use ($mount, $emitter) { |
|
131 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint().$path)); |
|
132 | 132 | }); |
133 | 133 | } |
134 | 134 | |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | $scanner = $storage->getScanner(); |
161 | 161 | $this->attachListener($mount); |
162 | 162 | |
163 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
163 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function($path) use ($storage) { |
|
164 | 164 | $this->triggerPropagator($storage, $path); |
165 | 165 | }); |
166 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
166 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function($path) use ($storage) { |
|
167 | 167 | $this->triggerPropagator($storage, $path); |
168 | 168 | }); |
169 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
169 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function($path) use ($storage) { |
|
170 | 170 | $this->triggerPropagator($storage, $path); |
171 | 171 | }); |
172 | 172 | |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | $scanner->setUseTransactions(false); |
220 | 220 | $this->attachListener($mount); |
221 | 221 | |
222 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
222 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function($path) use ($storage) { |
|
223 | 223 | $this->postProcessEntry($storage, $path); |
224 | 224 | }); |
225 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
225 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function($path) use ($storage) { |
|
226 | 226 | $this->postProcessEntry($storage, $path); |
227 | 227 | }); |
228 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
228 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function($path) use ($storage) { |
|
229 | 229 | $this->postProcessEntry($storage, $path); |
230 | 230 | }); |
231 | 231 | |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | } |
248 | 248 | $propagator->commitBatch(); |
249 | 249 | } catch (StorageNotAvailableException $e) { |
250 | - $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
250 | + $this->logger->error('Storage '.$storage->getId().' not available'); |
|
251 | 251 | $this->logger->logException($e); |
252 | 252 | $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
253 | 253 | } |
@@ -50,233 +50,233 @@ |
||
50 | 50 | * @package OC\Files\Utils |
51 | 51 | */ |
52 | 52 | class Scanner extends PublicEmitter { |
53 | - const MAX_ENTRIES_TO_COMMIT = 10000; |
|
53 | + const MAX_ENTRIES_TO_COMMIT = 10000; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string $user |
|
57 | - */ |
|
58 | - private $user; |
|
55 | + /** |
|
56 | + * @var string $user |
|
57 | + */ |
|
58 | + private $user; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var \OCP\IDBConnection |
|
62 | - */ |
|
63 | - protected $db; |
|
60 | + /** |
|
61 | + * @var \OCP\IDBConnection |
|
62 | + */ |
|
63 | + protected $db; |
|
64 | 64 | |
65 | - /** |
|
66 | - * @var ILogger |
|
67 | - */ |
|
68 | - protected $logger; |
|
65 | + /** |
|
66 | + * @var ILogger |
|
67 | + */ |
|
68 | + protected $logger; |
|
69 | 69 | |
70 | - /** |
|
71 | - * Whether to use a DB transaction |
|
72 | - * |
|
73 | - * @var bool |
|
74 | - */ |
|
75 | - protected $useTransaction; |
|
70 | + /** |
|
71 | + * Whether to use a DB transaction |
|
72 | + * |
|
73 | + * @var bool |
|
74 | + */ |
|
75 | + protected $useTransaction; |
|
76 | 76 | |
77 | - /** |
|
78 | - * Number of entries scanned to commit |
|
79 | - * |
|
80 | - * @var int |
|
81 | - */ |
|
82 | - protected $entriesToCommit; |
|
77 | + /** |
|
78 | + * Number of entries scanned to commit |
|
79 | + * |
|
80 | + * @var int |
|
81 | + */ |
|
82 | + protected $entriesToCommit; |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param string $user |
|
86 | - * @param \OCP\IDBConnection $db |
|
87 | - * @param ILogger $logger |
|
88 | - */ |
|
89 | - public function __construct($user, $db, ILogger $logger) { |
|
90 | - $this->logger = $logger; |
|
91 | - $this->user = $user; |
|
92 | - $this->db = $db; |
|
93 | - // when DB locking is used, no DB transactions will be used |
|
94 | - $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); |
|
95 | - } |
|
84 | + /** |
|
85 | + * @param string $user |
|
86 | + * @param \OCP\IDBConnection $db |
|
87 | + * @param ILogger $logger |
|
88 | + */ |
|
89 | + public function __construct($user, $db, ILogger $logger) { |
|
90 | + $this->logger = $logger; |
|
91 | + $this->user = $user; |
|
92 | + $this->db = $db; |
|
93 | + // when DB locking is used, no DB transactions will be used |
|
94 | + $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * get all storages for $dir |
|
99 | - * |
|
100 | - * @param string $dir |
|
101 | - * @return \OC\Files\Mount\MountPoint[] |
|
102 | - */ |
|
103 | - protected function getMounts($dir) { |
|
104 | - //TODO: move to the node based fileapi once that's done |
|
105 | - \OC_Util::tearDownFS(); |
|
106 | - \OC_Util::setupFS($this->user); |
|
97 | + /** |
|
98 | + * get all storages for $dir |
|
99 | + * |
|
100 | + * @param string $dir |
|
101 | + * @return \OC\Files\Mount\MountPoint[] |
|
102 | + */ |
|
103 | + protected function getMounts($dir) { |
|
104 | + //TODO: move to the node based fileapi once that's done |
|
105 | + \OC_Util::tearDownFS(); |
|
106 | + \OC_Util::setupFS($this->user); |
|
107 | 107 | |
108 | - $mountManager = Filesystem::getMountManager(); |
|
109 | - $mounts = $mountManager->findIn($dir); |
|
110 | - $mounts[] = $mountManager->find($dir); |
|
111 | - $mounts = array_reverse($mounts); //start with the mount of $dir |
|
108 | + $mountManager = Filesystem::getMountManager(); |
|
109 | + $mounts = $mountManager->findIn($dir); |
|
110 | + $mounts[] = $mountManager->find($dir); |
|
111 | + $mounts = array_reverse($mounts); //start with the mount of $dir |
|
112 | 112 | |
113 | - return $mounts; |
|
114 | - } |
|
113 | + return $mounts; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * attach listeners to the scanner |
|
118 | - * |
|
119 | - * @param \OC\Files\Mount\MountPoint $mount |
|
120 | - */ |
|
121 | - protected function attachListener($mount) { |
|
122 | - $scanner = $mount->getStorage()->getScanner(); |
|
123 | - $emitter = $this; |
|
124 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
125 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
126 | - }); |
|
127 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
128 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
129 | - }); |
|
130 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
131 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
132 | - }); |
|
133 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
134 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
135 | - }); |
|
136 | - } |
|
116 | + /** |
|
117 | + * attach listeners to the scanner |
|
118 | + * |
|
119 | + * @param \OC\Files\Mount\MountPoint $mount |
|
120 | + */ |
|
121 | + protected function attachListener($mount) { |
|
122 | + $scanner = $mount->getStorage()->getScanner(); |
|
123 | + $emitter = $this; |
|
124 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
125 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
126 | + }); |
|
127 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
128 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
129 | + }); |
|
130 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
131 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
132 | + }); |
|
133 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
134 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
135 | + }); |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * @param string $dir |
|
140 | - */ |
|
141 | - public function backgroundScan($dir) { |
|
142 | - $mounts = $this->getMounts($dir); |
|
143 | - foreach ($mounts as $mount) { |
|
144 | - $storage = $mount->getStorage(); |
|
145 | - if (is_null($storage)) { |
|
146 | - continue; |
|
147 | - } |
|
138 | + /** |
|
139 | + * @param string $dir |
|
140 | + */ |
|
141 | + public function backgroundScan($dir) { |
|
142 | + $mounts = $this->getMounts($dir); |
|
143 | + foreach ($mounts as $mount) { |
|
144 | + $storage = $mount->getStorage(); |
|
145 | + if (is_null($storage)) { |
|
146 | + continue; |
|
147 | + } |
|
148 | 148 | |
149 | - // don't bother scanning failed storages (shortcut for same result) |
|
150 | - if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
151 | - continue; |
|
152 | - } |
|
149 | + // don't bother scanning failed storages (shortcut for same result) |
|
150 | + if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
151 | + continue; |
|
152 | + } |
|
153 | 153 | |
154 | - // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
155 | - if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
156 | - continue; |
|
157 | - } |
|
158 | - $scanner = $storage->getScanner(); |
|
159 | - $this->attachListener($mount); |
|
154 | + // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
155 | + if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
156 | + continue; |
|
157 | + } |
|
158 | + $scanner = $storage->getScanner(); |
|
159 | + $this->attachListener($mount); |
|
160 | 160 | |
161 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
162 | - $this->triggerPropagator($storage, $path); |
|
163 | - }); |
|
164 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
165 | - $this->triggerPropagator($storage, $path); |
|
166 | - }); |
|
167 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
168 | - $this->triggerPropagator($storage, $path); |
|
169 | - }); |
|
161 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
162 | + $this->triggerPropagator($storage, $path); |
|
163 | + }); |
|
164 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
165 | + $this->triggerPropagator($storage, $path); |
|
166 | + }); |
|
167 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
168 | + $this->triggerPropagator($storage, $path); |
|
169 | + }); |
|
170 | 170 | |
171 | - $propagator = $storage->getPropagator(); |
|
172 | - $propagator->beginBatch(); |
|
173 | - $scanner->backgroundScan(); |
|
174 | - $propagator->commitBatch(); |
|
175 | - } |
|
176 | - } |
|
171 | + $propagator = $storage->getPropagator(); |
|
172 | + $propagator->beginBatch(); |
|
173 | + $scanner->backgroundScan(); |
|
174 | + $propagator->commitBatch(); |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @param string $dir |
|
180 | - * @param $recursive |
|
181 | - * @param callable|null $mountFilter |
|
182 | - * @throws ForbiddenException |
|
183 | - * @throws NotFoundException |
|
184 | - */ |
|
185 | - public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE, callable $mountFilter = null) { |
|
186 | - if (!Filesystem::isValidPath($dir)) { |
|
187 | - throw new \InvalidArgumentException('Invalid path to scan'); |
|
188 | - } |
|
189 | - $mounts = $this->getMounts($dir); |
|
190 | - foreach ($mounts as $mount) { |
|
191 | - if ($mountFilter && !$mountFilter($mount)) { |
|
192 | - continue; |
|
193 | - } |
|
194 | - $storage = $mount->getStorage(); |
|
195 | - if (is_null($storage)) { |
|
196 | - continue; |
|
197 | - } |
|
178 | + /** |
|
179 | + * @param string $dir |
|
180 | + * @param $recursive |
|
181 | + * @param callable|null $mountFilter |
|
182 | + * @throws ForbiddenException |
|
183 | + * @throws NotFoundException |
|
184 | + */ |
|
185 | + public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE, callable $mountFilter = null) { |
|
186 | + if (!Filesystem::isValidPath($dir)) { |
|
187 | + throw new \InvalidArgumentException('Invalid path to scan'); |
|
188 | + } |
|
189 | + $mounts = $this->getMounts($dir); |
|
190 | + foreach ($mounts as $mount) { |
|
191 | + if ($mountFilter && !$mountFilter($mount)) { |
|
192 | + continue; |
|
193 | + } |
|
194 | + $storage = $mount->getStorage(); |
|
195 | + if (is_null($storage)) { |
|
196 | + continue; |
|
197 | + } |
|
198 | 198 | |
199 | - // don't bother scanning failed storages (shortcut for same result) |
|
200 | - if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
201 | - continue; |
|
202 | - } |
|
199 | + // don't bother scanning failed storages (shortcut for same result) |
|
200 | + if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
201 | + continue; |
|
202 | + } |
|
203 | 203 | |
204 | - // if the home storage isn't writable then the scanner is run as the wrong user |
|
205 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
206 | - (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
207 | - ) { |
|
208 | - if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
209 | - throw new ForbiddenException(); |
|
210 | - } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
211 | - break; |
|
212 | - } |
|
204 | + // if the home storage isn't writable then the scanner is run as the wrong user |
|
205 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
206 | + (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
207 | + ) { |
|
208 | + if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
209 | + throw new ForbiddenException(); |
|
210 | + } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
211 | + break; |
|
212 | + } |
|
213 | 213 | |
214 | - } |
|
214 | + } |
|
215 | 215 | |
216 | - // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
217 | - if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
218 | - continue; |
|
219 | - } |
|
220 | - $relativePath = $mount->getInternalPath($dir); |
|
221 | - $scanner = $storage->getScanner(); |
|
222 | - $scanner->setUseTransactions(false); |
|
223 | - $this->attachListener($mount); |
|
216 | + // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
217 | + if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
218 | + continue; |
|
219 | + } |
|
220 | + $relativePath = $mount->getInternalPath($dir); |
|
221 | + $scanner = $storage->getScanner(); |
|
222 | + $scanner->setUseTransactions(false); |
|
223 | + $this->attachListener($mount); |
|
224 | 224 | |
225 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
226 | - $this->postProcessEntry($storage, $path); |
|
227 | - }); |
|
228 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
229 | - $this->postProcessEntry($storage, $path); |
|
230 | - }); |
|
231 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
232 | - $this->postProcessEntry($storage, $path); |
|
233 | - }); |
|
225 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
226 | + $this->postProcessEntry($storage, $path); |
|
227 | + }); |
|
228 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
229 | + $this->postProcessEntry($storage, $path); |
|
230 | + }); |
|
231 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
232 | + $this->postProcessEntry($storage, $path); |
|
233 | + }); |
|
234 | 234 | |
235 | - if (!$storage->file_exists($relativePath)) { |
|
236 | - throw new NotFoundException($dir); |
|
237 | - } |
|
235 | + if (!$storage->file_exists($relativePath)) { |
|
236 | + throw new NotFoundException($dir); |
|
237 | + } |
|
238 | 238 | |
239 | - if ($this->useTransaction) { |
|
240 | - $this->db->beginTransaction(); |
|
241 | - } |
|
242 | - try { |
|
243 | - $propagator = $storage->getPropagator(); |
|
244 | - $propagator->beginBatch(); |
|
245 | - $scanner->scan($relativePath, $recursive, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
246 | - $cache = $storage->getCache(); |
|
247 | - if ($cache instanceof Cache) { |
|
248 | - // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
249 | - $cache->correctFolderSize($relativePath); |
|
250 | - } |
|
251 | - $propagator->commitBatch(); |
|
252 | - } catch (StorageNotAvailableException $e) { |
|
253 | - $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
254 | - $this->logger->logException($e); |
|
255 | - $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
256 | - } |
|
257 | - if ($this->useTransaction) { |
|
258 | - $this->db->commit(); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
239 | + if ($this->useTransaction) { |
|
240 | + $this->db->beginTransaction(); |
|
241 | + } |
|
242 | + try { |
|
243 | + $propagator = $storage->getPropagator(); |
|
244 | + $propagator->beginBatch(); |
|
245 | + $scanner->scan($relativePath, $recursive, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
246 | + $cache = $storage->getCache(); |
|
247 | + if ($cache instanceof Cache) { |
|
248 | + // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
249 | + $cache->correctFolderSize($relativePath); |
|
250 | + } |
|
251 | + $propagator->commitBatch(); |
|
252 | + } catch (StorageNotAvailableException $e) { |
|
253 | + $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
254 | + $this->logger->logException($e); |
|
255 | + $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
256 | + } |
|
257 | + if ($this->useTransaction) { |
|
258 | + $this->db->commit(); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | - private function triggerPropagator(IStorage $storage, $internalPath) { |
|
264 | - $storage->getPropagator()->propagateChange($internalPath, time()); |
|
265 | - } |
|
263 | + private function triggerPropagator(IStorage $storage, $internalPath) { |
|
264 | + $storage->getPropagator()->propagateChange($internalPath, time()); |
|
265 | + } |
|
266 | 266 | |
267 | - private function postProcessEntry(IStorage $storage, $internalPath) { |
|
268 | - $this->triggerPropagator($storage, $internalPath); |
|
269 | - if ($this->useTransaction) { |
|
270 | - $this->entriesToCommit++; |
|
271 | - if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) { |
|
272 | - $propagator = $storage->getPropagator(); |
|
273 | - $this->entriesToCommit = 0; |
|
274 | - $this->db->commit(); |
|
275 | - $propagator->commitBatch(); |
|
276 | - $this->db->beginTransaction(); |
|
277 | - $propagator->beginBatch(); |
|
278 | - } |
|
279 | - } |
|
280 | - } |
|
267 | + private function postProcessEntry(IStorage $storage, $internalPath) { |
|
268 | + $this->triggerPropagator($storage, $internalPath); |
|
269 | + if ($this->useTransaction) { |
|
270 | + $this->entriesToCommit++; |
|
271 | + if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) { |
|
272 | + $propagator = $storage->getPropagator(); |
|
273 | + $this->entriesToCommit = 0; |
|
274 | + $this->db->commit(); |
|
275 | + $propagator->commitBatch(); |
|
276 | + $this->db->beginTransaction(); |
|
277 | + $propagator->beginBatch(); |
|
278 | + } |
|
279 | + } |
|
280 | + } |
|
281 | 281 | } |
282 | 282 |
@@ -24,7 +24,7 @@ |
||
24 | 24 | use OC\Files\Mount\MountPoint; |
25 | 25 | |
26 | 26 | class ExternalMountPoint extends MountPoint { |
27 | - public function getMountType() { |
|
28 | - return 'external'; |
|
29 | - } |
|
27 | + public function getMountType() { |
|
28 | + return 'external'; |
|
29 | + } |
|
30 | 30 | } |
@@ -23,24 +23,24 @@ |
||
23 | 23 | |
24 | 24 | class SocialSharingBundle extends Bundle { |
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return (string)$this->l10n->t('Social sharing bundle'); |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return (string)$this->l10n->t('Social sharing bundle'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - */ |
|
36 | - public function getAppIdentifiers() { |
|
37 | - return [ |
|
38 | - 'socialsharing_twitter', |
|
39 | - 'socialsharing_googleplus', |
|
40 | - 'socialsharing_facebook', |
|
41 | - 'socialsharing_email', |
|
42 | - 'socialsharing_diaspora', |
|
43 | - ]; |
|
44 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + */ |
|
36 | + public function getAppIdentifiers() { |
|
37 | + return [ |
|
38 | + 'socialsharing_twitter', |
|
39 | + 'socialsharing_googleplus', |
|
40 | + 'socialsharing_facebook', |
|
41 | + 'socialsharing_email', |
|
42 | + 'socialsharing_diaspora', |
|
43 | + ]; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * {@inheritDoc} |
28 | 28 | */ |
29 | 29 | public function getName() { |
30 | - return (string)$this->l10n->t('Social sharing bundle'); |
|
30 | + return (string) $this->l10n->t('Social sharing bundle'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -29,103 +29,103 @@ |
||
29 | 29 | */ |
30 | 30 | interface IMountPoint { |
31 | 31 | |
32 | - /** |
|
33 | - * get complete path to the mount point |
|
34 | - * |
|
35 | - * @return string |
|
36 | - * @since 8.0.0 |
|
37 | - */ |
|
38 | - public function getMountPoint(); |
|
32 | + /** |
|
33 | + * get complete path to the mount point |
|
34 | + * |
|
35 | + * @return string |
|
36 | + * @since 8.0.0 |
|
37 | + */ |
|
38 | + public function getMountPoint(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * Set the mountpoint |
|
42 | - * |
|
43 | - * @param string $mountPoint new mount point |
|
44 | - * @since 8.0.0 |
|
45 | - */ |
|
46 | - public function setMountPoint($mountPoint); |
|
40 | + /** |
|
41 | + * Set the mountpoint |
|
42 | + * |
|
43 | + * @param string $mountPoint new mount point |
|
44 | + * @since 8.0.0 |
|
45 | + */ |
|
46 | + public function setMountPoint($mountPoint); |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get the storage that is mounted |
|
50 | - * |
|
51 | - * @return \OC\Files\Storage\Storage |
|
52 | - * @since 8.0.0 |
|
53 | - */ |
|
54 | - public function getStorage(); |
|
48 | + /** |
|
49 | + * Get the storage that is mounted |
|
50 | + * |
|
51 | + * @return \OC\Files\Storage\Storage |
|
52 | + * @since 8.0.0 |
|
53 | + */ |
|
54 | + public function getStorage(); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get the id of the storages |
|
58 | - * |
|
59 | - * @return string |
|
60 | - * @since 8.0.0 |
|
61 | - */ |
|
62 | - public function getStorageId(); |
|
56 | + /** |
|
57 | + * Get the id of the storages |
|
58 | + * |
|
59 | + * @return string |
|
60 | + * @since 8.0.0 |
|
61 | + */ |
|
62 | + public function getStorageId(); |
|
63 | 63 | |
64 | - /** |
|
65 | - * Get the id of the storages |
|
66 | - * |
|
67 | - * @return int |
|
68 | - * @since 9.1.0 |
|
69 | - */ |
|
70 | - public function getNumericStorageId(); |
|
64 | + /** |
|
65 | + * Get the id of the storages |
|
66 | + * |
|
67 | + * @return int |
|
68 | + * @since 9.1.0 |
|
69 | + */ |
|
70 | + public function getNumericStorageId(); |
|
71 | 71 | |
72 | - /** |
|
73 | - * Get the path relative to the mountpoint |
|
74 | - * |
|
75 | - * @param string $path absolute path to a file or folder |
|
76 | - * @return string |
|
77 | - * @since 8.0.0 |
|
78 | - */ |
|
79 | - public function getInternalPath($path); |
|
72 | + /** |
|
73 | + * Get the path relative to the mountpoint |
|
74 | + * |
|
75 | + * @param string $path absolute path to a file or folder |
|
76 | + * @return string |
|
77 | + * @since 8.0.0 |
|
78 | + */ |
|
79 | + public function getInternalPath($path); |
|
80 | 80 | |
81 | - /** |
|
82 | - * Apply a storage wrapper to the mounted storage |
|
83 | - * |
|
84 | - * @param callable $wrapper |
|
85 | - * @since 8.0.0 |
|
86 | - */ |
|
87 | - public function wrapStorage($wrapper); |
|
81 | + /** |
|
82 | + * Apply a storage wrapper to the mounted storage |
|
83 | + * |
|
84 | + * @param callable $wrapper |
|
85 | + * @since 8.0.0 |
|
86 | + */ |
|
87 | + public function wrapStorage($wrapper); |
|
88 | 88 | |
89 | - /** |
|
90 | - * Get a mount option |
|
91 | - * |
|
92 | - * @param string $name Name of the mount option to get |
|
93 | - * @param mixed $default Default value for the mount option |
|
94 | - * @return mixed |
|
95 | - * @since 8.0.0 |
|
96 | - */ |
|
97 | - public function getOption($name, $default); |
|
89 | + /** |
|
90 | + * Get a mount option |
|
91 | + * |
|
92 | + * @param string $name Name of the mount option to get |
|
93 | + * @param mixed $default Default value for the mount option |
|
94 | + * @return mixed |
|
95 | + * @since 8.0.0 |
|
96 | + */ |
|
97 | + public function getOption($name, $default); |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get all options for the mount |
|
101 | - * |
|
102 | - * @return array |
|
103 | - * @since 8.1.0 |
|
104 | - */ |
|
105 | - public function getOptions(); |
|
99 | + /** |
|
100 | + * Get all options for the mount |
|
101 | + * |
|
102 | + * @return array |
|
103 | + * @since 8.1.0 |
|
104 | + */ |
|
105 | + public function getOptions(); |
|
106 | 106 | |
107 | - /** |
|
108 | - * Get the file id of the root of the storage |
|
109 | - * |
|
110 | - * @return int |
|
111 | - * @since 9.1.0 |
|
112 | - */ |
|
113 | - public function getStorageRootId(); |
|
107 | + /** |
|
108 | + * Get the file id of the root of the storage |
|
109 | + * |
|
110 | + * @return int |
|
111 | + * @since 9.1.0 |
|
112 | + */ |
|
113 | + public function getStorageRootId(); |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get the id of the configured mount |
|
117 | - * |
|
118 | - * @return int|null mount id or null if not applicable |
|
119 | - * @since 9.1.0 |
|
120 | - */ |
|
121 | - public function getMountId(); |
|
115 | + /** |
|
116 | + * Get the id of the configured mount |
|
117 | + * |
|
118 | + * @return int|null mount id or null if not applicable |
|
119 | + * @since 9.1.0 |
|
120 | + */ |
|
121 | + public function getMountId(); |
|
122 | 122 | |
123 | - /** |
|
124 | - * Get the type of mount point, used to distinguish things like shares and external storages |
|
125 | - * in the web interface |
|
126 | - * |
|
127 | - * @return string |
|
128 | - * @since 12.0.0 |
|
129 | - */ |
|
130 | - public function getMountType(); |
|
123 | + /** |
|
124 | + * Get the type of mount point, used to distinguish things like shares and external storages |
|
125 | + * in the web interface |
|
126 | + * |
|
127 | + * @return string |
|
128 | + * @since 12.0.0 |
|
129 | + */ |
|
130 | + public function getMountType(); |
|
131 | 131 | } |
@@ -132,7 +132,7 @@ |
||
132 | 132 | if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { |
133 | 133 | |
134 | 134 | // If the timestamp is older than 300 seconds request the files new |
135 | - if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
135 | + if ((int) $jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
136 | 136 | return $jsonBlob['data']; |
137 | 137 | } |
138 | 138 |
@@ -39,162 +39,162 @@ |
||
39 | 39 | use OCP\Util; |
40 | 40 | |
41 | 41 | abstract class Fetcher { |
42 | - const INVALIDATE_AFTER_SECONDS = 300; |
|
43 | - |
|
44 | - /** @var IAppData */ |
|
45 | - protected $appData; |
|
46 | - /** @var IClientService */ |
|
47 | - protected $clientService; |
|
48 | - /** @var ITimeFactory */ |
|
49 | - protected $timeFactory; |
|
50 | - /** @var IConfig */ |
|
51 | - protected $config; |
|
52 | - /** @var Ilogger */ |
|
53 | - protected $logger; |
|
54 | - /** @var string */ |
|
55 | - protected $fileName; |
|
56 | - /** @var string */ |
|
57 | - protected $endpointUrl; |
|
58 | - /** @var string */ |
|
59 | - protected $version; |
|
60 | - |
|
61 | - /** |
|
62 | - * @param Factory $appDataFactory |
|
63 | - * @param IClientService $clientService |
|
64 | - * @param ITimeFactory $timeFactory |
|
65 | - * @param IConfig $config |
|
66 | - * @param ILogger $logger |
|
67 | - */ |
|
68 | - public function __construct(Factory $appDataFactory, |
|
69 | - IClientService $clientService, |
|
70 | - ITimeFactory $timeFactory, |
|
71 | - IConfig $config, |
|
72 | - ILogger $logger) { |
|
73 | - $this->appData = $appDataFactory->get('appstore'); |
|
74 | - $this->clientService = $clientService; |
|
75 | - $this->timeFactory = $timeFactory; |
|
76 | - $this->config = $config; |
|
77 | - $this->logger = $logger; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Fetches the response from the server |
|
82 | - * |
|
83 | - * @param string $ETag |
|
84 | - * @param string $content |
|
85 | - * |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - protected function fetch($ETag, $content) { |
|
89 | - $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
90 | - |
|
91 | - if (!$appstoreenabled) { |
|
92 | - return []; |
|
93 | - } |
|
94 | - |
|
95 | - $options = [ |
|
96 | - 'timeout' => 10, |
|
97 | - ]; |
|
98 | - |
|
99 | - if ($ETag !== '') { |
|
100 | - $options['headers'] = [ |
|
101 | - 'If-None-Match' => $ETag, |
|
102 | - ]; |
|
103 | - } |
|
104 | - |
|
105 | - $client = $this->clientService->newClient(); |
|
106 | - $response = $client->get($this->endpointUrl, $options); |
|
107 | - |
|
108 | - $responseJson = []; |
|
109 | - if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) { |
|
110 | - $responseJson['data'] = json_decode($content, true); |
|
111 | - } else { |
|
112 | - $responseJson['data'] = json_decode($response->getBody(), true); |
|
113 | - $ETag = $response->getHeader('ETag'); |
|
114 | - } |
|
115 | - |
|
116 | - $responseJson['timestamp'] = $this->timeFactory->getTime(); |
|
117 | - $responseJson['ncversion'] = $this->getVersion(); |
|
118 | - if ($ETag !== '') { |
|
119 | - $responseJson['ETag'] = $ETag; |
|
120 | - } |
|
121 | - |
|
122 | - return $responseJson; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns the array with the categories on the appstore server |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function get() { |
|
131 | - $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
132 | - $internetavailable = $this->config->getSystemValue('has_internet_connection', true); |
|
133 | - |
|
134 | - if (!$appstoreenabled || !$internetavailable) { |
|
135 | - return []; |
|
136 | - } |
|
137 | - |
|
138 | - $rootFolder = $this->appData->getFolder('/'); |
|
139 | - |
|
140 | - $ETag = ''; |
|
141 | - $content = ''; |
|
142 | - |
|
143 | - try { |
|
144 | - // File does already exists |
|
145 | - $file = $rootFolder->getFile($this->fileName); |
|
146 | - $jsonBlob = json_decode($file->getContent(), true); |
|
147 | - if (is_array($jsonBlob)) { |
|
148 | - |
|
149 | - // No caching when the version has been updated |
|
150 | - if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { |
|
151 | - |
|
152 | - // If the timestamp is older than 300 seconds request the files new |
|
153 | - if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
154 | - return $jsonBlob['data']; |
|
155 | - } |
|
156 | - |
|
157 | - if (isset($jsonBlob['ETag'])) { |
|
158 | - $ETag = $jsonBlob['ETag']; |
|
159 | - $content = json_encode($jsonBlob['data']); |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - } catch (NotFoundException $e) { |
|
164 | - // File does not already exists |
|
165 | - $file = $rootFolder->newFile($this->fileName); |
|
166 | - } |
|
167 | - |
|
168 | - // Refresh the file content |
|
169 | - try { |
|
170 | - $responseJson = $this->fetch($ETag, $content); |
|
171 | - $file->putContent(json_encode($responseJson)); |
|
172 | - return json_decode($file->getContent(), true)['data']; |
|
173 | - } catch (ConnectException $e) { |
|
174 | - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO, 'message' => 'Could not connect to appstore']); |
|
175 | - return []; |
|
176 | - } catch (\Exception $e) { |
|
177 | - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO]); |
|
178 | - return []; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Get the currently Nextcloud version |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - protected function getVersion() { |
|
187 | - if ($this->version === null) { |
|
188 | - $this->version = $this->config->getSystemValue('version', '0.0.0'); |
|
189 | - } |
|
190 | - return $this->version; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Set the current Nextcloud version |
|
195 | - * @param string $version |
|
196 | - */ |
|
197 | - public function setVersion(string $version) { |
|
198 | - $this->version = $version; |
|
199 | - } |
|
42 | + const INVALIDATE_AFTER_SECONDS = 300; |
|
43 | + |
|
44 | + /** @var IAppData */ |
|
45 | + protected $appData; |
|
46 | + /** @var IClientService */ |
|
47 | + protected $clientService; |
|
48 | + /** @var ITimeFactory */ |
|
49 | + protected $timeFactory; |
|
50 | + /** @var IConfig */ |
|
51 | + protected $config; |
|
52 | + /** @var Ilogger */ |
|
53 | + protected $logger; |
|
54 | + /** @var string */ |
|
55 | + protected $fileName; |
|
56 | + /** @var string */ |
|
57 | + protected $endpointUrl; |
|
58 | + /** @var string */ |
|
59 | + protected $version; |
|
60 | + |
|
61 | + /** |
|
62 | + * @param Factory $appDataFactory |
|
63 | + * @param IClientService $clientService |
|
64 | + * @param ITimeFactory $timeFactory |
|
65 | + * @param IConfig $config |
|
66 | + * @param ILogger $logger |
|
67 | + */ |
|
68 | + public function __construct(Factory $appDataFactory, |
|
69 | + IClientService $clientService, |
|
70 | + ITimeFactory $timeFactory, |
|
71 | + IConfig $config, |
|
72 | + ILogger $logger) { |
|
73 | + $this->appData = $appDataFactory->get('appstore'); |
|
74 | + $this->clientService = $clientService; |
|
75 | + $this->timeFactory = $timeFactory; |
|
76 | + $this->config = $config; |
|
77 | + $this->logger = $logger; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Fetches the response from the server |
|
82 | + * |
|
83 | + * @param string $ETag |
|
84 | + * @param string $content |
|
85 | + * |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + protected function fetch($ETag, $content) { |
|
89 | + $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
90 | + |
|
91 | + if (!$appstoreenabled) { |
|
92 | + return []; |
|
93 | + } |
|
94 | + |
|
95 | + $options = [ |
|
96 | + 'timeout' => 10, |
|
97 | + ]; |
|
98 | + |
|
99 | + if ($ETag !== '') { |
|
100 | + $options['headers'] = [ |
|
101 | + 'If-None-Match' => $ETag, |
|
102 | + ]; |
|
103 | + } |
|
104 | + |
|
105 | + $client = $this->clientService->newClient(); |
|
106 | + $response = $client->get($this->endpointUrl, $options); |
|
107 | + |
|
108 | + $responseJson = []; |
|
109 | + if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) { |
|
110 | + $responseJson['data'] = json_decode($content, true); |
|
111 | + } else { |
|
112 | + $responseJson['data'] = json_decode($response->getBody(), true); |
|
113 | + $ETag = $response->getHeader('ETag'); |
|
114 | + } |
|
115 | + |
|
116 | + $responseJson['timestamp'] = $this->timeFactory->getTime(); |
|
117 | + $responseJson['ncversion'] = $this->getVersion(); |
|
118 | + if ($ETag !== '') { |
|
119 | + $responseJson['ETag'] = $ETag; |
|
120 | + } |
|
121 | + |
|
122 | + return $responseJson; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns the array with the categories on the appstore server |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function get() { |
|
131 | + $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
132 | + $internetavailable = $this->config->getSystemValue('has_internet_connection', true); |
|
133 | + |
|
134 | + if (!$appstoreenabled || !$internetavailable) { |
|
135 | + return []; |
|
136 | + } |
|
137 | + |
|
138 | + $rootFolder = $this->appData->getFolder('/'); |
|
139 | + |
|
140 | + $ETag = ''; |
|
141 | + $content = ''; |
|
142 | + |
|
143 | + try { |
|
144 | + // File does already exists |
|
145 | + $file = $rootFolder->getFile($this->fileName); |
|
146 | + $jsonBlob = json_decode($file->getContent(), true); |
|
147 | + if (is_array($jsonBlob)) { |
|
148 | + |
|
149 | + // No caching when the version has been updated |
|
150 | + if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { |
|
151 | + |
|
152 | + // If the timestamp is older than 300 seconds request the files new |
|
153 | + if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
154 | + return $jsonBlob['data']; |
|
155 | + } |
|
156 | + |
|
157 | + if (isset($jsonBlob['ETag'])) { |
|
158 | + $ETag = $jsonBlob['ETag']; |
|
159 | + $content = json_encode($jsonBlob['data']); |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + } catch (NotFoundException $e) { |
|
164 | + // File does not already exists |
|
165 | + $file = $rootFolder->newFile($this->fileName); |
|
166 | + } |
|
167 | + |
|
168 | + // Refresh the file content |
|
169 | + try { |
|
170 | + $responseJson = $this->fetch($ETag, $content); |
|
171 | + $file->putContent(json_encode($responseJson)); |
|
172 | + return json_decode($file->getContent(), true)['data']; |
|
173 | + } catch (ConnectException $e) { |
|
174 | + $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO, 'message' => 'Could not connect to appstore']); |
|
175 | + return []; |
|
176 | + } catch (\Exception $e) { |
|
177 | + $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO]); |
|
178 | + return []; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Get the currently Nextcloud version |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + protected function getVersion() { |
|
187 | + if ($this->version === null) { |
|
188 | + $this->version = $this->config->getSystemValue('version', '0.0.0'); |
|
189 | + } |
|
190 | + return $this->version; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Set the current Nextcloud version |
|
195 | + * @param string $version |
|
196 | + */ |
|
197 | + public function setVersion(string $version) { |
|
198 | + $this->version = $version; |
|
199 | + } |
|
200 | 200 | } |
@@ -32,85 +32,85 @@ |
||
32 | 32 | |
33 | 33 | class ImageExportPlugin extends ServerPlugin { |
34 | 34 | |
35 | - /** @var Server */ |
|
36 | - protected $server; |
|
37 | - /** @var PhotoCache */ |
|
38 | - private $cache; |
|
39 | - |
|
40 | - /** |
|
41 | - * ImageExportPlugin constructor. |
|
42 | - * |
|
43 | - * @param PhotoCache $cache |
|
44 | - */ |
|
45 | - public function __construct(PhotoCache $cache) { |
|
46 | - $this->cache = $cache; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Initializes the plugin and registers event handlers |
|
51 | - * |
|
52 | - * @param Server $server |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function initialize(Server $server) { |
|
56 | - $this->server = $server; |
|
57 | - $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Intercepts GET requests on addressbook urls ending with ?photo. |
|
62 | - * |
|
63 | - * @param RequestInterface $request |
|
64 | - * @param ResponseInterface $response |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - public function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
68 | - |
|
69 | - $queryParams = $request->getQueryParameters(); |
|
70 | - // TODO: in addition to photo we should also add logo some point in time |
|
71 | - if (!array_key_exists('photo', $queryParams)) { |
|
72 | - return true; |
|
73 | - } |
|
74 | - |
|
75 | - $size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1; |
|
76 | - |
|
77 | - $path = $request->getPath(); |
|
78 | - $node = $this->server->tree->getNodeForPath($path); |
|
79 | - |
|
80 | - if (!($node instanceof Card)) { |
|
81 | - return true; |
|
82 | - } |
|
83 | - |
|
84 | - $this->server->transactionType = 'carddav-image-export'; |
|
85 | - |
|
86 | - // Checking ACL, if available. |
|
87 | - if ($aclPlugin = $this->server->getPlugin('acl')) { |
|
88 | - /** @var \Sabre\DAVACL\Plugin $aclPlugin */ |
|
89 | - $aclPlugin->checkPrivileges($path, '{DAV:}read'); |
|
90 | - } |
|
91 | - |
|
92 | - // Fetch addressbook |
|
93 | - $addressbookpath = explode('/', $path); |
|
94 | - array_pop($addressbookpath); |
|
95 | - $addressbookpath = implode('/', $addressbookpath); |
|
96 | - /** @var AddressBook $addressbook */ |
|
97 | - $addressbook = $this->server->tree->getNodeForPath($addressbookpath); |
|
98 | - |
|
99 | - $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate'); |
|
100 | - $response->setHeader('Etag', $node->getETag() ); |
|
101 | - $response->setHeader('Pragma', 'public'); |
|
102 | - |
|
103 | - try { |
|
104 | - $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node); |
|
105 | - $response->setHeader('Content-Type', $file->getMimeType()); |
|
106 | - $response->setHeader('Content-Disposition', 'attachment'); |
|
107 | - $response->setStatus(200); |
|
108 | - |
|
109 | - $response->setBody($file->getContent()); |
|
110 | - } catch (NotFoundException $e) { |
|
111 | - $response->setStatus(404); |
|
112 | - } |
|
113 | - |
|
114 | - return false; |
|
115 | - } |
|
35 | + /** @var Server */ |
|
36 | + protected $server; |
|
37 | + /** @var PhotoCache */ |
|
38 | + private $cache; |
|
39 | + |
|
40 | + /** |
|
41 | + * ImageExportPlugin constructor. |
|
42 | + * |
|
43 | + * @param PhotoCache $cache |
|
44 | + */ |
|
45 | + public function __construct(PhotoCache $cache) { |
|
46 | + $this->cache = $cache; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Initializes the plugin and registers event handlers |
|
51 | + * |
|
52 | + * @param Server $server |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function initialize(Server $server) { |
|
56 | + $this->server = $server; |
|
57 | + $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Intercepts GET requests on addressbook urls ending with ?photo. |
|
62 | + * |
|
63 | + * @param RequestInterface $request |
|
64 | + * @param ResponseInterface $response |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + public function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
68 | + |
|
69 | + $queryParams = $request->getQueryParameters(); |
|
70 | + // TODO: in addition to photo we should also add logo some point in time |
|
71 | + if (!array_key_exists('photo', $queryParams)) { |
|
72 | + return true; |
|
73 | + } |
|
74 | + |
|
75 | + $size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1; |
|
76 | + |
|
77 | + $path = $request->getPath(); |
|
78 | + $node = $this->server->tree->getNodeForPath($path); |
|
79 | + |
|
80 | + if (!($node instanceof Card)) { |
|
81 | + return true; |
|
82 | + } |
|
83 | + |
|
84 | + $this->server->transactionType = 'carddav-image-export'; |
|
85 | + |
|
86 | + // Checking ACL, if available. |
|
87 | + if ($aclPlugin = $this->server->getPlugin('acl')) { |
|
88 | + /** @var \Sabre\DAVACL\Plugin $aclPlugin */ |
|
89 | + $aclPlugin->checkPrivileges($path, '{DAV:}read'); |
|
90 | + } |
|
91 | + |
|
92 | + // Fetch addressbook |
|
93 | + $addressbookpath = explode('/', $path); |
|
94 | + array_pop($addressbookpath); |
|
95 | + $addressbookpath = implode('/', $addressbookpath); |
|
96 | + /** @var AddressBook $addressbook */ |
|
97 | + $addressbook = $this->server->tree->getNodeForPath($addressbookpath); |
|
98 | + |
|
99 | + $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate'); |
|
100 | + $response->setHeader('Etag', $node->getETag() ); |
|
101 | + $response->setHeader('Pragma', 'public'); |
|
102 | + |
|
103 | + try { |
|
104 | + $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node); |
|
105 | + $response->setHeader('Content-Type', $file->getMimeType()); |
|
106 | + $response->setHeader('Content-Disposition', 'attachment'); |
|
107 | + $response->setStatus(200); |
|
108 | + |
|
109 | + $response->setBody($file->getContent()); |
|
110 | + } catch (NotFoundException $e) { |
|
111 | + $response->setStatus(404); |
|
112 | + } |
|
113 | + |
|
114 | + return false; |
|
115 | + } |
|
116 | 116 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | return true; |
73 | 73 | } |
74 | 74 | |
75 | - $size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1; |
|
75 | + $size = isset($queryParams['size']) ? (int) $queryParams['size'] : -1; |
|
76 | 76 | |
77 | 77 | $path = $request->getPath(); |
78 | 78 | $node = $this->server->tree->getNodeForPath($path); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $addressbook = $this->server->tree->getNodeForPath($addressbookpath); |
98 | 98 | |
99 | 99 | $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate'); |
100 | - $response->setHeader('Etag', $node->getETag() ); |
|
100 | + $response->setHeader('Etag', $node->getETag()); |
|
101 | 101 | $response->setHeader('Pragma', 'public'); |
102 | 102 | |
103 | 103 | try { |
@@ -41,7 +41,7 @@ |
||
41 | 41 | <?php p($theme->getName()); ?> |
42 | 42 | </h1> |
43 | 43 | <?php if(\OC::$server->getConfig()->getSystemValue('installed', false) |
44 | - && \OC::$server->getConfig()->getAppValue('theming', 'logoMime', false)): ?> |
|
44 | + && \OC::$server->getConfig()->getAppValue('theming', 'logoMime', false)): ?> |
|
45 | 45 | <img src="<?php p($theme->getLogo()); ?>"/> |
46 | 46 | <?php endif; ?> |
47 | 47 | </div> |
@@ -18,21 +18,21 @@ |
||
18 | 18 | <?php emit_script_loading_tags($_); ?> |
19 | 19 | <?php print_unescaped($_['headers']); ?> |
20 | 20 | </head> |
21 | - <body id="<?php p($_['bodyid']);?>"> |
|
21 | + <body id="<?php p($_['bodyid']); ?>"> |
|
22 | 22 | <?php include 'layout.noscript.warning.php'; ?> |
23 | 23 | <?php foreach ($_['initialStates'] as $app => $initialState) { ?> |
24 | 24 | <input type="hidden" id="initial-state-<?php p($app); ?>" value="<?php p(base64_encode($initialState)); ?>"> |
25 | 25 | <?php }?> |
26 | 26 | <div class="wrapper"> |
27 | 27 | <div class="v-align"> |
28 | - <?php if ($_['bodyid'] === 'body-login' ): ?> |
|
28 | + <?php if ($_['bodyid'] === 'body-login'): ?> |
|
29 | 29 | <header role="banner"> |
30 | 30 | <div id="header"> |
31 | 31 | <div class="logo"> |
32 | 32 | <h1 class="hidden-visually"> |
33 | 33 | <?php p($theme->getName()); ?> |
34 | 34 | </h1> |
35 | - <?php if(\OC::$server->getConfig()->getSystemValue('installed', false) |
|
35 | + <?php if (\OC::$server->getConfig()->getSystemValue('installed', false) |
|
36 | 36 | && \OC::$server->getConfig()->getAppValue('theming', 'logoMime', false)): ?> |
37 | 37 | <img src="<?php p($theme->getLogo()); ?>"/> |
38 | 38 | <?php endif; ?> |