Skip to content
Snippets Groups Projects
Commit 3a6b11d0 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #13767 from owncloud/issue/13764-mimetype-racecondition

Use insertIfNotExists() and reload mimetypes after inserting one
parents df2e712a a575dcf7
No related branches found
No related tags found
No related merge requests found
...@@ -74,9 +74,11 @@ class Cache { ...@@ -74,9 +74,11 @@ class Cache {
if (!isset(self::$mimetypeIds[$mime])) { if (!isset(self::$mimetypeIds[$mime])) {
try { try {
$result = \OC_DB::executeAudited('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)', array($mime)); $connection = \OC_DB::getConnection();
self::$mimetypeIds[$mime] = \OC_DB::insertid('*PREFIX*mimetypes'); $connection->insertIfNotExist('*PREFIX*mimetypes', [
self::$mimetypes[self::$mimetypeIds[$mime]] = $mime; 'mimetype' => $mime,
]);
$this->loadMimetypes();
} catch (\Doctrine\DBAL\DBALException $e) { } catch (\Doctrine\DBAL\DBALException $e) {
\OC_Log::write('core', 'Exception during mimetype insertion: ' . $e->getmessage(), \OC_Log::DEBUG); \OC_Log::write('core', 'Exception during mimetype insertion: ' . $e->getmessage(), \OC_Log::DEBUG);
return -1; return -1;
...@@ -95,6 +97,8 @@ class Cache { ...@@ -95,6 +97,8 @@ class Cache {
} }
public function loadMimetypes() { public function loadMimetypes() {
self::$mimetypeIds = self::$mimetypes = array();
$result = \OC_DB::executeAudited('SELECT `id`, `mimetype` FROM `*PREFIX*mimetypes`', array()); $result = \OC_DB::executeAudited('SELECT `id`, `mimetype` FROM `*PREFIX*mimetypes`', array());
if ($result) { if ($result) {
while ($row = $result->fetchRow()) { while ($row = $result->fetchRow()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment