chore: Treat not found noteInfos as NULL to prevent errors
This commit is contained in:
parent
ea472e6afb
commit
e8fefa064f
|
@ -38,12 +38,22 @@ class AnkiService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Give an array of IDs, the note Infos are returned. if info for a given
|
||||||
|
* doesn't exist, it is assigned to null instead of the default [].
|
||||||
|
*/
|
||||||
public function getNotesInfo(array $noteIds): array
|
public function getNotesInfo(array $noteIds): array
|
||||||
{
|
{
|
||||||
return $this->request('notesInfo', ['notes' => $noteIds]);
|
$noteInfos = $this->request('notesInfo', ['notes' => $noteIds]);
|
||||||
|
|
||||||
|
foreach ($noteInfos as &$noteInfo) {
|
||||||
|
if ([] === $noteInfo) $noteInfo = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $noteInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNoteInfo(int $noteId): array
|
/** Returns info form note given an ID, returns null if it doesn't exist */
|
||||||
|
public function getNoteInfo(int $noteId): ?array
|
||||||
{
|
{
|
||||||
return $this->getNotesInfo([$noteId])[0];
|
return $this->getNotesInfo([$noteId])[0];
|
||||||
}
|
}
|
||||||
|
@ -61,9 +71,7 @@ class AnkiService
|
||||||
public function updateNote(Note $note)
|
public function updateNote(Note $note)
|
||||||
{
|
{
|
||||||
$this->request('guiBrowse', ['query' => 'nid:1']);
|
$this->request('guiBrowse', ['query' => 'nid:1']);
|
||||||
|
|
||||||
$this->request('updateNoteFields', ['note' => $note->toAnki()]);
|
$this->request('updateNoteFields', ['note' => $note->toAnki()]);
|
||||||
|
|
||||||
$this->request('guiBrowse', ['query' => 'nid:' . $note->getId()]);
|
$this->request('guiBrowse', ['query' => 'nid:' . $note->getId()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue