Changeset 5982


Ignore:
Timestamp:
Apr 28, 2010, 4:28:05 PM (15 years ago)
Author:
plg
Message:

feature 1630: upgrade to Piwigo 2.1 :-)

bug 1604: only activate core themes not all themes.

Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_install.inc.php

    r5781 r5982  
    3434 * @return void
    3535 */
    36 function execute_sqlfile($filepath, $replaced, $replacing)
     36function execute_sqlfile($filepath, $replaced, $replacing, $dblayer)
    3737{
    3838  $sql_lines = file($filepath);
     
    5555      if (!preg_match('/^DROP TABLE/i', $query))
    5656      {
    57         global $install_charset_collate;
    58         if ( !empty($install_charset_collate) )
     57        if ('mysql' == $dblayer)
    5958        {
    6059          if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) )
    6160          {
    62             $query = $matches[1].' '.$install_charset_collate.';';
     61            $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';';
    6362          }
    6463        }
     
    126125
    127126/**
    128  * Automatically activate all themes in the "themes" directory.
     127 * Automatically activate all core themes in the "themes" directory.
    129128 *
    130129 * @return void
    131130 */
    132 function activate_all_themes()
     131function activate_core_themes()
    133132{
    134133  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
     
    136135  foreach ($themes->fs_themes as $theme_id => $fs_theme)
    137136  {
    138     $themes->perform_action('activate', $theme_id);
     137    if (in_array($theme_id, array('Sylvia', 'clear', 'dark')))
     138    {
     139      $themes->perform_action('activate', $theme_id);
     140    }
    139141  }
    140142}
     
    144146  try
    145147  {
    146     $pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'],
    147                                   $_POST['dbpasswd'], $_POST['dbname']);
    148  
    149     return $pwg_db_link;
     148    $pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpasswd'], $_POST['dbname']);
     149    if ($pwg_db_link)
     150    {
     151      pwg_db_check_version();
     152    }
    150153  }
    151154  catch (Exception $e)
     
    153156    array_push( $errors, l10n($e->getMessage()));
    154157  }
    155   return false;
    156158}
    157159?>
  • trunk/admin/include/functions_upgrade.php

    r5387 r5982  
    7777
    7878  $standard_plugins = array(
    79     'add_index',
    80     'admin_advices',
    8179    'admin_multi_view',
    8280    'c13y_upgrade',
     
    222220  try
    223221  {
    224     $pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
    225                                   $conf['db_password'], $conf['db_base']);
     222    $pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'], $conf['db_password'], $conf['db_base']);
     223    if ($pwg_db_link)
     224    {
     225      pwg_db_check_version();
     226    }
    226227  }
    227228  catch (Exception $e)
     
    231232}
    232233
     234/**
     235 *  Get languages defined in the language directory
     236 */ 
     237function get_fs_languages($target_charset = null)
     238{
     239  if ( empty($target_charset) )
     240  {
     241    $target_charset = get_pwg_charset();
     242  }
     243  $target_charset = strtolower($target_charset);
     244 
     245  $dir = opendir(PHPWG_ROOT_PATH.'language');
     246 
     247  while ($file = readdir($dir))
     248  {
     249    $path = PHPWG_ROOT_PATH.'language/'.$file;
     250    if (!is_link($path) and is_dir($path) and file_exists($path.'/iso.txt'))
     251    {
     252      list($language_name) = @file($path.'/iso.txt');
     253     
     254      $languages[$file] = convert_charset($language_name, $target_charset);
     255    }
     256  }
     257  closedir($dir);
     258  @asort($languages);
     259 
     260  return $languages;
     261}
     262
    233263?>
  • trunk/include/dblayer/functions_mysql.inc.php

    r5782 r5982  
    5353function pwg_db_check_charset()
    5454{
    55   defined('PWG_CHARSET') and defined('DB_CHARSET')
    56     or fatal_error('PWG_CHARSET and/or DB_CHARSET is not defined');
    57   if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
    58   {
    59     if (DB_CHARSET!='')
    60     {
    61       pwg_query('SET NAMES "'.DB_CHARSET.'"');
    62     }
    63   }
    64   elseif ( strtolower(PWG_CHARSET)!='iso-8859-1' )
    65   {
    66     fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
     55  $db_charset = 'utf8';
     56  if (defined('DB_CHARSET') and DB_CHARSET != '')
     57  {
     58    $db_charset = DB_CHARSET;
     59  }
     60  pwg_query('SET NAMES "'.$db_charset.'"');
     61}
     62
     63function pwg_db_check_version()
     64{
     65  $current_mysql = pwg_get_db_version();
     66  if (version_compare($current_mysql, REQUIRED_MYSQL_VERSION, '<'))
     67  {
     68    fatal_error(
     69      sprintf(
     70        'your MySQL version is too old, you have "%s" and you need at least "%s"',
     71        $current_mysql,
     72        REQUIRED_MYSQL_VERSION
     73        )
     74      );
    6775  }
    6876}
  • trunk/include/functions.inc.php

    r5781 r5982  
    695695  while ($row = pwg_db_fetch_assoc($result))
    696696  {
    697     if (file_exists($conf['themes_dir'].'/'.$row['id'].'/'.'themeconf.inc.php'))
     697    if (check_theme_installed($row['id']))
    698698    {
    699699      $themes[ $row['id'] ] = $row['name'];
     
    705705
    706706  return $themes;
     707}
     708
     709function check_theme_installed($theme_id)
     710{
     711  global $conf;
     712
     713  return file_exists($conf['themes_dir'].'/'.$theme_id.'/'.'themeconf.inc.php');
    707714}
    708715
     
    11491156function get_pwg_charset()
    11501157{
    1151   defined('PWG_CHARSET') or fatal_error('PWG_CHARSET undefined');
    1152   return PWG_CHARSET;
     1158  $pwg_charset = 'utf-8';
     1159  if (defined('PWG_CHARSET'))
     1160  {
     1161    $pwg_charset = PWG_CHARSET;
     1162  }
     1163  return $pwg_charset;
    11531164}
    11541165
  • trunk/include/functions_user.inc.php

    r5272 r5982  
    849849function get_default_theme()
    850850{
    851   return get_default_user_value('theme', PHPWG_DEFAULT_TEMPLATE);
     851  $theme = get_default_user_value('theme', PHPWG_DEFAULT_TEMPLATE);
     852  if (check_theme_installed($theme))
     853  {
     854    return $theme;
     855  }
     856 
     857  // let's find the first available theme
     858  $active_themes = get_pwg_themes();
     859  foreach (array_keys(get_pwg_themes()) as $theme_id)
     860  {
     861    if (check_theme_installed($theme_id))
     862    {
     863      return $theme_id;
     864    }
     865  }
    852866}
    853867
  • trunk/install.php

    r5781 r5982  
    263263if ( isset( $_POST['install'] ))
    264264{
    265   if ($pwg_db_link = install_db_connect($infos, $errors))
    266   {
    267     $required_version = constant('REQUIRED_'.strtoupper($dblayer).'_VERSION');
    268     if ( version_compare(pwg_get_db_version(), $required_version, '>=') )
    269     {
    270       $pwg_charset = 'utf-8';
    271       $pwg_db_charset = 'utf8';
    272       if ($dblayer=='mysql')
    273       {
    274         $install_charset_collate = "DEFAULT CHARACTER SET $pwg_db_charset";
    275         pwg_query('SET NAMES "'.$pwg_db_charset.'"');
    276       }
    277       else
    278       {
    279         $install_charset_collate = '';
    280       }
    281     }
    282     else
    283     {
    284       $pwg_charset = 'iso-8859-1';
    285       $pwg_db_charset = 'latin1';
    286       $install_charset_collate = '';
    287       if ( !array_key_exists($language, $languages->get_fs_languages($pwg_charset) ) )
    288       {
    289         $language='en_UK';
    290       }
    291     }
    292   }
     265  install_db_connect($infos, $errors);
     266  pwg_db_check_charset();
    293267
    294268  $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name ));
     
    321295
    322296define(\'PHPWG_INSTALLED\', true);
    323 define(\'PWG_CHARSET\', \''.$pwg_charset.'\');
    324 define(\'DB_CHARSET\', \''.$pwg_db_charset.'\');
     297define(\'PWG_CHARSET\', \'utf-8\');
     298define(\'DB_CHARSET\', \'utf8\');
    325299define(\'DB_COLLATE\', \'\');
    326300
     
    351325      PHPWG_ROOT_PATH.'install/piwigo_structure-'.$dblayer.'.sql',
    352326      DEFAULT_PREFIX_TABLE,
    353       $prefixeTable
     327      $prefixeTable,
     328      $dblayer
    354329      );
    355330    // We fill the tables with basic informations
     
    357332      PHPWG_ROOT_PATH.'install/config.sql',
    358333      DEFAULT_PREFIX_TABLE,
    359       $prefixeTable
     334      $prefixeTable,
     335      $dblayer
    360336      );
    361337
     
    367343
    368344    // fill languages table
    369     foreach ($languages->get_fs_languages($pwg_charset) as $language_code => $language_name)
     345    foreach ($languages->get_fs_languages() as $language_code => $language_name)
    370346    {
    371347      $languages->perform_action('activate', $language_code);
     
    379355    if (!defined('PWG_CHARSET'))
    380356    {
    381       define('PWG_CHARSET', $pwg_charset);
    382     }
    383     activate_all_themes();
     357      define('PWG_CHARSET', 'utf-8');
     358    }
     359    activate_core_themes();
    384360
    385361    $insert = array(
  • trunk/install/db/65-database.php

    r5215 r5982  
    166166  $query = 'SHOW TABLES LIKE "'.$prefixeTable.'%"';
    167167  $result = pwg_query($query);
    168   while ( $row=pwg_db_fetch_assoc($result) )
     168  while ( $row=pwg_db_fetch_row($result) )
    169169  {
    170170    array_push($all_tables, $row[0]);
  • trunk/install/db/86-database.php

    r5452 r5982  
    2727}
    2828
    29 $upgrade_description = 'Automatically activate core themes and used themes.';
     29$upgrade_description = 'Automatically activate core themes.';
    3030
    31 $themes_core = array('Sylvia', 'dark', 'clear');
    32 
    33 $query = '
    34 SELECT
    35     DISTINCT(theme)
    36   FROM '.PREFIX_TABLE.'user_infos
    37 ;';
    38 $themes_used = array_from_query($query, 'theme');
    39 
    40 $query = '
    41 SELECT
    42     id
    43   FROM '.PREFIX_TABLE.'themes
    44 ;';
    45 $themes_active = array_from_query($query, 'id');
    46 
    47 
    48 $themes_to_activate = array_diff(
    49   array_unique(array_merge($themes_used, $themes_core)),
    50   $themes_active
    51   );
    52 
    53 // echo '<pre>'; print_r($themes_to_activate); echo '</pre>'; exit();
    54 
    55 foreach ($themes_to_activate as $theme)
    56 {
    57   $query = '
    58 INSERT INTO '.PREFIX_TABLE.'themes
    59   (id) VALUES(\''.$theme.'\'
    60 ;';
    61   pwg_query($query);
    62 }
     31include_once(PHPWG_ROOT_PATH . 'admin/include/functions_install.inc.php');
     32activate_core_themes();
    6333
    6434echo
  • trunk/install/upgrade_1.7.0.php

    r5196 r5982  
    3333  }
    3434}
    35 
    36 define('UPGRADES_PATH', PHPWG_ROOT_PATH.'install/db');
    37 
    38 list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
    39 define('CURRENT_DATE', $dbnow);
    4035
    4136// +-----------------------------------------------------------------------+
     
    8984echo '<pre>';
    9085
    91 for ($upgrade_id = 61; ; $upgrade_id++)
     86for ($upgrade_id = 61; $upgrade_id <= 79; $upgrade_id++)
    9287{
    9388  if (!file_exists(UPGRADES_PATH.'/'.$upgrade_id.'-database.php'))
     
    120115
    121116// now we upgrade from 2.0.0
    122 // include_once(PHPWG_ROOT_PATH.'install/upgrade_2.0.0.php');
     117include_once(PHPWG_ROOT_PATH.'install/upgrade_2.0.0.php');
    123118?>
  • trunk/upgrade.php

    r5573 r5982  
    4848include_once(PHPWG_ROOT_PATH.'include/constants.php');
    4949define('PREFIX_TABLE', $prefixeTable);
     50define('UPGRADES_PATH', PHPWG_ROOT_PATH.'install/db');
    5051
    5152// +-----------------------------------------------------------------------+
     
    202203
    203204upgrade_db_connect();
    204 
    205205pwg_db_check_charset();
     206
     207list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
     208define('CURRENT_DATE', $dbnow);
    206209
    207210// +-----------------------------------------------------------------------+
     
    261264  $current_release = '1.7.0';
    262265}
     266else if (!in_array(PREFIX_TABLE.'themes', $tables))
     267{
     268  $current_release = '2.0.0';
     269}
    263270else
    264271{
     
    297304      if (!@file_put_contents($config_file, $config_file_contents))
    298305      {
    299         array_push($page['infos'],
    300                    l10n_args('In <i>%s</i>, before <b>?></b>, insert:',
    301                              'local/config/database.inc.php') .
    302                    '<p><textarea rows="4" cols="40">' .
    303                    implode("\r\n" , $mysql_changes).'</textarea></p>'
    304                    );
     306        array_push(
     307          $page['infos'],
     308          sprintf(
     309            l10n('In <i>%s</i>, before <b>?></b>, insert:'),
     310            'local/config/database.inc.php'
     311            )
     312          .'<p><textarea rows="4" cols="40">'
     313          .implode("\r\n" , $mysql_changes).'</textarea></p>'
     314          );
    305315      }
    306316    }
     
    368378else
    369379{
    370   foreach (get_languages('utf-8') as $language_code => $language_name)
     380  if (!defined('PWG_CHARSET'))
     381  {
     382    define('PWG_CHARSET', 'utf-8');
     383  }
     384
     385  include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php');
     386  $languages = new languages();
     387 
     388  foreach ($languages->fs_languages as $language_code => $language_name)
    371389  {
    372390    if ($language == $language_code)
Note: See TracChangeset for help on using the changeset viewer.