Changeset 1156 for trunk


Ignore:
Timestamp:
12/06/11 01:14:30 (6 months ago)
Author:
bogdan2412
Message:

Fix errors that appeared during deployment of avatar optimization

  • Use hardlinks for full size avatars when possible, so we conserve

disk space.

  • Skip users with invalid usernames
  • Create 'tiny', 'small', etc folders if missing
  • Added verbose parameter that allows one to view progress
  • Coding style, don't use " when not needed.

There are still some tasks left, as described in
REVIEW URL http://reviewboard.infoarena.ro/r/180/

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/avatar.php

    r1155 r1156  
    2121            'L50x50' => 'normal/' , '75x75'=> 'forum/', '150x150' => 'big/'); 
    2222 
    23     // Copying the original image 
    24     copy($filepath, IA_AVATAR_FOLDER.'full/'.$new_filename); 
     23    // Hardlink / Copy the original image 
     24    $new_filepath = IA_AVATAR_FOLDER . 'full/' . $new_filename; 
     25    if (is_file($new_filepath) || is_link($new_filepath)) { 
     26        unlink($new_filepath); 
     27    } 
     28    if (!link($filepath, $new_filepath)) { 
     29        if (!copy($filepath, $new_filepath)) { 
     30            log_error('Unable to copy user avatar into avatar folder'); 
     31        } 
     32    } 
    2533 
    2634    list($image_width, $image_height, $image_type, $image_attribute) = 
  • trunk/scripts/make-avatar-folder

    r1155 r1156  
    22<?php 
    33 
    4 require_once(dirname($argv[0])."/utilities.php"); 
    5 require_once(IA_ROOT_DIR.'common/db/db.php'); 
    6 require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); 
    7 require_once(IA_ROOT_DIR.'www/controllers/image_attachment.php'); 
    8 require_once(IA_ROOT_DIR.'common/db/attachment.php'); 
    9 require_once(IA_ROOT_DIR.'common/cache.php'); 
    10 require_once(IA_ROOT_DIR.'common/db/user.php'); 
    11 require_once(IA_ROOT_DIR.'common/avatar.php'); 
    12 require_once(IA_ROOT_DIR.'common/db/textblock.php'); 
     4require_once(dirname($argv[0]) . '/utilities.php'); 
     5require_once(IA_ROOT_DIR . 'common/db/db.php'); 
     6require_once(IA_ROOT_DIR . 'www/controllers/attachment.php'); 
     7require_once(IA_ROOT_DIR . 'www/controllers/image_attachment.php'); 
     8require_once(IA_ROOT_DIR . 'common/db/attachment.php'); 
     9require_once(IA_ROOT_DIR . 'common/cache.php'); 
     10require_once(IA_ROOT_DIR . 'common/db/user.php'); 
     11require_once(IA_ROOT_DIR . 'common/avatar.php'); 
     12require_once(IA_ROOT_DIR . 'common/db/textblock.php'); 
    1313 
    1414// Database connect 
    1515db_connect(); 
     16$verbose = getattr($argv, 1, false) === '-v'; 
    1617 
    1718// Managing the userinfo template from the textblock table 
    18 if (read_bool("Do you want to change the template/userinfo textblock?", 
     19if (read_bool('Do you want to change the template/userinfo textblock?', 
    1920        false)) { 
    2021    $textfortextblock = "table(compact). |=/5. ==UserImage". 
     
    2829    "\r\n\r\n\r\n"; 
    2930    textblock_add_revision('template/userinfo', 'template/userinfo', 
    30             $textfortextblock, 1, "protected"); 
     31            $textfortextblock, 1, 'protected'); 
    3132} 
    3233 
     
    4041if (file_exists(IA_AVATAR_FOLDER) == false) { 
    4142    mkdir(IA_AVATAR_FOLDER, 0777); 
    42     $size_types = array("tiny", "small", "normal", "forum", "big", "full"); 
    43     foreach ($size_types as $size) { 
    44         if (file_exists(IA_AVATAR_FOLDER."/".$size) == false) { 
    45             mkdir(IA_AVATAR_FOLDER."/".$size, 0777); 
    46         } 
     43} 
     44$size_types = array('tiny', 'small', 'normal', 'forum', 'big', 'full'); 
     45foreach ($size_types as $size) { 
     46    if (file_exists(IA_AVATAR_FOLDER . '/' . $size) == false) { 
     47        mkdir(IA_AVATAR_FOLDER . '/' . $size, 0777); 
    4748    } 
    4849} 
     
    5455// Going through all the users 
    5556foreach ($userlist as $user) { 
    56     $attach = attachment_get('avatar', 'utilizator/'.$user); 
     57    if (!is_user_name($user)) { 
     58        log_warn('Invalid username: ' . $user); 
     59        continue; 
     60    } 
     61    $attach = attachment_get('avatar', 'utilizator/' . $user); 
    5762    $found = !is_null($attach); 
    5863 
     
    6065        $real_name = attachment_get_filepath($attach); 
    6166        $found = file_exists($real_name); 
    62         if (!$found) 
    63             log_warn("File does not exists but it is in the Database."); 
     67        if (!$found) { 
     68            log_warn('File does not exists but it is in the Database.'); 
     69        } 
    6470    } 
    6571 
     
    7480 
    7581    // The user has a valid image, resizing it, but keeping the attachment 
     82    if ($verbose) { 
     83        log_print('Processing user: ' . $user); 
     84    } 
    7685    avatar_cache_resized($real_name, $img_info, "a".$user); 
    7786} 
Note: See TracChangeset for help on using the changeset viewer.