mikessthreat
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: XML-RPC MetaWeblog newMediaObject overwrite problemHi, I still seem to be having an issue with files not being removed from the filesystem whenever specifying overwrite to be true (and this is with v2.7.1 and WP Mu). I’m running WP Mu against a MySQL 5.1 database (which does not exhibit the -1 issue discussed above because the -1 is automatically converted to a 0 due to a default value on the column in question). I also did not see anything related to file overwriting in your issue tracker.
Steps to reproduce:
1. Create a new media object via XML-RPC.
2. Attempt to create the same media object via XML-RPC with overwrite=true
3. Notice in the uploads directory there are 2 files when there should be 1.Forum: Fixing WordPress
In reply to: XML-RPC MetaWeblog newMediaObject overwrite problemAh, thank you for the response. I’ll be sure to look in the issue tracker first next time.
Forum: Fixing WordPress
In reply to: XML-RPC MetaWeblog newMediaObject overwrite problemI believe the following code is causing this problem:
if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) { // Get postmeta info on the object. $old_file = $wpdb->get_row(" SELECT ID FROM {$wpdb->posts} WHERE post_title = '{$name}' AND post_type = 'attachment' "); // Delete previous file. wp_delete_attachment($old_file->ID); // Make sure the new name is different by pre-pending the // previous post id. $filename = preg_replace("/^wpid\d+-/", "", $name); $name = "wpid{$old_file->ID}-{$filename}"; } $upload = wp_upload_bits($name, $type, $bits); if ( ! empty($upload['error']) ) { $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']); logIO('O', '(MW) ' . $errorString); return new IXR_Error(500, $errorString); } // Construct the attachment array // attach to post_id -1 $post_id = -1; $attachment = array( 'post_title' => $name, 'post_content' => '', 'post_type' => 'attachment', 'post_parent' => $post_id, 'post_mime_type' => $type, 'guid' => $upload[ 'url' ] ); // Save the data $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id ); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
Notice that the $post_id here is being set to -1. I believe this is incorrect because whenever I upload an image via the WP GUI, the post_parent field is set to 0.
Using metaWeblog.newMediaObject does not result in any record being created in the wp_posts table using the -1 parent post value. However, I tried changing that to 0 (xmlrpc.php line 2877 in version 2.8.4 of WP) and a record in the wp_posts table is now being created. I have yet to verify that a file is correctly overwritten when using overwrite=true using the XMLRPC call; but I’m guessing since there’s an actual record in the database pointing to the uploaded image, that it will be properly overwritten when wp_delete_attachment() is called.