-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POC] Feature/introduce amd to MOVE #31851
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
643a450
composer require hhxsv5/php-sse
DeepDiver1975 18db44b
Introduce AMD style MOVE operation
DeepDiver1975 2e9e1fa
Add tests for SSE plugin
DeepDiver1975 6c3d738
Add Capability
DeepDiver1975 cef6bdc
Use async in files app
DeepDiver1975 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace OCA\dav\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Types\Type; | ||
use OCP\Migration\ISchemaMigration; | ||
|
||
class Version20180622095921 implements ISchemaMigration { | ||
public function changeSchema(Schema $schema, array $options) { | ||
$prefix = $options['tablePrefix']; | ||
if ($schema->hasTable("${prefix}dav_job_status")) { | ||
return; | ||
} | ||
$table = $schema->createTable("${prefix}dav_job_status"); | ||
$table->addColumn('id', Type::BIGINT, [ | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
'length' => 20, | ||
]); | ||
$table->addColumn('uuid', Type::GUID, [ | ||
'notnull' => true, | ||
]); | ||
$table->addColumn('user_id', Type::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('status_info', Type::STRING, [ | ||
'notnull' => true, | ||
'length' => 4000, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
$table->addUniqueIndex(['uuid']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?php | ||
/** | ||
* @author Thomas Müller <thomas.mueller@tmit.eu> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\DAV; | ||
|
||
use OCA\DAV\JobStatus\Entity\JobStatus; | ||
use OCA\DAV\JobStatus\Entity\JobStatusMapper; | ||
use OCP\ILogger; | ||
use OCP\IURLGenerator; | ||
use OCP\IUserSession; | ||
use OCP\Shutdown\IShutdownManager; | ||
use Sabre\DAV\Exception; | ||
use Sabre\DAV\Server; | ||
use Sabre\DAV\ServerPlugin; | ||
use Sabre\DAV\UUIDUtil; | ||
use Sabre\HTTP\RequestInterface; | ||
use Sabre\HTTP\Response; | ||
use Sabre\HTTP\ResponseInterface; | ||
|
||
/** | ||
* Class LazyOpsPlugin | ||
* | ||
* @package OCA\DAV\DAV | ||
*/ | ||
class LazyOpsPlugin extends ServerPlugin { | ||
|
||
/** @var Server */ | ||
private $server; | ||
/** @var string */ | ||
private $jobId; | ||
/** @var JobStatus */ | ||
private $entity; | ||
/** @var IUserSession */ | ||
private $userSession; | ||
/** @var IURLGenerator */ | ||
private $urlGenerator; | ||
/** @var IShutdownManager */ | ||
private $shutdownManager; | ||
/** @var ILogger */ | ||
private $logger; | ||
/** @var JobStatusMapper */ | ||
private $mapper; | ||
|
||
public function __construct(IUserSession $userSession, | ||
IURLGenerator $urlGenerator, | ||
IShutdownManager $shutdownManager, | ||
JobStatusMapper $jobStatusMapper, | ||
ILogger $logger) { | ||
$this->userSession = $userSession; | ||
$this->urlGenerator = $urlGenerator; | ||
$this->shutdownManager = $shutdownManager; | ||
$this->logger = $logger; | ||
$this->mapper = $jobStatusMapper; | ||
} | ||
|
||
/** | ||
* @param Server $server | ||
*/ | ||
public function initialize(Server $server) { | ||
$this->server = $server; | ||
$server->on('method:MOVE', [$this, 'httpMove'], 90); | ||
} | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param ResponseInterface $response | ||
* @return bool | ||
* @throws Exception\NotAuthenticated | ||
*/ | ||
public function httpMove(RequestInterface $request, ResponseInterface $response) { | ||
if (!$request->getHeader('OC-LazyOps')) { | ||
return true; | ||
} | ||
|
||
$this->jobId = UUIDUtil::getUUID(); | ||
$this->setJobStatus([ | ||
'status' => 'init' | ||
]); | ||
$userId = $this->getUserId(); | ||
$location = $this->urlGenerator | ||
->linkTo('', 'remote.php') . "/dav/job-status/{$userId}/{$this->jobId}"; | ||
|
||
$response->setStatus(202); | ||
$response->setHeader('Connection', 'close'); | ||
$response->setHeader('OC-JobStatus-Location', $location); | ||
|
||
$this->shutdownManager->register(function () use ($request, $response) { | ||
return $this->afterResponse($request, $response); | ||
}, IShutdownManager::HIGH); | ||
|
||
return false; | ||
} | ||
|
||
public function afterResponse(RequestInterface $request, ResponseInterface $response) { | ||
if (!$request->getHeader('OC-LazyOps')) { | ||
return true; | ||
} | ||
|
||
\flush(); | ||
$request->removeHeader('OC-LazyOps'); | ||
$responseDummy = new Response(); | ||
try { | ||
$this->setJobStatus([ | ||
'status' => 'started' | ||
]); | ||
$this->server->emit('method:MOVE', [$request, $responseDummy]); | ||
|
||
$this->setJobStatus([ | ||
'status' => 'finished', | ||
'fileId' => $response->getHeader('OC-FileId'), | ||
'ETag' => $response->getHeader('ETag') | ||
]); | ||
} catch (\Exception $ex) { | ||
$this->logger->logException($ex); | ||
|
||
$this->setJobStatus([ | ||
'status' => 'error', | ||
'errorCode' => $ex instanceof Exception ? $ex->getHTTPCode() : 500, | ||
'errorMessage' => $ex->getMessage() | ||
]); | ||
} | ||
return false; | ||
} | ||
|
||
private function setJobStatus(array $status) { | ||
if ($this->entity === null) { | ||
$userId = $this->getUserId(); | ||
|
||
$this->entity = new JobStatus(); | ||
$this->entity->setStatusInfo(\json_encode($status)); | ||
$this->entity->setUserId($userId); | ||
$this->entity->setUuid($this->jobId); | ||
$this->mapper->insert($this->entity); | ||
} else { | ||
$this->entity->setStatusInfo(\json_encode($status)); | ||
$this->mapper->update($this->entity); | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws Exception\NotAuthenticated | ||
*/ | ||
private function getUserId() { | ||
$user = $this->userSession->getUser(); | ||
if ($user === null) { | ||
throw new Exception\NotAuthenticated(); | ||
} | ||
return $user->getUID(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* @author Thomas Müller <thomas.mueller@tmit.eu> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\JobStatus\Entity; | ||
|
||
use OCP\AppFramework\Db\Entity; | ||
|
||
/** | ||
* Class JobStatus | ||
* | ||
* @method string getUuid() | ||
* @method void setUuid(string $uuid) | ||
* @method string getUserId() | ||
* @method void setUserId(string $userId) | ||
* @method string getStatusInfo() | ||
* @method void setStatusInfo(string $statusInfo) | ||
* | ||
* @package OCA\DAV\JobStatus\Entity | ||
*/ | ||
class JobStatus extends Entity { | ||
protected $uuid; | ||
protected $userId; | ||
protected $statusInfo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* @author Thomas Müller <thomas.mueller@tmit.eu> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\JobStatus\Entity; | ||
|
||
use OCP\AppFramework\Db\Mapper; | ||
use OCP\IDBConnection; | ||
|
||
class JobStatusMapper extends Mapper { | ||
public function __construct(IDBConnection $db) { | ||
parent::__construct($db, 'dav_job_status'); | ||
} | ||
|
||
/** | ||
* @param string $userId | ||
* @param string $jobId | ||
* @return JobStatus | ||
* @throws \OCP\AppFramework\Db\DoesNotExistException | ||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException | ||
*/ | ||
public function findByUserIdAndJobId($userId, $jobId) { | ||
$query = $this->db->getQueryBuilder(); | ||
$query->select('*') | ||
->from($this->getTableName()) | ||
->where($query->expr()->eq('uuid', $query->createNamedParameter($jobId))) | ||
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); | ||
return $this->mapRowToEntity($this->findOneQuery($query->getSQL(), $query->getParameters())); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we can store the final file name in there we could solve a lot of problems, like the fact that encryption relies on the part file name and uses magic extraction to find the final file name... here it could just read from the upload queue
speaking of which... does this work with user-key encryption ? cron doesn't have the user's private key so cannot encrypt...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the execution is not done in cron - but in the original client request.
The difference is that we defer the execution to PHP's shutdown handler which is called after the response is sent back to the client