Beispiel #1
0
 /**
  * Register updater object
  *
  * @param file_updater_interface $updater	Updater object
  */
 public function register(file_updater_interface $updater)
 {
     $name = $updater->get_method_name();
     $this->file_updaters[$name] = $updater;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $new_path = $this->update_helper->get_path_to_new_update_files();
     $file_update_info = $this->installer_config->get('update_files', array());
     $update_type_progress = $this->installer_config->get('file_updater_type_progress', '');
     $update_elem_progress = $this->installer_config->get('file_updater_elem_progress', '');
     $type_progress_found = false;
     $elem_progress_found = false;
     // Progress bar
     $task_count = 0;
     foreach ($file_update_info as $sub_array) {
         $task_count += count($sub_array);
     }
     // Everything is up to date, so just continue
     if ($task_count === 0) {
         return;
     }
     $progress_count = $this->installer_config->get('file_update_progress_count', 0);
     $this->iohandler->set_task_count($task_count, true);
     $this->iohandler->set_progress('UPDATE_UPDATING_FILES', 0);
     $this->file_updater = $this->get_file_updater();
     // File updater fallback logic
     try {
         // Update files
         foreach ($file_update_info as $type => $file_update_vector) {
             if (!$type_progress_found) {
                 if ($type === $update_type_progress || empty($update_elem_progress)) {
                     $type_progress_found = true;
                 } else {
                     continue;
                 }
             }
             foreach ($file_update_vector as $path) {
                 if (!$elem_progress_found) {
                     if ($path === $update_elem_progress || empty($update_elem_progress)) {
                         $elem_progress_found = true;
                     } else {
                         continue;
                     }
                 }
                 switch ($type) {
                     case 'delete':
                         $this->file_updater->delete_file($path);
                         break;
                     case 'new':
                         $this->file_updater->create_new_file($path, $new_path . $path);
                         break;
                     case 'update_without_diff':
                         $this->file_updater->update_file($path, $new_path . $path);
                         break;
                     case 'update_with_diff':
                         $this->file_updater->update_file($path, $this->cache->get('_file_' . md5($path)), true);
                         break;
                 }
                 // Save progress
                 $this->installer_config->set('file_updater_type_progress', $type);
                 $this->installer_config->set('file_updater_elem_progress', $path);
                 $progress_count++;
                 $this->iohandler->set_progress('UPDATE_UPDATING_FILES', $progress_count);
                 if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
                     // Request refresh
                     throw new resource_limit_reached_exception();
                 }
             }
         }
         $this->iohandler->finish_progress('UPDATE_UPDATING_FILES');
     } catch (runtime_exception $e) {
         if ($e instanceof resource_limit_reached_exception) {
             throw new resource_limit_reached_exception();
         }
         $current_method = $this->installer_config->get('file_update_method', '');
         // File updater failed, try to fallback to download file update mode
         if ($current_method !== 'compression') {
             $this->iohandler->add_warning_message(array('UPDATE_FILE_UPDATER_HAS_FAILED', $current_method, 'compression'));
             $this->installer_config->set('file_update_method', 'compression');
             // We only want a simple refresh here
             throw new resource_limit_reached_exception();
         } else {
             // Nowhere to fallback to :(
             // Due to the way the installer handles fatal errors, we need to throw a low level exception
             throw new runtime_exception('UPDATE_FILE_UPDATERS_HAVE_FAILED');
         }
     }
     $file_updater_method = $this->installer_config->get('file_update_method', '');
     if ($file_updater_method === 'compression' || $file_updater_method === 'ftp') {
         $this->file_updater->close();
     }
 }