Creating missing usergroup_rel_usergroup table, adding auto_increment id in announcement_rel_group see BT#4301

skala
Julio Montoya 12 years ago
parent 862202a450
commit eacf0ebe91
  1. 21
      main/inc/lib/database.constants.inc.php
  2. 28
      main/inc/lib/system_announcements.lib.php
  3. 22
      main/inc/lib/usergroup.lib.php
  4. 21
      main/install/1.10.0/db_main.sql
  5. 13
      main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql
  6. 13
      main/install/1.9.0/db_main.sql

@ -58,8 +58,6 @@ define('TABLE_MAIN_GRADEBOOK_LINK', 'gradebook_link');
define('TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY','gradebook_score_display');
define('TABLE_MAIN_GRADEBOOK_CERTIFICATE', 'gradebook_certificate');
//Profiling
define('TABLE_MAIN_USER_FIELD', 'user_field');
define('TABLE_MAIN_USER_FIELD_OPTIONS', 'user_field_options');
@ -69,13 +67,6 @@ define('TABLE_MAIN_USER_FIELD_VALUES', 'user_field_values');
define('TABLE_MAIN_TAG', 'tag');
define('TABLE_MAIN_USER_REL_TAG', 'user_rel_tag');
//User groups
/*
define('TABLE_MAIN_GROUP', 'groups');
define('TABLE_MAIN_USER_REL_GROUP', 'group_rel_user');
define('TABLE_MAIN_GROUP_REL_TAG', 'group_rel_tag');
define('TABLE_MAIN_GROUP_REL_GROUP', 'group_rel_group');
*/
// Search engine
define('TABLE_MAIN_SPECIFIC_FIELD', 'specific_field');
@ -309,6 +300,15 @@ define('TABLE_THEMATIC','thematic');
define('TABLE_THEMATIC_PLAN', 'thematic_plan');
define('TABLE_THEMATIC_ADVANCE','thematic_advance');
//User groups
/*
define('TABLE_MAIN_GROUP', 'groups');
define('TABLE_MAIN_USER_REL_GROUP', 'group_rel_user');
define('TABLE_MAIN_GROUP_REL_TAG', 'group_rel_tag');
define('TABLE_MAIN_GROUP_REL_GROUP', 'group_rel_group');
*/
// Careers, promotions, Usergroups
define('TABLE_CAREER', 'career');
define('TABLE_PROMOTION', 'promotion');
@ -317,7 +317,8 @@ define('TABLE_USERGROUP', 'usergroup');
define('TABLE_USERGROUP_REL_USER', 'usergroup_rel_user');
define('TABLE_USERGROUP_REL_COURSE', 'usergroup_rel_course');
define('TABLE_USERGROUP_REL_SESSION', 'usergroup_rel_session');
define('TABLE_USERGROUP_REL_TAG', 'usergroup_rel_tag');
define('TABLE_USERGROUP_REL_TAG', 'usergroup_rel_tag');
define('TABLE_USERGROUP_REL_USERGROUP', 'usergroup_rel_usergroup');
// Mail notifications
define('TABLE_NOTIFICATION', 'notification');

@ -144,8 +144,10 @@ class SystemAnnouncementManager {
}
if (count($groups) > 0 and $ann_group_db_ok ) {
$sql .= " OR id IN (SELECT announcement_id FROM $tbl_announcement_group
WHERE group_id in $groups_string) ";
$sql .= " OR id IN (
SELECT announcement_id FROM $tbl_announcement_group
WHERE group_id in $groups_string
) ";
}
if (api_is_multiple_url_enabled()) {
@ -367,7 +369,7 @@ class SystemAnnouncementManager {
public static function announcement_for_groups($announcement_id, $group_array){
$tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS);
//first delete all group associations for this announcement
$res = Database::query("DELETE FROM $tbl_announcement_group where announcement_id=".intval($announcement_id));
$res = Database::query("DELETE FROM $tbl_announcement_group WHERE announcement_id = ".intval($announcement_id));
if ($res === false) {
Debug::log_s(mysql_error());
return false;
@ -375,7 +377,7 @@ class SystemAnnouncementManager {
foreach ($group_array as $group_id) {
if (intval($group_id) != 0 ) {
$res = Database::query("INSERT into $tbl_announcement_group set announcement_id=".intval($announcement_id)
$res = Database::query("INSERT INTO $tbl_announcement_group SET announcement_id=".intval($announcement_id)
.", group_id=".intval($group_id));
if ($res === false) {
Debug::log_s(mysql_error());
@ -391,15 +393,15 @@ class SystemAnnouncementManager {
* @return array array of group id
**/
public static function get_announcement_groups($announcement_id){
$tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS);
$tbl_group = Database :: get_main_table(TABLE_MAIN_GROUP);
//first delete all group associations for this announcement
$res = Database::query("SELECT g.id as group_id , g.name as group_name FROM $tbl_group g , $tbl_announcement_group ag"
." WHERE announcement_id=".intval($announcement_id)
." AND ag.group_id = g.id");
$groups = Database::fetch_array($res);
return $groups;
$tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS);
$tbl_group = Database :: get_main_table(TABLE_USERGROUP);
//first delete all group associations for this announcement
$res = Database::query("SELECT g.id as group_id, g.name as group_name
FROM $tbl_group g , $tbl_announcement_group ag
WHERE announcement_id = ".intval($announcement_id)." AND ag.group_id = g.id");
$groups = Database::fetch_array($res);
return $groups;
}
/**

@ -647,7 +647,7 @@ class UserGroup extends Model
* @return true or false
**/
public function set_parent_group($group_id, $parent_group_id, $relation_type = 1){
$table = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
$table = Database :: get_main_table(TABLE_USERGROUP_REL_USERGROUP);
$group_id = intval($group_id);
$parent_group_id = intval($parent_group_id);
if ($parent_group_id == 0) {
@ -656,9 +656,9 @@ class UserGroup extends Model
$sql = "SELECT group_id FROM $table WHERE subgroup_id = $group_id";
$res = Database::query($sql);
if (Database::num_rows($res)==0) {
$sql = "INSERT INTO $table SET group_id = $parent_group_id, subgroup_id = $group_id, relation_type = $relation_type";
$sql = "INSERT INTO $table SET group_id = $parent_group_id, subgroup_id = $group_id, relation_type = $relation_type";
} else {
$sql = "UPDATE $table SET group_id = $parent_group_id, relation_type = $relation_type WHERE subgroup_id = $group_id";
$sql = "UPDATE $table SET group_id = $parent_group_id, relation_type = $relation_type WHERE subgroup_id = $group_id";
}
}
$res = Database::query($sql);
@ -671,10 +671,10 @@ class UserGroup extends Model
*
* @return int parent_group_id or false
**/
public function get_parent_group($group_id, $relation_type=1) {
$table = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
$group_id=intval($group_id);
//$parent_group_id=intval($parent_group_id);
public function get_parent_group($group_id, $relation_type = 1) {
$table = Database :: get_main_table(TABLE_USERGROUP_REL_USERGROUP);
$group_id = intval($group_id);
$sql = "SELECT group_id FROM $table WHERE subgroup_id = $group_id";
$res = Database::query($sql);
if (Database::num_rows($res)==0) {
@ -686,8 +686,8 @@ class UserGroup extends Model
}
public function get_subgroups($root, $level) {
$t_group = Database::get_main_table(TABLE_MAIN_GROUP);
$t_rel_group = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
$t_group = Database::get_main_table(TABLE_USERGROUP);
$t_rel_group = Database :: get_main_table(TABLE_USERGROUP_REL_USERGROUP);
$select_part = "SELECT ";
$cond_part='';
for ($i=1; $i <= $level; $i++) {
@ -699,7 +699,7 @@ class UserGroup extends Model
$select_part .="g$i.id as id_$i, g$i.name name_$i, ";
}
if ($i == 1) {
$cond_part .= "FROM $t_group g1 JOIN $t_rel_group rg0 on g1.id = rg0.subgroup_id and rg0.group_id = $root ";
$cond_part .= "FROM $t_group g1 JOIN $t_rel_group rg0 on g1.id = rg0.subgroup_id and rg0.usergroup_id = $root ";
} else {
$cond_part .= "LEFT JOIN $t_rel_group rg$rg_number on g$rg_number.id = rg$rg_number.group_id ";
$cond_part .= "LEFT JOIN $t_group g$g_number on rg$rg_number.subgroup_id = g$g_number.id ";
@ -728,7 +728,7 @@ class UserGroup extends Model
}
public function get_parent_groups($group_id) {
$t_rel_group = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP);
$t_rel_group = Database :: get_main_table(TABLE_USERGROUP_REL_USERGROUP);
$max_level = 10;
$select_part = "SELECT ";
$cond_part='';

@ -2658,9 +2658,10 @@ CREATE TABLE IF NOT EXISTS user_rel_tag (
DROP TABLE IF EXISTS announcement_rel_group;
CREATE TABLE IF NOT EXISTS announcement_rel_group (
id INT unsigned NOT NULL auto_increment,
group_id int NOT NULL,
announcement_id int NOT NULL,
PRIMARY KEY (group_id, announcement_id)
PRIMARY KEY (id)
);
--
-- Table structure for table message attachment
@ -2766,7 +2767,7 @@ CREATE TABLE IF NOT EXISTS usergroup (
);
DROP TABLE IF EXISTS usergroup_rel_user;
CREATE TABLE IF NOT EXISTS usergroup_rel_user (
CREATE TABLE IF NOT EXISTS usergroup_rel_user(
id INT NOT NULL AUTO_INCREMENT,
usergroup_id INT NOT NULL,
user_id INT NOT NULL,
@ -2778,7 +2779,6 @@ ALTER TABLE usergroup_rel_user ADD INDEX ( usergroup_id );
ALTER TABLE usergroup_rel_user ADD INDEX ( user_id );
ALTER TABLE usergroup_rel_user ADD INDEX ( relation_type );
DROP TABLE IF EXISTS usergroup_rel_course;
CREATE TABLE IF NOT EXISTS usergroup_rel_course (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
@ -2804,6 +2804,19 @@ CREATE TABLE IF NOT EXISTS usergroup_rel_tag(
ALTER TABLE usergroup_rel_tag ADD INDEX ( usergroup_id );
ALTER TABLE usergroup_rel_tag ADD INDEX ( tag_id );
DROP TABLE IF EXISTS usergroup_rel_usergroup;
CREATE TABLE IF NOT EXISTS usergroup_rel_usergroup (
id int NOT NULL AUTO_INCREMENT,
group_id int NOT NULL,
subgroup_id int NOT NULL,
relation_type int NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE usergroup_rel_usergroup ADD INDEX ( group_id );
ALTER TABLE usergroup_rel_usergroup ADD INDEX ( subgroup_id );
ALTER TABLE usergroup_rel_usergroup ADD INDEX ( relation_type );
--
-- Structure for Mail notifications
--
@ -3447,4 +3460,4 @@ ALTER TABLE personal_agenda ADD INDEX idx_personal_agenda_parent (parent_event_i
ALTER TABLE user_course_category ADD INDEX idx_user_c_cat_uid (user_id);
-- Do not move this
UPDATE settings_current SET selected_value = '1.10.0.f31bfcd' WHERE variable = 'chamilo_database_version';
UPDATE settings_current SET selected_value = '1.10.0.862202a' WHERE variable = 'chamilo_database_version';

@ -178,9 +178,20 @@ CREATE TABLE IF NOT EXISTS usergroup_rel_tag( id int NOT NULL AUTO_INCREMENT, ta
ALTER TABLE usergroup_rel_tag ADD INDEX ( usergroup_id );
ALTER TABLE usergroup_rel_tag ADD INDEX ( tag_id );
ALTER TABLE usergroup_rel_user ADD relation_type int NOT NULL default 0;
ALTER TABLE usergroup_rel_user ADD INDEX ( usergroup_id );
ALTER TABLE usergroup_rel_user ADD INDEX ( user_id );
ALTER TABLE usergroup_rel_user ADD INDEX ( relation_type );
CREATE TABLE IF NOT EXISTS usergroup_rel_usergroup (id int NOT NULL AUTO_INCREMENT, group_id int NOT NULL, subgroup_id int NOT NULL, relation_type int NOT NULL, PRIMARY KEY (id));
ALTER TABLE usergroup_rel_usergroup ADD INDEX ( group_id );
ALTER TABLE usergroup_rel_usergroup ADD INDEX ( subgroup_id );
ALTER TABLE usergroup_rel_usergroup ADD INDEX ( relation_type );
ALTER TABLE announcement_rel_group DROP PRIMARY KEY;
ALTER TABLE announcement_rel_group ADD COLUMN id INT unsigned NOT NULL auto_increment PRIMARY KEY;
-- Do not move this
UPDATE settings_current SET selected_value = '1.10.0.f31bfcd' WHERE variable = 'chamilo_database_version';
UPDATE settings_current SET selected_value = '1.10.0.862202a' WHERE variable = 'chamilo_database_version';

@ -2687,15 +2687,16 @@ CREATE TABLE IF NOT EXISTS group_rel_group (
relation_type int NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE group_rel_group ADD INDEX ( group_id );
ALTER TABLE group_rel_group ADD INDEX ( subgroup_id );
ALTER TABLE group_rel_group ADD INDEX ( relation_type );
DROP TABLE IF EXISTS announcement_rel_group;
CREATE TABLE IF NOT EXISTS announcement_rel_group (
group_id int NOT NULL,
announcement_id int NOT NULL,
PRIMARY KEY (group_id, announcement_id)
group_id int NOT NULL,
announcement_id int NOT NULL,
PRIMARY KEY (group_id, announcement_id)
);
--
-- Table structure for table message attachment
@ -3006,9 +3007,9 @@ ALTER TABLE gradebook_category ADD COLUMN grade_model_id INT DEFAULT 0;
DROP TABLE IF EXISTS course_type;
CREATE TABLE course_type (
id int unsigned not null auto_increment primary key,
name varchar(50) not null,
translation_var char(40) default 'UndefinedCourseTypeLabel',
description TEXT default '',
name varchar(50) not null,
translation_var char(40) default 'UndefinedCourseTypeLabel',
description TEXT default '',
props text default ''
);

Loading…
Cancel
Save