Ignore:
Timestamp:
Sep 30, 2011, 10:49:29 PM (13 years ago)
Author:
Eric
Message:

Merge r12275 from trunk to branch 2.30

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserAdvManager/branches/2.30/include/functions.inc.php

    r12272 r12276  
    28402840        for ($i=0; $i<$nb_fields; $i++)
    28412841        {
    2842           $insertions .= '\'' . mysql_real_escape_string($line[$i]) . '\', ';
     2842          $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', ';
    28432843        }
    28442844        $insertions = substr($insertions, 0, -2);
     
    28692869    for ($i=0; $i<$nb_fields; $i++)
    28702870    {
    2871       $insertions .= '\'' . mysql_real_escape_string($line[$i]) . '\', ';
     2871      $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', ';
    28722872    }
    28732873    $insertions = substr($insertions, 0, -2);
     
    29042904  return true;
    29052905}
     2906
     2907
     2908/**
     2909 * UAM_Restore_backup_file
     2910 * Restore backup database file
     2911 *
     2912 * @returns : Boolean
     2913 */
     2914function UAM_Restore_backup_file()
     2915{
     2916  global $prefixeTable, $dblayer, $conf;
     2917 
     2918  define('DEFAULT_PREFIX_TABLE', 'piwigo_');
     2919 
     2920  $Backup_File = UAM_PATH.'/include/backup/UAM_dbbackup.sql';
     2921
     2922  // Cleanup database before restoring
     2923  // ---------------------------------
     2924
     2925  // Delete UserAdvManager global config in #_config table
     2926  $q = '
     2927DELETE FROM '.CONFIG_TABLE.'
     2928WHERE param="UserAdvManager"
     2929;';
     2930
     2931  pwg_query($q);
     2932
     2933  // Delete UserAdvManager_ConfirmMail global config in #_config table
     2934  $q = '
     2935DELETE FROM '.CONFIG_TABLE.'
     2936WHERE param="UserAdvManager_ConfirmMail"
     2937;';
     2938
     2939  pwg_query($q);
     2940
     2941  // Delete UserAdvManager_Redir config in #_config table
     2942  $q = '
     2943DELETE FROM '.CONFIG_TABLE.'
     2944WHERE param="UserAdvManager_Redir"
     2945;';
     2946
     2947  pwg_query($q);
     2948
     2949  // Delete UserAdvManager_Version config in #_config table
     2950  $q = '
     2951DELETE FROM '.CONFIG_TABLE.'
     2952WHERE param="UserAdvManager_Version"
     2953;';
     2954
     2955  pwg_query($q);
     2956
     2957  // Restore sql backup file - DROP TABLE queries are executed
     2958  // ---------------------------------------------------------
     2959  UAM_execute_sqlfile(
     2960    $Backup_File,
     2961    DEFAULT_PREFIX_TABLE,
     2962    $prefixeTable,
     2963    $dblayer
     2964  );
     2965}
     2966
     2967
     2968/**
     2969 * loads an sql file and executes all queries / Based on Piwigo's original install file
     2970 *
     2971 * Before executing a query, $replaced is... replaced by $replacing. This is
     2972 * useful when the SQL file contains generic words.
     2973 *
     2974 * @param string filepath
     2975 * @param string replaced
     2976 * @param string replacing
     2977 * @return void
     2978 */
     2979function UAM_execute_sqlfile($filepath, $replaced, $replacing, $dblayer)
     2980{
     2981  $sql_lines = file($filepath);
     2982  $query = '';
     2983  foreach ($sql_lines as $sql_line)
     2984  {
     2985    $sql_line = trim($sql_line);
     2986    if (preg_match('/(^--|^$)/', $sql_line))
     2987    {
     2988      continue;
     2989    }
     2990   
     2991    $query.= ' '.$sql_line;
     2992   
     2993    // if we reached the end of query, we execute it and reinitialize the
     2994    // variable "query"
     2995    if (preg_match('/;$/', $sql_line))
     2996    {
     2997      $query = trim($query);
     2998      $query = str_replace($replaced, $replacing, $query);
     2999      if ('mysql' == $dblayer)
     3000      {
     3001        if (preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches))
     3002        {
     3003          $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';';
     3004        }
     3005      }
     3006      pwg_query($query);
     3007      $query = '';
     3008    }
     3009  }
     3010}
     3011
    29063012
    29073013
Note: See TracChangeset for help on using the changeset viewer.