Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 5774112

Browse files
committed
Etherpad: generate a new PadID on copy. Fix #891
1 parent 6da0596 commit 5774112

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

core/src/plugins/editor.etherpad/EtherpadClient.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
*/
2121
namespace Pydio\Editor\Etherpad;
2222

23+
use Psr\Http\Message\ResponseInterface;
24+
use Psr\Http\Message\ServerRequestInterface;
2325
use Pydio\Access\Core\Model\AJXP_Node;
2426
use Pydio\Access\Core\Model\UserSelection;
27+
use Pydio\Core\Exception\PydioException;
2528
use Pydio\Core\Model\ContextInterface;
2629

2730
use Pydio\Core\Controller\Controller;
@@ -43,28 +46,31 @@ class EtherpadClient extends Plugin
4346
public $baseURL = "http://localhost:9001";
4447
public $apiKey = "";
4548

49+
//public function switchAction($actionName, $httpVars, $fileVars, ContextInterface $ctx)
4650
/**
47-
* @param $actionName
48-
* @param $httpVars
49-
* @param $fileVars
50-
* @param ContextInterface $ctx
51+
* @param ServerRequestInterface $requestInterface
52+
* @param ResponseInterface $responseInterface
5153
* @return null
5254
* @throws \Exception
53-
* @throws \Exception
5455
*/
55-
public function switchAction($actionName, $httpVars, $fileVars, ContextInterface $ctx)
56+
public function switchAction(ServerRequestInterface $requestInterface, ResponseInterface &$responseInterface)
5657
{
58+
/** @var ContextInterface $ctx */
59+
$ctx = $requestInterface->getAttribute("ctx");
60+
$actionName = $requestInterface->getAttribute("action");
61+
$httpVars = $requestInterface->getParsedBody();
62+
5763
$this->baseURL = rtrim($this->getContextualOption($ctx, "ETHERPAD_SERVER"), "/");
5864
$this->apiKey = $this->getContextualOption($ctx, "ETHERPAD_APIKEY");
5965

6066
$userSelection = UserSelection::fromContext($ctx, $httpVars);
6167
if ($userSelection->isEmpty()){
62-
throw new \Exception("Empty selection");
68+
throw new PydioException("Empty selection");
6369
}
6470
$selectedNode = $userSelection->getUniqueNode();
6571
$selectedNode->loadNodeInfo();
6672
if(!$selectedNode->isLeaf()){
67-
throw new \Exception("Cannot handle folders, please select a file!");
73+
throw new PydioException("Cannot handle folders, please select a file!");
6874
}
6975
$nodeExtension = strtolower(pathinfo($selectedNode->getPath(), PATHINFO_EXTENSION));
7076

@@ -210,11 +216,15 @@ public function hideExtension(&$ajxpNode){
210216
* @param bool $copy
211217
*/
212218
public function handleNodeChange($fromNode=null, $toNode=null, $copy = false){
213-
if($fromNode == null) return;
214-
if($toNode == null){
219+
if($fromNode === null) return;
220+
if($toNode === null){
215221
$fromNode->removeMetadata("etherpad", AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_GLOBAL, false);
216222
}else if(!$copy){
217223
$toNode->copyOrMoveMetadataFromNode($fromNode, "etherpad", "move", AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_GLOBAL, false);
224+
}else if($copy && $toNode->getExtension() === 'pad'){
225+
$padID = StringHelper::generateRandomString();
226+
$toNode->setMetadata("etherpad", array("pad_id" => $padID), AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_GLOBAL, false);
227+
file_put_contents($toNode->getUrl(), $padID);
218228
}
219229
}
220230

0 commit comments

Comments
 (0)