Mass delete not working for 1000+ records

Mass delete not working for 1000+ records

Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

I have a problem when deleting many records at once. The following code works fine if 100 or 500 or 998 records are selected, however as soon as 999 records are selected I get the following error in the debug console:

Notice</b>: Undefined index: user_id in <b>/home/public_html/uploads/js/datatables/php/table.cms_module_tps_userlisting.php</b> on line <b>64</b>

Line 64 refers to my filter where I only show certain records.

->where( 'user_id', $_POST['user_id'] )

The full code looks like this,

Editor::inst( $db, 'cms_module_tps_userlisting', 'list_id' )
    ->fields(
        Field::inst( 'listphone' ),
        Field::inst( 'create_date' )
        ->getFormatter( 'Format::date_sql_to_format', 'd/m/Y \a\t H:i' ),
        Field::inst( 'checkcode' )
        ->getFormatter( function ( $val ) {
        $code = array('EDNP', 'ENUM', 'DUPNO', 'VALID');
        $real = array('<span class="red">DO NOT CALL</span>', '<span class="yellow">INCORRECT FORMAT</span>', '<span class="grey">DUPLICATE NUMBER</span>', '<span class="green">VALID</span>');
            return str_replace( $code, $real, $val );
        }),
        Field::inst( 'registered_with_tps' )
                ->getFormatter( function ($val, $data, $field) {
                if ($val == '0000-00-00 00:00:00') return "-";
                else if ($val <> '0000-00-00 00:00:00')
                $val = date("d/m/Y \a\t H:i", strtotime($val));
                return $val;
                })
    )
    ->where( 'user_id', $_POST['user_id'] )
    ->process( $_POST )
    ->json();

Why is this error occurring, does anyone have any ideas why the select all delete with this filter is limited to 999 records? Is the maximum number of records you can delete with a where filter 999?

Thanks

Chris

Replies

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    On further investigation it seems the problem is not related to the where filter. If I remove the filter then the error no longer appears however, still only a maximum of 999 records are deleted simultaneously. I have checked the mysql settings and there seems to be no limitation in the settings. Surely it is possible to delete more than 999 records at once?

    Editor::inst( $db, 'cms_module_tps_userlisting', 'list_id' )
        ->fields(
            Field::inst( 'listphone' ),
            Field::inst( 'create_date' ),
            Field::inst( 'checkcode' ),
            Field::inst( 'registered_with_tps' )
        )
        ->process( $_POST )
        ->json();
    
  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    I found the problem. PHP introduced in version 5.3.9 a new configuration variable called max_input_vars with default setting is 1000. So only the first 1000 variables are read from POST and GET.

    PHP introduced this, because there is an attack vector, to be precious a Denial of Service vector to shut down PHP. This happens, because PHP calculates hashes to store "array" values in a hash map. If the hash already exists, it is recalculated. If this hash already exists, it is rerecalulcated and so on.

    So to fix this problem, you can change the php.ini with max_input_vars = 10000; or whatever number you require.

  • allanallan Posts: 61,787Questions: 1Answers: 10,115 Site admin

    Hi,

    Reading through your thread I was wondering if there was a PHP limitation somewhere, but I didn't know about max_input_vars. Thanks for posting back your solution - I'll keep this in mind should anyone else ask about this in future!

    Regards,
    Allan

This discussion has been closed.