committed by
Julius Härtl
parent
725f99d8b8
commit
d27a5ac9ba
@@ -45,7 +45,7 @@ class AttachmentApiController extends ApiController {
|
||||
*
|
||||
*/
|
||||
public function getAll() {
|
||||
$attachment = $this->attachmentService->findAll($this->request->getParam('cardId'));
|
||||
$attachment = $this->attachmentService->findAll($this->request->getParam('cardId'), true);
|
||||
return new DataResponse($attachment, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class AttachmentController extends Controller {
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getAll($cardId) {
|
||||
return $this->attachmentService->findAll($cardId);
|
||||
return $this->attachmentService->findAll($cardId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,6 +81,22 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
|
||||
return $this->mapRowToEntity($row);
|
||||
}
|
||||
|
||||
public function findByData($cardId, $data) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('deck_attachment')
|
||||
->where($qb->expr()->eq('card_id', $qb->createNamedParameter($cardId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('data', $qb->createNamedParameter($data, IQueryBuilder::PARAM_STR)));
|
||||
$cursor = $qb->execute();
|
||||
$row = $cursor->fetch(PDO::FETCH_ASSOC);
|
||||
if($row === false) {
|
||||
$cursor->closeCursor();
|
||||
throw new DoesNotExistException('Did expect one result but found none when executing' . $qb);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
return $this->mapRowToEntity($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all attachments for a card
|
||||
*
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace OCA\Deck\Service;
|
||||
|
||||
use OC\Security\CSP\ContentSecurityPolicyManager;
|
||||
use OCA\Deck\Db\Attachment;
|
||||
use OCA\Deck\Db\AttachmentMapper;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\Exceptions\ConflictException;
|
||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
@@ -53,6 +54,7 @@ class FileService implements IAttachmentService {
|
||||
private $logger;
|
||||
private $rootFolder;
|
||||
private $config;
|
||||
private $attachmentMapper;
|
||||
|
||||
public function __construct(
|
||||
IL10N $l10n,
|
||||
@@ -60,7 +62,8 @@ class FileService implements IAttachmentService {
|
||||
IRequest $request,
|
||||
ILogger $logger,
|
||||
IRootFolder $rootFolder,
|
||||
IConfig $config
|
||||
IConfig $config,
|
||||
AttachmentMapper $attachmentMapper
|
||||
) {
|
||||
$this->l10n = $l10n;
|
||||
$this->appData = $appData;
|
||||
@@ -68,6 +71,7 @@ class FileService implements IAttachmentService {
|
||||
$this->logger = $logger;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->config = $config;
|
||||
$this->attachmentMapper = $attachmentMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,6 +159,7 @@ class FileService implements IAttachmentService {
|
||||
$folder = $this->getFolder($attachment);
|
||||
$fileName = $file['name'];
|
||||
if ($folder->fileExists($fileName)) {
|
||||
$attachment = $this->attachmentMapper->findByData($attachment->getCardId(), $fileName);
|
||||
throw new ConflictException('File already exists.', $attachment);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user