@@ -37,57 +37,57 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class ConsoleOutput implements IOutput { |
| 39 | 39 | |
| 40 | - /** @var OutputInterface */ |
|
| 41 | - private $output; |
|
| 40 | + /** @var OutputInterface */ |
|
| 41 | + private $output; |
|
| 42 | 42 | |
| 43 | - /** @var ProgressBar */ |
|
| 44 | - private $progressBar; |
|
| 43 | + /** @var ProgressBar */ |
|
| 44 | + private $progressBar; |
|
| 45 | 45 | |
| 46 | - public function __construct(OutputInterface $output) { |
|
| 47 | - $this->output = $output; |
|
| 48 | - } |
|
| 46 | + public function __construct(OutputInterface $output) { |
|
| 47 | + $this->output = $output; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $message |
|
| 52 | - */ |
|
| 53 | - public function info($message) { |
|
| 54 | - $this->output->writeln("<info>$message</info>"); |
|
| 55 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $message |
|
| 52 | + */ |
|
| 53 | + public function info($message) { |
|
| 54 | + $this->output->writeln("<info>$message</info>"); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param string $message |
|
| 59 | - */ |
|
| 60 | - public function warning($message) { |
|
| 61 | - $this->output->writeln("<comment>$message</comment>"); |
|
| 62 | - } |
|
| 57 | + /** |
|
| 58 | + * @param string $message |
|
| 59 | + */ |
|
| 60 | + public function warning($message) { |
|
| 61 | + $this->output->writeln("<comment>$message</comment>"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param int $max |
|
| 66 | - */ |
|
| 67 | - public function startProgress($max = 0) { |
|
| 68 | - if (!is_null($this->progressBar)) { |
|
| 69 | - $this->progressBar->finish(); |
|
| 70 | - } |
|
| 71 | - $this->progressBar = new ProgressBar($this->output); |
|
| 72 | - $this->progressBar->start($max); |
|
| 73 | - } |
|
| 64 | + /** |
|
| 65 | + * @param int $max |
|
| 66 | + */ |
|
| 67 | + public function startProgress($max = 0) { |
|
| 68 | + if (!is_null($this->progressBar)) { |
|
| 69 | + $this->progressBar->finish(); |
|
| 70 | + } |
|
| 71 | + $this->progressBar = new ProgressBar($this->output); |
|
| 72 | + $this->progressBar->start($max); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param int $step |
|
| 77 | - * @param string $description |
|
| 78 | - */ |
|
| 79 | - public function advance($step = 1, $description = '') { |
|
| 80 | - if (!is_null($this->progressBar)) { |
|
| 81 | - $this->progressBar = new ProgressBar($this->output); |
|
| 82 | - $this->progressBar->start(); |
|
| 83 | - } |
|
| 84 | - $this->progressBar->advance($step); |
|
| 85 | - } |
|
| 75 | + /** |
|
| 76 | + * @param int $step |
|
| 77 | + * @param string $description |
|
| 78 | + */ |
|
| 79 | + public function advance($step = 1, $description = '') { |
|
| 80 | + if (!is_null($this->progressBar)) { |
|
| 81 | + $this->progressBar = new ProgressBar($this->output); |
|
| 82 | + $this->progressBar->start(); |
|
| 83 | + } |
|
| 84 | + $this->progressBar->advance($step); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function finishProgress() { |
|
| 88 | - if (is_null($this->progressBar)) { |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - $this->progressBar->finish(); |
|
| 92 | - } |
|
| 87 | + public function finishProgress() { |
|
| 88 | + if (is_null($this->progressBar)) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + $this->progressBar->finish(); |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -29,141 +29,141 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Entry implements IEntry { |
| 31 | 31 | |
| 32 | - /** @var string|int|null */ |
|
| 33 | - private $id = null; |
|
| 34 | - |
|
| 35 | - /** @var string */ |
|
| 36 | - private $fullName = ''; |
|
| 37 | - |
|
| 38 | - /** @var string[] */ |
|
| 39 | - private $emailAddresses = []; |
|
| 40 | - |
|
| 41 | - /** @var string|null */ |
|
| 42 | - private $avatar; |
|
| 43 | - |
|
| 44 | - /** @var IAction[] */ |
|
| 45 | - private $actions = []; |
|
| 46 | - |
|
| 47 | - /** @var array */ |
|
| 48 | - private $properties = []; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param string $id |
|
| 52 | - */ |
|
| 53 | - public function setId($id) { |
|
| 54 | - $this->id = $id; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $displayName |
|
| 59 | - */ |
|
| 60 | - public function setFullName($displayName) { |
|
| 61 | - $this->fullName = $displayName; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function getFullName() { |
|
| 68 | - return $this->fullName; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param string $address |
|
| 73 | - */ |
|
| 74 | - public function addEMailAddress($address) { |
|
| 75 | - $this->emailAddresses[] = $address; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function getEMailAddresses() { |
|
| 82 | - return $this->emailAddresses; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string $avatar |
|
| 87 | - */ |
|
| 88 | - public function setAvatar($avatar) { |
|
| 89 | - $this->avatar = $avatar; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function getAvatar() { |
|
| 96 | - return $this->avatar; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param IAction $action |
|
| 101 | - */ |
|
| 102 | - public function addAction(IAction $action) { |
|
| 103 | - $this->actions[] = $action; |
|
| 104 | - $this->sortActions(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return IAction[] |
|
| 109 | - */ |
|
| 110 | - public function getActions() { |
|
| 111 | - return $this->actions; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * sort the actions by priority and name |
|
| 116 | - */ |
|
| 117 | - private function sortActions() { |
|
| 118 | - usort($this->actions, function(IAction $action1, IAction $action2) { |
|
| 119 | - $prio1 = $action1->getPriority(); |
|
| 120 | - $prio2 = $action2->getPriority(); |
|
| 121 | - |
|
| 122 | - if ($prio1 === $prio2) { |
|
| 123 | - // Ascending order for same priority |
|
| 124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Descending order when priority differs |
|
| 128 | - return $prio2 - $prio1; |
|
| 129 | - }); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param array $contact key-value array containing additional properties |
|
| 134 | - */ |
|
| 135 | - public function setProperties(array $contact) { |
|
| 136 | - $this->properties = $contact; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $key |
|
| 141 | - * @return mixed |
|
| 142 | - */ |
|
| 143 | - public function getProperty($key) { |
|
| 144 | - if (!isset($this->properties[$key])) { |
|
| 145 | - return null; |
|
| 146 | - } |
|
| 147 | - return $this->properties[$key]; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @return array |
|
| 152 | - */ |
|
| 153 | - public function jsonSerialize() { |
|
| 154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
| 155 | - $otherActions = array_map(function(IAction $action) { |
|
| 156 | - return $action->jsonSerialize(); |
|
| 157 | - }, array_slice($this->actions, 1)); |
|
| 158 | - |
|
| 159 | - return [ |
|
| 160 | - 'id' => $this->id, |
|
| 161 | - 'fullName' => $this->fullName, |
|
| 162 | - 'avatar' => $this->getAvatar(), |
|
| 163 | - 'topAction' => $topAction, |
|
| 164 | - 'actions' => $otherActions, |
|
| 165 | - 'lastMessage' => '', |
|
| 166 | - ]; |
|
| 167 | - } |
|
| 32 | + /** @var string|int|null */ |
|
| 33 | + private $id = null; |
|
| 34 | + |
|
| 35 | + /** @var string */ |
|
| 36 | + private $fullName = ''; |
|
| 37 | + |
|
| 38 | + /** @var string[] */ |
|
| 39 | + private $emailAddresses = []; |
|
| 40 | + |
|
| 41 | + /** @var string|null */ |
|
| 42 | + private $avatar; |
|
| 43 | + |
|
| 44 | + /** @var IAction[] */ |
|
| 45 | + private $actions = []; |
|
| 46 | + |
|
| 47 | + /** @var array */ |
|
| 48 | + private $properties = []; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param string $id |
|
| 52 | + */ |
|
| 53 | + public function setId($id) { |
|
| 54 | + $this->id = $id; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $displayName |
|
| 59 | + */ |
|
| 60 | + public function setFullName($displayName) { |
|
| 61 | + $this->fullName = $displayName; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function getFullName() { |
|
| 68 | + return $this->fullName; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param string $address |
|
| 73 | + */ |
|
| 74 | + public function addEMailAddress($address) { |
|
| 75 | + $this->emailAddresses[] = $address; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function getEMailAddresses() { |
|
| 82 | + return $this->emailAddresses; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $avatar |
|
| 87 | + */ |
|
| 88 | + public function setAvatar($avatar) { |
|
| 89 | + $this->avatar = $avatar; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function getAvatar() { |
|
| 96 | + return $this->avatar; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param IAction $action |
|
| 101 | + */ |
|
| 102 | + public function addAction(IAction $action) { |
|
| 103 | + $this->actions[] = $action; |
|
| 104 | + $this->sortActions(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return IAction[] |
|
| 109 | + */ |
|
| 110 | + public function getActions() { |
|
| 111 | + return $this->actions; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * sort the actions by priority and name |
|
| 116 | + */ |
|
| 117 | + private function sortActions() { |
|
| 118 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
| 119 | + $prio1 = $action1->getPriority(); |
|
| 120 | + $prio2 = $action2->getPriority(); |
|
| 121 | + |
|
| 122 | + if ($prio1 === $prio2) { |
|
| 123 | + // Ascending order for same priority |
|
| 124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Descending order when priority differs |
|
| 128 | + return $prio2 - $prio1; |
|
| 129 | + }); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param array $contact key-value array containing additional properties |
|
| 134 | + */ |
|
| 135 | + public function setProperties(array $contact) { |
|
| 136 | + $this->properties = $contact; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $key |
|
| 141 | + * @return mixed |
|
| 142 | + */ |
|
| 143 | + public function getProperty($key) { |
|
| 144 | + if (!isset($this->properties[$key])) { |
|
| 145 | + return null; |
|
| 146 | + } |
|
| 147 | + return $this->properties[$key]; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @return array |
|
| 152 | + */ |
|
| 153 | + public function jsonSerialize() { |
|
| 154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
| 155 | + $otherActions = array_map(function(IAction $action) { |
|
| 156 | + return $action->jsonSerialize(); |
|
| 157 | + }, array_slice($this->actions, 1)); |
|
| 158 | + |
|
| 159 | + return [ |
|
| 160 | + 'id' => $this->id, |
|
| 161 | + 'fullName' => $this->fullName, |
|
| 162 | + 'avatar' => $this->getAvatar(), |
|
| 163 | + 'topAction' => $topAction, |
|
| 164 | + 'actions' => $otherActions, |
|
| 165 | + 'lastMessage' => '', |
|
| 166 | + ]; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | 169 | } |
@@ -31,36 +31,36 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | interface IEntry extends JsonSerializable { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @since 12.0 |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getFullName(); |
|
| 34 | + /** |
|
| 35 | + * @since 12.0 |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getFullName(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @since 12.0 |
|
| 42 | - * @return string[] |
|
| 43 | - */ |
|
| 44 | - public function getEMailAddresses(); |
|
| 40 | + /** |
|
| 41 | + * @since 12.0 |
|
| 42 | + * @return string[] |
|
| 43 | + */ |
|
| 44 | + public function getEMailAddresses(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @since 12.0 |
|
| 48 | - * @return string|null image URI |
|
| 49 | - */ |
|
| 50 | - public function getAvatar(); |
|
| 46 | + /** |
|
| 47 | + * @since 12.0 |
|
| 48 | + * @return string|null image URI |
|
| 49 | + */ |
|
| 50 | + public function getAvatar(); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @since 12.0 |
|
| 54 | - * @param IAction $action an action to show in the contacts menu |
|
| 55 | - */ |
|
| 56 | - public function addAction(IAction $action); |
|
| 52 | + /** |
|
| 53 | + * @since 12.0 |
|
| 54 | + * @param IAction $action an action to show in the contacts menu |
|
| 55 | + */ |
|
| 56 | + public function addAction(IAction $action); |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Get an arbitrary property from the contact |
|
| 60 | - * |
|
| 61 | - * @since 12.0 |
|
| 62 | - * @param string $key |
|
| 63 | - * @return mixed the value of the property or null |
|
| 64 | - */ |
|
| 65 | - public function getProperty($key); |
|
| 58 | + /** |
|
| 59 | + * Get an arbitrary property from the contact |
|
| 60 | + * |
|
| 61 | + * @since 12.0 |
|
| 62 | + * @param string $key |
|
| 63 | + * @return mixed the value of the property or null |
|
| 64 | + */ |
|
| 65 | + public function getProperty($key); |
|
| 66 | 66 | } |
@@ -47,58 +47,58 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | interface IContainer { |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * If a parameter is not registered in the container try to instantiate it |
|
| 52 | - * by using reflection to find out how to build the class |
|
| 53 | - * @param string $name the class name to resolve |
|
| 54 | - * @return \stdClass |
|
| 55 | - * @since 8.2.0 |
|
| 56 | - * @throws QueryException if the class could not be found or instantiated |
|
| 57 | - */ |
|
| 58 | - public function resolve($name); |
|
| 50 | + /** |
|
| 51 | + * If a parameter is not registered in the container try to instantiate it |
|
| 52 | + * by using reflection to find out how to build the class |
|
| 53 | + * @param string $name the class name to resolve |
|
| 54 | + * @return \stdClass |
|
| 55 | + * @since 8.2.0 |
|
| 56 | + * @throws QueryException if the class could not be found or instantiated |
|
| 57 | + */ |
|
| 58 | + public function resolve($name); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Look up a service for a given name in the container. |
|
| 62 | - * |
|
| 63 | - * @param string $name |
|
| 64 | - * @return mixed |
|
| 65 | - * @throws QueryException if the query could not be resolved |
|
| 66 | - * @since 6.0.0 |
|
| 67 | - */ |
|
| 68 | - public function query($name); |
|
| 60 | + /** |
|
| 61 | + * Look up a service for a given name in the container. |
|
| 62 | + * |
|
| 63 | + * @param string $name |
|
| 64 | + * @return mixed |
|
| 65 | + * @throws QueryException if the query could not be resolved |
|
| 66 | + * @since 6.0.0 |
|
| 67 | + */ |
|
| 68 | + public function query($name); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * A value is stored in the container with it's corresponding name |
|
| 72 | - * |
|
| 73 | - * @param string $name |
|
| 74 | - * @param mixed $value |
|
| 75 | - * @return void |
|
| 76 | - * @since 6.0.0 |
|
| 77 | - */ |
|
| 78 | - public function registerParameter($name, $value); |
|
| 70 | + /** |
|
| 71 | + * A value is stored in the container with it's corresponding name |
|
| 72 | + * |
|
| 73 | + * @param string $name |
|
| 74 | + * @param mixed $value |
|
| 75 | + * @return void |
|
| 76 | + * @since 6.0.0 |
|
| 77 | + */ |
|
| 78 | + public function registerParameter($name, $value); |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * A service is registered in the container where a closure is passed in which will actually |
|
| 82 | - * create the service on demand. |
|
| 83 | - * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
| 84 | - * memory and be reused on subsequent calls. |
|
| 85 | - * In case the parameter is false the service will be recreated on every call. |
|
| 86 | - * |
|
| 87 | - * @param string $name |
|
| 88 | - * @param \Closure $closure |
|
| 89 | - * @param bool $shared |
|
| 90 | - * @return void |
|
| 91 | - * @since 6.0.0 |
|
| 92 | - */ |
|
| 93 | - public function registerService($name, Closure $closure, $shared = true); |
|
| 80 | + /** |
|
| 81 | + * A service is registered in the container where a closure is passed in which will actually |
|
| 82 | + * create the service on demand. |
|
| 83 | + * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
| 84 | + * memory and be reused on subsequent calls. |
|
| 85 | + * In case the parameter is false the service will be recreated on every call. |
|
| 86 | + * |
|
| 87 | + * @param string $name |
|
| 88 | + * @param \Closure $closure |
|
| 89 | + * @param bool $shared |
|
| 90 | + * @return void |
|
| 91 | + * @since 6.0.0 |
|
| 92 | + */ |
|
| 93 | + public function registerService($name, Closure $closure, $shared = true); |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Shortcut for returning a service from a service under a different key, |
|
| 97 | - * e.g. to tell the container to return a class when queried for an |
|
| 98 | - * interface |
|
| 99 | - * @param string $alias the alias that should be registered |
|
| 100 | - * @param string $target the target that should be resolved instead |
|
| 101 | - * @since 8.2.0 |
|
| 102 | - */ |
|
| 103 | - public function registerAlias($alias, $target); |
|
| 95 | + /** |
|
| 96 | + * Shortcut for returning a service from a service under a different key, |
|
| 97 | + * e.g. to tell the container to return a class when queried for an |
|
| 98 | + * interface |
|
| 99 | + * @param string $alias the alias that should be registered |
|
| 100 | + * @param string $target the target that should be resolved instead |
|
| 101 | + * @since 8.2.0 |
|
| 102 | + */ |
|
| 103 | + public function registerAlias($alias, $target); |
|
| 104 | 104 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $result = array(); |
| 45 | 45 | $timestamp = null; |
| 46 | 46 | |
| 47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
| 48 | 48 | |
| 49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
| 50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
| 73 | 73 | } |
| 74 | 74 | $originalPath = ''; |
| 75 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 75 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
| 76 | 76 | if (isset($originalLocations[$originalName][$timestamp])) { |
| 77 | 77 | $originalPath = $originalLocations[$originalName][$timestamp]; |
| 78 | 78 | if (substr($originalPath, -1) === '/') { |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | ); |
| 93 | 93 | if ($originalPath) { |
| 94 | 94 | if ($originalPath !== '.') { |
| 95 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 95 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
| 96 | 96 | } else { |
| 97 | 97 | $i['extraData'] = $originalName; |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 100 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if ($sortAttribute !== '') { |
@@ -33,96 +33,96 @@ |
||
| 33 | 33 | use OCP\Files\Cache\ICacheEntry; |
| 34 | 34 | |
| 35 | 35 | class Helper { |
| 36 | - /** |
|
| 37 | - * Retrieves the contents of a trash bin directory. |
|
| 38 | - * |
|
| 39 | - * @param string $dir path to the directory inside the trashbin |
|
| 40 | - * or empty to retrieve the root of the trashbin |
|
| 41 | - * @param string $user |
|
| 42 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 43 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
| 44 | - * @return \OCP\Files\FileInfo[] |
|
| 45 | - */ |
|
| 46 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 47 | - $result = array(); |
|
| 48 | - $timestamp = null; |
|
| 36 | + /** |
|
| 37 | + * Retrieves the contents of a trash bin directory. |
|
| 38 | + * |
|
| 39 | + * @param string $dir path to the directory inside the trashbin |
|
| 40 | + * or empty to retrieve the root of the trashbin |
|
| 41 | + * @param string $user |
|
| 42 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 43 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
| 44 | + * @return \OCP\Files\FileInfo[] |
|
| 45 | + */ |
|
| 46 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 47 | + $result = array(); |
|
| 48 | + $timestamp = null; |
|
| 49 | 49 | |
| 50 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 50 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 51 | 51 | |
| 52 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 53 | - throw new \Exception('Directory does not exists'); |
|
| 54 | - } |
|
| 52 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 53 | + throw new \Exception('Directory does not exists'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $mount = $view->getMount($dir); |
|
| 57 | - $storage = $mount->getStorage(); |
|
| 58 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
| 59 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 56 | + $mount = $view->getMount($dir); |
|
| 57 | + $storage = $mount->getStorage(); |
|
| 58 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
| 59 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 60 | 60 | |
| 61 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 62 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 63 | - foreach ($dirContent as $entry) { |
|
| 64 | - $entryName = $entry->getName(); |
|
| 65 | - $name = $entryName; |
|
| 66 | - if ($dir === '' || $dir === '/') { |
|
| 67 | - $pathparts = pathinfo($entryName); |
|
| 68 | - $timestamp = substr($pathparts['extension'], 1); |
|
| 69 | - $name = $pathparts['filename']; |
|
| 61 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 62 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 63 | + foreach ($dirContent as $entry) { |
|
| 64 | + $entryName = $entry->getName(); |
|
| 65 | + $name = $entryName; |
|
| 66 | + if ($dir === '' || $dir === '/') { |
|
| 67 | + $pathparts = pathinfo($entryName); |
|
| 68 | + $timestamp = substr($pathparts['extension'], 1); |
|
| 69 | + $name = $pathparts['filename']; |
|
| 70 | 70 | |
| 71 | - } else if ($timestamp === null) { |
|
| 72 | - // for subfolders we need to calculate the timestamp only once |
|
| 73 | - $parts = explode('/', ltrim($dir, '/')); |
|
| 74 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 75 | - } |
|
| 76 | - $originalPath = ''; |
|
| 77 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 78 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 79 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 80 | - if (substr($originalPath, -1) === '/') { |
|
| 81 | - $originalPath = substr($originalPath, 0, -1); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 85 | - $i = array( |
|
| 86 | - 'name' => $name, |
|
| 87 | - 'mtime' => $timestamp, |
|
| 88 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 89 | - 'type' => $type, |
|
| 90 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
| 91 | - 'size' => $entry->getSize(), |
|
| 92 | - 'etag' => '', |
|
| 93 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 94 | - 'fileid' => $entry->getId(), |
|
| 95 | - ); |
|
| 96 | - if ($originalPath) { |
|
| 97 | - if ($originalPath !== '.') { |
|
| 98 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 99 | - } else { |
|
| 100 | - $i['extraData'] = $originalName; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 104 | - } |
|
| 71 | + } else if ($timestamp === null) { |
|
| 72 | + // for subfolders we need to calculate the timestamp only once |
|
| 73 | + $parts = explode('/', ltrim($dir, '/')); |
|
| 74 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 75 | + } |
|
| 76 | + $originalPath = ''; |
|
| 77 | + $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 78 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 79 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 80 | + if (substr($originalPath, -1) === '/') { |
|
| 81 | + $originalPath = substr($originalPath, 0, -1); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 85 | + $i = array( |
|
| 86 | + 'name' => $name, |
|
| 87 | + 'mtime' => $timestamp, |
|
| 88 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 89 | + 'type' => $type, |
|
| 90 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
| 91 | + 'size' => $entry->getSize(), |
|
| 92 | + 'etag' => '', |
|
| 93 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 94 | + 'fileid' => $entry->getId(), |
|
| 95 | + ); |
|
| 96 | + if ($originalPath) { |
|
| 97 | + if ($originalPath !== '.') { |
|
| 98 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 99 | + } else { |
|
| 100 | + $i['extraData'] = $originalName; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - if ($sortAttribute !== '') { |
|
| 107 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 108 | - } |
|
| 109 | - return $result; |
|
| 110 | - } |
|
| 106 | + if ($sortAttribute !== '') { |
|
| 107 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 108 | + } |
|
| 109 | + return $result; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Format file infos for JSON |
|
| 114 | - * |
|
| 115 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 116 | - */ |
|
| 117 | - public static function formatFileInfos($fileInfos) { |
|
| 118 | - $files = array(); |
|
| 119 | - foreach ($fileInfos as $i) { |
|
| 120 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 121 | - $entry['id'] = $i->getId(); |
|
| 122 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 123 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 124 | - $files[] = $entry; |
|
| 125 | - } |
|
| 126 | - return $files; |
|
| 127 | - } |
|
| 112 | + /** |
|
| 113 | + * Format file infos for JSON |
|
| 114 | + * |
|
| 115 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 116 | + */ |
|
| 117 | + public static function formatFileInfos($fileInfos) { |
|
| 118 | + $files = array(); |
|
| 119 | + foreach ($fileInfos as $i) { |
|
| 120 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 121 | + $entry['id'] = $i->getId(); |
|
| 122 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 123 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 124 | + $files[] = $entry; |
|
| 125 | + } |
|
| 126 | + return $files; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | ]); |
| 111 | 111 | } |
| 112 | 112 | // password policy app throws exception |
| 113 | - } catch(HintException $e) { |
|
| 113 | + } catch (HintException $e) { |
|
| 114 | 114 | return new JSONResponse([ |
| 115 | 115 | 'status' => 'error', |
| 116 | 116 | 'data' => [ |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | 'message' => $this->l->t('Please provide an admin recovery password; otherwise, all user data will be lost.'), |
| 221 | 221 | ] |
| 222 | 222 | ]); |
| 223 | - } elseif ($recoveryEnabledForUser && ! $validRecoveryPassword) { |
|
| 223 | + } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) { |
|
| 224 | 224 | return new JSONResponse([ |
| 225 | 225 | 'status' => 'error', |
| 226 | 226 | 'data' => [ |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | try { |
| 232 | 232 | $result = $targetUser->setPassword($password, $recoveryPassword); |
| 233 | 233 | // password policy app throws exception |
| 234 | - } catch(HintException $e) { |
|
| 234 | + } catch (HintException $e) { |
|
| 235 | 235 | return new JSONResponse([ |
| 236 | 236 | 'status' => 'error', |
| 237 | 237 | 'data' => [ |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | ]); |
| 267 | 267 | } |
| 268 | 268 | // password policy app throws exception |
| 269 | - } catch(HintException $e) { |
|
| 269 | + } catch (HintException $e) { |
|
| 270 | 270 | return new JSONResponse([ |
| 271 | 271 | 'status' => 'error', |
| 272 | 272 | 'data' => [ |
@@ -41,244 +41,244 @@ |
||
| 41 | 41 | |
| 42 | 42 | class ChangePasswordController extends Controller { |
| 43 | 43 | |
| 44 | - /** @var string */ |
|
| 45 | - private $userId; |
|
| 44 | + /** @var string */ |
|
| 45 | + private $userId; |
|
| 46 | 46 | |
| 47 | - /** @var IUserManager */ |
|
| 48 | - private $userManager; |
|
| 47 | + /** @var IUserManager */ |
|
| 48 | + private $userManager; |
|
| 49 | 49 | |
| 50 | - /** @var IL10N */ |
|
| 51 | - private $l; |
|
| 50 | + /** @var IL10N */ |
|
| 51 | + private $l; |
|
| 52 | 52 | |
| 53 | - /** @var IGroupManager */ |
|
| 54 | - private $groupManager; |
|
| 53 | + /** @var IGroupManager */ |
|
| 54 | + private $groupManager; |
|
| 55 | 55 | |
| 56 | - /** @var Session */ |
|
| 57 | - private $userSession; |
|
| 56 | + /** @var Session */ |
|
| 57 | + private $userSession; |
|
| 58 | 58 | |
| 59 | - /** @var IAppManager */ |
|
| 60 | - private $appManager; |
|
| 59 | + /** @var IAppManager */ |
|
| 60 | + private $appManager; |
|
| 61 | 61 | |
| 62 | - public function __construct(string $appName, |
|
| 63 | - IRequest $request, |
|
| 64 | - string $userId, |
|
| 65 | - IUserManager $userManager, |
|
| 66 | - IUserSession $userSession, |
|
| 67 | - IGroupManager $groupManager, |
|
| 68 | - IAppManager $appManager, |
|
| 69 | - IL10N $l) { |
|
| 70 | - parent::__construct($appName, $request); |
|
| 62 | + public function __construct(string $appName, |
|
| 63 | + IRequest $request, |
|
| 64 | + string $userId, |
|
| 65 | + IUserManager $userManager, |
|
| 66 | + IUserSession $userSession, |
|
| 67 | + IGroupManager $groupManager, |
|
| 68 | + IAppManager $appManager, |
|
| 69 | + IL10N $l) { |
|
| 70 | + parent::__construct($appName, $request); |
|
| 71 | 71 | |
| 72 | - $this->userId = $userId; |
|
| 73 | - $this->userManager = $userManager; |
|
| 74 | - $this->userSession = $userSession; |
|
| 75 | - $this->groupManager = $groupManager; |
|
| 76 | - $this->appManager = $appManager; |
|
| 77 | - $this->l = $l; |
|
| 78 | - } |
|
| 72 | + $this->userId = $userId; |
|
| 73 | + $this->userManager = $userManager; |
|
| 74 | + $this->userSession = $userSession; |
|
| 75 | + $this->groupManager = $groupManager; |
|
| 76 | + $this->appManager = $appManager; |
|
| 77 | + $this->l = $l; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @NoAdminRequired |
|
| 82 | - * @NoSubadminRequired |
|
| 83 | - * @BruteForceProtection(action=changePersonalPassword) |
|
| 84 | - * |
|
| 85 | - * @param string $oldpassword |
|
| 86 | - * @param string $newpassword |
|
| 87 | - * |
|
| 88 | - * @return JSONResponse |
|
| 89 | - */ |
|
| 90 | - public function changePersonalPassword(string $oldpassword = '', string $newpassword = null): JSONResponse { |
|
| 91 | - /** @var IUser $user */ |
|
| 92 | - $user = $this->userManager->checkPassword($this->userId, $oldpassword); |
|
| 93 | - if ($user === false) { |
|
| 94 | - $response = new JSONResponse([ |
|
| 95 | - 'status' => 'error', |
|
| 96 | - 'data' => [ |
|
| 97 | - 'message' => $this->l->t('Wrong password'), |
|
| 98 | - ], |
|
| 99 | - ]); |
|
| 100 | - $response->throttle(); |
|
| 101 | - return $response; |
|
| 102 | - } |
|
| 80 | + /** |
|
| 81 | + * @NoAdminRequired |
|
| 82 | + * @NoSubadminRequired |
|
| 83 | + * @BruteForceProtection(action=changePersonalPassword) |
|
| 84 | + * |
|
| 85 | + * @param string $oldpassword |
|
| 86 | + * @param string $newpassword |
|
| 87 | + * |
|
| 88 | + * @return JSONResponse |
|
| 89 | + */ |
|
| 90 | + public function changePersonalPassword(string $oldpassword = '', string $newpassword = null): JSONResponse { |
|
| 91 | + /** @var IUser $user */ |
|
| 92 | + $user = $this->userManager->checkPassword($this->userId, $oldpassword); |
|
| 93 | + if ($user === false) { |
|
| 94 | + $response = new JSONResponse([ |
|
| 95 | + 'status' => 'error', |
|
| 96 | + 'data' => [ |
|
| 97 | + 'message' => $this->l->t('Wrong password'), |
|
| 98 | + ], |
|
| 99 | + ]); |
|
| 100 | + $response->throttle(); |
|
| 101 | + return $response; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - try { |
|
| 105 | - if ($newpassword === null || $user->setPassword($newpassword) === false) { |
|
| 106 | - return new JSONResponse([ |
|
| 107 | - 'status' => 'error' |
|
| 108 | - ]); |
|
| 109 | - } |
|
| 110 | - // password policy app throws exception |
|
| 111 | - } catch(HintException $e) { |
|
| 112 | - return new JSONResponse([ |
|
| 113 | - 'status' => 'error', |
|
| 114 | - 'data' => [ |
|
| 115 | - 'message' => $e->getHint(), |
|
| 116 | - ], |
|
| 117 | - ]); |
|
| 118 | - } |
|
| 104 | + try { |
|
| 105 | + if ($newpassword === null || $user->setPassword($newpassword) === false) { |
|
| 106 | + return new JSONResponse([ |
|
| 107 | + 'status' => 'error' |
|
| 108 | + ]); |
|
| 109 | + } |
|
| 110 | + // password policy app throws exception |
|
| 111 | + } catch(HintException $e) { |
|
| 112 | + return new JSONResponse([ |
|
| 113 | + 'status' => 'error', |
|
| 114 | + 'data' => [ |
|
| 115 | + 'message' => $e->getHint(), |
|
| 116 | + ], |
|
| 117 | + ]); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - $this->userSession->updateSessionTokenPassword($newpassword); |
|
| 120 | + $this->userSession->updateSessionTokenPassword($newpassword); |
|
| 121 | 121 | |
| 122 | - return new JSONResponse([ |
|
| 123 | - 'status' => 'success', |
|
| 124 | - 'data' => [ |
|
| 125 | - 'message' => $this->l->t('Saved'), |
|
| 126 | - ], |
|
| 127 | - ]); |
|
| 128 | - } |
|
| 122 | + return new JSONResponse([ |
|
| 123 | + 'status' => 'success', |
|
| 124 | + 'data' => [ |
|
| 125 | + 'message' => $this->l->t('Saved'), |
|
| 126 | + ], |
|
| 127 | + ]); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @NoAdminRequired |
|
| 132 | - * @PasswordConfirmationRequired |
|
| 133 | - * |
|
| 134 | - * @param string $username |
|
| 135 | - * @param string $password |
|
| 136 | - * @param string $recoveryPassword |
|
| 137 | - * |
|
| 138 | - * @return JSONResponse |
|
| 139 | - */ |
|
| 140 | - public function changeUserPassword(string $username = null, string $password = null, string $recoveryPassword = null): JSONResponse { |
|
| 141 | - if ($username === null) { |
|
| 142 | - return new JSONResponse([ |
|
| 143 | - 'status' => 'error', |
|
| 144 | - 'data' => [ |
|
| 145 | - 'message' => $this->l->t('No user supplied'), |
|
| 146 | - ], |
|
| 147 | - ]); |
|
| 148 | - } |
|
| 130 | + /** |
|
| 131 | + * @NoAdminRequired |
|
| 132 | + * @PasswordConfirmationRequired |
|
| 133 | + * |
|
| 134 | + * @param string $username |
|
| 135 | + * @param string $password |
|
| 136 | + * @param string $recoveryPassword |
|
| 137 | + * |
|
| 138 | + * @return JSONResponse |
|
| 139 | + */ |
|
| 140 | + public function changeUserPassword(string $username = null, string $password = null, string $recoveryPassword = null): JSONResponse { |
|
| 141 | + if ($username === null) { |
|
| 142 | + return new JSONResponse([ |
|
| 143 | + 'status' => 'error', |
|
| 144 | + 'data' => [ |
|
| 145 | + 'message' => $this->l->t('No user supplied'), |
|
| 146 | + ], |
|
| 147 | + ]); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - if ($password === null) { |
|
| 151 | - return new JSONResponse([ |
|
| 152 | - 'status' => 'error', |
|
| 153 | - 'data' => [ |
|
| 154 | - 'message' => $this->l->t('Unable to change password'), |
|
| 155 | - ], |
|
| 156 | - ]); |
|
| 157 | - } |
|
| 150 | + if ($password === null) { |
|
| 151 | + return new JSONResponse([ |
|
| 152 | + 'status' => 'error', |
|
| 153 | + 'data' => [ |
|
| 154 | + 'message' => $this->l->t('Unable to change password'), |
|
| 155 | + ], |
|
| 156 | + ]); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - $currentUser = $this->userSession->getUser(); |
|
| 160 | - $targetUser = $this->userManager->get($username); |
|
| 161 | - if ($currentUser === null || $targetUser === null || |
|
| 162 | - !($this->groupManager->isAdmin($this->userId) || |
|
| 163 | - $this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $targetUser)) |
|
| 164 | - ) { |
|
| 165 | - return new JSONResponse([ |
|
| 166 | - 'status' => 'error', |
|
| 167 | - 'data' => [ |
|
| 168 | - 'message' => $this->l->t('Authentication error'), |
|
| 169 | - ], |
|
| 170 | - ]); |
|
| 171 | - } |
|
| 159 | + $currentUser = $this->userSession->getUser(); |
|
| 160 | + $targetUser = $this->userManager->get($username); |
|
| 161 | + if ($currentUser === null || $targetUser === null || |
|
| 162 | + !($this->groupManager->isAdmin($this->userId) || |
|
| 163 | + $this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $targetUser)) |
|
| 164 | + ) { |
|
| 165 | + return new JSONResponse([ |
|
| 166 | + 'status' => 'error', |
|
| 167 | + 'data' => [ |
|
| 168 | + 'message' => $this->l->t('Authentication error'), |
|
| 169 | + ], |
|
| 170 | + ]); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - if ($this->appManager->isEnabledForUser('encryption')) { |
|
| 174 | - //handle the recovery case |
|
| 175 | - $crypt = new \OCA\Encryption\Crypto\Crypt( |
|
| 176 | - \OC::$server->getLogger(), |
|
| 177 | - \OC::$server->getUserSession(), |
|
| 178 | - \OC::$server->getConfig(), |
|
| 179 | - \OC::$server->getL10N('encryption')); |
|
| 180 | - $keyStorage = \OC::$server->getEncryptionKeyStorage(); |
|
| 181 | - $util = new \OCA\Encryption\Util( |
|
| 182 | - new \OC\Files\View(), |
|
| 183 | - $crypt, |
|
| 184 | - \OC::$server->getLogger(), |
|
| 185 | - \OC::$server->getUserSession(), |
|
| 186 | - \OC::$server->getConfig(), |
|
| 187 | - \OC::$server->getUserManager()); |
|
| 188 | - $keyManager = new \OCA\Encryption\KeyManager( |
|
| 189 | - $keyStorage, |
|
| 190 | - $crypt, |
|
| 191 | - \OC::$server->getConfig(), |
|
| 192 | - \OC::$server->getUserSession(), |
|
| 193 | - new \OCA\Encryption\Session(\OC::$server->getSession()), |
|
| 194 | - \OC::$server->getLogger(), |
|
| 195 | - $util); |
|
| 196 | - $recovery = new \OCA\Encryption\Recovery( |
|
| 197 | - \OC::$server->getUserSession(), |
|
| 198 | - $crypt, |
|
| 199 | - \OC::$server->getSecureRandom(), |
|
| 200 | - $keyManager, |
|
| 201 | - \OC::$server->getConfig(), |
|
| 202 | - $keyStorage, |
|
| 203 | - \OC::$server->getEncryptionFilesHelper(), |
|
| 204 | - new \OC\Files\View()); |
|
| 205 | - $recoveryAdminEnabled = $recovery->isRecoveryKeyEnabled(); |
|
| 173 | + if ($this->appManager->isEnabledForUser('encryption')) { |
|
| 174 | + //handle the recovery case |
|
| 175 | + $crypt = new \OCA\Encryption\Crypto\Crypt( |
|
| 176 | + \OC::$server->getLogger(), |
|
| 177 | + \OC::$server->getUserSession(), |
|
| 178 | + \OC::$server->getConfig(), |
|
| 179 | + \OC::$server->getL10N('encryption')); |
|
| 180 | + $keyStorage = \OC::$server->getEncryptionKeyStorage(); |
|
| 181 | + $util = new \OCA\Encryption\Util( |
|
| 182 | + new \OC\Files\View(), |
|
| 183 | + $crypt, |
|
| 184 | + \OC::$server->getLogger(), |
|
| 185 | + \OC::$server->getUserSession(), |
|
| 186 | + \OC::$server->getConfig(), |
|
| 187 | + \OC::$server->getUserManager()); |
|
| 188 | + $keyManager = new \OCA\Encryption\KeyManager( |
|
| 189 | + $keyStorage, |
|
| 190 | + $crypt, |
|
| 191 | + \OC::$server->getConfig(), |
|
| 192 | + \OC::$server->getUserSession(), |
|
| 193 | + new \OCA\Encryption\Session(\OC::$server->getSession()), |
|
| 194 | + \OC::$server->getLogger(), |
|
| 195 | + $util); |
|
| 196 | + $recovery = new \OCA\Encryption\Recovery( |
|
| 197 | + \OC::$server->getUserSession(), |
|
| 198 | + $crypt, |
|
| 199 | + \OC::$server->getSecureRandom(), |
|
| 200 | + $keyManager, |
|
| 201 | + \OC::$server->getConfig(), |
|
| 202 | + $keyStorage, |
|
| 203 | + \OC::$server->getEncryptionFilesHelper(), |
|
| 204 | + new \OC\Files\View()); |
|
| 205 | + $recoveryAdminEnabled = $recovery->isRecoveryKeyEnabled(); |
|
| 206 | 206 | |
| 207 | - $validRecoveryPassword = false; |
|
| 208 | - $recoveryEnabledForUser = false; |
|
| 209 | - if ($recoveryAdminEnabled) { |
|
| 210 | - $validRecoveryPassword = $keyManager->checkRecoveryPassword($recoveryPassword); |
|
| 211 | - $recoveryEnabledForUser = $recovery->isRecoveryEnabledForUser($username); |
|
| 212 | - } |
|
| 207 | + $validRecoveryPassword = false; |
|
| 208 | + $recoveryEnabledForUser = false; |
|
| 209 | + if ($recoveryAdminEnabled) { |
|
| 210 | + $validRecoveryPassword = $keyManager->checkRecoveryPassword($recoveryPassword); |
|
| 211 | + $recoveryEnabledForUser = $recovery->isRecoveryEnabledForUser($username); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - if ($recoveryEnabledForUser && $recoveryPassword === '') { |
|
| 215 | - return new JSONResponse([ |
|
| 216 | - 'status' => 'error', |
|
| 217 | - 'data' => [ |
|
| 218 | - 'message' => $this->l->t('Please provide an admin recovery password; otherwise, all user data will be lost.'), |
|
| 219 | - ] |
|
| 220 | - ]); |
|
| 221 | - } elseif ($recoveryEnabledForUser && ! $validRecoveryPassword) { |
|
| 222 | - return new JSONResponse([ |
|
| 223 | - 'status' => 'error', |
|
| 224 | - 'data' => [ |
|
| 225 | - 'message' => $this->l->t('Wrong admin recovery password. Please check the password and try again.'), |
|
| 226 | - ] |
|
| 227 | - ]); |
|
| 228 | - } else { // now we know that everything is fine regarding the recovery password, let's try to change the password |
|
| 229 | - try { |
|
| 230 | - $result = $targetUser->setPassword($password, $recoveryPassword); |
|
| 231 | - // password policy app throws exception |
|
| 232 | - } catch(HintException $e) { |
|
| 233 | - return new JSONResponse([ |
|
| 234 | - 'status' => 'error', |
|
| 235 | - 'data' => [ |
|
| 236 | - 'message' => $e->getHint(), |
|
| 237 | - ], |
|
| 238 | - ]); |
|
| 239 | - } |
|
| 240 | - if (!$result && $recoveryEnabledForUser) { |
|
| 241 | - return new JSONResponse([ |
|
| 242 | - 'status' => 'error', |
|
| 243 | - 'data' => [ |
|
| 244 | - 'message' => $this->l->t('Backend doesn\'t support password change, but the user\'s encryption key was updated.'), |
|
| 245 | - ] |
|
| 246 | - ]); |
|
| 247 | - } elseif (!$result && !$recoveryEnabledForUser) { |
|
| 248 | - return new JSONResponse([ |
|
| 249 | - 'status' => 'error', |
|
| 250 | - 'data' => [ |
|
| 251 | - 'message' => $this->l->t('Unable to change password'), |
|
| 252 | - ] |
|
| 253 | - ]); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } else { |
|
| 257 | - try { |
|
| 258 | - if ($targetUser->setPassword($password) === false) { |
|
| 259 | - return new JSONResponse([ |
|
| 260 | - 'status' => 'error', |
|
| 261 | - 'data' => [ |
|
| 262 | - 'message' => $this->l->t('Unable to change password'), |
|
| 263 | - ], |
|
| 264 | - ]); |
|
| 265 | - } |
|
| 266 | - // password policy app throws exception |
|
| 267 | - } catch(HintException $e) { |
|
| 268 | - return new JSONResponse([ |
|
| 269 | - 'status' => 'error', |
|
| 270 | - 'data' => [ |
|
| 271 | - 'message' => $e->getHint(), |
|
| 272 | - ], |
|
| 273 | - ]); |
|
| 274 | - } |
|
| 275 | - } |
|
| 214 | + if ($recoveryEnabledForUser && $recoveryPassword === '') { |
|
| 215 | + return new JSONResponse([ |
|
| 216 | + 'status' => 'error', |
|
| 217 | + 'data' => [ |
|
| 218 | + 'message' => $this->l->t('Please provide an admin recovery password; otherwise, all user data will be lost.'), |
|
| 219 | + ] |
|
| 220 | + ]); |
|
| 221 | + } elseif ($recoveryEnabledForUser && ! $validRecoveryPassword) { |
|
| 222 | + return new JSONResponse([ |
|
| 223 | + 'status' => 'error', |
|
| 224 | + 'data' => [ |
|
| 225 | + 'message' => $this->l->t('Wrong admin recovery password. Please check the password and try again.'), |
|
| 226 | + ] |
|
| 227 | + ]); |
|
| 228 | + } else { // now we know that everything is fine regarding the recovery password, let's try to change the password |
|
| 229 | + try { |
|
| 230 | + $result = $targetUser->setPassword($password, $recoveryPassword); |
|
| 231 | + // password policy app throws exception |
|
| 232 | + } catch(HintException $e) { |
|
| 233 | + return new JSONResponse([ |
|
| 234 | + 'status' => 'error', |
|
| 235 | + 'data' => [ |
|
| 236 | + 'message' => $e->getHint(), |
|
| 237 | + ], |
|
| 238 | + ]); |
|
| 239 | + } |
|
| 240 | + if (!$result && $recoveryEnabledForUser) { |
|
| 241 | + return new JSONResponse([ |
|
| 242 | + 'status' => 'error', |
|
| 243 | + 'data' => [ |
|
| 244 | + 'message' => $this->l->t('Backend doesn\'t support password change, but the user\'s encryption key was updated.'), |
|
| 245 | + ] |
|
| 246 | + ]); |
|
| 247 | + } elseif (!$result && !$recoveryEnabledForUser) { |
|
| 248 | + return new JSONResponse([ |
|
| 249 | + 'status' => 'error', |
|
| 250 | + 'data' => [ |
|
| 251 | + 'message' => $this->l->t('Unable to change password'), |
|
| 252 | + ] |
|
| 253 | + ]); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } else { |
|
| 257 | + try { |
|
| 258 | + if ($targetUser->setPassword($password) === false) { |
|
| 259 | + return new JSONResponse([ |
|
| 260 | + 'status' => 'error', |
|
| 261 | + 'data' => [ |
|
| 262 | + 'message' => $this->l->t('Unable to change password'), |
|
| 263 | + ], |
|
| 264 | + ]); |
|
| 265 | + } |
|
| 266 | + // password policy app throws exception |
|
| 267 | + } catch(HintException $e) { |
|
| 268 | + return new JSONResponse([ |
|
| 269 | + 'status' => 'error', |
|
| 270 | + 'data' => [ |
|
| 271 | + 'message' => $e->getHint(), |
|
| 272 | + ], |
|
| 273 | + ]); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - return new JSONResponse([ |
|
| 278 | - 'status' => 'success', |
|
| 279 | - 'data' => [ |
|
| 280 | - 'username' => $username, |
|
| 281 | - ], |
|
| 282 | - ]); |
|
| 283 | - } |
|
| 277 | + return new JSONResponse([ |
|
| 278 | + 'status' => 'success', |
|
| 279 | + 'data' => [ |
|
| 280 | + 'username' => $username, |
|
| 281 | + ], |
|
| 282 | + ]); |
|
| 283 | + } |
|
| 284 | 284 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
| 100 | 100 | // remote server revoked access to the address book, remove it |
| 101 | 101 | $this->backend->deleteAddressBook($addressBookId); |
| 102 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 102 | + $this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']); |
|
| 103 | 103 | throw $ex; |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function getClient($url, $userName, $sharedSecret) { |
| 151 | 151 | $settings = [ |
| 152 | - 'baseUri' => $url . '/', |
|
| 152 | + 'baseUri' => $url.'/', |
|
| 153 | 153 | 'userName' => $userName, |
| 154 | 154 | 'password' => $sharedSecret, |
| 155 | 155 | ]; |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | public function deleteUser($userOrCardId) { |
| 271 | 271 | $systemAddressBook = $this->getLocalSystemAddressBook(); |
| 272 | - if ($userOrCardId instanceof IUser){ |
|
| 272 | + if ($userOrCardId instanceof IUser) { |
|
| 273 | 273 | $name = $userOrCardId->getBackendClassName(); |
| 274 | 274 | $userId = $userOrCardId->getUID(); |
| 275 | 275 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | if (is_null($this->localSystemAddressBook)) { |
| 286 | 286 | $systemPrincipal = "principals/system/system"; |
| 287 | 287 | $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
| 288 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 288 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 289 | 289 | ]); |
| 290 | 290 | } |
| 291 | 291 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | // remove no longer existing |
| 305 | 305 | $allCards = $this->backend->getCards($systemAddressBook['id']); |
| 306 | - foreach($allCards as $card) { |
|
| 306 | + foreach ($allCards as $card) { |
|
| 307 | 307 | $vCard = Reader::read($card['carddata']); |
| 308 | 308 | $uid = $vCard->UID->getValue(); |
| 309 | 309 | // load backend and see if user exists |
@@ -39,304 +39,304 @@ |
||
| 39 | 39 | |
| 40 | 40 | class SyncService { |
| 41 | 41 | |
| 42 | - /** @var CardDavBackend */ |
|
| 43 | - private $backend; |
|
| 44 | - |
|
| 45 | - /** @var IUserManager */ |
|
| 46 | - private $userManager; |
|
| 47 | - |
|
| 48 | - /** @var ILogger */ |
|
| 49 | - private $logger; |
|
| 50 | - |
|
| 51 | - /** @var array */ |
|
| 52 | - private $localSystemAddressBook; |
|
| 53 | - |
|
| 54 | - /** @var AccountManager */ |
|
| 55 | - private $accountManager; |
|
| 56 | - |
|
| 57 | - /** @var string */ |
|
| 58 | - protected $certPath; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * SyncService constructor. |
|
| 62 | - * |
|
| 63 | - * @param CardDavBackend $backend |
|
| 64 | - * @param IUserManager $userManager |
|
| 65 | - * @param ILogger $logger |
|
| 66 | - * @param AccountManager $accountManager |
|
| 67 | - */ |
|
| 68 | - public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
| 69 | - $this->backend = $backend; |
|
| 70 | - $this->userManager = $userManager; |
|
| 71 | - $this->logger = $logger; |
|
| 72 | - $this->accountManager = $accountManager; |
|
| 73 | - $this->certPath = ''; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string $url |
|
| 78 | - * @param string $userName |
|
| 79 | - * @param string $addressBookUrl |
|
| 80 | - * @param string $sharedSecret |
|
| 81 | - * @param string $syncToken |
|
| 82 | - * @param int $targetBookId |
|
| 83 | - * @param string $targetPrincipal |
|
| 84 | - * @param array $targetProperties |
|
| 85 | - * @return string |
|
| 86 | - * @throws \Exception |
|
| 87 | - */ |
|
| 88 | - public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
| 89 | - // 1. create addressbook |
|
| 90 | - $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
| 91 | - $addressBookId = $book['id']; |
|
| 92 | - |
|
| 93 | - // 2. query changes |
|
| 94 | - try { |
|
| 95 | - $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
| 96 | - } catch (ClientHttpException $ex) { |
|
| 97 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
| 98 | - // remote server revoked access to the address book, remove it |
|
| 99 | - $this->backend->deleteAddressBook($addressBookId); |
|
| 100 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 101 | - throw $ex; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // 3. apply changes |
|
| 106 | - // TODO: use multi-get for download |
|
| 107 | - foreach ($response['response'] as $resource => $status) { |
|
| 108 | - $cardUri = basename($resource); |
|
| 109 | - if (isset($status[200])) { |
|
| 110 | - $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
| 111 | - $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
| 112 | - if ($existingCard === false) { |
|
| 113 | - $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
| 114 | - } else { |
|
| 115 | - $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $this->backend->deleteCard($addressBookId, $cardUri); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $response['token']; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param string $principal |
|
| 127 | - * @param string $id |
|
| 128 | - * @param array $properties |
|
| 129 | - * @return array|null |
|
| 130 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 131 | - */ |
|
| 132 | - public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
| 133 | - $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
| 134 | - if (!is_null($book)) { |
|
| 135 | - return $book; |
|
| 136 | - } |
|
| 137 | - $this->backend->createAddressBook($principal, $id, $properties); |
|
| 138 | - |
|
| 139 | - return $this->backend->getAddressBooksByUri($principal, $id); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Check if there is a valid certPath we should use |
|
| 144 | - * |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - protected function getCertPath() { |
|
| 148 | - |
|
| 149 | - // we already have a valid certPath |
|
| 150 | - if ($this->certPath !== '') { |
|
| 151 | - return $this->certPath; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** @var ICertificateManager $certManager */ |
|
| 155 | - $certManager = \OC::$server->getCertificateManager(null); |
|
| 156 | - $certPath = $certManager->getAbsoluteBundlePath(); |
|
| 157 | - if (file_exists($certPath)) { |
|
| 158 | - $this->certPath = $certPath; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $this->certPath; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param string $url |
|
| 166 | - * @param string $userName |
|
| 167 | - * @param string $addressBookUrl |
|
| 168 | - * @param string $sharedSecret |
|
| 169 | - * @return Client |
|
| 170 | - */ |
|
| 171 | - protected function getClient($url, $userName, $sharedSecret) { |
|
| 172 | - $settings = [ |
|
| 173 | - 'baseUri' => $url . '/', |
|
| 174 | - 'userName' => $userName, |
|
| 175 | - 'password' => $sharedSecret, |
|
| 176 | - ]; |
|
| 177 | - $client = new Client($settings); |
|
| 178 | - $certPath = $this->getCertPath(); |
|
| 179 | - $client->setThrowExceptions(true); |
|
| 180 | - |
|
| 181 | - if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
| 182 | - $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return $client; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param string $url |
|
| 190 | - * @param string $userName |
|
| 191 | - * @param string $addressBookUrl |
|
| 192 | - * @param string $sharedSecret |
|
| 193 | - * @param string $syncToken |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
| 197 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 198 | - |
|
| 199 | - $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
| 200 | - |
|
| 201 | - $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
| 202 | - 'Content-Type' => 'application/xml' |
|
| 203 | - ]); |
|
| 204 | - |
|
| 205 | - return $this->parseMultiStatus($response['body']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param string $url |
|
| 210 | - * @param string $userName |
|
| 211 | - * @param string $sharedSecret |
|
| 212 | - * @param string $resourcePath |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
| 216 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 217 | - return $client->request('GET', $resourcePath); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @param string|null $syncToken |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - private function buildSyncCollectionRequestBody($syncToken) { |
|
| 225 | - |
|
| 226 | - $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
| 227 | - $dom->formatOutput = true; |
|
| 228 | - $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
| 229 | - $sync = $dom->createElement('d:sync-token', $syncToken); |
|
| 230 | - $prop = $dom->createElement('d:prop'); |
|
| 231 | - $cont = $dom->createElement('d:getcontenttype'); |
|
| 232 | - $etag = $dom->createElement('d:getetag'); |
|
| 233 | - |
|
| 234 | - $prop->appendChild($cont); |
|
| 235 | - $prop->appendChild($etag); |
|
| 236 | - $root->appendChild($sync); |
|
| 237 | - $root->appendChild($prop); |
|
| 238 | - $dom->appendChild($root); |
|
| 239 | - return $dom->saveXML(); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param string $body |
|
| 244 | - * @return array |
|
| 245 | - * @throws \Sabre\Xml\ParseException |
|
| 246 | - */ |
|
| 247 | - private function parseMultiStatus($body) { |
|
| 248 | - $xml = new Service(); |
|
| 249 | - |
|
| 250 | - /** @var MultiStatus $multiStatus */ |
|
| 251 | - $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
| 252 | - |
|
| 253 | - $result = []; |
|
| 254 | - foreach ($multiStatus->getResponses() as $response) { |
|
| 255 | - $result[$response->getHref()] = $response->getResponseProperties(); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @param IUser $user |
|
| 263 | - */ |
|
| 264 | - public function updateUser(IUser $user) { |
|
| 265 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 266 | - $addressBookId = $systemAddressBook['id']; |
|
| 267 | - $converter = new Converter($this->accountManager); |
|
| 268 | - $name = $user->getBackendClassName(); |
|
| 269 | - $userId = $user->getUID(); |
|
| 270 | - |
|
| 271 | - $cardId = "$name:$userId.vcf"; |
|
| 272 | - $card = $this->backend->getCard($addressBookId, $cardId); |
|
| 273 | - if ($user->isEnabled()) { |
|
| 274 | - if ($card === false) { |
|
| 275 | - $vCard = $converter->createCardFromUser($user); |
|
| 276 | - if ($vCard !== null) { |
|
| 277 | - $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 278 | - } |
|
| 279 | - } else { |
|
| 280 | - $vCard = $converter->createCardFromUser($user); |
|
| 281 | - if (is_null($vCard)) { |
|
| 282 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
| 283 | - } else { |
|
| 284 | - $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } else { |
|
| 288 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @param IUser|string $userOrCardId |
|
| 294 | - */ |
|
| 295 | - public function deleteUser($userOrCardId) { |
|
| 296 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 297 | - if ($userOrCardId instanceof IUser){ |
|
| 298 | - $name = $userOrCardId->getBackendClassName(); |
|
| 299 | - $userId = $userOrCardId->getUID(); |
|
| 300 | - |
|
| 301 | - $userOrCardId = "$name:$userId.vcf"; |
|
| 302 | - } |
|
| 303 | - $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @return array|null |
|
| 308 | - */ |
|
| 309 | - public function getLocalSystemAddressBook() { |
|
| 310 | - if (is_null($this->localSystemAddressBook)) { |
|
| 311 | - $systemPrincipal = "principals/system/system"; |
|
| 312 | - $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
| 313 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 314 | - ]); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - return $this->localSystemAddressBook; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - public function syncInstance(\Closure $progressCallback = null) { |
|
| 321 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 322 | - $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
| 323 | - $this->updateUser($user); |
|
| 324 | - if (!is_null($progressCallback)) { |
|
| 325 | - $progressCallback(); |
|
| 326 | - } |
|
| 327 | - }); |
|
| 328 | - |
|
| 329 | - // remove no longer existing |
|
| 330 | - $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
| 331 | - foreach($allCards as $card) { |
|
| 332 | - $vCard = Reader::read($card['carddata']); |
|
| 333 | - $uid = $vCard->UID->getValue(); |
|
| 334 | - // load backend and see if user exists |
|
| 335 | - if (!$this->userManager->userExists($uid)) { |
|
| 336 | - $this->deleteUser($card['uri']); |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - } |
|
| 42 | + /** @var CardDavBackend */ |
|
| 43 | + private $backend; |
|
| 44 | + |
|
| 45 | + /** @var IUserManager */ |
|
| 46 | + private $userManager; |
|
| 47 | + |
|
| 48 | + /** @var ILogger */ |
|
| 49 | + private $logger; |
|
| 50 | + |
|
| 51 | + /** @var array */ |
|
| 52 | + private $localSystemAddressBook; |
|
| 53 | + |
|
| 54 | + /** @var AccountManager */ |
|
| 55 | + private $accountManager; |
|
| 56 | + |
|
| 57 | + /** @var string */ |
|
| 58 | + protected $certPath; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * SyncService constructor. |
|
| 62 | + * |
|
| 63 | + * @param CardDavBackend $backend |
|
| 64 | + * @param IUserManager $userManager |
|
| 65 | + * @param ILogger $logger |
|
| 66 | + * @param AccountManager $accountManager |
|
| 67 | + */ |
|
| 68 | + public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
| 69 | + $this->backend = $backend; |
|
| 70 | + $this->userManager = $userManager; |
|
| 71 | + $this->logger = $logger; |
|
| 72 | + $this->accountManager = $accountManager; |
|
| 73 | + $this->certPath = ''; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string $url |
|
| 78 | + * @param string $userName |
|
| 79 | + * @param string $addressBookUrl |
|
| 80 | + * @param string $sharedSecret |
|
| 81 | + * @param string $syncToken |
|
| 82 | + * @param int $targetBookId |
|
| 83 | + * @param string $targetPrincipal |
|
| 84 | + * @param array $targetProperties |
|
| 85 | + * @return string |
|
| 86 | + * @throws \Exception |
|
| 87 | + */ |
|
| 88 | + public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
| 89 | + // 1. create addressbook |
|
| 90 | + $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
| 91 | + $addressBookId = $book['id']; |
|
| 92 | + |
|
| 93 | + // 2. query changes |
|
| 94 | + try { |
|
| 95 | + $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
| 96 | + } catch (ClientHttpException $ex) { |
|
| 97 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
| 98 | + // remote server revoked access to the address book, remove it |
|
| 99 | + $this->backend->deleteAddressBook($addressBookId); |
|
| 100 | + $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 101 | + throw $ex; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // 3. apply changes |
|
| 106 | + // TODO: use multi-get for download |
|
| 107 | + foreach ($response['response'] as $resource => $status) { |
|
| 108 | + $cardUri = basename($resource); |
|
| 109 | + if (isset($status[200])) { |
|
| 110 | + $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
| 111 | + $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
| 112 | + if ($existingCard === false) { |
|
| 113 | + $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
| 114 | + } else { |
|
| 115 | + $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $this->backend->deleteCard($addressBookId, $cardUri); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $response['token']; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param string $principal |
|
| 127 | + * @param string $id |
|
| 128 | + * @param array $properties |
|
| 129 | + * @return array|null |
|
| 130 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 131 | + */ |
|
| 132 | + public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
| 133 | + $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
| 134 | + if (!is_null($book)) { |
|
| 135 | + return $book; |
|
| 136 | + } |
|
| 137 | + $this->backend->createAddressBook($principal, $id, $properties); |
|
| 138 | + |
|
| 139 | + return $this->backend->getAddressBooksByUri($principal, $id); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Check if there is a valid certPath we should use |
|
| 144 | + * |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + protected function getCertPath() { |
|
| 148 | + |
|
| 149 | + // we already have a valid certPath |
|
| 150 | + if ($this->certPath !== '') { |
|
| 151 | + return $this->certPath; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** @var ICertificateManager $certManager */ |
|
| 155 | + $certManager = \OC::$server->getCertificateManager(null); |
|
| 156 | + $certPath = $certManager->getAbsoluteBundlePath(); |
|
| 157 | + if (file_exists($certPath)) { |
|
| 158 | + $this->certPath = $certPath; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $this->certPath; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param string $url |
|
| 166 | + * @param string $userName |
|
| 167 | + * @param string $addressBookUrl |
|
| 168 | + * @param string $sharedSecret |
|
| 169 | + * @return Client |
|
| 170 | + */ |
|
| 171 | + protected function getClient($url, $userName, $sharedSecret) { |
|
| 172 | + $settings = [ |
|
| 173 | + 'baseUri' => $url . '/', |
|
| 174 | + 'userName' => $userName, |
|
| 175 | + 'password' => $sharedSecret, |
|
| 176 | + ]; |
|
| 177 | + $client = new Client($settings); |
|
| 178 | + $certPath = $this->getCertPath(); |
|
| 179 | + $client->setThrowExceptions(true); |
|
| 180 | + |
|
| 181 | + if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
| 182 | + $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return $client; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param string $url |
|
| 190 | + * @param string $userName |
|
| 191 | + * @param string $addressBookUrl |
|
| 192 | + * @param string $sharedSecret |
|
| 193 | + * @param string $syncToken |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
| 197 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 198 | + |
|
| 199 | + $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
| 200 | + |
|
| 201 | + $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
| 202 | + 'Content-Type' => 'application/xml' |
|
| 203 | + ]); |
|
| 204 | + |
|
| 205 | + return $this->parseMultiStatus($response['body']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param string $url |
|
| 210 | + * @param string $userName |
|
| 211 | + * @param string $sharedSecret |
|
| 212 | + * @param string $resourcePath |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
| 216 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 217 | + return $client->request('GET', $resourcePath); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @param string|null $syncToken |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + private function buildSyncCollectionRequestBody($syncToken) { |
|
| 225 | + |
|
| 226 | + $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
| 227 | + $dom->formatOutput = true; |
|
| 228 | + $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
| 229 | + $sync = $dom->createElement('d:sync-token', $syncToken); |
|
| 230 | + $prop = $dom->createElement('d:prop'); |
|
| 231 | + $cont = $dom->createElement('d:getcontenttype'); |
|
| 232 | + $etag = $dom->createElement('d:getetag'); |
|
| 233 | + |
|
| 234 | + $prop->appendChild($cont); |
|
| 235 | + $prop->appendChild($etag); |
|
| 236 | + $root->appendChild($sync); |
|
| 237 | + $root->appendChild($prop); |
|
| 238 | + $dom->appendChild($root); |
|
| 239 | + return $dom->saveXML(); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param string $body |
|
| 244 | + * @return array |
|
| 245 | + * @throws \Sabre\Xml\ParseException |
|
| 246 | + */ |
|
| 247 | + private function parseMultiStatus($body) { |
|
| 248 | + $xml = new Service(); |
|
| 249 | + |
|
| 250 | + /** @var MultiStatus $multiStatus */ |
|
| 251 | + $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
| 252 | + |
|
| 253 | + $result = []; |
|
| 254 | + foreach ($multiStatus->getResponses() as $response) { |
|
| 255 | + $result[$response->getHref()] = $response->getResponseProperties(); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @param IUser $user |
|
| 263 | + */ |
|
| 264 | + public function updateUser(IUser $user) { |
|
| 265 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 266 | + $addressBookId = $systemAddressBook['id']; |
|
| 267 | + $converter = new Converter($this->accountManager); |
|
| 268 | + $name = $user->getBackendClassName(); |
|
| 269 | + $userId = $user->getUID(); |
|
| 270 | + |
|
| 271 | + $cardId = "$name:$userId.vcf"; |
|
| 272 | + $card = $this->backend->getCard($addressBookId, $cardId); |
|
| 273 | + if ($user->isEnabled()) { |
|
| 274 | + if ($card === false) { |
|
| 275 | + $vCard = $converter->createCardFromUser($user); |
|
| 276 | + if ($vCard !== null) { |
|
| 277 | + $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 278 | + } |
|
| 279 | + } else { |
|
| 280 | + $vCard = $converter->createCardFromUser($user); |
|
| 281 | + if (is_null($vCard)) { |
|
| 282 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
| 283 | + } else { |
|
| 284 | + $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } else { |
|
| 288 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @param IUser|string $userOrCardId |
|
| 294 | + */ |
|
| 295 | + public function deleteUser($userOrCardId) { |
|
| 296 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 297 | + if ($userOrCardId instanceof IUser){ |
|
| 298 | + $name = $userOrCardId->getBackendClassName(); |
|
| 299 | + $userId = $userOrCardId->getUID(); |
|
| 300 | + |
|
| 301 | + $userOrCardId = "$name:$userId.vcf"; |
|
| 302 | + } |
|
| 303 | + $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @return array|null |
|
| 308 | + */ |
|
| 309 | + public function getLocalSystemAddressBook() { |
|
| 310 | + if (is_null($this->localSystemAddressBook)) { |
|
| 311 | + $systemPrincipal = "principals/system/system"; |
|
| 312 | + $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
| 313 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 314 | + ]); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + return $this->localSystemAddressBook; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + public function syncInstance(\Closure $progressCallback = null) { |
|
| 321 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 322 | + $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
| 323 | + $this->updateUser($user); |
|
| 324 | + if (!is_null($progressCallback)) { |
|
| 325 | + $progressCallback(); |
|
| 326 | + } |
|
| 327 | + }); |
|
| 328 | + |
|
| 329 | + // remove no longer existing |
|
| 330 | + $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
| 331 | + foreach($allCards as $card) { |
|
| 332 | + $vCard = Reader::read($card['carddata']); |
|
| 333 | + $uid = $vCard->UID->getValue(); |
|
| 334 | + // load backend and see if user exists |
|
| 335 | + if (!$this->userManager->userExists($uid)) { |
|
| 336 | + $this->deleteUser($card['uri']); |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | 341 | |
| 342 | 342 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param \OCP\Files\Mount\IMountPoint $mount |
| 88 | 88 | * @param \OCP\IUser|null $owner |
| 89 | 89 | */ |
| 90 | - public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
| 90 | + public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) { |
|
| 91 | 91 | $this->path = $path; |
| 92 | 92 | $this->storage = $storage; |
| 93 | 93 | $this->internalPath = $internalPath; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return int|null |
| 154 | 154 | */ |
| 155 | 155 | public function getId() { |
| 156 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 156 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | public function getEtag() { |
| 184 | 184 | $this->updateEntryfromSubMounts(); |
| 185 | 185 | if (count($this->childEtags) > 0) { |
| 186 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 186 | + $combinedEtag = $this->data['etag'].'::'.implode('::', $this->childEtags); |
|
| 187 | 187 | return md5($combinedEtag); |
| 188 | 188 | } else { |
| 189 | 189 | return $this->data['etag']; |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
| 380 | 380 | // attach the permissions to propagate etag on permision changes of submounts |
| 381 | 381 | $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
| 382 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 382 | + $this->childEtags[] = $relativeEntryPath.'/'.$data['etag'].$permissions; |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
@@ -38,360 +38,360 @@ |
||
| 38 | 38 | use OCP\IUser; |
| 39 | 39 | |
| 40 | 40 | class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { |
| 41 | - /** |
|
| 42 | - * @var array $data |
|
| 43 | - */ |
|
| 44 | - private $data; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $path |
|
| 48 | - */ |
|
| 49 | - private $path; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var \OC\Files\Storage\Storage $storage |
|
| 53 | - */ |
|
| 54 | - private $storage; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var string $internalPath |
|
| 58 | - */ |
|
| 59 | - private $internalPath; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var \OCP\Files\Mount\IMountPoint |
|
| 63 | - */ |
|
| 64 | - private $mount; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var IUser |
|
| 68 | - */ |
|
| 69 | - private $owner; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string[] |
|
| 73 | - */ |
|
| 74 | - private $childEtags = []; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var IMountPoint[] |
|
| 78 | - */ |
|
| 79 | - private $subMounts = []; |
|
| 80 | - |
|
| 81 | - private $subMountsUsed = false; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param string|boolean $path |
|
| 85 | - * @param Storage\Storage $storage |
|
| 86 | - * @param string $internalPath |
|
| 87 | - * @param array|ICacheEntry $data |
|
| 88 | - * @param \OCP\Files\Mount\IMountPoint $mount |
|
| 89 | - * @param \OCP\IUser|null $owner |
|
| 90 | - */ |
|
| 91 | - public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
| 92 | - $this->path = $path; |
|
| 93 | - $this->storage = $storage; |
|
| 94 | - $this->internalPath = $internalPath; |
|
| 95 | - $this->data = $data; |
|
| 96 | - $this->mount = $mount; |
|
| 97 | - $this->owner = $owner; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - public function offsetSet($offset, $value) { |
|
| 101 | - $this->data[$offset] = $value; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function offsetExists($offset) { |
|
| 105 | - return isset($this->data[$offset]); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function offsetUnset($offset) { |
|
| 109 | - unset($this->data[$offset]); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function offsetGet($offset) { |
|
| 113 | - if ($offset === 'type') { |
|
| 114 | - return $this->getType(); |
|
| 115 | - } else if ($offset === 'etag') { |
|
| 116 | - return $this->getEtag(); |
|
| 117 | - } else if ($offset === 'size') { |
|
| 118 | - return $this->getSize(); |
|
| 119 | - } else if ($offset === 'mtime') { |
|
| 120 | - return $this->getMTime(); |
|
| 121 | - } elseif ($offset === 'permissions') { |
|
| 122 | - return $this->getPermissions(); |
|
| 123 | - } elseif (isset($this->data[$offset])) { |
|
| 124 | - return $this->data[$offset]; |
|
| 125 | - } else { |
|
| 126 | - return null; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function getPath() { |
|
| 134 | - return $this->path; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return \OCP\Files\Storage |
|
| 139 | - */ |
|
| 140 | - public function getStorage() { |
|
| 141 | - return $this->storage; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - public function getInternalPath() { |
|
| 148 | - return $this->internalPath; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Get FileInfo ID or null in case of part file |
|
| 153 | - * |
|
| 154 | - * @return int|null |
|
| 155 | - */ |
|
| 156 | - public function getId() { |
|
| 157 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @return string |
|
| 162 | - */ |
|
| 163 | - public function getMimetype() { |
|
| 164 | - return $this->data['mimetype']; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function getMimePart() { |
|
| 171 | - return $this->data['mimepart']; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public function getName() { |
|
| 178 | - return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @return string |
|
| 183 | - */ |
|
| 184 | - public function getEtag() { |
|
| 185 | - $this->updateEntryfromSubMounts(); |
|
| 186 | - if (count($this->childEtags) > 0) { |
|
| 187 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 188 | - return md5($combinedEtag); |
|
| 189 | - } else { |
|
| 190 | - return $this->data['etag']; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @return int |
|
| 196 | - */ |
|
| 197 | - public function getSize() { |
|
| 198 | - $this->updateEntryfromSubMounts(); |
|
| 199 | - return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @return int |
|
| 204 | - */ |
|
| 205 | - public function getMTime() { |
|
| 206 | - $this->updateEntryfromSubMounts(); |
|
| 207 | - return (int) $this->data['mtime']; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @return bool |
|
| 212 | - */ |
|
| 213 | - public function isEncrypted() { |
|
| 214 | - return $this->data['encrypted']; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Return the currently version used for the HMAC in the encryption app |
|
| 219 | - * |
|
| 220 | - * @return int |
|
| 221 | - */ |
|
| 222 | - public function getEncryptedVersion() { |
|
| 223 | - return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return int |
|
| 228 | - */ |
|
| 229 | - public function getPermissions() { |
|
| 230 | - $perms = (int) $this->data['permissions']; |
|
| 231 | - if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
| 232 | - $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
| 233 | - } |
|
| 234 | - return (int) $perms; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
| 239 | - */ |
|
| 240 | - public function getType() { |
|
| 241 | - if (!isset($this->data['type'])) { |
|
| 242 | - $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
| 243 | - } |
|
| 244 | - return $this->data['type']; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - public function getData() { |
|
| 248 | - return $this->data; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @param int $permissions |
|
| 253 | - * @return bool |
|
| 254 | - */ |
|
| 255 | - protected function checkPermissions($permissions) { |
|
| 256 | - return ($this->getPermissions() & $permissions) === $permissions; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return bool |
|
| 261 | - */ |
|
| 262 | - public function isReadable() { |
|
| 263 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @return bool |
|
| 268 | - */ |
|
| 269 | - public function isUpdateable() { |
|
| 270 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Check whether new files or folders can be created inside this folder |
|
| 275 | - * |
|
| 276 | - * @return bool |
|
| 277 | - */ |
|
| 278 | - public function isCreatable() { |
|
| 279 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @return bool |
|
| 284 | - */ |
|
| 285 | - public function isDeletable() { |
|
| 286 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @return bool |
|
| 291 | - */ |
|
| 292 | - public function isShareable() { |
|
| 293 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Check if a file or folder is shared |
|
| 298 | - * |
|
| 299 | - * @return bool |
|
| 300 | - */ |
|
| 301 | - public function isShared() { |
|
| 302 | - $sid = $this->getStorage()->getId(); |
|
| 303 | - if (!is_null($sid)) { |
|
| 304 | - $sid = explode(':', $sid); |
|
| 305 | - return ($sid[0] === 'shared'); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return false; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - public function isMounted() { |
|
| 312 | - $storage = $this->getStorage(); |
|
| 313 | - if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 314 | - return false; |
|
| 315 | - } |
|
| 316 | - $sid = $storage->getId(); |
|
| 317 | - if (!is_null($sid)) { |
|
| 318 | - $sid = explode(':', $sid); |
|
| 319 | - return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Get the mountpoint the file belongs to |
|
| 327 | - * |
|
| 328 | - * @return \OCP\Files\Mount\IMountPoint |
|
| 329 | - */ |
|
| 330 | - public function getMountPoint() { |
|
| 331 | - return $this->mount; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Get the owner of the file |
|
| 336 | - * |
|
| 337 | - * @return \OCP\IUser |
|
| 338 | - */ |
|
| 339 | - public function getOwner() { |
|
| 340 | - return $this->owner; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @param IMountPoint[] $mounts |
|
| 345 | - */ |
|
| 346 | - public function setSubMounts(array $mounts) { |
|
| 347 | - $this->subMounts = $mounts; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - private function updateEntryfromSubMounts() { |
|
| 351 | - if ($this->subMountsUsed) { |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - $this->subMountsUsed = true; |
|
| 355 | - foreach ($this->subMounts as $mount) { |
|
| 356 | - $subStorage = $mount->getStorage(); |
|
| 357 | - if ($subStorage) { |
|
| 358 | - $subCache = $subStorage->getCache(''); |
|
| 359 | - $rootEntry = $subCache->get(''); |
|
| 360 | - $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Add a cache entry which is the child of this folder |
|
| 367 | - * |
|
| 368 | - * Sets the size, etag and size to for cross-storage childs |
|
| 369 | - * |
|
| 370 | - * @param array|ICacheEntry $data cache entry for the child |
|
| 371 | - * @param string $entryPath full path of the child entry |
|
| 372 | - */ |
|
| 373 | - public function addSubEntry($data, $entryPath) { |
|
| 374 | - $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
| 375 | - if (isset($data['mtime'])) { |
|
| 376 | - $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
| 377 | - } |
|
| 378 | - if (isset($data['etag'])) { |
|
| 379 | - // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
| 380 | - $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
| 381 | - // attach the permissions to propagate etag on permision changes of submounts |
|
| 382 | - $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
| 383 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @inheritdoc |
|
| 389 | - */ |
|
| 390 | - public function getChecksum() { |
|
| 391 | - return $this->data['checksum']; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - public function getExtension(): string { |
|
| 395 | - return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
| 396 | - } |
|
| 41 | + /** |
|
| 42 | + * @var array $data |
|
| 43 | + */ |
|
| 44 | + private $data; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $path |
|
| 48 | + */ |
|
| 49 | + private $path; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var \OC\Files\Storage\Storage $storage |
|
| 53 | + */ |
|
| 54 | + private $storage; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var string $internalPath |
|
| 58 | + */ |
|
| 59 | + private $internalPath; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var \OCP\Files\Mount\IMountPoint |
|
| 63 | + */ |
|
| 64 | + private $mount; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var IUser |
|
| 68 | + */ |
|
| 69 | + private $owner; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string[] |
|
| 73 | + */ |
|
| 74 | + private $childEtags = []; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var IMountPoint[] |
|
| 78 | + */ |
|
| 79 | + private $subMounts = []; |
|
| 80 | + |
|
| 81 | + private $subMountsUsed = false; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param string|boolean $path |
|
| 85 | + * @param Storage\Storage $storage |
|
| 86 | + * @param string $internalPath |
|
| 87 | + * @param array|ICacheEntry $data |
|
| 88 | + * @param \OCP\Files\Mount\IMountPoint $mount |
|
| 89 | + * @param \OCP\IUser|null $owner |
|
| 90 | + */ |
|
| 91 | + public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
| 92 | + $this->path = $path; |
|
| 93 | + $this->storage = $storage; |
|
| 94 | + $this->internalPath = $internalPath; |
|
| 95 | + $this->data = $data; |
|
| 96 | + $this->mount = $mount; |
|
| 97 | + $this->owner = $owner; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + public function offsetSet($offset, $value) { |
|
| 101 | + $this->data[$offset] = $value; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function offsetExists($offset) { |
|
| 105 | + return isset($this->data[$offset]); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function offsetUnset($offset) { |
|
| 109 | + unset($this->data[$offset]); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function offsetGet($offset) { |
|
| 113 | + if ($offset === 'type') { |
|
| 114 | + return $this->getType(); |
|
| 115 | + } else if ($offset === 'etag') { |
|
| 116 | + return $this->getEtag(); |
|
| 117 | + } else if ($offset === 'size') { |
|
| 118 | + return $this->getSize(); |
|
| 119 | + } else if ($offset === 'mtime') { |
|
| 120 | + return $this->getMTime(); |
|
| 121 | + } elseif ($offset === 'permissions') { |
|
| 122 | + return $this->getPermissions(); |
|
| 123 | + } elseif (isset($this->data[$offset])) { |
|
| 124 | + return $this->data[$offset]; |
|
| 125 | + } else { |
|
| 126 | + return null; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function getPath() { |
|
| 134 | + return $this->path; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return \OCP\Files\Storage |
|
| 139 | + */ |
|
| 140 | + public function getStorage() { |
|
| 141 | + return $this->storage; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + public function getInternalPath() { |
|
| 148 | + return $this->internalPath; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Get FileInfo ID or null in case of part file |
|
| 153 | + * |
|
| 154 | + * @return int|null |
|
| 155 | + */ |
|
| 156 | + public function getId() { |
|
| 157 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @return string |
|
| 162 | + */ |
|
| 163 | + public function getMimetype() { |
|
| 164 | + return $this->data['mimetype']; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function getMimePart() { |
|
| 171 | + return $this->data['mimepart']; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public function getName() { |
|
| 178 | + return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @return string |
|
| 183 | + */ |
|
| 184 | + public function getEtag() { |
|
| 185 | + $this->updateEntryfromSubMounts(); |
|
| 186 | + if (count($this->childEtags) > 0) { |
|
| 187 | + $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 188 | + return md5($combinedEtag); |
|
| 189 | + } else { |
|
| 190 | + return $this->data['etag']; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @return int |
|
| 196 | + */ |
|
| 197 | + public function getSize() { |
|
| 198 | + $this->updateEntryfromSubMounts(); |
|
| 199 | + return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @return int |
|
| 204 | + */ |
|
| 205 | + public function getMTime() { |
|
| 206 | + $this->updateEntryfromSubMounts(); |
|
| 207 | + return (int) $this->data['mtime']; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @return bool |
|
| 212 | + */ |
|
| 213 | + public function isEncrypted() { |
|
| 214 | + return $this->data['encrypted']; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Return the currently version used for the HMAC in the encryption app |
|
| 219 | + * |
|
| 220 | + * @return int |
|
| 221 | + */ |
|
| 222 | + public function getEncryptedVersion() { |
|
| 223 | + return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return int |
|
| 228 | + */ |
|
| 229 | + public function getPermissions() { |
|
| 230 | + $perms = (int) $this->data['permissions']; |
|
| 231 | + if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
| 232 | + $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
| 233 | + } |
|
| 234 | + return (int) $perms; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
| 239 | + */ |
|
| 240 | + public function getType() { |
|
| 241 | + if (!isset($this->data['type'])) { |
|
| 242 | + $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
| 243 | + } |
|
| 244 | + return $this->data['type']; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + public function getData() { |
|
| 248 | + return $this->data; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @param int $permissions |
|
| 253 | + * @return bool |
|
| 254 | + */ |
|
| 255 | + protected function checkPermissions($permissions) { |
|
| 256 | + return ($this->getPermissions() & $permissions) === $permissions; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return bool |
|
| 261 | + */ |
|
| 262 | + public function isReadable() { |
|
| 263 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @return bool |
|
| 268 | + */ |
|
| 269 | + public function isUpdateable() { |
|
| 270 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Check whether new files or folders can be created inside this folder |
|
| 275 | + * |
|
| 276 | + * @return bool |
|
| 277 | + */ |
|
| 278 | + public function isCreatable() { |
|
| 279 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @return bool |
|
| 284 | + */ |
|
| 285 | + public function isDeletable() { |
|
| 286 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @return bool |
|
| 291 | + */ |
|
| 292 | + public function isShareable() { |
|
| 293 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Check if a file or folder is shared |
|
| 298 | + * |
|
| 299 | + * @return bool |
|
| 300 | + */ |
|
| 301 | + public function isShared() { |
|
| 302 | + $sid = $this->getStorage()->getId(); |
|
| 303 | + if (!is_null($sid)) { |
|
| 304 | + $sid = explode(':', $sid); |
|
| 305 | + return ($sid[0] === 'shared'); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return false; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + public function isMounted() { |
|
| 312 | + $storage = $this->getStorage(); |
|
| 313 | + if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 316 | + $sid = $storage->getId(); |
|
| 317 | + if (!is_null($sid)) { |
|
| 318 | + $sid = explode(':', $sid); |
|
| 319 | + return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Get the mountpoint the file belongs to |
|
| 327 | + * |
|
| 328 | + * @return \OCP\Files\Mount\IMountPoint |
|
| 329 | + */ |
|
| 330 | + public function getMountPoint() { |
|
| 331 | + return $this->mount; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Get the owner of the file |
|
| 336 | + * |
|
| 337 | + * @return \OCP\IUser |
|
| 338 | + */ |
|
| 339 | + public function getOwner() { |
|
| 340 | + return $this->owner; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @param IMountPoint[] $mounts |
|
| 345 | + */ |
|
| 346 | + public function setSubMounts(array $mounts) { |
|
| 347 | + $this->subMounts = $mounts; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + private function updateEntryfromSubMounts() { |
|
| 351 | + if ($this->subMountsUsed) { |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + $this->subMountsUsed = true; |
|
| 355 | + foreach ($this->subMounts as $mount) { |
|
| 356 | + $subStorage = $mount->getStorage(); |
|
| 357 | + if ($subStorage) { |
|
| 358 | + $subCache = $subStorage->getCache(''); |
|
| 359 | + $rootEntry = $subCache->get(''); |
|
| 360 | + $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Add a cache entry which is the child of this folder |
|
| 367 | + * |
|
| 368 | + * Sets the size, etag and size to for cross-storage childs |
|
| 369 | + * |
|
| 370 | + * @param array|ICacheEntry $data cache entry for the child |
|
| 371 | + * @param string $entryPath full path of the child entry |
|
| 372 | + */ |
|
| 373 | + public function addSubEntry($data, $entryPath) { |
|
| 374 | + $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
| 375 | + if (isset($data['mtime'])) { |
|
| 376 | + $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
| 377 | + } |
|
| 378 | + if (isset($data['etag'])) { |
|
| 379 | + // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
| 380 | + $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
| 381 | + // attach the permissions to propagate etag on permision changes of submounts |
|
| 382 | + $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
| 383 | + $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @inheritdoc |
|
| 389 | + */ |
|
| 390 | + public function getChecksum() { |
|
| 391 | + return $this->data['checksum']; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + public function getExtension(): string { |
|
| 395 | + return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
| 396 | + } |
|
| 397 | 397 | } |
@@ -23,86 +23,86 @@ |
||
| 23 | 23 | namespace OC; |
| 24 | 24 | |
| 25 | 25 | class RedisFactory { |
| 26 | - /** @var \Redis */ |
|
| 27 | - private $instance; |
|
| 26 | + /** @var \Redis */ |
|
| 27 | + private $instance; |
|
| 28 | 28 | |
| 29 | - /** @var SystemConfig */ |
|
| 30 | - private $config; |
|
| 29 | + /** @var SystemConfig */ |
|
| 30 | + private $config; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * RedisFactory constructor. |
|
| 34 | - * |
|
| 35 | - * @param SystemConfig $config |
|
| 36 | - */ |
|
| 37 | - public function __construct(SystemConfig $config) { |
|
| 38 | - $this->config = $config; |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * RedisFactory constructor. |
|
| 34 | + * |
|
| 35 | + * @param SystemConfig $config |
|
| 36 | + */ |
|
| 37 | + public function __construct(SystemConfig $config) { |
|
| 38 | + $this->config = $config; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - private function create() { |
|
| 42 | - if ($config = $this->config->getValue('redis.cluster', [])) { |
|
| 43 | - if (!class_exists('RedisCluster')) { |
|
| 44 | - throw new \Exception('Redis Cluster support is not available'); |
|
| 45 | - } |
|
| 46 | - // cluster config |
|
| 47 | - if (isset($config['timeout'])) { |
|
| 48 | - $timeout = $config['timeout']; |
|
| 49 | - } else { |
|
| 50 | - $timeout = null; |
|
| 51 | - } |
|
| 52 | - if (isset($config['read_timeout'])) { |
|
| 53 | - $readTimeout = $config['read_timeout']; |
|
| 54 | - } else { |
|
| 55 | - $readTimeout = null; |
|
| 56 | - } |
|
| 57 | - $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout); |
|
| 41 | + private function create() { |
|
| 42 | + if ($config = $this->config->getValue('redis.cluster', [])) { |
|
| 43 | + if (!class_exists('RedisCluster')) { |
|
| 44 | + throw new \Exception('Redis Cluster support is not available'); |
|
| 45 | + } |
|
| 46 | + // cluster config |
|
| 47 | + if (isset($config['timeout'])) { |
|
| 48 | + $timeout = $config['timeout']; |
|
| 49 | + } else { |
|
| 50 | + $timeout = null; |
|
| 51 | + } |
|
| 52 | + if (isset($config['read_timeout'])) { |
|
| 53 | + $readTimeout = $config['read_timeout']; |
|
| 54 | + } else { |
|
| 55 | + $readTimeout = null; |
|
| 56 | + } |
|
| 57 | + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout); |
|
| 58 | 58 | |
| 59 | - if (isset($config['failover_mode'])) { |
|
| 60 | - $this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']); |
|
| 61 | - } |
|
| 62 | - } else { |
|
| 59 | + if (isset($config['failover_mode'])) { |
|
| 60 | + $this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']); |
|
| 61 | + } |
|
| 62 | + } else { |
|
| 63 | 63 | |
| 64 | - $this->instance = new \Redis(); |
|
| 65 | - $config = $this->config->getValue('redis', []); |
|
| 66 | - if (isset($config['host'])) { |
|
| 67 | - $host = $config['host']; |
|
| 68 | - } else { |
|
| 69 | - $host = '127.0.0.1'; |
|
| 70 | - } |
|
| 71 | - if (isset($config['port'])) { |
|
| 72 | - $port = $config['port']; |
|
| 73 | - } else { |
|
| 74 | - $port = 6379; |
|
| 75 | - } |
|
| 76 | - if (isset($config['timeout'])) { |
|
| 77 | - $timeout = $config['timeout']; |
|
| 78 | - } else { |
|
| 79 | - $timeout = 0.0; // unlimited |
|
| 80 | - } |
|
| 64 | + $this->instance = new \Redis(); |
|
| 65 | + $config = $this->config->getValue('redis', []); |
|
| 66 | + if (isset($config['host'])) { |
|
| 67 | + $host = $config['host']; |
|
| 68 | + } else { |
|
| 69 | + $host = '127.0.0.1'; |
|
| 70 | + } |
|
| 71 | + if (isset($config['port'])) { |
|
| 72 | + $port = $config['port']; |
|
| 73 | + } else { |
|
| 74 | + $port = 6379; |
|
| 75 | + } |
|
| 76 | + if (isset($config['timeout'])) { |
|
| 77 | + $timeout = $config['timeout']; |
|
| 78 | + } else { |
|
| 79 | + $timeout = 0.0; // unlimited |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $this->instance->connect($host, $port, $timeout); |
|
| 83 | - if (isset($config['password']) && $config['password'] !== '') { |
|
| 84 | - $this->instance->auth($config['password']); |
|
| 85 | - } |
|
| 82 | + $this->instance->connect($host, $port, $timeout); |
|
| 83 | + if (isset($config['password']) && $config['password'] !== '') { |
|
| 84 | + $this->instance->auth($config['password']); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - if (isset($config['dbindex'])) { |
|
| 88 | - $this->instance->select($config['dbindex']); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 87 | + if (isset($config['dbindex'])) { |
|
| 88 | + $this->instance->select($config['dbindex']); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function getInstance() { |
|
| 94 | - if (!$this->isAvailable()) { |
|
| 95 | - throw new \Exception('Redis support is not available'); |
|
| 96 | - } |
|
| 97 | - if (!$this->instance instanceof \Redis) { |
|
| 98 | - $this->create(); |
|
| 99 | - } |
|
| 93 | + public function getInstance() { |
|
| 94 | + if (!$this->isAvailable()) { |
|
| 95 | + throw new \Exception('Redis support is not available'); |
|
| 96 | + } |
|
| 97 | + if (!$this->instance instanceof \Redis) { |
|
| 98 | + $this->create(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return $this->instance; |
|
| 102 | - } |
|
| 101 | + return $this->instance; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - public function isAvailable() { |
|
| 105 | - return extension_loaded('redis') |
|
| 106 | - && version_compare(phpversion('redis'), '2.2.5', '>='); |
|
| 107 | - } |
|
| 104 | + public function isAvailable() { |
|
| 105 | + return extension_loaded('redis') |
|
| 106 | + && version_compare(phpversion('redis'), '2.2.5', '>='); |
|
| 107 | + } |
|
| 108 | 108 | } |