Changeset 1057 for trunk/common


Ignore:
Timestamp:
11/03/09 00:08:26 (3 years ago)
Author:
bogdan2412
Message:

Implemented script for copying textblock pages in bulk.

This can be used, for example, to copy everything under algoritmiada-2009/ to algoritmiada-2010/.

  • Script was based on existing "recursive-move".
  • textblock_copy_replace was modified to use textblock_copy which also supports copying attachments, instead of textblock_add_revision.
  • textblock_copy was changed to receive an existing textblock object to copy, instead of the name of the one to copy. This allows modifying parts of the textblock before copying.

Reviewed: http://reviewboard.infoarena.ro/r/95/

Location:
trunk/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/textblock.php

    r1030 r1057  
    1 <?php  
     1<?php 
    22 
    33require_once(IA_ROOT_DIR."common/db/db.php"); 
     
    4040        // copy current version to revision table 
    4141        db_insert('ia_textblock_revision', $current_revision); 
    42      
     42 
    4343        // replace current version 
    4444        $query = sprintf("DELETE FROM ia_textblock 
     
    323323} 
    324324 
    325 function textblock_copy($old_name, $new_name, $user_id, $remote_ip_info) { 
    326     $old_name = normalize_page_name($old_name); 
     325// Copy a textblock to new_name. 
     326// Also copies attachments. 
     327function textblock_copy($old_textblock, $new_name, $user_id, $remote_ip_info) { 
     328    log_assert(!textblock_validate($old_textblock)); 
    327329    $new_name = normalize_page_name($new_name); 
    328     log_assert(is_normal_page_name($old_name)); 
    329330    log_assert(is_normal_page_name($new_name)); 
    330331 
    331     $new_textblock = textblock_get_revision($old_name); 
     332    $new_textblock = $old_textblock; 
    332333    $new_textblock['name'] = $new_name; 
    333334    $new_textblock['user_id'] = $user_id; 
     335    $new_textblock['creation_timestamp'] = null; 
     336    // Keep creation_timestamp correct when textblock with new name already exists 
     337    $aux = textblock_get_revision($new_name); 
     338    if ($aux) { 
     339        $new_textblock['creation_timestamp'] = $aux['creation_timestamp']; 
     340    } 
    334341    textblock_add_revision($new_textblock['name'], $new_textblock['title'], 
    335342                           $new_textblock['text'], $new_textblock['user_id'], 
    336343                           $new_textblock['security'], 
    337                            $new_textblock['forum_topic'], null, null, 
     344                           $new_textblock['forum_topic'], 
     345                           null, $new_textblock['creation_timestamp'], 
    338346                           $remote_ip_info); 
    339347 
    340348    // Get a list of attachments. 
    341     $files = attachment_get_all($old_name); 
     349    $files = attachment_get_all($old_textblock["name"]); 
    342350 
    343351    // Copy attachments in db and hard drive 
  • trunk/common/textblock.php

    r997 r1057  
    152152        $user_id, $remote_ip_info = null) { 
    153153    assert($srcprefix != $dstprefix); 
    154     assert(is_textblock_security_descriptor($security)); 
     154    assert($security === null || is_textblock_security_descriptor($security)); 
    155155    assert(is_whole_number($user_id)); 
    156156 
     
    160160            textblock_template_replace($textblock, $replace); 
    161161        } 
    162         if ($replace !== null) { 
     162        if ($security !== null) { 
    163163            $textblock['security'] = $security; 
    164164        } 
    165         $textblock['name'] = preg_replace('/^'.preg_quote($srcprefix, '/').'/i', $dstprefix, $textblock['name']); 
     165        $new_name = preg_replace('/^'.preg_quote($srcprefix, '/').'/i', 
     166            $dstprefix, $textblock['name']); 
    166167 
    167         //FIXME: hack to keep creation_timestamp correct when textblock already exists 
    168         $first_textblock = textblock_get_revision($textblock['name']); 
    169         if (!$first_textblock) { 
    170             $first_textblock['creation_timestamp'] = null; 
    171         } 
    172  
    173         textblock_add_revision($textblock['name'], $textblock['title'], 
    174                 $textblock['text'], $user_id, $textblock['security'], 
    175                 $textblock['forum_topic'], null, 
    176                 $first_textblock['creation_timestamp'], $remote_ip_info); 
     168        textblock_copy($textblock, $new_name, $user_id, $remote_ip_info); 
    177169    } 
    178170} 
Note: See TracChangeset for help on using the changeset viewer.