Skip to content

Commit

Permalink
Fix sharing creation insert and get
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed May 3, 2023
1 parent d95ccfd commit fa76b87
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions lib/private/Share20/DefaultShareProvider.php
Expand Up @@ -38,6 +38,7 @@
use OC\Share20\Exception\BackendError;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Exception\ProviderException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\Files\Folder;
Expand Down Expand Up @@ -90,19 +91,19 @@ class DefaultShareProvider implements IShareProvider {
/** @var IURLGenerator */
private $urlGenerator;

/** @var IConfig */
private $config;
private ITimeFactory $timeFactory;

public function __construct(
IDBConnection $connection,
IUserManager $userManager,
IGroupManager $groupManager,
IRootFolder $rootFolder,
IMailer $mailer,
Defaults $defaults,
IFactory $l10nFactory,
IURLGenerator $urlGenerator,
IConfig $config) {
IDBConnection $connection,
IUserManager $userManager,
IGroupManager $groupManager,
IRootFolder $rootFolder,
IMailer $mailer,
Defaults $defaults,
IFactory $l10nFactory,
IURLGenerator $urlGenerator,
ITimeFactory $timeFactory,
) {
$this->dbConn = $connection;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
Expand All @@ -111,7 +112,7 @@ public function __construct(
$this->defaults = $defaults;
$this->l10nFactory = $l10nFactory;
$this->urlGenerator = $urlGenerator;
$this->config = $config;
$this->timeFactory = $timeFactory;
}

/**
Expand Down Expand Up @@ -216,32 +217,22 @@ public function create(\OCP\Share\IShare $share) {
}

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

// insert the data and fetch the id of the share
$this->dbConn->beginTransaction();
$qb->execute();
$id = $this->dbConn->lastInsertId('*PREFIX*share');

// Now fetch the inserted share and create a complete share object
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
$qb->executeStatement();

$cursor = $qb->execute();
$data = $cursor->fetch();
$this->dbConn->commit();
$cursor->closeCursor();
// Update mandatory data
$id = $qb->getLastInsertId();
$share->setId((string)$id);
$share->setProviderId($this->identifier());

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

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

$share = $this->createShare($data);
return $share;
}

Expand Down

0 comments on commit fa76b87

Please sign in to comment.