Ignore:
Timestamp:
Mar 5, 2006, 12:31:46 AM (18 years ago)
Author:
plg
Message:

new feature: source/destination links between categories. Will we keep this
feature? Code is complicated and very few people will understand how it
works...

modification: #images.storage_category_id replaced by
#image_category.is_storage

improvement: many code refactoring to improve readibility

improvement: virtual category creation code was moved to a dedicated
function in order to be called from admin/cat_list.php and
admin/cat_modify.php (create a new destination category)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/site_update.php

    r1058 r1064  
    2828if (!defined('PHPWG_ROOT_PATH'))
    2929{
    30   die ('Hacking attempt!');
     30  die('Hacking attempt!');
    3131}
    3232include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
    3333
    34 if (! is_numeric($_GET['site']) )
     34if (!is_numeric($_GET['site']))
    3535{
    3636  die ('site param missing or invalid');
    3737}
    3838$site_id = $_GET['site'];
    39 $query='SELECT galleries_url FROM '.SITES_TABLE.'
    40 WHERE id='.$site_id.'
    41 ;';
    42 list($site_url)=mysql_fetch_row(pwg_query($query));
    43 if (! isset($site_url) )
    44 {
    45   die ("site $site_id does not exist");
     39
     40$query='
     41SELECT galleries_url
     42  FROM '.SITES_TABLE.'
     43  WHERE id = '.$site_id.'
     44;';
     45list($site_url) = mysql_fetch_row(pwg_query($query));
     46if (!isset($site_url))
     47{
     48  die('site '.$site_id.' does not exist');
    4649}
    4750$site_is_remote = url_is_remote($site_url);
     
    5154
    5255$error_labels = array(
    53   'PWG-UPDATE-1' => array( l10n('update_wrong_dirname_short'),
    54                            l10n('update_wrong_dirname_info') ),
    55   'PWG-UPDATE-2' => array( l10n('update_missing_tn_short'),
    56                            l10n('update_missing_tn_info')
    57                            . implode(',', $conf['picture_ext']) ),
    58   'PWG-ERROR-NO-FS' => array( l10n('update_missing_file_or_dir'),
    59                              l10n('update_missing_file_or_dir_info')),
    60   'PWG-ERROR-VERSION' => array( l10n('update_err_pwg_version_differs'),
    61                              l10n('update_err_pwg_version_differs_info')),
    62   'PWG-ERROR-NOLISTING' => array( l10n('update_err_remote_listing_not_found'),
    63                              l10n('update_err_remote_listing_not_found_info'))
    64                       );
     56  'PWG-UPDATE-1' => array(
     57    l10n('update_wrong_dirname_short'),
     58    l10n('update_wrong_dirname_info')
     59    ),
     60  'PWG-UPDATE-2' => array(
     61    l10n('update_missing_tn_short'),
     62    l10n('update_missing_tn_info').implode(',', $conf['picture_ext'])
     63    ),
     64  'PWG-ERROR-NO-FS' => array(
     65    l10n('update_missing_file_or_dir'),
     66    l10n('update_missing_file_or_dir_info')
     67    ),
     68  'PWG-ERROR-VERSION' => array(
     69    l10n('update_err_pwg_version_differs'),
     70    l10n('update_err_pwg_version_differs_info')
     71    ),
     72  'PWG-ERROR-NOLISTING' => array(
     73    l10n('update_err_remote_listing_not_found'),
     74    l10n('update_err_remote_listing_not_found_info')
     75    )
     76  );
    6577$errors = array();
    6678$infos = array();
     
    6880if ($site_is_remote)
    6981{
    70   include_once( PHPWG_ROOT_PATH.'admin/site_reader_remote.php');
     82  include_once(PHPWG_ROOT_PATH.'admin/site_reader_remote.php');
    7183  $site_reader = new RemoteSiteReader($site_url);
    7284}
     
    7789}
    7890
    79 $general_failure=true;
     91$general_failure = true;
    8092if (isset($_POST['submit']))
    8193{
     
    214226    if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir))
    215227    {
    216       $insert = array();
    217 
    218       $insert{'id'} = $next_id++;
    219       $insert{'dir'} = $dir;
    220       $insert{'name'} = str_replace('_', ' ', $dir);
    221       $insert{'site_id'} = $site_id;
    222       $insert{'commentable'} = $conf['newcat_default_commentable'];
    223       if (! $site_is_remote)
    224       {
    225         $insert{'uploadable'} = $conf['newcat_default_uploadable'];
    226       }
    227       else
    228       {
    229         $insert{'uploadable'} = 'false';
    230       }
    231       $insert{'status'} = $conf{'newcat_default_status'};
    232       $insert{'visible'} = $conf{'newcat_default_visible'};
     228      $insert = array(
     229        'id'          => $next_id++,
     230        'dir'         => $dir,
     231        'name'        => str_replace('_', ' ', $dir),
     232        'site_id'     => $site_id,
     233        'commentable' => $conf['newcat_default_commentable'],
     234        'uploadable'  => $site_is_remote
     235          ? false
     236          : $conf['newcat_default_uploadable'],
     237        'status'      => $conf{'newcat_default_status'},
     238        'visible'     => $conf{'newcat_default_visible'},
     239        );
    233240
    234241      if (isset($db_fulldirs[dirname($fulldir)]))
     
    259266
    260267      array_push($inserts, $insert);
    261       array_push($infos, array('path' => $fulldir,
    262                                'info' => l10n('update_research_added')));
     268      array_push(
     269        $infos,
     270        array(
     271          'path' => $fulldir,
     272          'info' => l10n('update_research_added')
     273          )
     274        );
    263275
    264276      // add the new category to $db_categories and $db_fulldirs array
     
    276288    else
    277289    {
    278       array_push($errors, array('path' => $fulldir, 'type' => 'PWG-UPDATE-1'));
     290      array_push(
     291        $errors,
     292        array(
     293          'path' => $fulldir,
     294          'type' => 'PWG-UPDATE-1'
     295          )
     296        );
    279297    }
    280298  }
     
    339357SELECT id, path
    340358  FROM '.IMAGES_TABLE.'
    341   WHERE storage_category_id IN (
    342 '.wordwrap(implode(', ', $cat_ids), 80, "\n").')
     359    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
     360  WHERE is_storage = \'true\'
     361    AND category_id IN ('.
     362      wordwrap(
     363        implode(', ', $cat_ids),
     364        80,
     365        "\n"
     366        ).
     367      ')
    343368;';
    344369    $result = pwg_query($query);
     
    362387      array_push(
    363388        $db_unvalidated,
    364         array_search($row['storage_category_id'],
    365                      $db_fulldirs).'/'.$row['file']
     389        array_search(
     390          $row['storage_category_id'],
     391          $db_fulldirs)
     392        .'/'.$row['file']
    366393        );
    367394    }
     
    392419    if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
    393420    {
    394       array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-1'));
     421      array_push(
     422        $errors,
     423        array(
     424          'path' => $path,
     425          'type' => 'PWG-UPDATE-1'
     426          )
     427        );
     428     
    395429      continue;
    396430    }
     
    402436    {
    403437      // if we found a thumnbnail corresponding to our picture...
    404       if ( isset($fs[$path]['tn_ext']) )
     438      if (isset($fs[$path]['tn_ext']))
    405439      {
    406         $insert{'id'} = $next_element_id++;
    407         $insert{'file'} = $filename;
    408         $insert{'storage_category_id'} = $db_fulldirs[$dirname];
    409         $insert{'date_available'} = CURRENT_DATE;
    410         $insert{'tn_ext'} = $fs[$path]['tn_ext'];
    411         if ( isset($fs[$path]['has_high']) )
    412         {
    413           $insert{'has_high'} = $fs[$path]['has_high'];
    414         }
    415         else
    416         {
    417           $insert{'has_high'} = null;
    418         }
    419         $insert{'path'} = $path;
    420 
    421         array_push($inserts, $insert);
    422         array_push($insert_links,
    423                    array('image_id' => $insert{'id'},
    424                          'category_id' => $insert{'storage_category_id'}));
    425         array_push($infos, array('path' => $insert{'path'},
    426                                  'info' => l10n('update_research_added')));
     440        $insert = array(
     441          'id'             => $next_element_id++,
     442          'file'           => $filename,
     443          'date_available' => CURRENT_DATE,
     444          'tn_ext'         => $fs[$path]['tn_ext'],
     445          'has_high'       => isset($fs[$path]['has_high'])
     446            ? $fs[$path]['has_high']
     447            : null,
     448          'path'           => $path,
     449          );
     450       
     451        array_push(
     452          $inserts,
     453          $insert
     454          );
     455       
     456        array_push(
     457          $insert_links,
     458          array(
     459            'image_id'    => $insert{'id'},
     460            'category_id' => $db_fulldirs[$dirname],
     461            'is_storage'  => 'true',
     462            )
     463          );
     464        array_push(
     465          $infos,
     466          array(
     467            'path' => $insert{'path'},
     468            'info' => l10n('update_research_added')
     469            )
     470          );
    427471      }
    428472      else
    429473      {
    430         array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-2'));
     474        array_push(
     475          $errors,
     476          array(
     477            'path' => $path,
     478            'type' => 'PWG-UPDATE-2'
     479            )
     480          );
    431481      }
    432482    }
    433483    else
    434484    {
    435       $insert{'id'} = $next_element_id++;
    436       $insert{'file'} = $filename;
    437       $insert{'storage_category_id'} = $db_fulldirs[$dirname];
    438       $insert{'date_available'} = CURRENT_DATE;
    439       $insert{'has_high'} = $fs[$path]['has_high'];
    440       if ( isset($fs[$path]['has_high']) )
    441       {
    442         $insert{'has_high'} = $fs[$path]['has_high'];
    443       }
    444       else
    445       {
    446         $insert{'has_high'} = null;
    447       }
    448       $insert{'path'} = $path;
    449 
    450       if ( isset($fs[$path]['tn_ext']) )
    451       {
    452         $insert{'tn_ext'} = $fs[$path]['tn_ext'];
    453       }
    454       if (isset($fs[$path]['representative_ext']))
    455       {
    456         $insert{'representative_ext'} = $fs[$path]['representative_ext'];
    457       }
    458 
    459       array_push($inserts, $insert);
    460       array_push($insert_links,
    461                  array('image_id' => $insert{'id'},
    462                        'category_id' => $insert{'storage_category_id'}));
    463       array_push($infos, array('path' => $insert{'path'},
    464                                'info' => l10n('update_research_added')));
     485      $insert = array(
     486        'id'             => $next_element_id++,
     487        'file'           => $filename,
     488        'date_available' => CURRENT_DATE,
     489        'path'           => $path,
     490        'has_high'       => isset($fs[$path]['has_high'])
     491          ? $fs[$path]['has_high']
     492          : null,
     493        'tn_ext'         => isset($fs[$path]['tn_ext'])
     494          ? $fs[$path]['tn_ext']
     495          : null,
     496        'representative_ext' => isset($fs[$path]['representative_ext'])
     497          ? $fs[$path]['representative_ext']
     498          : null,
     499        );
     500
     501      array_push(
     502        $inserts,
     503        $insert
     504        );
     505
     506      array_push(
     507        $insert_links,
     508        array(
     509          'image_id'    => $insert{'id'},
     510          'category_id' => $db_fulldirs[$dirname],
     511          'is_storage'  => 'true',
     512          )
     513        );
     514
     515      array_push(
     516        $infos,
     517        array(
     518          'path' => $insert{'path'},
     519          'info' => l10n('update_research_added')
     520          )
     521        );
    465522    }
    466523  }
     
    471528    {
    472529      // inserts all new elements
    473       $dbfields = array(
    474         'id','file','storage_category_id','date_available','tn_ext'
    475         ,'representative_ext', 'has_high', 'path'
    476         );
    477       mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
    478 
    479       // insert all links between new elements and their storage category
    480       $dbfields = array('image_id','category_id');
    481       mass_inserts(IMAGE_CATEGORY_TABLE, $dbfields, $insert_links);
     530      mass_inserts(
     531        IMAGES_TABLE,
     532        array(
     533          'id', 'file', 'date_available', 'tn_ext', 'representative_ext',
     534          'has_high', 'path',
     535          ),
     536        $inserts
     537        );
     538
     539      // inserts all links between new elements and their storage category
     540      mass_inserts(
     541        IMAGE_CATEGORY_TABLE,
     542        array(
     543          'image_id','category_id', 'is_storage',
     544          ),
     545        $insert_links
     546        );
    482547    }
    483548    $counts['new_elements'] = count($inserts);
     
    533598SELECT id
    534599  FROM '.IMAGES_TABLE.'
    535   WHERE storage_category_id = \''.$row['storage_category_id'].'\'
     600    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
     601  WHERE is_storage = \'true\'
     602    AND category_id = '.$row['storage_category_id'].'
    536603    AND file = \''.$row['file'].'\'
    537604;';
     
    580647  if (!$simulate)
    581648  {
     649    $start = get_moment();
     650    check_links('all');
     651    echo '<!-- check_links(all) : ';
     652    echo get_elapsed_time($start,get_moment());
     653    echo ' -->'."\n";
    582654    $start = get_moment();
    583655    update_category('all');
Note: See TracChangeset for help on using the changeset viewer.