public static function fix_duplicate_contributions()
 {
     global $wpdb;
     $contributions = self::find_duplicate_episode_contributions();
     if (!is_array($contributions) || empty($contributions)) {
         Repair::add_to_repair_log(__('Contributions did not need repair', 'podlove'));
         return;
     }
     foreach ($contributions as $contribution) {
         $sql = "\n\t\t\t\tDELETE FROM\n\t\t\t\t\t" . \Podlove\Modules\Contributors\Model\EpisodeContribution::table_name() . "\n\t\t\t\tWHERE\n\t\t\t\t\tid != " . $contribution['id'] . "\n\t\t\t\t\tAND `contributor_id` = \"" . $contribution['contributor_id'] . "\"\n\t\t\t\t\tAND `episode_id` = \"" . $contribution['episode_id'] . "\"\n\t\t\t\t\tAND `role_id` = \"" . $contribution['role_id'] . "\"\n\t\t\t\t\tAND `group_id` = \"" . $contribution['group_id'] . "\"\n\t\t\t\t";
         $wpdb->query($sql);
         $ec = \Podlove\Modules\Contributors\Model\EpisodeContribution::find_by_id($contribution['id']);
         $ec->save();
         // recalculates contribution count
     }
     Repair::add_to_repair_log(sprintf(_n('Deleted 1 duplicate contribution', 'Deleted %s duplicate contributions', count($contributions), 'podlove'), count($contributions)));
 }
 public function delete_episode_contributor()
 {
     $object_id = (int) $_REQUEST['object_id'];
     if (!$object_id) {
         return;
     }
     if ($service = EpisodeContribution::find_by_id($object_id)) {
         $service->delete();
     }
 }