Completed
Pull Request — master (#4810)
by Joas
14:56
created
lib/private/Files/Type/Loader.php 2 patches
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -33,146 +33,146 @@
 block discarded – undo
33 33
  */
34 34
 class Loader implements IMimeTypeLoader {
35 35
 
36
-	/** @var IDBConnection */
37
-	private $dbConnection;
38
-
39
-	/** @var array [id => mimetype] */
40
-	protected $mimetypes;
41
-
42
-	/** @var array [mimetype => id] */
43
-	protected $mimetypeIds;
44
-
45
-	/**
46
-	 * @param IDBConnection $dbConnection
47
-	 */
48
-	public function __construct(IDBConnection $dbConnection) {
49
-		$this->dbConnection = $dbConnection;
50
-		$this->mimetypes = [];
51
-		$this->mimetypeIds = [];
52
-	}
53
-
54
-	/**
55
-	 * Get a mimetype from its ID
56
-	 *
57
-	 * @param int $id
58
-	 * @return string|null
59
-	 */
60
-	public function getMimetypeById($id) {
61
-		if (!$this->mimetypes) {
62
-			$this->loadMimetypes();
63
-		}
64
-		if (isset($this->mimetypes[$id])) {
65
-			return $this->mimetypes[$id];
66
-		}
67
-		return null;
68
-	}
69
-
70
-	/**
71
-	 * Get a mimetype ID, adding the mimetype to the DB if it does not exist
72
-	 *
73
-	 * @param string $mimetype
74
-	 * @return int
75
-	 */
76
-	public function getId($mimetype) {
77
-		if (!$this->mimetypeIds) {
78
-			$this->loadMimetypes();
79
-		}
80
-		if (isset($this->mimetypeIds[$mimetype])) {
81
-			return $this->mimetypeIds[$mimetype];
82
-		}
83
-		return $this->store($mimetype);
84
-	}
85
-
86
-	/**
87
-	 * Test if a mimetype exists in the database
88
-	 *
89
-	 * @param string $mimetype
90
-	 * @return bool
91
-	 */
92
-	public function exists($mimetype) {
93
-		if (!$this->mimetypeIds) {
94
-			$this->loadMimetypes();
95
-		}
96
-		return isset($this->mimetypeIds[$mimetype]);
97
-	}
98
-
99
-	/**
100
-	 * Clear all loaded mimetypes, allow for re-loading
101
-	 */
102
-	public function reset() {
103
-		$this->mimetypes = [];
104
-		$this->mimetypeIds = [];
105
-	}
106
-
107
-	/**
108
-	 * Store a mimetype in the DB
109
-	 *
110
-	 * @param string $mimetype
111
-	 * @param int inserted ID
112
-	 */
113
-	protected function store($mimetype) {
114
-		try {
115
-			$qb = $this->dbConnection->getQueryBuilder();
116
-			$qb->insert('mimetypes')
117
-				->values([
118
-					'mimetype' => $qb->createNamedParameter($mimetype)
119
-				]);
120
-			$qb->execute();
121
-		} catch (UniqueConstraintViolationException $e) {
122
-			// something inserted it before us
123
-		}
124
-
125
-		$fetch = $this->dbConnection->getQueryBuilder();
126
-		$fetch->select('id')
127
-			->from('mimetypes')
128
-			->where(
129
-				$fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype)
130
-			));
131
-		$row = $fetch->execute()->fetch();
132
-
133
-		$this->mimetypes[$row['id']] = $mimetype;
134
-		$this->mimetypeIds[$mimetype] = $row['id'];
135
-		return $row['id'];
136
-	}
137
-
138
-	/**
139
-	 * Load all mimetypes from DB
140
-	 */
141
-	private function loadMimetypes() {
142
-		$qb = $this->dbConnection->getQueryBuilder();
143
-		$qb->select('id', 'mimetype')
144
-			->from('mimetypes');
145
-		$results = $qb->execute()->fetchAll();
146
-
147
-		foreach ($results as $row) {
148
-			$this->mimetypes[$row['id']] = $row['mimetype'];
149
-			$this->mimetypeIds[$row['mimetype']] = $row['id'];
150
-		}
151
-	}
152
-
153
-	/**
154
-	 * Update filecache mimetype based on file extension
155
-	 *
156
-	 * @param string $ext file extension
157
-	 * @param int $mimetypeId
158
-	 * @return int number of changed rows
159
-	 */
160
-	public function updateFilecache($ext, $mimetypeId) {
161
-		$isFolderId = $this->getId('httpd/unix-directory');
162
-		$update = $this->dbConnection->getQueryBuilder();
163
-		$update->update('filecache')
164
-			->set('mimetype', $update->createNamedParameter($mimetypeId))
165
-			->where($update->expr()->neq(
166
-				'mimetype', $update->createNamedParameter($mimetypeId)
167
-			))
168
-			->andWhere($update->expr()->neq(
169
-				'mimetype', $update->createNamedParameter($isFolderId)
170
-			))
171
-			->andWhere($update->expr()->like(
172
-				$update->createFunction('LOWER(' . $update->getColumnName('name') . ')'),
173
-				$update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext))
174
-			));
175
-		return $update->execute();
176
-	}
36
+    /** @var IDBConnection */
37
+    private $dbConnection;
38
+
39
+    /** @var array [id => mimetype] */
40
+    protected $mimetypes;
41
+
42
+    /** @var array [mimetype => id] */
43
+    protected $mimetypeIds;
44
+
45
+    /**
46
+     * @param IDBConnection $dbConnection
47
+     */
48
+    public function __construct(IDBConnection $dbConnection) {
49
+        $this->dbConnection = $dbConnection;
50
+        $this->mimetypes = [];
51
+        $this->mimetypeIds = [];
52
+    }
53
+
54
+    /**
55
+     * Get a mimetype from its ID
56
+     *
57
+     * @param int $id
58
+     * @return string|null
59
+     */
60
+    public function getMimetypeById($id) {
61
+        if (!$this->mimetypes) {
62
+            $this->loadMimetypes();
63
+        }
64
+        if (isset($this->mimetypes[$id])) {
65
+            return $this->mimetypes[$id];
66
+        }
67
+        return null;
68
+    }
69
+
70
+    /**
71
+     * Get a mimetype ID, adding the mimetype to the DB if it does not exist
72
+     *
73
+     * @param string $mimetype
74
+     * @return int
75
+     */
76
+    public function getId($mimetype) {
77
+        if (!$this->mimetypeIds) {
78
+            $this->loadMimetypes();
79
+        }
80
+        if (isset($this->mimetypeIds[$mimetype])) {
81
+            return $this->mimetypeIds[$mimetype];
82
+        }
83
+        return $this->store($mimetype);
84
+    }
85
+
86
+    /**
87
+     * Test if a mimetype exists in the database
88
+     *
89
+     * @param string $mimetype
90
+     * @return bool
91
+     */
92
+    public function exists($mimetype) {
93
+        if (!$this->mimetypeIds) {
94
+            $this->loadMimetypes();
95
+        }
96
+        return isset($this->mimetypeIds[$mimetype]);
97
+    }
98
+
99
+    /**
100
+     * Clear all loaded mimetypes, allow for re-loading
101
+     */
102
+    public function reset() {
103
+        $this->mimetypes = [];
104
+        $this->mimetypeIds = [];
105
+    }
106
+
107
+    /**
108
+     * Store a mimetype in the DB
109
+     *
110
+     * @param string $mimetype
111
+     * @param int inserted ID
112
+     */
113
+    protected function store($mimetype) {
114
+        try {
115
+            $qb = $this->dbConnection->getQueryBuilder();
116
+            $qb->insert('mimetypes')
117
+                ->values([
118
+                    'mimetype' => $qb->createNamedParameter($mimetype)
119
+                ]);
120
+            $qb->execute();
121
+        } catch (UniqueConstraintViolationException $e) {
122
+            // something inserted it before us
123
+        }
124
+
125
+        $fetch = $this->dbConnection->getQueryBuilder();
126
+        $fetch->select('id')
127
+            ->from('mimetypes')
128
+            ->where(
129
+                $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype)
130
+            ));
131
+        $row = $fetch->execute()->fetch();
132
+
133
+        $this->mimetypes[$row['id']] = $mimetype;
134
+        $this->mimetypeIds[$mimetype] = $row['id'];
135
+        return $row['id'];
136
+    }
137
+
138
+    /**
139
+     * Load all mimetypes from DB
140
+     */
141
+    private function loadMimetypes() {
142
+        $qb = $this->dbConnection->getQueryBuilder();
143
+        $qb->select('id', 'mimetype')
144
+            ->from('mimetypes');
145
+        $results = $qb->execute()->fetchAll();
146
+
147
+        foreach ($results as $row) {
148
+            $this->mimetypes[$row['id']] = $row['mimetype'];
149
+            $this->mimetypeIds[$row['mimetype']] = $row['id'];
150
+        }
151
+    }
152
+
153
+    /**
154
+     * Update filecache mimetype based on file extension
155
+     *
156
+     * @param string $ext file extension
157
+     * @param int $mimetypeId
158
+     * @return int number of changed rows
159
+     */
160
+    public function updateFilecache($ext, $mimetypeId) {
161
+        $isFolderId = $this->getId('httpd/unix-directory');
162
+        $update = $this->dbConnection->getQueryBuilder();
163
+        $update->update('filecache')
164
+            ->set('mimetype', $update->createNamedParameter($mimetypeId))
165
+            ->where($update->expr()->neq(
166
+                'mimetype', $update->createNamedParameter($mimetypeId)
167
+            ))
168
+            ->andWhere($update->expr()->neq(
169
+                'mimetype', $update->createNamedParameter($isFolderId)
170
+            ))
171
+            ->andWhere($update->expr()->like(
172
+                $update->createFunction('LOWER(' . $update->getColumnName('name') . ')'),
173
+                $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext))
174
+            ));
175
+        return $update->execute();
176
+    }
177 177
 
178 178
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -169,8 +169,8 @@
 block discarded – undo
169 169
 				'mimetype', $update->createNamedParameter($isFolderId)
170 170
 			))
171 171
 			->andWhere($update->expr()->like(
172
-				$update->createFunction('LOWER(' . $update->getColumnName('name') . ')'),
173
-				$update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext))
172
+				$update->createFunction('LOWER('.$update->getColumnName('name').')'),
173
+				$update->createNamedParameter('%'.$this->dbConnection->escapeLikeParameter('.'.$ext))
174 174
 			));
175 175
 		return $update->execute();
176 176
 	}
Please login to merge, or discard this patch.