@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $this->loadTable($schema, $child); |
| 95 | 95 | break; |
| 96 | 96 | default: |
| 97 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 97 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 98 | 98 | |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | switch ($child->getName()) { |
| 116 | 116 | case 'name': |
| 117 | - $name = (string)$child; |
|
| 117 | + $name = (string) $child; |
|
| 118 | 118 | $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); |
| 119 | 119 | $name = $this->platform->quoteIdentifier($name); |
| 120 | 120 | $table = $schema->createTable($name); |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $this->loadDeclaration($table, $child); |
| 133 | 133 | break; |
| 134 | 134 | default: |
| 135 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 135 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $this->loadIndex($table, $child); |
| 157 | 157 | break; |
| 158 | 158 | default: |
| 159 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 159 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 160 | 160 | |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -168,18 +168,18 @@ discard block |
||
| 168 | 168 | * @throws \DomainException |
| 169 | 169 | */ |
| 170 | 170 | private function loadField($table, $xml) { |
| 171 | - $options = array( 'notnull' => false ); |
|
| 171 | + $options = array('notnull' => false); |
|
| 172 | 172 | foreach ($xml->children() as $child) { |
| 173 | 173 | /** |
| 174 | 174 | * @var \SimpleXMLElement $child |
| 175 | 175 | */ |
| 176 | 176 | switch ($child->getName()) { |
| 177 | 177 | case 'name': |
| 178 | - $name = (string)$child; |
|
| 178 | + $name = (string) $child; |
|
| 179 | 179 | $name = $this->platform->quoteIdentifier($name); |
| 180 | 180 | break; |
| 181 | 181 | case 'type': |
| 182 | - $type = (string)$child; |
|
| 182 | + $type = (string) $child; |
|
| 183 | 183 | switch ($type) { |
| 184 | 184 | case 'text': |
| 185 | 185 | $type = 'string'; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | break; |
| 198 | 198 | case 'length': |
| 199 | - $length = (string)$child; |
|
| 199 | + $length = (string) $child; |
|
| 200 | 200 | $options['length'] = $length; |
| 201 | 201 | break; |
| 202 | 202 | case 'unsigned': |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | $options['autoincrement'] = $autoincrement; |
| 213 | 213 | break; |
| 214 | 214 | case 'default': |
| 215 | - $default = (string)$child; |
|
| 215 | + $default = (string) $child; |
|
| 216 | 216 | $options['default'] = $default; |
| 217 | 217 | break; |
| 218 | 218 | case 'comments': |
| 219 | - $comment = (string)$child; |
|
| 219 | + $comment = (string) $child; |
|
| 220 | 220 | $options['comment'] = $comment; |
| 221 | 221 | break; |
| 222 | 222 | case 'primary': |
@@ -224,15 +224,15 @@ discard block |
||
| 224 | 224 | $options['primary'] = $primary; |
| 225 | 225 | break; |
| 226 | 226 | case 'precision': |
| 227 | - $precision = (string)$child; |
|
| 227 | + $precision = (string) $child; |
|
| 228 | 228 | $options['precision'] = $precision; |
| 229 | 229 | break; |
| 230 | 230 | case 'scale': |
| 231 | - $scale = (string)$child; |
|
| 231 | + $scale = (string) $child; |
|
| 232 | 232 | $options['scale'] = $scale; |
| 233 | 233 | break; |
| 234 | 234 | default: |
| 235 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 235 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 236 | 236 | |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | if ($type === 'integer' && isset($options['default'])) { |
| 257 | - $options['default'] = (int)$options['default']; |
|
| 257 | + $options['default'] = (int) $options['default']; |
|
| 258 | 258 | } |
| 259 | 259 | if ($type === 'integer' && isset($options['length'])) { |
| 260 | 260 | $length = $options['length']; |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | switch ($child->getName()) { |
| 295 | 295 | case 'name': |
| 296 | - $name = (string)$child; |
|
| 296 | + $name = (string) $child; |
|
| 297 | 297 | break; |
| 298 | 298 | case 'primary': |
| 299 | 299 | $primary = $this->asBool($child); |
@@ -308,20 +308,20 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | switch ($field->getName()) { |
| 310 | 310 | case 'name': |
| 311 | - $field_name = (string)$field; |
|
| 311 | + $field_name = (string) $field; |
|
| 312 | 312 | $field_name = $this->platform->quoteIdentifier($field_name); |
| 313 | 313 | $fields[] = $field_name; |
| 314 | 314 | break; |
| 315 | 315 | case 'sorting': |
| 316 | 316 | break; |
| 317 | 317 | default: |
| 318 | - throw new \DomainException('Unknown element: ' . $field->getName()); |
|
| 318 | + throw new \DomainException('Unknown element: '.$field->getName()); |
|
| 319 | 319 | |
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | break; |
| 323 | 323 | default: |
| 324 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 324 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 325 | 325 | |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | } |
| 340 | 340 | } |
| 341 | 341 | } else { |
| 342 | - throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); |
|
| 342 | + throw new \DomainException('Empty index definition: '.$name.' options:'.print_r($fields, true)); |
|
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | 345 | |
@@ -348,13 +348,13 @@ discard block |
||
| 348 | 348 | * @return bool |
| 349 | 349 | */ |
| 350 | 350 | private function asBool($xml) { |
| 351 | - $result = (string)$xml; |
|
| 351 | + $result = (string) $xml; |
|
| 352 | 352 | if ($result == 'true') { |
| 353 | 353 | $result = true; |
| 354 | 354 | } elseif ($result == 'false') { |
| 355 | 355 | $result = false; |
| 356 | 356 | } |
| 357 | - return (bool)$result; |
|
| 357 | + return (bool) $result; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | } |
@@ -39,313 +39,313 @@ |
||
| 39 | 39 | |
| 40 | 40 | class MDB2SchemaReader { |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string $DBTABLEPREFIX |
|
| 44 | - */ |
|
| 45 | - protected $DBTABLEPREFIX; |
|
| 42 | + /** |
|
| 43 | + * @var string $DBTABLEPREFIX |
|
| 44 | + */ |
|
| 45 | + protected $DBTABLEPREFIX; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
| 49 | - */ |
|
| 50 | - protected $platform; |
|
| 47 | + /** |
|
| 48 | + * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
| 49 | + */ |
|
| 50 | + protected $platform; |
|
| 51 | 51 | |
| 52 | - /** @var IConfig */ |
|
| 53 | - protected $config; |
|
| 52 | + /** @var IConfig */ |
|
| 53 | + protected $config; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param \OCP\IConfig $config |
|
| 57 | - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
| 58 | - */ |
|
| 59 | - public function __construct(IConfig $config, AbstractPlatform $platform) { |
|
| 60 | - $this->platform = $platform; |
|
| 61 | - $this->config = $config; |
|
| 62 | - $this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_'); |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * @param \OCP\IConfig $config |
|
| 57 | + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
| 58 | + */ |
|
| 59 | + public function __construct(IConfig $config, AbstractPlatform $platform) { |
|
| 60 | + $this->platform = $platform; |
|
| 61 | + $this->config = $config; |
|
| 62 | + $this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_'); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param string $file |
|
| 67 | - * @param Schema $schema |
|
| 68 | - * @return Schema |
|
| 69 | - * @throws \DomainException |
|
| 70 | - */ |
|
| 71 | - public function loadSchemaFromFile($file, Schema $schema) { |
|
| 72 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 73 | - $xml = simplexml_load_file($file); |
|
| 74 | - libxml_disable_entity_loader($loadEntities); |
|
| 75 | - foreach ($xml->children() as $child) { |
|
| 76 | - /** |
|
| 77 | - * @var \SimpleXMLElement $child |
|
| 78 | - */ |
|
| 79 | - switch ($child->getName()) { |
|
| 80 | - case 'name': |
|
| 81 | - case 'create': |
|
| 82 | - case 'overwrite': |
|
| 83 | - case 'charset': |
|
| 84 | - break; |
|
| 85 | - case 'table': |
|
| 86 | - $this->loadTable($schema, $child); |
|
| 87 | - break; |
|
| 88 | - default: |
|
| 89 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 65 | + /** |
|
| 66 | + * @param string $file |
|
| 67 | + * @param Schema $schema |
|
| 68 | + * @return Schema |
|
| 69 | + * @throws \DomainException |
|
| 70 | + */ |
|
| 71 | + public function loadSchemaFromFile($file, Schema $schema) { |
|
| 72 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 73 | + $xml = simplexml_load_file($file); |
|
| 74 | + libxml_disable_entity_loader($loadEntities); |
|
| 75 | + foreach ($xml->children() as $child) { |
|
| 76 | + /** |
|
| 77 | + * @var \SimpleXMLElement $child |
|
| 78 | + */ |
|
| 79 | + switch ($child->getName()) { |
|
| 80 | + case 'name': |
|
| 81 | + case 'create': |
|
| 82 | + case 'overwrite': |
|
| 83 | + case 'charset': |
|
| 84 | + break; |
|
| 85 | + case 'table': |
|
| 86 | + $this->loadTable($schema, $child); |
|
| 87 | + break; |
|
| 88 | + default: |
|
| 89 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 90 | 90 | |
| 91 | - } |
|
| 92 | - } |
|
| 93 | - return $schema; |
|
| 94 | - } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + return $schema; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @param \Doctrine\DBAL\Schema\Schema $schema |
|
| 98 | - * @param \SimpleXMLElement $xml |
|
| 99 | - * @throws \DomainException |
|
| 100 | - */ |
|
| 101 | - private function loadTable($schema, $xml) { |
|
| 102 | - $table = null; |
|
| 103 | - foreach ($xml->children() as $child) { |
|
| 104 | - /** |
|
| 105 | - * @var \SimpleXMLElement $child |
|
| 106 | - */ |
|
| 107 | - switch ($child->getName()) { |
|
| 108 | - case 'name': |
|
| 109 | - $name = (string)$child; |
|
| 110 | - $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); |
|
| 111 | - $name = $this->platform->quoteIdentifier($name); |
|
| 112 | - $table = $schema->createTable($name); |
|
| 113 | - break; |
|
| 114 | - case 'create': |
|
| 115 | - case 'overwrite': |
|
| 116 | - case 'charset': |
|
| 117 | - break; |
|
| 118 | - case 'declaration': |
|
| 119 | - if (is_null($table)) { |
|
| 120 | - throw new \DomainException('Table declaration before table name'); |
|
| 121 | - } |
|
| 122 | - $this->loadDeclaration($table, $child); |
|
| 123 | - break; |
|
| 124 | - default: |
|
| 125 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 96 | + /** |
|
| 97 | + * @param \Doctrine\DBAL\Schema\Schema $schema |
|
| 98 | + * @param \SimpleXMLElement $xml |
|
| 99 | + * @throws \DomainException |
|
| 100 | + */ |
|
| 101 | + private function loadTable($schema, $xml) { |
|
| 102 | + $table = null; |
|
| 103 | + foreach ($xml->children() as $child) { |
|
| 104 | + /** |
|
| 105 | + * @var \SimpleXMLElement $child |
|
| 106 | + */ |
|
| 107 | + switch ($child->getName()) { |
|
| 108 | + case 'name': |
|
| 109 | + $name = (string)$child; |
|
| 110 | + $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); |
|
| 111 | + $name = $this->platform->quoteIdentifier($name); |
|
| 112 | + $table = $schema->createTable($name); |
|
| 113 | + break; |
|
| 114 | + case 'create': |
|
| 115 | + case 'overwrite': |
|
| 116 | + case 'charset': |
|
| 117 | + break; |
|
| 118 | + case 'declaration': |
|
| 119 | + if (is_null($table)) { |
|
| 120 | + throw new \DomainException('Table declaration before table name'); |
|
| 121 | + } |
|
| 122 | + $this->loadDeclaration($table, $child); |
|
| 123 | + break; |
|
| 124 | + default: |
|
| 125 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 126 | 126 | |
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 133 | - * @param \SimpleXMLElement $xml |
|
| 134 | - * @throws \DomainException |
|
| 135 | - */ |
|
| 136 | - private function loadDeclaration($table, $xml) { |
|
| 137 | - foreach ($xml->children() as $child) { |
|
| 138 | - /** |
|
| 139 | - * @var \SimpleXMLElement $child |
|
| 140 | - */ |
|
| 141 | - switch ($child->getName()) { |
|
| 142 | - case 'field': |
|
| 143 | - $this->loadField($table, $child); |
|
| 144 | - break; |
|
| 145 | - case 'index': |
|
| 146 | - $this->loadIndex($table, $child); |
|
| 147 | - break; |
|
| 148 | - default: |
|
| 149 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 131 | + /** |
|
| 132 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 133 | + * @param \SimpleXMLElement $xml |
|
| 134 | + * @throws \DomainException |
|
| 135 | + */ |
|
| 136 | + private function loadDeclaration($table, $xml) { |
|
| 137 | + foreach ($xml->children() as $child) { |
|
| 138 | + /** |
|
| 139 | + * @var \SimpleXMLElement $child |
|
| 140 | + */ |
|
| 141 | + switch ($child->getName()) { |
|
| 142 | + case 'field': |
|
| 143 | + $this->loadField($table, $child); |
|
| 144 | + break; |
|
| 145 | + case 'index': |
|
| 146 | + $this->loadIndex($table, $child); |
|
| 147 | + break; |
|
| 148 | + default: |
|
| 149 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 150 | 150 | |
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 157 | - * @param \SimpleXMLElement $xml |
|
| 158 | - * @throws \DomainException |
|
| 159 | - */ |
|
| 160 | - private function loadField($table, $xml) { |
|
| 161 | - $options = array( 'notnull' => false ); |
|
| 162 | - foreach ($xml->children() as $child) { |
|
| 163 | - /** |
|
| 164 | - * @var \SimpleXMLElement $child |
|
| 165 | - */ |
|
| 166 | - switch ($child->getName()) { |
|
| 167 | - case 'name': |
|
| 168 | - $name = (string)$child; |
|
| 169 | - $name = $this->platform->quoteIdentifier($name); |
|
| 170 | - break; |
|
| 171 | - case 'type': |
|
| 172 | - $type = (string)$child; |
|
| 173 | - switch ($type) { |
|
| 174 | - case 'text': |
|
| 175 | - $type = 'string'; |
|
| 176 | - break; |
|
| 177 | - case 'clob': |
|
| 178 | - $type = 'text'; |
|
| 179 | - break; |
|
| 180 | - case 'timestamp': |
|
| 181 | - $type = 'datetime'; |
|
| 182 | - break; |
|
| 183 | - case 'numeric': |
|
| 184 | - $type = 'decimal'; |
|
| 185 | - break; |
|
| 186 | - } |
|
| 187 | - break; |
|
| 188 | - case 'length': |
|
| 189 | - $length = (string)$child; |
|
| 190 | - $options['length'] = $length; |
|
| 191 | - break; |
|
| 192 | - case 'unsigned': |
|
| 193 | - $unsigned = $this->asBool($child); |
|
| 194 | - $options['unsigned'] = $unsigned; |
|
| 195 | - break; |
|
| 196 | - case 'notnull': |
|
| 197 | - $notnull = $this->asBool($child); |
|
| 198 | - $options['notnull'] = $notnull; |
|
| 199 | - break; |
|
| 200 | - case 'autoincrement': |
|
| 201 | - $autoincrement = $this->asBool($child); |
|
| 202 | - $options['autoincrement'] = $autoincrement; |
|
| 203 | - break; |
|
| 204 | - case 'default': |
|
| 205 | - $default = (string)$child; |
|
| 206 | - $options['default'] = $default; |
|
| 207 | - break; |
|
| 208 | - case 'comments': |
|
| 209 | - $comment = (string)$child; |
|
| 210 | - $options['comment'] = $comment; |
|
| 211 | - break; |
|
| 212 | - case 'primary': |
|
| 213 | - $primary = $this->asBool($child); |
|
| 214 | - $options['primary'] = $primary; |
|
| 215 | - break; |
|
| 216 | - case 'precision': |
|
| 217 | - $precision = (string)$child; |
|
| 218 | - $options['precision'] = $precision; |
|
| 219 | - break; |
|
| 220 | - case 'scale': |
|
| 221 | - $scale = (string)$child; |
|
| 222 | - $options['scale'] = $scale; |
|
| 223 | - break; |
|
| 224 | - default: |
|
| 225 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 155 | + /** |
|
| 156 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 157 | + * @param \SimpleXMLElement $xml |
|
| 158 | + * @throws \DomainException |
|
| 159 | + */ |
|
| 160 | + private function loadField($table, $xml) { |
|
| 161 | + $options = array( 'notnull' => false ); |
|
| 162 | + foreach ($xml->children() as $child) { |
|
| 163 | + /** |
|
| 164 | + * @var \SimpleXMLElement $child |
|
| 165 | + */ |
|
| 166 | + switch ($child->getName()) { |
|
| 167 | + case 'name': |
|
| 168 | + $name = (string)$child; |
|
| 169 | + $name = $this->platform->quoteIdentifier($name); |
|
| 170 | + break; |
|
| 171 | + case 'type': |
|
| 172 | + $type = (string)$child; |
|
| 173 | + switch ($type) { |
|
| 174 | + case 'text': |
|
| 175 | + $type = 'string'; |
|
| 176 | + break; |
|
| 177 | + case 'clob': |
|
| 178 | + $type = 'text'; |
|
| 179 | + break; |
|
| 180 | + case 'timestamp': |
|
| 181 | + $type = 'datetime'; |
|
| 182 | + break; |
|
| 183 | + case 'numeric': |
|
| 184 | + $type = 'decimal'; |
|
| 185 | + break; |
|
| 186 | + } |
|
| 187 | + break; |
|
| 188 | + case 'length': |
|
| 189 | + $length = (string)$child; |
|
| 190 | + $options['length'] = $length; |
|
| 191 | + break; |
|
| 192 | + case 'unsigned': |
|
| 193 | + $unsigned = $this->asBool($child); |
|
| 194 | + $options['unsigned'] = $unsigned; |
|
| 195 | + break; |
|
| 196 | + case 'notnull': |
|
| 197 | + $notnull = $this->asBool($child); |
|
| 198 | + $options['notnull'] = $notnull; |
|
| 199 | + break; |
|
| 200 | + case 'autoincrement': |
|
| 201 | + $autoincrement = $this->asBool($child); |
|
| 202 | + $options['autoincrement'] = $autoincrement; |
|
| 203 | + break; |
|
| 204 | + case 'default': |
|
| 205 | + $default = (string)$child; |
|
| 206 | + $options['default'] = $default; |
|
| 207 | + break; |
|
| 208 | + case 'comments': |
|
| 209 | + $comment = (string)$child; |
|
| 210 | + $options['comment'] = $comment; |
|
| 211 | + break; |
|
| 212 | + case 'primary': |
|
| 213 | + $primary = $this->asBool($child); |
|
| 214 | + $options['primary'] = $primary; |
|
| 215 | + break; |
|
| 216 | + case 'precision': |
|
| 217 | + $precision = (string)$child; |
|
| 218 | + $options['precision'] = $precision; |
|
| 219 | + break; |
|
| 220 | + case 'scale': |
|
| 221 | + $scale = (string)$child; |
|
| 222 | + $options['scale'] = $scale; |
|
| 223 | + break; |
|
| 224 | + default: |
|
| 225 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 226 | 226 | |
| 227 | - } |
|
| 228 | - } |
|
| 229 | - if (isset($name) && isset($type)) { |
|
| 230 | - if (isset($options['default']) && empty($options['default'])) { |
|
| 231 | - if (empty($options['notnull']) || !$options['notnull']) { |
|
| 232 | - unset($options['default']); |
|
| 233 | - $options['notnull'] = false; |
|
| 234 | - } else { |
|
| 235 | - $options['default'] = ''; |
|
| 236 | - } |
|
| 237 | - if ($type == 'integer' || $type == 'decimal') { |
|
| 238 | - $options['default'] = 0; |
|
| 239 | - } elseif ($type == 'boolean') { |
|
| 240 | - $options['default'] = false; |
|
| 241 | - } |
|
| 242 | - if (!empty($options['autoincrement']) && $options['autoincrement']) { |
|
| 243 | - unset($options['default']); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - if ($type === 'integer' && isset($options['default'])) { |
|
| 247 | - $options['default'] = (int)$options['default']; |
|
| 248 | - } |
|
| 249 | - if ($type === 'integer' && isset($options['length'])) { |
|
| 250 | - $length = $options['length']; |
|
| 251 | - if ($length < 4) { |
|
| 252 | - $type = 'smallint'; |
|
| 253 | - } else if ($length > 4) { |
|
| 254 | - $type = 'bigint'; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - if ($type === 'boolean' && isset($options['default'])) { |
|
| 258 | - $options['default'] = $this->asBool($options['default']); |
|
| 259 | - } |
|
| 260 | - if (!empty($options['autoincrement']) |
|
| 261 | - && !empty($options['notnull']) |
|
| 262 | - ) { |
|
| 263 | - $options['primary'] = true; |
|
| 264 | - } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + if (isset($name) && isset($type)) { |
|
| 230 | + if (isset($options['default']) && empty($options['default'])) { |
|
| 231 | + if (empty($options['notnull']) || !$options['notnull']) { |
|
| 232 | + unset($options['default']); |
|
| 233 | + $options['notnull'] = false; |
|
| 234 | + } else { |
|
| 235 | + $options['default'] = ''; |
|
| 236 | + } |
|
| 237 | + if ($type == 'integer' || $type == 'decimal') { |
|
| 238 | + $options['default'] = 0; |
|
| 239 | + } elseif ($type == 'boolean') { |
|
| 240 | + $options['default'] = false; |
|
| 241 | + } |
|
| 242 | + if (!empty($options['autoincrement']) && $options['autoincrement']) { |
|
| 243 | + unset($options['default']); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + if ($type === 'integer' && isset($options['default'])) { |
|
| 247 | + $options['default'] = (int)$options['default']; |
|
| 248 | + } |
|
| 249 | + if ($type === 'integer' && isset($options['length'])) { |
|
| 250 | + $length = $options['length']; |
|
| 251 | + if ($length < 4) { |
|
| 252 | + $type = 'smallint'; |
|
| 253 | + } else if ($length > 4) { |
|
| 254 | + $type = 'bigint'; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + if ($type === 'boolean' && isset($options['default'])) { |
|
| 258 | + $options['default'] = $this->asBool($options['default']); |
|
| 259 | + } |
|
| 260 | + if (!empty($options['autoincrement']) |
|
| 261 | + && !empty($options['notnull']) |
|
| 262 | + ) { |
|
| 263 | + $options['primary'] = true; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - $table->addColumn($name, $type, $options); |
|
| 267 | - if (!empty($options['primary']) && $options['primary']) { |
|
| 268 | - $table->setPrimaryKey(array($name)); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } |
|
| 266 | + $table->addColumn($name, $type, $options); |
|
| 267 | + if (!empty($options['primary']) && $options['primary']) { |
|
| 268 | + $table->setPrimaryKey(array($name)); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 275 | - * @param \SimpleXMLElement $xml |
|
| 276 | - * @throws \DomainException |
|
| 277 | - */ |
|
| 278 | - private function loadIndex($table, $xml) { |
|
| 279 | - $name = null; |
|
| 280 | - $fields = array(); |
|
| 281 | - foreach ($xml->children() as $child) { |
|
| 282 | - /** |
|
| 283 | - * @var \SimpleXMLElement $child |
|
| 284 | - */ |
|
| 285 | - switch ($child->getName()) { |
|
| 286 | - case 'name': |
|
| 287 | - $name = (string)$child; |
|
| 288 | - break; |
|
| 289 | - case 'primary': |
|
| 290 | - $primary = $this->asBool($child); |
|
| 291 | - break; |
|
| 292 | - case 'unique': |
|
| 293 | - $unique = $this->asBool($child); |
|
| 294 | - break; |
|
| 295 | - case 'field': |
|
| 296 | - foreach ($child->children() as $field) { |
|
| 297 | - /** |
|
| 298 | - * @var \SimpleXMLElement $field |
|
| 299 | - */ |
|
| 300 | - switch ($field->getName()) { |
|
| 301 | - case 'name': |
|
| 302 | - $field_name = (string)$field; |
|
| 303 | - $field_name = $this->platform->quoteIdentifier($field_name); |
|
| 304 | - $fields[] = $field_name; |
|
| 305 | - break; |
|
| 306 | - case 'sorting': |
|
| 307 | - break; |
|
| 308 | - default: |
|
| 309 | - throw new \DomainException('Unknown element: ' . $field->getName()); |
|
| 273 | + /** |
|
| 274 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 275 | + * @param \SimpleXMLElement $xml |
|
| 276 | + * @throws \DomainException |
|
| 277 | + */ |
|
| 278 | + private function loadIndex($table, $xml) { |
|
| 279 | + $name = null; |
|
| 280 | + $fields = array(); |
|
| 281 | + foreach ($xml->children() as $child) { |
|
| 282 | + /** |
|
| 283 | + * @var \SimpleXMLElement $child |
|
| 284 | + */ |
|
| 285 | + switch ($child->getName()) { |
|
| 286 | + case 'name': |
|
| 287 | + $name = (string)$child; |
|
| 288 | + break; |
|
| 289 | + case 'primary': |
|
| 290 | + $primary = $this->asBool($child); |
|
| 291 | + break; |
|
| 292 | + case 'unique': |
|
| 293 | + $unique = $this->asBool($child); |
|
| 294 | + break; |
|
| 295 | + case 'field': |
|
| 296 | + foreach ($child->children() as $field) { |
|
| 297 | + /** |
|
| 298 | + * @var \SimpleXMLElement $field |
|
| 299 | + */ |
|
| 300 | + switch ($field->getName()) { |
|
| 301 | + case 'name': |
|
| 302 | + $field_name = (string)$field; |
|
| 303 | + $field_name = $this->platform->quoteIdentifier($field_name); |
|
| 304 | + $fields[] = $field_name; |
|
| 305 | + break; |
|
| 306 | + case 'sorting': |
|
| 307 | + break; |
|
| 308 | + default: |
|
| 309 | + throw new \DomainException('Unknown element: ' . $field->getName()); |
|
| 310 | 310 | |
| 311 | - } |
|
| 312 | - } |
|
| 313 | - break; |
|
| 314 | - default: |
|
| 315 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + break; |
|
| 314 | + default: |
|
| 315 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 316 | 316 | |
| 317 | - } |
|
| 318 | - } |
|
| 319 | - if (!empty($fields)) { |
|
| 320 | - if (isset($primary) && $primary) { |
|
| 321 | - if ($table->hasPrimaryKey()) { |
|
| 322 | - return; |
|
| 323 | - } |
|
| 324 | - $table->setPrimaryKey($fields, $name); |
|
| 325 | - } else { |
|
| 326 | - if (isset($unique) && $unique) { |
|
| 327 | - $table->addUniqueIndex($fields, $name); |
|
| 328 | - } else { |
|
| 329 | - $table->addIndex($fields, $name); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - } else { |
|
| 333 | - throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); |
|
| 334 | - } |
|
| 335 | - } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + if (!empty($fields)) { |
|
| 320 | + if (isset($primary) && $primary) { |
|
| 321 | + if ($table->hasPrimaryKey()) { |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | + $table->setPrimaryKey($fields, $name); |
|
| 325 | + } else { |
|
| 326 | + if (isset($unique) && $unique) { |
|
| 327 | + $table->addUniqueIndex($fields, $name); |
|
| 328 | + } else { |
|
| 329 | + $table->addIndex($fields, $name); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + } else { |
|
| 333 | + throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - /** |
|
| 338 | - * @param \SimpleXMLElement|string $xml |
|
| 339 | - * @return bool |
|
| 340 | - */ |
|
| 341 | - private function asBool($xml) { |
|
| 342 | - $result = (string)$xml; |
|
| 343 | - if ($result == 'true') { |
|
| 344 | - $result = true; |
|
| 345 | - } elseif ($result == 'false') { |
|
| 346 | - $result = false; |
|
| 347 | - } |
|
| 348 | - return (bool)$result; |
|
| 349 | - } |
|
| 337 | + /** |
|
| 338 | + * @param \SimpleXMLElement|string $xml |
|
| 339 | + * @return bool |
|
| 340 | + */ |
|
| 341 | + private function asBool($xml) { |
|
| 342 | + $result = (string)$xml; |
|
| 343 | + if ($result == 'true') { |
|
| 344 | + $result = true; |
|
| 345 | + } elseif ($result == 'false') { |
|
| 346 | + $result = false; |
|
| 347 | + } |
|
| 348 | + return (bool)$result; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | 351 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | case 'database': |
| 95 | 95 | case 'mysql': |
| 96 | 96 | case 'sqlite': |
| 97 | - \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 97 | + \OCP\Util::writeLog('core', 'Adding user backend '.$backend.'.', \OCP\Util::DEBUG); |
|
| 98 | 98 | self::$_usedBackends[$backend] = new \OC\User\Database(); |
| 99 | 99 | \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
| 100 | 100 | break; |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
| 104 | 104 | break; |
| 105 | 105 | default: |
| 106 | - \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 107 | - $className = 'OC_USER_' . strtoupper($backend); |
|
| 106 | + \OCP\Util::writeLog('core', 'Adding default user backend '.$backend.'.', \OCP\Util::DEBUG); |
|
| 107 | + $className = 'OC_USER_'.strtoupper($backend); |
|
| 108 | 108 | self::$_usedBackends[$backend] = new $className(); |
| 109 | 109 | \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
| 110 | 110 | break; |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | self::useBackend($backend); |
| 141 | 141 | self::$_setupedBackends[] = $i; |
| 142 | 142 | } else { |
| 143 | - \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', \OCP\Util::DEBUG); |
|
| 143 | + \OCP\Util::writeLog('core', 'User backend '.$class.' already initialized.', \OCP\Util::DEBUG); |
|
| 144 | 144 | } |
| 145 | 145 | } else { |
| 146 | - \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', \OCP\Util::ERROR); |
|
| 146 | + \OCP\Util::writeLog('core', 'User backend '.$class.' not found.', \OCP\Util::ERROR); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | if ($user) { |
| 472 | 472 | return $user->getHome(); |
| 473 | 473 | } else { |
| 474 | - return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid; |
|
| 474 | + return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$uid; |
|
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | 477 | |
@@ -363,7 +363,7 @@ |
||
| 363 | 363 | * get the display name of the user currently logged in. |
| 364 | 364 | * |
| 365 | 365 | * @param string $uid |
| 366 | - * @return string|bool uid or false |
|
| 366 | + * @return string|false uid or false |
|
| 367 | 367 | */ |
| 368 | 368 | public static function getDisplayName($uid = null) { |
| 369 | 369 | if ($uid) { |
@@ -57,437 +57,437 @@ |
||
| 57 | 57 | */ |
| 58 | 58 | class OC_User { |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return \OC\User\Session |
|
| 62 | - */ |
|
| 63 | - public static function getUserSession() { |
|
| 64 | - return OC::$server->getUserSession(); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - private static $_usedBackends = array(); |
|
| 68 | - |
|
| 69 | - private static $_setupedBackends = array(); |
|
| 70 | - |
|
| 71 | - // bool, stores if a user want to access a resource anonymously, e.g if they open a public link |
|
| 72 | - private static $incognitoMode = false; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Adds the backend to the list of used backends |
|
| 76 | - * |
|
| 77 | - * @param string|\OCP\UserInterface $backend default: database The backend to use for user management |
|
| 78 | - * @return bool |
|
| 79 | - * |
|
| 80 | - * Set the User Authentication Module |
|
| 81 | - * @suppress PhanDeprecatedFunction |
|
| 82 | - */ |
|
| 83 | - public static function useBackend($backend = 'database') { |
|
| 84 | - if ($backend instanceof \OCP\UserInterface) { |
|
| 85 | - self::$_usedBackends[get_class($backend)] = $backend; |
|
| 86 | - \OC::$server->getUserManager()->registerBackend($backend); |
|
| 87 | - } else { |
|
| 88 | - // You'll never know what happens |
|
| 89 | - if (null === $backend OR !is_string($backend)) { |
|
| 90 | - $backend = 'database'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Load backend |
|
| 94 | - switch ($backend) { |
|
| 95 | - case 'database': |
|
| 96 | - case 'mysql': |
|
| 97 | - case 'sqlite': |
|
| 98 | - \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 99 | - self::$_usedBackends[$backend] = new \OC\User\Database(); |
|
| 100 | - \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
|
| 101 | - break; |
|
| 102 | - case 'dummy': |
|
| 103 | - self::$_usedBackends[$backend] = new \Test\Util\User\Dummy(); |
|
| 104 | - \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
|
| 105 | - break; |
|
| 106 | - default: |
|
| 107 | - \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 108 | - $className = 'OC_USER_' . strtoupper($backend); |
|
| 109 | - self::$_usedBackends[$backend] = new $className(); |
|
| 110 | - \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
|
| 111 | - break; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * remove all used backends |
|
| 119 | - */ |
|
| 120 | - public static function clearBackends() { |
|
| 121 | - self::$_usedBackends = array(); |
|
| 122 | - \OC::$server->getUserManager()->clearBackends(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * setup the configured backends in config.php |
|
| 127 | - * @suppress PhanDeprecatedFunction |
|
| 128 | - */ |
|
| 129 | - public static function setupBackends() { |
|
| 130 | - OC_App::loadApps(['prelogin']); |
|
| 131 | - $backends = \OC::$server->getSystemConfig()->getValue('user_backends', []); |
|
| 132 | - if (isset($backends['default']) && !$backends['default']) { |
|
| 133 | - // clear default backends |
|
| 134 | - self::clearBackends(); |
|
| 135 | - } |
|
| 136 | - foreach ($backends as $i => $config) { |
|
| 137 | - if (!is_array($config)) { |
|
| 138 | - continue; |
|
| 139 | - } |
|
| 140 | - $class = $config['class']; |
|
| 141 | - $arguments = $config['arguments']; |
|
| 142 | - if (class_exists($class)) { |
|
| 143 | - if (array_search($i, self::$_setupedBackends) === false) { |
|
| 144 | - // make a reflection object |
|
| 145 | - $reflectionObj = new ReflectionClass($class); |
|
| 146 | - |
|
| 147 | - // use Reflection to create a new instance, using the $args |
|
| 148 | - $backend = $reflectionObj->newInstanceArgs($arguments); |
|
| 149 | - self::useBackend($backend); |
|
| 150 | - self::$_setupedBackends[] = $i; |
|
| 151 | - } else { |
|
| 152 | - \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', \OCP\Util::DEBUG); |
|
| 153 | - } |
|
| 154 | - } else { |
|
| 155 | - \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', \OCP\Util::ERROR); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Try to login a user, assuming authentication |
|
| 162 | - * has already happened (e.g. via Single Sign On). |
|
| 163 | - * |
|
| 164 | - * Log in a user and regenerate a new session. |
|
| 165 | - * |
|
| 166 | - * @param \OCP\Authentication\IApacheBackend $backend |
|
| 167 | - * @return bool |
|
| 168 | - */ |
|
| 169 | - public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) { |
|
| 170 | - |
|
| 171 | - $uid = $backend->getCurrentUserId(); |
|
| 172 | - $run = true; |
|
| 173 | - OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); |
|
| 174 | - |
|
| 175 | - if ($uid) { |
|
| 176 | - if (self::getUser() !== $uid) { |
|
| 177 | - self::setUserId($uid); |
|
| 178 | - $userSession = self::getUserSession(); |
|
| 179 | - $userSession->setLoginName($uid); |
|
| 180 | - $request = OC::$server->getRequest(); |
|
| 181 | - $userSession->createSessionToken($request, $uid, $uid); |
|
| 182 | - // setup the filesystem |
|
| 183 | - OC_Util::setupFS($uid); |
|
| 184 | - // first call the post_login hooks, the login-process needs to be |
|
| 185 | - // completed before we can safely create the users folder. |
|
| 186 | - // For example encryption needs to initialize the users keys first |
|
| 187 | - // before we can create the user folder with the skeleton files |
|
| 188 | - OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); |
|
| 189 | - //trigger creation of user home and /files folder |
|
| 190 | - \OC::$server->getUserFolder($uid); |
|
| 191 | - } |
|
| 192 | - return true; |
|
| 193 | - } |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Verify with Apache whether user is authenticated. |
|
| 199 | - * |
|
| 200 | - * @return boolean|null |
|
| 201 | - * true: authenticated |
|
| 202 | - * false: not authenticated |
|
| 203 | - * null: not handled / no backend available |
|
| 204 | - */ |
|
| 205 | - public static function handleApacheAuth() { |
|
| 206 | - $backend = self::findFirstActiveUsedBackend(); |
|
| 207 | - if ($backend) { |
|
| 208 | - OC_App::loadApps(); |
|
| 209 | - |
|
| 210 | - //setup extra user backends |
|
| 211 | - self::setupBackends(); |
|
| 212 | - self::getUserSession()->unsetMagicInCookie(); |
|
| 213 | - |
|
| 214 | - return self::loginWithApache($backend); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return null; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Sets user id for session and triggers emit |
|
| 223 | - * |
|
| 224 | - * @param string $uid |
|
| 225 | - */ |
|
| 226 | - public static function setUserId($uid) { |
|
| 227 | - $userSession = \OC::$server->getUserSession(); |
|
| 228 | - $userManager = \OC::$server->getUserManager(); |
|
| 229 | - if ($user = $userManager->get($uid)) { |
|
| 230 | - $userSession->setUser($user); |
|
| 231 | - } else { |
|
| 232 | - \OC::$server->getSession()->set('user_id', $uid); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Sets user display name for session |
|
| 238 | - * |
|
| 239 | - * @param string $uid |
|
| 240 | - * @param string $displayName |
|
| 241 | - * @return bool Whether the display name could get set |
|
| 242 | - */ |
|
| 243 | - public static function setDisplayName($uid, $displayName = null) { |
|
| 244 | - if (is_null($displayName)) { |
|
| 245 | - $displayName = $uid; |
|
| 246 | - } |
|
| 247 | - $user = \OC::$server->getUserManager()->get($uid); |
|
| 248 | - if ($user) { |
|
| 249 | - return $user->setDisplayName($displayName); |
|
| 250 | - } else { |
|
| 251 | - return false; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Check if the user is logged in, considers also the HTTP basic credentials |
|
| 257 | - * |
|
| 258 | - * @deprecated use \OC::$server->getUserSession()->isLoggedIn() |
|
| 259 | - * @return bool |
|
| 260 | - */ |
|
| 261 | - public static function isLoggedIn() { |
|
| 262 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * set incognito mode, e.g. if a user wants to open a public link |
|
| 267 | - * |
|
| 268 | - * @param bool $status |
|
| 269 | - */ |
|
| 270 | - public static function setIncognitoMode($status) { |
|
| 271 | - self::$incognitoMode = $status; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * get incognito mode status |
|
| 276 | - * |
|
| 277 | - * @return bool |
|
| 278 | - */ |
|
| 279 | - public static function isIncognitoMode() { |
|
| 280 | - return self::$incognitoMode; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Returns the current logout URL valid for the currently logged-in user |
|
| 285 | - * |
|
| 286 | - * @param \OCP\IURLGenerator $urlGenerator |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) { |
|
| 290 | - $backend = self::findFirstActiveUsedBackend(); |
|
| 291 | - if ($backend) { |
|
| 292 | - return $backend->getLogoutUrl(); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $logoutUrl = $urlGenerator->linkToRouteAbsolute( |
|
| 296 | - 'core.login.logout', |
|
| 297 | - [ |
|
| 298 | - 'requesttoken' => \OCP\Util::callRegister(), |
|
| 299 | - ] |
|
| 300 | - ); |
|
| 301 | - |
|
| 302 | - return $logoutUrl; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Check if the user is an admin user |
|
| 307 | - * |
|
| 308 | - * @param string $uid uid of the admin |
|
| 309 | - * @return bool |
|
| 310 | - */ |
|
| 311 | - public static function isAdminUser($uid) { |
|
| 312 | - $group = \OC::$server->getGroupManager()->get('admin'); |
|
| 313 | - $user = \OC::$server->getUserManager()->get($uid); |
|
| 314 | - if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) { |
|
| 315 | - return true; |
|
| 316 | - } |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * get the user id of the user currently logged in. |
|
| 323 | - * |
|
| 324 | - * @return string|bool uid or false |
|
| 325 | - */ |
|
| 326 | - public static function getUser() { |
|
| 327 | - $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null; |
|
| 328 | - if (!is_null($uid) && self::$incognitoMode === false) { |
|
| 329 | - return $uid; |
|
| 330 | - } else { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * get the display name of the user currently logged in. |
|
| 337 | - * |
|
| 338 | - * @param string $uid |
|
| 339 | - * @return string|bool uid or false |
|
| 340 | - */ |
|
| 341 | - public static function getDisplayName($uid = null) { |
|
| 342 | - if ($uid) { |
|
| 343 | - $user = \OC::$server->getUserManager()->get($uid); |
|
| 344 | - if ($user) { |
|
| 345 | - return $user->getDisplayName(); |
|
| 346 | - } else { |
|
| 347 | - return $uid; |
|
| 348 | - } |
|
| 349 | - } else { |
|
| 350 | - $user = self::getUserSession()->getUser(); |
|
| 351 | - if ($user) { |
|
| 352 | - return $user->getDisplayName(); |
|
| 353 | - } else { |
|
| 354 | - return false; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Set password |
|
| 361 | - * |
|
| 362 | - * @param string $uid The username |
|
| 363 | - * @param string $password The new password |
|
| 364 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 365 | - * @return bool |
|
| 366 | - * |
|
| 367 | - * Change the password of a user |
|
| 368 | - */ |
|
| 369 | - public static function setPassword($uid, $password, $recoveryPassword = null) { |
|
| 370 | - $user = \OC::$server->getUserManager()->get($uid); |
|
| 371 | - if ($user) { |
|
| 372 | - return $user->setPassword($password, $recoveryPassword); |
|
| 373 | - } else { |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Check if the password is correct |
|
| 380 | - * |
|
| 381 | - * @param string $uid The username |
|
| 382 | - * @param string $password The password |
|
| 383 | - * @return string|false user id a string on success, false otherwise |
|
| 384 | - * |
|
| 385 | - * Check if the password is correct without logging in the user |
|
| 386 | - * returns the user id or false |
|
| 387 | - */ |
|
| 388 | - public static function checkPassword($uid, $password) { |
|
| 389 | - $manager = \OC::$server->getUserManager(); |
|
| 390 | - $username = $manager->checkPassword($uid, $password); |
|
| 391 | - if ($username !== false) { |
|
| 392 | - return $username->getUID(); |
|
| 393 | - } |
|
| 394 | - return false; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @param string $uid The username |
|
| 399 | - * @return string |
|
| 400 | - * |
|
| 401 | - * returns the path to the users home directory |
|
| 402 | - * @deprecated Use \OC::$server->getUserManager->getHome() |
|
| 403 | - */ |
|
| 404 | - public static function getHome($uid) { |
|
| 405 | - $user = \OC::$server->getUserManager()->get($uid); |
|
| 406 | - if ($user) { |
|
| 407 | - return $user->getHome(); |
|
| 408 | - } else { |
|
| 409 | - return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid; |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Get a list of all users |
|
| 415 | - * |
|
| 416 | - * @return array an array of all uids |
|
| 417 | - * |
|
| 418 | - * Get a list of all users. |
|
| 419 | - * @param string $search |
|
| 420 | - * @param integer $limit |
|
| 421 | - * @param integer $offset |
|
| 422 | - */ |
|
| 423 | - public static function getUsers($search = '', $limit = null, $offset = null) { |
|
| 424 | - $users = \OC::$server->getUserManager()->search($search, $limit, $offset); |
|
| 425 | - $uids = array(); |
|
| 426 | - foreach ($users as $user) { |
|
| 427 | - $uids[] = $user->getUID(); |
|
| 428 | - } |
|
| 429 | - return $uids; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Get a list of all users display name |
|
| 434 | - * |
|
| 435 | - * @param string $search |
|
| 436 | - * @param int $limit |
|
| 437 | - * @param int $offset |
|
| 438 | - * @return array associative array with all display names (value) and corresponding uids (key) |
|
| 439 | - * |
|
| 440 | - * Get a list of all display names and user ids. |
|
| 441 | - * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead. |
|
| 442 | - */ |
|
| 443 | - public static function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 444 | - $displayNames = array(); |
|
| 445 | - $users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset); |
|
| 446 | - foreach ($users as $user) { |
|
| 447 | - $displayNames[$user->getUID()] = $user->getDisplayName(); |
|
| 448 | - } |
|
| 449 | - return $displayNames; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * check if a user exists |
|
| 454 | - * |
|
| 455 | - * @param string $uid the username |
|
| 456 | - * @return boolean |
|
| 457 | - */ |
|
| 458 | - public static function userExists($uid) { |
|
| 459 | - return \OC::$server->getUserManager()->userExists($uid); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * checks if a user is enabled |
|
| 464 | - * |
|
| 465 | - * @param string $uid |
|
| 466 | - * @return bool |
|
| 467 | - */ |
|
| 468 | - public static function isEnabled($uid) { |
|
| 469 | - $user = \OC::$server->getUserManager()->get($uid); |
|
| 470 | - if ($user) { |
|
| 471 | - return $user->isEnabled(); |
|
| 472 | - } else { |
|
| 473 | - return false; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Returns the first active backend from self::$_usedBackends. |
|
| 479 | - * |
|
| 480 | - * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend |
|
| 481 | - */ |
|
| 482 | - private static function findFirstActiveUsedBackend() { |
|
| 483 | - foreach (self::$_usedBackends as $backend) { |
|
| 484 | - if ($backend instanceof OCP\Authentication\IApacheBackend) { |
|
| 485 | - if ($backend->isSessionActive()) { |
|
| 486 | - return $backend; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - return null; |
|
| 492 | - } |
|
| 60 | + /** |
|
| 61 | + * @return \OC\User\Session |
|
| 62 | + */ |
|
| 63 | + public static function getUserSession() { |
|
| 64 | + return OC::$server->getUserSession(); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + private static $_usedBackends = array(); |
|
| 68 | + |
|
| 69 | + private static $_setupedBackends = array(); |
|
| 70 | + |
|
| 71 | + // bool, stores if a user want to access a resource anonymously, e.g if they open a public link |
|
| 72 | + private static $incognitoMode = false; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Adds the backend to the list of used backends |
|
| 76 | + * |
|
| 77 | + * @param string|\OCP\UserInterface $backend default: database The backend to use for user management |
|
| 78 | + * @return bool |
|
| 79 | + * |
|
| 80 | + * Set the User Authentication Module |
|
| 81 | + * @suppress PhanDeprecatedFunction |
|
| 82 | + */ |
|
| 83 | + public static function useBackend($backend = 'database') { |
|
| 84 | + if ($backend instanceof \OCP\UserInterface) { |
|
| 85 | + self::$_usedBackends[get_class($backend)] = $backend; |
|
| 86 | + \OC::$server->getUserManager()->registerBackend($backend); |
|
| 87 | + } else { |
|
| 88 | + // You'll never know what happens |
|
| 89 | + if (null === $backend OR !is_string($backend)) { |
|
| 90 | + $backend = 'database'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Load backend |
|
| 94 | + switch ($backend) { |
|
| 95 | + case 'database': |
|
| 96 | + case 'mysql': |
|
| 97 | + case 'sqlite': |
|
| 98 | + \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 99 | + self::$_usedBackends[$backend] = new \OC\User\Database(); |
|
| 100 | + \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
|
| 101 | + break; |
|
| 102 | + case 'dummy': |
|
| 103 | + self::$_usedBackends[$backend] = new \Test\Util\User\Dummy(); |
|
| 104 | + \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
|
| 105 | + break; |
|
| 106 | + default: |
|
| 107 | + \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 108 | + $className = 'OC_USER_' . strtoupper($backend); |
|
| 109 | + self::$_usedBackends[$backend] = new $className(); |
|
| 110 | + \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
|
| 111 | + break; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * remove all used backends |
|
| 119 | + */ |
|
| 120 | + public static function clearBackends() { |
|
| 121 | + self::$_usedBackends = array(); |
|
| 122 | + \OC::$server->getUserManager()->clearBackends(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * setup the configured backends in config.php |
|
| 127 | + * @suppress PhanDeprecatedFunction |
|
| 128 | + */ |
|
| 129 | + public static function setupBackends() { |
|
| 130 | + OC_App::loadApps(['prelogin']); |
|
| 131 | + $backends = \OC::$server->getSystemConfig()->getValue('user_backends', []); |
|
| 132 | + if (isset($backends['default']) && !$backends['default']) { |
|
| 133 | + // clear default backends |
|
| 134 | + self::clearBackends(); |
|
| 135 | + } |
|
| 136 | + foreach ($backends as $i => $config) { |
|
| 137 | + if (!is_array($config)) { |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 140 | + $class = $config['class']; |
|
| 141 | + $arguments = $config['arguments']; |
|
| 142 | + if (class_exists($class)) { |
|
| 143 | + if (array_search($i, self::$_setupedBackends) === false) { |
|
| 144 | + // make a reflection object |
|
| 145 | + $reflectionObj = new ReflectionClass($class); |
|
| 146 | + |
|
| 147 | + // use Reflection to create a new instance, using the $args |
|
| 148 | + $backend = $reflectionObj->newInstanceArgs($arguments); |
|
| 149 | + self::useBackend($backend); |
|
| 150 | + self::$_setupedBackends[] = $i; |
|
| 151 | + } else { |
|
| 152 | + \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', \OCP\Util::DEBUG); |
|
| 153 | + } |
|
| 154 | + } else { |
|
| 155 | + \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', \OCP\Util::ERROR); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Try to login a user, assuming authentication |
|
| 162 | + * has already happened (e.g. via Single Sign On). |
|
| 163 | + * |
|
| 164 | + * Log in a user and regenerate a new session. |
|
| 165 | + * |
|
| 166 | + * @param \OCP\Authentication\IApacheBackend $backend |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) { |
|
| 170 | + |
|
| 171 | + $uid = $backend->getCurrentUserId(); |
|
| 172 | + $run = true; |
|
| 173 | + OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); |
|
| 174 | + |
|
| 175 | + if ($uid) { |
|
| 176 | + if (self::getUser() !== $uid) { |
|
| 177 | + self::setUserId($uid); |
|
| 178 | + $userSession = self::getUserSession(); |
|
| 179 | + $userSession->setLoginName($uid); |
|
| 180 | + $request = OC::$server->getRequest(); |
|
| 181 | + $userSession->createSessionToken($request, $uid, $uid); |
|
| 182 | + // setup the filesystem |
|
| 183 | + OC_Util::setupFS($uid); |
|
| 184 | + // first call the post_login hooks, the login-process needs to be |
|
| 185 | + // completed before we can safely create the users folder. |
|
| 186 | + // For example encryption needs to initialize the users keys first |
|
| 187 | + // before we can create the user folder with the skeleton files |
|
| 188 | + OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); |
|
| 189 | + //trigger creation of user home and /files folder |
|
| 190 | + \OC::$server->getUserFolder($uid); |
|
| 191 | + } |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Verify with Apache whether user is authenticated. |
|
| 199 | + * |
|
| 200 | + * @return boolean|null |
|
| 201 | + * true: authenticated |
|
| 202 | + * false: not authenticated |
|
| 203 | + * null: not handled / no backend available |
|
| 204 | + */ |
|
| 205 | + public static function handleApacheAuth() { |
|
| 206 | + $backend = self::findFirstActiveUsedBackend(); |
|
| 207 | + if ($backend) { |
|
| 208 | + OC_App::loadApps(); |
|
| 209 | + |
|
| 210 | + //setup extra user backends |
|
| 211 | + self::setupBackends(); |
|
| 212 | + self::getUserSession()->unsetMagicInCookie(); |
|
| 213 | + |
|
| 214 | + return self::loginWithApache($backend); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return null; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Sets user id for session and triggers emit |
|
| 223 | + * |
|
| 224 | + * @param string $uid |
|
| 225 | + */ |
|
| 226 | + public static function setUserId($uid) { |
|
| 227 | + $userSession = \OC::$server->getUserSession(); |
|
| 228 | + $userManager = \OC::$server->getUserManager(); |
|
| 229 | + if ($user = $userManager->get($uid)) { |
|
| 230 | + $userSession->setUser($user); |
|
| 231 | + } else { |
|
| 232 | + \OC::$server->getSession()->set('user_id', $uid); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Sets user display name for session |
|
| 238 | + * |
|
| 239 | + * @param string $uid |
|
| 240 | + * @param string $displayName |
|
| 241 | + * @return bool Whether the display name could get set |
|
| 242 | + */ |
|
| 243 | + public static function setDisplayName($uid, $displayName = null) { |
|
| 244 | + if (is_null($displayName)) { |
|
| 245 | + $displayName = $uid; |
|
| 246 | + } |
|
| 247 | + $user = \OC::$server->getUserManager()->get($uid); |
|
| 248 | + if ($user) { |
|
| 249 | + return $user->setDisplayName($displayName); |
|
| 250 | + } else { |
|
| 251 | + return false; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Check if the user is logged in, considers also the HTTP basic credentials |
|
| 257 | + * |
|
| 258 | + * @deprecated use \OC::$server->getUserSession()->isLoggedIn() |
|
| 259 | + * @return bool |
|
| 260 | + */ |
|
| 261 | + public static function isLoggedIn() { |
|
| 262 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * set incognito mode, e.g. if a user wants to open a public link |
|
| 267 | + * |
|
| 268 | + * @param bool $status |
|
| 269 | + */ |
|
| 270 | + public static function setIncognitoMode($status) { |
|
| 271 | + self::$incognitoMode = $status; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * get incognito mode status |
|
| 276 | + * |
|
| 277 | + * @return bool |
|
| 278 | + */ |
|
| 279 | + public static function isIncognitoMode() { |
|
| 280 | + return self::$incognitoMode; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Returns the current logout URL valid for the currently logged-in user |
|
| 285 | + * |
|
| 286 | + * @param \OCP\IURLGenerator $urlGenerator |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) { |
|
| 290 | + $backend = self::findFirstActiveUsedBackend(); |
|
| 291 | + if ($backend) { |
|
| 292 | + return $backend->getLogoutUrl(); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $logoutUrl = $urlGenerator->linkToRouteAbsolute( |
|
| 296 | + 'core.login.logout', |
|
| 297 | + [ |
|
| 298 | + 'requesttoken' => \OCP\Util::callRegister(), |
|
| 299 | + ] |
|
| 300 | + ); |
|
| 301 | + |
|
| 302 | + return $logoutUrl; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Check if the user is an admin user |
|
| 307 | + * |
|
| 308 | + * @param string $uid uid of the admin |
|
| 309 | + * @return bool |
|
| 310 | + */ |
|
| 311 | + public static function isAdminUser($uid) { |
|
| 312 | + $group = \OC::$server->getGroupManager()->get('admin'); |
|
| 313 | + $user = \OC::$server->getUserManager()->get($uid); |
|
| 314 | + if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) { |
|
| 315 | + return true; |
|
| 316 | + } |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * get the user id of the user currently logged in. |
|
| 323 | + * |
|
| 324 | + * @return string|bool uid or false |
|
| 325 | + */ |
|
| 326 | + public static function getUser() { |
|
| 327 | + $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null; |
|
| 328 | + if (!is_null($uid) && self::$incognitoMode === false) { |
|
| 329 | + return $uid; |
|
| 330 | + } else { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * get the display name of the user currently logged in. |
|
| 337 | + * |
|
| 338 | + * @param string $uid |
|
| 339 | + * @return string|bool uid or false |
|
| 340 | + */ |
|
| 341 | + public static function getDisplayName($uid = null) { |
|
| 342 | + if ($uid) { |
|
| 343 | + $user = \OC::$server->getUserManager()->get($uid); |
|
| 344 | + if ($user) { |
|
| 345 | + return $user->getDisplayName(); |
|
| 346 | + } else { |
|
| 347 | + return $uid; |
|
| 348 | + } |
|
| 349 | + } else { |
|
| 350 | + $user = self::getUserSession()->getUser(); |
|
| 351 | + if ($user) { |
|
| 352 | + return $user->getDisplayName(); |
|
| 353 | + } else { |
|
| 354 | + return false; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Set password |
|
| 361 | + * |
|
| 362 | + * @param string $uid The username |
|
| 363 | + * @param string $password The new password |
|
| 364 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 365 | + * @return bool |
|
| 366 | + * |
|
| 367 | + * Change the password of a user |
|
| 368 | + */ |
|
| 369 | + public static function setPassword($uid, $password, $recoveryPassword = null) { |
|
| 370 | + $user = \OC::$server->getUserManager()->get($uid); |
|
| 371 | + if ($user) { |
|
| 372 | + return $user->setPassword($password, $recoveryPassword); |
|
| 373 | + } else { |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Check if the password is correct |
|
| 380 | + * |
|
| 381 | + * @param string $uid The username |
|
| 382 | + * @param string $password The password |
|
| 383 | + * @return string|false user id a string on success, false otherwise |
|
| 384 | + * |
|
| 385 | + * Check if the password is correct without logging in the user |
|
| 386 | + * returns the user id or false |
|
| 387 | + */ |
|
| 388 | + public static function checkPassword($uid, $password) { |
|
| 389 | + $manager = \OC::$server->getUserManager(); |
|
| 390 | + $username = $manager->checkPassword($uid, $password); |
|
| 391 | + if ($username !== false) { |
|
| 392 | + return $username->getUID(); |
|
| 393 | + } |
|
| 394 | + return false; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @param string $uid The username |
|
| 399 | + * @return string |
|
| 400 | + * |
|
| 401 | + * returns the path to the users home directory |
|
| 402 | + * @deprecated Use \OC::$server->getUserManager->getHome() |
|
| 403 | + */ |
|
| 404 | + public static function getHome($uid) { |
|
| 405 | + $user = \OC::$server->getUserManager()->get($uid); |
|
| 406 | + if ($user) { |
|
| 407 | + return $user->getHome(); |
|
| 408 | + } else { |
|
| 409 | + return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Get a list of all users |
|
| 415 | + * |
|
| 416 | + * @return array an array of all uids |
|
| 417 | + * |
|
| 418 | + * Get a list of all users. |
|
| 419 | + * @param string $search |
|
| 420 | + * @param integer $limit |
|
| 421 | + * @param integer $offset |
|
| 422 | + */ |
|
| 423 | + public static function getUsers($search = '', $limit = null, $offset = null) { |
|
| 424 | + $users = \OC::$server->getUserManager()->search($search, $limit, $offset); |
|
| 425 | + $uids = array(); |
|
| 426 | + foreach ($users as $user) { |
|
| 427 | + $uids[] = $user->getUID(); |
|
| 428 | + } |
|
| 429 | + return $uids; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Get a list of all users display name |
|
| 434 | + * |
|
| 435 | + * @param string $search |
|
| 436 | + * @param int $limit |
|
| 437 | + * @param int $offset |
|
| 438 | + * @return array associative array with all display names (value) and corresponding uids (key) |
|
| 439 | + * |
|
| 440 | + * Get a list of all display names and user ids. |
|
| 441 | + * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead. |
|
| 442 | + */ |
|
| 443 | + public static function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 444 | + $displayNames = array(); |
|
| 445 | + $users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset); |
|
| 446 | + foreach ($users as $user) { |
|
| 447 | + $displayNames[$user->getUID()] = $user->getDisplayName(); |
|
| 448 | + } |
|
| 449 | + return $displayNames; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * check if a user exists |
|
| 454 | + * |
|
| 455 | + * @param string $uid the username |
|
| 456 | + * @return boolean |
|
| 457 | + */ |
|
| 458 | + public static function userExists($uid) { |
|
| 459 | + return \OC::$server->getUserManager()->userExists($uid); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * checks if a user is enabled |
|
| 464 | + * |
|
| 465 | + * @param string $uid |
|
| 466 | + * @return bool |
|
| 467 | + */ |
|
| 468 | + public static function isEnabled($uid) { |
|
| 469 | + $user = \OC::$server->getUserManager()->get($uid); |
|
| 470 | + if ($user) { |
|
| 471 | + return $user->isEnabled(); |
|
| 472 | + } else { |
|
| 473 | + return false; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Returns the first active backend from self::$_usedBackends. |
|
| 479 | + * |
|
| 480 | + * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend |
|
| 481 | + */ |
|
| 482 | + private static function findFirstActiveUsedBackend() { |
|
| 483 | + foreach (self::$_usedBackends as $backend) { |
|
| 484 | + if ($backend instanceof OCP\Authentication\IApacheBackend) { |
|
| 485 | + if ($backend->isSessionActive()) { |
|
| 486 | + return $backend; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + return null; |
|
| 492 | + } |
|
| 493 | 493 | } |
@@ -30,28 +30,28 @@ |
||
| 30 | 30 | |
| 31 | 31 | class ActionFactory implements IActionFactory { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param string $icon |
|
| 35 | - * @param string $name |
|
| 36 | - * @param string $href |
|
| 37 | - * @return ILinkAction |
|
| 38 | - */ |
|
| 39 | - public function newLinkAction($icon, $name, $href) { |
|
| 40 | - $action = new LinkAction(); |
|
| 41 | - $action->setName($name); |
|
| 42 | - $action->setIcon($icon); |
|
| 43 | - $action->setHref($href); |
|
| 44 | - return $action; |
|
| 45 | - } |
|
| 33 | + /** |
|
| 34 | + * @param string $icon |
|
| 35 | + * @param string $name |
|
| 36 | + * @param string $href |
|
| 37 | + * @return ILinkAction |
|
| 38 | + */ |
|
| 39 | + public function newLinkAction($icon, $name, $href) { |
|
| 40 | + $action = new LinkAction(); |
|
| 41 | + $action->setName($name); |
|
| 42 | + $action->setIcon($icon); |
|
| 43 | + $action->setHref($href); |
|
| 44 | + return $action; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param string $icon |
|
| 49 | - * @param string $name |
|
| 50 | - * @param string $email |
|
| 51 | - * @return ILinkAction |
|
| 52 | - */ |
|
| 53 | - public function newEMailAction($icon, $name, $email) { |
|
| 54 | - return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email)); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * @param string $icon |
|
| 49 | + * @param string $name |
|
| 50 | + * @param string $email |
|
| 51 | + * @return ILinkAction |
|
| 52 | + */ |
|
| 53 | + public function newEMailAction($icon, $name, $email) { |
|
| 54 | + return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email)); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | } |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | * @return ILinkAction |
| 52 | 52 | */ |
| 53 | 53 | public function newEMailAction($icon, $name, $email) { |
| 54 | - return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email)); |
|
| 54 | + return $this->newLinkAction($icon, $name, 'mailto:'.urlencode($email)); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | } |
@@ -28,76 +28,76 @@ |
||
| 28 | 28 | |
| 29 | 29 | class LinkAction implements ILinkAction { |
| 30 | 30 | |
| 31 | - /** @var string */ |
|
| 32 | - private $icon; |
|
| 33 | - |
|
| 34 | - /** @var string */ |
|
| 35 | - private $name; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - private $href; |
|
| 39 | - |
|
| 40 | - /** @var int */ |
|
| 41 | - private $priority = 10; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param string $icon absolute URI to an icon |
|
| 45 | - */ |
|
| 46 | - public function setIcon($icon) { |
|
| 47 | - $this->icon = $icon; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param string $name |
|
| 52 | - */ |
|
| 53 | - public function setName($name) { |
|
| 54 | - $this->name = $name; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function getName() { |
|
| 61 | - return $this->name; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param int $priority |
|
| 66 | - */ |
|
| 67 | - public function setPriority($priority) { |
|
| 68 | - $this->priority = $priority; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return int |
|
| 73 | - */ |
|
| 74 | - public function getPriority() { |
|
| 75 | - return $this->priority; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param string $href |
|
| 80 | - */ |
|
| 81 | - public function setHref($href) { |
|
| 82 | - $this->href = $href; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public function getHref() { |
|
| 89 | - return $this->href; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return array |
|
| 94 | - */ |
|
| 95 | - public function jsonSerialize() { |
|
| 96 | - return [ |
|
| 97 | - 'title' => $this->name, |
|
| 98 | - 'icon' => $this->icon, |
|
| 99 | - 'hyperlink' => $this->href, |
|
| 100 | - ]; |
|
| 101 | - } |
|
| 31 | + /** @var string */ |
|
| 32 | + private $icon; |
|
| 33 | + |
|
| 34 | + /** @var string */ |
|
| 35 | + private $name; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + private $href; |
|
| 39 | + |
|
| 40 | + /** @var int */ |
|
| 41 | + private $priority = 10; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param string $icon absolute URI to an icon |
|
| 45 | + */ |
|
| 46 | + public function setIcon($icon) { |
|
| 47 | + $this->icon = $icon; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param string $name |
|
| 52 | + */ |
|
| 53 | + public function setName($name) { |
|
| 54 | + $this->name = $name; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function getName() { |
|
| 61 | + return $this->name; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param int $priority |
|
| 66 | + */ |
|
| 67 | + public function setPriority($priority) { |
|
| 68 | + $this->priority = $priority; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return int |
|
| 73 | + */ |
|
| 74 | + public function getPriority() { |
|
| 75 | + return $this->priority; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param string $href |
|
| 80 | + */ |
|
| 81 | + public function setHref($href) { |
|
| 82 | + $this->href = $href; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public function getHref() { |
|
| 89 | + return $this->href; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return array |
|
| 94 | + */ |
|
| 95 | + public function jsonSerialize() { |
|
| 96 | + return [ |
|
| 97 | + 'title' => $this->name, |
|
| 98 | + 'icon' => $this->icon, |
|
| 99 | + 'hyperlink' => $this->href, |
|
| 100 | + ]; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | } |
@@ -33,33 +33,33 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | interface IAction extends JsonSerializable { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $icon absolute URI to an icon |
|
| 38 | - * @since 12.0 |
|
| 39 | - */ |
|
| 40 | - public function setIcon($icon); |
|
| 36 | + /** |
|
| 37 | + * @param string $icon absolute URI to an icon |
|
| 38 | + * @since 12.0 |
|
| 39 | + */ |
|
| 40 | + public function setIcon($icon); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return string localized action name, e.g. 'Call' |
|
| 44 | - * @since 12.0 |
|
| 45 | - */ |
|
| 46 | - public function getName(); |
|
| 42 | + /** |
|
| 43 | + * @return string localized action name, e.g. 'Call' |
|
| 44 | + * @since 12.0 |
|
| 45 | + */ |
|
| 46 | + public function getName(); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $name localized action name, e.g. 'Call' |
|
| 50 | - * @since 12.0 |
|
| 51 | - */ |
|
| 52 | - public function setName($name); |
|
| 48 | + /** |
|
| 49 | + * @param string $name localized action name, e.g. 'Call' |
|
| 50 | + * @since 12.0 |
|
| 51 | + */ |
|
| 52 | + public function setName($name); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param int $priority priorize actions, high order ones are shown on top |
|
| 56 | - * @since 12.0 |
|
| 57 | - */ |
|
| 58 | - public function setPriority($priority); |
|
| 54 | + /** |
|
| 55 | + * @param int $priority priorize actions, high order ones are shown on top |
|
| 56 | + * @since 12.0 |
|
| 57 | + */ |
|
| 58 | + public function setPriority($priority); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return int priority to priorize actions, high order ones are shown on top |
|
| 62 | - * @since 12.0 |
|
| 63 | - */ |
|
| 64 | - public function getPriority(); |
|
| 60 | + /** |
|
| 61 | + * @return int priority to priorize actions, high order ones are shown on top |
|
| 62 | + * @since 12.0 |
|
| 63 | + */ |
|
| 64 | + public function getPriority(); |
|
| 65 | 65 | } |
@@ -28,27 +28,27 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | interface IActionFactory { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Construct and return a new link action for the contacts menu |
|
| 33 | - * |
|
| 34 | - * @since 12.0 |
|
| 35 | - * |
|
| 36 | - * @param string $icon full path to the action's icon |
|
| 37 | - * @param string $name localized name of the action |
|
| 38 | - * @param string $href target URL |
|
| 39 | - * @return ILinkAction |
|
| 40 | - */ |
|
| 41 | - public function newLinkAction($icon, $name, $href); |
|
| 31 | + /** |
|
| 32 | + * Construct and return a new link action for the contacts menu |
|
| 33 | + * |
|
| 34 | + * @since 12.0 |
|
| 35 | + * |
|
| 36 | + * @param string $icon full path to the action's icon |
|
| 37 | + * @param string $name localized name of the action |
|
| 38 | + * @param string $href target URL |
|
| 39 | + * @return ILinkAction |
|
| 40 | + */ |
|
| 41 | + public function newLinkAction($icon, $name, $href); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Construct and return a new email action for the contacts menu |
|
| 45 | - * |
|
| 46 | - * @since 12.0 |
|
| 47 | - * |
|
| 48 | - * @param string $icon full path to the action's icon |
|
| 49 | - * @param string $name localized name of the action |
|
| 50 | - * @param string $email target e-mail address |
|
| 51 | - * @return ILinkAction |
|
| 52 | - */ |
|
| 53 | - public function newEMailAction($icon, $name, $email); |
|
| 43 | + /** |
|
| 44 | + * Construct and return a new email action for the contacts menu |
|
| 45 | + * |
|
| 46 | + * @since 12.0 |
|
| 47 | + * |
|
| 48 | + * @param string $icon full path to the action's icon |
|
| 49 | + * @param string $name localized name of the action |
|
| 50 | + * @param string $email target e-mail address |
|
| 51 | + * @return ILinkAction |
|
| 52 | + */ |
|
| 53 | + public function newEMailAction($icon, $name, $email); |
|
| 54 | 54 | } |
@@ -29,15 +29,15 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface ILinkAction extends IAction { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @since 12.0 |
|
| 34 | - * @param string $href the target URL of the action |
|
| 35 | - */ |
|
| 36 | - public function setHref($href); |
|
| 32 | + /** |
|
| 33 | + * @since 12.0 |
|
| 34 | + * @param string $href the target URL of the action |
|
| 35 | + */ |
|
| 36 | + public function setHref($href); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @since 12.0 |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function getHref(); |
|
| 38 | + /** |
|
| 39 | + * @since 12.0 |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function getHref(); |
|
| 43 | 43 | } |
@@ -33,6 +33,6 @@ |
||
| 33 | 33 | * @inheritdoc |
| 34 | 34 | */ |
| 35 | 35 | public function like($x, $y, $type = null) { |
| 36 | - return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
| 36 | + return parent::like($x, $y, $type)." ESCAPE '\\'"; |
|
| 37 | 37 | } |
| 38 | 38 | } |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | class SqliteExpressionBuilder extends ExpressionBuilder { |
| 26 | - /** |
|
| 27 | - * @inheritdoc |
|
| 28 | - */ |
|
| 29 | - public function like($x, $y, $type = null) { |
|
| 30 | - return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
| 31 | - } |
|
| 26 | + /** |
|
| 27 | + * @inheritdoc |
|
| 28 | + */ |
|
| 29 | + public function like($x, $y, $type = null) { |
|
| 30 | + return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | use OC\DB\QueryBuilder\QueryFunction; |
| 25 | 25 | |
| 26 | 26 | class OCIFunctionBuilder extends FunctionBuilder { |
| 27 | - public function md5($input) { |
|
| 28 | - return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))'); |
|
| 29 | - } |
|
| 27 | + public function md5($input) { |
|
| 28 | + return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))'); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -25,6 +25,6 @@ |
||
| 25 | 25 | |
| 26 | 26 | class OCIFunctionBuilder extends FunctionBuilder { |
| 27 | 27 | public function md5($input) { |
| 28 | - return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))'); |
|
| 28 | + return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw('.$this->helper->quoteColumnName($input).')))'); |
|
| 29 | 29 | } |
| 30 | 30 | } |