Changes between Version 8 and Version 9 of AdminTips


Ignore:
Timestamp:
2012-09-12T17:56:50Z (12 years ago)
Author:
Pan Luo
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdminTips

    v8 v9  
    3636Replace EVENT_ID to event id and COURSE_ID to course id.
    3737
     38=== Merge Students with Duplicated Accounts (the accounts starts with "s" and without) ===
     39{{{
     40#!sql
     41DROP PROCEDURE IF EXISTS merge_students;
     42
     43delimiter //
     44
     45CREATE PROCEDURE merge_students()
     46BEGIN
     47        DECLARE old, new INT;
     48        DECLARE done INT DEFAULT FALSE;
     49        DECLARE cur CURSOR FOR (SELECT u1.id, u2.id FROM users as u1 JOIN users as u2 ON u2.username = CONCAT("s", u1.username) WHERE u1.username REGEXP '[0-9]{8}');
     50        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
     51       
     52        OPEN cur;
     53       
     54        read_loop: LOOP
     55                FETCH cur INTO old, new;
     56                IF done THEN
     57                        LEAVE read_loop;
     58                END IF;
     59          SELECT CONCAT("Merging user ", new, " into ", old) as "";
     60        update groups_members set user_id = old where user_id = new;
     61        update user_enrols set user_id = old where user_id = new;
     62        update survey_inputs set user_id = old where user_id = new;
     63        update evaluation_submissions set submitter_id = old where submitter_id = new;
     64        update evaluation_simples set evaluator = old where evaluator = new;
     65        update evaluation_simples set evaluatee = old where evaluatee = new;
     66        update evaluation_rubrics set evaluator = old where evaluator = new;
     67        update evaluation_rubrics set evaluatee = old where evaluatee = new;
     68        update evaluation_mixevals set evaluator = old where evaluator = new;
     69        update evaluation_mixevals set evaluatee = old where evaluatee = new;
     70        delete from users where id = new;
     71
     72        END LOOP;
     73       
     74        CLOSE cur;
     75END;
     76
     77CALL merge_students();
     78}}}
    3879
    3980== Statistics ==