MDL-37984 portfolio: using older Google libraries
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
*/
|
||||
require_once($CFG->libdir.'/portfolio/plugin.php');
|
||||
require_once($CFG->libdir . '/google/lib.php');
|
||||
require_once($CFG->libdir . '/google/Google/Service/Drive.php');
|
||||
require_once($CFG->libdir . '/google/Google_Client.php');
|
||||
require_once($CFG->libdir . '/google/contrib/Google_DriveService.php');
|
||||
|
||||
class portfolio_plugin_googledocs extends portfolio_plugin_push_base {
|
||||
/**
|
||||
@@ -75,11 +75,20 @@ class portfolio_plugin_googledocs extends portfolio_plugin_push_base {
|
||||
if (!$this->client) {
|
||||
throw new portfolio_plugin_exception('noauthtoken', 'portfolio_googledocs');
|
||||
}
|
||||
// Portfolio_exporter::rewaken_object does not 'wake' client properly
|
||||
// ...auth is null after unserialize, therefore initialize again!!!
|
||||
if (!$this->client->getAuth()) {
|
||||
$this->initialize_oauth();
|
||||
// Get access token from session and set it to client.
|
||||
if (!$this->get_access_token()) {
|
||||
throw new portfolio_plugin_exception('noauthtoken', 'portfolio_googledocs');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->exporter->get_tempfiles() as $file) {
|
||||
try {
|
||||
// Create drivefile object and fill it with data.
|
||||
$drivefile = new Google_Service_Drive_DriveFile();
|
||||
$drivefile = new Google_DriveFile();
|
||||
$drivefile->setTitle($file->get_filename());
|
||||
$drivefile->setMimeType($file->get_mimetype());
|
||||
|
||||
@@ -141,6 +150,11 @@ class portfolio_plugin_googledocs extends portfolio_plugin_push_base {
|
||||
}
|
||||
// Get the authentication code send by Google.
|
||||
$code = isset($params['oauth2code']) ? $params['oauth2code'] : null;
|
||||
// Portfolio_exporter::rewaken_object does not 'wake' client properly
|
||||
// ...auth is null after unserialize, therefore initialize again!!!
|
||||
if (!$this->client->getAuth()) {
|
||||
$this->initialize_oauth();
|
||||
}
|
||||
// Try to authenticate (throws exception which is catched higher).
|
||||
$this->client->authenticate($code);
|
||||
// Make sure we accually have access token at this time
|
||||
@@ -192,15 +206,14 @@ class portfolio_plugin_googledocs extends portfolio_plugin_push_base {
|
||||
$secret = $this->get_config('secret');
|
||||
|
||||
// Setup Google client.
|
||||
$this->client = get_google_client();
|
||||
$this->client = new Google_Client();
|
||||
$this->client->setClientId($clientid);
|
||||
$this->client->setClientSecret($secret);
|
||||
$this->client->setScopes(array(Google_Service_Drive::DRIVE_FILE));
|
||||
$this->client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
|
||||
$this->client->setRedirectUri($redirecturi->out(false));
|
||||
// URL to be called when redirecting from authentication.
|
||||
$this->client->setState($returnurl->out_as_local_url(false));
|
||||
// Setup drive upload service.
|
||||
$this->service = new Google_Service_Drive($this->client);
|
||||
$this->service = new Google_DriveService($this->client);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user