Code style fixes and cleanup

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-11-25 14:09:38 +01:00
parent bc36cc808f
commit 9a2694fcb0
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
8 changed files with 75 additions and 52 deletions

View File

@ -7,7 +7,7 @@ use OCP\DirectEditing\IManager;
class CleanupDirectEditingTokens extends TimedJob {
const INTERVAL_MINUTES = 15 * 60;
private const INTERVAL_MINUTES = 15 * 60;
/**
* @var IManager

View File

@ -30,6 +30,8 @@ use OCP\Capabilities\ICapability;
use OCP\DirectEditing\ACreateEmpty;
use OCP\DirectEditing\ACreateFromTemplate;
use OCP\DirectEditing\IEditor;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
/**
@ -38,17 +40,25 @@ use OCP\IConfig;
* @package OCA\Files
*/
class Capabilities implements ICapability {
/** @var IConfig */
protected $config;
/** @var Manager */
protected $directEditingManager;
/** @var IEventDispatcher */
protected $eventDispatcher;
/**
* Capabilities constructor.
*
* @param IConfig $config
*/
public function __construct(IConfig $config, Manager $manager) {
public function __construct(IConfig $config, Manager $manager, IEventDispatcher $eventDispatcher) {
$this->config = $config;
$this->directEditingManager = $manager;
$this->eventDispatcher = $eventDispatcher;
}
/**
@ -66,7 +76,9 @@ class Capabilities implements ICapability {
];
}
private function getDirectEditingCapabilitites() {
private function getDirectEditingCapabilitites(): array {
$this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
$capabilities = [
'editors' => [],
'creators' => []

View File

@ -66,7 +66,7 @@ class DirectEditingController extends OCSController {
* @NoAdminRequired
*/
public function create(string $path, string $editorId, string $creatorId, string $templateId = null): DataResponse {
$this->eventDispatcher->dispatch(RegisterDirectEditorEvent::class, new RegisterDirectEditorEvent($this->directEditingManager));
$this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
try {
$token = $this->directEditingManager->create($path, $editorId, $creatorId, $templateId);
@ -83,7 +83,7 @@ class DirectEditingController extends OCSController {
* @NoAdminRequired
*/
public function open(int $fileId, string $editorId = null): DataResponse {
$this->eventDispatcher->dispatch(RegisterDirectEditorEvent::class, new RegisterDirectEditorEvent($this->directEditingManager));
$this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
try {
$token = $this->directEditingManager->open($fileId, $editorId);
@ -102,7 +102,7 @@ class DirectEditingController extends OCSController {
* @NoAdminRequired
*/
public function templates(string $editorId, string $creatorId): DataResponse {
$this->eventDispatcher->dispatch(RegisterDirectEditorEvent::class, new RegisterDirectEditorEvent($this->directEditingManager));
$this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
try {
return new DataResponse($this->directEditingManager->getTemplates($editorId, $creatorId));

View File

@ -50,44 +50,42 @@ class Version18000Date20191014105105 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('direct_edit')) {
$table = $schema->createTable('direct_edit');
$table = $schema->createTable('direct_edit');
$table->addColumn('id', Type::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('editor_id', Type::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('token', Type::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('file_id', Type::BIGINT, [
'notnull' => true,
]);
$table->addColumn('user_id', Type::STRING, [
'notnull' => false,
'length' => 64,
]);
$table->addColumn('share_id', Type::BIGINT, [
'notnull' => false
]);
$table->addColumn('timestamp', Type::BIGINT, [
'notnull' => true,
'length' => 20,
'unsigned' => true,
]);
$table->addColumn('accessed', Type::BOOLEAN, [
'notnull' => true,
'default' => false
]);
$table->addColumn('id', Type::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('editor_id', Type::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('token', Type::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('file_id', Type::BIGINT, [
'notnull' => true,
]);
$table->addColumn('user_id', Type::STRING, [
'notnull' => false,
'length' => 64,
]);
$table->addColumn('share_id', Type::BIGINT, [
'notnull' => false
]);
$table->addColumn('timestamp', Type::BIGINT, [
'notnull' => true,
'length' => 20,
'unsigned' => true,
]);
$table->addColumn('accessed', Type::BOOLEAN, [
'notnull' => true,
'default' => false
]);
$table->setPrimaryKey(['id']);
$table->addIndex(['token']);
}
$table->setPrimaryKey(['id']);
$table->addIndex(['token']);
return $schema;
}

View File

@ -64,15 +64,12 @@ class Manager implements IManager {
ISecureRandom $random,
IDBConnection $connection,
IUserSession $userSession,
IRootFolder $rootFolder,
IEventDispatcher $eventDispatcher
IRootFolder $rootFolder
) {
$this->random = $random;
$this->connection = $connection;
$this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null;
$this->rootFolder = $rootFolder;
$eventDispatcher->dispatch(RegisterDirectEditorEvent::class, new RegisterDirectEditorEvent($this));
}
public function registerDirectEditor(IEditor $directEditor): void {

View File

@ -32,7 +32,7 @@ abstract class ACreateFromTemplate extends ACreateEmpty {
* List of available templates for the create from template action
*
* @since 18.0.0
* @return array
* @return ATemplate[]
*/
abstract public function getTemplates(): array;

View File

@ -56,7 +56,7 @@ interface IEditor {
* A list of mimetypes that should open the editor by default
*
* @since 18.0.0
* @return array
* @return string[]
*/
public function getMimetypes(): array;
@ -64,7 +64,7 @@ interface IEditor {
* A list of mimetypes that can be opened in the editor optionally
*
* @since 18.0.0
* @return array
* @return string[]
*/
public function getMimetypesOptional(): array;
@ -72,7 +72,7 @@ interface IEditor {
* Return a list of file creation options to be presented to the user
*
* @since 18.0.0
* @return array of ICreateFromTemplate|ICreateEmpty
* @return ACreateFromTemplate[]|ACreateEmpty[]
*/
public function getCreators(): array;

View File

@ -7,7 +7,6 @@ use OC\Files\Node\File;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\DirectEditing\ACreateEmpty;
use OCP\DirectEditing\IEditor;
use OCP\DirectEditing\IToken;
@ -16,6 +15,7 @@ use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class CreateEmpty extends ACreateEmpty {
@ -82,9 +82,25 @@ class ManagerTest extends TestCase {
*/
private $editor;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
* @var MockObject|ISecureRandom
*/
private $random;
/**
* @var IDBConnection
*/
private $connection;
/**
* @var MockObject|IUserSession
*/
private $userSession;
/**
* @var MockObject|IRootFolder
*/
private $rootFolder;
/**
* @var MockObject|Folder
*/
private $userFolder;
protected function setUp() {
parent::setUp();