Skip to content

Commit

Permalink
#17 Adding unit tests and code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
hughdevore committed Aug 14, 2017
1 parent e703053 commit 7e4aba7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Type/MediaItem/Mutation/MediaItemCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public static function mutate( \WP_Post_Type $post_type_object ) {
}

/**
* Set the file name, whether it's a local file or from a URL
* Set the file name, whether it's a local file or from a URL.
* Then set the url for the uploaded file
*/
$file_name = basename( $input['filePath'] );
$uploaded_file_url = $input['filePath'];

/**
* Check if the download_url method exists and include it if not
Expand All @@ -81,9 +83,6 @@ public static function mutate( \WP_Post_Type $post_type_object ) {
if ( 'file' === parse_url( $input['filePath'], PHP_URL_SCHEME) ) {
$uploaded_file = wp_upload_bits( $file_name, null, file_get_contents( $input['filePath'] ) );
$uploaded_file_url = $uploaded_file['url'];
} else {
update_option('hd_local_file_invalid_url', $input['filePath'] );
$uploaded_file_url = $input['filePath'];
}

/**
Expand Down Expand Up @@ -144,8 +143,9 @@ public static function mutate( \WP_Post_Type $post_type_object ) {
* Stop now if a user isn't allowed to edit the parent post
*/
// Attaching media to a post requires ability to edit said post.
if ( ! empty( $attachment_parent_id ) ) {
$parent = get_post( $attachment_parent_id );
$parent = get_post( $attachment_parent_id );

if ( null !== get_post( $attachment_parent_id ) ) {
$post_parent_type = get_post_type_object( $parent->post_type );
if ( ! current_user_can( $post_parent_type->cap->edit_post, $attachment_parent_id ) ) {
throw new \Exception( __( 'Sorry, you are not allowed to upload mediaItems to this post', 'wp-graphql' ) );
Expand Down

0 comments on commit 7e4aba7

Please sign in to comment.