Beispiel #1
0
 /**
  * Processes AJAX requests for upgrades.
  * The updater starts with the passed $version and goes on until the
  * last one.
  *
  * The response is in the following format:
  * <percent-complete>|<next-action>|<status-message>
  *
  * @static
  * @param  string  $version
  * @return string
  */
 public static function update($action)
 {
     // Get the update versions and current scope
     $versions = Config::get('schema.update');
     $versionNames = array_keys($versions);
     // Initialize everything
     if (!Session::has('setup.updating')) {
         Session::put('setup.updating', TRUE);
         Session::forget('setup.messages');
         return "5|{$action}|" . sprintf(Lang::get('setup.process_version'), $action);
     } else {
         if ($action == '~complete') {
             // Set the final stage
             Session::put('setup.stage', 3);
             // Update the version number in the database
             Site::config('general', array('version' => Config::get('app.version')));
             // Flush the cache
             Cache::flush();
             // All done!
             return "100||" . Lang::get('setup.update_complete');
         } else {
             if (array_key_exists($action, $versions)) {
                 try {
                     // In case the exception is not caught
                     static::setHandler('mainProcess');
                     // Scope is the current version being processed
                     $scope = $versions[$action];
                     // Create new tables
                     if (isset($scope['newTables'])) {
                         foreach ($scope['newTables'] as $tableName => $schema) {
                             // Drop the table
                             Schema::dropIfExists($tableName);
                             // Generate schema and create the table
                             Schema::create($tableName, function ($table) use($schema) {
                                 Setup::schema($table, $schema);
                             });
                         }
                     }
                     // Update existing tables
                     if (isset($scope['modifyTables'])) {
                         foreach ($scope['modifyTables'] as $tableName => $schema) {
                             // Generate schema and modify the table
                             Schema::table($tableName, function ($table) use($schema) {
                                 Setup::schema($table, $schema);
                             });
                         }
                     }
                     // Run the closure for this version
                     if (isset($scope['closure'])) {
                         call_user_func($scope['closure']);
                     }
                     // Output the next action in queue
                     return Setup::nextAction($action, $versionNames, 'setup.process_version');
                 } catch (Exception $e) {
                     Session::put('setup.error', $e->getMessage());
                     return '-1||' . Lang::get('setup.error_occurred');
                 }
             }
         }
     }
 }