Skip to content

Commit e909f1c

Browse files
authored
Merge pull request #696 from bitrix24/feature/687-note-collection-v3
Add REST v3 note.collection move, restore and unarchive (#687)
2 parents 1027b1e + 8b42472 commit e909f1c

19 files changed

Lines changed: 721 additions & 17 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66
- Added REST v3 `note.file.list` with typed file results, attachment dates, and opaque cursor pagination; added dedicated file field metadata access while preserving existing methods ([#688](https://github.com/bitrix24/b24phpsdk/issues/688))
7+
- Added REST v3 `note.collection.move`, `note.collection.restore` and `note.collection.unarchive` to the Note `Collection` service; added `accessLevel`, `state` (`CollectionState` enum), `isArchived` and `markdownDescription` to `CollectionItemResult`, matching selectors to `CollectionSelectBuilder`, `editableGroups` to `CollectionFieldItemResult` and `getFieldsDescription()` to `CollectionFieldsResult` ([#687](https://github.com/bitrix24/b24phpsdk/issues/687))
78
- Added an eager `Core\Credentials\RenewedAuthToken` compatibility alias preserving legacy constructors, signatures and serialized tokens ([#117](https://github.com/bitrix24/b24phpsdk/issues/117))
89
- Added non-interactive legacy API coverage reporting with `--show`, `--scope` and `--format=json` options ([#410](https://github.com/bitrix24/b24phpsdk/issues/410))
910

@@ -19,6 +20,7 @@
1920
- Corrected `InstantMessenger::VALUE_TYPE` conversion and PHPDoc to use `InstantMessengerValueType` ([#156](https://github.com/bitrix24/b24phpsdk/issues/156))
2021
- Distinguished response decoding failures with `ResponseDecodingException` while preserving sanitized diagnostics and excluding unsafe exception chains ([#667](https://github.com/bitrix24/b24phpsdk/issues/667))
2122
- Reused core pagination for Task, Sale Order and BasketItem batches, preserving requested sorting, nested result references, filters and limits ([#363](https://github.com/bitrix24/b24phpsdk/issues/363))
23+
- Fixed dead REST v3 documentation links in the Note `Collection` service metadata; they now point to `https://apidocs.bitrix24.com/api-reference/note/collection/` ([#687](https://github.com/bitrix24/b24phpsdk/issues/687))
2224

2325
## 3.7.0
2426

‎docs/open-api/openapi.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎src/Services/Note/Collection/Result/CollectionFieldItemResult.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* @property-read bool $filterable
2828
* @property-read bool $sortable
2929
* @property-read bool $editable
30+
* @property-read array|null $editableGroups
3031
* @property-read bool $multiple
3132
* @property-read string|null $elementType
3233
*/

‎src/Services/Note/Collection/Result/CollectionFieldsResult.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,33 @@
1414
namespace Bitrix24\SDK\Services\Note\Collection\Result;
1515

1616
use Bitrix24\SDK\Core\Exceptions\BaseException;
17+
use Bitrix24\SDK\Core\Exceptions\LogicException;
1718
use Bitrix24\SDK\Core\Result\AbstractResult;
1819

1920
class CollectionFieldsResult extends AbstractResult
2021
{
22+
/**
23+
* Include name when selecting metadata fields so descriptors can be indexed.
24+
*
25+
* @return array<string, array<string, mixed>>
26+
* @throws BaseException
27+
* @throws LogicException
28+
*/
29+
public function getFieldsDescription(): array
30+
{
31+
$fields = [];
32+
foreach ($this->getCoreResponse()->getResponseData()->getResult()['items'] as $field) {
33+
$name = $field['name'] ?? null;
34+
if (!is_string($name) || $name === '') {
35+
throw new LogicException('Collection field metadata must contain a nonempty string name.');
36+
}
37+
38+
$fields[$name] = $field;
39+
}
40+
41+
return $fields;
42+
}
43+
2144
/**
2245
* @return CollectionFieldItemResult[]
2346
* @throws BaseException

‎src/Services/Note/Collection/Result/CollectionItemResult.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
* @property-read string $name
2626
* @property-read int|null $position
2727
* @property-read string|null $policyLevel
28+
* @property-read string|null $accessLevel
29+
* @property-read CollectionState $state
30+
* @property-read bool $isArchived
2831
* @property-read int|null $createdBy
2932
* @property-read CarbonImmutable $createdAt
3033
* @property-read int|null $updatedBy
3134
* @property-read CarbonImmutable $updatedAt
35+
* @property-read string|null $markdownDescription
3236
*/
3337
#[OpenApiEntity(
3438
entityKey: 'bitrix.note.collectionitemdto',
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <mesilov.maxim@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Note\Collection\Result;
15+
16+
/**
17+
* Lifecycle state of a knowledge base (collection).
18+
*/
19+
enum CollectionState: string
20+
{
21+
case live = 'live';
22+
case archived = 'archived';
23+
case trashed = 'trashed';
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <mesilov.maxim@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Note\Collection\Result;
15+
16+
use Bitrix24\SDK\Core\Exceptions\BaseException;
17+
use Bitrix24\SDK\Core\Result\AbstractResult;
18+
19+
class RestoredCollectionResult extends AbstractResult
20+
{
21+
/**
22+
* @throws BaseException
23+
*/
24+
public function isSuccess(): bool
25+
{
26+
return (bool)($this->getCoreResponse()->getResponseData()->getResult()['result'] ?? false);
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <mesilov.maxim@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Note\Collection\Result;
15+
16+
use Bitrix24\SDK\Core\Exceptions\BaseException;
17+
use Bitrix24\SDK\Core\Result\AbstractResult;
18+
19+
class UnarchivedCollectionResult extends AbstractResult
20+
{
21+
/**
22+
* @throws BaseException
23+
*/
24+
public function isSuccess(): bool
25+
{
26+
return (bool)($this->getCoreResponse()->getResponseData()->getResult()['result'] ?? false);
27+
}
28+
}

‎src/Services/Note/Collection/Service/Collection.php‎

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@
2828
use Bitrix24\SDK\Services\Note\Collection\Result\CollectionResult;
2929
use Bitrix24\SDK\Services\Note\Collection\Result\CollectionsResult;
3030
use Bitrix24\SDK\Services\Note\Collection\Result\DeletedCollectionResult;
31+
use Bitrix24\SDK\Services\Note\Collection\Result\RestoredCollectionResult;
32+
use Bitrix24\SDK\Services\Note\Collection\Result\UnarchivedCollectionResult;
3133

3234
#[ApiServiceMetadata(new Scope(['note']))]
3335
class Collection extends AbstractService
3436
{
3537
/**
3638
* Creates a new knowledge base (collection).
3739
*
38-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-add.html
40+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-add.html
3941
*
4042
* @throws BaseException
4143
* @throws TransportException
4244
*/
4345
#[ApiEndpointMetadata(
4446
'note.collection.add',
45-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-add.html',
47+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-add.html',
4648
'Creates a new knowledge base.',
4749
ApiVersion::v3
4850
)]
@@ -68,14 +70,14 @@ public function add(string $name, ?int $position = null): CollectionResult
6870
/**
6971
* Archives a knowledge base.
7072
*
71-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-archive.html
73+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-archive.html
7274
*
7375
* @throws BaseException
7476
* @throws TransportException
7577
*/
7678
#[ApiEndpointMetadata(
7779
'note.collection.archive',
78-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-archive.html',
80+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-archive.html',
7981
'Archives a knowledge base.',
8082
ApiVersion::v3
8183
)]
@@ -89,15 +91,15 @@ public function archive(int $id): ArchivedCollectionResult
8991
/**
9092
* Deletes a knowledge base by id or by filter.
9193
*
92-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-delete.html
94+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-delete.html
9395
*
9496
* @param array|FilterBuilderInterface $filter Filter conditions (REST v3 format)
9597
* @throws BaseException
9698
* @throws TransportException
9799
*/
98100
#[ApiEndpointMetadata(
99101
'note.collection.delete',
100-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-delete.html',
102+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-delete.html',
101103
'Deletes a knowledge base.',
102104
ApiVersion::v3
103105
)]
@@ -125,15 +127,15 @@ public function delete(?int $id = null, array|FilterBuilderInterface $filter = [
125127
/**
126128
* Returns the metadata of a single `note.collection` field.
127129
*
128-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-field-get.html
130+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-field-get.html
129131
*
130132
* @param array<int,string> $select
131133
* @throws BaseException
132134
* @throws TransportException
133135
*/
134136
#[ApiEndpointMetadata(
135137
'note.collection.field.get',
136-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-field-get.html',
138+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-field-get.html',
137139
'Returns metadata of a single collection field.',
138140
ApiVersion::v3
139141
)]
@@ -157,15 +159,15 @@ public function fieldGet(string $name, array $select = []): CollectionFieldResul
157159
/**
158160
* Returns the metadata of all `note.collection` fields.
159161
*
160-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-field-list.html
162+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-field-list.html
161163
*
162164
* @param array<int,string> $select
163165
* @throws BaseException
164166
* @throws TransportException
165167
*/
166168
#[ApiEndpointMetadata(
167169
'note.collection.field.list',
168-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-field-list.html',
170+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-field-list.html',
169171
'Returns metadata of all collection fields.',
170172
ApiVersion::v3
171173
)]
@@ -183,15 +185,15 @@ public function fieldList(array $select = []): CollectionFieldsResult
183185
/**
184186
* Returns a single knowledge base by id.
185187
*
186-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-get.html
188+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-get.html
187189
*
188190
* @param array<int,string>|CollectionSelectBuilder $select
189191
* @throws BaseException
190192
* @throws TransportException
191193
*/
192194
#[ApiEndpointMetadata(
193195
'note.collection.get',
194-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-get.html',
196+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-get.html',
195197
'Returns a single knowledge base by id.',
196198
ApiVersion::v3
197199
)]
@@ -219,14 +221,14 @@ public function get(int $id, array|CollectionSelectBuilder $select = []): Collec
219221
/**
220222
* Returns a cursor-paginated list of knowledge bases available to the user.
221223
*
222-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-list.html
224+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-list.html
223225
*
224226
* @throws BaseException
225227
* @throws TransportException
226228
*/
227229
#[ApiEndpointMetadata(
228230
'note.collection.list',
229-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-list.html',
231+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-list.html',
230232
'Returns a list of knowledge bases available to the user.',
231233
ApiVersion::v3
232234
)]
@@ -241,10 +243,91 @@ public function list(?CollectionListPagination $pagination = null): CollectionsR
241243
);
242244
}
243245

246+
/**
247+
* Moves a knowledge base to another place in the portal-wide list of knowledge bases.
248+
*
249+
* `position` is a sort weight: pass a value between the weights of two knowledge bases to land between them,
250+
* omit it to land last. The stored weight is recomputed from the neighbours, so read it from the result.
251+
* Archived and trashed knowledge bases cannot be moved.
252+
*
253+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-move.html
254+
*
255+
* @throws BaseException
256+
* @throws TransportException
257+
*/
258+
#[ApiEndpointMetadata(
259+
'note.collection.move',
260+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-move.html',
261+
'Moves a knowledge base to another place in the list.',
262+
ApiVersion::v3
263+
)]
264+
public function move(int $id, ?int $position = null): CollectionResult
265+
{
266+
return new CollectionResult(
267+
$this->core->call(
268+
'note.collection.move',
269+
array_filter(
270+
[
271+
'id' => $id,
272+
'position' => $position,
273+
],
274+
static fn (mixed $value): bool => $value !== null
275+
),
276+
ApiVersion::v3
277+
)
278+
);
279+
}
280+
281+
/**
282+
* Restores a knowledge base from the recycle bin together with the documents deleted with it.
283+
*
284+
* A repeated call for a knowledge base that is already out of the recycle bin succeeds.
285+
*
286+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-restore.html
287+
*
288+
* @throws BaseException
289+
* @throws TransportException
290+
*/
291+
#[ApiEndpointMetadata(
292+
'note.collection.restore',
293+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-restore.html',
294+
'Restores a knowledge base from the recycle bin.',
295+
ApiVersion::v3
296+
)]
297+
public function restore(int $id): RestoredCollectionResult
298+
{
299+
return new RestoredCollectionResult(
300+
$this->core->call('note.collection.restore', ['id' => $id], ApiVersion::v3)
301+
);
302+
}
303+
304+
/**
305+
* Returns a knowledge base from the archive together with its documents.
306+
*
307+
* A knowledge base that is not archived is reported as not found; a trashed one must be restored first.
308+
*
309+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-unarchive.html
310+
*
311+
* @throws BaseException
312+
* @throws TransportException
313+
*/
314+
#[ApiEndpointMetadata(
315+
'note.collection.unarchive',
316+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-unarchive.html',
317+
'Returns a knowledge base from the archive.',
318+
ApiVersion::v3
319+
)]
320+
public function unarchive(int $id): UnarchivedCollectionResult
321+
{
322+
return new UnarchivedCollectionResult(
323+
$this->core->call('note.collection.unarchive', ['id' => $id], ApiVersion::v3)
324+
);
325+
}
326+
244327
/**
245328
* Updates a knowledge base by id or by filter.
246329
*
247-
* @link https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-update.html
330+
* @link https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-update.html
248331
*
249332
* @param array $fields fields to update, e.g. ['name' => 'New name']
250333
* @param array|FilterBuilderInterface $filter Filter conditions (REST v3 format)
@@ -253,7 +336,7 @@ public function list(?CollectionListPagination $pagination = null): CollectionsR
253336
*/
254337
#[ApiEndpointMetadata(
255338
'note.collection.update',
256-
'https://apidocs.bitrix24.com/api-reference/rest-v3/note/collection/note-collection-update.html',
339+
'https://apidocs.bitrix24.com/api-reference/note/collection/note-collection-update.html',
257340
'Updates a knowledge base.',
258341
ApiVersion::v3
259342
)]

0 commit comments

Comments
 (0)