[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/include/admin/ -> upgrader.inc.php (source)

   1  <?php # $Id: upgrader.inc.php 1816 2007-08-06 10:18:39Z garvinhicking $
   2  # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
   3  # All rights reserved.  See LICENSE file for licensing details
   4  
   5  if (IN_serendipity !== true) {
   6      die ('Don\'t hack!');
   7  }
   8  
   9  require_once (S9Y_INCLUDE_PATH . 'include/functions_installer.inc.php');
  10  require_once (S9Y_INCLUDE_PATH . 'include/functions_upgrader.inc.php');
  11  
  12  define('S9Y_U_ERROR', -1);
  13  define('S9Y_U_WARNING', 0);
  14  define('S9Y_U_SUCCESS', 1);
  15  
  16  /**
  17   * Checks a return code constant if it's successfull or an error and return HTML code
  18   *
  19   * The diagnosis checks return codes of several PHP checks. Depending
  20   * on the input, a specially formatted string is returned.
  21   *
  22   * @access public
  23   * @param  int      Return code
  24   * @param  string   String to return wrapped in special HTML markup
  25   * @return string   returned String
  26   */
  27  function serendipity_upgraderResultDiagnose($result, $s) {
  28      global $errorCount;
  29  
  30      if ( $result === S9Y_U_SUCCESS ) {
  31          return '<span style="color: green; font-weight: bold">'. $s .'</span>';
  32      }
  33  
  34      if ( $result === S9Y_U_WARNING ) {
  35          return '<span style="color: orange; font-weight: bold">'. $s .'</span>';
  36      }
  37  
  38      if ( $result === S9Y_U_ERROR ) {
  39          $errorCount++;
  40          return '<span style="color: red; font-weight: bold">'. $s .'</span>';
  41      }
  42  }
  43  
  44  // Setting this value to 'FALSE' is recommended only for SHARED BLOG INSTALLATIONS. This enforces all shared blogs with a common
  45  // codebase to only allow upgrading, no bypassing and thus causing instabilities.
  46  // This variable can also be set as $serendipity['UpgraderShowAbort'] inside serendipity_config_local.inc.php to prevent
  47  // your setting being changed when updating serendipity in first place.
  48  $showAbort  = (isset($serendipity['UpgraderShowAbort']) ? $serendipity['UpgraderShowAbort'] : true);
  49  
  50  $abortLoc   = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=ignore';
  51  $upgradeLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=upgrade';
  52  
  53  /* Functions which needs to be run if installed version is equal or lower */
  54  $tasks = array(array('version'   => '0.5.1',
  55                       'function'  => 'serendipity_syncThumbs',
  56                       'title'     => 'Image Sync',
  57                       'desc'      => 'Version 0.5.1 introduces image sync with the database'. "\n" .
  58                                      'With your permission I would like to perform the image sync'),
  59  
  60                 array('version'   => '0.6.5',
  61                       'function'  => 'serendipity_rebuildCategoryTree',
  62                       'title'     => 'Nested subcategories, post to multiple categories',
  63                       'desc'      => 'This update will update the categories table of your database and update the relations from entries to categories.'. "\n" .
  64                                      'This is a possibly dangerous task to perform, so <strong style="color: red">make sure you have a backup of your database!</strong>'),
  65  
  66                 array('version'   => '0.6.8',
  67                       'function'  => 'serendipity_installFiles',
  68                       'title'     => 'Update of .htaccess file',
  69                       'desc'      => 'Changes were made to the .htaccess file, you need to regenerate it'),
  70  
  71                 array('version'   => '0.6.10',
  72                       'functon'   => 'serendipity_installFiles',
  73                       'title'     => 'Update of .htaccess file',
  74                       'desc'      => 'Changes were made to the .htaccess file, you need to regenerate it'),
  75  
  76                 array('version'   => '0.6.12',
  77                       'function'  => 'serendipity_installFiles',
  78                       'title'     => 'Update of .htaccess file',
  79                       'desc'      => 'Changes were made to the .htaccess file, you need to regenerate it'),
  80  
  81                 array('version'   => '0.8-alpha3',
  82                       'function'  => 'serendipity_removeFiles',
  83                       'title'     => 'Removal of obsolete files',
  84                       'arguments' => array($obsolete_files),
  85                       'desc'      => 'The directory structure has been reworked. The following files will be moved to a folder called "backup". If you made manual changes to those files, be sure to read the file docs/CHANGED_FILES to re-implement your changes.<br /><div style="font-size: x-small; margin: 15px">' . implode(', ', $obsolete_files) . '</div>'),
  86  
  87                 array('version'   => '0.8-alpha4',
  88                       'function'  => 'serendipity_removeFiles',
  89                       'title'     => 'Removal of serendipity_entries.php',
  90                       'arguments' => array(array('serendipity_entries.php')),
  91                       'desc'      => 'In order to implement the new administration, we have to remove the leftovers'),
  92  
  93                 array('version'   => '0.8-alpha4',
  94                       'function'  => 'serendipity_installFiles',
  95                       'title'     => 'Update of .htaccess file',
  96                       'desc'      => 'In order to implement the new administration, changes were made to the .htaccess file, you need to regenerate it'),
  97  
  98                 array('version'   => '0.8-alpha7',
  99                       'function'  => 'serendipity_removeObsoleteVars',
 100                       'title'     => 'Removal of obsolete configuration variables',
 101                       'desc'      => 'Because of the new configuration parsing methods, some database variables are now only stored in serendipity_config_local.inc.php. Those obsolete variables will be removed from the database'),
 102  
 103                 array('version'   => '0.8-alpha8',
 104                       'function'  => array('serendipity_plugin_api', 'create_plugin_instance'),
 105                       'arguments' => array('serendipity_event_browsercompatibility', null, 'event'),
 106                       'title'     => 'Plugin for Browser Compatibility',
 107                       'desc'      => 'Includes some CSS-behaviours and other functions to maximize browser compatibility'),
 108  
 109                 array('version'   => '0.8-alpha9',
 110                       'function'  => 'serendipity_installFiles',
 111                       'title'     => 'Update of .htaccess file',
 112                       'desc'      => 'In order to implement author views, changes were made to the .htaccess file, you need to regenerate it'),
 113  
 114                 array('version'   => '0.8-alpha11',
 115                       'function'  => 'serendipity_installFiles',
 116                       'title'     => 'Update of .htaccess file',
 117                       'desc'      => 'In order to implement URL rewrite improvement, changes were made to the .htaccess file, you need to regenerate it'),
 118  
 119                 array('version'   => '0.8-alpha12',
 120                       'type'      => 'TEMPLATE_NOTICE',
 121                       'function'  => '',
 122                       'title'     => '<b>TEMPLATE_NOTICE:</b> The template file "entries.tpl" has changed.',
 123                       'desc'      => 'Authors can now have longer real names instead of only their loginnames. Those new fields need to be displayed in your Template, if you manually created one. Following variables were changes:
 124                                       <b>{$entry.username}</b> =&gt; <b>{$entry.author}</b>
 125                                       <b>{$entry.link_username}</b> =&gt; <b>{$entry.link_author}</b>
 126                                       Those variables have been replaced in all bundled templates and those in our additional_themes repository.
 127                                       ' . serendipity_upgraderResultDiagnose(S9Y_U_WARNING, 'Manual user interaction is required! This can NOT be done automatically!')),
 128  
 129                 array('version'   => '0.8-beta3',
 130                       'function'  => 'serendipity_fixPlugins',
 131                       'arguments' => array('markup_column_names'),
 132                       'title'     => 'Configuration options of markup plugins',
 133                       'desc'      => 'Because of the latest multilingual improvements in Serendipity, the database key names for certain configuration directives only found in markup plugins need to be renamed.<br />'
 134                                      . 'This will be automatically handled by Serendipity for all internally bundled and external plugins. If you are using the external plugins "GeShi" and "Markdown", please make sure you will upgrade to their latest versions!<br />'
 135                                      . 'We also advise that you check the plugin configuration of all your markup plugins (like emoticate, nl2br, s9ymarkup, bbcode) and see if the settings you made are all properly migrated.'),
 136  
 137                 array('version'   => '0.8-beta5',
 138                       'function'  => 'serendipity_smarty_purge',
 139                       'title'     => 'Clear Smarty compiled templates',
 140                       'desc'      => 'Smarty has been upgraded to its latest stable version, and we therefore need to purge all compiled templates and cache'),
 141  
 142                 array('version'   => '0.9-alpha2',
 143                       'function'  => 'serendipity_buildPermalinks',
 144                       'title'     => 'Build permalink patterns',
 145                       'desc'      => 'This version introduces user-configurable Permalinks and needs to pre-cache the list of all permalinks to be later able to fetch the corresponding entries for a permalink.'),
 146  
 147                 array('version'   => '0.9-alpha3',
 148                       'function'  => 'serendipity_addDefaultGroups',
 149                       'title'     => 'Introduce author groups',
 150                       'desc'      => 'This version introduces customizable user groups. Your existing users will be migrated into the new default groups.'),
 151  
 152  );
 153  
 154  /* Fetch SQL files which needs to be run */
 155  $dir      = opendir(S9Y_INCLUDE_PATH . 'sql/');
 156  $tmpfiles = array();
 157  while (($file = readdir($dir)) !== false ) {
 158      if (preg_match('@db_update_(.*)_(.*)_(.*).sql@', $file, $res)) {
 159          list(, $verFrom, $verTo, $dbType) = $res;
 160          if (version_compare($verFrom, $serendipity['versionInstalled']) >= 0) {
 161              $tmpFiles[$verFrom][$dbType] = $file;
 162          }
 163      }
 164  }
 165  
 166  $sqlfiles = array();
 167  if (is_array($tmpFiles)) {
 168      foreach ($tmpFiles as $version => $db) {
 169          if (array_key_exists($serendipity['dbType'], $db) === false ) {
 170              $sqlfiles[$version] = $db['mysql'];
 171          } else {
 172              $sqlfiles[$version] = $db[$serendipity['dbType']];
 173          }
 174      }
 175  }
 176  
 177  @uksort($sqlfiles, "strnatcasecmp");
 178  
 179  if ($serendipity['GET']['action'] == 'ignore') {
 180      /* Todo: Don't know what to put here? */
 181  
 182  } elseif ($serendipity['GET']['action'] == 'upgrade') {
 183  
 184      $errors = array();
 185  
 186      /* Install SQL files */
 187      foreach ($sqlfiles as $sqlfile) {
 188          $sql = file_get_contents(S9Y_INCLUDE_PATH .'sql/'. $sqlfile);
 189          $sql = str_replace('{PREFIX}', $serendipity['dbPrefix'], $sql);
 190          preg_match_all("@(.*);@iUs", $sql, $res);
 191          foreach ($res[0] as $sql) {
 192              $r = serendipity_db_schema_import($sql);
 193              if (is_string($r)) {
 194                  $errors[] = trim($r);
 195              }
 196          }
 197      }
 198  
 199      /* Call functions */
 200      foreach ($tasks as $task) {
 201          if (!empty($task['function']) && version_compare($serendipity['versionInstalled'], $task['version'], '<') ) {
 202              if (is_callable($task['function'])) {
 203                  echo sprintf('Calling %s ...<br />', (is_array($task['function']) ? $task['function'][0] . '::'. $task['function'][1] : $task['function']));;
 204  
 205                  if (empty($task['arguments'])) {
 206                      call_user_func($task['function']);
 207                  } else {
 208                      call_user_func_array($task['function'], $task['arguments']);
 209                  }
 210              } else {
 211                  $errors[] = 'Unable to call '. $task['function'];
 212              }
 213          }
 214      }
 215  
 216      if (sizeof($errors)) {
 217          echo DIAGNOSTIC_ERROR . '<br /><br />';
 218          echo '<div class="serendipityAdminMsgError">- <img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . implode('<br />', $errors) . '</div><br /><br />';
 219      }
 220  
 221      /* I don't care what you told me, I will always nuke Smarty cache */
 222      serendipity_smarty_purge();
 223  
 224  }
 225  
 226  if (($showAbort && $serendipity['GET']['action'] == 'ignore') || $serendipity['GET']['action'] == 'upgrade') {
 227      $privateVariables = array();
 228      if (isset($serendipity['UpgraderShowAbort'])) {
 229          $privateVariables['UpgraderShowAbort'] = $serendipity['UpgraderShowAbort'];
 230      }
 231  
 232      $r = serendipity_updateLocalConfig(
 233             $serendipity['dbName'],
 234             $serendipity['dbPrefix'],
 235             $serendipity['dbHost'],
 236             $serendipity['dbUser'],
 237             $serendipity['dbPass'],
 238             $serendipity['dbType'],
 239             $serendipity['dbPersistent'],
 240             $privateVariables
 241      );
 242  
 243      if ($serendipity['GET']['action'] == 'ignore') {
 244          echo SERENDIPITY_UPGRADER_YOU_HAVE_IGNORED;
 245      } elseif ($serendipity['GET']['action'] == 'upgrade') {
 246          printf('<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . SERENDIPITY_UPGRADER_NOW_UPGRADED .'</div>', $serendipity['version']);
 247      }
 248      echo '<br />';
 249      printf('<div align="center">'. SERENDIPITY_UPGRADER_RETURN_HERE .'</div>', '<a href="'. $serendipity['serendipityHTTPPath'] .'">', '</a>');
 250      $_SESSION['serendipityAuthedUser'] = false;
 251      @session_destroy();
 252  } else {
 253      echo '<h2>' . SERENDIPITY_UPGRADER_WELCOME . '</h2>';
 254      printf(SERENDIPITY_UPGRADER_PURPOSE . '<br />', $serendipity['versionInstalled']);
 255      printf(SERENDIPITY_UPGRADER_WHY . '.', $serendipity['version']);
 256      echo '<br />' . FIRST_WE_TAKE_A_LOOK  . '.';
 257  ?>
 258  <br /><br />
 259  <div align="center"><?php printf(ERRORS_ARE_DISPLAYED_IN, serendipity_upgraderResultDiagnose(S9Y_U_ERROR, RED), serendipity_upgraderResultDiagnose(S9Y_U_WARNING, YELLOW), serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, GREEN)); ?>.<br />
 260  <?php
 261      $errorCount = 0;
 262      $showWritableNote = false;
 263      $basedir = $serendipity['serendipityPath'];
 264  ?>
 265  <div align="center">
 266  <table class="serendipity_admin_list_item serendipity_admin_list_item_even" width="90%" align="center">
 267      <tr>
 268          <td colspan="2" style="font-weight: bold"><?php echo PERMISSIONS ?></td>
 269      </tr>
 270      <tr>
 271          <td><?php echo $basedir ?></td>
 272          <td width="200"><?php
 273              if ( is_writable($basedir) ) {
 274                  echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
 275              } else {
 276                  $showWritableNote = false;
 277                  #Figure out if we're set up a little more securely
 278                  #PATH_SMARTY_COMPILE/
 279                  #uploads/
 280                  #archives/
 281                  #.htaccess
 282                  #serendipity_config_local.inc.php
 283                  # For completeness we could test to make sure the directories
 284                  # really are directories, but that's probably overkill
 285                  foreach (array('archives/', PATH_SMARTY_COMPILE . '/', 'uploads/', '.htaccess', 'serendipity_config_local.inc.php') as $path) {
 286                      if (!is_writeable($basedir . $path)) {
 287                          echo serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
 288                          $showWritableNote = true;
 289                          break;
 290                      }
 291                  }
 292  
 293                  if (!$showWritableNote) {
 294                      echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
 295                  }
 296              }
 297       ?></td>
 298      </tr>
 299      <tr>
 300          <td><?php echo $basedir . PATH_SMARTY_COMPILE?></td>
 301          <td width="200"><?php
 302              if ( is_writable($basedir . PATH_SMARTY_COMPILE) ) {
 303                  echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
 304              } else {
 305                  echo serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
 306                  $showWritableNote = true;
 307              }
 308       ?></td>
 309      </tr>
 310  <?php if (is_dir($basedir . $serendipity['uploadHTTPPath'])) { ?>
 311      <tr>
 312          <td><?php echo $basedir . $serendipity['uploadHTTPPath']; ?></td>
 313          <td width="200"><?php
 314              if (is_writable($basedir . $serendipity['uploadHTTPPath'])) {
 315                  echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
 316              } else {
 317                  echo serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
 318                  $showWritableNote = true;
 319              }
 320       ?></td>
 321      </tr>
 322  <?php } ?>
 323  </table>
 324  </div>
 325  <?php if ($showWritableNote === true) { ?>
 326      <div class="serendipityAdminMsgNote"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_note.png'); ?>" alt="" /><?php echo sprintf(PROBLEM_PERMISSIONS_HOWTO, 'chmod 1777') ?></div>
 327  <?php }
 328  
 329      if ($errorCount > 0) { ?>
 330      <div align="center">
 331          <div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_error.png'); ?>" alt="" />
 332  <?php echo PROBLEM_DIAGNOSTIC ?></div>
 333          <h2><a href="serendipity_admin.php"><?php echo RECHECK_INSTALLATION ?></a></h2>
 334      </div>
 335  <?php }
 336  ?>
 337  </div>
 338  
 339  <?php
 340      if ($errorCount < 1) {
 341          if (sizeof($sqlfiles) > 0) { ?>
 342      <br />
 343      <h3><?php printf(SERENDIPITY_UPGRADER_DATABASE_UPDATES, $serendipity['dbType']) ?>:</h3>
 344  <?php echo SERENDIPITY_UPGRADER_FOUND_SQL_FILES ?>:<br />
 345  <?php
 346              foreach ($sqlfiles as $sqlfile) {
 347                  echo '<div style="padding-left: 5px"><strong>'. $sqlfile .'</strong></div>';
 348              }
 349          }
 350  ?>
 351      <br />
 352  
 353      <h3><?php echo SERENDIPITY_UPGRADER_VERSION_SPECIFIC ?>:</h3>
 354  <?php
 355          $taskCount = 0;
 356  
 357          foreach ( $tasks as $task ) {
 358              if (version_compare($serendipity['versionInstalled'], $task['version'], '<'))  {
 359                  echo '<div><strong>'. $task['version'] .' - '. $task['title'] .'</strong></div>';
 360                  echo '<div style="padding-left: 5px">'. nl2br($task['desc']) .'</div><br />';
 361                  $taskCount++;
 362              }
 363          }
 364  
 365          if ($taskCount == 0) {
 366              echo SERENDIPITY_UPGRADER_NO_VERSION_SPECIFIC;
 367          }
 368  ?>
 369  
 370      <br /><br />
 371      <hr noshade="noshade">
 372  <?php if ($taskCount > 0 || sizeof($sqlfiles) > 0) { ?>
 373          <strong><?php echo SERENDIPITY_UPGRADER_PROCEED_QUESTION ?></strong>
 374          <br /><br /><a href="<?php echo $upgradeLoc; ?>" class="serendipityPrettyButton input_button"><?php echo SERENDIPITY_UPGRADER_PROCEED_DOIT ?></a> <?php if ($showAbort) { ?><a href="<?php echo $abortLoc; ?>" class="serendipityPrettyButton"><?php echo SERENDIPITY_UPGRADER_PROCEED_ABORT ?></a><?php } ?>
 375  <?php } else { ?>
 376          <strong><?php echo SERENDIPITY_UPGRADER_NO_UPGRADES ?></strong>
 377          <br /><br /><a href="<?php echo $upgradeLoc; ?>" class="serendipityPrettyButton input_button"><?php echo SERENDIPITY_UPGRADER_CONSIDER_DONE ?></a>
 378  <?php }
 379      }
 380  }


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics