Ignore:
Timestamp:
Aug 29, 2008, 2:35:16 PM (16 years ago)
Author:
rvelices
Message:

synchro improvements:

  • able to sync metadata at the same time as the files/dirs
  • by default empty metadata does not overwrite database infos (checkbox can switch to previous behaviour) (bug 132)
  • the form is shown again even after a successfull non simulated run
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/site_update.php

    r2344 r2491  
    4343SELECT galleries_url
    4444  FROM '.SITES_TABLE.'
    45   WHERE id = '.$site_id.'
    46 ;';
     45  WHERE id = '.$site_id;
    4746list($site_url) = mysql_fetch_row(pwg_query($query));
    4847if (!isset($site_url))
     
    140139  $start = get_moment();
    141140  // which categories to update ?
    142   $cat_ids = array();
    143 
    144141  $query = '
    145142SELECT id, uppercats, global_rank, status, visible
     
    162159    }
    163160  }
    164   $query.= '
    165 ;';
    166   $result = pwg_query($query);
    167 
    168   $db_categories = array();
    169   while ($row = mysql_fetch_array($result))
    170   {
    171     $db_categories[$row['id']] = $row;
    172   }
     161  $db_categories = hash_from_query($query, 'id');
    173162
    174163  // get categort full directories in an array for comparison with file
     
    195184  $query = '
    196185SELECT id
    197   FROM '.CATEGORIES_TABLE.'
    198 ;';
     186  FROM '.CATEGORIES_TABLE;
    199187  $result = pwg_query($query);
    200188  while ($row = mysql_fetch_array($result))
     
    207195SELECT id_uppercat, MAX(rank)+1 AS next_rank
    208196  FROM '.CATEGORIES_TABLE.'
    209   GROUP BY id_uppercat
    210 ;';
     197  GROUP BY id_uppercat';
    211198  $result = pwg_query($query);
    212199  while ($row = mysql_fetch_array($result))
     
    223210  $query = '
    224211SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
    225   FROM '.CATEGORIES_TABLE.'
    226 ;';
     212  FROM '.CATEGORIES_TABLE;
    227213  list($next_id) = mysql_fetch_array(pwg_query($query));
    228214
     
    389375        80,
    390376        "\n"
    391         ).')
    392 ;';
    393     $result = pwg_query($query);
    394     while ($row = mysql_fetch_array($result))
    395     {
    396       $db_elements[$row['id']] = $row['path'];
    397     }
     377        ).')';
     378    $db_elements = simple_hash_from_query($query, 'id', 'path');
    398379
    399380    // searching the unvalidated waiting elements (they must not be taken into
     
    404385  WHERE storage_category_id IN (
    405386'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
    406     AND validated = \'false\'
    407 ;';
     387    AND validated = \'false\'';
    408388    $result = pwg_query($query);
    409389    while ($row = mysql_fetch_array($result))
     
    422402  $query = '
    423403SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
    424   FROM '.IMAGES_TABLE.'
    425 ;';
     404  FROM '.IMAGES_TABLE;
    426405  list($next_element_id) = mysql_fetch_array(pwg_query($query));
    427406
     
    565544  WHERE storage_category_id IN (
    566545'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
    567     AND validated = \'true\'
    568 ;';
     546    AND validated = \'true\'';
    569547    $result = pwg_query($query);
    570548
     
    586564  FROM '.IMAGES_TABLE.'
    587565  WHERE storage_category_id = '.$row['storage_category_id'].'
    588     AND file = \''.$row['file'].'\'
    589 ;';
     566    AND file = \''.$row['file'].'\'';
    590567      list($data['id']) = mysql_fetch_array(pwg_query($query));
    591568
     
    724701// |                          synchronize metadata                         |
    725702// +-----------------------------------------------------------------------+
    726 if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
     703if (isset($_POST['submit']) and isset($_POST['sync_meta'])
    727704         and !$general_failure)
    728705{
    729706  // sync only never synchronized files ?
    730   if ($_POST['sync'] == 'metadata_new')
    731   {
    732     $opts['only_new'] = true;
    733   }
    734   else
    735   {
    736     $opts['only_new'] = false;
    737   }
     707  $opts['only_new'] = isset($_POST['meta_all']) ? false : true;
    738708  $opts['category_id'] = '';
    739709  $opts['recursive'] = true;
     
    777747    AND id IN (
    778748'.wordwrap(implode(', ', $image_ids), 80, "\n").'
    779 )
    780 ;';
    781 
    782     $result = pwg_query($query);
    783     while ($row = mysql_fetch_array($result))
    784     {
    785       array_push($has_high_images, $row['id']);
    786     }
     749)';
     750    $has_high_images = array_from_query($query, 'id' );
    787751  }
    788752
     
    844808            )
    845809          ),
    846         $datas
     810        $datas,
     811        isset($_POST['meta_empty_overrides']) ? 0 : MASS_UPDATES_SKIP_EMPTY
    847812        );
    848813    }
     
    894859// |                        introduction : choices                         |
    895860// +-----------------------------------------------------------------------+
    896 if (!isset($_POST['submit']) or (isset($simulate) and $simulate))
    897 {
    898   if (isset($simulate) and $simulate)
    899   {
    900     $tpl_introduction = array(
    901         'sync'  => $_POST['sync'],
    902         'display_info' => isset($_POST['display_info']) and $_POST['display_info']==1,
    903         'add_to_caddie' => isset($_POST['add_to_caddie']) and $_POST['add_to_caddie']==1,
    904         'subcats_included' => isset($_POST['subcats-included']) and $_POST['subcats-included']==1,
    905         'privacy_level_selected' => (int)@$_POST['privacy_level'],
    906       );
    907 
    908     if (isset($_POST['cat']) and is_numeric($_POST['cat']))
    909     {
    910       $cat_selected = array($_POST['cat']);
    911     }
    912     else
    913     {
    914       $cat_selected = array();
    915     }
     861if (isset($_POST['submit']))
     862{
     863  $tpl_introduction = array(
     864      'sync'  => $_POST['sync'],
     865      'sync_meta'  => isset($_POST['sync_meta']) ? true : false,
     866      'display_info' => isset($_POST['display_info']) and $_POST['display_info']==1,
     867      'add_to_caddie' => isset($_POST['add_to_caddie']) and $_POST['add_to_caddie']==1,
     868      'subcats_included' => isset($_POST['subcats-included']) and $_POST['subcats-included']==1,
     869      'privacy_level_selected' => (int)@$_POST['privacy_level'],
     870      'meta_all'  => isset($_POST['meta_all']) ? true : false,
     871      'meta_empty_overrides'  => isset($_POST['meta_empty_overrides']) ? true : false,
     872    );
     873
     874  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
     875  {
     876    $cat_selected = array($_POST['cat']);
    916877  }
    917878  else
    918879  {
    919     $tpl_introduction = array(
    920         'sync'  => 'dirs',
    921         'display_info' => false,
    922         'add_to_caddie' => false,
    923         'subcats_included' => true,
    924         'privacy_level_selected' => 0,
    925       );
    926 
    927880    $cat_selected = array();
    928881  }
    929 
    930   $tpl_introduction['privacy_level_options']=array();
    931   foreach ($conf['available_permission_levels'] as $level)
    932   {
    933     $tpl_introduction['privacy_level_options'][$level] = l10n( sprintf('Level %d', $level) );
    934   }
    935 
    936   $template->assign('introduction', $tpl_introduction);
    937 
    938   $query = '
     882}
     883else
     884{
     885  $tpl_introduction = array(
     886      'sync'  => 'dirs',
     887      'sync_meta'  => true,
     888      'display_info' => false,
     889      'add_to_caddie' => false,
     890      'subcats_included' => true,
     891      'privacy_level_selected' => 0,
     892      'meta_all'  => false,
     893      'meta_empty_overrides'  => false,
     894    );
     895
     896  $cat_selected = array();
     897}
     898
     899$tpl_introduction['privacy_level_options']=array();
     900foreach ($conf['available_permission_levels'] as $level)
     901{
     902  $tpl_introduction['privacy_level_options'][$level] = l10n( sprintf('Level %d', $level) );
     903}
     904
     905$template->assign('introduction', $tpl_introduction);
     906
     907$query = '
    939908SELECT id,name,uppercats,global_rank
    940909  FROM '.CATEGORIES_TABLE.'
    941   WHERE site_id = '.$site_id.'
    942 ;';
    943   display_select_cat_wrapper($query,
    944                              $cat_selected,
    945                              'category_options',
    946                              false);
    947 }
     910  WHERE site_id = '.$site_id;
     911display_select_cat_wrapper($query,
     912                           $cat_selected,
     913                           'category_options',
     914                           false);
     915
    948916
    949917if (count($errors) > 0)
Note: See TracChangeset for help on using the changeset viewer.