Changeset 1131


Ignore:
Timestamp:
04/24/10 13:42:06 (2 years ago)
Author:
wefgef
Message:

Task reordering fixes forum topics for archive.

Location:
branches/taskreordering
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/taskreordering/common/db/round.php

    r1130 r1131  
    227227 
    228228    // delete round-task relations 
    229     $query = sprintf("DELETE FROM ia_round_task 
    230                       WHERE round_id = %s AND task_id IN (%s)", 
    231                      db_quote($round_id), 
    232                      implode(',', array_map("db_quote", $old_tasks))); 
    233     db_query($query); 
     229    if (count($old_tasks) > 0) { 
     230        $query = sprintf("DELETE FROM ia_round_task 
     231                          WHERE round_id = %s AND task_id IN (%s)", 
     232                         db_quote($round_id), 
     233                         implode(',', array_map("db_quote", $old_tasks))); 
     234        db_query($query); 
     235    } 
    234236 
    235237    foreach($old_tasks as $task) { 
  • branches/taskreordering/common/db/round_task.php

    r1129 r1131  
    22 
    33require_once(IA_ROOT_DIR."common/db/db.php"); 
     4require_once(IA_ROOT_DIR."common/db/task.php"); 
    45 
    56// Updates the `order_id` for a (round, task) pair. 
     
    2425    foreach ($res as $row) { 
    2526        $order_id += 1; 
    26         $query = sprintf( 
    27             "UPDATE ia_round_task 
    28              SET order_id = %s 
    29              WHERE round_id = %s AND task_id = %s", 
    30              db_quote($order_id), db_quote($round_id), 
    31              db_quote($row['task_id'])); 
    32         db_query($query); 
     27 
     28        if ($order_id != $row['order_id']) { 
     29            $query = sprintf( 
     30                "UPDATE ia_round_task 
     31                 SET order_id = %s 
     32                 WHERE round_id = %s AND task_id = %s", 
     33                 db_quote($order_id), db_quote($round_id), 
     34                 db_quote($row['task_id'])); 
     35            db_query($query); 
     36 
     37            // update forum if necessary 
     38            if ($round_id == 'arhiva') { 
     39                task_update_forum_topic($row['task_id']); 
     40            } 
     41        } 
    3342    } 
    3443} 
  • branches/taskreordering/common/db/task.php

    r1129 r1131  
    263263    return $tasks; 
    264264} 
     265 
     266// Updates the forum topic associated with a task. 
     267function task_update_forum_topic($task_id, $round_id = "arhiva") { 
     268    if (!is_task_id($task_id)) { 
     269        log_error("Invalid task id"); 
     270    } 
     271 
     272    // Get task info 
     273    $query = "SELECT title, page_name FROM ia_task 
     274              WHERE id = " . db_quote($task_id); 
     275    $task = db_fetch($query); 
     276 
     277    // Get the forum topic 
     278    $query = "SELECT forum_topic 
     279              FROM ia_textblock 
     280              WHERE name = " . db_quote($task['page_name']); 
     281    $res = db_fetch($query); 
     282    $topic_id = $res['forum_topic']; 
     283 
     284    // Check the textblock has an associated forum topic. 
     285    if (is_null($topic_id)) { 
     286        return; 
     287    } 
     288 
     289    // Get the first message from the topic 
     290    $query = "SELECT ID_FIRST_MSG AS `msg_id` 
     291              FROM ia_smf_topics 
     292              WHERE ID_TOPIC = " . db_quote($topic_id); 
     293    $res = db_fetch($query); 
     294    // Topic id doesn't exist 
     295    if (is_null($res)) { 
     296        return; 
     297    } 
     298    $message_id = $res['msg_id']; 
     299 
     300    // Get the subject and the body of the message 
     301    $query = "SELECT subject, body FROM ia_smf_messages 
     302              WHERE ID_MSG = " . db_quote($message_id); 
     303    $message = db_fetch($query); 
     304 
     305    // Find the number associated with the (task, round) pair. 
     306    $query = sprintf( 
     307        "SELECT order_id FROM ia_round_task 
     308         WHERE round_id = %s AND task_id = %s", 
     309         db_quote($round_id), db_quote($task_id)); 
     310    $res = db_fetch($query); 
     311    $task_number = sprintf("%03d", $res['order_id'] - 1); 
     312 
     313    // New info 
     314    $new_subject = $task_number . " " . $task['title']; 
     315    $body_start = mb_substr($message['body'], 0, 35); 
     316    if ($body_start != "Aici puteti discuta despre problema" && 
     317        $body_start != "Aici puteÈ›i discuta despre prob" && 
     318        $body_start != "Aici puteÅ£i discuta despre probl") { 
     319        $new_body = 'Aici puteÅ£i discuta despre problema ' . 
     320                    '[url=http://infoarena.ro/problema/' . $task_id . ']' . 
     321                    $task['title'] . '[/url].'; 
     322    } else { 
     323        $new_body = $message['body']; 
     324    } 
     325 
     326    // Finally, update the message 
     327    $query = sprintf( 
     328        "UPDATE ia_smf_messages 
     329         SET subject = %s, body = %s 
     330         WHERE ID_MSG = %s", 
     331         db_quote($new_subject), db_quote($new_body), db_quote($message_id)); 
     332    db_query($query); 
     333 
     334    // Not finished yet, must change replies too. 
     335    // This is extremely time consuming. 
     336    if ($new_subject != $message['subject']) { 
     337        $query = sprintf( 
     338            "UPDATE ia_smf_messages 
     339             SET subject = %s 
     340             WHERE subject LIKE %s", 
     341             db_quote("Răspuns: " . $new_subject), 
     342             db_quote("%" . $message['subject'])); 
     343        db_query($query); 
     344    } 
     345} 
     346 
    265347?> 
  • branches/taskreordering/scripts/add-round-task-order

    r1129 r1131  
    33 
    44require_once(dirname($argv[0])."/utilities.php"); 
    5 require_once(dirname($argv[0])."/../common/task.php"); 
     5require_once(dirname($argv[0])."/../common/db/task.php"); 
    66 
    77db_connect(); 
     
    4444} 
    4545 
     46// Update forum topics 
     47$query = "SELECT task_id FROM ia_round_task 
     48          WHERE round_id = 'arhiva'"; 
     49$res = db_fetch_all($query); 
     50foreach ($res as $task) { 
     51    task_update_forum_topic($task['task_id']); 
     52} 
     53 
    4654?> 
  • branches/taskreordering/www/controllers/round.php

    r1129 r1131  
    265265            if ($current_id != $order_id) { 
    266266                round_task_update_order_id($round_id, $task_id, $current_id); 
    267                 //task_update_forum_topic($task_id); 
     267                task_update_forum_topic($task_id); 
    268268            } 
    269269 
Note: See TracChangeset for help on using the changeset viewer.