Skip to content

Commit

Permalink
Merge pull request #178 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/4.0.0
  • Loading branch information
LinneyS authored Dec 16, 2019
2 parents 2457828 + f8bbd7d commit e365528
Show file tree
Hide file tree
Showing 18 changed files with 723 additions and 194 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 4.0.0
## Added
- Polish translation
- British (en_GB) file templates

## Changed
- co-editing for federated share
- Nextcloud v14 is no longer supported

## 3.0.2
## Changed
- federated share saving fixed
Expand Down
2 changes: 1 addition & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

namespace OCA\Onlyoffice\AppInfo;

$app = new Application();
$app = \OC::$server->query(Application::class);
3 changes: 2 additions & 1 deletion appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ function() {
$this->appConfig,
$this->crypt,
$c->query("IManager"),
$c->query("Session")
$c->query("Session"),
$c->query("ClientService")
);
});

Expand Down
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>ONLYOFFICE connector enables you to edit Office documents within ONLYOFFICE from the familiar web interface. This will create a new Open in ONLYOFFICE action within the document library for Office documents. This allows multiple users to collaborate in real time and to save back those changes to your file storage.</description>
<licence>agpl</licence>
<author mail="[email protected]" homepage="https://www.onlyoffice.com/">Ascensio System SIA</author>
<version>3.0.2</version>
<version>4.0.0</version>
<namespace>Onlyoffice</namespace>
<types>
<filesystem/>
Expand All @@ -29,7 +29,7 @@
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-nextcloud/master/screenshots/new.png</screenshot>
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-nextcloud/master/screenshots/open.png</screenshot>
<dependencies>
<nextcloud min-version="14" max-version="17"/>
<nextcloud min-version="15" max-version="17"/>
</dependencies>
<settings>
<admin>OCA\Onlyoffice\AdminSettings</admin>
Expand Down
3 changes: 3 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
["name" => "settings#save_common", "url" => "/ajax/settings/common", "verb" => "PUT"],
["name" => "settings#save_watermark", "url" => "/ajax/settings/watermark", "verb" => "PUT"],
["name" => "settings#get_settings", "url" => "/ajax/settings", "verb" => "GET"],
],
"ocs" => [
["name" => "federation#key", "url" => "/api/v1/key", "verb" => "POST"]
]
];
Binary file added assets/en_GB/new.docx
Binary file not shown.
Binary file added assets/en_GB/new.pptx
Binary file not shown.
Binary file added assets/en_GB/new.xlsx
Binary file not shown.
108 changes: 82 additions & 26 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Lock\LockedException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;

Expand Down Expand Up @@ -212,14 +213,13 @@ public function download($doc) {
if ($this->userSession->isLoggedIn()) {
$userId = $this->userSession->getUser()->getUID();
} else {
$userId = $hashData->ownerId;
\OC_Util::tearDownFS();

if (empty($this->userManager->get($userId))) {
$userId = $hashData->userId;
}
$userId = $hashData->userId;
\OC_User::setUserId($userId);

\OC_Util::tearDownFS();
if (!empty($userId)) {
$user = $this->userManager->get($userId);
if (!empty($user)) {
\OC_Util::setupFS($userId);
}
}
Expand Down Expand Up @@ -382,34 +382,40 @@ public function track($doc, $users, $key, $status, $url, $token) {

try {
$shareToken = isset($hashData->shareToken) ? $hashData->shareToken : NULL;
$filePath = null;

\OC_Util::tearDownFS();

// author of the latest changes
$userId = $this->parseUserId($users[0]);
\OC_User::setUserId($userId);

$userId = $users[0];
$user = $this->userManager->get($userId);
if (!empty($user)) {
$this->userSession->setUser($user);
\OC_Util::setupFS($userId);
} else {
if (empty($shareToken)) {
$this->logger->error("Track without access: $fileId status $trackerStatus", array("app" => $this->appName));
return new JSONResponse(["message" => "User and token is empty"], Http::STATUS_BAD_REQUEST);
// author of the callback link
$userId = $hashData->userId;
\OC_User::setUserId($userId);
$this->logger->debug("Track for $userId: $fileId status $trackerStatus", array("app" => $this->appName));

$user = $this->userManager->get($userId);
if (!empty($user)) {
\OC_Util::setupFS($userId);

// path for author of the callback link
$filePath = $hashData->filePath;
}
} else {
$this->logger->debug("Track $fileId by token for $userId", array("app" => $this->appName));
}

$this->logger->debug("Track by anonymous $userId", array("app" => $this->appName));
}

$ownerId = $hashData->ownerId;
if (!empty($this->userManager->get($ownerId))) {
$userId = $ownerId;
}

\OC_Util::tearDownFS();
if (!empty($userId)) {
\OC_Util::setupFS($userId);
}

list ($file, $error) = empty($shareToken) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $shareToken);
list ($file, $error) = empty($shareToken) ? $this->getFile($userId, $fileId, $filePath) : $this->getFileByToken($fileId, $shareToken);

if (isset($error)) {
$this->logger->error("track error$fileId" ." " . json_encode($error->getData()), array("app" => $this->appName));
$this->logger->error("track error $fileId" . " " . json_encode($error->getData()), array("app" => $this->appName));
return $error;
}

Expand All @@ -435,7 +441,10 @@ public function track($doc, $users, $key, $status, $url, $token) {
$newData = $documentService->Request($url);

$this->logger->debug("Track put content " . $file->getPath(), array("app" => $this->appName));
$file->putContent($newData);
$this->retryOperation(function () use ($file, $newData){
return $file->putContent($newData);
});

$result = 0;
} catch (\Exception $e) {
$this->logger->error("Track $trackerStatus error: " . $e->getMessage(), array("app" => $this->appName));
Expand All @@ -459,10 +468,11 @@ public function track($doc, $users, $key, $status, $url, $token) {
*
* @param string $userId - user identifier
* @param integer $fileId - file identifier
* @param string $filePath - file path
*
* @return array
*/
private function getFile($userId, $fileId) {
private function getFile($userId, $fileId, $filePath = NULL) {
if (empty($fileId)) {
return [NULL, new JSONResponse(["message" => $this->trans->t("FileId is empty")], Http::STATUS_BAD_REQUEST)];
}
Expand All @@ -478,8 +488,19 @@ private function getFile($userId, $fileId) {
$this->logger->error("Files not found: $fileId", array("app" => $this->appName));
return [NULL, new JSONResponse(["message" => $this->trans->t("Files not found")], Http::STATUS_NOT_FOUND)];
}

$file = $files[0];

if (count($files) > 1 && !empty($filePath)) {
$filePath = "/" . $userId . "/files" . $filePath;
foreach ($files as $curFile) {
if ($curFile->getPath() === $filePath) {
$file = $curFile;
break;
}
}
}

if (!($file instanceof File)) {
$this->logger->error("File not found: $fileId", array("app" => $this->appName));
return [NULL, new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND)];
Expand Down Expand Up @@ -555,4 +576,39 @@ private function getShare($shareToken) {

return [$share, NULL];
}

/**
* Parse user identifier for current instance
*
* @param string $userId - unique user identifier
*
* @return string
*/
private function parseUserId($uniqueUserId) {
$instanceId = $this->config->GetSystemValue("instanceid", true);
$userId = ltrim($uniqueUserId, $instanceId . "_");
return $userId;
}

/**
* Retry operation if a LockedException occurred
* Other exceptions will still be thrown
*
* @param callable $operation
*
* @throws LockedException
*/
private function retryOperation(callable $operation) {
$i = 0;
while (true) {
try {
return $operation();
} catch (LockedException $e) {
if (++$i === 4) {
throw $e;
}
}
usleep(500000);
}
}
}
Loading

0 comments on commit e365528

Please sign in to comment.