Skip to content

Commit

Permalink
Merge pull request #17765 from nextcloud/filecache-extension
Browse files Browse the repository at this point in the history
Upload time and Creation time
  • Loading branch information
rullzer authored Nov 18, 2019
2 parents 497737f + 8800a7e commit 5320f08
Show file tree
Hide file tree
Showing 23 changed files with 869 additions and 454 deletions.
13 changes: 13 additions & 0 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ public function put($data) {
}
}

$fileInfoUpdate = [
'upload_time' => time()
];

// allow sync clients to send the creation time along in a header
if (isset($this->request->server['HTTP_X_OC_CTIME'])) {
$ctime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_CTIME']);
$fileInfoUpdate['creation_time'] = $ctime;
$this->header('X-OC-CTime: accepted');
}

$this->fileView->putFileInfo($this->path, $fileInfoUpdate);

if ($view) {
$this->emitPostHooks($exists);
}
Expand Down
18 changes: 18 additions & 0 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class FilesPlugin extends ServerPlugin {
const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
const SHARE_NOTE = '{http://nextcloud.org/ns}note';

/**
Expand Down Expand Up @@ -400,6 +403,14 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
return new ChecksumList($checksum);
});

$propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) {
return $node->getFileInfo()->getCreationTime();
});

$propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) {
return $node->getFileInfo()->getUploadTime();
});

}

if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
Expand Down Expand Up @@ -470,6 +481,13 @@ public function handleUpdateProperties($path, PropPatch $propPatch) {
}
return false;
});
$propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) {
if (empty($time)) {
return false;
}
$node->setCreationTime((int) $time);
return true;
});
}

/**
Expand Down
8 changes: 8 additions & 0 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ public function setETag($etag) {
return $this->fileView->putFileInfo($this->path, array('etag' => $etag));
}

public function setCreationTime(int $time) {
return $this->fileView->putFileInfo($this->path, array('creation_time' => $time));
}

public function setUploadTime(int $time) {
return $this->fileView->putFileInfo($this->path, array('upload_time' => $time));
}

/**
* Returns the size of the node, in bytes
*
Expand Down
8 changes: 8 additions & 0 deletions apps/files_trashbin/lib/Trash/TrashItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,12 @@ public function getExtension(): string {
public function getTitle(): string {
return $this->getOriginalLocation();
}

public function getCreationTime(): int {
return $this->fileInfo->getCreationTime();
}

public function getUploadTime(): int {
return $this->fileInfo->getUploadTime();
}
}
2 changes: 1 addition & 1 deletion core/Migrations/Version17000Date20190514105811.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$schema = $schemaClosure();
if(!$schema->hasTable('filecache_extended')) {
$table = $schema->createTable('filecache_extended');
$table->addColumn('fileid', Type::INTEGER, [
$table->addColumn('fileid', Type::BIGINT, [
'notnull' => true,
'length' => 4,
'unsigned' => true,
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@
'OC\\Files\\Cache\\AbstractCacheEvent' => $baseDir . '/lib/private/Files/Cache/AbstractCacheEvent.php',
'OC\\Files\\Cache\\Cache' => $baseDir . '/lib/private/Files/Cache/Cache.php',
'OC\\Files\\Cache\\CacheEntry' => $baseDir . '/lib/private/Files/Cache/CacheEntry.php',
'OC\\Files\\Cache\\CacheQueryBuilder' => $baseDir . '/lib/private/Files/Cache/CacheQueryBuilder.php',
'OC\\Files\\Cache\\FailedCache' => $baseDir . '/lib/private/Files/Cache/FailedCache.php',
'OC\\Files\\Cache\\HomeCache' => $baseDir . '/lib/private/Files/Cache/HomeCache.php',
'OC\\Files\\Cache\\HomePropagator' => $baseDir . '/lib/private/Files/Cache/HomePropagator.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Files\\Cache\\AbstractCacheEvent' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/AbstractCacheEvent.php',
'OC\\Files\\Cache\\Cache' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Cache.php',
'OC\\Files\\Cache\\CacheEntry' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/CacheEntry.php',
'OC\\Files\\Cache\\CacheQueryBuilder' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/CacheQueryBuilder.php',
'OC\\Files\\Cache\\FailedCache' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/FailedCache.php',
'OC\\Files\\Cache\\HomeCache' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/HomeCache.php',
'OC\\Files\\Cache\\HomePropagator' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/HomePropagator.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public function subtract($x, $y) {
return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
}

public function count($count, $alias = '') {
public function count($count = '', $alias = '') {
$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
return new QueryFunction('COUNT(' . $this->helper->quoteColumnName($count) . ')' . $alias);
$quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
}

public function max($field) {
Expand Down
Loading

0 comments on commit 5320f08

Please sign in to comment.