20
20
*/
21
21
namespace Pydio \Editor \Etherpad ;
22
22
23
+ use Psr \Http \Message \ResponseInterface ;
24
+ use Psr \Http \Message \ServerRequestInterface ;
23
25
use Pydio \Access \Core \Model \AJXP_Node ;
24
26
use Pydio \Access \Core \Model \UserSelection ;
27
+ use Pydio \Core \Exception \PydioException ;
25
28
use Pydio \Core \Model \ContextInterface ;
26
29
27
30
use Pydio \Core \Controller \Controller ;
@@ -43,28 +46,31 @@ class EtherpadClient extends Plugin
43
46
public $ baseURL = "http://localhost:9001 " ;
44
47
public $ apiKey = "" ;
45
48
49
+ //public function switchAction($actionName, $httpVars, $fileVars, ContextInterface $ctx)
46
50
/**
47
- * @param $actionName
48
- * @param $httpVars
49
- * @param $fileVars
50
- * @param ContextInterface $ctx
51
+ * @param ServerRequestInterface $requestInterface
52
+ * @param ResponseInterface $responseInterface
51
53
* @return null
52
54
* @throws \Exception
53
- * @throws \Exception
54
55
*/
55
- public function switchAction ($ actionName , $ httpVars , $ fileVars , ContextInterface $ ctx )
56
+ public function switchAction (ServerRequestInterface $ requestInterface , ResponseInterface & $ responseInterface )
56
57
{
58
+ /** @var ContextInterface $ctx */
59
+ $ ctx = $ requestInterface ->getAttribute ("ctx " );
60
+ $ actionName = $ requestInterface ->getAttribute ("action " );
61
+ $ httpVars = $ requestInterface ->getParsedBody ();
62
+
57
63
$ this ->baseURL = rtrim ($ this ->getContextualOption ($ ctx , "ETHERPAD_SERVER " ), "/ " );
58
64
$ this ->apiKey = $ this ->getContextualOption ($ ctx , "ETHERPAD_APIKEY " );
59
65
60
66
$ userSelection = UserSelection::fromContext ($ ctx , $ httpVars );
61
67
if ($ userSelection ->isEmpty ()){
62
- throw new \ Exception ("Empty selection " );
68
+ throw new PydioException ("Empty selection " );
63
69
}
64
70
$ selectedNode = $ userSelection ->getUniqueNode ();
65
71
$ selectedNode ->loadNodeInfo ();
66
72
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! " );
68
74
}
69
75
$ nodeExtension = strtolower (pathinfo ($ selectedNode ->getPath (), PATHINFO_EXTENSION ));
70
76
@@ -210,11 +216,15 @@ public function hideExtension(&$ajxpNode){
210
216
* @param bool $copy
211
217
*/
212
218
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 ){
215
221
$ fromNode ->removeMetadata ("etherpad " , AJXP_METADATA_ALLUSERS , AJXP_METADATA_SCOPE_GLOBAL , false );
216
222
}else if (!$ copy ){
217
223
$ 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 );
218
228
}
219
229
}
220
230
0 commit comments