function relationship_find_and_update($a_type, $b_type, $name, $updates = array())
{
    $existing_rel_id = relationship_finder($a_type, $b_type, $name);
    if (!empty($existing_rel_id) && !empty($updates)) {
        // build criteria clause - only want to update if it is actually needed
        $set_str = $where_str_body = '';
        $where_str_start = " AND (";
        foreach ($updates as $k => $v) {
            $set_str .= !empty($set_str) ? ", " : '';
            $where_str_body .= !empty($where_str_body) ? ") OR (" : "(";
            $where_str_body .= $k . ' != "' . reason_sql_string_escape($v) . '"';
            $set_str .= $k . ' = "' . reason_sql_string_escape($v) . '"';
        }
        $where_str_end = "))";
        $q = 'UPDATE allowable_relationship SET ' . $set_str . ' WHERE ID=' . $existing_rel_id . $where_str_start . $where_str_body . $where_str_end;
        db_query($q, 'could not update the places a blog on a page relationship');
        $num_rows = mysql_affected_rows();
        if (!empty($num_rows)) {
            echo '<p>updated relationship ' . $name . '</p>';
            pray($updates);
            return true;
        } else {
            return false;
        }
    }
}
Ejemplo n.º 2
0
 if (create_allowable_relationship(id_of('event_type'), $news_type, 'event_to_news', array('description' => 'Event to News / Post', 'connections' => 'many_to_many', 'display_name' => 'Associate with a News Item', 'directionality' => 'bidirectional', 'is_sortable' => 'yes', 'display_name_reverse_direction' => 'Assign to event(s)', 'description_reverse_direction' => 'Events for this news items'))) {
     echo '<p>Created event_to_news allowable relationship</p>';
 }
 //Update Places a blog on a page relationship to proper format
 if ($blog_type_exists) {
     $existing_rel_id = relationship_finder('minisite_page', 'blog_type', 'Places a blog on a page');
     if (!empty($existing_rel_id)) {
         $q = 'UPDATE allowable_relationship SET name="page_to_blog" WHERE ID=' . $existing_rel_id;
         db_query($q, 'could not update the places a blog on a page relationship');
         echo '<p>Renamed "Places a blog on a page" relationship to "page_to_blog"</p>';
     } else {
         echo '<p>The "Places a blog on a page" relationship has already been updated</p>';
     }
 }
 $news_to_issue_rel = relationship_finder('news', 'issue_type', 'news_to_issue');
 $news_to_news_section_rel = relationship_finder('news', 'news_section_type', 'news_to_news_section');
 if (check_required($news_to_issue_rel)) {
     if (remove_required_relationship($news_to_issue_rel)) {
         echo '<p>Set required to "no" for news_to_issue relationship</p>';
     }
 } else {
     echo '<p>Required is already set to "no" for news_to_issue relationship - no changes made</p>';
 }
 if (check_required($news_to_news_section_rel)) {
     if (remove_required_relationship($news_to_news_section_rel)) {
         echo '<p>Set required to "no" for news_to_news_section relationship</p>';
     }
 } else {
     echo '<p>Required is already set to "no" for news_to_news_section relationship - no changes made</p>';
 }
 //if (check_required($news_to_news_section_rel)) echo 'required for news_to_news_section_rel';