6 * @copyright (c) 2006 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 * @todo add successful file update to log
10 * @todo add successful database update to log
11 * @todo do database update before updating files. Within the updater create a new config variable (version_update_from). Use this version in favor of the real versino to check for the database update successfully run through. After successful file update remove the information.
12 * @todo check memory by setting limit to 8MB locally.
13 * @todo make sure binary files get updated too, omitting the diff engine for this (handle like a conflict)
14 * @todo do not require login...
19 if (!defined('IN_INSTALL'))
21 // Someone has tried to access the file directly. This is not a good idea, so exit
25 if (!empty($setmodules))
27 // If phpBB is not installed we do not include this module
28 if (@file_exists
($phpbb_root_path . 'config.' . $phpEx) && !@file_exists
($phpbb_root_path . 'cache/install_lock'))
30 include_once($phpbb_root_path . 'config.' . $phpEx);
32 if (!defined('PHPBB_INSTALLED'))
43 'module_type' => 'update',
44 'module_title' => 'UPDATE',
45 'module_filename' => substr(basename(__FILE__
), 0, -strlen($phpEx)-1),
48 'module_stages' => array('INTRO', 'VERSION_CHECK', 'FILE_CHECK', 'UPDATE_FILES', 'UPDATE_DB'),
57 class install_update
extends module
68 var $test_update = false;
70 function install_update(&$p_master)
72 $this->p_master
= &$p_master;
75 function main($mode, $sub)
77 global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth;
79 $this->tpl_name
= 'install_update';
80 $this->page_title
= 'UPDATE_INSTALLATION';
82 $this->old_location
= $phpbb_root_path . 'install/update/old/';
83 $this->new_location
= $phpbb_root_path . 'install/update/new/';
86 require($phpbb_root_path . 'config.' . $phpEx);
87 require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
88 require($phpbb_root_path . 'includes/constants.' . $phpEx);
93 $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
95 // We do not need this any longer, unset for safety purposes
100 $sql = 'SELECT config_name, config_value
101 FROM ' . CONFIG_TABLE
;
102 $result = $db->sql_query($sql);
104 while ($row = $db->sql_fetchrow($result))
106 $config[$row['config_name']] = $row['config_value'];
108 $db->sql_freeresult($result);
110 // First of all, init the user session
111 $user->session_begin();
112 $auth->acl($user->data
);
113 $user->setup('install');
115 // Include renderer and engine
116 include_once($phpbb_root_path . 'includes/diff/diff.' . $phpEx);
117 include_once($phpbb_root_path . 'includes/diff/engine.' . $phpEx);
118 include_once($phpbb_root_path . 'includes/diff/renderer.' . $phpEx);
120 // If we are within the intro page we need to make sure we get up-to-date version info
123 $cache->destroy('_version_info');
126 // Set custom template again. ;)
127 $template->set_custom_template('../adm/style', 'admin');
129 // Get current and latest version
130 $this->current_version
= $config['version'];
132 if (($latest_version = $cache->get('_version_info')) === false)
134 $this->latest_version
= $this->get_file('version_info');
135 $cache->put('_version_info', $this->latest_version
);
139 $this->latest_version
= $latest_version;
142 $up_to_date = (version_compare(strtolower($this->current_version
), strtolower($this->latest_version
), '<')) ?
false : true;
144 // Check for a valid update directory, else point the user to the phpbb.com website
145 if (!file_exists($phpbb_root_path . 'install/update') ||
!file_exists($phpbb_root_path . 'install/update/index.' . $phpEx) ||
!file_exists($this->old_location
) ||
!file_exists($this->new_location
))
147 $template->assign_vars(array(
149 'ERROR_MSG' => ($up_to_date) ?
$user->lang
['NO_UPDATE_FILES_UP_TO_DATE'] : sprintf($user->lang
['NO_UPDATE_FILES_OUTDATED'], $config['version'], $this->current_version
, $this->latest_version
))
155 $this->update_info
= $this->get_file('update_info');
157 // Make sure the update directory holds the correct information
158 // Since admins are able to run the update/checks more than once we only check if the current version is lower or equal than the version to which we update to.
159 if (version_compare(strtolower($this->current_version
), strtolower($this->update_info
['version']['to']), '>'))
161 $template->assign_vars(array(
163 'ERROR_MSG' => sprintf($user->lang
['INCOMPATIBLE_UPDATE_FILES'], $config['version'], $this->update_info
['version']['from'], $this->update_info
['version']['to']))
169 // Check if the update files stored are for the latest version...
170 if ($this->latest_version
!= $this->update_info
['version']['to'])
172 $template->assign_vars(array(
174 'ERROR_MSG' => sprintf($user->lang
['OLD_UPDATE_FILES'], $this->update_info
['version']['from'], $this->update_info
['version']['to'], $this->latest_version
))
180 // Got the updater template itself updated? If so, we are able to directly use it - but only if all three files are present
181 if (in_array('adm/style/install_update.html', $this->update_info
['files']))
183 $this->tpl_name
= '../../install/update/new/adm/style/install_update';
186 // What about the language file? Got it updated?
187 if (in_array('language/en/install.php', $this->update_info
['files']))
190 include('./update/new/language/en/install.php');
191 $user->lang
= array_merge($user->lang
, $lang);
194 // Make sure we stay at the file check if checking the files again
195 if (!empty($_POST['check_again']))
197 $sub = $this->p_master
->sub
= 'file_check';
203 $this->page_title
= 'UPDATE_INSTALLATION';
205 $template->assign_vars(array(
207 'U_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=version_check"),
210 // Make sure the update list is destroyed.
211 $cache->destroy('_update_list');
214 case 'version_check':
215 $this->page_title
= 'STAGE_VERSION_CHECK';
217 $template->assign_vars(array(
218 'S_UP_TO_DATE' => $up_to_date,
219 'S_VERSION_CHECK' => true,
220 'U_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=file_check"),
222 'LATEST_VERSION' => $this->latest_version
,
223 'CURRENT_VERSION' => $config['version'])
230 $this->page_title
= 'STAGE_FILE_CHECK';
232 // Now make sure our update list is correct if the admin refreshes
233 $action = request_var('action', '');
235 // We are directly within an update. To make sure our update list is correct we check its status.
236 $update_list = (!empty($_POST['check_again'])) ?
false : $cache->get('_update_list');
237 $modified = ($update_list !== false) ? @filemtime
($cache->cache_dir
. 'data_update_list.' . $phpEx) : 0;
239 // Make sure the list is up-to-date
240 if ($update_list !== false)
242 $get_new_list = false;
243 foreach ($this->update_info
['files'] as $file)
245 if (file_exists($phpbb_root_path . $file) && filemtime($phpbb_root_path . $file) > $modified)
247 $get_new_list = true;
254 $get_new_list = true;
259 $update_list = $this->get_update_structure();
260 $cache->put('_update_list', $update_list);
263 if ($action == 'diff')
265 $this->show_diff($update_list);
269 if (sizeof($update_list['no_update']))
271 $template->assign_vars(array(
272 'S_NO_UPDATE_FILES' => true,
273 'NO_UPDATE_FILES' => implode(', ', array_map('htmlspecialchars', $update_list['no_update'])))
277 // Now assign the list to the template
278 foreach ($update_list as $status => $filelist)
280 if ($status == 'no_update' ||
!sizeof($filelist))
285 $template->assign_block_vars('files', array(
288 'L_STATUS' => $user->lang
['STATUS_' . strtoupper($status)],
289 'TITLE' => $user->lang
['FILES_' . strtoupper($status)],
290 'EXPLAIN' => $user->lang
['FILES_' . strtoupper($status) . '_EXPLAIN'],
294 foreach ($filelist as $file_struct)
296 $template->assign_block_vars('files', array(
299 'FILENAME' => htmlspecialchars($file_struct['filename']),
300 'NUM_CONFLICTS' => (isset($file_struct['conflicts'])) ?
$file_struct['conflicts'] : 0,
302 'S_CUSTOM' => ($file_struct['custom']) ?
true : false,
303 'CUSTOM_ORIGINAL' => ($file_struct['custom']) ?
$file_struct['original'] : '',
305 'U_SHOW_DIFF' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=file_check&action=diff&status=$status&file=" . urlencode($file_struct['filename'])),
306 'UA_SHOW_DIFF' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=file_check&action=diff&status=$status&file=" . urlencode($file_struct['filename']), false),
307 'L_SHOW_DIFF' => ($status != 'up_to_date') ?
$user->lang
['SHOW_DIFF_' . strtoupper($status)] : '',
312 $all_up_to_date = true;
313 foreach ($update_list as $status => $filelist)
315 if ($status != 'up_to_date' && $status != 'custom' && sizeof($filelist))
317 $all_up_to_date = false;
322 $template->assign_vars(array(
323 'S_FILE_CHECK' => true,
324 'S_ALL_UP_TO_DATE' => $all_up_to_date,
325 'S_VERSION_UP_TO_DATE' => $up_to_date,
326 'U_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=file_check"),
327 'U_UPDATE_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=update_files"),
328 'U_DB_UPDATE_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=update_db"),
335 $this->page_title
= 'STAGE_UPDATE_FILES';
337 $s_hidden_fields = '';
338 foreach (request_var('conflict', array('' => 0)) as $filename => $merge_option)
340 $s_hidden_fields .= '<input type="hidden" name="conflict[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />';
343 $no_update = request_var('no_update', array(0 => ''));
345 foreach ($no_update as $index => $filename)
347 $s_hidden_fields .= '<input type="hidden" name="no_update[]" value="' . htmlspecialchars($filename) . '" />';
350 if (!empty($_POST['download']))
352 include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
354 $use_method = request_var('use_method', '');
355 $methods = array('.tar');
357 $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
358 foreach ($available_methods as $type => $module)
360 if (!@extension_loaded
($module))
368 // Let the user decide in which format he wants to have the pack
371 $this->page_title
= 'SELECT_DOWNLOAD_FORMAT';
374 foreach ($methods as $method)
376 $radio_buttons .= '<input type="radio"' . ((!$radio_buttons) ?
' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . ' ';
379 $template->assign_vars(array(
380 'S_DOWNLOAD_FILES' => true,
381 'U_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=update_files"),
382 'RADIO_BUTTONS' => $radio_buttons,
383 'S_HIDDEN_FIELDS' => $s_hidden_fields)
386 // To ease the update process create a file location map
387 $update_list = $cache->get('_update_list');
389 foreach ($update_list as $status => $files)
391 if ($status == 'up_to_date' ||
$status == 'no_update')
396 foreach ($files as $file_struct)
398 if (in_array($file_struct['filename'], $no_update))
403 $template->assign_block_vars('location', array(
404 'SOURCE' => htmlspecialchars($file_struct['filename']),
405 'DESTINATION' => $user->page
['root_script_path'] . htmlspecialchars($file_struct['filename']),
413 if (!in_array($use_method, $methods))
415 $use_method = '.tar';
418 $update_mode = 'download';
422 include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
424 // Choose FTP, if not available use fsock...
425 $method = request_var('method', '');
426 $submit = (isset($_POST['submit'])) ?
true : false;
427 $test_ftp_connection = request_var('test_connection', '');
432 $methods = transfer
::methods();
434 if (!in_array('ftp', $methods))
436 $method = $methods[0];
440 $test_connection = false;
441 if ($test_ftp_connection ||
$submit)
443 $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
444 $test_connection = $transfer->open_session();
446 // Make sure that the directory is correct by checking for the existence of common.php
447 if ($test_connection === true)
449 // Check for common.php file
450 if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx))
452 $test_connection = 'ERR_WRONG_PATH_TO_PHPBB';
456 $transfer->close_session();
458 // Make sure the login details are correct before continuing
459 if ($submit && $test_connection !== true)
462 $test_ftp_connection = true;
468 $this->page_title
= 'SELECT_FTP_SETTINGS';
470 $requested_data = call_user_func(array($method, 'data'));
471 foreach ($requested_data as $data => $default)
473 $template->assign_block_vars('data', array(
475 'NAME' => $user->lang
[strtoupper($method . '_' . $data)],
476 'EXPLAIN' => $user->lang
[strtoupper($method . '_' . $data) . '_EXPLAIN'],
477 'DEFAULT' => (!empty($_REQUEST[$data])) ?
request_var($data, '') : $default
481 $s_hidden_fields .= build_hidden_fields(array('method' => $method));
483 $template->assign_vars(array(
484 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ?
true : false,
485 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ?
true : false,
486 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ?
$user->lang
[$test_connection] : '',
488 'S_FTP_UPLOAD' => true,
489 'UPLOAD_METHOD' => $method,
490 'U_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=update_files"),
491 'S_HIDDEN_FIELDS' => $s_hidden_fields)
497 $update_mode = 'upload';
500 // Now update the installation or download the archive...
501 $archive_filename = 'update_' . $this->update_info
['version']['from'] . '_to_' . $this->update_info
['version']['to'];
502 $update_list = $cache->get('_update_list');
503 $conflicts = request_var('conflict', array('' => 0));
505 if ($update_list === false)
507 trigger_error($user->lang
['NO_UPDATE_INFO'], E_USER_ERROR
);
510 // Check if the conflicts data is valid
511 if (sizeof($conflicts))
513 $conflict_filenames = array();
514 foreach ($update_list['conflict'] as $files)
516 $conflict_filenames[] = $files['filename'];
519 $new_conflicts = array();
520 foreach ($conflicts as $filename => $diff_method)
522 if (in_array($filename, $conflict_filenames))
524 $new_conflicts[$filename] = $diff_method;
528 $conflicts = $new_conflicts;
531 if (sizeof($update_list['conflict']) != sizeof($conflicts))
533 trigger_error($user->lang
['MERGE_SELECT_ERROR'], E_USER_ERROR
);
536 // Now init the connection
537 if ($update_mode == 'download')
539 if ($use_method == '.zip')
541 $compress = new compress_zip('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method);
545 $compress = new compress_tar('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method, $use_method);
550 $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
551 $transfer->open_session();
554 // Ok, go through the update list and do the operations based on their status
555 foreach ($update_list as $status => $files)
557 foreach ($files as $file_struct)
559 // Skip this file if the user selected to not update it
560 if (in_array($file_struct['filename'], $no_update))
565 $original_filename = ($file_struct['custom']) ?
$file_struct['original'] : $file_struct['filename'];
572 if ($update_mode == 'download')
574 $compress->add_custom_file($this->new_location
. $original_filename, $file_struct['filename']);
578 if ($status != 'new')
580 $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
582 $transfer->copy_file($this->new_location
. $original_filename, $file_struct['filename']);
589 'file1' => file_get_contents($this->old_location
. $original_filename),
590 'file2' => file_get_contents($phpbb_root_path . $file_struct['filename']),
591 'file3' => file_get_contents($this->new_location
. $original_filename),
594 $diff = &new diff3($tmp['file1'], $tmp['file2'], $tmp['file3']);
595 $contents = implode("\n", $diff->merged_output());
599 if ($update_mode == 'download')
601 $compress->add_data($contents, $file_struct['filename']);
605 // @todo add option to specify if a backup file should be created?
606 $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
607 $transfer->write_file($file_struct['filename'], $contents);
614 'file1' => file_get_contents($this->old_location
. $original_filename),
615 'file2' => file_get_contents($phpbb_root_path . $file_struct['filename']),
616 'file3' => file_get_contents($this->new_location
. $original_filename),
619 $diff = &new diff3($tmp['file1'], $tmp['file2'], $tmp['file3']);
623 if ($conflicts[$file_struct['filename']] == 1)
625 $contents = implode("\n", $diff->merged_new_output());
627 else if ($conflicts[$file_struct['filename']] == 2)
629 $contents = implode("\n", $diff->merged_orig_output());
639 if ($update_mode == 'download')
641 $compress->add_data($contents, $file_struct['filename']);
645 $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
646 $transfer->write_file($file_struct['filename'], $contents);
653 if ($update_mode == 'download')
657 $compress->download($archive_filename);
658 @unlink
($phpbb_root_path . 'store/' . $archive_filename . $use_method);
664 $transfer->close_session();
666 $template->assign_vars(array(
667 'S_UPLOAD_SUCCESS' => true,
668 'U_ACTION' => append_sid($this->p_master
->module_url
, "mode=$mode&sub=file_check"))
677 // Make sure the database update is valid for the latest version
679 $updates_to_version = '';
681 if (file_exists($phpbb_root_path . 'install/database_update.' . $phpEx))
683 include_once($phpbb_root_path . 'install/database_update.' . $phpEx);
685 if ($updates_to_version === $this->latest_version
)
691 // Should not happen at all
694 trigger_error($user->lang
['DATABASE_UPDATE_INFO_OLD'], E_USER_ERROR
);
697 // Because we are done with the file update we purge the cache directory
700 // Redirect the user to the database update script with some explanations...
701 $template->assign_vars(array(
702 'S_DB_UPDATE' => true,
703 'U_DB_UPDATE' => $phpbb_root_path . 'install/database_update.' . $phpEx)
715 function show_diff(&$update_list)
717 global $phpbb_root_path, $template, $user;
719 $this->tpl_name
= 'install_update_diff';
720 $this->page_title
= 'VIEWING_FILE_DIFF';
722 $status = request_var('status', '');
723 $file = request_var('file', '');
724 $diff_mode = request_var('diff_mode', 'inline');
726 // First of all make sure the file is within our file update list with the correct status
727 $found_entry = array();
728 foreach ($update_list[$status] as $index => $file_struct)
730 if ($file_struct['filename'] === $file)
732 $found_entry = $update_list[$status][$index];
736 if (empty($found_entry))
738 trigger_error($user->lang
['FILE_DIFF_NOT_ALLOWED'], E_USER_ERROR
);
741 // If the status is 'up_to_date' then we do not need to show a diff
742 if ($status == 'up_to_date')
744 trigger_error($user->lang
['FILE_ALREADY_UP_TO_DATE'], E_USER_ERROR
);
747 $original_file = ($found_entry['custom']) ?
$found_entry['original'] : $file;
749 // Get the correct diff
754 'file1' => file_get_contents($this->old_location
. $original_file),
755 'file2' => file_get_contents($phpbb_root_path . $file),
756 'file3' => file_get_contents($this->new_location
. $original_file),
759 $diff = &new diff3($tmp['file1'], $tmp['file2'], $tmp['file3']);
763 $template->assign_vars(array(
764 'S_DIFF_CONFLICT_FILE' => true,
765 'NUM_CONFLICTS' => $diff->merged_output(false, false, false, true))
771 'file1' => file_get_contents($this->old_location
. $original_file),
772 'file2' => file_get_contents($phpbb_root_path . $original_file),
773 'file3' => file_get_contents($this->new_location
. $file),
776 $diff = &new diff3($tmp['file1'], $tmp['file2'], $tmp['file3']);
784 'file1' => file_get_contents($phpbb_root_path . $file),
785 'file2' => file_get_contents($this->new_location
. $original_file),
788 $diff = &new diff($tmp['file1'], $tmp['file2']);
796 'file2' => file_get_contents($this->new_location
. $original_file),
799 $diff = &new diff($tmp['file1'], $tmp['file2']);
803 $template->assign_var('S_DIFF_NEW_FILE', true);
804 $diff_mode = 'inline';
805 $this->page_title
= 'VIEWING_FILE_CONTENTS';
809 $diff_mode_options = '';
810 foreach (array('side_by_side', 'inline', 'unified', 'raw') as $option)
812 $diff_mode_options .= '<option value="' . $option . '"' . (($diff_mode == $option) ?
' selected="selected"' : '') . '>' . $user->lang
['DIFF_' . strtoupper($option)] . '</option>';
815 // Now the correct renderer
816 $render_class = 'diff_renderer_' . $diff_mode;
818 if (!class_exists($render_class))
820 trigger_error('Chosen diff mode is not supported', E_USER_ERROR
);
823 $renderer = &new $render_class();
825 $template->assign_vars(array(
826 'DIFF_CONTENT' => $renderer->get_diff_content($diff),
827 'S_DIFF_MODE_OPTIONS' => $diff_mode_options,
828 'S_SHOW_DIFF' => true,
831 unset($diff, $renderer);
835 * Collect all file status infos we need for the update by diffing all files
837 function get_update_structure()
839 global $phpbb_root_path, $phpEx, $user;
841 $update_list = array(
842 'up_to_date' => array(),
844 'not_modified' => array(),
845 'modified' => array(),
846 'new_conflict' => array(),
847 'conflict' => array(),
848 'no_update' => array(),
851 // Get a list of those files which are completely new by checking with file_exists...
852 foreach ($this->update_info
['files'] as $index => $file)
854 if (!file_exists($phpbb_root_path . $file))
856 // Make sure the update files are consistent by checking if the file is in new_files...
857 if (!file_exists($this->new_location
. $file))
859 trigger_error($user->lang
['INCOMPLETE_UPDATE_FILES'], E_USER_ERROR
);
862 // If the file exists within the old directory the file got removed and we will write it back
863 // not a biggie, but we might want to state this circumstance seperatly later.
864 // if (file_exists($this->old_location . $file))
866 // $update_list['removed'][] = $file;
869 // Only include a new file as new if the underlying path exist
870 // The path normally do not exist if the original style or language has been removed
871 if (file_exists($phpbb_root_path . dirname($file)))
873 $this->get_custom_info($update_list['new'], $file);
874 $update_list['new'][] = array('filename' => $file, 'custom' => false);
878 $update_list['no_update'][] = $file;
880 unset($this->update_info
['files'][$index]);
884 if (!sizeof($this->update_info
['files']))
889 // Now diff the remaining files to get information about their status (not modified/modified/up-to-date)
892 foreach ($this->update_info
['files'] as $index => $file)
894 $this->make_update_diff($update_list, $file, $file);
897 // Now to the styles...
898 if (empty($this->update_info
['custom']))
903 foreach ($this->update_info
['custom'] as $original_file => $file_ary)
905 foreach ($file_ary as $index => $file)
907 $this->make_update_diff($update_list, $original_file, $file, true);
915 * Compare files for storage in update_list
917 function make_update_diff(&$update_list, $original_file, $file, $custom = false)
919 global $phpbb_root_path, $user;
921 $update_ary = array('filename' => $file, 'custom' => $custom);
925 $update_ary['original'] = $original_file;
928 // On a successfull update the new location file exists but the old one does not exist.
929 // Check for this circumstance, the new file need to be up-to-date with the current file then...
930 if (!file_exists($this->old_location
. $original_file) && file_exists($this->new_location
. $original_file) && file_exists($phpbb_root_path . $file))
933 'file1' => file_get_contents($this->new_location
. $original_file),
934 'file2' => file_get_contents($phpbb_root_path . $file),
937 // We need to diff the contents here to make sure the file is really the one we expect
938 $diff = &new diff($tmp['file1'], $tmp['file2'], false);
939 $empty = $diff->is_empty();
943 // if there are no differences we have an up-to-date file...
946 $update_list['up_to_date'][] = $update_ary;
950 // If no other status matches we have another file in the way...
951 $update_list['new_conflict'][] = $update_ary;
955 // Check for existance, else abort immediatly
956 if (!file_exists($this->old_location
. $original_file) ||
!file_exists($this->new_location
. $original_file))
958 trigger_error($user->lang
['INCOMPLETE_UPDATE_FILES'], E_USER_ERROR
);
962 'file1' => file_get_contents($this->old_location
. $original_file),
963 'file2' => file_get_contents($phpbb_root_path . $file),
966 // We need to diff the contents here to make sure the file is really the one we expect
967 $diff = &new diff($tmp['file1'], $tmp['file2'], false);
968 $empty_1 = $diff->is_empty();
973 'file1' => file_get_contents($this->new_location
. $original_file),
974 'file2' => file_get_contents($phpbb_root_path . $file),
977 // We need to diff the contents here to make sure the file is really the one we expect
978 $diff = &new diff($tmp['file1'], $tmp['file2'], false);
979 $empty_2 = $diff->is_empty();
983 // If the file is not modified we are finished here...
986 // Further check if it is already up to date - it could happen that non-modified files
990 $update_list['up_to_date'][] = $update_ary;
994 $update_list['not_modified'][] = $update_ary;
998 // If the file had been modified then we need to check if it is already up to date
1000 // if there are no differences we have an up-to-date file...
1003 $update_list['up_to_date'][] = $update_ary;
1007 // if the file is modified we try to make sure a merge succeed
1009 'file1' => file_get_contents($this->old_location
. $original_file),
1010 'file2' => file_get_contents($phpbb_root_path . $file),
1011 'file3' => file_get_contents($this->new_location
. $original_file),
1014 $diff = &new diff3($tmp['file1'], $tmp['file2'], $tmp['file3'], false);
1018 if ($diff->merged_output(false, false, false, true))
1020 $update_ary['conflicts'] = $diff->_conflicting_blocks
;
1021 $update_list['conflict'][] = $update_ary;
1029 'file1' => file_get_contents($phpbb_root_path . $file),
1030 'file2' => implode("\n", $diff->merged_output()),
1033 // now compare the merged output with the original file to see if the modified file is up to date
1034 $diff = &new diff($tmp['file1'], $tmp['file2'], false);
1035 $empty = $diff->is_empty();
1039 $update_list['up_to_date'][] = $update_ary;
1043 // If no other status matches we have a modified file...
1044 $update_list['modified'][] = $update_ary;
1048 * Update update_list with custom new files
1050 function get_custom_info(&$update_list, $file)
1052 if (empty($this->update_info
['custom']))
1057 if (in_array($file, array_keys($this->update_info
['custom'])))
1059 foreach ($this->update_info
['custom'][$file] as $_file)
1061 $update_list[] = array('filename' => $_file, 'custom' => true, 'original' => $file);
1069 function get_file($mode)
1078 case 'version_info':
1079 $info = get_remote_file('www.phpbb.com', '/updatecheck', '30x.txt', $errstr, $errno);
1081 if ($info !== false)
1083 $info = explode("\n", $info);
1084 $info = trim($info[0]);
1087 if ($this->test_update
!== false)
1089 $info = $this->test_update
;
1094 global $phpbb_root_path, $phpEx;
1096 $update_info = array();
1097 include($phpbb_root_path . 'install/update/index.php');
1099 $info = (empty($update_info) ||
!is_array($update_info)) ?
false : $update_info;
1100 $errstr = ($info === false) ?
$user->lang
['WRONG_INFO_FILE_FORMAT'] : '';
1102 if ($info !== false)
1104 // Adjust the update info file to hold some specific style-related information
1105 $info['custom'] = array();
1107 /* Get custom installed styles...
1108 $sql = 'SELECT template_name, template_path
1109 FROM ' . STYLES_TEMPLATE_TABLE . "
1110 WHERE template_name NOT IN ('subSilver', 'BLABLA')";
1111 $result = $db->sql_query($sql);
1113 $templates = array();
1114 while ($row = $db->sql_fetchrow($result))
1116 $templates[] = $row;
1118 $db->sql_freeresult($result);
1120 if (sizeof($templates))
1122 foreach ($info['files'] as $filename)
1125 if (strpos($filename, 'styles/subSilver/template/') === 0)
1127 foreach ($templates as $row)
1129 $info['custom'][$filename][] = str_replace('/subSilver/', '/' . $row['template_path'] . '/', $filename);
1139 trigger_error('Mode for getting remote file not specified', E_USER_ERROR
);
1143 if ($info === false)
1145 trigger_error($errstr, E_USER_ERROR
);