Completed
Push — master ( 93bf15...69947f )
by Maxence
01:58
created

Index::unsetStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * FullTextSearch - Full text search framework for Nextcloud
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2018
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\FullTextSearch\Model;
28
29
class Index implements \JsonSerializable {
30
31
	const INDEX_OK = 1;
32
	const INDEX_IGNORE = 2;
33
34
	const INDEX_META = 4;
35
	const INDEX_CONTENT = 8;
36
	const INDEX_FULL = 12;
37
	const INDEX_REMOVE = 16;
38
39
	const INDEX_DONE = 32;
40
	const INDEX_FAILED = 64;
41
42
	const ERROR_FAILED = 1;
43
	const ERROR_FAILED2 = 2;
44
	const ERROR_FAILED3 = 4;
45
46
47
	/** @var string */
48
	private $providerId;
49
50
	/** @var string */
51
	private $documentId;
52
53
	/** @var string */
54
	private $ownerId = '';
55
56
	/** @var int */
57
	private $status = 0;
58
59
	/** @var int */
60
	private $err = 0;
61
62
	/** @var int */
63
	private $lastIndex = 0;
64
65
66
	public function __construct($providerId, $documentId) {
67
		$this->providerId = $providerId;
68
		$this->documentId = $documentId;
69
	}
70
71
72
	/**
73
	 * @return string
74
	 */
75
	public function getProviderId() {
76
		return $this->providerId;
77
	}
78
79
	/**
80
	 * @return string
81
	 */
82
	public function getDocumentId() {
83
		return $this->documentId;
84
	}
85
86
87
	/**
88
	 * @param string $ownerId
89
	 *
90
	 * @return $this
91
	 */
92
	public function setOwnerId($ownerId) {
93
		$this->ownerId = $ownerId;
94
95
		return $this;
96
	}
97
98
	/**
99
	 * @return string
100
	 */
101
	public function getOwnerId() {
102
		return $this->ownerId;
103
	}
104
105
106
	/**
107
	 * @param int $status
108
	 * @param bool $reset
109
	 *
110
	 * @return $this
111
	 */
112
	public function setStatus($status, $reset = false) {
113
		if ($reset === true) {
114
			$this->status = $status;
115
		} else if (!$this->isStatus($status)) {
116
			$this->status += $status;
117
		}
118
119
		return $this;
120
	}
121
122
	/**
123
	 * @return int
124
	 */
125
	public function getStatus() {
126
		return $this->status;
127
	}
128
129
	/**
130
	 * @param int $status
131
	 *
132
	 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
133
	 */
134
	public function isStatus($status) {
135
		return ((int)$status & $this->getStatus());
136
	}
137
138
	/**
139
	 * @param int $status
140
	 */
141
	public function unsetStatus($status) {
142
		if (!$this->isStatus($status)) {
143
			return;
144
		}
145
146
		$this->status -= $status;
147
	}
148
149
	/**
150
	 * @param int $err
151
	 *
152
	 * @return $this
153
	 */
154
	public function setError($err) {
155
		$this->err = $err;
156
157
		return $this;
158
	}
159
160
	/**
161
	 * @return int
162
	 */
163
	public function getError() {
164
		return $this->err;
165
	}
166
167
168
	/**
169
	 * @param int $lastIndex
170
	 *
171
	 * @return $this
172
	 */
173
	public function setLastIndex($lastIndex = -1) {
174
		if ($lastIndex === -1) {
175
			$lastIndex = time();
176
		}
177
178
		$this->lastIndex = $lastIndex;
179
180
		return $this;
181
	}
182
183
	/**
184
	 * @return int
185
	 */
186
	public function getLastIndex() {
187
		return $this->lastIndex;
188
	}
189
190
191
	/**
192
	 * @return array<string,string|integer>
193
	 */
194
	public function jsonSerialize() {
195
		return [
196
			'ownerId'    => $this->getOwnerId(),
197
			'providerId' => $this->getProviderId(),
198
			'documentId' => $this->getDocumentId(),
199
			'lastIndex'  => $this->getLastIndex(),
200
			'status'     => (int)$this->getStatus()
201
		];
202
	}
203
204
}