[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/claroline/admin/upgrade/ -> upgrade_courses.php (source)

   1  <?php // $Id: upgrade_courses.php,v 1.63 2006/12/19 08:21:47 moosh Exp $
   2  /**
   3   * CLAROLINE 
   4   * 
   5   * This script Upgrade course database and course space.
   6   *
   7   * @version 1.8 $Revision: 1.63 $
   8   *
   9   * @copyright 2001-2006 Universite catholique de Louvain (UCL)
  10   * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
  11   * @see http://www.claroline.net/wiki/index.php/Upgrade_claroline_1.6
  12   * @package UPGRADE
  13   * @author Claro Team <cvs@claroline.net>
  14   * @author Christophe Gesché <moosh@claroline.net>
  15   * @author Mathieu Laurent <laurent@cerdecam.be>
  16   *
  17   */
  18  
  19  // Initialise Upgrade
  20  require  'upgrade_init_global.inc.php';
  21  
  22  // Include Libraries
  23  include  ('upgrade_course_16.lib.php');
  24  include  ('upgrade_course_17.lib.php');
  25  include  ('upgrade_course_18.lib.php');
  26  
  27  // Security Check
  28  if (!claro_is_platform_admin()) upgrade_disp_auth_form();
  29  
  30  // DB tables definition
  31  $tbl_mdb_names = claro_sql_get_main_tbl();
  32  $tbl_course = $tbl_mdb_names['course'];
  33  $tbl_rel_course_user   = $tbl_mdb_names['rel_course_user'];
  34  $tbl_course_tool       = $tbl_mdb_names['tool'];
  35  
  36  /**
  37   * Displays flags
  38   * Using __LINE__ to have an arbitrary value
  39   */
  40  
  41  DEFINE ('DISPLAY_WELCOME_PANEL', __LINE__ );
  42  DEFINE ('DISPLAY_RESULT_PANEL', __LINE__);
  43  
  44  /*=====================================================================
  45    Statements Section
  46   =====================================================================*/
  47  
  48  if ( isset($_REQUEST['verbose']) ) $verbose = true;
  49  
  50  if ( isset($_REQUEST['cmd']) ) $cmd = $_REQUEST['cmd'];
  51  else                           $cmd = FALSE;
  52  
  53  $upgradeCoursesError = isset($_REQUEST['upgradeCoursesError']) 
  54                       ? $_REQUEST['upgradeCoursesError']
  55                       : FALSE;
  56  
  57  if ( $cmd == 'run')
  58  {
  59      $display = DISPLAY_RESULT_PANEL;
  60  }
  61  else 
  62  {
  63      $display = DISPLAY_WELCOME_PANEL;
  64  }
  65  
  66  // Get start time
  67  $mtime = microtime();$mtime = explode(' ',$mtime);$mtime = $mtime[1] + $mtime[0];$starttime = $mtime;$steptime =$starttime;
  68  
  69  // count course to upgrade
  70  $count_course_upgraded = count_course_upgraded($new_version_branch);
  71  
  72  $count_course = $count_course_upgraded['total'];
  73  $count_course_error = $count_course_upgraded['error'];
  74  $count_course_upgraded = $count_course_upgraded['upgraded'];
  75  
  76  $count_course_error_at_start = $count_course_error;
  77  $count_course_upgraded_at_start =  $count_course_upgraded;
  78  
  79  /*=====================================================================
  80    Main Section
  81   =====================================================================*/
  82  
  83  /*---------------------------------------------------------------------
  84    Steps of Display 
  85   ---------------------------------------------------------------------*/
  86  
  87  // auto refresh
  88  if ( $display == DISPLAY_RESULT_PANEL && ($count_course_upgraded + $count_course_error ) < $count_course )
  89  {
  90      $refresh_time = 20;
  91      $htmlHeadXtra[] = '<meta http-equiv="refresh" content="'. $refresh_time  .'" />'."\n";
  92  }
  93  
  94  // Display Header
  95  echo upgrade_disp_header();
  96  
  97  /*---------------------------------------------------------------------
  98    Main
  99   ---------------------------------------------------------------------*/
 100  
 101  switch ($display)
 102  {
 103      case DISPLAY_WELCOME_PANEL :
 104  
 105          echo '<h2>Step 3 of 3: courses upgrade</h2>
 106               <p>Now the <em>Claroline Upgrade Tool</em> is going to prepare <b>course</b> data 
 107              (directories and database tables) one by one and set it to be compatible with the new 
 108              Claroline version.<p class="help">Note. Depending of the speed of your server or the amount 
 109              of data stored on your platform, this operation may take some time.</p>
 110              <p style="text-align: center"><strong>' . $count_course_upgraded . ' courses
 111              on ' . $count_course . ' already upgraded</strong><br /></p>
 112              <center>
 113              <p><button onclick="document.location=\'' . $_SERVER['PHP_SELF'] . '?cmd=run\';">Launch course data upgrade</button></p>
 114              </center>';
 115          break;
 116                  
 117      case DISPLAY_RESULT_PANEL : 
 118  
 119          echo '<h2>Step 3 of 3: courses upgrade</h2>
 120                <p>The <em>Claroline Upgrade Tool</em> proceeds to the courses data upgrade</p>'; 
 121  
 122          // display course upgraded
 123  
 124          echo '<p style="text-align: center"><strong>' . $count_course_upgraded . ' courses 
 125                on ' . $count_course . ' already upgraded</strong><br /></p>';
 126  
 127          flush();
 128                  
 129          /*
 130           * display refresh bloc
 131           */
 132  
 133          echo  '<div class="help" id="refreshIfBlock">
 134              <p>In case of interruption <sup>*</sup>, the <em>Claroline Upgrade tool</em> should restart automatically</p>
 135              <p style="text-align: center">
 136              <button onclick="document.location=\'' . $_SERVER['PHP_SELF'].'?cmd=run\';">Continue courses data upgrade</button>
 137              </p>
 138              <p><small>(*) see in the status bar of your browser.</small></p>
 139              </div>'; 
 140  
 141          flush();
 142  
 143          /*
 144           * Build query to select course to upgrade
 145           */
 146  
 147          if ( isset($_REQUEST['upgradeCoursesError']) )
 148          {
 149              // retry to upgrade course where upgrade failed
 150              claro_sql_query(" UPDATE `" . $tbl_course . "` SET `versionClaro` = '1.5' WHERE `versionClaro` = 'error-1.5'");
 151              claro_sql_query(" UPDATE `" . $tbl_course . "` SET `versionClaro` = '1.6' WHERE `versionClaro` = 'error-1.6'");
 152              claro_sql_query(" UPDATE `" . $tbl_course . "` SET `versionClaro` = '1.7' WHERE `versionClaro` = 'error-1.7'");
 153          }
 154  
 155          $sql_course_to_upgrade = " SELECT c.dbName dbName, 
 156                                            c.code , 
 157                                            c.fake_code , 
 158                                            c.directory coursePath,
 159                                            c.creationDate,
 160                                            c.versionClaro "
 161                                 . " FROM `" . $tbl_course . "` `c` ";
 162          
 163          if ( isset($_REQUEST['upgradeCoursesError']) )
 164          {
 165              // retry to upgrade course where upgrade failed
 166              $sql_course_to_upgrade .= " WHERE c.versionClaro not like '". $new_version_branch ."%'
 167                                          ORDER BY c.dbName";
 168          }
 169          else
 170          {
 171              // not upgrade course where upgrade failed ( versionClaro == error* )
 172              $sql_course_to_upgrade .= " WHERE ( c.versionClaro not like '". $new_version_branch . "%' )
 173                                                and c.versionClaro not like 'error%' 
 174                                          ORDER BY c.dbName ";
 175          }
 176                
 177          $res_course_to_upgrade = mysql_query($sql_course_to_upgrade);
 178          
 179          /*
 180           * Upgrade course
 181           */
 182  
 183          while ( ($course = mysql_fetch_array($res_course_to_upgrade) ) )
 184          {   
 185              // initialise variables
 186  
 187              $currentCourseDbName       = $course['dbName'];
 188              $currentcoursePathSys      = get_path('coursesRepositorySys') . $course['coursePath'].'/';
 189              $currentcoursePathWeb      = get_path('coursesRepositoryWeb') . $course['coursePath'].'/';
 190              $currentCourseCode         = $course['code'];
 191              $currentCourseFakeCode     = $course['fake_code'];
 192              $currentCourseCreationDate = $course['creationDate'];
 193              $currentCourseVersion      = $course['versionClaro'];
 194              $currentCourseDbNameGlu    = get_conf('courseTablePrefix') . $currentCourseDbName . get_conf('dbGlu'); // use in all queries
 195  
 196              // initialise
 197              $error = false;
 198              $upgraded = false;
 199              $message = '';
 200              
 201              echo '<p><strong>' . ( $count_course_upgraded + 1 ) . ' . </strong> 
 202                    Upgrading course <strong>' . $currentCourseFakeCode . '</strong><br />
 203                    <small>DB Name : ' . $currentCourseDbName . ' - Course ID : ' . $currentCourseCode . '</small></p>';
 204              
 205              /**
 206               * Make some check.
 207               * For next versions these test would be set in separate process and available out of upgrade
 208               */
 209  
 210              // repair tables
 211              sql_repair_course_database($currentCourseDbNameGlu);
 212                  
 213              // course repository doesn't exists
 214  
 215              if ( !file_exists($currentcoursePathSys) )
 216              {            
 217                  $error = true;
 218                  $message .= '<p class="help"><strong>Course has no repository.</strong><br />
 219                               <small>' .  $currentcoursePathSys . '</small> Not found</p>' . "\n";
 220                  $message .= '<p class="comment">The upgrade tool is not able to upgrade this course.<br />
 221                               Fix, first, the technical problem and relaunch the upgrade tool.</p>' . "\n";
 222              }
 223  
 224              if ( ! $error ) 
 225              {
 226                  /*---------------------------------------------------------------------
 227                    Upgrade 1.5 to 1.6
 228                   ---------------------------------------------------------------------*/                
 229  
 230                  if ( preg_match('/^1.5/',$currentCourseVersion) )
 231                  {
 232                      // Function to upgrade tool to 1.6
 233                      $function_list = array('assignment_upgrade_to_16',
 234                                             'forum_upgrade_to_16',
 235                                             'quizz_upgrade_to_16',
 236                                             'tracking_upgrade_to_16' );
 237  
 238                      foreach ( $function_list as $function )
 239                      {
 240                          $step = $function($currentCourseCode);
 241                          if ( $step > 0 )
 242                          {
 243                              echo 'Error : ' . $function . ' at step . ' . $step . '<br />';
 244                              $error = true;
 245                          }
 246                      }
 247                     
 248                      if ( ! $error )
 249                      {
 250                          // Upgrade succeeded
 251                          clean_upgrade_status($currentCourseCode);
 252                          $currentCourseVersion = '1.6';
 253                      }
 254                      else
 255                      {
 256                          // Upgrade failed
 257                          $currentCourseVersion = 'error-1.5';
 258                      }
 259                      // Save version
 260                      save_course_current_version($currentCourseCode,$currentCourseVersion);
 261                  }
 262                  
 263                  /*---------------------------------------------------------------------
 264                    Upgrade 1.6 to 1.7
 265                   ---------------------------------------------------------------------*/                
 266  
 267                  if ( preg_match('/^1.6/',$currentCourseVersion) )
 268                  {
 269                      // Function to upgrade tool to 1.7
 270                      $function_list = array( 'agenda_upgrade_to_17',
 271                                              'announcement_upgrade_to_17',
 272                                              'course_description_upgrade_to_17',
 273                                              'forum_upgrade_to_17',
 274                                              'introtext_upgrade_to_17',
 275                                              'linker_upgrade_to_17',
 276                                              'tracking_upgrade_to_17',
 277                                              'wiki_upgrade_to_17');
 278  
 279                      foreach ( $function_list as $function )
 280                      {
 281                          $step = $function($currentCourseCode);
 282                          if ( $step > 0 )
 283                          {
 284                              echo 'Error : ' . $function . ' at step ' . $step . '<br />';
 285                              $error = true;
 286                          }
 287                      }
 288                      
 289                      if ( ! $error )
 290                      {
 291                          // Upgrade succeeded
 292                          clean_upgrade_status($currentCourseCode);
 293                          $currentCourseVersion = '1.7';
 294                      }
 295                      else
 296                      {
 297                          // Upgrade failed
 298                          $currentCourseVersion = 'error-1.6';
 299                      }
 300                      // Save version
 301                      save_course_current_version($currentCourseCode,$currentCourseVersion);
 302                  
 303                  }
 304                  
 305                  /*---------------------------------------------------------------------
 306                    Upgrade 1.7 to 1.8
 307                   ---------------------------------------------------------------------*/                
 308  
 309                  if ( preg_match('/^1.7/',$currentCourseVersion) )
 310                  {
 311                      // Function to upgrade tool to 1.8
 312                      $function_list = array( 'course_repository_upgrade_to_18',
 313                                              'group_upgrade_to_18',
 314                                              'tool_list_upgrade_to_18',
 315                                              'quiz_upgrade_to_18',
 316                                              'tool_intro_upgrade_to_18',
 317                                              'tracking_upgrade_to_18',
 318                                              'forum_upgrade_to_18' );
 319  
 320                      foreach ( $function_list as $function )
 321                      {
 322                          $step = $function($currentCourseCode);
 323                          if ( $step > 0 )
 324                          {
 325                              echo 'Error : ' . $function . ' at step ' . $step . '<br />';
 326                              $error = true;
 327                          }
 328                      }
 329                      
 330                      if ( ! $error )
 331                      {
 332                          // Upgrade succeeded
 333                          clean_upgrade_status($currentCourseCode);
 334                          $currentCourseVersion = '1.8';
 335                      }
 336                      else
 337                      {
 338                          // Upgrade failed
 339                          $currentCourseVersion = 'error-1.7';
 340                      }
 341                      // Save version
 342                      save_course_current_version($currentCourseCode,$currentCourseVersion);
 343                  
 344                  }
 345  
 346              }
 347  
 348              
 349              if ( ! $error )
 350              {
 351                  if ( preg_match('/^1.8/',$currentCourseVersion) )
 352                  {
 353                      $message .= '<p class="success">Upgrade succeeded</p>';
 354                      // course upgraded
 355                      $count_course_upgraded++;
 356                  }
 357                  else
 358                  {
 359                      // course version unknown
 360                      $count_course_error++;
 361                      $message .= '<p class="error">Course version unknown : ' . $currentCourseVersion . '</p>';
 362                      log_message('Course version unknown : ' . $currentCourseVersion . '(in ' . $currentCourseCode . ')');
 363                  }
 364              }
 365              else
 366              {
 367                  $count_course_error++;
 368                  $message .= '<p class="error">Upgrade failed</p>';
 369              }
 370              
 371              // display message
 372              echo $message;
 373              
 374              // Calculate time            
 375              $mtime = microtime(); $mtime = explode(' ',$mtime);    $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime;
 376              $totaltime = ($endtime - $starttime);
 377              $stepDuration = ($endtime - $steptime);
 378              $steptime = $endtime;
 379              $stepDurationAvg = $totaltime / ( ($count_course_upgraded-$count_course_upgraded_at_start) 
 380                                               + ($count_course_error-$count_course_error_at_start) );
 381  
 382              $leftCourses = (int) ($count_course-$count_course_upgraded);
 383              $leftTime = strftime('%H:%M:%S',$leftCourses * $stepDurationAvg);
 384              
 385              $str_execution_time = sprintf(" <!-- Execution time for this course [%01.2f s] - average [%01.2f s] - total [%s] - left courses [%d]. -->
 386                                             <strong>Expected remaining time %s</strong>."
 387                                            ,$stepDuration
 388                                            ,$stepDurationAvg
 389                                            ,strftime('%H:%M:%S',$totaltime)
 390                                            ,$leftCourses
 391                                            ,$leftTime
 392                                           );
 393  
 394              echo '<p>' . $str_execution_time . '</p>';
 395  
 396              echo '<hr noshade="noshade" />';           
 397              flush();
 398  
 399          } // end of course upgrade
 400                  
 401          $mtime = microtime(); $mtime = explode(" ",$mtime);    $mtime = $mtime[1] + $mtime[0];    $endtime = $mtime; $totaltime = ($endtime - $starttime);
 402          
 403          if ( $count_course_error > 0 )
 404          {
 405              /*
 406               * display block with list of course where upgrade failed
 407               * add a link to retry upgrade of this course
 408               */
 409      
 410              $sql = "SELECT code 
 411                      FROM `" . $tbl_course . "` 
 412                      WHERE versionClaro like 'error-%' ";
 413      
 414              $result = claro_sql_query($sql);
 415      
 416              if ( mysql_num_rows($result) )
 417              {
 418                  echo '<p  class="error">Upgrade tool is not able to upgrade the following courses : ';
 419                  while ( ( $course = mysql_fetch_array($result)) )
 420                  {
 421                      echo $course['code'] . ' ; ';    
 422                  }
 423                  echo  '</p>';
 424  
 425              }
 426  
 427              echo '<p class="comment">'
 428                      . sprintf('Fix first the technical problem and <a href="%s">relaunch the upgrade tool</a>.', 
 429                                $_SERVER['PHP_SELF'] . '?cmd=run&upgradeCoursesError=1')
 430                      . '</p>';
 431          }
 432          else
 433          {
 434              // display next step
 435              echo '<p class="success">The Claroline upgrade process completed</p>' . "\n";
 436              echo '<div align="right"><p><button onclick="document.location=\'upgrade.php\';">Next ></button></p></div>';
 437          }
 438  
 439          /*
 440           * Hide Refresh Block
 441           */
 442                         
 443          echo '<script type="text/javascript">' . "\n";
 444          echo 'document.getElementById(\'refreshIfBlock\').style.visibility = "hidden"';
 445          echo '</script>';
 446                  
 447          break;
 448  
 449  } // end of switch display
 450  
 451  /*---------------------------------------------------------------------
 452    Display Footer
 453   ---------------------------------------------------------------------*/
 454  
 455  // Display footer
 456  echo upgrade_disp_footer();
 457  
 458  ?>


Généré le : Thu Nov 29 14:38:42 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics