Skip to content

Commit

Permalink
💡 Got it! Add some episode-validity checks in validating module
Browse files Browse the repository at this point in the history
fixes #107
fixes #137
  • Loading branch information
eteubert committed Jul 6, 2013
1 parent 481adfe commit 38a4c32
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
27 changes: 27 additions & 0 deletions lib/model/episode.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,33 @@ public function delete_caches() {

}

/**
* Check for basic validity.
*
* - MUST have an existing associated post
* - associated post MUST be of type 'podcast'
* - MUST NOT be deleted/trashed
*
* @return boolean
*/
public function is_valid() {

$post = get_post( $this->post_id );

if ( ! $post )
return false;

// skip deleted podcasts
if ( ! in_array( $post->post_status, array( 'draft', 'publish', 'pending', 'future' ) ) )
return false;

// skip versions
if ( $post->post_type != 'podcast' )
return false;

return true;
}

}

Episode::property( 'id', 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY' );
Expand Down
8 changes: 5 additions & 3 deletions lib/modules/asset_validation/asset_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ public function do_valiations() {

private function validate_post( \WP_Post $post ) {
$episode = Model\Episode::find_or_create_by_post_id( $post->ID );
Log::get()->addInfo( 'Validate episode', array( 'episode_id' => $episode->id ) );
$episode->refetch_files();
update_post_meta( $post->ID, '_podlove_last_validated_at', time() );
if ( $episode && $episode->is_valid() ) {
Log::get()->addInfo( 'Validate episode', array( 'episode_id' => $episode->id ) );
$episode->refetch_files();
update_post_meta( $post->ID, '_podlove_last_validated_at', time() );
}
}

/**
Expand Down
10 changes: 1 addition & 9 deletions lib/settings/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,7 @@ public static function validate_podcast_files() {
$post_id = $episode->post_id;
$post = get_post( $post_id );

if ( ! $post )
continue;

// skip deleted podcasts
if ( ! in_array( $post->post_status, array( 'draft', 'publish', 'pending', 'future' ) ) )
continue;

// skip versions
if ( $post->post_type != 'podcast' )
if ( ! $episode || ! $episode->is_valid() )
continue;
?>
<tr>
Expand Down

0 comments on commit 38a4c32

Please sign in to comment.