-
Notifications
You must be signed in to change notification settings - Fork 48
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: Maxence Lange <[email protected]>
- Loading branch information
1 parent
3419018
commit ca76ac0
Showing
13 changed files
with
380 additions
and
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Circles\Db; | ||
|
||
use OC\DB\Exceptions\DbalException; | ||
use OCA\Circles\Exceptions\MountNotFoundException; | ||
use OCA\Circles\Model\Mountpoint; | ||
use OCA\Circles\Tools\Traits\TStringTools; | ||
|
||
class MountPointRequest extends MountPointRequestBuilder { | ||
use TStringTools; | ||
|
||
/** | ||
* @param Mountpoint $mountpoint | ||
*/ | ||
public function insert(Mountpoint $mountpoint): void { | ||
$qb = $this->getMountPointInsertSql(); | ||
|
||
$hash = ($mountpoint->getMountPoint() === '-') ? '' : md5($mountpoint->getMountPoint()); | ||
$qb->setValue('mountpoint', $qb->createNamedParameter($mountpoint->getMountPoint())) | ||
->setValue('mountpoint_hash', $qb->createNamedParameter($hash)) | ||
->setValue('mount_id', $qb->createNamedParameter($mountpoint->getMountId())) | ||
->setValue('single_id', $qb->createNamedParameter($mountpoint->getSingleId())); | ||
$qb->executeStatement(); | ||
} | ||
|
||
/** | ||
* @param Mountpoint $mountpoint | ||
* @throws MountNotFoundException | ||
*/ | ||
public function update(Mountpoint $mountpoint): void { | ||
$qb = $this->getMountPointUpdateSql(); | ||
|
||
$hash = ($mountpoint->getMountPoint() === '-') ? '' : md5($mountpoint->getMountPoint()); | ||
|
||
$qb->set('mountpoint', $qb->createNamedParameter($mountpoint->getMountPoint())) | ||
->set('mountpoint_hash', $qb->createNamedParameter($hash)); | ||
$qb->limit('mount_id', $mountpoint->getMountId()); | ||
$qb->limitToSingleId($mountpoint->getSingleId()); | ||
$nb = $qb->executeStatement(); | ||
|
||
if ($nb === 0) { | ||
throw new MountNotFoundException('Mount not found'); | ||
} | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Circles\Db; | ||
|
||
use OCA\Circles\Exceptions\MountNotFoundException; | ||
use OCA\Circles\Model\Mount; | ||
use OCA\Circles\Model\Mountpoint; | ||
use OCA\Circles\Tools\Exceptions\RowNotFoundException; | ||
|
||
class MountPointRequestBuilder extends CoreRequestBuilder { | ||
protected function getMountPointInsertSql(): CoreQueryBuilder { | ||
$qb = $this->getQueryBuilder(); | ||
$qb->insert(self::TABLE_MOUNTPOINT); | ||
|
||
return $qb; | ||
} | ||
|
||
protected function getMountPointUpdateSql(): CoreQueryBuilder { | ||
$qb = $this->getQueryBuilder(); | ||
$qb->update(self::TABLE_MOUNTPOINT); | ||
|
||
return $qb; | ||
} | ||
|
||
protected function getMountPointSelectSql(string $alias = CoreQueryBuilder::MOUNTPOINT): CoreQueryBuilder { | ||
$qb = $this->getQueryBuilder(); | ||
$qb->generateSelect(self::TABLE_MOUNTPOINT, self::$tables[self::TABLE_MOUNTPOINT], $alias); | ||
|
||
return $qb; | ||
} | ||
|
||
protected function getMountPointDeleteSql(): CoreQueryBuilder { | ||
$qb = $this->getQueryBuilder(); | ||
$qb->delete(self::TABLE_MOUNTPOINT); | ||
|
||
return $qb; | ||
} | ||
|
||
public function getItemFromRequest(CoreQueryBuilder $qb): MountPoint { | ||
/** @var MountPoint $mountpoint */ | ||
try { | ||
$mountpoint = $qb->asItem(MountPoint::class); | ||
} catch (RowNotFoundException $e) { | ||
throw new MountNotFoundException('Mount not found'); | ||
} | ||
|
||
return $mountpoint; | ||
} | ||
|
||
/** | ||
* @param CoreQueryBuilder $qb | ||
* | ||
* @return Mount[] | ||
*/ | ||
public function getItemsFromRequest(CoreQueryBuilder $qb): array { | ||
/** @var MountPoint[] $result */ | ||
return $qb->asItems(MountPoint::class); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Circles\Exceptions; | ||
|
||
class MountPointNotFoundException extends FederatedItemNotFoundException { | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
|
||
namespace OCA\Circles\Migration; | ||
|
||
use Closure; | ||
use Doctrine\DBAL\Schema\SchemaException; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class Version0031Date20241105133904 extends SimpleMigrationStep { | ||
public function __construct( | ||
private LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
try { | ||
$table = $schema->getTable('circles_mountpoint'); | ||
if (!$table->hasIndex('dname')) { | ||
$table->addUniqueIndex(['single_id', 'mountpoint_hash'], 'mp_sid_hash'); | ||
} | ||
} catch (SchemaException $e) { | ||
$this->logger->warning('Could not find circles_mountpoint', ['exception' => $e]); | ||
} | ||
|
||
return $schema; | ||
} | ||
} |
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
Oops, something went wrong.