summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2013-05-30 21:45:16 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2013-05-30 21:45:16 -0400
commit8be23efa730e99083bd6ac95f163f9007644db5a (patch)
tree940d9980c0444f86401c05c561f0a8f7d2b8e56a /apps/files_external
parentbd0d189f6fb96c3b21bd71c10349a02e6cc2e5d7 (diff)
downloadnextcloud-server-8be23efa730e99083bd6ac95f163f9007644db5a.tar.gz
nextcloud-server-8be23efa730e99083bd6ac95f163f9007644db5a.zip
Implement hasUpdated() to watch for changes on Google Drive side
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/google.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index df3dc41be27..678799545d7 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -465,4 +465,63 @@ class Google extends \OC\Files\Storage\Common {
return false;
}
+ public function hasUpdated($path, $time) {
+ if ($this->is_file($path)) {
+ return parent::hasUpdated($path, $time);
+ } else {
+ // Google Drive doesn't change modified times of folders when files inside are updated
+ // Instead we use the Changes API to see if folders have been updated, and it's a pain
+ $folder = $this->getDriveFile($path);
+ if ($folder) {
+ $result = false;
+ $folderId = $folder->getId();
+ $startChangeId = \OC_Appconfig::getValue('files_external', $this->getId().'cId');
+ $params = array(
+ 'includeDeleted' => true,
+ 'includeSubscribed' => true,
+ );
+ if (isset($startChangeId)) {
+ $startChangeId = (int)$startChangeId;
+ $largestChangeId = $startChangeId;
+ $params['startChangeId'] = $startChangeId + 1;
+ } else {
+ $largestChangeId = 0;
+ }
+ $pageToken = true;
+ while ($pageToken) {
+ if ($pageToken !== true) {
+ $params['pageToken'] = $pageToken;
+ }
+ $changes = $this->service->changes->listChanges($params);
+ if ($largestChangeId === 0 || $largestChangeId === $startChangeId) {
+ $largestChangeId = $changes->getLargestChangeId();
+ }
+ if (isset($startChangeId)) {
+ // Check if a file in this folder has been updated
+ // There is no way to filter by folder at the API level...
+ foreach ($changes->getItems() as $change) {
+ foreach ($change->getFile()->getParents() as $parent) {
+ if ($parent->getId() === $folderId) {
+ $result = true;
+ // Check if there are changes in different folders
+ } else if ($change->getId() <= $largestChangeId) {
+ // Decrement id so this change is fetched when called again
+ $largestChangeId = $change->getId();
+ $largestChangeId--;
+ }
+ }
+ }
+ $pageToken = $changes->getNextPageToken();
+ } else {
+ // Assuming the initial scan just occurred and changes are negligible
+ break;
+ }
+ }
+ \OC_Appconfig::setValue('files_external', $this->getId().'cId', $largestChangeId);
+ return $result;
+ }
+ }
+ return false;
+ }
+
} \ No newline at end of file