Files
itflow/api/v1/kb_articles/update.php

52 lines
1.8 KiB
PHP

<?php
/*
* API - Knowledge Base articles - Update
* POST /api/v1/kb_articles/update.php
*
* Change an article, as Edit Article does - what it said before is kept in its versions when its
* words change. Only what is sent changes.
*
* Parameters (POST, JSON body):
* api_key required - Your API key
* kb_article_id required - The article - not an archived one (unarchive.php first)
* any of the fields create.php takes. kb_article_content makes it an article in rich text,
* kb_article_markdown one in Markdown; sending neither leaves what it says as it is. Sending
* tags sets its tags to those. Sending kb_article_client_ids sets the clients it is shared
* with - apart from any the key's user can't reach, which stay.
*/
require_once '../validate_api_key.php';
require_once '../require_post_method.php';
require_once 'kb_article_model.php';
$update_count = false;
$row = kbApiArticle($_POST['kb_article_id'] ?? 0);
if ($row['kb_article_archived_at']) {
kbApiFail('That article is archived - unarchive.php brings it back to be changed.');
}
[$fields, $error] = kbApiFields($_POST, $row);
if ($error !== '') {
kbApiFail($error);
}
$kb_article_id = intval($row['kb_article_id']);
kbArticleSave($fields, $row);
if (isset($_POST['tags'])) {
tagSetForRecord('kb_article', $kb_article_id, kbApiList($_POST['tags']));
}
$update_count = 1;
$title = escapeSql($fields['title']);
$was = !empty($row['kb_article_published_at']);
$how = $fields['published'] === $was ? 'edited' : ($fields['published'] ? 'edited and published' : 'edited and made a draft of');
logAudit("Knowledge Base", "Edit", "$session_name $how article $title via API ($api_key_name)", 0, $kb_article_id);
logAudit("API", "Success", "Edited Knowledge Base article $title via API ($api_key_name)", 0);
// Output
require_once '../update_output.php';