1111use API \Commons \Exceptions \AuthenticationError ;
1212use ConnectedServices \ConnectedServiceDao ;
1313use ConnectedServices \ConnectedServiceStruct ;
14+ use ConnectedServices \GoogleClientFactory ;
1415use Constants ;
1516use ConversionHandler ;
1617use 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 ' );
0 commit comments