1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Tahaa Karim <[email protected]> |
4
|
|
|
* |
5
|
|
|
* ownCloud - Mail |
6
|
|
|
* |
7
|
|
|
* This code is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
9
|
|
|
* as published by the Free Software Foundation. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Affero General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
namespace OCA\Mail\Service; |
21
|
|
|
|
22
|
|
|
use Exception; |
23
|
|
|
use OCA\Mail\Db\Alias; |
24
|
|
|
use OCA\Mail\Db\AliasMapper; |
25
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
26
|
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException; |
27
|
|
|
|
28
|
|
|
class AliasesService { |
29
|
|
|
|
30
|
|
|
/** @var \OCA\Mail\Db\AliasMapper */ |
31
|
|
|
private $mapper; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param AliasMapper $mapper |
35
|
|
|
*/ |
36
|
|
|
public function __construct(AliasMapper $mapper) { |
37
|
|
|
$this->mapper = $mapper; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param $e |
42
|
|
|
* @throws NotFoundException |
43
|
|
|
*/ |
44
|
|
|
private function handleException ($e) { |
45
|
|
|
if ($e instanceof DoesNotExistException || |
|
|
|
|
46
|
|
|
$e instanceof MultipleObjectsReturnedException) { |
|
|
|
|
47
|
|
|
throw new NotFoundException($e->getMessage()); |
48
|
|
|
} else { |
49
|
|
|
throw $e; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param int $accountId |
55
|
|
|
* @param String $currentUserId |
56
|
|
|
* @return Alias[] |
57
|
|
|
*/ |
58
|
|
|
public function findAll($accountId, $currentUserId) { |
59
|
|
|
return $this->mapper->findAll($accountId, $currentUserId); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int $aliasId |
64
|
|
|
* @param String $currentUserId |
65
|
|
|
* @return Alias |
66
|
|
|
*/ |
67
|
|
|
public function find($aliasId, $currentUserId) { |
68
|
|
|
return $this->mapper->find($aliasId, $currentUserId); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param int $accountId |
73
|
|
|
* @param String $alias |
74
|
|
|
* @param String $aliasName |
75
|
|
|
* @return Alias |
76
|
|
|
*/ |
77
|
|
|
public function create($accountId, $alias, $aliasName) { |
78
|
|
|
try { |
79
|
|
|
$aliasEntity = new Alias(); |
80
|
|
|
$aliasEntity->setAccountId($accountId); |
81
|
|
|
$aliasEntity->setAlias($alias); |
82
|
|
|
$aliasEntity->setName($aliasName); |
83
|
|
|
return $this->mapper->insert($aliasEntity); |
84
|
|
|
} catch(Exception $e){ |
85
|
|
|
$this->handleException($e); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param int $aliasId |
91
|
|
|
* @param String $currentUserId |
92
|
|
|
* @return \OCA\Mail\Db\Alias |
93
|
|
|
*/ |
94
|
|
|
public function delete($aliasId, $currentUserId) { |
95
|
|
|
try { |
96
|
|
|
$alias = $this->mapper->find($aliasId, $currentUserId); |
97
|
|
|
$this->mapper->delete($alias); |
98
|
|
|
return $alias; |
99
|
|
|
} catch(Exception $e) { |
100
|
|
|
$this->handleException($e); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.