Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ostico committed Sep 18, 2024
2 parents e014c20 + 6ab2c96 commit 2b33971
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
4 changes: 3 additions & 1 deletion lib/Controller/ConnectedServices/GDrive/GDriveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use API\Commons\KleinController;
use Aws\S3\Exception\S3Exception;
use Bootstrap;
use ConnectedServices\GoogleClientFactory;
use Constants;
use CookieManager;
use Exception;
Expand Down Expand Up @@ -137,7 +138,8 @@ private function doImport() {

for ( $i = 0; $i < count( $listOfIds ) && $this->isImportingSuccessful === true; $i++ ) {
try {
$this->gdriveUserSession->importFile( $listOfIds[ $i ] );
$client = GoogleClientFactory::getGoogleClient( INIT::$HTTPHOST . "/gdrive/oauth/response" );
$this->gdriveUserSession->importFile( $listOfIds[ $i ], $client );
} catch ( Exception $e){
$this->isImportingSuccessful = false;
$this->error = [
Expand Down
1 change: 1 addition & 0 deletions lib/Decorator/CatDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function decorate() {
}, RemoteFiles_RemoteFileDao::getByJobId( $this->job->id ) );

$this->template->remoteFilesInJob = $files;
$this->template->isGDriveProject = $this->isGDriveProject;
}

$this->template->support_mail = INIT::$SUPPORT_MAIL;
Expand Down
36 changes: 20 additions & 16 deletions lib/Utils/ConnectedServices/GDrive/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use API\Commons\Exceptions\AuthenticationError;
use ConnectedServices\ConnectedServiceDao;
use ConnectedServices\ConnectedServiceStruct;
use ConnectedServices\GoogleClientFactory;
use Constants;
use ConversionHandler;
use DirectoryIterator;
Expand Down Expand Up @@ -412,6 +413,8 @@ public function getService( Google_Client $gClient ): ?Google_Service_Drive {
}

/**
* @param Google_Client $gClient
*
* @return RemoteFileService
* @throws Exception
*/
Expand Down Expand Up @@ -455,7 +458,7 @@ public function removeFile( string $fileId ): bool {
$tempUploadedFileDir = INIT::$UPLOAD_REPOSITORY . DIRECTORY_SEPARATOR . $this->session[ 'upload_session' ];

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

Expand Down Expand Up @@ -579,28 +582,30 @@ public function setConversionParams( string $guid, string $source_lang, string $
}

/**
* @param int $fileId
* @param string $remoteFileId
* @param int $fileId
* @param string $remoteFileId
* @param Google_Client $gClient
*
* @throws Exception
*/
public function createRemoteFile( int $fileId, string $remoteFileId ) {
$this->getService();
public function createRemoteFile( int $fileId, string $remoteFileId, Google_Client $gClient ) {
$this->getService( $gClient );
RemoteFiles_RemoteFileDao::insert( $fileId, 0, $remoteFileId, $this->serviceStruct->id, 1 );
}

/**
*
* Creates copies of the original remote file there the translation will be saved.
*
* @param int $id_file
* @param int $id_job
* @param int $id_file
* @param int $id_job
* @param Google_Client $gClient
*
* @throws Exception
*/
public function createRemoteCopiesWhereToSaveTranslation( int $id_file, int $id_job, Google_Client $gClient ) {

$service = $this->getService();
$service = $this->getService( $gClient );

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

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

$this->grantFileAccessByUrl( $copiedFile->id );
$this->grantFileAccessByUrl( $copiedFile->id, $gClient );
}

/**
* @param string $googleFileId
*
* @return Google_Service_Drive_Permission
* @throws Exception
*/
public function grantFileAccessByUrl( string $googleFileId ): Google_Service_Drive_Permission {
public function grantFileAccessByUrl( string $googleFileId, Google_Client $gClient ): Google_Service_Drive_Permission {
if ( !$this->__getUser() ) {
throw new Exception( 'Cannot proceed without a User' );
}
Expand All @@ -638,7 +641,7 @@ public function grantFileAccessByUrl( string $googleFileId ): Google_Service_Dri
$urlPermission->setType( 'anyone' );
$urlPermission->setRole( 'reader' );

$service = $this->getService();
$service = $this->getService( $gClient );

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

/**
* @param string $googleFileId
* @param string $googleFileId
* @param Google_Client $gClient
*
* @throws AuthenticationError
* @throws EndQueueException
Expand All @@ -657,13 +661,13 @@ public function grantFileAccessByUrl( string $googleFileId ): Google_Service_Dri
* @throws ValidationError
* @throws Exception
*/
public function importFile( string $googleFileId ) {
public function importFile( string $googleFileId, Google_Client $gClient ) {

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

$service = $this->getService();
$service = $this->getService( $gClient );

if ( !$service ) {
throw new Exception( 'Cannot instantiate service' );
Expand Down
3 changes: 2 additions & 1 deletion lib/Utils/ProjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,8 @@ protected function _insertFiles( $_originalFileNames, $sha1_original, $cachedXli
if ( $this->gdriveSession ) {
$gdriveFileId = $this->gdriveSession->findFileIdByName( $originalFileName );
if ( $gdriveFileId ) {
$this->gdriveSession->createRemoteFile( $fid, $gdriveFileId );
$client = GoogleClientFactory::getGoogleClient( INIT::$HTTPHOST . "/gdrive/oauth/response" );
$this->gdriveSession->createRemoteFile( $fid, $gdriveFileId, $client );
}
}

Expand Down

0 comments on commit 2b33971

Please sign in to comment.