Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->iohandler->get_input('submit_continue_file_update', false)) {
         // Handle merge conflicts
         $merge_conflicts = $this->installer_config->get('merge_conflict_list', array());
         // Create archive for merge conflicts
         if (!empty($merge_conflicts)) {
             $compression_method = $this->installer_config->get('compression_method', '');
             $conflict_archive = $this->file_updater->init($compression_method);
             $this->installer_config->set('update_file_conflict_archive', $conflict_archive);
             foreach ($merge_conflicts as $filename) {
                 $this->file_updater->create_new_file($filename, base64_decode($this->cache->get('_file_' . md5($filename))), true);
             }
             // Render download box
             $this->iohandler->add_download_link('phpbb_installer_update_conflict_download', 'DOWNLOAD_CONFLICTS', 'DOWNLOAD_CONFLICTS_EXPLAIN');
             $this->file_updater->close();
         }
         // Render update file statuses
         $file_update_info = $this->installer_config->get('update_files', array());
         $file_status = array('deleted' => !isset($file_update_info['delete']) ? array() : $file_update_info['delete'], 'new' => !isset($file_update_info['new']) ? array() : $file_update_info['new'], 'conflict' => $this->installer_config->get('merge_conflict_list', array()), 'modified' => !isset($file_update_info['update_with_diff']) ? array() : $file_update_info['update_with_diff'], 'not_modified' => !isset($file_update_info['update_without_diff']) ? array() : $file_update_info['update_without_diff']);
         $this->iohandler->render_update_file_status($file_status);
         // Add form to continue update
         $this->iohandler->add_user_form_group('UPDATE_CONTINUE_FILE_UPDATE', array('submit_continue_file_update' => array('label' => 'UPDATE_CONTINUE_FILE_UPDATE', 'type' => 'submit')));
         // Show results to the user
         throw new user_interaction_required_exception();
     } else {
         $conflict_archive_path = $this->installer_config->get('update_file_conflict_archive', null);
         // Remove archive
         if ($conflict_archive_path !== null && $this->filesystem->exists($conflict_archive_path)) {
             $this->filesystem->remove($conflict_archive_path);
         }
         $this->installer_config->set('update_file_conflict_archive', null);
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  *
  * @throws file_updater_failure_exception	When the file is not writable
  * @throws filesystem_exception				When the filesystem class fails
  */
 public function update_file($path_to_file_to_update, $source, $create_from_content = false)
 {
     $path_to_file_to_update = $this->phpbb_root_path . $path_to_file_to_update;
     $original_file_perms = false;
     // Maybe necessary for binary files
     $dir = dirname($path_to_file_to_update);
     if (!$this->filesystem->exists($dir)) {
         $this->make_dir($dir);
     }
     if (!$this->filesystem->is_writable($path_to_file_to_update)) {
         // Extract last 9 bits we actually need
         $original_file_perms = @fileperms($path_to_file_to_update) & 511;
         $this->filesystem->phpbb_chmod($path_to_file_to_update, filesystem::CHMOD_WRITE);
     }
     if (!$create_from_content) {
         try {
             $this->filesystem->copy($source, $path_to_file_to_update, true);
         } catch (filesystem_exception $e) {
             $this->write_file($path_to_file_to_update, $source, $create_from_content);
         }
     } else {
         $this->write_file($path_to_file_to_update, $source, $create_from_content);
     }
     if ($original_file_perms !== false) {
         $this->filesystem->phpbb_chmod($path_to_file_to_update, $original_file_perms);
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->installer_config->has_restart_point('check_update_files')) {
         $this->installer_config->create_progress_restart_point('check_update_files');
     }
     $old_path = $this->update_helper->get_path_to_old_update_files();
     $new_path = $this->update_helper->get_path_to_new_update_files();
     $update_info = $this->installer_config->get('update_info', array());
     $file_update_info = $this->installer_config->get('update_files', array());
     if (empty($update_info)) {
         $root_path = $this->phpbb_root_path;
         $update_info = $this->installer_config->get('update_info_unprocessed', array());
         $file_update_info = array();
         $file_update_info['update_without_diff'] = array_diff($update_info['binary'], $update_info['deleted']);
         // Filter out files that are already deleted
         $file_update_info['delete'] = array_filter($update_info['deleted'], function ($filename) use($root_path) {
             return file_exists($root_path . $filename);
         });
     }
     $progress_count = $this->installer_config->get('file_check_progress_count', 0);
     $task_count = count($update_info['files']);
     $this->iohandler->set_task_count($task_count);
     $this->iohandler->set_progress('UPDATE_CHECK_FILES', 0);
     foreach ($update_info['files'] as $key => $filename) {
         $old_file = $old_path . $filename;
         $new_file = $new_path . $filename;
         $file = $this->phpbb_root_path . $filename;
         if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
             // Save progress
             $this->installer_config->set('update_info', $update_info);
             $this->installer_config->set('file_check_progress_count', $progress_count);
             $this->installer_config->set('update_files', $file_update_info);
             // Request refresh
             throw new resource_limit_reached_exception();
         }
         $progress_count++;
         $this->iohandler->set_progress('UPDATE_CHECK_FILES', $progress_count);
         if (!$this->filesystem->exists($file)) {
             $file_update_info['new'][] = $filename;
         } else {
             $file_checksum = md5_file($file);
             if ($file_checksum === md5_file($new_file)) {
                 // File already up to date
                 continue;
             } else {
                 if ($this->filesystem->exists($old_file) && $file_checksum === md5_file($old_file)) {
                     // No need to diff the file
                     $file_update_info['update_without_diff'][] = $filename;
                 } else {
                     $file_update_info['update_with_diff'][] = $filename;
                 }
             }
         }
         unset($update_info['files'][$key]);
     }
     $this->installer_config->set('update_files', $file_update_info);
     $this->installer_config->set('update_info', array());
 }
Esempio n. 4
0
 /**
  * proxy_instantiator constructor
  * @param string $cache_dir Cache dir for fall back when using open_basedir
  */
 public function __construct($cache_dir)
 {
     $config = new Configuration();
     // Prevent trying to write to system temp dir in case of open_basedir
     // restrictions being in effect
     $ini_wrapper = new IniGetWrapper();
     $filesystem = new filesystem();
     $tmp_dir = function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : '';
     if (empty($tmp_dir) || $ini_wrapper->getString('open_basedir') && (!$filesystem->exists($tmp_dir) || !$filesystem->is_writable($tmp_dir))) {
         $config->setProxiesTargetDir($cache_dir);
     }
     $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     $this->factory = new LazyLoadingValueHolderFactory($config);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     // Array of update files
     $update_files = array($this->phpbb_root_path . 'install/update', $this->phpbb_root_path . 'install/update/index.' . $this->php_ext);
     // Check for a valid update directory
     if (!$this->filesystem->exists($update_files) || !$this->filesystem->is_readable($update_files)) {
         $this->iohandler->add_warning_message('UPDATE_FILES_NOT_FOUND');
         $this->set_test_passed(false);
         // If there are no update files, we can't check the version etc
         // However, we can let the users run migrations if they really want to...
         $this->installer_config->set('disable_filesystem_update', true);
         return true;
     }
     // Recover version numbers
     $update_info = array();
     @(include $this->phpbb_root_path . 'install/update/index.' . $this->php_ext);
     $info = empty($update_info) || !is_array($update_info) ? false : $update_info;
     $update_version = false;
     if ($info !== false) {
         $update_version = !empty($info['version']['to']) ? trim($info['version']['to']) : false;
     }
     // Get current and latest version
     try {
         $latest_version = $this->version_helper->get_latest_on_current_branch(true);
     } catch (\RuntimeException $e) {
         $latest_version = $update_version;
     }
     $current_version = !empty($this->config['version_update_from']) ? $this->config['version_update_from'] : $this->config['version'];
     // Check if the update package
     if (!$this->update_helper->phpbb_version_compare($current_version, $update_version, '<')) {
         $this->iohandler->add_error_message('NO_UPDATE_FILES_UP_TO_DATE');
         $this->tests_passed = false;
     }
     // Check if the update package works with the installed version
     if (empty($info['version']['from']) || $info['version']['from'] !== $current_version) {
         $this->iohandler->add_error_message(array('INCOMPATIBLE_UPDATE_FILES', $current_version, $info['version']['from'], $update_version));
         $this->tests_passed = false;
     }
     // check if this is the latest update package
     if ($this->update_helper->phpbb_version_compare($update_version, $latest_version, '<')) {
         $this->iohandler->add_warning_message(array('OLD_UPDATE_FILES', $info['version']['from'], $update_version, $latest_version));
     }
     return $this->tests_passed;
 }
Esempio n. 6
0
    /**
     * Delete attachment from filesystem
     *
     * @param string $filename Filename of attachment
     * @param string $mode Delete mode
     * @param bool $entry_removed Whether entry was removed. Defaults to false
     * @return bool True if file was removed, false if not
     */
    public function unlink_attachment($filename, $mode = 'file', $entry_removed = false)
    {
        // Because of copying topics or modifications a physical filename could be assigned more than once. If so, do not remove the file itself.
        $sql = 'SELECT COUNT(attach_id) AS num_entries
		FROM ' . ATTACHMENTS_TABLE . "\n\t\tWHERE physical_filename = '" . $this->db->sql_escape(utf8_basename($filename)) . "'";
        $result = $this->db->sql_query($sql);
        $num_entries = (int) $this->db->sql_fetchfield('num_entries');
        $this->db->sql_freeresult($result);
        // Do not remove file if at least one additional entry with the same name exist.
        if ($entry_removed && $num_entries > 0 || !$entry_removed && $num_entries > 1) {
            return false;
        }
        $filename = $mode == 'thumbnail' ? 'thumb_' . utf8_basename($filename) : utf8_basename($filename);
        $filepath = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $filename;
        try {
            if ($this->filesystem->exists($filepath)) {
                $this->filesystem->remove($this->phpbb_root_path . $this->config['upload_path'] . '/' . $filename);
                return true;
            }
        } catch (\phpbb\filesystem\exception\filesystem_exception $exception) {
            // Fail is covered by return statement below
        }
        return false;
    }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->installer_config->has_restart_point('check_update_files')) {
         $this->installer_config->create_progress_restart_point('check_update_files');
     }
     $old_path = $this->update_helper->get_path_to_old_update_files();
     $new_path = $this->update_helper->get_path_to_new_update_files();
     $update_info = $this->installer_config->get('update_info', array());
     $file_update_info = $this->installer_config->get('update_files', array());
     if (empty($update_info)) {
         $root_path = $this->phpbb_root_path;
         $update_info = $this->installer_config->get('update_info_unprocessed', array());
         $file_update_info = array();
         $file_update_info['update_without_diff'] = array_diff($update_info['binary'], $update_info['deleted']);
         // Filter out files that are already deleted
         $file_update_info['delete'] = array_filter($update_info['deleted'], function ($filename) use($root_path) {
             return file_exists($root_path . $filename);
         });
     }
     $progress_count = $this->installer_config->get('file_check_progress_count', 0);
     $task_count = count($update_info['files']);
     $this->iohandler->set_task_count($task_count);
     $this->iohandler->set_progress('UPDATE_CHECK_FILES', 0);
     // Create list of default extensions that should have been added prior
     // to this update
     $default_update_extensions = [];
     foreach (\phpbb\install\module\update_database\task\update_extensions::$default_extensions_update as $version => $extensions) {
         if ($this->update_helper->phpbb_version_compare($update_info['version']['from'], $version, '>')) {
             $default_update_extensions = array_merge($default_update_extensions, $extensions);
         }
     }
     foreach ($update_info['files'] as $key => $filename) {
         $old_file = $old_path . $filename;
         $new_file = $new_path . $filename;
         $file = $this->phpbb_root_path . $filename;
         if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
             // Save progress
             $this->installer_config->set('update_info', $update_info);
             $this->installer_config->set('file_check_progress_count', $progress_count);
             $this->installer_config->set('update_files', $file_update_info);
             // Request refresh
             throw new resource_limit_reached_exception();
         }
         $progress_count++;
         $this->iohandler->set_progress('UPDATE_CHECK_FILES', $progress_count);
         // Do not copy default extension again if the previous version was
         // packaged with it but it does not exist (e.g. deleted by admin)
         if (strpos($file, $this->phpbb_root_path . 'ext/') !== false) {
             $skip_file = false;
             foreach ($default_update_extensions as $ext_name) {
                 if (strpos($file, $this->phpbb_root_path . 'ext/' . $ext_name) !== false && !$this->filesystem->exists($this->phpbb_root_path . 'ext/' . $ext_name . '/composer.json')) {
                     $skip_file = true;
                     break;
                 }
             }
             if ($skip_file) {
                 continue;
             }
         }
         if (!$this->filesystem->exists($file)) {
             $file_update_info['new'][] = $filename;
         } else {
             $file_checksum = md5_file($file);
             if ($file_checksum === md5_file($new_file)) {
                 // File already up to date
                 continue;
             } else {
                 if ($this->filesystem->exists($old_file) && $file_checksum === md5_file($old_file)) {
                     // No need to diff the file
                     $file_update_info['update_without_diff'][] = $filename;
                 } else {
                     $file_update_info['update_with_diff'][] = $filename;
                 }
             }
         }
         unset($update_info['files'][$key]);
     }
     $this->installer_config->set('update_files', $file_update_info);
     $this->installer_config->set('update_info', array());
 }