How to save log massage when update datable?

How to save log massage when update datable?

t3631867t3631867 Posts: 5Questions: 2Answers: 0
edited April 2016 in Free community support

I want to log who update the table info, so I try to log msg when datatable updating.

I put the log code in Editor.php as below, but it's not work.

private function _update( $id, $values )
    {
        $id = str_replace( $this->_idPrefix, '', $id );

        // Update or insert the rows for the parent table and the left joined
        // tables
        $this->_insert_or_update( $id, $values );

        // And the join tables
        for ( $i=0 ; $i<count($this->_join) ; $i++ ) {
            $this->_join[$i]->update( $this, $id, $values );
        }

        // Was the primary key altered as part of the edit? Unusual, but it is
        // possible
        $pkeyField = $this->_find_field( $this->_pkey, 'name' );
        $getId = $pkeyField && $pkeyField->apply( 'edit', $values ) ?
            $pkeyField->val( 'set', $values ) :
            $id;

        // Full data set for the modified row
        $row = $this->_get( $getId );
        $row = count( $row['data'] ) > 0 ?
            $row['data'][0] :
            null;

        $this->_trigger( 'postEdit', $id, $values, $row );

        // ********** my log message **********
        $f=fopen("mylog_update_product.txt","a+");
        $str="";
                $str.="id     = ".$id."\r\n";
                $str.="values = ".$values[0]."\r\n";
                $str.="================================================"."\r\n";      
                fwrite($f, $str);
                fclose($f);
                // ********** END my log message **********

        return $row;
    }

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,281Questions: 1Answers: 10,425 Site admin
    Answer ✓

    I would strongly suggest you don't put it into Editor.php - use the postEdit server-side event instead.

    See also this blog post on the topic.

    The reason not to modify Editor.php is that when you update to future versions, you'll need to patch your copy every time!

    Regards,
    Allan

  • t3631867t3631867 Posts: 5Questions: 2Answers: 0

    got it. thank's your hint.
    I can log update message now!

This discussion has been closed.