22
22
23
23
use Pydio \Access \Core \AbstractAccessDriver ;
24
24
use Pydio \Access \Core \Model \AJXP_Node ;
25
+ use Pydio \Access \Core \Model \NodesDiff ;
25
26
use Pydio \Access \Core \Model \UserSelection ;
26
27
use Pydio \Core \Exception \PydioException ;
28
+ use Pydio \Core \Http \Response \SerializableResponseStream ;
27
29
use Pydio \Core \Model \ContextInterface ;
28
30
use Pydio \Core \PluginFramework \PluginsService ;
29
31
use Pydio \Core \Services \LocaleService ;
@@ -58,14 +60,12 @@ public function initMeta(ContextInterface $ctx, AbstractAccessDriver $accessDriv
58
60
if ($ store === false ) {
59
61
throw new PydioException ("The 'meta.simple_lock' plugin requires at least one active 'metastore' plugin " );
60
62
}
61
- $ this ->metaStore = $ store ;
62
- $ this ->metaStore ->initMeta ($ ctx , $ accessDriver );
63
63
}
64
64
65
65
/**
66
66
* @param \Psr\Http\Message\ServerRequestInterface $requestInterface
67
67
* @param \Psr\Http\Message\ResponseInterface $responseInterface
68
- * @throws \Exception
68
+ * @throws PydioException
69
69
*/
70
70
public function applyChangeLock (\Psr \Http \Message \ServerRequestInterface $ requestInterface , \Psr \Http \Message \ResponseInterface &$ responseInterface )
71
71
{
@@ -74,29 +74,29 @@ public function applyChangeLock(\Psr\Http\Message\ServerRequestInterface $reques
74
74
$ ctx = $ requestInterface ->getAttribute ("ctx " );
75
75
76
76
if ($ ctx ->getRepository ()->getDriverInstance ($ ctx ) instanceof \Pydio \Access \Driver \StreamProvider \FS \DemoAccessDriver) {
77
- throw new \ Exception ("Write actions are disabled in demo mode! " );
77
+ throw new PydioException ("Write actions are disabled in demo mode! " );
78
78
}
79
79
$ repo = $ ctx ->getRepository ();
80
80
$ user = $ ctx ->getUser ();
81
81
if (!UsersService::usersEnabled () && $ user !=null && !$ user ->canWrite ($ repo ->getId ())) {
82
- throw new \ Exception ("You have no right on this action. " );
82
+ throw new PydioException ("You have no right on this action. " );
83
83
}
84
84
$ selection = UserSelection::fromContext ($ ctx , $ httpVars );
85
85
86
86
$ unlock = (isSet ($ httpVars ["unlock " ])?true :false );
87
+ $ node = $ selection ->getUniqueNode ();
87
88
if ($ unlock ) {
88
- $ this -> metaStore -> removeMetadata ($ selection -> getUniqueNode (), self ::METADATA_LOCK_NAMESPACE , false , AJXP_METADATA_SCOPE_GLOBAL );
89
+ $ node -> removeMetadata (self ::METADATA_LOCK_NAMESPACE , false , AJXP_METADATA_SCOPE_GLOBAL );
89
90
} else {
90
- $ this ->metaStore ->setMetadata (
91
- $ selection ->getUniqueNode (),
91
+ $ node ->setMetadata (
92
92
SimpleLockManager::METADATA_LOCK_NAMESPACE ,
93
93
array ("lock_user " => $ ctx ->getUser ()->getId ()),
94
94
false ,
95
95
AJXP_METADATA_SCOPE_GLOBAL
96
96
);
97
97
}
98
- $ x = new \ Pydio \ Core \ Http \ Response \ SerializableResponseStream ();
99
- $ diff = new \ Pydio \ Access \ Core \ Model \ NodesDiff ();
98
+ $ x = new SerializableResponseStream ();
99
+ $ diff = new NodesDiff ();
100
100
$ diff ->update ($ selection ->getUniqueNode ());
101
101
$ x ->addChunk ($ diff );
102
102
$ responseInterface = $ responseInterface ->withBody ($ x );
@@ -109,8 +109,7 @@ public function processLockMeta($node)
109
109
{
110
110
// Transform meta into overlay_icon
111
111
// $this->logDebug("SHOULD PROCESS METADATA FOR ", $node->getLabel());
112
- $ lock = $ this ->metaStore ->retrieveMetadata (
113
- $ node ,
112
+ $ lock = $ node ->retrieveMetadata (
114
113
SimpleLockManager::METADATA_LOCK_NAMESPACE ,
115
114
false ,
116
115
AJXP_METADATA_SCOPE_GLOBAL );
@@ -138,21 +137,20 @@ public function processLockMeta($node)
138
137
139
138
/**
140
139
* @param \Pydio\Access\Core\Model\AJXP_Node $node
141
- * @throws \Exception
140
+ * @throws PydioException
142
141
*/
143
142
public function checkFileLock ($ node )
144
143
{
145
144
$ this ->logDebug ("SHOULD CHECK LOCK METADATA FOR " , $ node ->getLabel ());
146
- $ lock = $ this ->metaStore ->retrieveMetadata (
147
- $ node ,
145
+ $ lock = $ node ->retrieveMetadata (
148
146
SimpleLockManager::METADATA_LOCK_NAMESPACE ,
149
147
false ,
150
148
AJXP_METADATA_SCOPE_GLOBAL );
151
149
if (is_array ($ lock )
152
150
&& array_key_exists ("lock_user " , $ lock )
153
151
&& $ lock ["lock_user " ] != $ node ->getUserId ()){
154
152
$ mess = LocaleService::getMessages ();
155
- throw new \ Exception ($ mess ["meta.simple_lock.5 " ]);
153
+ throw new PydioException ($ mess ["meta.simple_lock.5 " ]);
156
154
}
157
155
}
158
156
}
0 commit comments