Skip to content

Commit

Permalink
fix update to reset column on oracle #31692
Browse files Browse the repository at this point in the history
  • Loading branch information
IljaN committed Jul 5, 2018
1 parent db35412 commit 97d0454
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

namespace OC\Files\Cache;

use Doctrine\DBAL\Platforms\OraclePlatform;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
use \OCP\Files\IMimeTypeLoader;
Expand Down Expand Up @@ -305,6 +306,16 @@ public function update($id, array $data) {
$params = \array_merge($params, $params);
$params[] = $id;

// Oracle does not support empty string values so we convert them to nulls
// https://github.com/owncloud/core/issues/31692
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
foreach ($data as $param => $value) {
if ($value === '') {
$data[$param] = null;
}
}
}

// don't update if the data we try to set is the same as the one in the record
// some databases (Postgres) don't like superfluous updates
$sql = 'UPDATE `*PREFIX*filecache` SET ' . \implode(' = ?, ', $queryParts) . '=? ' .
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/Files/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,15 @@ public function testEscaping($name) {
}
}

public function testUpdateClearsCacheColumn() {
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'checksum' => 'abc'];
$this->cache->put('somefile.txt', $data);

$this->cache->update($this->cache->getId('somefile.txt'), ['mtime' => 0,'checksum' => '']);
$entry = $this->cache->get('somefile.txt');
$this->assertEmpty($entry['checksum']);
}

protected function tearDown() {
if ($this->cache) {
$this->cache->clear();
Expand Down

0 comments on commit 97d0454

Please sign in to comment.