function update_option($option_name, $option_value) { //function to update an option in the options table. global $wpdb; if (bebop_tables::check_option_exists($option_name) == true) { $result = $wpdb->query('UPDATE ' . bp_core_get_table_prefix() . "bp_bebop_options SET option_value = '" . $wpdb->escape($option_value) . "' WHERE option_name = '" . $wpdb->escape($option_name) . "' LIMIT 1"); if (!empty($result)) { return $result; } else { return false; } } else { bebop_tables::add_option($option_name, $option_value); bebop_tables::update_option($option_name, $option_value); } }
} //3 - hash secondary_item_ids $update_3 = bebop_tables::get_option_value('bebop_db_update_3'); if (!$update_3) { $update_secondary_item_id = array(); $results = $wpdb->get_results('SELECT id, secondary_item_id FROM ' . bp_core_get_table_prefix() . 'bp_bebop_oer_manager'); if (!empty($results)) { foreach ($results as $result) { $update_secondary_item_id[] = array('indices' => array('id' => $result->id), 'data' => md5($result->secondary_item_id)); } $update_array = array('secondary_item_id' => $update_secondary_item_id); $update_string = array(); foreach ($update_array as $key => $data) { $string = $key . ' = CASE '; foreach ($data as $update_data) { $indices_loop = array(); foreach ($update_data['indices'] as $index_name => $index_data) { $indices_loop[] = $index_name . ' = \'' . $index_data . '\''; } $string .= 'WHEN ' . implode(' AND ', $indices_loop) . ' THEN \'' . $update_data['data'] . '\' '; } $update_string[] = $string . 'ELSE ' . $key . ' END'; } $query = implode(', ', $update_string); $update = $wpdb->get_results('UPDATE ' . bp_core_get_table_prefix() . 'bp_bebop_oer_manager SET ' . $query); unset($update_secondary_item_id); } bebop_tables::add_option('bebop_db_update_3', true); } bebop_tables::add_option('bebop_db_version', '1.3.1');