Changeset 589 for trunk/admin/update.php


Ignore:
Timestamp:
Nov 1, 2004, 4:01:28 PM (19 years ago)
Author:
z0rglub
Message:
  • synchronization interface redesigned : a form lets user choose option of dirs/files/metadata sync on all categories or a defined one (including subcategories)
  • database sync is only available through update.php
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/update.php

    r587 r589  
    3333
    3434define('CURRENT_DATE', "'".date('Y-m-d')."'");
    35 //------------------------------------------------------------------- functions
     35// +-----------------------------------------------------------------------+
     36// |                              functions                                |
     37// +-----------------------------------------------------------------------+
     38
    3639/**
    3740 * order categories (update categories.rank database field)
     
    119122    // 2. we search pictures of the category only if the update is for all
    120123    //    or a cat_id is specified
    121     if (isset($page['cat']) or $_GET['update'] == 'all')
     124    if ($_POST['sync'] == 'files')
    122125    {
    123126      $output.= insert_local_element($cat_directory, $id_uppercat);
     
    240243
    241244  // Recursive call on the sub-categories (not virtual ones)
    242   $query = '
     245  if (!isset($_POST['cat'])
     246      or (isset($_POST['subcats-included'])
     247          and $_POST['subcats-included'] == 1))
     248  {
     249    $query = '
    243250SELECT id
    244251  FROM '.CATEGORIES_TABLE.'
    245252  WHERE site_id = 1
    246253';
    247   if (!is_numeric($id_uppercat))
    248   {
    249     $query.= '    AND id_uppercat IS NULL';
    250   }
    251   else
    252   {
    253     $query.= '    AND id_uppercat = '.$id_uppercat;
    254   }
    255   $query.= '
     254    if (!is_numeric($id_uppercat))
     255    {
     256      $query.= '    AND id_uppercat IS NULL';
     257    }
     258    else
     259    {
     260      $query.= '    AND id_uppercat = '.$id_uppercat;
     261    }
     262    $query.= '
    256263    AND dir IS NOT NULL'; // virtual categories not taken
    257   $query.= '
    258 ;';
    259   $result = pwg_query($query);
    260   while ($row = mysql_fetch_array($result))
    261   {
    262     $output.= insert_local_category($row['id']);
     264    $query.= '
     265;';
     266    $result = pwg_query($query);
     267    while ($row = mysql_fetch_array($result))
     268    {
     269      $output.= insert_local_category($row['id']);
     270    }
    263271  }
    264272
     
    543551  return $output;
    544552}
    545 //----------------------------------------------------- template initialization
     553// +-----------------------------------------------------------------------+
     554// |                        template initialization                        |
     555// +-----------------------------------------------------------------------+
    546556$template->set_filenames(array('update'=>'admin/update.tpl'));
    547557
    548 $template->assign_vars(array(
    549   'L_UPDATE_TITLE'=>$lang['update_default_title'],
    550   'L_CAT_UPDATE'=>$lang['update_only_cat'],
    551   'L_ALL_UPDATE'=>$lang['update_all'],
    552   'L_RESULT_UPDATE'=>$lang['update_part_research'],
    553   'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'],
    554   'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'],
    555   'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'],
    556   'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'],
    557   'L_UPDATE_SYNC_METADATA_QUESTION'=>$lang['update_sync_metadata_question'],
    558  
    559   'U_CAT_UPDATE'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=update&update=cats'),
    560   'U_ALL_UPDATE'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=update&update=all')
    561  ));
    562 //-------------------------------------------- introduction : choices of update
    563 // Display choice if "update" var is not specified
    564 if (!isset($_GET['update']))
     558$base_url = PHPWG_ROOT_PATH.'admin.php?page=update';
     559
     560$template->assign_vars(
     561  array(
     562    'L_SUBMIT'=>$lang['submit'],
     563    'L_UPDATE_TITLE'=>$lang['update_default_title'],
     564    'L_UPDATE_SYNC_FILES'=>$lang['update_sync_files'],
     565    'L_UPDATE_SYNC_DIRS'=>$lang['update_sync_dirs'],
     566    'L_UPDATE_SYNC_ALL'=>$lang['update_sync_all'],
     567    'L_UPDATE_SYNC_METADATA'=>$lang['update_sync_metadata'],
     568    'L_UPDATE_SYNC_METADATA_NEW'=>$lang['update_sync_metadata_new'],
     569    'L_UPDATE_SYNC_METADATA_ALL'=>$lang['update_sync_metadata_all'],
     570    'L_UPDATE_CATS_SUBSET'=>$lang['update_cats_subset'],
     571    'L_RESULT_UPDATE'=>$lang['update_part_research'],
     572    'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'],
     573    'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'],
     574    'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'],
     575    'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'],
     576    'L_SEARCH_SUBCATS_INCLUDED'=>$lang['search_subcats_included'],
     577   
     578    'U_SYNC_DIRS'=>add_session_id($base_url.'&update=dirs'),
     579    'U_SYNC_ALL'=>add_session_id($base_url.'&update=all'),
     580    'U_SYNC_METADATA_NEW'=>add_session_id($base_url.'&metadata=all:new'),
     581    'U_SYNC_METADATA_ALL'=>add_session_id($base_url.'&metadata=all')
     582    ));
     583// +-----------------------------------------------------------------------+
     584// |                        introduction : choices                         |
     585// +-----------------------------------------------------------------------+
     586if (!isset($_POST['submit']))
    565587{
    566  $template->assign_block_vars('introduction',array());
     588  $template->assign_block_vars('introduction', array());
     589
     590  $query = '
     591SELECT id
     592  FROM '.CATEGORIES_TABLE.'
     593  WHERE site_id != 1
     594;';
     595  $result = pwg_query($query);
     596  while ($row = mysql_fetch_array($result))
     597  {
     598    array_push($user['restrictions'], $row['id']);
     599  }
     600  $user['forbidden_categories'] = implode(',', $user['restrictions']);
     601  $user['expand'] = true;
     602  $structure = create_user_structure('');
     603  display_select_categories($structure,
     604                            ' ',
     605                            array(),
     606                            'introduction.category_option');
    567607}
    568 //-------------------------------------------------- local update : ./galleries
    569 else if (!isset($_GET['metadata']))
     608// +-----------------------------------------------------------------------+
     609// |                          synchronize files                            |
     610// +-----------------------------------------------------------------------+
     611else if (isset($_POST['submit'])
     612         and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
    570613{
    571   check_cat_id($_GET['update']);
    572   $start = get_moment();
    573614  $counts = array(
    574615    'new_elements' => 0,
     
    577618    'del_categories' => 0
    578619    );
    579  
    580   if (isset($page['cat']))
    581   {
    582     $categories = insert_local_category($page['cat']);
     620
     621  if (isset($_POST['cat']))
     622  {
     623    $opts['category_id'] = $_POST['cat'];
    583624  }
    584625  else
    585626  {
    586     $categories = insert_local_category('NULL');
    587   }
     627    $opts['category_id'] = 'NULL';
     628  }
     629 
     630  $start = get_moment();
     631  $categories = insert_local_category($opts['category_id']);
    588632  echo get_elapsed_time($start,get_moment()).' for scanning directories<br />';
     633 
    589634  $template->assign_block_vars(
    590635    'update',
     
    596641      'NB_DEL_ELEMENTS'=>$counts['del_elements']
    597642      ));
    598   if ($counts['new_elements'] > 0)
    599   {
    600     $url = PHPWG_ROOT_PATH.'admin.php?page=update&amp;metadata=1';
    601     if (isset($page['cat']))
    602     {
    603       $url.= '&amp;update='.$page['cat'];
    604     }
    605     $template->assign_block_vars(
    606       'update.sync_metadata',
    607       array(
    608         'U_URL' => add_session_id($url)
    609         ));
    610   }
    611 }
    612 //---------------------------------------- update informations about categories
    613 if (!isset($_GET['metadata'])
    614     and (isset($_GET['update'])
    615          or isset($page['cat'])
    616          or @is_file('./listing.xml') && DEBUG))
    617 {
    618643  $start = get_moment();
    619644  update_category('all');
     
    623648  echo get_elapsed_time($start, get_moment()).' for ordering categories<br />';
    624649}
    625 //---------------------------------------------------- metadata synchronization
    626 if (isset($_GET['metadata']))
     650// +-----------------------------------------------------------------------+
     651// |                          synchronize metadata                         |
     652// +-----------------------------------------------------------------------+
     653else if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync']))
    627654{
    628   if (isset($_GET['update']))
    629   {
    630     check_cat_id($_GET['update']);
    631   }
    632 
     655  // sync only never synchronized files ?
     656  if ($_POST['sync'] == 'metadata_new')
     657  {
     658    $opts['only_new'] = true;
     659  }
     660  else
     661  {
     662    $opts['only_new'] = false;
     663  }
     664  $opts['category_id'] = '';
     665  $opts['recursive'] = true;
     666 
     667  if (isset($_POST['cat']))
     668  {
     669    $opts['category_id'] = $_POST['cat'];
     670    // recursive ?
     671    if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
     672    {
     673      $opts['recursive'] = false;
     674    }
     675  }
    633676  $start = get_moment();
    634   if (isset($page['cat']))
    635   {
    636     $files = get_filelist($page['cat'],true,true);
    637   }
    638   else
    639   {
    640     $files = get_filelist('',true,true);
    641   }
     677  $files = get_filelist($opts['category_id'],
     678                        $opts['recursive'],
     679                        $opts['only_new']);
    642680  echo get_elapsed_time($start, get_moment()).' for get_filelist<br />';
    643681 
     
    646684  echo get_elapsed_time($start, get_moment()).' for metadata update<br />';
    647685}
    648 //----------------------------------------------------------- sending html code
     686// +-----------------------------------------------------------------------+
     687// |                          sending html code                            |
     688// +-----------------------------------------------------------------------+
    649689$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
    650690?>
Note: See TracChangeset for help on using the changeset viewer.