• Resolved nuancedesignstudio

    (@nuancedesignstudio)


    Hi,

    Thank you for this great plugin.
    How can I get the old value of the update query.

    Basically I have a custom function like this

    add_action(‘dbte_row_updated’, ‘my_seat_row_upserted’, 10, 4);
    add_action(‘dbte_row_inserted’, ‘my_seat_row_upserted’, 10, 4);
    function my_seat_row_upserted($currentTable, $values, $columns, $indexedModified) …

    Now I want to keep a record the old values but there is no way to see the old values in my case. The $values variable shows the new values.

    Please do let me know how I can achieve this?

    Regards,
    Karan

    https://ww.wp.xz.cn/plugins/wp-db-table-editor/

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

    (@bobbysmith007)

    It sounds like you are trying to create a data journal.

    * Why not just use the new values? Assuming you are always journaling, the old values will be in the journal?
    * You could hook add_action( 'wp_ajax_dbte_save', 'dbte_save_cb' ); with higher priority than the plugin and then query the database before the change.
    * You could submit a patch that adds a “before_save” action, though the plugin never queryies the old values, before saving, so your code would still need to do that (negating much of the benefit the action might provide).
    * https://github.com/AccelerationNet/wp-db-table-editor

    Thread Starter nuancedesignstudio

    (@nuancedesignstudio)

    Great. I just needed to know how to get to the row before the plugin makes the change. I just need to get the primary_key. This is how I did it in case any one wants to do something similar (it’s from the gist: https://github.com/AccelerationNet/wp-db-table-editor)

    add_action( 'wp_ajax_dbte_save', 'my_before_dbte_save_cb', 1 );
    function my_before_dbte_save_cb()
    {
        global $wpdb;
        $d = $_REQUEST['data'];
        $tbl= $_REQUEST['table'];
        $cur = dbte_current($tbl);
        $d = json_decode(htmlspecialchars_decode(stripslashes($d)), true);
        $rows = @$d["rows"];
        foreach($rows as $row)
        {
            $primary_key_of_row = $row[id];
        }
    	//do something with $primary_key_of_row
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Capture OLD values before update/delete’ is closed to new replies.