• Resolved christopher51

    (@christopher51)


    Does anyone have a working example of the bulk-import found in the cookbook? The example does not seem to do anything even after changing the paths for my environment. It runs up to the point where the loop begins but stops without error.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor nwjames

    (@nwjames)

    @christopher51,
    Even though I am the last person to have updated this module just to meet the WP coding standard, I have never executed it previously.

    However I did so today in response to your note. I edited the file to contain absolute paths for both wp-load.php and the file directory.

    I then executed php bulk-import.php

    It worked. That is, I had put two PDF documents into the folder – and it created two PDF documents that I could acess as documents.

    At one level, that’s the good news.

    However, there are a number of issues around this that need to be resolved.

    If I tried calling the module from the browser, then I got a 404 error. That is why I called it directly using php.

    Since it will upload all files with the given extension in the import folder, then it is, by definition, a staging folder. It needs to copy the file from the source directory into the document folder probably with a year/month addition.

    It probably should delete the file from the staging folder once successfully uploaded.

    Hope this information is of use.

    Also ordinarily the file loaded is obscured into a MD5 format name. This is not done here.

    Hope this is of use,
    Neil James

    Plugin Contributor nwjames

    (@nwjames)

    @christopher51,
    I don’t know if you have now had success, or whether you are still interested to get this working..

    First of all, by putting the file into the root directory, the issue with Error 494 goes away and it can be run via the browser.

    I have placed a version of the module on my GitHub clone at https://github.com/NeilWJames/WP-Document-Revisions-Code-Cookbook which may be of use if you wish to progress this.

    If you do use and find issues, please can you raise issues.

    It wordks with WPDR 3.4.0 which must be present in the plugin library and uses a number of functions from that codebase to avoid putting code directly here that can get out of date over time. However the result is that the documents are loaded consistent with WPDR rules.

    Hope this is of use,
    Neil James

    Thread Starter christopher51

    (@christopher51)

    @nwjames

    Thanks for the help and direction on this. When I run the file from the command line I am getting an error: Unable to load dynamic library ‘php_imagick.dll’

    Does this script use this plugin or does this look to be an issue with the environment I’m working in?

    Plugin Contributor nwjames

    (@nwjames)

    @christopher51,
    Thank you very much for running this.

    The strict answer is that there is no plugin involved. However what is happening is that when the WP media loader loads a file, for PDFs it can also create a jpeg image of page 1 of your document. To do this, it will use this dynamic library.

    The problem that the code is trying to solve is that the plugin hides from all public view the name of the file as held in file system so that the file cannot be extracted directly. But this standard WP processing creates a thumbnail that uses the encoded file name, i.e. X.pdf has an image called X-pdf.jpg. And if the image is able to be used, then of necessity this name needs to be publicly available – and hence will expose the file name. Hence the code changes the name of the image files.

    Now within the WP function wp_generate_attachment_metadata it does make a call to WP function wp_get_image_editor( $file ) which is supposed to find out the editor that you have to convert a PDF file into a JPEG. This is normally Imagick.

    Meanwhile I have investigated why there was a difference in this processing – and where it was being called. It turns out that I used a call wp_handle_upload. I should have used media_handle_upload (which calls wp_handle_upload, and more importantly the wp_generate_attachment_metadata call).

    This removes a lot of this coding.

    I have removed the “belt and braces” approach of explicitly calling the metadata call so it uses the same logic as underlying WP. This ought to remove your error message.

    I have updated the code in the GitHub repository and would be grateful if you could see if this version is better.

    Regards,
    Neil James

    Thread Starter christopher51

    (@christopher51)

    Thank you, Neil. I appreciate your time on this.

    I pulled down the latest but the bulk-import file looks the same. Could you point me to the repo that was updated?

    Regards,
    Chris.

    Plugin Contributor nwjames

    (@nwjames)

    @christopher51,
    It’s here:
    https://github.com/NeilWJames/WP-Document-Revisions-Code-Cookbook/blob/master/bulk-import.php

    The last update comment is `Make use of media_handle_upload to simplify code.

    Hope this is of use,
    Neil James

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