Skip to content

Commit 2b33971

Browse files
committed
Merge branch 'develop'
2 parents e014c20 + 6ab2c96 commit 2b33971

4 files changed

Lines changed: 26 additions & 18 deletions

File tree

lib/Controller/ConnectedServices/GDrive/GDriveController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use API\Commons\KleinController;
66
use Aws\S3\Exception\S3Exception;
77
use Bootstrap;
8+
use ConnectedServices\GoogleClientFactory;
89
use Constants;
910
use CookieManager;
1011
use Exception;
@@ -137,7 +138,8 @@ private function doImport() {
137138

138139
for ( $i = 0; $i < count( $listOfIds ) && $this->isImportingSuccessful === true; $i++ ) {
139140
try {
140-
$this->gdriveUserSession->importFile( $listOfIds[ $i ] );
141+
$client = GoogleClientFactory::getGoogleClient( INIT::$HTTPHOST . "/gdrive/oauth/response" );
142+
$this->gdriveUserSession->importFile( $listOfIds[ $i ], $client );
141143
} catch ( Exception $e){
142144
$this->isImportingSuccessful = false;
143145
$this->error = [

lib/Decorator/CatDecorator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function decorate() {
6060
}, RemoteFiles_RemoteFileDao::getByJobId( $this->job->id ) );
6161

6262
$this->template->remoteFilesInJob = $files;
63+
$this->template->isGDriveProject = $this->isGDriveProject;
6364
}
6465

6566
$this->template->support_mail = INIT::$SUPPORT_MAIL;

lib/Utils/ConnectedServices/GDrive/Session.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use API\Commons\Exceptions\AuthenticationError;
1212
use ConnectedServices\ConnectedServiceDao;
1313
use ConnectedServices\ConnectedServiceStruct;
14+
use ConnectedServices\GoogleClientFactory;
1415
use Constants;
1516
use ConversionHandler;
1617
use DirectoryIterator;
@@ -412,6 +413,8 @@ public function getService( Google_Client $gClient ): ?Google_Service_Drive {
412413
}
413414

414415
/**
416+
* @param Google_Client $gClient
417+
*
415418
* @return RemoteFileService
416419
* @throws Exception
417420
*/
@@ -455,7 +458,7 @@ public function removeFile( string $fileId ): bool {
455458
$tempUploadedFileDir = INIT::$UPLOAD_REPOSITORY . DIRECTORY_SEPARATOR . $this->session[ 'upload_session' ];
456459

457460
/** @var DirectoryIterator $item */
458-
foreach ( $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $tempUploadedFileDir, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::SELF_FIRST ) as $item ) {
461+
foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $tempUploadedFileDir, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::SELF_FIRST ) as $item ) {
459462
$target = explode( '__', $pathCache );
460463
$hashFile = $file[ 'fileHash' ] . "|" . end( $target );
461464

@@ -579,28 +582,30 @@ public function setConversionParams( string $guid, string $source_lang, string $
579582
}
580583

581584
/**
582-
* @param int $fileId
583-
* @param string $remoteFileId
585+
* @param int $fileId
586+
* @param string $remoteFileId
587+
* @param Google_Client $gClient
584588
*
585589
* @throws Exception
586590
*/
587-
public function createRemoteFile( int $fileId, string $remoteFileId ) {
588-
$this->getService();
591+
public function createRemoteFile( int $fileId, string $remoteFileId, Google_Client $gClient ) {
592+
$this->getService( $gClient );
589593
RemoteFiles_RemoteFileDao::insert( $fileId, 0, $remoteFileId, $this->serviceStruct->id, 1 );
590594
}
591595

592596
/**
593597
*
594598
* Creates copies of the original remote file there the translation will be saved.
595599
*
596-
* @param int $id_file
597-
* @param int $id_job
600+
* @param int $id_file
601+
* @param int $id_job
602+
* @param Google_Client $gClient
598603
*
599604
* @throws Exception
600605
*/
601606
public function createRemoteCopiesWhereToSaveTranslation( int $id_file, int $id_job, Google_Client $gClient ) {
602607

603-
$service = $this->getService();
608+
$service = $this->getService( $gClient );
604609

605610
if ( !$service ) {
606611
throw new Exception( 'Cannot instantiate service' );
@@ -620,16 +625,14 @@ public function createRemoteCopiesWhereToSaveTranslation( int $id_file, int $id_
620625

621626
RemoteFiles_RemoteFileDao::insert( $id_file, $id_job, $copiedFile->id, $this->serviceStruct->id );
622627

623-
$this->grantFileAccessByUrl( $copiedFile->id );
628+
$this->grantFileAccessByUrl( $copiedFile->id, $gClient );
624629
}
625630

626631
/**
627-
* @param string $googleFileId
628632
*
629-
* @return Google_Service_Drive_Permission
630633
* @throws Exception
631634
*/
632-
public function grantFileAccessByUrl( string $googleFileId ): Google_Service_Drive_Permission {
635+
public function grantFileAccessByUrl( string $googleFileId, Google_Client $gClient ): Google_Service_Drive_Permission {
633636
if ( !$this->__getUser() ) {
634637
throw new Exception( 'Cannot proceed without a User' );
635638
}
@@ -638,7 +641,7 @@ public function grantFileAccessByUrl( string $googleFileId ): Google_Service_Dri
638641
$urlPermission->setType( 'anyone' );
639642
$urlPermission->setRole( 'reader' );
640643

641-
$service = $this->getService();
644+
$service = $this->getService( $gClient );
642645

643646
if ( !$service ) {
644647
throw new Exception( 'Cannot instantiate service' );
@@ -648,7 +651,8 @@ public function grantFileAccessByUrl( string $googleFileId ): Google_Service_Dri
648651
}
649652

650653
/**
651-
* @param string $googleFileId
654+
* @param string $googleFileId
655+
* @param Google_Client $gClient
652656
*
653657
* @throws AuthenticationError
654658
* @throws EndQueueException
@@ -657,13 +661,13 @@ public function grantFileAccessByUrl( string $googleFileId ): Google_Service_Dri
657661
* @throws ValidationError
658662
* @throws Exception
659663
*/
660-
public function importFile( string $googleFileId ) {
664+
public function importFile( string $googleFileId, Google_Client $gClient ) {
661665

662666
if ( !isset( $this->guid ) ) {
663667
throw new Exception( 'conversion params not set' );
664668
}
665669

666-
$service = $this->getService();
670+
$service = $this->getService( $gClient );
667671

668672
if ( !$service ) {
669673
throw new Exception( 'Cannot instantiate service' );

lib/Utils/ProjectManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,8 @@ protected function _insertFiles( $_originalFileNames, $sha1_original, $cachedXli
22682268
if ( $this->gdriveSession ) {
22692269
$gdriveFileId = $this->gdriveSession->findFileIdByName( $originalFileName );
22702270
if ( $gdriveFileId ) {
2271-
$this->gdriveSession->createRemoteFile( $fid, $gdriveFileId );
2271+
$client = GoogleClientFactory::getGoogleClient( INIT::$HTTPHOST . "/gdrive/oauth/response" );
2272+
$this->gdriveSession->createRemoteFile( $fid, $gdriveFileId, $client );
22722273
}
22732274
}
22742275

0 commit comments

Comments
 (0)