-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
Signed-off-by: Hamza Mahjoubi <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Db; | ||
|
||
use JsonSerializable; | ||
use OCP\AppFramework\Db\Entity; | ||
use ReturnTypeWillChange; | ||
|
||
/** | ||
* @method string getOwner() | ||
* @method void setOwner(string $owner) | ||
* @method string geTitle() | ||
* @method void setTitle(string $title) | ||
* @method string getContent() | ||
* @method void setContent(string $content) | ||
*/ | ||
class Snippet extends Entity implements JsonSerializable { | ||
protected $owner; | ||
protected $title; | ||
protected $content; | ||
|
||
public function __construct() { | ||
$this->addType('owner', 'string'); | ||
$this->addType('title', 'string'); | ||
$this->addType('content', 'string'); | ||
} | ||
|
||
#[ReturnTypeWillChange] | ||
public function jsonSerialize() { | ||
return [ | ||
'id' => $this->getId(), | ||
'owner' => $this->getOwner(), | ||
'title' => $this->geTitle(), | ||
'content' => $this->getContent(), | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Db; | ||
|
||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Db\QBMapper; | ||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
use OCP\IDBConnection; | ||
|
||
/** | ||
* @template-extends QBMapper<Snippet> | ||
*/ | ||
class SnippetMapper extends QBMapper { | ||
/** | ||
* @param IDBConnection $db | ||
*/ | ||
public function __construct(IDBConnection $db) { | ||
parent::__construct($db, 'mail_snippets'); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* @param string $owner | ||
* @return Snippet | ||
* | ||
* @throws DoesNotExistException | ||
*/ | ||
public function find(int $id, string $owner): Snippet { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from($this->getTableName()) | ||
->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) | ||
->andWhere($qb->expr()->eq('owner', $qb->createNamedParameter($owner))); | ||
|
||
return $this->findEntity($qb); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @return Snippet[] | ||
*/ | ||
public function findAll(string $owner): array { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from($this->getTableName()) | ||
->where( | ||
$qb->expr()->eq('owner', $qb->createNamedParameter($owner, IQueryBuilder::PARAM_STR)) | ||
); | ||
|
||
return $this->findEntities($qb); | ||
} | ||
|
||
/** | ||
* @param string $userId | ||
* @param array $groups | ||
* @return Snippet[] | ||
*/ | ||
public function findSharedWithMe(string $userId, array $groups): array { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('s.*') | ||
->from($this->getTableName(), 's') | ||
->join('s', 'mail_snippets_shares', 'share', $qb->expr()->eq('s.id', 'sshare.snippet_id')) | ||
->where($qb->expr()->andX( | ||
$qb->expr()->eq('sshare.share_with', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)), | ||
$qb->expr()->in('sshare.type', $qb->createNamedParameter('user', IQueryBuilder::PARAM_STR)) | ||
)) | ||
->orWhere( | ||
$qb->expr()->andX( | ||
$qb->expr()->in('sshare.share_with', $qb->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY)), | ||
$qb->expr()->in('sshare.type', $qb->createNamedParameter('group', IQueryBuilder::PARAM_STR)) | ||
) | ||
); | ||
return $this->findEntities($qb); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Db; | ||
|
||
use JsonSerializable; | ||
use OCP\AppFramework\Db\Entity; | ||
use ReturnTypeWillChange; | ||
|
||
/** | ||
* @method string getType() | ||
* @method void setType(string $type) | ||
* @method string getShareWith() | ||
* @method void setShareWith((string $shareWith) | ||
* @method string getSnippetId() | ||
* @method void setSnippetId(string $snippetId) | ||
*/ | ||
class SnippetShare extends Entity implements JsonSerializable { | ||
Check failure on line 24 in lib/Db/SnippetShare.php GitHub Actions / static-psalm-analysis dev-masterInvalidDocblock
|
||
protected $owner; | ||
protected $title; | ||
protected $content; | ||
|
||
public function __construct() { | ||
$this->addType('type', 'string'); | ||
$this->addType('shareWith', 'string'); | ||
$this->addType('snippetId', 'string'); | ||
} | ||
|
||
#[ReturnTypeWillChange] | ||
public function jsonSerialize() { | ||
return [ | ||
'id' => $this->getId(), | ||
'type' => $this->getType(), | ||
Check failure on line 39 in lib/Db/SnippetShare.php GitHub Actions / static-psalm-analysis dev-masterUndefinedMagicMethod
|
||
'shareWith' => $this->getShareWith(), | ||
Check failure on line 40 in lib/Db/SnippetShare.php GitHub Actions / static-psalm-analysis dev-masterUndefinedMagicMethod
|
||
'snippetId' => $this->getSnippetId(), | ||
Check failure on line 41 in lib/Db/SnippetShare.php GitHub Actions / static-psalm-analysis dev-masterUndefinedMagicMethod
|
||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Db; | ||
|
||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Db\QBMapper; | ||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
use OCP\IDBConnection; | ||
|
||
/** | ||
* @template-extends QBMapper<SnippetShare> | ||
*/ | ||
class SnippetShareMapper extends QBMapper { | ||
/** | ||
* @param IDBConnection $db | ||
*/ | ||
public function __construct(IDBConnection $db) { | ||
parent::__construct($db, 'mail_snippets_shares'); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* @param string $owner | ||
* @return Snippet | ||
Check failure on line 31 in lib/Db/SnippetShareMapper.php GitHub Actions / static-psalm-analysis dev-masterInvalidReturnType
|
||
* | ||
* @throws DoesNotExistException | ||
*/ | ||
public function find(int $id, string $owner): Snippet { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from($this->getTableName()) | ||
->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) | ||
->andWhere($qb->expr()->eq('owner', $qb->createNamedParameter($owner))); | ||
|
||
return $this->findEntity($qb); | ||
Check failure on line 42 in lib/Db/SnippetShareMapper.php GitHub Actions / static-psalm-analysis dev-masterInvalidReturnStatement
|
||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @return SnippetShare[] | ||
*/ | ||
public function findAllShares(string $owner): array { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('sshare.*') | ||
->from($this->getTableName(), 'sshare') | ||
->join('sshare', 'mail_snippets', 's', $qb->expr()->eq('sshare.snippet_id', 's.id', IQueryBuilder::PARAM_INT)) | ||
->where( | ||
$qb->expr()->eq('s.owner', $qb->createNamedParameter($owner, IQueryBuilder::PARAM_STR)) | ||
); | ||
|
||
return $this->findEntities($qb); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $snippetId | ||
* | ||
* @return SnippetShare[] | ||
*/ | ||
public function findSnippetShares(string $owner, string $snippetId): array { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('sshare.*') | ||
->from($this->getTableName(), 'sshare') | ||
->where( | ||
$qb->expr()->eq('s.owner', $qb->createNamedParameter($owner, IQueryBuilder::PARAM_STR)) | ||
) | ||
->andWhere( | ||
$qb->expr()->eq('sshare.snippet_id', $qb->createNamedParameter($snippetId, IQueryBuilder::PARAM_STR)) | ||
); | ||
|
||
return $this->findEntities($qb); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version4001Date20241017154801 extends SimpleMigrationStep { | ||
/** | ||
* @param IOutput $output | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
* @param array $options | ||
* @return ISchemaWrapper | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
$table = $schema->createTable('mail_snippets'); | ||
|
||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
'length' => 4, | ||
]); | ||
$table->addColumn('owner', Types::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('title', Types::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('content', Types::TEXT, [ | ||
'notnull' => true, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
|
||
return $schema; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version4001Date20241017155914 extends SimpleMigrationStep { | ||
/** | ||
* @param IOutput $output | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
* @param array $options | ||
* @return ISchemaWrapper | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
$table = $schema->createTable('mail_snippets_shares'); | ||
|
||
$table->addColumn('id', Types::INTEGER, [ | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
'length' => 4, | ||
]); | ||
$table->addColumn('type', Types::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('share_with', Types::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('snippet_id', Types::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
return $schema; | ||
} | ||
} |