From 62b859d66fa93a0954831985c124d5feb5a185fa Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Tue, 28 Jan 2014 19:57:07 -0800 Subject: [PATCH] Migrate Google Drive storage app to v1.0.0 of the client library --- apps/files_external/ajax/google.php | 2 +- apps/files_external/lib/google.php | 48 ++++++++++++++--------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/apps/files_external/ajax/google.php b/apps/files_external/ajax/google.php index 40c10aa5d0..f967140a6c 100644 --- a/apps/files_external/ajax/google.php +++ b/apps/files_external/ajax/google.php @@ -1,7 +1,7 @@ setClientId($params['client_id']); - $client->setClientSecret($params['client_secret']); - $client->setScopes(array('https://www.googleapis.com/auth/drive')); - $client->setUseObjects(true); - $client->setAccessToken($params['token']); + $this->client = new \Google_Client(); + $this->client->setClientId($params['client_id']); + $this->client->setClientSecret($params['client_secret']); + $this->client->setScopes(array('https://www.googleapis.com/auth/drive')); + $this->client->setAccessToken($params['token']); // note: API connection is lazy - $this->service = new \Google_DriveService($client); + $this->service = new \Google_Service_Drive($this->client); $token = json_decode($params['token'], true); $this->id = 'google::'.substr($params['client_id'], 0, 30).$token['created']; } else { @@ -66,9 +65,9 @@ class Google extends \OC\Files\Storage\Common { } /** - * Get the Google_DriveFile object for the specified path + * Get the Google_Service_Drive_DriveFile object for the specified path * @param string $path - * @return string + * @return Google_Service_Drive_DriveFile */ private function getDriveFile($path) { // Remove leading and trailing slashes @@ -115,7 +114,7 @@ class Google extends \OC\Files\Storage\Common { $pathWithoutExt = substr($path, 0, $pos); $file = $this->getDriveFile($pathWithoutExt); if ($file) { - // Switch cached Google_DriveFile to the correct index + // Switch cached Google_Service_Drive_DriveFile to the correct index unset($this->driveFiles[$pathWithoutExt]); $this->driveFiles[$path] = $file; $parentId = $file->getId(); @@ -133,9 +132,9 @@ class Google extends \OC\Files\Storage\Common { } /** - * Set the Google_DriveFile object in the cache + * Set the Google_Service_Drive_DriveFile object in the cache * @param string $path - * @param Google_DriveFile|false $file + * @param Google_Service_Drive_DriveFile|false $file */ private function setDriveFile($path, $file) { $path = trim($path, '/'); @@ -188,10 +187,10 @@ class Google extends \OC\Files\Storage\Common { if (!$this->is_dir($path)) { $parentFolder = $this->getDriveFile(dirname($path)); if ($parentFolder) { - $folder = new \Google_DriveFile(); + $folder = new \Google_Service_Drive_DriveFile(); $folder->setTitle(basename($path)); $folder->setMimeType(self::FOLDER); - $parent = new \Google_ParentReference(); + $parent = new \Google_Service_Drive_ParentReference(); $parent->setId($parentFolder->getId()); $folder->setParents(array($parent)); $result = $this->service->files->insert($folder); @@ -266,7 +265,7 @@ class Google extends \OC\Files\Storage\Common { $this->onDuplicateFileDetected($filepath); } } else { - // Cache the Google_DriveFile for future use + // Cache the Google_Service_Drive_DriveFile for future use $this->setDriveFile($filepath, $child); $files[] = $name; } @@ -356,7 +355,7 @@ class Google extends \OC\Files\Storage\Common { // Change file parent $parentFolder2 = $this->getDriveFile(dirname($path2)); if ($parentFolder2) { - $parent = new \Google_ParentReference(); + $parent = new \Google_Service_Drive_ParentReference(); $parent->setId($parentFolder2->getId()); $file->setParents(array($parent)); } else { @@ -395,8 +394,8 @@ class Google extends \OC\Files\Storage\Common { $downloadUrl = $file->getDownloadUrl(); } if (isset($downloadUrl)) { - $request = new \Google_HttpRequest($downloadUrl, 'GET', null, null); - $httpRequest = \Google_Client::$io->authenticatedRequest($request); + $request = new \Google_Http_Request($downloadUrl, 'GET', null, null); + $httpRequest = $this->client->getAuth()->authenticatedRequest($request); if ($httpRequest->getResponseHttpCode() == 200) { $tmpFile = \OC_Helper::tmpFile($ext); $data = $httpRequest->getResponseBody(); @@ -440,16 +439,17 @@ class Google extends \OC\Files\Storage\Common { $params = array( 'data' => $data, 'mimeType' => $mimetype, + 'uploadType' => 'media' ); $result = false; if ($this->file_exists($path)) { $file = $this->getDriveFile($path); $result = $this->service->files->update($file->getId(), $file, $params); } else { - $file = new \Google_DriveFile(); + $file = new \Google_Service_Drive_DriveFile(); $file->setTitle(basename($path)); $file->setMimeType($mimetype); - $parent = new \Google_ParentReference(); + $parent = new \Google_Service_Drive_ParentReference(); $parent->setId($parentFolder->getId()); $file->setParents(array($parent)); $result = $this->service->files->insert($file, $params); @@ -506,9 +506,9 @@ class Google extends \OC\Files\Storage\Common { } else { $parentFolder = $this->getDriveFile(dirname($path)); if ($parentFolder) { - $file = new \Google_DriveFile(); + $file = new \Google_Service_Drive_DriveFile(); $file->setTitle(basename($path)); - $parent = new \Google_ParentReference(); + $parent = new \Google_Service_Drive_ParentReference(); $parent->setId($parentFolder->getId()); $file->setParents(array($parent)); $result = $this->service->files->insert($file);