• Plugin Author David Cavins

    (@dcavins)


    HI Boone-

    I need to bulk create many, many bp-docs as an import from an old system. Would you suggest making POST requests to BP_Docs_Query::save as the best option? It looks like I could set the title and content easily enough, but setting the author and uploading attachments maybe not so much.

    Or is there another method that would be better?

    Thanks for your advice,

    -David

    http://wordpress.org/plugins/buddypress-docs/

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

    (@boonebgorges)

    Hi David – It’s going to be a bit tricky. I guess it partially depends on how your import data is structured. A couple suggestions:

    – I’d do this all in PHP. Don’t try to fake the front-end using POST requests. This’ll be a nightmare.
    – Go ahead and use the BP_Docs_Query::save() method, but it’s poorly written, so you’ll have to do some ugly stuff. In particular, you’ll need to look for the places where it’s looking in $_POST and fake that on your end. So,

    foreach ( $docs_to_insert as $doc ) {
        $_POST = array();
        $_POST['doc_content'] = $doc['content'];
        $_POST['associated_group_id'] = $doc['group_id'];
    }

    etc.

    – You can either filter the logged in user id, or you can just switch it after creation, using the $doc_id that you get back from the save method. I’d suggest the latter.

    – Attachments are going to be a bit of a bear. I guess I’d suggest putting the source files in a directory accessible from your PHP script (which I guess would be structured as a WP plugin), and then using WP’s sideload functionality (in particular, wp_handle_sideload()) to move stuff around. You’ll probably need to manually add some of the filters in buddypress-docs/includes/attachments.php to ensure that wp_upload_dir() gets filtered correctly, and your files go to the correct place.

    Hopefully that’s a good starting point. Good luck!

    Plugin Author David Cavins

    (@dcavins)

    Hi Boone-

    Thanks for the prompt response and for pointing me in the right direction. I think it’ll be a straight-up hootenanny. bp_docs_create_doc, here we go!

    Thanks again,

    -David

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bulk creating new docs’ is closed to new replies.