Another stab at fixing Issue #201
When no categories are delivered to serendipity_updertEntry this can mean two things: - categories need to be un-assigned - categories where not addressed/fetched/passed to the function [see include/admin/overview.inc.php for publishing a post! Or plugins like freetag, using serendipity_updertEntry] To address this a new serendipity[had_categories] is added to the backend template, which can be checked for. Feedback appreciated!
This commit is contained in:
parent
f9bddffc3e
commit
9b89c3d815
@ -44,7 +44,9 @@ switch($serendipity['GET']['adminAction']) {
|
||||
'allow_comments' => $serendipity['POST']['allow_comments'],
|
||||
'moderate_comments' => $serendipity['POST']['moderate_comments'],
|
||||
'exflag' => (!empty($serendipity['POST']['extended']) ? true : false),
|
||||
'had_categories' => $serendipity['POST']['had_categories']
|
||||
// Messing with other attributes causes problems when entry is saved
|
||||
// Attributes need to explicitly matched/addressed in serendipity_updertEntry!
|
||||
|
||||
);
|
||||
}
|
||||
|
@ -1309,6 +1309,9 @@ function serendipity_updertEntry($entry) {
|
||||
|
||||
$categories = $entry['categories'];
|
||||
unset($entry['categories']);
|
||||
|
||||
$had_categories = $entry['had_categories'];
|
||||
unset($entry['had_categories']);
|
||||
|
||||
$newEntry = 0;
|
||||
$exflag = 0;
|
||||
@ -1400,6 +1403,13 @@ function serendipity_updertEntry($entry) {
|
||||
foreach ($categories as $cat) {
|
||||
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
|
||||
}
|
||||
} elseif ($had_categories) {
|
||||
// This case actually only happens if an existing entry is edited, and its category assignments are all removed.
|
||||
// This field is set as a HIDDEN input field in the admin/entries.tpl template.
|
||||
// This is more of a hotfix. In the future it should be thoroughly checked whether calls to serendipity_updertEntry()
|
||||
// really always carry through existing categories. We do not want to accidentally remove category assignments,
|
||||
// just because a plugin or so passes an incomplete $entry structure to this function.
|
||||
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entrycat WHERE entryid={$entry['id']}");
|
||||
}
|
||||
|
||||
if ($entry['isdraft'] === 0) {
|
||||
|
@ -127,6 +127,7 @@
|
||||
|
||||
{foreach from=$entry_vars.category_options item="entry_cat"}
|
||||
<div class="form_check">
|
||||
<input type="hidden" name="serendipity[had_categories]" value="1" />
|
||||
{$entry_cat.depth_pad}
|
||||
<input id="serendipity_category_{$entry_cat.categoryid}" name="serendipity[categories][]" type="checkbox" value="{$entry_cat.categoryid}"{if $entry_cat.is_selected} checked="checked"{/if}>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user