[owncloud] backport upstream support for google PHP lib 1.x and unbundle it

Adam Williamson adamwill at fedoraproject.org
Sat Dec 20 23:12:45 UTC 2014


commit b729706f9f4814587fb1d2e7a3271d3ada4b926f
Author: Adam Williamson <awilliam at redhat.com>
Date:   Sat Dec 20 15:12:32 2014 -0800

    backport upstream support for google PHP lib 1.x and unbundle it

 owncloud-7.0.4-google1.patch |  234 ++++++++++++++++++++++++++++++++++++++++++
 owncloud.spec                |   14 ++-
 2 files changed, 244 insertions(+), 4 deletions(-)
---
diff --git a/owncloud-7.0.4-google1.patch b/owncloud-7.0.4-google1.patch
new file mode 100644
index 0000000..856f68f
--- /dev/null
+++ b/owncloud-7.0.4-google1.patch
@@ -0,0 +1,234 @@
+diff --git owncloud-7.0.4/apps/files_external/ajax/google.php owncloud-7.0.4-google1/apps/files_external/ajax/google.php
+index 13e7407..b80f24b 100644
+--- owncloud-7.0.4/apps/files_external/ajax/google.php
++++ owncloud-7.0.4-google1/apps/files_external/ajax/google.php
+@@ -1,12 +1,12 @@
+ <?php
+ set_include_path(get_include_path().PATH_SEPARATOR.
+ 	\OC_App::getAppPath('files_external').'/3rdparty/google-api-php-client/src');
+-require_once 'Google_Client.php';
++require_once 'Google/Client.php';
+ 
+ OCP\JSON::checkAppEnabled('files_external');
+ OCP\JSON::checkLoggedIn();
+ OCP\JSON::callCheck();
+-$l = OC_L10N::get('files_external');
++$l = \OC::$server->getL10N('files_external');
+ 
+ if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST['redirect'])) {
+ 	$client = new Google_Client();
+@@ -14,6 +14,7 @@ if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST
+ 	$client->setClientSecret($_POST['client_secret']);
+ 	$client->setRedirectUri($_POST['redirect']);
+ 	$client->setScopes(array('https://www.googleapis.com/auth/drive'));
++	$client->setAccessType('offline');
+ 	if (isset($_POST['step'])) {
+ 		$step = $_POST['step'];
+ 		if ($step == 1) {
+diff --git owncloud-7.0.4/apps/files_external/lib/google.php owncloud-7.0.4-google1/apps/files_external/lib/google.php
+index e71c7ab..bd9bdce 100644
+--- owncloud-7.0.4/apps/files_external/lib/google.php
++++ owncloud-7.0.4-google1/apps/files_external/lib/google.php
+@@ -23,11 +23,12 @@ namespace OC\Files\Storage;
+ 
+ set_include_path(get_include_path().PATH_SEPARATOR.
+ 	\OC_App::getAppPath('files_external').'/3rdparty/google-api-php-client/src');
+-require_once 'Google_Client.php';
+-require_once 'contrib/Google_DriveService.php';
++require_once 'Google/Client.php';
++require_once 'Google/Service/Drive.php';
+ 
+ class Google extends \OC\Files\Storage\Common {
+ 
++	private $client;
+ 	private $id;
+ 	private $service;
+ 	private $driveFiles;
+@@ -46,14 +47,19 @@ class Google extends \OC\Files\Storage\Common {
+ 			&& isset($params['client_id']) && isset($params['client_secret'])
+ 			&& isset($params['token'])
+ 		) {
+-			$client = new \Google_Client();
+-			$client->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']);
++			// if curl isn't available we're likely to run into
++			// https://github.com/google/google-api-php-client/issues/59
++			// - disable gzip to avoid it.
++			if (!function_exists('curl_version') || !function_exists('curl_exec')) {
++				$this->client->setClassConfig("Google_Http_Request", "disable_gzip", true);
++			}
+ 			// 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 +72,10 @@ 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.
++	 * Returns false on failure.
+ 	 * @param string $path
+-	 * @return string
++	 * @return \Google_Service_Drive_DriveFile|false
+ 	 */
+ 	private function getDriveFile($path) {
+ 		// Remove leading and trailing slashes
+@@ -115,7 +122,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 +140,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 +195,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);
+@@ -205,6 +212,9 @@ class Google extends \OC\Files\Storage\Common {
+ 	}
+ 
+ 	public function rmdir($path) {
++		if (!$this->isDeletable($path)) {
++			return false;
++		}
+ 		if (trim($path, '/') === '') {
+ 			$dir = $this->opendir($path);
+ 			if(is_resource($dir)) {
+@@ -263,7 +273,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;
+ 					}
+@@ -287,7 +297,7 @@ class Google extends \OC\Files\Storage\Common {
+ 				// Check if this is a Google Doc
+ 				if ($this->getMimeType($path) !== $file->getMimeType()) {
+ 					// Return unknown file size
+-					$stat['size'] = \OC\Files\SPACE_UNKNOWN;
++					$stat['size'] = \OCP\Files\FileInfo::SPACE_UNKNOWN;
+ 				} else {
+ 					$stat['size'] = $file->getFileSize();
+ 				}
+@@ -353,17 +363,29 @@ 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 {
+ 					return false;
+ 				}
+ 			}
++			// We need to get the object for the existing file with the same
++			// name (if there is one) before we do the patch. If oldfile
++			// exists and is a directory we have to delete it before we
++			// do the rename too.
++			$oldfile = $this->getDriveFile($path2);
++			if ($oldfile && $this->is_dir($path2)) {
++				$this->rmdir($path2);
++				$oldfile = false;
++			}
+ 			$result = $this->service->files->patch($file->getId(), $file);
+ 			if ($result) {
+ 				$this->setDriveFile($path1, false);
+ 				$this->setDriveFile($path2, $result);
++				if ($oldfile) {
++					$this->service->files->delete($oldfile->getId());
++				}
+ 			}
+ 			return (bool)$result;
+ 		} else {
+@@ -392,8 +414,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();
+@@ -437,16 +459,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);
+@@ -493,7 +516,10 @@ class Google extends \OC\Files\Storage\Common {
+ 		$result = false;
+ 		if ($file) {
+ 			if (isset($mtime)) {
+-				$file->setModifiedDate($mtime);
++				// This is just RFC3339, but frustratingly, GDrive's API *requires*
++				// the fractions portion be present, while no handy PHP constant
++				// for RFC3339 or ISO8601 includes it. So we do it ourselves.
++				$file->setModifiedDate(date('Y-m-d\TH:i:s.uP', $mtime));
+ 				$result = $this->service->files->patch($file->getId(), $file, array(
+ 					'setModifiedDate' => true,
+ 				));
+@@ -503,9 +529,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);
diff --git a/owncloud.spec b/owncloud.spec
index 191b7c9..436e841 100644
--- a/owncloud.spec
+++ b/owncloud.spec
@@ -1,6 +1,6 @@
 Name:           owncloud
 Version:        7.0.4
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        Private file sync and share server
 
 License:        AGPLv3+ and MIT and BSD and CC-BY and CC-BY-SA and GPLv3 and Public Domain and (MPLv1.1 or GPLv2+ or LGPLv2+) and (MIT or GPL+) and (MIT or GPLv2) and ASL 2.0 and LGPLv3
@@ -54,6 +54,9 @@ Patch14:        %{name}-7.0.3-3rdparty_includes.patch
 # Be less heavy-handed about clearing the opcache after editing config.php
 # Avoids triggering a crash in php-opcache: https://github.com/owncloud/core/issues/9885
 Patch15:        %{name}-7.0.3-opcache_invalidate.patch
+# Backported from upstream 8.x, updates Google Drive external storage support
+# for v1.x of the Google API library.
+Patch16:        %{name}-7.0.4-google1.patch
 
 BuildArch:      noarch
 
@@ -120,6 +123,7 @@ Requires:       php-ZendFramework-Search-Lucene
 ## apps/files_external
 Requires:       php-pear(pear.dropbox-php.com/Dropbox)
 Requires:       php-pear(phpseclib.sourceforge.net/Net_SFTP)
+Requires:       php-composer(google/apiclient) >= 1.0.3
 
 %if 0%{?rhel}
 Requires(post): policycoreutils-python
@@ -220,6 +224,7 @@ sed -i 's/\r$//' apps/files_encryption/lib/crypt.php
 %patch13 -p1
 %patch14 -p1
 %patch15 -p1
+%patch16 -p1
 
 # prepare package doc
 cp %{SOURCE3} README.fedora
@@ -242,6 +247,7 @@ mkdir -p 3rdparty/phpseclib/phpseclib/phpseclib/Crypt
 rm -r apps/files_encryption/3rdparty/Crypt_Blowfish
 rm -r apps/search_lucene/3rdparty/Zend
 rm -r apps/files_external/3rdparty/Dropbox
+rm -r apps/files_external/3rdparty/google-api-php-client
 
 # ===== BUNDLING NOTES =====
 
@@ -271,9 +277,6 @@ rm -r apps/files_external/3rdparty/Dropbox
 ## apps/files_external/3rdparty/smb4php - forked php class from
 # http://www.phpclasses.org/package/4129-PHP-Stream-wrapper-to-access-Windows-shared-files.html
 
-## apps/files_external/3rdparty/google-api-php-client - http://code.google.com/p/google-api-php-client
-# Review request: https://bugzilla.redhat.com/show_bug.cgi?id=1047626
-
 ## apps/files_external/3rdparty/aws-sdk-php - https://github.com/aws/aws-sdk-php
 # Old version, 2.4.0. Not forked, but stripped. We have 2.5.3 packaged as
 # php-aws-sdk. Upstream master is up to 2.6.11, now provided via Packagist/Composer.
@@ -429,6 +432,9 @@ fi
 
 
 %changelog
+* Sat Dec 20 2014 Adam Williamson <awilliam at redhat.com> - 7.0.4-2
+- backport upstream support for google PHP lib 1.x and unbundle it
+
 * Tue Dec 09 2014 Adam Williamson <awilliam at redhat.com> - 7.0.4-1
 - new release 7.0.4
 


More information about the scm-commits mailing list