Merge remote-tracking branch 'upstream/3.0.1.7-Gmail' into 3.0.1.7-Gmail

This commit is contained in:
Dante
2015-12-20 10:31:42 -04:00
5 changed files with 63 additions and 37 deletions

View File

@@ -409,6 +409,7 @@ class AppDocumentDrive
$emails = $appDoc->getSyncPermissions();
$emails = !empty($emails) ? explode('|', $emails) : array();
$result = null;
foreach ($emails as $index => $email) {
if (!empty($email)) {
if ($index == 0 && $fields['SYNC_WITH_DRIVE'] == 'UNSYNCHRONIZED') {
@@ -451,13 +452,14 @@ class AppDocumentDrive
}
}
$fields['SYNC_WITH_DRIVE'] = 'SYNCHRONIZED';
$fields['SYNC_PERMISSIONS'] = null;
if ($result != null) {
$fields['SYNC_WITH_DRIVE'] = 'SYNCHRONIZED';
$fields['SYNC_PERMISSIONS'] = null;
}
} else {
$fields['SYNC_WITH_DRIVE'] = 'NO_EXIST_FILE_PM';
if ($log) {
eprintln('File no exists:' . $name , 'red');
//eprintln($realPath , 'red');
}
}
$appDoc->update($fields);

View File

@@ -94,12 +94,13 @@ class PMDrive extends PMGoogleApi
*/
public function listFolder($fileId)
{
$this->setScope('https://www.googleapis.com/auth/drive');
$this->setScope('https://www.googleapis.com/auth/drive.file');
$this->setScope('https://www.googleapis.com/auth/drive.readonly');
$this->setScope('https://www.googleapis.com/auth/drive.metadata.readonly');
$this->setScope('https://www.googleapis.com/auth/drive.appdata');
$this->setScope('https://www.googleapis.com/auth/drive.metadata');
$this->setScope(static::DRIVE);
$this->setScope(static::DRIVE_FILE);
$this->setScope(static::DRIVE_READONLY);
$this->setScope(static::DRIVE_METADATA);
$this->setScope(static::DRIVE_METADATA_READONLY);
$this->setScope(static::DRIVE_APPDATA);
$service = $this->serviceDrive();
try {
@@ -126,7 +127,7 @@ class PMDrive extends PMGoogleApi
*/
public function createFolder($name, $parentId = null)
{
$this->setScope('https://www.googleapis.com/auth/drive.file');
$this->setScope(static::DRIVE_FILE);
$service = $this->serviceDrive();
@@ -159,7 +160,7 @@ class PMDrive extends PMGoogleApi
*/
public function uploadFile($mime, $src, $name, $parentId = null)
{
$this->setScope('https://www.googleapis.com/auth/drive.file');
$this->setScope(static::DRIVE_FILE);
$service = $this->serviceDrive();
@@ -200,13 +201,13 @@ class PMDrive extends PMGoogleApi
*/
public function downloadFile($fileId)
{
$this->setScope('https://www.googleapis.com/auth/drive');
$this->setScope('https://www.googleapis.com/auth/drive.appdata');
$this->setScope('https://www.googleapis.com/auth/drive.apps.readonly');
$this->setScope('https://www.googleapis.com/auth/drive.file');
$this->setScope('https://www.googleapis.com/auth/drive.metadata');
$this->setScope('https://www.googleapis.com/auth/drive.metadata.readonly');
$this->setScope('https://www.googleapis.com/auth/drive.readonly');
$this->setScope(static::DRIVE);
$this->setScope(static::DRIVE_APPDATA);
$this->setScope(static::DRIVE_APPS_READONLY);
$this->setScope(static::DRIVE_FILE);
$this->setScope(static::DRIVE_METADATA);
$this->setScope(static::DRIVE_METADATA_READONLY);
$this->setScope(static::DRIVE_READONLY);
$service = $this->serviceDrive();
$response = null;
@@ -241,8 +242,8 @@ class PMDrive extends PMGoogleApi
*/
public function setPermission($fileId, $value, $type = 'user', $role = 'reader', $sendNotification = false)
{
$this->setScope('https://www.googleapis.com/auth/drive');
$this->setScope('https://www.googleapis.com/auth/drive.file');
$this->setScope(static::DRIVE);
$this->setScope(static::DRIVE_FILE);
$service = $this->serviceDrive();

View File

@@ -9,6 +9,15 @@ require_once PATH_TRUNK . 'vendor' . PATH_SEP . 'google' . PATH_SEP . 'apiclient
class PMGoogleApi
{
const DRIVE = 'https://www.googleapis.com/auth/drive';
const DRIVE_FILE = 'https://www.googleapis.com/auth/drive.file';
const DRIVE_APPS_READONLY = 'https://www.googleapis.com/auth/drive.apps.readonly';
const DRIVE_READONLY = 'https://www.googleapis.com/auth/drive.readonly';
const DRIVE_METADATA = 'https://www.googleapis.com/auth/drive.metadata';
const DRIVE_METADATA_READONLY = 'https://www.googleapis.com/auth/drive.metadata.readonly';
const DRIVE_APPDATA = 'https://www.googleapis.com/auth/drive.appdata';
const DRIVE_PHOTOS_READONLY = 'https://www.googleapis.com/auth/drive.photos.readonly';
private $scope = array();
private $serviceAccountEmail;
private $serviceAccountP12;
@@ -244,13 +253,13 @@ class PMGoogleApi
{
$scope = array(
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/drive.metadata.readonly',
'https://www.googleapis.com/auth/drive.appdata',
'https://www.googleapis.com/auth/drive.metadata',
'https://www.googleapis.com/auth/drive.photos.readonly'
static::DRIVE,
static::DRIVE_FILE,
static::DRIVE_READONLY,
static::DRIVE_METADATA,
static::DRIVE_METADATA_READONLY,
static::DRIVE_APPDATA,
static::DRIVE_PHOTOS_READONLY
);
if ($credentials->typeAuth == 'webApplication') {

View File

@@ -107,6 +107,7 @@ if (! $sw_file_exists) {
$res['message'] = $oAppDocument->Fields['APP_DOC_FILENAME'];
print G::json_encode( $res );
} else {
$nameFile = $oAppDocument->Fields['APP_DOC_FILENAME'];
$licensedFeatures = &PMLicensedFeatures::getSingleton();
$downloadStatus = false;
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
@@ -116,14 +117,20 @@ if (! $sw_file_exists) {
$fieldDrive = $oAppDocument->getAppDocDriveDownload();
$drive->loadUser($_SESSION['USER_LOGGED']);
$uidDrive = $drive->changeUrlDrive($oAppDocument->Fields, $oAppDocument->getAppDocType());
$result = $drive->download($uidDrive);
//verify download
file_put_contents($oAppDocument->Fields['APP_DOC_FILENAME'], $result);
$downloadStatus = true;
$fileContent = $drive->download($uidDrive);
if ($fileContent !== null) {
$downloadStatus = true;
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename='.$nameFile);
header('Content-Transfer-Encoding: binary');
header('Set-Cookie: fileLoading=true');
echo $fileContent;
exit();
}
}
}
if (!$downloadStatus) {
G::streamFile( $realPath, $bDownload, $oAppDocument->Fields['APP_DOC_FILENAME'] ); //download
G::streamFile( $realPath, $bDownload, $nameFile ); //download
}

View File

@@ -109,6 +109,7 @@ if (! $sw_file_exists) {
$res['message'] = $info['basename'] . $ver . '.' . $ext;
print G::json_encode( $res );
} else {
$nameFile = $info['basename'] . $ver . '.' . $ext;
$licensedFeatures = &PMLicensedFeatures::getSingleton();
$downloadStatus = false;
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
@@ -119,14 +120,20 @@ if (! $sw_file_exists) {
$drive->loadUser($_SESSION['USER_LOGGED']);
$type = $ext == 'doc' ? 'OUTPUT_DOC' : 'OUTPUT_PDF';
$uidDrive = $drive->changeUrlDrive($oAppDocument->Fields, $type);
$result = $drive->download($uidDrive);
//verify download file
file_put_contents($info['basename'] . $ver . '.' . $ext , $result);
$downloadStatus = true;
$fileContent = $drive->download($uidDrive);
if ($fileContent !== null) {
$downloadStatus = true;
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename='.$nameFile);
header('Content-Transfer-Encoding: binary');
header('Set-Cookie: fileLoading=true');
echo $fileContent;
exit();
}
}
}
if (!$downloadStatus) {
G::streamFile( $realPath, $download, $info['basename'] . $ver . '.' . $ext ); //download
G::streamFile( $realPath, $download, $nameFile); //download
}
//die($realPath);