1 | <?php |
||
43 | class LazyOpsPlugin extends ServerPlugin { |
||
44 | |||
45 | /** @var Server */ |
||
46 | private $server; |
||
47 | /** @var string */ |
||
48 | private $jobId; |
||
49 | /** @var JobStatus */ |
||
50 | private $entity; |
||
51 | /** @var IUserSession */ |
||
52 | private $userSession; |
||
53 | /** @var IURLGenerator */ |
||
54 | private $urlGenerator; |
||
55 | /** @var IShutdownManager */ |
||
56 | private $shutdownManager; |
||
57 | /** @var ILogger */ |
||
58 | private $logger; |
||
59 | /** @var JobStatusMapper */ |
||
60 | private $mapper; |
||
61 | |||
62 | public function __construct(IUserSession $userSession, |
||
73 | |||
74 | /** |
||
75 | * @param Server $server |
||
76 | */ |
||
77 | public function initialize(Server $server) { |
||
81 | |||
82 | /** |
||
83 | * @param RequestInterface $request |
||
84 | * @param ResponseInterface $response |
||
85 | * @return bool |
||
86 | * @throws Exception\NotAuthenticated |
||
87 | */ |
||
88 | public function httpMove(RequestInterface $request, ResponseInterface $response) { |
||
111 | |||
112 | public function afterResponse(RequestInterface $request, ResponseInterface $response) { |
||
113 | if (!$request->getHeader('OC-LazyOps')) { |
||
114 | return true; |
||
115 | } |
||
116 | |||
117 | \flush(); |
||
118 | $request->removeHeader('OC-LazyOps'); |
||
119 | $responseDummy = new Response(); |
||
120 | try { |
||
121 | $this->setJobStatus([ |
||
122 | 'status' => 'started' |
||
123 | ]); |
||
124 | $this->server->emit('method:MOVE', [$request, $responseDummy]); |
||
125 | |||
126 | $this->setJobStatus([ |
||
127 | 'status' => 'finished', |
||
128 | 'fileId' => $response->getHeader('OC-FileId'), |
||
129 | 'ETag' => $response->getHeader('ETag') |
||
130 | ]); |
||
131 | } catch (\Exception $ex) { |
||
132 | $this->logger->logException($ex); |
||
133 | |||
134 | $this->setJobStatus([ |
||
135 | 'status' => 'error', |
||
136 | 'errorCode' => $ex instanceof Exception ? $ex->getHTTPCode() : 500, |
||
137 | 'errorMessage' => $ex->getMessage() |
||
138 | ]); |
||
139 | } |
||
140 | return false; |
||
141 | } |
||
142 | |||
143 | private function setJobStatus(array $status) { |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | * @throws Exception\NotAuthenticated |
||
161 | */ |
||
162 | private function getUserId() { |
||
169 | } |
||
170 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: