• Resolved Cassie

    (@cassiedong)


    Hi,

    The changes to the database cannot be saved for some reason. The table detected how many changes I’ve made, but when I clicked on “Save (xx) Changes”, it doesn’t update the database and there is no error message. I even checked the Console and no js error is detected, although it does look like it’s sending empty data via ajax. Can you please help?

    The rest of the plugin works like a charm, thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author bobbysmith007

    (@bobbysmith007)

    I have not had any reports like this before, so I am not sure what to suggest (usually I say look in the js-console, network tab and monitor the request etc.) Does this happen on all dbte instances or only one? If its sending a blank request, it definitely will not save any changes.

    The request params for the save action should look like:

    
    action:dbte_save
    data:{"modifiedIdxs":[[2,3]],"columns":["the_date","entered_ts","entered_dt","name","id"],"rows":[{"0":"2015-11-13 00:00:00","1":"2015-11-14 00:00:00","2":"2015-11-22 00:00:00","3":"more than stuff","4":"10","5":null,"id":"10","dirty":true,"modifiedIdxs":[2,3]}]}
    page:dbte_dbte_test
    table:dbte_test
    

    The response is generally an empty array []

    Perhaps if you post the basic table config I will spot something. Usually editing errors have been related to the table not having an id column (or one configured by a different name) or by the current user not having edit permissions.

    Thread Starter Cassie

    (@cassiedong)

    Hi @bobbysmith007, thanks for your prompt reply!

    Yeah there is definitely an issue then. I’ve defined the id column (see below) and it’s allowing me to make edits, but it’s just not saving the updates to the database.

    if(function_exists('add_db_table_editor')){ 
    
    add_db_table_editor(array( 'title'=>'Room Rates', 'table'=>'rates', 'id_column' => 'rate_id','sql'=>'SELECT rate_id, nights.number_of_nights,checkin, checkout, two_share, extra_adult, extra_child, infant, rhd.hot_deal_id, rin.inclusion_id FROM rates JOIN booking_dates USING (booking_date_id) JOIN number_of_nights nights USING (number_of_night_id) LEFT JOIN rates_hot_deals rhd USING (rate_id) LEFT JOIN rates_inclusions rin USING (rate_id)', 'cap' => 'manage_options', 'editcap' => 'manage_options' ));
    
    }

    Would be great to get this resolved so we can start using the plugin.

    Thanks.

    Thread Starter Cassie

    (@cassiedong)

    By the way I’ve tested it using a simpler SQL and is having the same issue:

    add_db_table_editor(array( 'title'=>'Hot Deals', 'table'=>'hot_deals', 'id_column' => 'hot_deal_id','sql'=>'SELECT * FROM hot_deals', 'cap' => 'manage_options', 'editcap' => 'manage_options' ));

    Plugin Author bobbysmith007

    (@bobbysmith007)

    If it is sending a blank request it should almost certainly be a client side error. You will probably have better luck debugging this than I because I have not been able to recreate this bug.

    Does the console report that the save succeeded or failed? Can you copy and paste the request headers and parameters and response here please?

    You could also try redefining DBTableEditor.save to have more logging by pasting this into the console before clicking the save button:

    
    DBTableEditor.save = function(){
      console.log("DBTE Save");
      if (Slick.GlobalEditorLock.isActive() && !Slick.GlobalEditorLock.commitCurrentEdit())
        return;
      jQuery('button.save').attr("disabled", "disabled");
      var src = jQuery('button.save img').attr('src');
      jQuery('button.save img').attr('src',src.replace('accept.png','loading.gif'));
    
      // the last time we modified a row should contain all the final modifications
      var it,h = {},i,r, toSave=[], rows=[], mod = DBTableEditor.modifiedRows.slice(0), modified;
      while(( r = mod.pop() )){
        var column = DBTableEditor.data.columns[r.cell];
        // console.log(column, r.cell);
        if(column && column.isDate){
          r.item[r.cell-1] = DBTableEditor.toISO8601(r.item[r.cell-1], true);
          //console.log('Saving date',  r.item, r.cell, column, r.item[r.cell-1]);
        }
    
        // cells have a delete idx to be removed
        if((it = h[r.item.id])){
          it.modifiedIdxs.push(r.cell-1);
          continue;
        }
        r.item.modifiedIdxs = [r.cell-1];
        h[r.item.id] = r.item;
        // the extend ensures we send object json which includes ".id"
        // instead of array json which elides it
        toSave.push(jQuery.extend({}, DBTableEditor.default_values, r.item));
        rows.push(r.item);
      }
      console.log('We are trying to save: ', toSave);
      var cols = DBTableEditor.data.columns.map(function(c){return c.originalName;});
      cols.shift(); // remove buttons
      var toSend = JSON.stringify({
        modifiedIdxs:toSave.map(function(it){return it.modifiedIdxs;}),
        columns:cols,
        rows:toSave
      });
      console.log('Firing Request');
      jQuery.post(ajaxurl,
                  jQuery.extend({},DBTableEditor.query,DBTableEditor.hashQuery,
                                {action:'dbte_save',
                                 data:toSend,
                                 table:DBTableEditor.id}))
        .success(DBTableEditor.makeSaveCB(rows))
        .error(DBTableEditor.saveFailCB);
    
    };
    
    Plugin Author bobbysmith007

    (@bobbysmith007)

    By the way, your add_db_table_editor calls look reasonable to me, I dont spot anything that seems odd.

    Plugin Author bobbysmith007

    (@bobbysmith007)

    Any luck finding the issue, or getting a log of the network request?

    Thanks for helping debug this

    Thread Starter Cassie

    (@cassiedong)

    Hi @bobbysmith007, thanks so much for the followup. I’m still unable to save changes to the database unfortunately. I’ve updated the DBTableEditor.save function as per your instructions and this is what I’ve got in the console log:

    DBTE Save
    We are trying to save: Array[1]0: Object0: “5”1: “1”2: “2017-06-25″3: “2017-07-15″4: “195”5: “134”6: “98”7: “25”8: “11”9: “6”10: nulldirty: trueid: “5”modifiedIdxs: Array[1]__proto__: Objectlength: 1__proto__: Array[0]concat: concat()constructor: Array()copyWithin: copyWithin()entries: entries()every: every()fill: fill()filter: filter()find: find()findIndex: findIndex()forEach: forEach()includes: includes()indexOf: indexOf()join: join()keys: keys()lastIndexOf: lastIndexOf()length: 0map: map()pop: pop()push: push()reduce: reduce()reduceRight: reduceRight()reverse: reverse()shift: shift()slice: slice()some: some()sort: sort()splice: splice()toLocaleString: toLocaleString()toString: toString()unshift: unshift()Symbol(Symbol.iterator): values()Symbol(Symbol.unscopables): Object__proto__: Object
    Firing Request
    Save Success Array[0]length: 0__proto__: Array[0]

    Is it possible to send you the login to our website so you can have a look? Do you have an email address that we can send the details to?

    Thanks!

    Plugin Author bobbysmith007

    (@bobbysmith007)

    Thanks for the reply. My email address is the same as my username at gmail.com. I will login and see if I can spot whats happening if you send me a login.

    Cheers,
    Russ

    I would like to give this db editor a go but I don’t really have the time to figure out how to integrate it. Do you have a decent example of how I can get an editor working for one table?

    I had the no-save problem with another db editor. I am pretty sure that the cause was the MySQL setting ‘secure_file_priv’. This can only be set in the my.ini; and cannot be set dynamically. Use ‘SHOW VARIABLES LIKE “secure_file_priv”‘ to see what your current setting is. I think you need to remove the setting value and try again with the save.

    Hope that works.

    Plugin Author bobbysmith007

    (@bobbysmith007)

    As in the README:

    if(function_exists('add_db_table_editor')){
      add_db_table_editor('title=Employees&table=employees');
    
      add_db_table_editor(array(
        'title'=>'Event Registrations',
        'table'=>'event_registrations',
        'sql'=>'SELECT * FROM event_registrations ORDER BY date_entered DESC'
      ));
    
    }

    If tables dont have an id column you will need to specify which is hte “id_col” or add an id column
    —-

    Actually I believe we resolved this over email (she gave me access to her website). Just forgot to follow up here :).

    The problem ended up being that a column that was not updateble on the table was included. I believe the resolution was to add that column to the “noedit_columns” list

    Thanks for the advice

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Having trouble saving changes’ is closed to new replies.