Commit 4704b113 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #10001 TIME 3:30 fix create templates with office sharepoint + increase...

FEAT #10001 TIME 3:30 fix create templates with office sharepoint + increase delay to delete file on sharepoint
parent c1f09192
......@@ -57,70 +57,76 @@ class Office365SharepointController
return $response->withStatus(400)->withJson(['errors' => 'Body data is not a string']);
}
$document = CollaboraOnlineController::getDocument([
'id' => $body['resId'],
'type' => $body['type'],
'format' => $body['format'],
'path' => $body['path']
]);
if (!empty($document['errors'])) {
return $response->withStatus($document['code'])->withJson(['errors' => $document['errors']]);
}
if (empty($body['encodedContent'])) {
$document = CollaboraOnlineController::getDocument([
'id' => $body['resId'],
'type' => $body['type'],
'format' => $body['format'],
'path' => $body['path']
]);
if (!empty($document['docserver_id'])) {
$docserver = DocserverModel::getByDocserverId(['docserverId' => $document['docserver_id'], 'select' => ['path_template', 'docserver_type_id']]);
if (empty($docserver['path_template']) || !file_exists($docserver['path_template'])) {
return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']);
if (!empty($document['errors'])) {
return $response->withStatus($document['code'])->withJson(['errors' => $document['errors']]);
}
} else {
$docserver['path_template'] = '';
}
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $document['path']) . $document['filename'];
if (!file_exists($pathToDocument)) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']);
}
if ($body['type'] == 'resourceModification' || $body['type'] == 'attachmentModification') {
$docserverType = DocserverTypeModel::getById(['id' => $docserver['docserver_type_id'], 'select' => ['fingerprint_mode']]);
$fingerprint = StoreController::getFingerPrint(['filePath' => $pathToDocument, 'mode' => $docserverType['fingerprint_mode']]);
if (empty($document['fingerprint']) && $body['type'] == 'resourceModification') {
ResModel::update(['set' => ['fingerprint' => $fingerprint], 'where' => ['res_id = ?'], 'data' => [$args['id']]]);
$document['fingerprint'] = $fingerprint;
} elseif (empty($document['fingerprint']) && $body['type'] == 'attachmentModification') {
AttachmentModel::update(['set' => ['fingerprint' => $fingerprint], 'where' => ['res_id = ?'], 'data' => [$args['id']]]);
$document['fingerprint'] = $fingerprint;
if (!empty($document['docserver_id'])) {
$docserver = DocserverModel::getByDocserverId(['docserverId' => $document['docserver_id'], 'select' => ['path_template', 'docserver_type_id']]);
if (empty($docserver['path_template']) || !file_exists($docserver['path_template'])) {
return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']);
}
} else {
$docserver['path_template'] = '';
}
if ($document['fingerprint'] != $fingerprint) {
return $response->withStatus(400)->withJson(['errors' => 'Fingerprints do not match']);
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $document['path']) . $document['filename'];
if (!file_exists($pathToDocument)) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']);
}
}
if ($body['type'] == 'resourceCreation' || $body['type'] == 'attachmentCreation') {
$dataToMerge = ['userId' => $GLOBALS['id']];
if (!empty($tokenCheckResult['data']) && is_array($tokenCheckResult['data'])) {
$dataToMerge = array_merge($dataToMerge, $tokenCheckResult['data']);
if ($body['type'] == 'resourceModification' || $body['type'] == 'attachmentModification') {
$docserverType = DocserverTypeModel::getById(['id' => $docserver['docserver_type_id'], 'select' => ['fingerprint_mode']]);
$fingerprint = StoreController::getFingerPrint(['filePath' => $pathToDocument, 'mode' => $docserverType['fingerprint_mode']]);
if (empty($document['fingerprint']) && $body['type'] == 'resourceModification') {
ResModel::update(['set' => ['fingerprint' => $fingerprint], 'where' => ['res_id = ?'], 'data' => [$args['id']]]);
$document['fingerprint'] = $fingerprint;
} elseif (empty($document['fingerprint']) && $body['type'] == 'attachmentModification') {
AttachmentModel::update(['set' => ['fingerprint' => $fingerprint], 'where' => ['res_id = ?'], 'data' => [$args['id']]]);
$document['fingerprint'] = $fingerprint;
}
if ($document['fingerprint'] != $fingerprint) {
return $response->withStatus(400)->withJson(['errors' => 'Fingerprints do not match']);
}
}
$mergedDocument = MergeController::mergeDocument([
'path' => $pathToDocument,
'data' => $dataToMerge
]);
$content = $mergedDocument['encodedDocument'];
} else {
$fileContent = file_get_contents($pathToDocument);
if ($fileContent === false) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found']);
if ($body['type'] == 'resourceCreation' || $body['type'] == 'attachmentCreation') {
$dataToMerge = ['userId' => $GLOBALS['id']];
if (!empty($tokenCheckResult['data']) && is_array($tokenCheckResult['data'])) {
$dataToMerge = array_merge($dataToMerge, $tokenCheckResult['data']);
}
$mergedDocument = MergeController::mergeDocument([
'path' => $pathToDocument,
'data' => $dataToMerge
]);
$content = $mergedDocument['encodedDocument'];
} else {
$fileContent = file_get_contents($pathToDocument);
if ($fileContent === false) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found']);
}
$content = base64_encode($fileContent);
}
$content = base64_encode($fileContent);
$pathInfo = pathinfo($pathToDocument);
} else {
$content = $body['encodedContent'];
$pathInfo['extension'] = $body['format'];
}
$fileContent = base64_decode($content);
$fileSize = strlen($fileContent);
$pathInfo = pathinfo($pathToDocument);
$filename = "maarch_{$GLOBALS['login']}_" . rand() . ".{$pathInfo['extension']}";
$accessToken = Office365SharepointController::getAuthenticationToken(['configuration' => $configuration]);
......@@ -143,12 +149,13 @@ class Office365SharepointController
$id = $sendResult['response']['id'];
$body = json_encode(['item' => ['@microsoft.graph.conflictBehavior' => 'replace']]);
$sendResult = CurlModel::exec([
'url' => 'https://graph.microsoft.com/v1.0/sites/' . $configuration['siteId'] . '/drive/items/' . $id . '/createUploadSession',
'bearerAuth' => ['token' => $accessToken],
'headers' => ['Content-Type: application/json'],
'headers' => ['Content-Type: application/json', 'Content-Length: ' . strlen($body)],
'method' => 'POST',
'body' => ['item' => ['@microsoft.graph.conflictBehavior' => 'replace']]
'body' => $body
]);
if ($sendResult['code'] != 200) {
......
......@@ -67,6 +67,16 @@ export class Office365SharepointViewerComponent implements OnInit, AfterViewInit
this.key = this.generateUniqueId(10);
if (this.canLaunchOffice365Sharepoint()) {
this.params.objectPath = undefined;
if (typeof this.params.objectId === 'string' && (this.params.objectType === 'templateModification' || this.params.objectType === 'templateCreation')) {
this.params.objectPath = this.params.objectId;
this.params.objectId = this.key;
} else if (typeof this.params.objectId === 'string' && this.params.objectType === 'encodedResource') {
this.params.content = this.params.objectId;
this.params.objectId = this.key;
this.params.objectType = 'templateEncoded';
}
await this.sendDocument();
this.loading = false;
}
......@@ -107,7 +117,7 @@ export class Office365SharepointViewerComponent implements OnInit, AfterViewInit
this.eventAction.next(this.file);
setTimeout(() => {
this.deleteDocument();
}, 1000);
}, 10000);
resolve(true);
}),
catchError((err) => {
......@@ -141,10 +151,12 @@ export class Office365SharepointViewerComponent implements OnInit, AfterViewInit
format: this.file.format,
path: this.params.objectPath,
data: this.params.dataToMerge,
encodedContent: this.params.content
}).pipe(
tap((data: any) => {
this.documentId = data.documentId;
this.documentWebUrl = data.webUrl;
this.openDocument();
resolve(true);
}),
catchError((err) => {
......@@ -158,16 +170,18 @@ export class Office365SharepointViewerComponent implements OnInit, AfterViewInit
deleteDocument() {
return new Promise((resolve) => {
this.http.delete('../rest/office365/' + this.documentId).pipe(
tap(() => {
resolve(true);
}),
catchError((err) => {
this.notify.handleErrors(err);
this.triggerCloseEditor.emit();
return of(false);
}),
).subscribe();
setTimeout(() => {
this.http.delete('../rest/office365/' + this.documentId).pipe(
tap(() => {
resolve(true);
}),
catchError((err) => {
this.notify.handleErrors(err);
this.triggerCloseEditor.emit();
return of(false);
}),
).subscribe();
}, 10000);
});
}
......
......@@ -2496,7 +2496,7 @@
"clientId": "Client ID",
"clientSecret": "Client Secret",
"siteUrl": "URL de l'espace Sharepoint Online",
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> est la suite bureautique en ligne de Microsoft. L'édtion se fait via Sharepoint Online.",
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> est la suite bureautique en ligne de Microsoft. L'édition se fait via Sharepoint Online.",
"addOtpUser": "Ajouter un utilisateur OTP",
"securityMode": "Mode d'envoi du code de sécurité",
"sms": "SMS",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment