b2evolution PHP Cross Reference Blogging Systems

Source: /inc/maintenance/model/_maintenance.funcs.php - 869 lines - 23737 bytes - Summary - Text - Print

   1  <?php
   2  
   3  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
   4  
   5  
   6  /**
   7   * Get the upgrade folder path
   8   *
   9   * @param string Name of folder with current downloaded version
  10   * @return string The upgrade folder path (No slash at the end)
  11   */
  12  function get_upgrade_folder_path( $version_folder_name )
  13  {
  14      global $upgrade_path;
  15  
  16      if( empty( $version_folder_name ) || ! file_exists( $upgrade_path.$version_folder_name ) )
  17      { // Don't allow an invalid upgrade folder
  18          debug_die( 'Invalid name of upgrade folder' );
  19      }
  20  
  21      // Use a root path by default
  22      $upgrade_folder_path = $upgrade_path.$version_folder_name;
  23  
  24      if( file_exists( $upgrade_folder_path.'/b2evolution/blogs' ) )
  25      { // Use 'b2evolution/blogs' folder
  26          $upgrade_folder_path .= '/b2evolution/blogs';
  27      }
  28      else if( file_exists( $upgrade_folder_path.'/b2evolution/site' ) )
  29      { // Use 'b2evolution/site' folder
  30          $upgrade_folder_path .= '/b2evolution/site';
  31      }
  32      else if( file_exists( $upgrade_folder_path.'/b2evolution' ) )
  33      { // Use 'b2evolution' folder
  34          $upgrade_folder_path .= '/b2evolution';
  35      }
  36  
  37      return $upgrade_folder_path;
  38  }
  39  
  40  
  41  /**
  42   * Check version of downloaded upgrade vs. current version
  43   *
  44   * @param new version dir name
  45   * @return string message or NULL
  46   */
  47  function check_version( $new_version_dir )
  48  {
  49      global $rsc_url, $upgrade_path, $conf_path;
  50  
  51      $new_version_file = get_upgrade_folder_path( $new_version_dir ).'/conf/_application.php';
  52  
  53      if( ! file_exists( $new_version_file ) )
  54      { // Invalid structure of the downloaded upgrade package
  55          debug_die( '/conf/_application.php not found in /b2evolution/blogs/ nor /b2evolution/site/ nor /b2evolution/! You may have downloaded an invalid ZIP package.' );
  56      }
  57  
  58      require( $new_version_file );
  59  
  60      $vc = version_compare( $app_version, $GLOBALS['app_version'] );
  61  
  62      if( $vc < 0 )
  63      {
  64          $result = 'old';
  65      }
  66      elseif( $vc == 0 )
  67      {
  68          if( $app_date == $GLOBALS['app_date'] )
  69          {
  70              $result = 'same';
  71          }
  72          elseif( $app_date < $GLOBALS['app_date'] )
  73          {
  74              $result = 'old';
  75          }
  76      }
  77  
  78      if( empty( $result ) )
  79      {
  80          return NULL;
  81      }
  82      elseif( $result == 'old' )
  83      {
  84          return T_( 'This is an old version!' )
  85              .'<p>'.T_('You should NOT install this older version.').'</p>';
  86      }
  87      elseif( $result == 'same' )
  88      {
  89          return T_( 'This package is already installed!' )
  90              .'<p style="color:#000">'.T_( 'No upgrade is needed at this time. You might force a re-install if you want to force a cleanup.' ).'</p>';
  91      }
  92  }
  93  
  94  
  95  /**
  96   * Enable/disable maintenance mode
  97   *
  98   * @param boolean true if maintenance mode need to be enabled
  99   * @param string Mode: 'all', 'install', 'upgrade'
 100   * @param string maintenance mode message
 101   * @param boolean TRUE to don't print out a message status
 102   */
 103  function switch_maintenance_mode( $enable, $mode = 'all', $msg = '', $silent = false )
 104  {
 105      global $conf_path;
 106  
 107      switch( $mode )
 108      {
 109          case 'install':
 110              // Use maintenance mode except of install actions
 111              $maintenance_mode_file = 'imaintenance.html';
 112              break;
 113  
 114          case 'upgrade':
 115              // Use maintenance mode except of upgrade actions
 116              $maintenance_mode_file = 'umaintenance.html';
 117              break;
 118  
 119          default:
 120              // Use full maintenance mode
 121              $maintenance_mode_file = 'maintenance.html';
 122              break;
 123      }
 124  
 125      if( $enable )
 126      {    // Create maintenance file
 127          echo '<p>'.T_('Switching to maintenance mode...');
 128          evo_flush();
 129  
 130          $content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 131  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
 132  <head>
 133      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 134      <title>Site temporarily down for maintenance.</title>
 135  </head>
 136  <body>
 137  <h1>503 Service Unavailable</h1>
 138  <p>'.$msg.'</p>
 139  <hr />
 140  <p>Site administrators: please view the source of this page for details.</p>
 141  <!--
 142  If you need to manually put b2evolution out of maintenance mode, delete or rename the file /conf/maintenance.html
 143  -->
 144  </body>
 145  </html>';
 146  
 147          if( save_to_file( $content, $conf_path.$maintenance_mode_file, 'w+' ) )
 148          { // Maintenance file has been created
 149              echo ' OK.</p>';
 150          }
 151          else
 152          { // Maintenance file has not been created
 153              echo '</p><p style="color:red">'.sprintf( T_( 'Unable to switch maintenance mode. Maintenance file can\'t be created: &laquo;%s&raquo;' ), $maintenance_mode_file ).'</p>';
 154              evo_flush();
 155  
 156              return false;
 157          }
 158      }
 159      else
 160      {    // Delete maintenance file
 161          if( ! $silent )
 162          {
 163              echo '<p>'.T_('Switching out of maintenance mode...');
 164          }
 165          if( is_writable( $conf_path.$maintenance_mode_file ) )
 166          { // Delete a maintenance file if it exists and writable
 167              if( @unlink( $conf_path.$maintenance_mode_file ) )
 168              { // Unlink was successful
 169                  if( ! $silent )
 170                  { // Dispaly OK message
 171                      echo ' OK.</p>';
 172                  }
 173              }
 174              else
 175              { // Unlink failed
 176                  echo '</p><p style="color:red">'.sprintf( T_( 'Unable to delete a maintenance file: &laquo;%s&raquo;' ), $maintenance_mode_file ).'</p>';
 177              }
 178          }
 179          evo_flush();
 180      }
 181  
 182      return true;
 183  }
 184  
 185  
 186  /**
 187   * Prepare maintenance directory
 188   *
 189   * @param string directory path
 190   * @param boolean create .htaccess file with 'deny from all' text
 191   * @return boolean
 192   */
 193  function prepare_maintenance_dir( $dir_name, $deny_access = true )
 194  {
 195  
 196      // echo '<p>'.T_('Checking destination directory: ').$dir_name.'</p>';
 197      if( !file_exists( $dir_name ) )
 198      {    // We can create directory
 199          if ( ! mkdir_r( $dir_name ) )
 200          {
 201              echo '<p style="color:red">'.sprintf( T_( 'Unable to create &laquo;%s&raquo; directory.' ), $dir_name ).'</p>';
 202              evo_flush();
 203  
 204              return false;
 205          }
 206      }
 207  
 208      if( $deny_access )
 209      {    // Create .htaccess file
 210          echo '<p>'.T_('Checking .htaccess denial for directory: ').$dir_name;
 211          evo_flush();
 212  
 213          $htaccess_name = $dir_name.'.htaccess';
 214  
 215          if( !file_exists( $htaccess_name ) )
 216          {    // We can create .htaccess file
 217              if( ! save_to_file( 'deny from all', $htaccess_name, 'w' ) )
 218              {
 219                  echo '</p><p style="color:red">'.sprintf( T_( 'Unable to create &laquo;%s&raquo; file in directory.' ), $htaccess_name ).'</p>';
 220                  evo_flush();
 221  
 222                  return false;
 223              }
 224  
 225              if( ! file_exists($dir_name.'index.html') )
 226              {    // Create index.html to disable directory browsing
 227                  save_to_file( '', $dir_name.'index.html', 'w' );
 228              }
 229          }
 230  
 231          echo ' : OK.</p>';
 232          evo_flush();
 233  
 234          // fp> TODO: make sure "deny all" actually works by trying to request the directory through HTTP
 235      }
 236  
 237      return true;
 238  }
 239  
 240  
 241  /**
 242   * Unpack ZIP archive to destination directory
 243   *
 244   * @param string source file path
 245   * @param string destination directory path
 246   * @param boolean true if create destination directory
 247   * @param string Zip file name
 248   * @return boolean results
 249   */
 250  function unpack_archive( $src_file, $dest_dir, $mk_dest_dir = false, $src_file_name = '' )
 251  {
 252      if( !file_exists( $dest_dir ) )
 253      { // We can create directory
 254          if ( ! mkdir_r( $dest_dir ) )
 255          {
 256              echo '<p style="color:red">'.sprintf( T_( 'Unable to create &laquo;%s&raquo; directory to extract files from ZIP archive.' ), $dest_dir ).'</p>';
 257              evo_flush();
 258  
 259              return false;
 260          }
 261      }
 262  
 263      if( function_exists( 'gzopen' ) )
 264      { // Unpack using 'zlib' extension and PclZip wrapper
 265  
 266          // Load PclZip class (PHP4):
 267          load_class( '_ext/pclzip/pclzip.lib.php', 'PclZip' );
 268  
 269          $PclZip = new PclZip( $src_file );
 270          if( $PclZip->extract( PCLZIP_OPT_PATH, $dest_dir ) == 0 )
 271          {
 272              if( empty( $src_file_name ) )
 273              { // Set zip file name
 274                  $src_file_name = $src_file;
 275              }
 276              echo '<p style="color:red">'
 277                  .sprintf( T_( 'Unable to unpack &laquo;%s&raquo; ZIP archive.' ), $src_file_name ).'<br />'
 278                  .sprintf( T_( 'Error: %s' ), $PclZip->errorInfo( true ) )
 279                  .'</p>';
 280              evo_flush();
 281  
 282              return false;
 283          }
 284      }
 285      else
 286      {
 287          debug_die( 'There is no \'zip\' or \'zlib\' extension installed!' );
 288      }
 289  
 290      return true;
 291  }
 292  
 293  
 294  /**
 295   * Verify that destination files can be overwritten
 296   *
 297   * @param string source directory
 298   * @param string destination directory
 299   * @param string action name
 300   * @param boolean overwrite
 301   * @param array read only file list
 302   */
 303  function verify_overwrite( $src, $dest, $action = '', $overwrite = true, & $read_only_list )
 304  {
 305      global $basepath;
 306  
 307      /**
 308       * Result of this function is FALSE when some error was detected
 309       * @var boolean
 310       */
 311      $result = true;
 312  
 313      $dir = opendir( $src );
 314  
 315      if( $dir === false )
 316      { // $dir is not a valid directory or it can not be opened due to permission restrictions
 317          echo '<div class="red">The &laquo;'.htmlspecialchars( $src ).'&raquo; is not a valid direcotry or the directory can not be opened due to permission restrictions or filesystem errors.</div>';
 318          return false;
 319      }
 320  
 321      $dir_list = array();
 322      $file_list = array();
 323      while( false !== ( $file = readdir( $dir ) ) )
 324      {
 325          if ( ( $file != '.' ) && ( $file != '..' ) )
 326          {
 327              $srcfile = $src.'/'.$file;
 328              $destfile = $dest.'/'.$file;
 329  
 330              if( isset( $read_only_list ) && file_exists( $destfile ) && !is_writable( $destfile ) )
 331              { // Folder or file is not writable
 332                  $read_only_list[] = $destfile;
 333              }
 334  
 335              if ( is_dir( $srcfile ) )
 336              {
 337                  $dir_list[$srcfile] = $destfile;
 338              }
 339              elseif( $overwrite )
 340              { // Add to overwrite
 341                  $file_list[$srcfile] = $destfile;
 342              }
 343          }
 344      }
 345  
 346      $config_ignore_files = get_upgrade_config( 'ignore' );
 347      $config_softmove_files = get_upgrade_config( 'softmove');
 348      $config_forcemove_files = get_upgrade_config( 'forcemove' );
 349  
 350      if( ! empty( $action ) && $action == 'Copying' )
 351      { // Display errors about config file or the unknown and incorrect commands from config file
 352          if( is_string( $config_ignore_files ) )
 353          { // Config file has some errors, but the upgrade should not fail because of that
 354              echo '<div class="red">'.$config_ignore_files.'</div>';
 355          }
 356          else
 357          {
 358              $config_unknown_commands = get_upgrade_config( 'unknown' );
 359              $config_incorrect_commands = get_upgrade_config( 'incorrect' );
 360  
 361              if( ! empty( $config_unknown_commands ) && is_array( $config_unknown_commands ) )
 362              { // Unknown commands
 363                  foreach( $config_unknown_commands as $config_unknown_command )
 364                  {
 365                      echo '<div class="red">'.sprintf( T_('Unknown policy command: %s'), $config_unknown_command ).'</div>';
 366                  }
 367              }
 368  
 369              if( ! empty( $config_incorrect_commands ) && is_array( $config_incorrect_commands ) )
 370              { // Incorrect commands
 371                  foreach( $config_incorrect_commands as $config_incorrect_command )
 372                  {
 373                      echo '<div class="red">'.sprintf( T_('Incorrect policy command: %s'), $config_incorrect_command ).'</div>';
 374                  }
 375              }
 376          }
 377      }
 378  
 379      foreach( $dir_list as $src_dir => $dest_dir )
 380      {
 381          $dest_dir_name = str_replace( $basepath, '', $dest_dir );
 382          // Detect if we should ignore this folder
 383          $ignore_dir = $overwrite && is_array( $config_ignore_files ) && in_array( $dest_dir_name, $config_ignore_files );
 384  
 385          $dir_success = false;
 386          if( !empty( $action ) )
 387          {
 388              if( $ignore_dir )
 389              { // Ignore folder
 390                  echo '<div class="orange">'.sprintf( T_('Ignoring %s because of upgrade_policy.conf'), '&laquo;<b>'.$dest_dir.'</b>&raquo;' ).'</div>';
 391              }
 392              else
 393              { // progressive display of what backup is doing
 394                  echo $action.' &laquo;<strong>'.$dest_dir.'</strong>&raquo;...';
 395                  $dir_success = true;
 396              }
 397              evo_flush();
 398          }
 399          elseif( $ignore_dir )
 400          { // This subfolder must be ingored, Display message about this
 401              echo '<div class="orange">'.sprintf( T_('Ignoring %s because of upgrade_policy.conf'), '&laquo;<b>'.$dest_dir_name.'</b>&raquo;' ).'</div>';
 402              $dir_success = false;
 403              evo_flush();
 404          }
 405  
 406          if( $ignore_dir )
 407          { // Skip the ignored folder
 408              continue;
 409          }
 410  
 411          if( $overwrite && !file_exists( $dest_dir ) )
 412          {
 413              // Create destination directory
 414              if( ! evo_mkdir( $dest_dir ) )
 415              { // No permission to create a folder
 416                  echo '<div class="red">'.sprintf( T_('Unavailable creating of folder %s, probably no permissions.'), '&laquo;<b>'.$dest_dir_name.'</b>&raquo;' ).'</div>';
 417                  $result = false;
 418                  $dir_success = false;
 419                  evo_flush();
 420                  continue;
 421              }
 422          }
 423  
 424          if( $dir_success )
 425          {
 426              echo ' OK.<br />';
 427              evo_flush();
 428          }
 429  
 430          $result = $result && verify_overwrite( $src_dir, $dest_dir, '', $overwrite, $read_only_list );
 431      }
 432  
 433      foreach( $file_list as $src_file => $dest_file )
 434      { // Overwrite destination file
 435          $dest_file_name = str_replace( $basepath, '', $dest_file );
 436          if( is_array( $config_ignore_files ) && in_array( $dest_file_name, $config_ignore_files ) )
 437          { // Ignore this file
 438              echo '<div class="orange">'.sprintf( T_('Ignoring %s because of upgrade_policy.conf'), '&laquo;<b>'.$dest_file_name.'</b>&raquo;' ).'</div>';
 439              evo_flush();
 440              continue;
 441          }
 442  
 443          if( is_array( $config_softmove_files ) && !empty( $config_softmove_files[ $dest_file_name ] ) )
 444          { // Action 'softmove': This file should be copied to other location with saving old file
 445              $copy_file_name = $config_softmove_files[ $dest_file_name ];
 446              // Don't rewrite old file
 447              $rewrite_old_file = false;
 448          }
 449          if( is_array( $config_forcemove_files ) && !empty( $config_forcemove_files[ $dest_file_name ] ) )
 450          { // Action 'forcemove': This file should be copied to other location with rewriting old file
 451              $copy_file_name = $config_forcemove_files[ $dest_file_name ];
 452              // Rewrite old file
 453              $rewrite_old_file = true;
 454          }
 455  
 456          if( ! empty( $copy_file_name ) )
 457          { // This file is marked in config to copy to other location
 458              $copy_file = $basepath.$copy_file_name;
 459              if( ! $rewrite_old_file && file_exists( $copy_file ) )
 460              { // Display warning if we cannot rewrite an existing file
 461                  echo '<div class="orange">'.sprintf( T_('Ignoring softmove of %s because %s is already in place (see upgrade_policy.conf)'),
 462                          '&laquo;<b>'.$dest_file_name.'</b>&raquo;',
 463                          '&laquo;<b>'.$copy_file_name.'</b>&raquo;' ).'</div>';
 464                  evo_flush();
 465                  unset( $copy_file_name );
 466                  continue; // Skip this file
 467              }
 468              else
 469              { // We can copy this file to other location
 470                  echo '<div class="orange">'.sprintf( T_('Moving %s to %s as stated in upgrade_policy.conf'),
 471                          '&laquo;<b>'.$dest_file_name.'</b>&raquo;',
 472                          '&laquo;<b>'.$copy_file_name.'</b>&raquo;' ).'</div>';
 473                  evo_flush();
 474                  // Set new location for a moving file
 475                  $dest_file = $copy_file;
 476                  $dest_file_name = $copy_file_name;
 477                  unset( $copy_file_name );
 478              }
 479          }
 480  
 481          // Copying
 482          if( ! @copy( $src_file, $dest_file ) )
 483          { // Display error if a copy command is unavailable
 484              echo '<div class="red">'.sprintf( T_('Unavailable copying to %s, probably no permissions.'), '&laquo;<b>'.$dest_file_name.'</b>&raquo;' ).'</div>';
 485              $result = false;
 486              evo_flush();
 487          }
 488      }
 489  
 490      closedir( $dir );
 491  
 492      return $result;
 493  }
 494  
 495  
 496  /**
 497   * Convert aliases to real table names as table backup works with real table names
 498   * @param mixed aliases
 499   * @return mixed
 500   */
 501  function aliases_to_tables( $aliases )
 502  {
 503      global $DB;
 504  
 505      if( is_array( $aliases ) )
 506      {
 507          $tables = array();
 508          foreach( $aliases as $alias )
 509          {
 510              $tables[] = preg_replace( $DB->dbaliases, $DB->dbreplaces, $alias );
 511          }
 512          return $tables;
 513      }
 514      elseif( $aliases == '*' )
 515      {
 516          return $aliases;
 517      }
 518      else
 519      {
 520          return preg_replace( $DB->dbaliases, $DB->dbreplaces, $aliases );
 521      }
 522  }
 523  
 524  
 525  /**
 526   * Check if the upgrade config file exists and display error message if config doesn't exist
 527   *
 528   * @return boolean TRUE if config exists
 529   */
 530  function check_upgrade_config( $display_message = false )
 531  {
 532      global $conf_path;
 533  
 534      if( !file_exists( $conf_path.'upgrade_policy.conf' ) )
 535      { // No upgrade config file
 536          if( $display_message )
 537          { // Display error message
 538              global $Messages;
 539              $Messages->add( T_('WARNING: upgrade_policy.conf not found. ALL FILES WILL BE BLINDLY UPGRADED WITHOUT DISCRIMINATION. Please refer to /conf/upgrade_policy_sample.conf for more info.') );
 540          }
 541          return false;
 542      }
 543  
 544      return true;
 545  }
 546  
 547  
 548  /**
 549   * Get a list of files and folders that must be ignored/removed on upgrade
 550   *
 551   * @param string Type of action: 'ignore', 'remove', 'softmove', 'forcemove'
 552   *                               'unknown' - Stores all unknown actions
 553   *                               'incorrect' - Stores all incorrect actions
 554   * @return array|string List of files and folders | Error message
 555   */
 556  function get_upgrade_config( $action )
 557  {
 558      global $conf_path, $upgrade_policy_config;
 559  
 560      if( !isset( $upgrade_policy_config ) )
 561      { // Init global array first time
 562          $upgrade_policy_config = array();
 563      }
 564      elseif( is_string( $upgrade_policy_config ) )
 565      { // Return error about config file
 566          return $upgrade_policy_config;
 567      }
 568  
 569      if( isset( $upgrade_policy_config[ $action ] ) )
 570      { // The config files were already initialized before, Don't make it twice
 571          return $upgrade_policy_config[ $action ];
 572      }
 573  
 574      if( !check_upgrade_config() )
 575      { // No config file
 576          $upgrade_policy_config = sprintf( T_('%s was not found.'), '&laquo;<b>upgrade_policy.conf</b>&raquo;' );
 577          return $upgrade_policy_config;
 578      }
 579  
 580      $config_handle = @fopen( $conf_path.'upgrade_policy.conf', 'r' );
 581      if( ! $config_handle )
 582      { // No permissions to open file
 583          $upgrade_policy_config = sprintf( T_('No permission to open %s.'), '&laquo;<b>upgrade_policy.conf</b>&raquo;' );
 584          return $upgrade_policy_config;
 585      }
 586  
 587      // Get content from config file
 588      $config_content = '';
 589      while( !feof( $config_handle ) )
 590      {
 591          $config_content .= fgets( $config_handle, 4096 );
 592      }
 593      fclose( $config_handle );
 594  
 595      if( empty( $config_content ) )
 596      { // Config file is empty for required action
 597          $upgrade_policy_config = sprintf( T_('%s is empty.'), '&laquo;<b>upgrade_policy.conf</b>&raquo;' );
 598          return $upgrade_policy_config;
 599      }
 600  
 601      // Only these actions are available in the upgrade_policy.conf
 602      $available_actions = array( 'ignore', 'remove', 'softmove', 'forcemove' );
 603  
 604      $all_actions = array_merge( $available_actions, array( 'unknown', 'incorrect' ) );
 605      foreach( $all_actions as $available_action )
 606      { // Init array for all actions only first time
 607          if( !isset( $upgrade_policy_config[ $available_action ] ) )
 608          {
 609              $upgrade_policy_config[ $available_action ] = array();
 610          }
 611      }
 612  
 613      $config_content = str_replace( "\r", '', $config_content );
 614      $config_content = explode( "\n", $config_content );
 615  
 616      foreach( $config_content as $config_line )
 617      {
 618          if( substr( $config_line, 0, 1 ) == ';' )
 619          { // This line is comment text, Skip it
 620              continue;
 621          }
 622  
 623          $config_line = trim( $config_line );
 624  
 625          $config_line_params = explode( ' ', $config_line );
 626          $line_action =  $config_line_params[0];
 627          if( in_array( $line_action, $available_actions ) )
 628          { // This line has an available action
 629              if( empty( $config_line_params[1] ) )
 630              { // Incorrect command
 631                  $upgrade_policy_config[ 'incorrect' ][] = $config_line;
 632                  continue;
 633              }
 634              if( $line_action == 'softmove' || $line_action == 'forcemove' )
 635              { // These actions have two params
 636                  if( empty( $config_line_params[1] ) || empty( $config_line_params[2] ) )
 637                  { // Incorrect command
 638                      $upgrade_policy_config[ 'incorrect' ][] = $config_line;
 639                      continue;
 640                  }
 641                  $upgrade_policy_config[ $line_action ][ $config_line_params[1] ] = $config_line_params[2];
 642              }
 643              else
 644              { // Actions 'ignore' & 'remove' have only one param
 645                  $upgrade_policy_config[ $line_action ][] = $config_line_params[1];
 646              }
 647          }
 648          elseif( !empty( $line_action ) )
 649          { // Also save all unknown actions to display error
 650              $upgrade_policy_config[ 'unknown' ][] = $config_line;
 651          }
 652      }
 653  
 654      return $upgrade_policy_config[ $action ];
 655  }
 656  
 657  
 658  /**
 659   * Remove files/folders after upgrade, See file upgrade_policy.conf
 660   */
 661  function remove_after_upgrade()
 662  {
 663      global $basepath, $conf_path;
 664  
 665      $upgrade_removed_files = get_upgrade_config( 'remove' );
 666  
 667      echo '<h4>'.T_('Cleaning up...').'</h4>';
 668      evo_flush();
 669  
 670      if( is_string( $upgrade_removed_files ) )
 671      { // Errors on opening of upgrade_policy.conf
 672          $config_error = $upgrade_removed_files;
 673      }
 674      elseif( empty( $upgrade_removed_files ) )
 675      { // No files/folders to remove, Exit here
 676          $config_error = sprintf( T_('No "remove" sections have been defined in the file %s.'), '&laquo;<b>upgrade_policy.conf</b>&raquo;' );
 677      }
 678  
 679      if( !empty( $config_error ) )
 680      { // Display config error
 681          echo '<div class="red">';
 682          echo $config_error;
 683          echo ' '.T_('No cleanup is being done. You should manually remove the /install folder and check for other unwanted files...');
 684          echo '</div>';
 685          return;
 686      }
 687  
 688      foreach( $upgrade_removed_files as $file_path )
 689      {
 690          $file_path = $basepath.$file_path;
 691          $log_message = sprintf( T_('Removing %s as stated in upgrade_policy.conf...'), '&laquo;<b>'.$file_path.'</b>&raquo;' ).' ';
 692          $success = true;
 693          if( file_exists( $file_path ) )
 694          { // File exists
 695              if( is_dir( $file_path ) )
 696              { // Remove folder recursively
 697                  if( rmdir_r( $file_path ) )
 698                  { // Success
 699                      $log_message .= T_('OK');
 700                  }
 701                  else
 702                  { // Failed
 703                      $log_message .= T_('Failed').': '.T_('No permissions to delete the folder');
 704                      $success = false;
 705                  }
 706              }
 707              elseif( is_writable( $file_path ) )
 708              { // Remove file
 709                  if( @unlink( $file_path ) )
 710                  { // Success
 711                      $log_message .= T_('OK');
 712                  }
 713                  else
 714                  { // Failed
 715                      $log_message .= T_('Failed').': '.T_('No permissions to delete the file');
 716                      $success = false;
 717                  }
 718              }
 719              else
 720              { // File is not writable
 721                  $log_message .= T_('Failed').': '.T_('No permissions to delete the file');
 722                  $success = false;
 723              }
 724          }
 725          else
 726          { // No file/folder
 727              $log_message .= T_('Failed').': '.T_('No file found');
 728              $success = false;
 729          }
 730  
 731          echo $success ? $log_message.'<br />' : '<div class="orange">'.$log_message.'</div>';
 732          evo_flush();
 733      }
 734  }
 735  
 736  
 737  /**
 738   * Get affected paths
 739   *
 740   * @param string Path
 741   * @return string
 742   */
 743  function get_affected_paths( $path )
 744  {
 745      global $basepath;
 746  
 747      $affected_paths = T_( 'Affected paths:' ).' ';
 748      if( is_array( $path ) )
 749      {
 750          $paths = array();
 751          foreach( $path as $p )
 752              $paths[] = no_trailing_slash( $p );
 753  
 754          $affected_paths .= implode( ', ', $paths );
 755      }
 756      elseif( $path == '*' )
 757      {
 758          $filename_params = array(
 759                  'inc_files'    => false,
 760                  'recurse'    => false,
 761                  'basename'    => true,
 762              );
 763          $affected_paths .= implode( ', ', get_filenames( $basepath, $filename_params ) );
 764      }
 765      else
 766      {
 767          $affected_paths .= no_trailing_slash( $path );
 768      }
 769      return $affected_paths;
 770  }
 771  
 772  
 773  /**
 774   * Get affected tables
 775   *
 776   * @param string Table
 777   * @return string
 778   */
 779  function get_affected_tables( $table )
 780  {
 781      global $DB;
 782  
 783      $affected_tables = T_( 'Affected tables:' ).' ';
 784      if( is_array( $table ) )
 785      {
 786          $affected_tables .= implode( ', ', aliases_to_tables( $table ) );
 787      }
 788      elseif( $table == '*' )
 789      {
 790          $tables = array();
 791          foreach( $DB->get_results( 'SHOW TABLES', ARRAY_N ) as $row )
 792                  $tables[] = $row[0];
 793  
 794          $affected_tables .= implode( ', ', $tables );
 795      }
 796      else
 797      {
 798          $affected_tables .= aliases_to_tables( $table );
 799      }
 800      return $affected_tables;
 801  }
 802  
 803  /**
 804   * Get html template of steps panel
 805   *
 806   * @param array Steps
 807   * @param integer Current step
 808   * @return string
 809   */
 810  function get_tool_steps( $steps, $current_step )
 811  {
 812      if( empty( $steps ) || empty( $current_step ) )
 813      { // Bad input data
 814          return '';
 815      }
 816  
 817      $r = '<div class="tool_steps">';
 818      foreach( $steps as $step_num => $step_title )
 819      {
 820          $r .= '<div class="step'.( $step_num == $current_step ? ' current' : '' ).'">'
 821                      .'<div>'.$step_num
 822                          .( $step_num < $current_step ? '<span>&#10003;</span>' : '' )
 823                      .'</div>'
 824                      .$step_title
 825                  .'</div>';
 826      }
 827      $r .= '</div>';
 828  
 829      return $r;
 830  }
 831  
 832  /**
 833   * Display steps panel
 834   *
 835   * @param integer Current step
 836   */
 837  function autoupgrade_display_steps( $current_step )
 838  {
 839      $steps = array(
 840              1 => T_('Check for updates'),
 841              2 => T_('Download'),
 842              3 => T_('Unzip'),
 843              4 => T_('Ready to upgrade'),
 844              5 => T_('Backup &amp; Upgrade'),
 845              6 => T_('Installer script'),
 846          );
 847  
 848      echo get_tool_steps( $steps, $current_step );
 849  }
 850  
 851  
 852  /**
 853   * Display steps panel
 854   *
 855   * @param integer Current step
 856   */
 857  function svnupgrade_display_steps( $current_step )
 858  {
 859      $steps = array(
 860              1 => T_('Connect to SVN'),
 861              2 => T_('Export'),
 862              3 => T_('Ready to upgrade'),
 863              4 => T_('Backup &amp; Upgrade'),
 864              5 => T_('Installer script'),
 865          );
 866  
 867      echo get_tool_steps( $steps, $current_step );
 868  }
 869  ?>

title

Description

title

Description

title

Description

title

title

Body