1 | <?php |
||
17 | class RemoveFile extends ChatAPI { |
||
18 | |||
19 | /** |
||
20 | * @var $pushMessageMapper \OCA\Chat\OCH\Db\PushMessageMapper |
||
21 | */ |
||
22 | private $pushMessageMapper; |
||
23 | |||
24 | /** |
||
25 | * @var $attachmentMapper \OCA\Chat\OCH\Db\AttachmentMapper |
||
26 | */ |
||
27 | private $attachmentMapper; |
||
28 | |||
29 | /** |
||
30 | * @var $userMapper \OCA\Chat\OCH\Db\UserMapper |
||
31 | */ |
||
32 | private $userMapper; |
||
33 | |||
34 | public function __construct( |
||
35 | Chat $app, |
||
36 | PushMessageMapper $pushMessageMapper, |
||
37 | AttachmentMapper $attachmentMapper, |
||
38 | UserMapper $userMapper |
||
39 | ){ |
||
40 | $this->app = $app; |
||
|
|||
41 | $this->pushMessageMapper = $pushMessageMapper; |
||
42 | $this->attachmentMapper = $attachmentMapper; |
||
43 | $this->userMapper = $userMapper; |
||
44 | } |
||
45 | |||
46 | |||
47 | |||
48 | /* |
||
49 | * @param $requestData['user'] String user id of the client |
||
50 | * @param $requestData['session_id'] String session_id of the client |
||
51 | * @param $requestData['timestamp'] Int timestamp when the command was send |
||
52 | */ |
||
53 | public function setRequestData(array $requestData){ |
||
54 | $this->requestData = $requestData; |
||
55 | $attachment = $this->attachmentMapper->findByPathAndConvId($this->requestData['path'], $this->requestData['conv_id']); |
||
56 | if ($attachment->getOwner() !== $this->app->getUserId()){ |
||
57 | throw new RequestDataInvalid(ApiController::NOT_OWNER_OF_FILE); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | public function execute(){ |
||
62 | |||
63 | $fileId = $this->app->getFileId($this->requestData['path']); |
||
64 | $file = new Attachment(); |
||
65 | $file->setConvId($this->requestData['conv_id']); |
||
66 | $file->setFileId($fileId); |
||
67 | $this->attachmentMapper->deleteByConvAndFileID($file); |
||
68 | $this->sendPushMessage($this->requestData['path']); |
||
69 | $users = $this->userMapper->findUsersInConv($this->requestData['conv_id']); |
||
70 | foreach ($users as $user) { |
||
71 | if ($user !== $this->app->getUserId()) { |
||
72 | $this->unShare($fileId, $user); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param $fileId the fileId of the file |
||
79 | * @param $shareWIth the ownCloud user to share the file with |
||
80 | */ |
||
81 | private function unShare($fileId, $shareWIth){ |
||
82 | try { |
||
83 | \OCP\Share::unshare('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $shareWIth); |
||
84 | } Catch (\Exception $e){ |
||
85 | |||
86 | } |
||
87 | } |
||
88 | |||
89 | private function sendPushMessage($path){ |
||
111 | |||
112 | |||
113 | } |
||
114 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: