Skip to content

Commit 1f6ff7b

Browse files
committed
Fix sharing creation insert and get
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 527de8a commit 1f6ff7b

2 files changed

Lines changed: 24 additions & 33 deletions

File tree

lib/private/Share20/DefaultShareProvider.php

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
use OC\Share20\Exception\BackendError;
3939
use OC\Share20\Exception\InvalidShare;
4040
use OC\Share20\Exception\ProviderException;
41+
use OCP\AppFramework\Utility\ITimeFactory;
4142
use OCP\DB\QueryBuilder\IQueryBuilder;
4243
use OCP\Defaults;
4344
use OCP\Files\Folder;
4445
use OCP\Files\IRootFolder;
4546
use OCP\Files\Node;
46-
use OCP\IConfig;
4747
use OCP\IDBConnection;
4848
use OCP\IGroupManager;
4949
use OCP\IURLGenerator;
@@ -90,19 +90,19 @@ class DefaultShareProvider implements IShareProvider {
9090
/** @var IURLGenerator */
9191
private $urlGenerator;
9292

93-
/** @var IConfig */
94-
private $config;
93+
private ITimeFactory $timeFactory;
9594

9695
public function __construct(
97-
IDBConnection $connection,
98-
IUserManager $userManager,
99-
IGroupManager $groupManager,
100-
IRootFolder $rootFolder,
101-
IMailer $mailer,
102-
Defaults $defaults,
103-
IFactory $l10nFactory,
104-
IURLGenerator $urlGenerator,
105-
IConfig $config) {
96+
IDBConnection $connection,
97+
IUserManager $userManager,
98+
IGroupManager $groupManager,
99+
IRootFolder $rootFolder,
100+
IMailer $mailer,
101+
Defaults $defaults,
102+
IFactory $l10nFactory,
103+
IURLGenerator $urlGenerator,
104+
ITimeFactory $timeFactory,
105+
) {
106106
$this->dbConn = $connection;
107107
$this->userManager = $userManager;
108108
$this->groupManager = $groupManager;
@@ -111,7 +111,7 @@ public function __construct(
111111
$this->defaults = $defaults;
112112
$this->l10nFactory = $l10nFactory;
113113
$this->urlGenerator = $urlGenerator;
114-
$this->config = $config;
114+
$this->timeFactory = $timeFactory;
115115
}
116116

117117
/**
@@ -216,32 +216,22 @@ public function create(\OCP\Share\IShare $share) {
216216
}
217217

218218
// Set the time this share was created
219-
$qb->setValue('stime', $qb->createNamedParameter(time()));
219+
$shareTime = $this->timeFactory->now();
220+
$qb->setValue('stime', $qb->createNamedParameter($shareTime->getTimestamp()));
220221

221222
// insert the data and fetch the id of the share
222-
$this->dbConn->beginTransaction();
223-
$qb->execute();
224-
$id = $this->dbConn->lastInsertId('*PREFIX*share');
225-
226-
// Now fetch the inserted share and create a complete share object
227-
$qb = $this->dbConn->getQueryBuilder();
228-
$qb->select('*')
229-
->from('share')
230-
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
223+
$qb->executeStatement();
231224

232-
$cursor = $qb->execute();
233-
$data = $cursor->fetch();
234-
$this->dbConn->commit();
235-
$cursor->closeCursor();
225+
// Update mandatory data
226+
$id = $qb->getLastInsertId();
227+
$share->setId((string)$id);
228+
$share->setProviderId($this->identifier());
236229

237-
if ($data === false) {
238-
throw new ShareNotFound('Newly created share could not be found');
239-
}
230+
$share->setShareTime(\DateTime::createFromImmutable($shareTime));
240231

241232
$mailSendValue = $share->getMailSend();
242-
$data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue;
233+
$share->setMailSend(($mailSendValue === null) ? true : $mailSendValue);
243234

244-
$share = $this->createShare($data);
245235
return $share;
246236
}
247237

lib/private/Share20/ProviderFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use OCA\ShareByMail\Settings\SettingsManager;
4242
use OCA\ShareByMail\ShareByMailProvider;
4343
use OCA\Talk\Share\RoomShareProvider;
44+
use OCP\AppFramework\Utility\ITimeFactory;
4445
use OCP\Defaults;
4546
use OCP\EventDispatcher\IEventDispatcher;
4647
use OCP\IServerContainer;
@@ -104,7 +105,7 @@ protected function defaultShareProvider() {
104105
$this->serverContainer->query(Defaults::class),
105106
$this->serverContainer->getL10NFactory(),
106107
$this->serverContainer->getURLGenerator(),
107-
$this->serverContainer->getConfig()
108+
$this->serverContainer->query(ITimeFactory::class),
108109
);
109110
}
110111

0 commit comments

Comments
 (0)