Completed
Push — master ( eba447...1a7516 )
by Blizzz
18:31
created
apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -33,78 +33,78 @@
 block discarded – undo
33 33
 
34 34
 class ShareRecipientSorter implements ISorter {
35 35
 
36
-	/** @var IManager */
37
-	private $shareManager;
38
-	/** @var Folder */
39
-	private $rootFolder;
40
-	/** @var IUserSession */
41
-	private $userSession;
36
+    /** @var IManager */
37
+    private $shareManager;
38
+    /** @var Folder */
39
+    private $rootFolder;
40
+    /** @var IUserSession */
41
+    private $userSession;
42 42
 
43
-	public function __construct(IManager $shareManager, IRootFolder $rootFolder, IUserSession $userSession) {
44
-		$this->shareManager = $shareManager;
45
-		$this->rootFolder = $rootFolder;
46
-		$this->userSession = $userSession;
47
-	}
43
+    public function __construct(IManager $shareManager, IRootFolder $rootFolder, IUserSession $userSession) {
44
+        $this->shareManager = $shareManager;
45
+        $this->rootFolder = $rootFolder;
46
+        $this->userSession = $userSession;
47
+    }
48 48
 
49
-	public function getId() {
50
-		return 'share-recipients';
51
-	}
49
+    public function getId() {
50
+        return 'share-recipients';
51
+    }
52 52
 
53
-	public function sort(array &$sortArray, array $context) {
54
-		// let's be tolerant. Comments  uses "files" by default, other usages are often singular
55
-		if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
56
-			return;
57
-		}
58
-		$user = $this->userSession->getUser();
59
-		if($user === null) {
60
-			return;
61
-		}
62
-		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
63
-		/** @var Node[] $nodes */
64
-		$nodes = $userFolder->getById((int)$context['itemId']);
65
-		if(count($nodes) === 0) {
66
-			return;
67
-		}
68
-		$al = $this->shareManager->getAccessList($nodes[0]);
53
+    public function sort(array &$sortArray, array $context) {
54
+        // let's be tolerant. Comments  uses "files" by default, other usages are often singular
55
+        if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
56
+            return;
57
+        }
58
+        $user = $this->userSession->getUser();
59
+        if($user === null) {
60
+            return;
61
+        }
62
+        $userFolder = $this->rootFolder->getUserFolder($user->getUID());
63
+        /** @var Node[] $nodes */
64
+        $nodes = $userFolder->getById((int)$context['itemId']);
65
+        if(count($nodes) === 0) {
66
+            return;
67
+        }
68
+        $al = $this->shareManager->getAccessList($nodes[0]);
69 69
 
70
-		foreach ($sortArray as $type => &$byType) {
71
-			if(!isset($al[$type]) || !is_array($al[$type])) {
72
-				continue;
73
-			}
70
+        foreach ($sortArray as $type => &$byType) {
71
+            if(!isset($al[$type]) || !is_array($al[$type])) {
72
+                continue;
73
+            }
74 74
 
75
-			// at least on PHP 5.6 usort turned out to be not stable. So we add
76
-			// the current index to the value and compare it on a draw
77
-			$i = 0;
78
-			$workArray = array_map(function($element) use (&$i) {
79
-				return [$i++, $element];
80
-			}, $byType);
75
+            // at least on PHP 5.6 usort turned out to be not stable. So we add
76
+            // the current index to the value and compare it on a draw
77
+            $i = 0;
78
+            $workArray = array_map(function($element) use (&$i) {
79
+                return [$i++, $element];
80
+            }, $byType);
81 81
 
82
-			usort($workArray, function ($a, $b) use ($al, $type) {
83
-				$result = $this->compare($a[1], $b[1], $al[$type]);
84
-				if($result === 0) {
85
-					$result = $a[0] - $b[0];
86
-				}
87
-				return $result;
88
-			});
82
+            usort($workArray, function ($a, $b) use ($al, $type) {
83
+                $result = $this->compare($a[1], $b[1], $al[$type]);
84
+                if($result === 0) {
85
+                    $result = $a[0] - $b[0];
86
+                }
87
+                return $result;
88
+            });
89 89
 
90
-			// and remove the index values again
91
-			$byType = array_column($workArray, 1);
92
-		}
93
-	}
90
+            // and remove the index values again
91
+            $byType = array_column($workArray, 1);
92
+        }
93
+    }
94 94
 
95
-	/**
96
-	 * @param array $a
97
-	 * @param array $b
98
-	 * @param array $al
99
-	 * @return int
100
-	 */
101
-	protected function compare(array $a, array $b, array $al) {
102
-		$a = $a['value']['shareWith'];
103
-		$b = $b['value']['shareWith'];
95
+    /**
96
+     * @param array $a
97
+     * @param array $b
98
+     * @param array $al
99
+     * @return int
100
+     */
101
+    protected function compare(array $a, array $b, array $al) {
102
+        $a = $a['value']['shareWith'];
103
+        $b = $b['value']['shareWith'];
104 104
 
105
-		$valueA = (int)in_array($a, $al, true);
106
-		$valueB = (int)in_array($b, $al, true);
105
+        $valueA = (int)in_array($a, $al, true);
106
+        $valueB = (int)in_array($b, $al, true);
107 107
 
108
-		return $valueB - $valueA;
109
-	}
108
+        return $valueB - $valueA;
109
+    }
110 110
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -52,23 +52,23 @@  discard block
 block discarded – undo
52 52
 
53 53
 	public function sort(array &$sortArray, array $context) {
54 54
 		// let's be tolerant. Comments  uses "files" by default, other usages are often singular
55
-		if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
55
+		if ($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
56 56
 			return;
57 57
 		}
58 58
 		$user = $this->userSession->getUser();
59
-		if($user === null) {
59
+		if ($user === null) {
60 60
 			return;
61 61
 		}
62 62
 		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
63 63
 		/** @var Node[] $nodes */
64
-		$nodes = $userFolder->getById((int)$context['itemId']);
65
-		if(count($nodes) === 0) {
64
+		$nodes = $userFolder->getById((int) $context['itemId']);
65
+		if (count($nodes) === 0) {
66 66
 			return;
67 67
 		}
68 68
 		$al = $this->shareManager->getAccessList($nodes[0]);
69 69
 
70 70
 		foreach ($sortArray as $type => &$byType) {
71
-			if(!isset($al[$type]) || !is_array($al[$type])) {
71
+			if (!isset($al[$type]) || !is_array($al[$type])) {
72 72
 				continue;
73 73
 			}
74 74
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 				return [$i++, $element];
80 80
 			}, $byType);
81 81
 
82
-			usort($workArray, function ($a, $b) use ($al, $type) {
82
+			usort($workArray, function($a, $b) use ($al, $type) {
83 83
 				$result = $this->compare($a[1], $b[1], $al[$type]);
84
-				if($result === 0) {
84
+				if ($result === 0) {
85 85
 					$result = $a[0] - $b[0];
86 86
 				}
87 87
 				return $result;
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 		$a = $a['value']['shareWith'];
103 103
 		$b = $b['value']['shareWith'];
104 104
 
105
-		$valueA = (int)in_array($a, $al, true);
106
-		$valueB = (int)in_array($b, $al, true);
105
+		$valueA = (int) in_array($a, $al, true);
106
+		$valueB = (int) in_array($b, $al, true);
107 107
 
108 108
 		return $valueB - $valueA;
109 109
 	}
Please login to merge, or discard this patch.
apps/comments/lib/Collaboration/CommentersSorter.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -29,87 +29,87 @@
 block discarded – undo
29 29
 
30 30
 class CommentersSorter implements ISorter {
31 31
 
32
-	/** @var ICommentsManager */
33
-	private $commentsManager;
34
-
35
-	public function __construct(ICommentsManager $commentsManager) {
36
-		$this->commentsManager = $commentsManager;
37
-	}
38
-
39
-	public function getId() {
40
-		return 'commenters';
41
-	}
42
-
43
-	/**
44
-	 * Sorts people who commented on the given item atop (descelating) of the
45
-	 * others
46
-	 *
47
-	 * @param array $sortArray
48
-	 * @param array $context
49
-	 */
50
-	public function sort(array &$sortArray, array $context) {
51
-		$commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
52
-		if(count($commenters) === 0) {
53
-			return;
54
-		}
55
-
56
-		foreach ($sortArray as $type => &$byType) {
57
-			if(!isset($commenters[$type])) {
58
-				continue;
59
-			}
60
-
61
-			// at least on PHP 5.6 usort turned out to be not stable. So we add
62
-			// the current index to the value and compare it on a draw
63
-			$i = 0;
64
-			$workArray = array_map(function($element) use (&$i) {
65
-				return [$i++, $element];
66
-			}, $byType);
67
-
68
-			usort($workArray, function ($a, $b) use ($commenters, $type) {
69
-				$r = $this->compare($a[1], $b[1], $commenters[$type]);
70
-				if($r === 0) {
71
-					$r = $a[0] - $b[0];
72
-				}
73
-				return $r;
74
-			});
75
-
76
-			// and remove the index values again
77
-			$byType = array_column($workArray, 1);
78
-		}
79
-	}
80
-
81
-	/**
82
-	 * @param $type
83
-	 * @param $id
84
-	 * @return array
85
-	 */
86
-	protected function retrieveCommentsInformation($type, $id) {
87
-		$comments = $this->commentsManager->getForObject($type, $id);
88
-		if(count($comments) === 0) {
89
-			return [];
90
-		}
91
-
92
-		$actors = [];
93
-		foreach ($comments as $comment) {
94
-			if(!isset($actors[$comment->getActorType()])) {
95
-				$actors[$comment->getActorType()] = [];
96
-			}
97
-			if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
98
-				$actors[$comment->getActorType()][$comment->getActorId()] = 1;
99
-			} else {
100
-				$actors[$comment->getActorType()][$comment->getActorId()]++;
101
-			}
102
-		}
103
-		return $actors;
104
-	}
105
-
106
-	protected function compare(array $a, array $b, array $commenters) {
107
-		$a = $a['value']['shareWith'];
108
-		$b = $b['value']['shareWith'];
109
-
110
-		$valueA = isset($commenters[$a]) ? $commenters[$a] : 0;
111
-		$valueB = isset($commenters[$b]) ? $commenters[$b] : 0;
112
-
113
-		return $valueB - $valueA;
114
-	}
32
+    /** @var ICommentsManager */
33
+    private $commentsManager;
34
+
35
+    public function __construct(ICommentsManager $commentsManager) {
36
+        $this->commentsManager = $commentsManager;
37
+    }
38
+
39
+    public function getId() {
40
+        return 'commenters';
41
+    }
42
+
43
+    /**
44
+     * Sorts people who commented on the given item atop (descelating) of the
45
+     * others
46
+     *
47
+     * @param array $sortArray
48
+     * @param array $context
49
+     */
50
+    public function sort(array &$sortArray, array $context) {
51
+        $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
52
+        if(count($commenters) === 0) {
53
+            return;
54
+        }
55
+
56
+        foreach ($sortArray as $type => &$byType) {
57
+            if(!isset($commenters[$type])) {
58
+                continue;
59
+            }
60
+
61
+            // at least on PHP 5.6 usort turned out to be not stable. So we add
62
+            // the current index to the value and compare it on a draw
63
+            $i = 0;
64
+            $workArray = array_map(function($element) use (&$i) {
65
+                return [$i++, $element];
66
+            }, $byType);
67
+
68
+            usort($workArray, function ($a, $b) use ($commenters, $type) {
69
+                $r = $this->compare($a[1], $b[1], $commenters[$type]);
70
+                if($r === 0) {
71
+                    $r = $a[0] - $b[0];
72
+                }
73
+                return $r;
74
+            });
75
+
76
+            // and remove the index values again
77
+            $byType = array_column($workArray, 1);
78
+        }
79
+    }
80
+
81
+    /**
82
+     * @param $type
83
+     * @param $id
84
+     * @return array
85
+     */
86
+    protected function retrieveCommentsInformation($type, $id) {
87
+        $comments = $this->commentsManager->getForObject($type, $id);
88
+        if(count($comments) === 0) {
89
+            return [];
90
+        }
91
+
92
+        $actors = [];
93
+        foreach ($comments as $comment) {
94
+            if(!isset($actors[$comment->getActorType()])) {
95
+                $actors[$comment->getActorType()] = [];
96
+            }
97
+            if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
98
+                $actors[$comment->getActorType()][$comment->getActorId()] = 1;
99
+            } else {
100
+                $actors[$comment->getActorType()][$comment->getActorId()]++;
101
+            }
102
+        }
103
+        return $actors;
104
+    }
105
+
106
+    protected function compare(array $a, array $b, array $commenters) {
107
+        $a = $a['value']['shareWith'];
108
+        $b = $b['value']['shareWith'];
109
+
110
+        $valueA = isset($commenters[$a]) ? $commenters[$a] : 0;
111
+        $valueB = isset($commenters[$b]) ? $commenters[$b] : 0;
112
+
113
+        return $valueB - $valueA;
114
+    }
115 115
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function sort(array &$sortArray, array $context) {
51 51
 		$commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
52
-		if(count($commenters) === 0) {
52
+		if (count($commenters) === 0) {
53 53
 			return;
54 54
 		}
55 55
 
56 56
 		foreach ($sortArray as $type => &$byType) {
57
-			if(!isset($commenters[$type])) {
57
+			if (!isset($commenters[$type])) {
58 58
 				continue;
59 59
 			}
60 60
 
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 				return [$i++, $element];
66 66
 			}, $byType);
67 67
 
68
-			usort($workArray, function ($a, $b) use ($commenters, $type) {
68
+			usort($workArray, function($a, $b) use ($commenters, $type) {
69 69
 				$r = $this->compare($a[1], $b[1], $commenters[$type]);
70
-				if($r === 0) {
70
+				if ($r === 0) {
71 71
 					$r = $a[0] - $b[0];
72 72
 				}
73 73
 				return $r;
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	protected function retrieveCommentsInformation($type, $id) {
87 87
 		$comments = $this->commentsManager->getForObject($type, $id);
88
-		if(count($comments) === 0) {
88
+		if (count($comments) === 0) {
89 89
 			return [];
90 90
 		}
91 91
 
92 92
 		$actors = [];
93 93
 		foreach ($comments as $comment) {
94
-			if(!isset($actors[$comment->getActorType()])) {
94
+			if (!isset($actors[$comment->getActorType()])) {
95 95
 				$actors[$comment->getActorType()] = [];
96 96
 			}
97
-			if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
97
+			if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
98 98
 				$actors[$comment->getActorType()][$comment->getActorId()] = 1;
99 99
 			} else {
100 100
 				$actors[$comment->getActorType()][$comment->getActorId()]++;
Please login to merge, or discard this patch.
lib/private/DB/OracleMigrator.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -34,194 +34,194 @@
 block discarded – undo
34 34
 
35 35
 class OracleMigrator extends Migrator {
36 36
 
37
-	/**
38
-	 * Quote a column's name but changing the name requires recreating
39
-	 * the column instance and copying over all properties.
40
-	 *
41
-	 * @param Column $column old column
42
-	 * @return Column new column instance with new name
43
-	 */
44
-	protected function quoteColumn(Column $column) {
45
-		$newColumn = new Column(
46
-			$this->connection->quoteIdentifier($column->getName()),
47
-			$column->getType()
48
-		);
49
-		$newColumn->setAutoincrement($column->getAutoincrement());
50
-		$newColumn->setColumnDefinition($column->getColumnDefinition());
51
-		$newColumn->setComment($column->getComment());
52
-		$newColumn->setDefault($column->getDefault());
53
-		$newColumn->setFixed($column->getFixed());
54
-		$newColumn->setLength($column->getLength());
55
-		$newColumn->setNotnull($column->getNotnull());
56
-		$newColumn->setPrecision($column->getPrecision());
57
-		$newColumn->setScale($column->getScale());
58
-		$newColumn->setUnsigned($column->getUnsigned());
59
-		$newColumn->setPlatformOptions($column->getPlatformOptions());
60
-		$newColumn->setCustomSchemaOptions($column->getPlatformOptions());
61
-		return $newColumn;
62
-	}
63
-
64
-	/**
65
-	 * Quote an index's name but changing the name requires recreating
66
-	 * the index instance and copying over all properties.
67
-	 *
68
-	 * @param Index $index old index
69
-	 * @return Index new index instance with new name
70
-	 */
71
-	protected function quoteIndex($index) {
72
-		return new Index(
73
-		//TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()),
74
-			$index->getName(),
75
-			array_map(function($columnName) {
76
-				return $this->connection->quoteIdentifier($columnName);
77
-			}, $index->getColumns()),
78
-			$index->isUnique(),
79
-			$index->isPrimary(),
80
-			$index->getFlags(),
81
-			$index->getOptions()
82
-		);
83
-	}
84
-
85
-	/**
86
-	 * Quote an ForeignKeyConstraint's name but changing the name requires recreating
87
-	 * the ForeignKeyConstraint instance and copying over all properties.
88
-	 *
89
-	 * @param ForeignKeyConstraint $fkc old fkc
90
-	 * @return ForeignKeyConstraint new fkc instance with new name
91
-	 */
92
-	protected function quoteForeignKeyConstraint($fkc) {
93
-		return new ForeignKeyConstraint(
94
-			array_map(function($columnName) {
95
-				return $this->connection->quoteIdentifier($columnName);
96
-			}, $fkc->getLocalColumns()),
97
-			$this->connection->quoteIdentifier($fkc->getForeignTableName()),
98
-			array_map(function($columnName) {
99
-				return $this->connection->quoteIdentifier($columnName);
100
-			}, $fkc->getForeignColumns()),
101
-			$fkc->getName(),
102
-			$fkc->getOptions()
103
-		);
104
-	}
105
-
106
-	/**
107
-	 * @param Schema $targetSchema
108
-	 * @param \Doctrine\DBAL\Connection $connection
109
-	 * @return \Doctrine\DBAL\Schema\SchemaDiff
110
-	 * @throws DBALException
111
-	 */
112
-	protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
113
-		$schemaDiff = parent::getDiff($targetSchema, $connection);
114
-
115
-		// oracle forces us to quote the identifiers
116
-		$schemaDiff->newTables = array_map(function(Table $table) {
117
-			return new Table(
118
-				$this->connection->quoteIdentifier($table->getName()),
119
-				array_map(function(Column $column) {
120
-					return $this->quoteColumn($column);
121
-				}, $table->getColumns()),
122
-				array_map(function(Index $index) {
123
-					return $this->quoteIndex($index);
124
-				}, $table->getIndexes()),
125
-				array_map(function(ForeignKeyConstraint $fck) {
126
-					return $this->quoteForeignKeyConstraint($fck);
127
-				}, $table->getForeignKeys()),
128
-				0,
129
-				$table->getOptions()
130
-			);
131
-		}, $schemaDiff->newTables);
132
-
133
-		$schemaDiff->removedTables = array_map(function(Table $table) {
134
-			return new Table(
135
-				$this->connection->quoteIdentifier($table->getName()),
136
-				$table->getColumns(),
137
-				$table->getIndexes(),
138
-				$table->getForeignKeys(),
139
-				0,
140
-				$table->getOptions()
141
-			);
142
-		}, $schemaDiff->removedTables);
143
-
144
-		foreach ($schemaDiff->changedTables as $tableDiff) {
145
-			$tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
146
-
147
-			$tableDiff->addedColumns = array_map(function(Column $column) {
148
-				return $this->quoteColumn($column);
149
-			}, $tableDiff->addedColumns);
150
-
151
-			foreach ($tableDiff->changedColumns as $column) {
152
-				$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
153
-				// auto increment is not relevant for oracle and can anyhow not be applied on change
154
-				$column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
155
-			}
156
-			// remove columns that no longer have changed (because autoincrement and unsigned are not supported)
157
-			$tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) {
158
-				return count($column->changedProperties) > 0;
159
-			});
160
-
161
-			$tableDiff->removedColumns = array_map(function(Column $column) {
162
-				return $this->quoteColumn($column);
163
-			}, $tableDiff->removedColumns);
164
-
165
-			$tableDiff->renamedColumns = array_map(function(Column $column) {
166
-				return $this->quoteColumn($column);
167
-			}, $tableDiff->renamedColumns);
168
-
169
-			$tableDiff->addedIndexes = array_map(function(Index $index) {
170
-				return $this->quoteIndex($index);
171
-			}, $tableDiff->addedIndexes);
172
-
173
-			$tableDiff->changedIndexes = array_map(function(Index $index) {
174
-				return $this->quoteIndex($index);
175
-			}, $tableDiff->changedIndexes);
176
-
177
-			$tableDiff->removedIndexes = array_map(function(Index $index) {
178
-				return $this->quoteIndex($index);
179
-			}, $tableDiff->removedIndexes);
180
-
181
-			$tableDiff->renamedIndexes = array_map(function(Index $index) {
182
-				return $this->quoteIndex($index);
183
-			}, $tableDiff->renamedIndexes);
184
-
185
-			$tableDiff->addedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
186
-				return $this->quoteForeignKeyConstraint($fkc);
187
-			}, $tableDiff->addedForeignKeys);
188
-
189
-			$tableDiff->changedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
190
-				return $this->quoteForeignKeyConstraint($fkc);
191
-			}, $tableDiff->changedForeignKeys);
192
-
193
-			$tableDiff->removedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
194
-				return $this->quoteForeignKeyConstraint($fkc);
195
-			}, $tableDiff->removedForeignKeys);
196
-		}
197
-
198
-		return $schemaDiff;
199
-	}
200
-
201
-	/**
202
-	 * @param string $name
203
-	 * @return string
204
-	 */
205
-	protected function generateTemporaryTableName($name) {
206
-		return 'oc_' . uniqid();
207
-	}
208
-
209
-	/**
210
-	 * @param $statement
211
-	 * @return string
212
-	 */
213
-	protected function convertStatementToScript($statement) {
214
-		if (substr($statement, -1) === ';') {
215
-			return $statement . PHP_EOL . '/' . PHP_EOL;
216
-		}
217
-		$script = $statement . ';';
218
-		$script .= PHP_EOL;
219
-		$script .= PHP_EOL;
220
-		return $script;
221
-	}
222
-
223
-	protected function getFilterExpression() {
224
-		return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
225
-	}
37
+    /**
38
+     * Quote a column's name but changing the name requires recreating
39
+     * the column instance and copying over all properties.
40
+     *
41
+     * @param Column $column old column
42
+     * @return Column new column instance with new name
43
+     */
44
+    protected function quoteColumn(Column $column) {
45
+        $newColumn = new Column(
46
+            $this->connection->quoteIdentifier($column->getName()),
47
+            $column->getType()
48
+        );
49
+        $newColumn->setAutoincrement($column->getAutoincrement());
50
+        $newColumn->setColumnDefinition($column->getColumnDefinition());
51
+        $newColumn->setComment($column->getComment());
52
+        $newColumn->setDefault($column->getDefault());
53
+        $newColumn->setFixed($column->getFixed());
54
+        $newColumn->setLength($column->getLength());
55
+        $newColumn->setNotnull($column->getNotnull());
56
+        $newColumn->setPrecision($column->getPrecision());
57
+        $newColumn->setScale($column->getScale());
58
+        $newColumn->setUnsigned($column->getUnsigned());
59
+        $newColumn->setPlatformOptions($column->getPlatformOptions());
60
+        $newColumn->setCustomSchemaOptions($column->getPlatformOptions());
61
+        return $newColumn;
62
+    }
63
+
64
+    /**
65
+     * Quote an index's name but changing the name requires recreating
66
+     * the index instance and copying over all properties.
67
+     *
68
+     * @param Index $index old index
69
+     * @return Index new index instance with new name
70
+     */
71
+    protected function quoteIndex($index) {
72
+        return new Index(
73
+        //TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()),
74
+            $index->getName(),
75
+            array_map(function($columnName) {
76
+                return $this->connection->quoteIdentifier($columnName);
77
+            }, $index->getColumns()),
78
+            $index->isUnique(),
79
+            $index->isPrimary(),
80
+            $index->getFlags(),
81
+            $index->getOptions()
82
+        );
83
+    }
84
+
85
+    /**
86
+     * Quote an ForeignKeyConstraint's name but changing the name requires recreating
87
+     * the ForeignKeyConstraint instance and copying over all properties.
88
+     *
89
+     * @param ForeignKeyConstraint $fkc old fkc
90
+     * @return ForeignKeyConstraint new fkc instance with new name
91
+     */
92
+    protected function quoteForeignKeyConstraint($fkc) {
93
+        return new ForeignKeyConstraint(
94
+            array_map(function($columnName) {
95
+                return $this->connection->quoteIdentifier($columnName);
96
+            }, $fkc->getLocalColumns()),
97
+            $this->connection->quoteIdentifier($fkc->getForeignTableName()),
98
+            array_map(function($columnName) {
99
+                return $this->connection->quoteIdentifier($columnName);
100
+            }, $fkc->getForeignColumns()),
101
+            $fkc->getName(),
102
+            $fkc->getOptions()
103
+        );
104
+    }
105
+
106
+    /**
107
+     * @param Schema $targetSchema
108
+     * @param \Doctrine\DBAL\Connection $connection
109
+     * @return \Doctrine\DBAL\Schema\SchemaDiff
110
+     * @throws DBALException
111
+     */
112
+    protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
113
+        $schemaDiff = parent::getDiff($targetSchema, $connection);
114
+
115
+        // oracle forces us to quote the identifiers
116
+        $schemaDiff->newTables = array_map(function(Table $table) {
117
+            return new Table(
118
+                $this->connection->quoteIdentifier($table->getName()),
119
+                array_map(function(Column $column) {
120
+                    return $this->quoteColumn($column);
121
+                }, $table->getColumns()),
122
+                array_map(function(Index $index) {
123
+                    return $this->quoteIndex($index);
124
+                }, $table->getIndexes()),
125
+                array_map(function(ForeignKeyConstraint $fck) {
126
+                    return $this->quoteForeignKeyConstraint($fck);
127
+                }, $table->getForeignKeys()),
128
+                0,
129
+                $table->getOptions()
130
+            );
131
+        }, $schemaDiff->newTables);
132
+
133
+        $schemaDiff->removedTables = array_map(function(Table $table) {
134
+            return new Table(
135
+                $this->connection->quoteIdentifier($table->getName()),
136
+                $table->getColumns(),
137
+                $table->getIndexes(),
138
+                $table->getForeignKeys(),
139
+                0,
140
+                $table->getOptions()
141
+            );
142
+        }, $schemaDiff->removedTables);
143
+
144
+        foreach ($schemaDiff->changedTables as $tableDiff) {
145
+            $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
146
+
147
+            $tableDiff->addedColumns = array_map(function(Column $column) {
148
+                return $this->quoteColumn($column);
149
+            }, $tableDiff->addedColumns);
150
+
151
+            foreach ($tableDiff->changedColumns as $column) {
152
+                $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
153
+                // auto increment is not relevant for oracle and can anyhow not be applied on change
154
+                $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
155
+            }
156
+            // remove columns that no longer have changed (because autoincrement and unsigned are not supported)
157
+            $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) {
158
+                return count($column->changedProperties) > 0;
159
+            });
160
+
161
+            $tableDiff->removedColumns = array_map(function(Column $column) {
162
+                return $this->quoteColumn($column);
163
+            }, $tableDiff->removedColumns);
164
+
165
+            $tableDiff->renamedColumns = array_map(function(Column $column) {
166
+                return $this->quoteColumn($column);
167
+            }, $tableDiff->renamedColumns);
168
+
169
+            $tableDiff->addedIndexes = array_map(function(Index $index) {
170
+                return $this->quoteIndex($index);
171
+            }, $tableDiff->addedIndexes);
172
+
173
+            $tableDiff->changedIndexes = array_map(function(Index $index) {
174
+                return $this->quoteIndex($index);
175
+            }, $tableDiff->changedIndexes);
176
+
177
+            $tableDiff->removedIndexes = array_map(function(Index $index) {
178
+                return $this->quoteIndex($index);
179
+            }, $tableDiff->removedIndexes);
180
+
181
+            $tableDiff->renamedIndexes = array_map(function(Index $index) {
182
+                return $this->quoteIndex($index);
183
+            }, $tableDiff->renamedIndexes);
184
+
185
+            $tableDiff->addedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
186
+                return $this->quoteForeignKeyConstraint($fkc);
187
+            }, $tableDiff->addedForeignKeys);
188
+
189
+            $tableDiff->changedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
190
+                return $this->quoteForeignKeyConstraint($fkc);
191
+            }, $tableDiff->changedForeignKeys);
192
+
193
+            $tableDiff->removedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
194
+                return $this->quoteForeignKeyConstraint($fkc);
195
+            }, $tableDiff->removedForeignKeys);
196
+        }
197
+
198
+        return $schemaDiff;
199
+    }
200
+
201
+    /**
202
+     * @param string $name
203
+     * @return string
204
+     */
205
+    protected function generateTemporaryTableName($name) {
206
+        return 'oc_' . uniqid();
207
+    }
208
+
209
+    /**
210
+     * @param $statement
211
+     * @return string
212
+     */
213
+    protected function convertStatementToScript($statement) {
214
+        if (substr($statement, -1) === ';') {
215
+            return $statement . PHP_EOL . '/' . PHP_EOL;
216
+        }
217
+        $script = $statement . ';';
218
+        $script .= PHP_EOL;
219
+        $script .= PHP_EOL;
220
+        return $script;
221
+    }
222
+
223
+    protected function getFilterExpression() {
224
+        return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 				$column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
155 155
 			}
156 156
 			// remove columns that no longer have changed (because autoincrement and unsigned are not supported)
157
-			$tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) {
157
+			$tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function(ColumnDiff $column) {
158 158
 				return count($column->changedProperties) > 0;
159 159
 			});
160 160
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @return string
204 204
 	 */
205 205
 	protected function generateTemporaryTableName($name) {
206
-		return 'oc_' . uniqid();
206
+		return 'oc_'.uniqid();
207 207
 	}
208 208
 
209 209
 	/**
@@ -212,16 +212,16 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	protected function convertStatementToScript($statement) {
214 214
 		if (substr($statement, -1) === ';') {
215
-			return $statement . PHP_EOL . '/' . PHP_EOL;
215
+			return $statement.PHP_EOL.'/'.PHP_EOL;
216 216
 		}
217
-		$script = $statement . ';';
217
+		$script = $statement.';';
218 218
 		$script .= PHP_EOL;
219 219
 		$script .= PHP_EOL;
220 220
 		return $script;
221 221
 	}
222 222
 
223 223
 	protected function getFilterExpression() {
224
-		return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
224
+		return '/^"'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/';
225 225
 	}
226 226
 
227 227
 }
Please login to merge, or discard this patch.
lib/private/DB/MDB2SchemaManager.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -37,136 +37,136 @@
 block discarded – undo
37 37
 use OCP\IDBConnection;
38 38
 
39 39
 class MDB2SchemaManager {
40
-	/** @var \OC\DB\Connection $conn */
41
-	protected $conn;
40
+    /** @var \OC\DB\Connection $conn */
41
+    protected $conn;
42 42
 
43
-	/**
44
-	 * @param IDBConnection $conn
45
-	 */
46
-	public function __construct($conn) {
47
-		$this->conn = $conn;
48
-	}
43
+    /**
44
+     * @param IDBConnection $conn
45
+     */
46
+    public function __construct($conn) {
47
+        $this->conn = $conn;
48
+    }
49 49
 
50
-	/**
51
-	 * saves database scheme to xml file
52
-	 * @param string $file name of file
53
-	 * @return bool
54
-	 *
55
-	 * TODO: write more documentation
56
-	 */
57
-	public function getDbStructure($file) {
58
-		return \OC\DB\MDB2SchemaWriter::saveSchemaToFile($file, $this->conn);
59
-	}
50
+    /**
51
+     * saves database scheme to xml file
52
+     * @param string $file name of file
53
+     * @return bool
54
+     *
55
+     * TODO: write more documentation
56
+     */
57
+    public function getDbStructure($file) {
58
+        return \OC\DB\MDB2SchemaWriter::saveSchemaToFile($file, $this->conn);
59
+    }
60 60
 
61
-	/**
62
-	 * Creates tables from XML file
63
-	 * @param string $file file to read structure from
64
-	 * @return bool
65
-	 *
66
-	 * TODO: write more documentation
67
-	 */
68
-	public function createDbFromStructure($file) {
69
-		$schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform());
70
-		$toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
71
-		$toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema);
72
-		return $this->executeSchemaChange($toSchema);
73
-	}
61
+    /**
62
+     * Creates tables from XML file
63
+     * @param string $file file to read structure from
64
+     * @return bool
65
+     *
66
+     * TODO: write more documentation
67
+     */
68
+    public function createDbFromStructure($file) {
69
+        $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform());
70
+        $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
71
+        $toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema);
72
+        return $this->executeSchemaChange($toSchema);
73
+    }
74 74
 
75
-	/**
76
-	 * @return \OC\DB\Migrator
77
-	 */
78
-	public function getMigrator() {
79
-		$random = \OC::$server->getSecureRandom();
80
-		$platform = $this->conn->getDatabasePlatform();
81
-		$config = \OC::$server->getConfig();
82
-		$dispatcher = \OC::$server->getEventDispatcher();
83
-		if ($platform instanceof SqlitePlatform) {
84
-			return new SQLiteMigrator($this->conn, $random, $config, $dispatcher);
85
-		} else if ($platform instanceof OraclePlatform) {
86
-			return new OracleMigrator($this->conn, $random, $config, $dispatcher);
87
-		} else if ($platform instanceof MySqlPlatform) {
88
-			return new MySQLMigrator($this->conn, $random, $config, $dispatcher);
89
-		} else if ($platform instanceof PostgreSqlPlatform) {
90
-			return new PostgreSqlMigrator($this->conn, $random, $config, $dispatcher);
91
-		} else {
92
-			return new Migrator($this->conn, $random, $config, $dispatcher);
93
-		}
94
-	}
75
+    /**
76
+     * @return \OC\DB\Migrator
77
+     */
78
+    public function getMigrator() {
79
+        $random = \OC::$server->getSecureRandom();
80
+        $platform = $this->conn->getDatabasePlatform();
81
+        $config = \OC::$server->getConfig();
82
+        $dispatcher = \OC::$server->getEventDispatcher();
83
+        if ($platform instanceof SqlitePlatform) {
84
+            return new SQLiteMigrator($this->conn, $random, $config, $dispatcher);
85
+        } else if ($platform instanceof OraclePlatform) {
86
+            return new OracleMigrator($this->conn, $random, $config, $dispatcher);
87
+        } else if ($platform instanceof MySqlPlatform) {
88
+            return new MySQLMigrator($this->conn, $random, $config, $dispatcher);
89
+        } else if ($platform instanceof PostgreSqlPlatform) {
90
+            return new PostgreSqlMigrator($this->conn, $random, $config, $dispatcher);
91
+        } else {
92
+            return new Migrator($this->conn, $random, $config, $dispatcher);
93
+        }
94
+    }
95 95
 
96
-	/**
97
-	 * Reads database schema from file
98
-	 *
99
-	 * @param string $file file to read from
100
-	 * @return \Doctrine\DBAL\Schema\Schema
101
-	 */
102
-	private function readSchemaFromFile($file) {
103
-		$platform = $this->conn->getDatabasePlatform();
104
-		$schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform);
105
-		$toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
106
-		return $schemaReader->loadSchemaFromFile($file, $toSchema);
107
-	}
96
+    /**
97
+     * Reads database schema from file
98
+     *
99
+     * @param string $file file to read from
100
+     * @return \Doctrine\DBAL\Schema\Schema
101
+     */
102
+    private function readSchemaFromFile($file) {
103
+        $platform = $this->conn->getDatabasePlatform();
104
+        $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform);
105
+        $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
106
+        return $schemaReader->loadSchemaFromFile($file, $toSchema);
107
+    }
108 108
 
109
-	/**
110
-	 * update the database scheme
111
-	 * @param string $file file to read structure from
112
-	 * @param bool $generateSql only return the sql needed for the upgrade
113
-	 * @return string|boolean
114
-	 */
115
-	public function updateDbFromStructure($file, $generateSql = false) {
116
-		$toSchema = $this->readSchemaFromFile($file);
117
-		$migrator = $this->getMigrator();
109
+    /**
110
+     * update the database scheme
111
+     * @param string $file file to read structure from
112
+     * @param bool $generateSql only return the sql needed for the upgrade
113
+     * @return string|boolean
114
+     */
115
+    public function updateDbFromStructure($file, $generateSql = false) {
116
+        $toSchema = $this->readSchemaFromFile($file);
117
+        $migrator = $this->getMigrator();
118 118
 
119
-		if ($generateSql) {
120
-			return $migrator->generateChangeScript($toSchema);
121
-		} else {
122
-			$migrator->migrate($toSchema);
123
-			return true;
124
-		}
125
-	}
119
+        if ($generateSql) {
120
+            return $migrator->generateChangeScript($toSchema);
121
+        } else {
122
+            $migrator->migrate($toSchema);
123
+            return true;
124
+        }
125
+    }
126 126
 
127
-	/**
128
-	 * @param \Doctrine\DBAL\Schema\Schema $schema
129
-	 * @return string
130
-	 */
131
-	public function generateChangeScript($schema) {
132
-		$migrator = $this->getMigrator();
133
-		return $migrator->generateChangeScript($schema);
134
-	}
127
+    /**
128
+     * @param \Doctrine\DBAL\Schema\Schema $schema
129
+     * @return string
130
+     */
131
+    public function generateChangeScript($schema) {
132
+        $migrator = $this->getMigrator();
133
+        return $migrator->generateChangeScript($schema);
134
+    }
135 135
 
136
-	/**
137
-	 * remove all tables defined in a database structure xml file
138
-	 *
139
-	 * @param string $file the xml file describing the tables
140
-	 */
141
-	public function removeDBStructure($file) {
142
-		$schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform());
143
-		$toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
144
-		$fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema);
145
-		$toSchema = clone $fromSchema;
146
-		/** @var $table \Doctrine\DBAL\Schema\Table */
147
-		foreach ($toSchema->getTables() as $table) {
148
-			$toSchema->dropTable($table->getName());
149
-		}
150
-		$comparator = new \Doctrine\DBAL\Schema\Comparator();
151
-		$schemaDiff = $comparator->compare($fromSchema, $toSchema);
152
-		$this->executeSchemaChange($schemaDiff);
153
-	}
136
+    /**
137
+     * remove all tables defined in a database structure xml file
138
+     *
139
+     * @param string $file the xml file describing the tables
140
+     */
141
+    public function removeDBStructure($file) {
142
+        $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform());
143
+        $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
144
+        $fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema);
145
+        $toSchema = clone $fromSchema;
146
+        /** @var $table \Doctrine\DBAL\Schema\Table */
147
+        foreach ($toSchema->getTables() as $table) {
148
+            $toSchema->dropTable($table->getName());
149
+        }
150
+        $comparator = new \Doctrine\DBAL\Schema\Comparator();
151
+        $schemaDiff = $comparator->compare($fromSchema, $toSchema);
152
+        $this->executeSchemaChange($schemaDiff);
153
+    }
154 154
 
155
-	/**
156
-	 * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema
157
-	 * @return bool
158
-	 */
159
-	private function executeSchemaChange($schema) {
160
-		$this->conn->beginTransaction();
161
-		foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) {
162
-			$this->conn->query($sql);
163
-		}
164
-		$this->conn->commit();
155
+    /**
156
+     * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema
157
+     * @return bool
158
+     */
159
+    private function executeSchemaChange($schema) {
160
+        $this->conn->beginTransaction();
161
+        foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) {
162
+            $this->conn->query($sql);
163
+        }
164
+        $this->conn->commit();
165 165
 
166
-		if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) {
167
-			$this->conn->close();
168
-			$this->conn->connect();
169
-		}
170
-		return true;
171
-	}
166
+        if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) {
167
+            $this->conn->close();
168
+            $this->conn->connect();
169
+        }
170
+        return true;
171
+    }
172 172
 }
Please login to merge, or discard this patch.
lib/private/Repair/RepairMimeTypes.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	private function updateMimetypes($updatedMimetypes) {
90 90
 		if (empty($this->folderMimeTypeId)) {
91 91
 			$result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory'));
92
-			$this->folderMimeTypeId = (int)$result->fetchOne();
92
+			$this->folderMimeTypeId = (int) $result->fetchOne();
93 93
 		}
94 94
 
95 95
 		$count = 0;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 			$mimetypeId = $result->fetchOne();
108 108
 
109 109
 			// change mimetype for files with x extension
110
-			$count += \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension));
110
+			$count += \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.'.$extension));
111 111
 		}
112 112
 
113 113
 		return $count;
Please login to merge, or discard this patch.
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -34,196 +34,196 @@
 block discarded – undo
34 34
 use OCP\Migration\IRepairStep;
35 35
 
36 36
 class RepairMimeTypes implements IRepairStep {
37
-	/**
38
-	 * @var \OCP\IConfig
39
-	 */
40
-	protected $config;
41
-
42
-	/**
43
-	 * @var int
44
-	 */
45
-	protected $folderMimeTypeId;
46
-
47
-	/**
48
-	 * @param \OCP\IConfig $config
49
-	 */
50
-	public function __construct($config) {
51
-		$this->config = $config;
52
-	}
53
-
54
-	public function getName() {
55
-		return 'Repair mime types';
56
-	}
57
-
58
-	private static function existsStmt() {
59
-		return \OC_DB::prepare('
37
+    /**
38
+     * @var \OCP\IConfig
39
+     */
40
+    protected $config;
41
+
42
+    /**
43
+     * @var int
44
+     */
45
+    protected $folderMimeTypeId;
46
+
47
+    /**
48
+     * @param \OCP\IConfig $config
49
+     */
50
+    public function __construct($config) {
51
+        $this->config = $config;
52
+    }
53
+
54
+    public function getName() {
55
+        return 'Repair mime types';
56
+    }
57
+
58
+    private static function existsStmt() {
59
+        return \OC_DB::prepare('
60 60
 			SELECT count(`mimetype`)
61 61
 			FROM   `*PREFIX*mimetypes`
62 62
 			WHERE  `mimetype` = ?
63 63
 		');
64
-	}
64
+    }
65 65
 
66
-	private static function getIdStmt() {
67
-		return \OC_DB::prepare('
66
+    private static function getIdStmt() {
67
+        return \OC_DB::prepare('
68 68
 			SELECT `id`
69 69
 			FROM   `*PREFIX*mimetypes`
70 70
 			WHERE  `mimetype` = ?
71 71
 		');
72
-	}
72
+    }
73 73
 
74
-	private static function insertStmt() {
75
-		return \OC_DB::prepare('
74
+    private static function insertStmt() {
75
+        return \OC_DB::prepare('
76 76
 			INSERT INTO `*PREFIX*mimetypes` ( `mimetype` )
77 77
 			VALUES ( ? )
78 78
 		');
79
-	}
79
+    }
80 80
 
81
-	private static function updateByNameStmt() {
82
-		return \OC_DB::prepare('
81
+    private static function updateByNameStmt() {
82
+        return \OC_DB::prepare('
83 83
 			UPDATE `*PREFIX*filecache`
84 84
 			SET `mimetype` = ?
85 85
 			WHERE `mimetype` <> ? AND `mimetype` <> ? AND `name` ILIKE ?
86 86
 		');
87
-	}
88
-
89
-	private function updateMimetypes($updatedMimetypes) {
90
-		if (empty($this->folderMimeTypeId)) {
91
-			$result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory'));
92
-			$this->folderMimeTypeId = (int)$result->fetchOne();
93
-		}
94
-
95
-		$count = 0;
96
-		foreach ($updatedMimetypes as $extension => $mimetype) {
97
-			$result = \OC_DB::executeAudited(self::existsStmt(), array($mimetype));
98
-			$exists = $result->fetchOne();
99
-
100
-			if (!$exists) {
101
-				// insert mimetype
102
-				\OC_DB::executeAudited(self::insertStmt(), array($mimetype));
103
-			}
104
-
105
-			// get target mimetype id
106
-			$result = \OC_DB::executeAudited(self::getIdStmt(), array($mimetype));
107
-			$mimetypeId = $result->fetchOne();
108
-
109
-			// change mimetype for files with x extension
110
-			$count += \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension));
111
-		}
112
-
113
-		return $count;
114
-	}
115
-
116
-	private function introduceImageTypes() {
117
-		$updatedMimetypes = array(
118
-			'jp2' => 'image/jp2',
119
-			'webp' => 'image/webp',
120
-		);
121
-
122
-		return $this->updateMimetypes($updatedMimetypes);
123
-	}
124
-
125
-	private function introduceWindowsProgramTypes() {
126
-		$updatedMimetypes = array(
127
-			'htaccess' => 'text/plain',
128
-			'bat' => 'application/x-msdos-program',
129
-			'cmd' => 'application/cmd',
130
-		);
131
-
132
-		return $this->updateMimetypes($updatedMimetypes);
133
-	}
134
-
135
-	private function introduceLocationTypes() {
136
-		$updatedMimetypes = [
137
-			'gpx' => 'application/gpx+xml',
138
-			'kml' => 'application/vnd.google-earth.kml+xml',
139
-			'kmz' => 'application/vnd.google-earth.kmz',
140
-			'tcx' => 'application/vnd.garmin.tcx+xml',
141
-		];
142
-
143
-		return $this->updateMimetypes($updatedMimetypes);
144
-	}
145
-
146
-	private function introduceInternetShortcutTypes() {
147
-		$updatedMimetypes = [
148
-			'url' => 'application/internet-shortcut',
149
-			'webloc' => 'application/internet-shortcut'
150
-		];
151
-
152
-		return $this->updateMimetypes($updatedMimetypes);
153
-	}
154
-
155
-	private function introduceStreamingTypes() {
156
-		$updatedMimetypes = [
157
-			'm3u' => 'audio/mpegurl',
158
-			'm3u8' => 'audio/mpegurl',
159
-			'pls' => 'audio/x-scpls'
160
-		];
161
-
162
-		return $this->updateMimetypes($updatedMimetypes);
163
-	}
164
-
165
-	private function introduceVisioTypes() {
166
-		$updatedMimetypes = [
167
-			'vsdm' => 'application/vnd.visio',
168
-			'vsdx' => 'application/vnd.visio',
169
-			'vssm' => 'application/vnd.visio',
170
-			'vssx' => 'application/vnd.visio',
171
-			'vstm' => 'application/vnd.visio',
172
-			'vstx' => 'application/vnd.visio',
173
-		];
174
-
175
-		return $this->updateMimetypes($updatedMimetypes);
176
-	}
177
-
178
-	private function introduceComicbookTypes() {
179
-		$updatedMimetypes = [
180
-			'cb7' => 'application/comicbook+7z',
181
-			'cba' => 'application/comicbook+ace',
182
-			'cbr' => 'application/comicbook+rar',
183
-			'cbt' => 'application/comicbook+tar',
184
-			'cbtc' => 'application/comicbook+truecrypt',
185
-			'cbz' => 'application/comicbook+zip',
186
-		];
187
-
188
-		return $this->updateMimetypes($updatedMimetypes);
189
-	}
190
-
191
-	/**
192
-	 * Fix mime types
193
-	 */
194
-	public function run(IOutput $out) {
195
-
196
-		$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
197
-
198
-		// NOTE TO DEVELOPERS: when adding new mime types, please make sure to
199
-		// add a version comparison to avoid doing it every time
200
-
201
-		if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) {
202
-			$out->info('Fixed image mime types');
203
-		}
204
-
205
-		if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) {
206
-			$out->info('Fixed windows program mime types');
207
-		}
208
-
209
-		if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) {
210
-			$out->info('Fixed geospatial mime types');
211
-		}
212
-
213
-		if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) {
214
-			$out->info('Fixed internet-shortcut mime types');
215
-		}
216
-
217
-		if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.6', '<') && $this->introduceStreamingTypes()) {
218
-			$out->info('Fixed streaming mime types');
219
-		}
220
-
221
-		if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.8', '<') && $this->introduceVisioTypes()) {
222
-			$out->info('Fixed visio mime types');
223
-		}
224
-
225
-		if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.10', '<') && $this->introduceComicbookTypes()) {
226
-			$out->info('Fixed comicbook mime types');
227
-		}
228
-	}
87
+    }
88
+
89
+    private function updateMimetypes($updatedMimetypes) {
90
+        if (empty($this->folderMimeTypeId)) {
91
+            $result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory'));
92
+            $this->folderMimeTypeId = (int)$result->fetchOne();
93
+        }
94
+
95
+        $count = 0;
96
+        foreach ($updatedMimetypes as $extension => $mimetype) {
97
+            $result = \OC_DB::executeAudited(self::existsStmt(), array($mimetype));
98
+            $exists = $result->fetchOne();
99
+
100
+            if (!$exists) {
101
+                // insert mimetype
102
+                \OC_DB::executeAudited(self::insertStmt(), array($mimetype));
103
+            }
104
+
105
+            // get target mimetype id
106
+            $result = \OC_DB::executeAudited(self::getIdStmt(), array($mimetype));
107
+            $mimetypeId = $result->fetchOne();
108
+
109
+            // change mimetype for files with x extension
110
+            $count += \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension));
111
+        }
112
+
113
+        return $count;
114
+    }
115
+
116
+    private function introduceImageTypes() {
117
+        $updatedMimetypes = array(
118
+            'jp2' => 'image/jp2',
119
+            'webp' => 'image/webp',
120
+        );
121
+
122
+        return $this->updateMimetypes($updatedMimetypes);
123
+    }
124
+
125
+    private function introduceWindowsProgramTypes() {
126
+        $updatedMimetypes = array(
127
+            'htaccess' => 'text/plain',
128
+            'bat' => 'application/x-msdos-program',
129
+            'cmd' => 'application/cmd',
130
+        );
131
+
132
+        return $this->updateMimetypes($updatedMimetypes);
133
+    }
134
+
135
+    private function introduceLocationTypes() {
136
+        $updatedMimetypes = [
137
+            'gpx' => 'application/gpx+xml',
138
+            'kml' => 'application/vnd.google-earth.kml+xml',
139
+            'kmz' => 'application/vnd.google-earth.kmz',
140
+            'tcx' => 'application/vnd.garmin.tcx+xml',
141
+        ];
142
+
143
+        return $this->updateMimetypes($updatedMimetypes);
144
+    }
145
+
146
+    private function introduceInternetShortcutTypes() {
147
+        $updatedMimetypes = [
148
+            'url' => 'application/internet-shortcut',
149
+            'webloc' => 'application/internet-shortcut'
150
+        ];
151
+
152
+        return $this->updateMimetypes($updatedMimetypes);
153
+    }
154
+
155
+    private function introduceStreamingTypes() {
156
+        $updatedMimetypes = [
157
+            'm3u' => 'audio/mpegurl',
158
+            'm3u8' => 'audio/mpegurl',
159
+            'pls' => 'audio/x-scpls'
160
+        ];
161
+
162
+        return $this->updateMimetypes($updatedMimetypes);
163
+    }
164
+
165
+    private function introduceVisioTypes() {
166
+        $updatedMimetypes = [
167
+            'vsdm' => 'application/vnd.visio',
168
+            'vsdx' => 'application/vnd.visio',
169
+            'vssm' => 'application/vnd.visio',
170
+            'vssx' => 'application/vnd.visio',
171
+            'vstm' => 'application/vnd.visio',
172
+            'vstx' => 'application/vnd.visio',
173
+        ];
174
+
175
+        return $this->updateMimetypes($updatedMimetypes);
176
+    }
177
+
178
+    private function introduceComicbookTypes() {
179
+        $updatedMimetypes = [
180
+            'cb7' => 'application/comicbook+7z',
181
+            'cba' => 'application/comicbook+ace',
182
+            'cbr' => 'application/comicbook+rar',
183
+            'cbt' => 'application/comicbook+tar',
184
+            'cbtc' => 'application/comicbook+truecrypt',
185
+            'cbz' => 'application/comicbook+zip',
186
+        ];
187
+
188
+        return $this->updateMimetypes($updatedMimetypes);
189
+    }
190
+
191
+    /**
192
+     * Fix mime types
193
+     */
194
+    public function run(IOutput $out) {
195
+
196
+        $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
197
+
198
+        // NOTE TO DEVELOPERS: when adding new mime types, please make sure to
199
+        // add a version comparison to avoid doing it every time
200
+
201
+        if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) {
202
+            $out->info('Fixed image mime types');
203
+        }
204
+
205
+        if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) {
206
+            $out->info('Fixed windows program mime types');
207
+        }
208
+
209
+        if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) {
210
+            $out->info('Fixed geospatial mime types');
211
+        }
212
+
213
+        if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) {
214
+            $out->info('Fixed internet-shortcut mime types');
215
+        }
216
+
217
+        if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.6', '<') && $this->introduceStreamingTypes()) {
218
+            $out->info('Fixed streaming mime types');
219
+        }
220
+
221
+        if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.8', '<') && $this->introduceVisioTypes()) {
222
+            $out->info('Fixed visio mime types');
223
+        }
224
+
225
+        if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.10', '<') && $this->introduceComicbookTypes()) {
226
+            $out->info('Fixed comicbook mime types');
227
+        }
228
+    }
229 229
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/ILDAPUserPlugin.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -26,68 +26,68 @@
 block discarded – undo
26 26
 
27 27
 interface ILDAPUserPlugin {
28 28
 
29
-	/**
30
-	 * Check if plugin implements actions
31
-	 * @return int
32
-	 *
33
-	 * Returns the supported actions as int to be
34
-	 * compared with OC_USER_BACKEND_CREATE_USER etc.
35
-	 */
36
-	public function respondToActions();
29
+    /**
30
+     * Check if plugin implements actions
31
+     * @return int
32
+     *
33
+     * Returns the supported actions as int to be
34
+     * compared with OC_USER_BACKEND_CREATE_USER etc.
35
+     */
36
+    public function respondToActions();
37 37
 
38
-	/**
39
-	 * Create a new user in LDAP Backend
40
-	 *
41
-	 * @param string $uid The UID of the user to create
42
-	 * @param string $password The password of the new user
43
-	 * @return bool
44
-	 */
45
-	public function createUser($uid, $password);
38
+    /**
39
+     * Create a new user in LDAP Backend
40
+     *
41
+     * @param string $uid The UID of the user to create
42
+     * @param string $password The password of the new user
43
+     * @return bool
44
+     */
45
+    public function createUser($uid, $password);
46 46
 
47
-	/**
48
-	 * Set password
49
-	 *
50
-	 * @param string $uid The username
51
-	 * @param string $password The new password
52
-	 * @return bool
53
-	 *
54
-	 * Change the password of a user
55
-	 */
56
-	public function setPassword($uid, $password);
47
+    /**
48
+     * Set password
49
+     *
50
+     * @param string $uid The username
51
+     * @param string $password The new password
52
+     * @return bool
53
+     *
54
+     * Change the password of a user
55
+     */
56
+    public function setPassword($uid, $password);
57 57
 
58
-	/**
59
-	 * get the user's home directory
60
-	 * @param string $uid the username
61
-	 * @return boolean
62
-	 */
63
-	public function getHome($uid);
58
+    /**
59
+     * get the user's home directory
60
+     * @param string $uid the username
61
+     * @return boolean
62
+     */
63
+    public function getHome($uid);
64 64
 
65
-	/**
66
-	 * get display name of the user
67
-	 * @param string $uid user ID of the user
68
-	 * @return string display name
69
-	 */
70
-	public function getDisplayName($uid);
65
+    /**
66
+     * get display name of the user
67
+     * @param string $uid user ID of the user
68
+     * @return string display name
69
+     */
70
+    public function getDisplayName($uid);
71 71
 
72
-	/**
73
-	 * set display name of the user
74
-	 * @param string $uid user ID of the user
75
-	 * @param string $displayName new user's display name
76
-	 * @return string display name
77
-	 */
78
-	public function setDisplayName($uid, $displayName);
72
+    /**
73
+     * set display name of the user
74
+     * @param string $uid user ID of the user
75
+     * @param string $displayName new user's display name
76
+     * @return string display name
77
+     */
78
+    public function setDisplayName($uid, $displayName);
79 79
 
80
-	/**
81
-	 * checks whether the user is allowed to change his avatar in Nextcloud
82
-	 * @param string $uid the Nextcloud user name
83
-	 * @return boolean either the user can or cannot
84
-	 */
85
-	public function canChangeAvatar($uid);
80
+    /**
81
+     * checks whether the user is allowed to change his avatar in Nextcloud
82
+     * @param string $uid the Nextcloud user name
83
+     * @return boolean either the user can or cannot
84
+     */
85
+    public function canChangeAvatar($uid);
86 86
 
87
-	/**
88
-	 * Count the number of users
89
-	 * @return int|bool
90
-	 */
91
-	public function countUsers();
87
+    /**
88
+     * Count the number of users
89
+     * @return int|bool
90
+     */
91
+    public function countUsers();
92 92
 
93 93
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAPProvider.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		$this->deletedUsersIndex = $deletedUsersIndex;
55 55
 		$userBackendFound = false;
56 56
 		$groupBackendFound = false;
57
-		foreach ($serverContainer->getUserManager()->getBackends() as $backend){
57
+		foreach ($serverContainer->getUserManager()->getBackends() as $backend) {
58 58
 			$this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']);
59 59
 			if ($backend instanceof IUserLDAP) {
60 60
 				$this->userBackend = $backend;
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 				break;
63 63
 			}
64 64
         }
65
-		foreach ($serverContainer->getGroupManager()->getBackends() as $backend){
65
+		foreach ($serverContainer->getGroupManager()->getBackends() as $backend) {
66 66
 			$this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']);
67 67
 			if ($backend instanceof IGroupLDAP) {
68 68
 				$this->groupBackend = $backend;
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	 * @throws \Exception if translation was unsuccessful
84 84
 	 */
85 85
 	public function getUserDN($uid) {
86
-		if(!$this->userBackend->userExists($uid)){
86
+		if (!$this->userBackend->userExists($uid)) {
87 87
 			throw new \Exception('User id not found in LDAP');
88 88
 		}
89 89
 		$result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid);
90
-		if(!$result){
90
+		if (!$result) {
91 91
 			throw new \Exception('Translation to LDAP DN unsuccessful');
92 92
 		}
93 93
 		return $result;
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
 	 * @throws \Exception
101 101
 	 */
102 102
 	public function getGroupDN($gid) {
103
-		if(!$this->groupBackend->groupExists($gid)){
103
+		if (!$this->groupBackend->groupExists($gid)) {
104 104
 			throw new \Exception('Group id not found in LDAP');
105 105
 		}
106 106
 		$result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid);
107
-		if(!$result){
107
+		if (!$result) {
108 108
 			throw new \Exception('Translation to LDAP DN unsuccessful');
109 109
 		}
110 110
 		return $result;	
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function getUserName($dn) {
121 121
 		$result = $this->userBackend->dn2UserName($dn);
122
-		if(!$result){
122
+		if (!$result) {
123 123
 			throw new \Exception('Translation to internal user name unsuccessful');
124 124
 		}
125 125
 		return $result;
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @throws \Exception if user id was not found in LDAP
152 152
 	 */
153 153
 	public function getLDAPConnection($uid) {
154
-		if(!$this->userBackend->userExists($uid)){
154
+		if (!$this->userBackend->userExists($uid)) {
155 155
 			throw new \Exception('User id not found in LDAP');
156 156
 		}
157 157
 		return $this->userBackend->getNewLDAPConnection($uid);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @throws \Exception if group id was not found in LDAP
166 166
 	 */
167 167
 	public function getGroupLDAPConnection($gid) {
168
-		if(!$this->groupBackend->groupExists($gid)){
168
+		if (!$this->groupBackend->groupExists($gid)) {
169 169
 			throw new \Exception('Group id not found in LDAP');
170 170
 		}
171 171
 		return $this->groupBackend->getNewLDAPConnection($gid);
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @throws \Exception if user id was not found in LDAP
179 179
 	 */
180 180
 	public function getLDAPBaseUsers($uid) {
181
-		if(!$this->userBackend->userExists($uid)){
181
+		if (!$this->userBackend->userExists($uid)) {
182 182
 			throw new \Exception('User id not found in LDAP');
183 183
 		}	
184 184
 		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users'];
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @throws \Exception if user id was not found in LDAP
192 192
 	 */
193 193
 	public function getLDAPBaseGroups($uid) {
194
-		if(!$this->userBackend->userExists($uid)){
194
+		if (!$this->userBackend->userExists($uid)) {
195 195
 			throw new \Exception('User id not found in LDAP');
196 196
 		}
197 197
 		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups'];
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @throws \Exception if user id was not found in LDAP
204 204
 	 */
205 205
 	public function clearCache($uid) {
206
-		if(!$this->userBackend->userExists($uid)){
206
+		if (!$this->userBackend->userExists($uid)) {
207 207
 			throw new \Exception('User id not found in LDAP');
208 208
 		}
209 209
 		$this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache();
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 * @throws \Exception if user id was not found in LDAP
217 217
 	 */
218 218
 	public function clearGroupCache($gid) {
219
-		if(!$this->groupBackend->groupExists($gid)){
219
+		if (!$this->groupBackend->groupExists($gid)) {
220 220
 			throw new \Exception('Group id not found in LDAP');
221 221
 		}
222 222
 		$this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache();
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @throws \Exception if user id was not found in LDAP
256 256
 	 */
257 257
 	public function getLDAPDisplayNameField($uid) {
258
-		if(!$this->userBackend->userExists($uid)){
258
+		if (!$this->userBackend->userExists($uid)) {
259 259
 			throw new \Exception('User id not found in LDAP');
260 260
 		}
261 261
 		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name'];
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @throws \Exception if user id was not found in LDAP
269 269
 	 */
270 270
 	public function getLDAPEmailField($uid) {
271
-		if(!$this->userBackend->userExists($uid)){
271
+		if (!$this->userBackend->userExists($uid)) {
272 272
 			throw new \Exception('User id not found in LDAP');
273 273
 		}
274 274
 		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr'];
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @throws \Exception if group id was not found in LDAP
282 282
 	 */
283 283
 	public function getLDAPGroupMemberAssoc($gid) {
284
-		if(!$this->groupBackend->groupExists($gid)){
284
+		if (!$this->groupBackend->groupExists($gid)) {
285 285
 			throw new \Exception('Group id not found in LDAP');
286 286
 		}
287 287
 		return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute'];
Please login to merge, or discard this patch.
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -37,256 +37,256 @@
 block discarded – undo
37 37
  */
38 38
 class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
39 39
 
40
-	private $userBackend;
41
-	private $groupBackend;
42
-	private $logger;
43
-	private $helper;
44
-	private $deletedUsersIndex;
40
+    private $userBackend;
41
+    private $groupBackend;
42
+    private $logger;
43
+    private $helper;
44
+    private $deletedUsersIndex;
45 45
 	
46
-	/**
47
-	 * Create new LDAPProvider
48
-	 * @param \OCP\IServerContainer $serverContainer
49
-	 * @param Helper $helper
50
-	 * @param DeletedUsersIndex $deletedUsersIndex
51
-	 * @throws \Exception if user_ldap app was not enabled
52
-	 */
53
-	public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) {
54
-		$this->logger = $serverContainer->getLogger();
55
-		$this->helper = $helper;
56
-		$this->deletedUsersIndex = $deletedUsersIndex;
57
-		$userBackendFound = false;
58
-		$groupBackendFound = false;
59
-		foreach ($serverContainer->getUserManager()->getBackends() as $backend){
60
-			$this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']);
61
-			if ($backend instanceof IUserLDAP) {
62
-				$this->userBackend = $backend;
63
-				$userBackendFound = true;
64
-				break;
65
-			}
46
+    /**
47
+     * Create new LDAPProvider
48
+     * @param \OCP\IServerContainer $serverContainer
49
+     * @param Helper $helper
50
+     * @param DeletedUsersIndex $deletedUsersIndex
51
+     * @throws \Exception if user_ldap app was not enabled
52
+     */
53
+    public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) {
54
+        $this->logger = $serverContainer->getLogger();
55
+        $this->helper = $helper;
56
+        $this->deletedUsersIndex = $deletedUsersIndex;
57
+        $userBackendFound = false;
58
+        $groupBackendFound = false;
59
+        foreach ($serverContainer->getUserManager()->getBackends() as $backend){
60
+            $this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']);
61
+            if ($backend instanceof IUserLDAP) {
62
+                $this->userBackend = $backend;
63
+                $userBackendFound = true;
64
+                break;
65
+            }
66
+        }
67
+        foreach ($serverContainer->getGroupManager()->getBackends() as $backend){
68
+            $this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']);
69
+            if ($backend instanceof IGroupLDAP) {
70
+                $this->groupBackend = $backend;
71
+                $groupBackendFound = true;
72
+                break;
73
+            }
66 74
         }
67
-		foreach ($serverContainer->getGroupManager()->getBackends() as $backend){
68
-			$this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']);
69
-			if ($backend instanceof IGroupLDAP) {
70
-				$this->groupBackend = $backend;
71
-				$groupBackendFound = true;
72
-				break;
73
-			}
74
-		}
75 75
 
76 76
         if (!$userBackendFound or !$groupBackendFound) {
77
-			throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled');
78
-		}
79
-	}
77
+            throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled');
78
+        }
79
+    }
80 80
 	
81
-	/**
82
-	 * Translate an user id to LDAP DN
83
-	 * @param string $uid user id
84
-	 * @return string with the LDAP DN
85
-	 * @throws \Exception if translation was unsuccessful
86
-	 */
87
-	public function getUserDN($uid) {
88
-		if(!$this->userBackend->userExists($uid)){
89
-			throw new \Exception('User id not found in LDAP');
90
-		}
91
-		$result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid);
92
-		if(!$result){
93
-			throw new \Exception('Translation to LDAP DN unsuccessful');
94
-		}
95
-		return $result;
96
-	}
81
+    /**
82
+     * Translate an user id to LDAP DN
83
+     * @param string $uid user id
84
+     * @return string with the LDAP DN
85
+     * @throws \Exception if translation was unsuccessful
86
+     */
87
+    public function getUserDN($uid) {
88
+        if(!$this->userBackend->userExists($uid)){
89
+            throw new \Exception('User id not found in LDAP');
90
+        }
91
+        $result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid);
92
+        if(!$result){
93
+            throw new \Exception('Translation to LDAP DN unsuccessful');
94
+        }
95
+        return $result;
96
+    }
97 97
 
98
-	/**
99
-	 * Translate a group id to LDAP DN.
100
-	 * @param string $gid group id
101
-	 * @return string
102
-	 * @throws \Exception
103
-	 */
104
-	public function getGroupDN($gid) {
105
-		if(!$this->groupBackend->groupExists($gid)){
106
-			throw new \Exception('Group id not found in LDAP');
107
-		}
108
-		$result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid);
109
-		if(!$result){
110
-			throw new \Exception('Translation to LDAP DN unsuccessful');
111
-		}
112
-		return $result;	
113
-	}
98
+    /**
99
+     * Translate a group id to LDAP DN.
100
+     * @param string $gid group id
101
+     * @return string
102
+     * @throws \Exception
103
+     */
104
+    public function getGroupDN($gid) {
105
+        if(!$this->groupBackend->groupExists($gid)){
106
+            throw new \Exception('Group id not found in LDAP');
107
+        }
108
+        $result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid);
109
+        if(!$result){
110
+            throw new \Exception('Translation to LDAP DN unsuccessful');
111
+        }
112
+        return $result;	
113
+    }
114 114
 
115
-	/**
116
-	 * Translate a LDAP DN to an internal user name. If there is no mapping between 
117
-	 * the DN and the user name, a new one will be created.
118
-	 * @param string $dn LDAP DN
119
-	 * @return string with the internal user name
120
-	 * @throws \Exception if translation was unsuccessful
121
-	 */
122
-	public function getUserName($dn) {
123
-		$result = $this->userBackend->dn2UserName($dn);
124
-		if(!$result){
125
-			throw new \Exception('Translation to internal user name unsuccessful');
126
-		}
127
-		return $result;
128
-	}
115
+    /**
116
+     * Translate a LDAP DN to an internal user name. If there is no mapping between 
117
+     * the DN and the user name, a new one will be created.
118
+     * @param string $dn LDAP DN
119
+     * @return string with the internal user name
120
+     * @throws \Exception if translation was unsuccessful
121
+     */
122
+    public function getUserName($dn) {
123
+        $result = $this->userBackend->dn2UserName($dn);
124
+        if(!$result){
125
+            throw new \Exception('Translation to internal user name unsuccessful');
126
+        }
127
+        return $result;
128
+    }
129 129
 	
130
-	/**
131
-	 * Convert a stored DN so it can be used as base parameter for LDAP queries.
132
-	 * @param string $dn the DN in question
133
-	 * @return string
134
-	 */
135
-	public function DNasBaseParameter($dn) {
136
-		return $this->helper->DNasBaseParameter($dn);
137
-	}
130
+    /**
131
+     * Convert a stored DN so it can be used as base parameter for LDAP queries.
132
+     * @param string $dn the DN in question
133
+     * @return string
134
+     */
135
+    public function DNasBaseParameter($dn) {
136
+        return $this->helper->DNasBaseParameter($dn);
137
+    }
138 138
 	
139
-	/**
140
-	 * Sanitize a DN received from the LDAP server.
141
-	 * @param array $dn the DN in question
142
-	 * @return array the sanitized DN
143
-	 */
144
-	public function sanitizeDN($dn) {
145
-		return $this->helper->sanitizeDN($dn);
146
-	}
139
+    /**
140
+     * Sanitize a DN received from the LDAP server.
141
+     * @param array $dn the DN in question
142
+     * @return array the sanitized DN
143
+     */
144
+    public function sanitizeDN($dn) {
145
+        return $this->helper->sanitizeDN($dn);
146
+    }
147 147
 	
148
-	/**
149
-	 * Return a new LDAP connection resource for the specified user. 
150
-	 * The connection must be closed manually.
151
-	 * @param string $uid user id
152
-	 * @return resource of the LDAP connection
153
-	 * @throws \Exception if user id was not found in LDAP
154
-	 */
155
-	public function getLDAPConnection($uid) {
156
-		if(!$this->userBackend->userExists($uid)){
157
-			throw new \Exception('User id not found in LDAP');
158
-		}
159
-		return $this->userBackend->getNewLDAPConnection($uid);
160
-	}
148
+    /**
149
+     * Return a new LDAP connection resource for the specified user. 
150
+     * The connection must be closed manually.
151
+     * @param string $uid user id
152
+     * @return resource of the LDAP connection
153
+     * @throws \Exception if user id was not found in LDAP
154
+     */
155
+    public function getLDAPConnection($uid) {
156
+        if(!$this->userBackend->userExists($uid)){
157
+            throw new \Exception('User id not found in LDAP');
158
+        }
159
+        return $this->userBackend->getNewLDAPConnection($uid);
160
+    }
161 161
 
162
-	/**
163
-	 * Return a new LDAP connection resource for the specified user.
164
-	 * The connection must be closed manually.
165
-	 * @param string $gid group id
166
-	 * @return resource of the LDAP connection
167
-	 * @throws \Exception if group id was not found in LDAP
168
-	 */
169
-	public function getGroupLDAPConnection($gid) {
170
-		if(!$this->groupBackend->groupExists($gid)){
171
-			throw new \Exception('Group id not found in LDAP');
172
-		}
173
-		return $this->groupBackend->getNewLDAPConnection($gid);
174
-	}
162
+    /**
163
+     * Return a new LDAP connection resource for the specified user.
164
+     * The connection must be closed manually.
165
+     * @param string $gid group id
166
+     * @return resource of the LDAP connection
167
+     * @throws \Exception if group id was not found in LDAP
168
+     */
169
+    public function getGroupLDAPConnection($gid) {
170
+        if(!$this->groupBackend->groupExists($gid)){
171
+            throw new \Exception('Group id not found in LDAP');
172
+        }
173
+        return $this->groupBackend->getNewLDAPConnection($gid);
174
+    }
175 175
 	
176
-	/**
177
-	 * Get the LDAP base for users.
178
-	 * @param string $uid user id
179
-	 * @return string the base for users
180
-	 * @throws \Exception if user id was not found in LDAP
181
-	 */
182
-	public function getLDAPBaseUsers($uid) {
183
-		if(!$this->userBackend->userExists($uid)){
184
-			throw new \Exception('User id not found in LDAP');
185
-		}	
186
-		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users'];
187
-	}
176
+    /**
177
+     * Get the LDAP base for users.
178
+     * @param string $uid user id
179
+     * @return string the base for users
180
+     * @throws \Exception if user id was not found in LDAP
181
+     */
182
+    public function getLDAPBaseUsers($uid) {
183
+        if(!$this->userBackend->userExists($uid)){
184
+            throw new \Exception('User id not found in LDAP');
185
+        }	
186
+        return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users'];
187
+    }
188 188
 	
189
-	/**
190
-	 * Get the LDAP base for groups.
191
-	 * @param string $uid user id
192
-	 * @return string the base for groups
193
-	 * @throws \Exception if user id was not found in LDAP
194
-	 */
195
-	public function getLDAPBaseGroups($uid) {
196
-		if(!$this->userBackend->userExists($uid)){
197
-			throw new \Exception('User id not found in LDAP');
198
-		}
199
-		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups'];
200
-	}
189
+    /**
190
+     * Get the LDAP base for groups.
191
+     * @param string $uid user id
192
+     * @return string the base for groups
193
+     * @throws \Exception if user id was not found in LDAP
194
+     */
195
+    public function getLDAPBaseGroups($uid) {
196
+        if(!$this->userBackend->userExists($uid)){
197
+            throw new \Exception('User id not found in LDAP');
198
+        }
199
+        return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups'];
200
+    }
201 201
 	
202
-	/**
203
-	 * Clear the cache if a cache is used, otherwise do nothing.
204
-	 * @param string $uid user id
205
-	 * @throws \Exception if user id was not found in LDAP
206
-	 */
207
-	public function clearCache($uid) {
208
-		if(!$this->userBackend->userExists($uid)){
209
-			throw new \Exception('User id not found in LDAP');
210
-		}
211
-		$this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache();
212
-	}
202
+    /**
203
+     * Clear the cache if a cache is used, otherwise do nothing.
204
+     * @param string $uid user id
205
+     * @throws \Exception if user id was not found in LDAP
206
+     */
207
+    public function clearCache($uid) {
208
+        if(!$this->userBackend->userExists($uid)){
209
+            throw new \Exception('User id not found in LDAP');
210
+        }
211
+        $this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache();
212
+    }
213 213
 
214
-	/**
215
-	 * Clear the cache if a cache is used, otherwise do nothing.
216
-	 * Acts on the LDAP connection of a group
217
-	 * @param string $gid group id
218
-	 * @throws \Exception if user id was not found in LDAP
219
-	 */
220
-	public function clearGroupCache($gid) {
221
-		if(!$this->groupBackend->groupExists($gid)){
222
-			throw new \Exception('Group id not found in LDAP');
223
-		}
224
-		$this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache();
225
-	}
214
+    /**
215
+     * Clear the cache if a cache is used, otherwise do nothing.
216
+     * Acts on the LDAP connection of a group
217
+     * @param string $gid group id
218
+     * @throws \Exception if user id was not found in LDAP
219
+     */
220
+    public function clearGroupCache($gid) {
221
+        if(!$this->groupBackend->groupExists($gid)){
222
+            throw new \Exception('Group id not found in LDAP');
223
+        }
224
+        $this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache();
225
+    }
226 226
 	
227
-	/**
228
-	 * Check whether a LDAP DN exists
229
-	 * @param string $dn LDAP DN
230
-	 * @return bool whether the DN exists
231
-	 */
232
-	public function dnExists($dn) {
233
-		$result = $this->userBackend->dn2UserName($dn);
234
-		return !$result ? false : true;
235
-	}
227
+    /**
228
+     * Check whether a LDAP DN exists
229
+     * @param string $dn LDAP DN
230
+     * @return bool whether the DN exists
231
+     */
232
+    public function dnExists($dn) {
233
+        $result = $this->userBackend->dn2UserName($dn);
234
+        return !$result ? false : true;
235
+    }
236 236
 	
237
-	/**
238
-	 * Flag record for deletion.
239
-	 * @param string $uid user id
240
-	 */
241
-	public function flagRecord($uid) {
242
-		$this->deletedUsersIndex->markUser($uid);
243
-	}
237
+    /**
238
+     * Flag record for deletion.
239
+     * @param string $uid user id
240
+     */
241
+    public function flagRecord($uid) {
242
+        $this->deletedUsersIndex->markUser($uid);
243
+    }
244 244
 	
245
-	/**
246
-	 * Unflag record for deletion.
247
-	 * @param string $uid user id
248
-	 */
249
-	public function unflagRecord($uid) {
250
-		//do nothing
251
-	}
245
+    /**
246
+     * Unflag record for deletion.
247
+     * @param string $uid user id
248
+     */
249
+    public function unflagRecord($uid) {
250
+        //do nothing
251
+    }
252 252
 
253
-	/**
254
-	 * Get the LDAP attribute name for the user's display name
255
-	 * @param string $uid user id
256
-	 * @return string the display name field
257
-	 * @throws \Exception if user id was not found in LDAP
258
-	 */
259
-	public function getLDAPDisplayNameField($uid) {
260
-		if(!$this->userBackend->userExists($uid)){
261
-			throw new \Exception('User id not found in LDAP');
262
-		}
263
-		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name'];
264
-	}
253
+    /**
254
+     * Get the LDAP attribute name for the user's display name
255
+     * @param string $uid user id
256
+     * @return string the display name field
257
+     * @throws \Exception if user id was not found in LDAP
258
+     */
259
+    public function getLDAPDisplayNameField($uid) {
260
+        if(!$this->userBackend->userExists($uid)){
261
+            throw new \Exception('User id not found in LDAP');
262
+        }
263
+        return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name'];
264
+    }
265 265
 
266
-	/**
267
-	 * Get the LDAP attribute name for the email
268
-	 * @param string $uid user id
269
-	 * @return string the email field
270
-	 * @throws \Exception if user id was not found in LDAP
271
-	 */
272
-	public function getLDAPEmailField($uid) {
273
-		if(!$this->userBackend->userExists($uid)){
274
-			throw new \Exception('User id not found in LDAP');
275
-		}
276
-		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr'];
277
-	}
266
+    /**
267
+     * Get the LDAP attribute name for the email
268
+     * @param string $uid user id
269
+     * @return string the email field
270
+     * @throws \Exception if user id was not found in LDAP
271
+     */
272
+    public function getLDAPEmailField($uid) {
273
+        if(!$this->userBackend->userExists($uid)){
274
+            throw new \Exception('User id not found in LDAP');
275
+        }
276
+        return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr'];
277
+    }
278 278
 
279
-	/**
280
-	 * Get the LDAP type of association between users and groups
281
-	 * @param string $gid group id
282
-	 * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber'
283
-	 * @throws \Exception if group id was not found in LDAP
284
-	 */
285
-	public function getLDAPGroupMemberAssoc($gid) {
286
-		if(!$this->groupBackend->groupExists($gid)){
287
-			throw new \Exception('Group id not found in LDAP');
288
-		}
289
-		return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute'];
290
-	}
279
+    /**
280
+     * Get the LDAP type of association between users and groups
281
+     * @param string $gid group id
282
+     * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber'
283
+     * @throws \Exception if group id was not found in LDAP
284
+     */
285
+    public function getLDAPGroupMemberAssoc($gid) {
286
+        if(!$this->groupBackend->groupExists($gid)){
287
+            throw new \Exception('Group id not found in LDAP');
288
+        }
289
+        return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute'];
290
+    }
291 291
 
292 292
 }
Please login to merge, or discard this patch.
core/Controller/WalledGardenController.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -28,15 +28,15 @@
 block discarded – undo
28 28
 
29 29
 class WalledGardenController extends Controller {
30 30
 
31
-	/**
32
-	 * @PublicPage
33
-	 * @NoCSRFRequired
34
-	 *
35
-	 * @return Response
36
-	 */
37
-	function get() {
38
-		$resp = new Response();
39
-		$resp->setStatus(Http::STATUS_NO_CONTENT);
40
-		return $resp;
41
-	}
31
+    /**
32
+     * @PublicPage
33
+     * @NoCSRFRequired
34
+     *
35
+     * @return Response
36
+     */
37
+    function get() {
38
+        $resp = new Response();
39
+        $resp->setStatus(Http::STATUS_NO_CONTENT);
40
+        return $resp;
41
+    }
42 42
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/ILDAPGroupPlugin.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -26,61 +26,61 @@
 block discarded – undo
26 26
 
27 27
 interface ILDAPGroupPlugin {
28 28
 
29
-	/**
30
-	 * Check if plugin implements actions
31
-	 * @return int
32
-	 *
33
-	 * Returns the supported actions as int to be
34
-	 * compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
35
-	 */
36
-	public function respondToActions();
29
+    /**
30
+     * Check if plugin implements actions
31
+     * @return int
32
+     *
33
+     * Returns the supported actions as int to be
34
+     * compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
35
+     */
36
+    public function respondToActions();
37 37
 
38
-	/**
39
-	 * @param string $gid
40
-	 * @return string|null The group DN if group creation was successful.
41
-	 */
42
-	public function createGroup($gid);
38
+    /**
39
+     * @param string $gid
40
+     * @return string|null The group DN if group creation was successful.
41
+     */
42
+    public function createGroup($gid);
43 43
 
44
-	/**
45
-	 * delete a group
46
-	 * @param string $gid gid of the group to delete
47
-	 * @return bool
48
-	 */
49
-	public function deleteGroup($gid);
44
+    /**
45
+     * delete a group
46
+     * @param string $gid gid of the group to delete
47
+     * @return bool
48
+     */
49
+    public function deleteGroup($gid);
50 50
 
51
-	/**
52
-	 * Add a user to a group
53
-	 * @param string $uid Name of the user to add to group
54
-	 * @param string $gid Name of the group in which add the user
55
-	 * @return bool
56
-	 *
57
-	 * Adds a user to a group.
58
-	 */
59
-	public function addToGroup($uid, $gid);
51
+    /**
52
+     * Add a user to a group
53
+     * @param string $uid Name of the user to add to group
54
+     * @param string $gid Name of the group in which add the user
55
+     * @return bool
56
+     *
57
+     * Adds a user to a group.
58
+     */
59
+    public function addToGroup($uid, $gid);
60 60
 
61
-	/**
62
-	 * Removes a user from a group
63
-	 * @param string $uid Name of the user to remove from group
64
-	 * @param string $gid Name of the group from which remove the user
65
-	 * @return bool
66
-	 *
67
-	 * removes the user from a group.
68
-	 */
69
-	public function removeFromGroup($uid, $gid);
61
+    /**
62
+     * Removes a user from a group
63
+     * @param string $uid Name of the user to remove from group
64
+     * @param string $gid Name of the group from which remove the user
65
+     * @return bool
66
+     *
67
+     * removes the user from a group.
68
+     */
69
+    public function removeFromGroup($uid, $gid);
70 70
 
71
-	/**
72
-	 * get the number of all users matching the search string in a group
73
-	 * @param string $gid
74
-	 * @param string $search
75
-	 * @return int|false
76
-	 */
77
-	public function countUsersInGroup($gid, $search = '');
71
+    /**
72
+     * get the number of all users matching the search string in a group
73
+     * @param string $gid
74
+     * @param string $search
75
+     * @return int|false
76
+     */
77
+    public function countUsersInGroup($gid, $search = '');
78 78
 
79
-	/**
80
-	 * get an array with group details
81
-	 * @param string $gid
82
-	 * @return array|false
83
-	 */
84
-	public function getGroupDetails($gid);
79
+    /**
80
+     * get an array with group details
81
+     * @param string $gid
82
+     * @return array|false
83
+     */
84
+    public function getGroupDetails($gid);
85 85
 
86 86
 }
Please login to merge, or discard this patch.