コード例 #1
0
 function deleted_post($post_id)
 {
     foreach (P2P_Connection_Type_Factory::get_all_instances() as $p2p_type => $ctype) {
         foreach (array('from', 'to') as $direction) {
             if ('post' == $ctype->object[$direction]) {
                 p2p_delete_connections($p2p_type, array($direction => $post_id));
             }
         }
     }
 }
コード例 #2
0
ファイル: storage.php プロジェクト: ugurbastan/swe-574-group4
 static function deleted_object($object_id)
 {
     $object_type = str_replace('deleted_', '', current_filter());
     foreach (P2P_Connection_Type_Factory::get_all_instances() as $p2p_type => $ctype) {
         foreach (array('from', 'to') as $direction) {
             if ($object_type == $ctype->object[$direction]) {
                 p2p_delete_connections($p2p_type, array($direction => $object_id));
             }
         }
     }
 }
コード例 #3
0
 /**
  * After import has run, go back and connect all the posts.
  */
 public function wp_parser_ending_import()
 {
     if (defined('WP_CLI') && WP_CLI) {
         WP_CLI::log('Removing current relationships...');
     }
     p2p_delete_connections('functions_to_functions');
     p2p_delete_connections('functions_to_methods');
     p2p_delete_connections('functions_to_hooks');
     p2p_delete_connections('methods_to_functions');
     p2p_delete_connections('methods_to_methods');
     p2p_delete_connections('methods_to_hooks');
     if (defined('WP_CLI') && WP_CLI) {
         WP_CLI::log('Setting up relationships...');
     }
     // Iterate over post types being related FROM: functions, methods, and hooks
     foreach ($this->post_types as $from_type) {
         // Iterate over relationships for each post type
         foreach ((array) @$this->relationships[$from_type] as $from_id => $to_types) {
             // Iterate over slugs for each post type being related TO
             foreach ($to_types as $to_type => $to_slugs) {
                 // Convert slugs to IDs.
                 if (empty($this->slugs_to_ids[$to_type])) {
                     // TODO why might this be empty? test class-IXR.php
                     continue;
                 }
                 $this->relationships[$from_type][$from_id][$to_type] = $this->get_ids_for_slugs($to_slugs, $this->slugs_to_ids[$to_type]);
             }
         }
     }
     // Repeat loop over post_types and relationships now that all slugs have been mapped to IDs
     foreach ($this->post_types as $from_type) {
         foreach ((array) @$this->relationships[$from_type] as $from_id => $to_types) {
             // Connect Functions
             if ($from_type == $this->post_types['function']) {
                 foreach ($to_types as $to_type => $to_slugs) {
                     // ...to Functions
                     if ($this->post_types['function'] == $to_type) {
                         foreach ($to_slugs as $to_slug => $to_id) {
                             $to_id = intval($to_id, 10);
                             if (0 != $to_id) {
                                 p2p_type('functions_to_functions')->connect($from_id, $to_id, array('date' => current_time('mysql')));
                             }
                         }
                     }
                     // ...to Methods
                     if ($this->post_types['method'] == $to_type) {
                         foreach ($to_slugs as $to_slug => $to_id) {
                             $to_id = intval($to_id, 10);
                             if (0 != $to_id) {
                                 p2p_type('functions_to_methods')->connect($from_id, $to_id, array('date' => current_time('mysql')));
                             }
                         }
                     }
                     // ...to Hooks
                     if ($this->post_types['hook'] == $to_type) {
                         foreach ($to_slugs as $to_slug => $to_id) {
                             $to_id = intval($to_id, 10);
                             if (0 != $to_id) {
                                 p2p_type('functions_to_hooks')->connect($from_id, $to_id, array('date' => current_time('mysql')));
                             }
                         }
                     }
                 }
             }
             // Connect Methods
             if ($from_type === $this->post_types['method']) {
                 foreach ($to_types as $to_type => $to_slugs) {
                     // ...to Functions
                     if ($this->post_types['function'] === $to_type) {
                         foreach ($to_slugs as $to_slug => $to_id) {
                             $to_id = intval($to_id, 10);
                             if (0 != $to_id) {
                                 p2p_type('methods_to_functions')->connect($from_id, $to_id, array('data' => current_time('mysql')));
                             }
                         }
                     }
                     // ...to Methods
                     if ($this->post_types['method'] === $to_type) {
                         foreach ($to_slugs as $to_slug => $to_id) {
                             $to_id = intval($to_id, 10);
                             if (0 != $to_id) {
                                 p2p_type('methods_to_methods')->connect($from_id, $to_id, array('data' => current_time('mysql')));
                             }
                         }
                     }
                     // ...to Hooks
                     if ($this->post_types['hook'] === $to_type) {
                         foreach ($to_slugs as $to_slug => $to_id) {
                             $to_id = intval($to_id, 10);
                             if (0 != $to_id) {
                                 p2p_type('methods_to_hooks')->connect($from_id, $to_id, array('data' => current_time('mysql')));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #4
0
 public function clear_post_connection_to_entity($from_post_type, $to_post_type, $from = '', $to = '')
 {
     return p2p_delete_connections($from_post_type . '_to_' . $to_post_type, array('from' => $from, 'to' => $to));
 }
コード例 #5
0
 /**
  * Delete all connections for a certain post.
  *
  * @param int The post id.
  */
 public function disconnect_all($from)
 {
     return p2p_delete_connections($this->name, array('direction' => $this->direction, 'from' => $from));
 }
コード例 #6
0
function gdlist_create_connection_for_each_post($cur_post_id, $post_ids)
{
    $listed_posts = gdlist_get_all_listed_posts($cur_post_id);
    $listed_post_ids = array();
    foreach ($listed_posts as $key => $title) {
        $listed_post_ids[] = (string) $key;
    }
    $removed_ids = array_diff($listed_post_ids, $post_ids);
    $added_ids = array_diff($post_ids, $listed_post_ids);
    if (current_user_can('edit_post', $cur_post_id)) {
        foreach ($added_ids as $pid) {
            $con_type = get_post_type($pid) . '_to_gd_list';
            $args = array('from' => $pid, 'to' => $cur_post_id);
            //$exists = p2p_connection_exists($con_type, $args);
            //if(!$exists) {
            p2p_create_connection($con_type, $args);
            //}
        }
        foreach ($removed_ids as $pid) {
            $con_type = get_post_type($pid) . '_to_gd_list';
            $args = array('from' => $pid, 'to' => $cur_post_id);
            //$exists = p2p_connection_exists($con_type, $args);
            //if($exists) {
            p2p_delete_connections($con_type, $args);
            //}
        }
    }
}
コード例 #7
0
/**
 * Update a gig's venue and the gig count for any modified venues.
 *
 * @since 1.0.0
 */
function set_audiotheme_gig_venue($gig_id, $venue_name)
{
    $gig = get_audiotheme_gig($gig_id);
    // Retrieve current venue info.
    $venue_name = trim(stripslashes($venue_name));
    if (empty($venue_name)) {
        p2p_delete_connections('audiotheme_venue_to_gig', array('to' => $gig_id));
    } elseif (!isset($gig->venue->name) || $venue_name !== $gig->venue->name) {
        p2p_delete_connections('audiotheme_venue_to_gig', array('to' => $gig_id));
        $new_venue = get_audiotheme_venue_by('name', $venue_name);
        if (!$new_venue) {
            $new_venue = array('name' => $venue_name, 'gig_count' => 1);
            // Timezone is important, so retrieve it from the global $_POST array if it exists.
            if (!empty($_POST['audiotheme_venue']['timezone_string'])) {
                $new_venue['timezone_string'] = $_POST['audiotheme_venue']['timezone_string'];
            }
            $venue_id = save_audiotheme_venue($new_venue);
            if ($venue_id) {
                p2p_create_connection('audiotheme_venue_to_gig', array('from' => $venue_id, 'to' => $gig_id));
            }
        } else {
            $venue_id = $new_venue->ID;
            p2p_create_connection('audiotheme_venue_to_gig', array('from' => $new_venue->ID, 'to' => $gig_id));
            update_audiotheme_venue_gig_count($new_venue->ID);
        }
    }
    if (isset($gig->venue->ID)) {
        $venue_id = $gig->venue->ID;
        update_audiotheme_venue_gig_count($venue_id);
    }
    return empty($venue_id) ? false : get_audiotheme_venue($venue_id);
}
コード例 #8
0
function delete_old_connections($types, $post_id)
{
    foreach ($types as $type) {
        p2p_delete_connections($type, array('from' => $post_id));
    }
}
コード例 #9
0
function sfhiv_location_relation_save($post_ID, $location_ID)
{
    p2p_delete_connections('related_location', array("from" => $post_ID));
    p2p_create_connection('related_location', array('from' => $post_ID, 'to' => $location_ID));
    $taxonomies = get_object_taxonomies(get_post_type($post_ID));
    if (in_array('sfhiv_neighborhood_category', $taxonomies)) {
        $neighborhood_terms = wp_get_object_terms($location_ID, 'sfhiv_neighborhood_category', array('fields' => 'slugs'));
        wp_set_object_terms($post_ID, $neighborhood_terms, 'sfhiv_neighborhood_category');
    }
}