Skip to content

Commit fe7ee4c

Browse files
committed
fixup! feat(snowflake): extend Entity class to support snowflakes
1 parent 76703af commit fe7ee4c

5 files changed

Lines changed: 8 additions & 33 deletions

File tree

apps/files_sharing/lib/AppInfo/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ public function registerEventsScripts(IEventDispatcher $dispatcher): void {
142142
// notifications api to accept incoming user shares
143143
$dispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event): void {
144144
/** @var Listener $listener */
145-
$listener = $this->getContainer()->query(Listener::class);
145+
$listener = $this->getContainer()->get(Listener::class);
146146
$listener->shareNotification($event);
147147
});
148148
$dispatcher->addListener(IGroup::class . '::postAddUser', function ($event): void {
149149
if (!$event instanceof OldGenericEvent) {
150150
return;
151151
}
152152
/** @var Listener $listener */
153-
$listener = $this->getContainer()->query(Listener::class);
153+
$listener = $this->getContainer()->get(Listener::class);
154154
$listener->userAddedToGroup($event);
155155
});
156156
}

core/AppInfo/Application.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,19 @@
2222
use OC\Core\Listener\BeforeTemplateRenderedListener;
2323
use OC\Core\Listener\PasswordUpdatedListener;
2424
use OC\Core\Notification\CoreNotifier;
25-
use OC\Snowflake\ISequence;
26-
use OC\Snowflake\SnowflakeDecoder;
27-
use OC\Snowflake\SnowflakeGenerator;
2825
use OC\TagManager;
2926
use OCP\AppFramework\App;
3027
use OCP\AppFramework\Bootstrap\IBootContext;
3128
use OCP\AppFramework\Bootstrap\IBootstrap;
3229
use OCP\AppFramework\Bootstrap\IRegistrationContext;
3330
use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
3431
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
35-
use OCP\AppFramework\Utility\ITimeFactory;
3632
use OCP\DB\Events\AddMissingIndicesEvent;
3733
use OCP\DB\Events\AddMissingPrimaryKeyEvent;
38-
use OCP\IConfig;
39-
use OCP\Snowflake\ISnowflakeDecoder;
40-
use OCP\Snowflake\ISnowflakeGenerator;
4134
use OCP\User\Events\BeforeUserDeletedEvent;
4235
use OCP\User\Events\PasswordUpdatedEvent;
4336
use OCP\User\Events\UserDeletedEvent;
4437
use OCP\Util;
45-
use Psr\Container\ContainerInterface;
4638

4739
/**
4840
* Class Application

lib/private/Server.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,16 +1266,8 @@ public function __construct($webRoot, \OC\Config $config) {
12661266
$this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class);
12671267

12681268
$this->registerAlias(ISignatureManager::class, SignatureManager::class);
1269-
//
1270-
// $this->registerAlias(ISnowflakeGenerator::class, SnowflakeGenerator::class);
1271-
$this->registerService(ISnowflakeGenerator::class, function (ContainerInterface $c) {
1272-
return new SnowflakeGenerator(
1273-
$c->get(ITimeFactory::class),
1274-
$c->get(IConfig::class),
1275-
$c->get(ISequence::class),
1276-
);
1277-
});
12781269

1270+
$this->registerAlias(ISnowflakeGenerator::class, SnowflakeGenerator::class);
12791271
$this->registerService(ISequence::class, function (ContainerInterface $c): ISequence {
12801272
if (PHP_SAPI !== 'cli') {
12811273
$sequence = $c->get(APCuSequence::class);
@@ -1286,12 +1278,7 @@ public function __construct($webRoot, \OC\Config $config) {
12861278

12871279
return $c->get(FileSequence::class);
12881280
}, false);
1289-
1290-
1291-
$this->registerService(ISnowflakeDecoder::class, function (ContainerInterface $c) {
1292-
return new SnowflakeDecoder();
1293-
});
1294-
// $this->registerAlias(ISnowflakeDecoder::class, SnowflakeDecoder::class);
1281+
$this->registerAlias(ISnowflakeDecoder::class, SnowflakeDecoder::class);
12951282

12961283
$this->connectDispatcher();
12971284
}

lib/private/Snowflake/SnowflakeGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
final readonly class SnowflakeGenerator implements ISnowflakeGenerator {
2525
public function __construct(
2626
private ITimeFactory $timeFactory,
27-
private IConfig $config,
28-
private ISequence $sequenceGenerator,
27+
private IConfig $config,
28+
private ISequence $sequenceGenerator,
2929
) {
3030
}
3131

lib/public/AppFramework/Db/SnowflakeAwareEntity.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ abstract class SnowflakeAwareEntity extends Entity {
2929
/** @var array<string, \OCP\DB\Types::*> */
3030
private array $_fieldTypes = ['id' => Types::STRING];
3131

32-
private ISnowflakeGenerator $snowflakeGenerator;
33-
private ISnowflakeDecoder $snowflakeDecoder;
34-
35-
3632
/**
3733
* Automatically creates a snowflake ID
3834
*
@@ -41,7 +37,7 @@ abstract class SnowflakeAwareEntity extends Entity {
4137
#[\Override]
4238
public function setId(): void {
4339
if (empty($this->id)) {
44-
$this->id = $this->snowflakeGenerator->nextId();
40+
$this->id = Server::get(ISnowflakeGenerator::class)->nextId();
4541
$this->markFieldUpdated('id');
4642
}
4743
}
@@ -65,7 +61,7 @@ public function getSnowflake(): ?Snowflake {
6561
}
6662

6763
if ($this->snowflake === null) {
68-
$this->snowflake = $this->snowflakeDecoder->decode($this->id);
64+
$this->snowflake = Server::get(ISnowflakeDecoder::class)->decode($this->id);
6965
}
7066

7167
return $this->snowflake;

0 commit comments

Comments
 (0)