BUG dbClean on FileUpload (many) delete all files

BUG dbClean on FileUpload (many) delete all files

marcobamarcoba Posts: 8Questions: 1Answers: 0

am i wrong or this bug is still here?

https://datatables.net/forums/discussion/39326/deleting-files-while-using-dte-file-upload-many

PS. "An error occurred while moving the uploaded file." is shown when trying to upload something on public example pages for file upload
https://editor.datatables.net/examples/advanced/upload.html
https://editor.datatables.net/examples/advanced/upload-many.html

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Apologies for the error on the examples - I had a permissions error due to a recent upgrade. Resolved now.

    I'm afraid it looks like the Mjoin upload many with db clean is still a problem. I've got it logged to address it for 1.7.3 which I expect to release next week. Thanks for pointing that out!

    Allan

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    I've been digging into this before the 1.7.3 release (a little delayed from when I'd hoped!). There is actually code to allow for this in 1.7.2 - what you need to do is pass information about the table / field which contains the information about the files which are in use to the dbClean() method:

                            ->dbClean( 'users_files.file_id', function ( $files ) {
                                print_r( $files );
                            })
    

    Outside of the Mjoin it is possible to derive the name of the table and field that should be used for the check to see if a file is in use, but that isn't so easy with an Mjoin, hence the need to specify the table and field as the first parameter to the dbClean method.

    Allan

  • marcobamarcoba Posts: 8Questions: 1Answers: 0

    should we consider this as solved in the relased 1.7.3?

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    It should actually work in 1.7.2 as well. It didn't require any specific changes in 1.7.3 - you just need to make sure that you pass the table and field name in the first parameter to dbClean.

    Allan

  • marcobamarcoba Posts: 8Questions: 1Answers: 0

    oh ok so we still need to pass the table name in 1.7.3

    Thanks

  • coderxcoderx Posts: 45Questions: 7Answers: 0

    Hello Allan,

    I downloaded version 1.7.3.

    I was just trying to get to work your code from March 13:

    ->dbClean( 'users_files.file_id', function ( $files ) {
        print_r( $files );
    })
    

    But I am not able to figure it out. :(

    I might be missing something small, but just to be sure, could you provide me with working code example?

    ->dbClean( 'files.id', function ( $files ) { // fyi pivot table is files_links
        // Remove the files from the file system
        for ( $i=0, $ien=count($files) ; $i<$ien ; $i++ ) {
            unlink( $files[$i]['system_path'] );
        }
    
        // Have Editor remove the rows from the database
        return true;
    
        //print_r( $files ); // This did not return anything in my case.
    })
    
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    The example I gave above will work in the Mjoin upload example.

    Could you clarify in what way it isn't working for you? Any error messages? Can you link to a page showing the issue?

    Allan

  • marcobamarcoba Posts: 8Questions: 1Answers: 0

    @coderx probably you are specifing the wrong table field: you have to specify the table field that is doing the (multi) record->file_id binding and not the table that is storing all files infos

  • coderxcoderx Posts: 45Questions: 7Answers: 0

    @marcoba, thank you very much for your comment, exactly this was my problem. I was specifying table storing all files data.

    @allan, I apologize, the example you provided, works very well. There was unfortunate naming convention on my side and I did not use pivot table.

This discussion has been closed.