Changeset 1738 for trunk

Show
Ignore:
Timestamp:
09/03/2008 03:44:05 PM (4 months ago)
Author:
driehle
Message:

First draft for a update system

Location:
trunk
Files:
5 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/update.php

    r1736 r1738  
    1 <?php 
     1<?php  
    22### update.php  Jlog 1.0.2 => Jlog 1.1.0 
    33 
    44  define("JLOG_ADMIN", true); 
    55  define("JLOG_UPDATE", true); 
    6   define("JLOG_LANGUAGE", "de"); // per default load the german language files 
    76   
    87  // load prepend.inc.php 
    98  require_once('..'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'prepend.inc.php'); 
    109    
    11   /** 
    12    * If there is no version information available we think of the installation 
    13    * as of Jlog 1.0.2, which means that it will be impossible to upgrade from any 
    14    * version earlier as 1.0.2 - you MUST upgrade to 1.0.2 before 
    15    * you can install this version of Jlog. 
    16    */ 
    17   if(!defined('JLOG_INSTALLED_VERSION')) { 
    18     define('JLOG_INSTALLED_VERSION', '1.0.2'); 
     10  if (!defined(JLOG_LANGUAGE)) { 
     11      define('JLOG_LANGUAGE', 'de'); 
    1912  } 
     13   
     14  include(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang.'.JLOG_LANGUAGE.'.inc.php'); 
     15  include(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang-admin.'.JLOG_LANGUAGE.'.inc.php'); 
     16   
    2017  // Rendering 
    2118  $c['meta']['title'] = "Update"; 
    22   $c['main'] = sprintf("<h2>Update von <var>%s</var> auf <var>%s</var></h2>", JLOG_INSTALLED_VERSION, JLOG_SOFTWARE_VERSION); 
     19  //$c['main'] = sprintf("<h2>Update von <var>%s</var> auf <var>%s</var></h2>", JLOG_INSTALLED_VERSION, JLOG_SOFTWARE_VERSION); 
    2320 
    24   /** 
    25    * If we are already at the version we want to upgrade to this means that the 
    26    * upgrade script did already do its job. 
    27    */ 
    28   if(version_compare(JLOG_SOFTWARE_VERSION, JLOG_INSTALLED_VERSION, '==')) { 
    29     $c['main'] .= '<p class="error">Version '.JLOG_INSTALLED_VERSION.' ist bereits komplett installiert.</p>'; 
    30   } else { 
    31  
    32         // get list of available languages 
    33         $dir = opendir(JLOG_BASEPATH.'lang'); 
    34         $languages = array(); 
    35         while(($file = readdir($dir)) !== false) { 
    36           if($file == '.' OR $file == '..') continue; 
    37           if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue; 
    38           $languages[] = $matches[1]; 
    39         } 
    40         // detect current language 
    41         include(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.inc.php"); 
    42         list($old_language) = explode("-", $l["language"]); 
    43         include(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang.'.JLOG_LANGUAGE.'.inc.php'); 
    44  
    45         if(!isset($_POST['update'])) { 
    46           $c['main'] .= "<form action='".$_SERVER['SCRIPT_NAME']."' method='post' accept-charset='UTF-8'> 
    47               <p><label for='password'>Bitte geben Sie Ihr aktuelles Administrator-Passwort ein (zum Schutz gegen unbefugtes Aufrufen dieses Scriptes):</label><br /> 
    48                 <input type='password' name='password' id='password' value='' /></p> 
    49               <p><label for='language'>Bitte wÀhlen Sie die gewÃŒnschte Sprache fÃŒr Ihr Weblog:</label><br /> 
    50                 <select class='userdata' id='language' name='jlog_language'>";  
    51           foreach($languages as $lang) { 
    52             $c['main'] .= "<option"; 
    53             if((isset($_POST['jlog_language']) AND $_POST['jlog_language'] == $lang) OR $old_language == $lang) $c['main'] .= " selected='selected'"; 
    54             $c['main'] .= ">$lang</option>"; 
    55           } 
    56           $c['main'] .= "</select> 
    57              </p> 
    58                  <p>Die Zeichenkodierung ihrer Template-Datei <code>personal/template.tpl</code> muss nach UTF-8 umgewandelt werden. Wenn diese Datei 
    59                     beschreibbar ist (z.B.: chmod 777), wird dies vom Updatescript automatisch fÃŒr sie erledigt. 
    60                     Andernfalls mÃŒssen Sie die Konvertierung nachtrÀglich manuell vornehmen.</p> 
    61              <p><input type='submit' name='update' value='Update starten' /></p> 
    62              </form>"; 
    63         } 
    64         else { 
    65           /** 
    66            * The hash of the administrator password is the hash of an ISO-encoded 
    67            * password, which is different from the hash of the same password encoded 
    68            * in UTF-8. Therefore, we have to convert the received password to ISO first, 
    69            * before we can run md5(). 
    70            */ 
    71           $pass1 = md5($_POST['password']);              # This is how it should look in  
    72                                                          # Jlog 1.1.0 
    73           $pass2 = md5(utf8_decode($_POST['password'])); # This is what we need to do for  
    74                                                          # Jlog 1.0.2 password 
    75           $pass3 = md5(utf8_encode($_POST['password'])); # actually this should not happen, 
    76                                                          # but better try this as well, as we 
    77                                                          # don't know how the end-user's  
    78                                                          # system looks like 
    79            
    80           /** 
    81            * validate form data 
    82            */ 
    83           if(JLOG_ADMIN_PASSWORD != $pass1 AND JLOG_ADMIN_PASSWORD != $pass2 AND JLOG_ADMIN_PASSWORD != $pass3) { 
    84             $update_errors[] = 'Administrator-Passwort fehlerhaft!'; 
    85           } 
    86   
    87           if(empty($update_errors)) { 
    88             require(JLOG_BASEPATH."scripts".DIRECTORY_SEPARATOR."settings.class.php"); 
    89     
    90             // read current settings from environment and POSTed data 
    91             $update = new Settings($l); 
    92             $update->get_data(); 
    93             $update->get_userdata(); 
    94     
    95             // convert all settings to utf8 
    96             foreach($update->d as $key => $value) { 
    97               $update->d[$key] = utf8_encode($value); 
    98             } 
    99     
    100             // reset hash of the administrator password (reasons, see above) 
    101             $update->d['jlog_admin_password'] = $pass1; 
    102     
    103             // store chosen language 
    104             $update->d['jlog_language'] = $_POST['jlog_language']; 
    105     
    106             // rewrite settings.inc.php 
    107             $update_errors = $update->do_settings(); 
    108           
    109             /** 
    110              * On a correct Jlog 1.0.2 installation, the template is saved with an ISO 
    111              * encoding, so we're going to try to convert this to UTF-8 
    112              */ 
    113             $template = JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."template.tpl"; 
    114             if(@file_put_contents($template, utf8_encode(@file_get_contents($template))) == false) { 
    115               $update_errors[] = 'Die Datei <code>personal/template.tpl</code> konnte nicht in UTF-8 Kodierung konvertiert werden.'; 
    116             } 
    117  
    118             // Ready :-) 
    119             require(JLOG_BASEPATH."scripts".DIRECTORY_SEPARATOR."update.php"); 
    120     
    121             if(empty($update_errors)) { 
    122               $c['main'] .= "<p>Update erfolgreich, <a href='../'>Viel Spaß</a>!</p>"; 
    123             } 
    124             else { 
    125                 $c['main'] .= error_output($update_errors, "", "Das Update wurde durchgefÃŒhrt, allerdings sind folgende Probleme aufgetreten"); 
    126               $c['main'] .= '<p>Sie können versuchen diese Schritte von Hand nachzuvollziehen. <a href="../">Zur Startseite</a></p>'; 
    127             } 
    128           } 
    129           else { 
    130          $c['main'] .= error_output($update_errors, "", "Fehler beim Update"); 
    131             $c['main'] .= '<p><a href="">Erneut versuchen</a></p>'; 
    132           } 
    133         } 
     21  require_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'JlogUpdater.php'); 
     22  $updater = new JlogUpdater(); 
     23   
     24  if ($updater->isUp2Date()) { 
     25      $c['main'] = '<p>Das Update auf ' . JLOG_INSTALLED_VERSION . ' wurde bereits erfolgreich durchgefÃŒhrt.</p>'; 
     26  } 
     27  else if (!isset($_POST['update'])) { 
     28      $c['main'] = $updater->prepareForm($l); 
     29  } 
     30  else { 
     31      $c['main'] = $updater->performUpdate($l); 
     32       
     33      // Ready :-) 
     34      require(JLOG_BASEPATH."scripts".DIRECTORY_SEPARATOR."update.php"); 
    13435  } 
    13536 
  • trunk/scripts/settings.class.php

    r1736 r1738  
    114114      if(!in_array($key, $search) AND strpos($key, "JLOG_") !== false) { 
    115115        $key = strtolower($key); 
    116         $this->d[$key] = stripslashes($value); 
     116        // we used stripslashes() on the value here before, which caused 
     117        // problems under windows, as C:\Path\Folder becomes C:PathFolder 
     118        $this->d[$key] = $value; 
    117119      } 
    118120    } 
  • trunk/scripts/update.php

    r1716 r1738  
    101101 
    102102   ### Plugin Hook 
    103    $data = $plugins->callHook('onUpdate', $data); 
     103   if (isset($plugins) and is_object($plugins)) { 
     104       $data = $plugins->callHook('onUpdate', $data); 
     105   } 
    104106 
    105107$i = 0;