Permalink
Browse files

Fixed Relationship Bug on Blog delete

  • Loading branch information...
1 parent e5206d4 commit 7c3f3078b15bf15ac27c503636fd2c8f4846c19a @dasllama dasllama committed Feb 23, 2012
Showing with 50 additions and 13 deletions.
  1. +6 −8 inc/class-Mlp_Default_Module.php
  2. +44 −5 multilingual-press.php
@@ -229,7 +229,7 @@ public function save_blog_settings_form_fields( $data ) {
update_site_option( 'inpsyde_multilingual', $siteoption );
// Custom flag URL
- if ( ISSET( $data[ 'inpsyde_multilingual_flag_url' ] ) )
+ if ( isset( $data[ 'inpsyde_multilingual_flag_url' ] ) )
update_blog_option( $current_blog_id, 'inpsyde_multilingual_flag_url', esc_url( $data[ 'inpsyde_multilingual_flag_url' ], array( 'http' ) ) );
// Update blog relationships
@@ -241,10 +241,9 @@ public function save_blog_settings_form_fields( $data ) {
// The user defined new relationships for this blog. We add it's own ID
// for internal purposes
- $data[ 'related_blogs' ][ ] = $current_blog_id;
+ $data[ 'related_blogs' ][] = $current_blog_id;
$new_rel = $data[ 'related_blogs' ];
- //@TODO: unchanged settings?
// Loop through related blogs
foreach ( $all_blogs as $blog_id => $blog_data ) {
@@ -262,12 +261,11 @@ public function save_blog_settings_form_fields( $data ) {
$key = array_search( $current_blog_id, $current_rel );
if ( in_array( $blog_id, $new_rel ) ) {
-
// Connect these blogs, if not already.
- if ( FALSE === $key ) {
- $current_rel[ ] = $current_blog_id;
- }
- } else {
+ if ( FALSE === $key )
+ $current_rel[] = $current_blog_id;
+ }
+ else {
@nullbytes

nullbytes Feb 23, 2012

Owner

nach der neuen regel soll es } else { sein

// These blogs should not be connected. Delete
// possibly existing connection
if ( FALSE !== $key && ISSET( $current_rel[ $key ] ) )
View
@@ -504,7 +504,6 @@ public function save_post( $post_id ) {
if ( 'on' != $_POST[ 'translate_this_post' ] )
return;
-
// Get the post
$postdata = get_post( $post_id, ARRAY_A );
@@ -974,13 +973,53 @@ protected function get_module_state( $module ) {
public function delete_blog( $blog_id ) {
global $wpdb;
-
+
+ $current_blog_id = $blog_id;
+
+ // Update Blog Relationships
+ // Get blogs related to the current blog
+ $all_blogs = get_site_option( 'inpsyde_multilingual' );
+
+ if ( ! $all_blogs )
+ $all_blogs = array( );
+
+ // The user defined new relationships for this blog. We add it's own ID
+ // for internal purposes
+ $data[ 'related_blogs' ][] = $current_blog_id;
+ $new_rel = $data[ 'related_blogs' ];
+
+ // Loop through related blogs
+ foreach ( $all_blogs as $blog_id => $blog_data ) {
+
+ if ( $current_blog_id == $blog_id )
+ continue;
+
+ // 1. Get related blogs' current relationships
+ $current_rel = get_blog_option( $blog_id, 'inpsyde_multilingual_blog_relationship' );
+
+ if ( ! is_array( $current_rel ) )
+ $current_rel = array();
+
+ // 2. Compare old to new relationships
+ // Get the key of the current blog in the relationships array of the looped blog
+ $key = array_search( $current_blog_id, $current_rel );
+
+ // These blogs should not be connected. Delete
+ // possibly existing connection
+ if ( FALSE !== $key && isset( $current_rel[ $key ] ) )
+ unset( $current_rel[ $key ] );
+
+ // $current_rel should be our relationships array for the currently looped blog
+ update_blog_option( $blog_id, 'inpsyde_multilingual_blog_relationship', $current_rel );
+ }
+
// Update site_option
$blogs = get_site_option( 'inpsyde_multilingual' );
- if ( array_key_exists( $blog_id, $blogs ) )
- unset( $blogs[ $blog_id ] );
+ if ( array_key_exists( $current_blog_id, $blogs ) )
+ unset( $blogs[ $current_blog_id ] );
+
update_site_option( 'inpsyde_multilingual', $blogs );
-
+
// Cleanup linked elements table
$error = $wpdb->query( $wpdb->prepare( "DELETE FROM {$this->link_table} WHERE ml_source_blogid = %d OR ml_blogid = %d", $blog_id, $blog_id ) );
}

0 comments on commit 7c3f307

Please sign in to comment.