Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: exp_category_posts data for entry is deleted when using Add categories batch option on entry manager screen

Status Resolved
Add-on / Version Advanced Categories 1.1.0
Severity
EE Version 6.3.5

adamrifat

Mar 17, 2023

I need to move multiple entries from one category to another for housekeeping purposes.

On the entry manager screen I applied ‘Familiies’ as Category filter which returned 55 entries. I then chose ‘Add categories’ from the ‘actions’ dropdown at the bottom of the list.

In the resulting modal window it stated ‘Any categories selected will be assigned to the selected entries in addition to the current category selection for those entries’ which is what wanted. I selected ‘Leisure’ as the additional category and hit the ‘Save all & close’ button.

To my dismay all 55 original entries were no longer appearing when I filtered on either Families or Leisure. Looking at the database I noticed that the exp_category_posts data was missing for each of the 55 entries meaning that essentially these entries were no longer categorised at all.

As I had taken a db backup beforehand I managed to restore the category information.

After a bit of debugging it looks as though it’s the ‘before_channel_entry_save’ extension hook which is causing this issue. As far as I can tell this hook, when called from the bulk edit toolbar wipes all category data for all the entries selected.

 

#1

BoldMinded (Brian)

Can you take a screenshot of the bulk edit page prior to submission so I can accurately replicate this locally?

#2

adamrifat

Sure. I’ve attached a screenshot.

This is basically after selecting some entries and choosing Add categories in the dropdown at the bottom of the list.

Thanks.

#3

BoldMinded (Brian)

Comment has been marked private.

#4

adamrifat

After updating to 1.1.1 I get the following error when I try to edit an entry.

Argument 1 passed to Advanced_categories_ft::getInvalidCategories() must be of the type array, null given, called in user/addons/advanced_categories/ft.advanced_categories.php on line 121

If I try and add a category via the bulk edit the existing entry data in exp_category_posts doesn’t get deleted this time but the new category isn’t added either.

#5

BoldMinded (Brian)

Ok. PHP v8?

#6

adamrifat

PHP is 7.4 locally

#7

BoldMinded (Brian)

Comment has been marked private.

#8

BoldMinded (Brian)

It should handle the bulk add/remove category option better, but if you have restrictions on your AC field, e.g. must have at least 1 selected, or no more than 2 selected, those rules aren’t enforced when bulk editing. I’ll have to update the docs to call this out.

#9

adamrifat

When I bulk edit and choose ‘Add Categories’ it does appear to add the category data to the exp_category_posts table as expected. Likewise, when I bulk edit and choose ‘Remove Categories’ it does seem to remove the category data as expected.

However, there are now issues with how the field works on the entry edit screen.

Firstly, I have two ACF fields assigned to my channel but the input name is missing in the html for the first field as shown below.

<input type="hidden" name="" value="206">
<input type="hidden" name="field_id_408" value="131">

This appears to be a regression and means that one of the fields doesn’t have any $postData in the before_channel_entry_save hook and so doesn’t save correctly.

Additionally, there seems to be an issue with the code that runs when $isAdd and $isRemove are true in the extension hook. After I bulk Remove Categories all the field data for the entry is missing from the channel_data_field_ table. See attached screenshot for how the field looks on the entry edit screen after the bulk removal of a category.

In $isRemove perhaps the field data needs to be json decoded before trying to remove the category id, I’m not sure.

Thanks.

#10

BoldMinded (Brian)

I added 2 fields to an entry and the HTML looks fine and they both saved fine.

https://www.dropbox.com/s/kpytdjwp2e5nym4/ticket-2640.png?dl=0

#11

adamrifat

Looks like you’re creating a new entry. The problem I’m seeing with the missing name attribute is happening for existing entries.

I reverted locally to version 1.0.0 of ACF (which is the version employed on prod) and the field name does indeed come through correctly so it does appear to be a regression. I’ll see if I can get any more information that might give us a clue on that one.

Did you manage to recreate the data corruption with the bulk edit remove categories?

At this point I’m thinking to uninstall ACF, doing the bulk edits and then setting up the fields again.

#12

BoldMinded (Brian)

The field html looks fine and the field values save fine for me when editing an entry too. For the field that is not rendering the correct html, what do field settings look like? Also those are React fields… are there any JS errors in your console?

#13

BoldMinded (Brian)

Comment has been marked private.

#14

adamrifat

Thanks, I installed the above build and the field is broken when I go to the edit screen.

I checked the console and I see an error as follows:

Uncaught TypeError: fieldSettings is null
    <a>/admin.php?/cp/publish/edit/entry/19303:3220
    jQuery 8
        i
        fireWith
        ready
        J
        promise
        <a>
        <a>
        <a>
admin.php:3220:13
    <a>/admin.php?/cp/publish/edit/entry/19303:3220
    jQuery 8
// If any field on the page sets the Categories tab to hidden...
line 3220 -->    if (fieldSettings.hide_tab === 'y') { 
            $('.tab-bar--sticky button').each(function () {
                var $button = $(this);
                if ($button.text() === EE.lang.categories) {
                    $button.hide();
                }
            });
        }
#15

BoldMinded (Brian)

Did you try re-saving the field’s custom settings?

#16

BoldMinded (Brian)

I’ll include this in the next release, but this should fix it. Find the for loop on line 69 of the js file and add the if conditional:

for (var fieldName in EE.advancedCategories) {
        var fieldSettings = EE.advancedCategories[fieldName];

        // add me
        if (!fieldSettings) {
            return;
        }

       // If any field on the page sets the Categories tab to hidden...
       if (fieldSettings.hide_tab === 'y') {

Login to reply