-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Luka Trovic <[email protected]>
- Loading branch information
1 parent
4b6a34a
commit b76a132
Showing
14 changed files
with
365 additions
and
0 deletions.
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
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Whiteboard\Events; | ||
|
||
use OCA\Whiteboard\Model\User; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\Files\File; | ||
|
||
abstract class AbstractWhiteboardEvent extends Event { | ||
public function __construct( | ||
private File $file, | ||
private User $user, | ||
private array $data, | ||
) { | ||
} | ||
|
||
public function getFile(): File { | ||
return $this->file; | ||
} | ||
|
||
public function getUser(): User { | ||
return $this->user; | ||
} | ||
|
||
public function getData(): array { | ||
return $this->data; | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Whiteboard\Events; | ||
|
||
class WhiteboardOpenedEvent extends AbstractWhiteboardEvent { | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Whiteboard\Events; | ||
|
||
class WhiteboardUpdatedEvent extends AbstractWhiteboardEvent { | ||
} |
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Whiteboard\Listener; | ||
|
||
use OCA\Whiteboard\Service\EventsService; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Events\Node\NodeCreatedEvent; | ||
use OCP\IUserSession; | ||
|
||
/** @template-implements IEventListener<NodeCreatedEvent|Event> */ | ||
/** | ||
* @psalm-suppress UndefinedClass | ||
* @psalm-suppress MissingTemplateParam | ||
*/ | ||
final class FileCreatedListener implements IEventListener { | ||
public function __construct( | ||
protected EventsService $eventsService, | ||
protected IUserSession $userSession, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof NodeCreatedEvent)) { | ||
return; | ||
} | ||
|
||
$node = $event->getNode(); | ||
|
||
if ($node->getExtension() !== 'whiteboard') { | ||
return; | ||
} | ||
|
||
$currentUser = $this->userSession->getUser(); | ||
|
||
$this->eventsService->insertEvent([ | ||
'user' => $currentUser ? $currentUser->getUID() : $node->getOwner()->getUID(), | ||
'type' => 'created', | ||
'share_token' => '', | ||
'fileid' => $node->getId(), | ||
'elements' => '', | ||
'size' => 0, | ||
'timestamp' => time(), | ||
]); | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Whiteboard\Listener; | ||
|
||
use OCA\Whiteboard\Events\WhiteboardOpenedEvent; | ||
use OCA\Whiteboard\Model\PublicSharingUser; | ||
use OCA\Whiteboard\Service\EventsService; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Events\Node\NodeCreatedEvent; | ||
|
||
/** @template-implements IEventListener<NodeCreatedEvent|Event> */ | ||
/** | ||
* @psalm-suppress UndefinedClass | ||
* @psalm-suppress MissingTemplateParam | ||
*/ | ||
final class WhiteboardOpenedListener implements IEventListener { | ||
public function __construct( | ||
protected EventsService $eventsService, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof WhiteboardOpenedEvent)) { | ||
return; | ||
} | ||
|
||
$user = $event->getUser(); | ||
$file = $event->getFile(); | ||
$data = $event->getData(); | ||
|
||
$this->eventsService->insertEvent([ | ||
'user' => $user->getUID(), | ||
'type' => 'opened', | ||
'share_token' => $user instanceof PublicSharingUser ? $user->getPublicSharingToken() : '', | ||
'fileid' => $file->getId(), | ||
'elements' => $data['elements'] ?? '', | ||
'size' => $file->getSize(), | ||
'timestamp' => time(), | ||
]); | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Whiteboard\Listener; | ||
|
||
use OCA\Whiteboard\Events\WhiteboardUpdatedEvent; | ||
use OCA\Whiteboard\Model\PublicSharingUser; | ||
use OCA\Whiteboard\Service\EventsService; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Events\Node\NodeCreatedEvent; | ||
|
||
/** @template-implements IEventListener<NodeCreatedEvent|Event> */ | ||
/** | ||
* @psalm-suppress UndefinedClass | ||
* @psalm-suppress MissingTemplateParam | ||
*/ | ||
final class WhiteboardUpdatedListener implements IEventListener { | ||
public function __construct( | ||
protected EventsService $eventsService, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof WhiteboardUpdatedEvent)) { | ||
return; | ||
} | ||
|
||
$user = $event->getUser(); | ||
$file = $event->getFile(); | ||
$data = $event->getData(); | ||
|
||
$this->eventsService->insertEvent([ | ||
'user' => $user->getUID(), | ||
'type' => 'opened', | ||
'share_token' => $user instanceof PublicSharingUser ? $user->getPublicSharingToken() : '', | ||
'fileid' => $file->getId(), | ||
'elements' => $data['elements'] ?? '', | ||
'size' => $file->getSize(), | ||
'timestamp' => time(), | ||
]); | ||
} | ||
} |
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,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version1000Date20241213132620 extends SimpleMigrationStep { | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
* @param array $options | ||
*/ | ||
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
} | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
* @param array $options | ||
* @return null|ISchemaWrapper | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
if (!$schema->hasTable('whiteboard_events')) { | ||
$table = $schema->createTable('whiteboard_events'); | ||
$table->addColumn('id', Types::BIGINT, [ | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
'length' => 20, | ||
]); | ||
$table->addColumn('user', Types::STRING, [ | ||
'notnull' => false, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('type', Types::STRING, [ | ||
'notnull' => false, | ||
'length' => 255, | ||
]); | ||
$table->addColumn('share_token', Types::STRING, [ | ||
'notnull' => false, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('fileid', Types::BIGINT, [ | ||
'notnull' => false, | ||
'length' => 20, | ||
]); | ||
$table->addColumn('elements', Types::JSON, [ | ||
'notnull' => false, | ||
]); | ||
$table->addColumn('size', Types::INTEGER, [ | ||
'notnull' => false, | ||
'length' => 11, | ||
'default' => 0, | ||
]); | ||
$table->addColumn('timestamp', Types::INTEGER, [ | ||
'notnull' => true, | ||
'length' => 11, | ||
'default' => 0, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
$table->addIndex(['user'], 'user_index'); | ||
$table->addIndex(['fileid'], 'fileid_index'); | ||
} | ||
|
||
return $schema; | ||
} | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
* @param array $options | ||
*/ | ||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
} | ||
} |
Oops, something went wrong.