Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
diff_files.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\install\module\update_filesystem\task;
015
016 use phpbb\install\exception\resource_limit_reached_exception;
017 use phpbb\install\exception\user_interaction_required_exception;
018 use phpbb\install\helper\config;
019 use phpbb\install\helper\container_factory;
020 use phpbb\install\helper\iohandler\iohandler_interface;
021 use phpbb\install\helper\update_helper;
022 use phpbb\install\task_base;
023
024 /**
025 * Merges user made changes into the files
026 */
027 class diff_files extends task_base
028 {
029 /**
030 * @var \phpbb\cache\driver\driver_interface
031 */
032 protected $cache;
033
034 /**
035 * @var config
036 */
037 protected $installer_config;
038
039 /**
040 * @var iohandler_interface
041 */
042 protected $iohandler;
043
044 /**
045 * @var string
046 */
047 protected $phpbb_root_path;
048
049 /**
050 * @var string
051 */
052 protected $php_ext;
053
054 /**
055 * @var update_helper
056 */
057 protected $update_helper;
058
059 /**
060 * Constructor
061 *
062 * @param container_factory $container
063 * @param config $config
064 * @param iohandler_interface $iohandler
065 * @param update_helper $update_helper
066 * @param string $phpbb_root_path
067 * @param string $php_ext
068 */
069 public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path, $php_ext)
070 {
071 $this->installer_config = $config;
072 $this->iohandler = $iohandler;
073 $this->update_helper = $update_helper;
074 $this->phpbb_root_path = $phpbb_root_path;
075 $this->php_ext = $php_ext;
076
077 $this->cache = $container->get('cache.driver');
078
079 parent::__construct(false);
080 }
081
082 /**
083 * {@inheritdoc}
084 */
085 public function check_requirements()
086 {
087 $files_to_diff = $this->installer_config->get('update_files', array());
088 $files_to_diff = (isset($files_to_diff['update_with_diff'])) ? $files_to_diff['update_with_diff'] : array();
089
090 return $this->installer_config->get('do_update_files', false) && count($files_to_diff) > 0;
091 }
092
093 /**
094 * {@inheritdoc}
095 */
096 public function run()
097 {
098 // Include diff engine
099 $this->update_helper->include_file('includes/diff/diff.' . $this->php_ext);
100 $this->update_helper->include_file('includes/diff/engine.' . $this->php_ext);
101
102 // Set up basic vars
103 $old_path = $this->update_helper->get_path_to_old_update_files();
104 $new_path = $this->update_helper->get_path_to_new_update_files();
105
106 $files_to_diff = $this->installer_config->get('update_files', array());
107 $files_to_diff = $files_to_diff['update_with_diff'];
108
109 // Set progress bar
110 $this->iohandler->set_task_count(count($files_to_diff), true);
111 $this->iohandler->set_progress('UPDATE_FILE_DIFF', 0);
112 $progress_count = $this->installer_config->get('file_diff_update_count', 0);
113
114 // Recover progress
115 $progress_key = $this->installer_config->get('differ_progress_key', -1);
116 $progress_recovered = ($progress_key === -1);
117 $merge_conflicts = $this->installer_config->get('merge_conflict_list', array());
118
119 foreach ($files_to_diff as $key => $filename)
120 {
121 if ($progress_recovered === false)
122 {
123 if ($progress_key === $key)
124 {
125 $progress_recovered = true;
126 }
127
128 continue;
129 }
130
131 // Read in files' content
132 $file_contents = array();
133
134 // Handle the special case when user created a file with the filename that is now new in the core
135 $file_contents[0] = (file_exists($old_path . $filename)) ? file_get_contents($old_path . $filename) : '';
136
137 $filenames = array(
138 $this->phpbb_root_path . $filename,
139 $new_path . $filename
140 );
141
142 foreach ($filenames as $file_to_diff)
143 {
144 $file_contents[] = file_get_contents($file_to_diff);
145
146 if ($file_contents[sizeof($file_contents) - 1] === false)
147 {
148 $this->iohandler->add_error_message(array('FILE_DIFFER_ERROR_FILE_CANNOT_BE_READ', $files_to_diff));
149 unset($file_contents);
150 throw new user_interaction_required_exception();
151 }
152 }
153
154 $diff = new \diff3($file_contents[0], $file_contents[1], $file_contents[2]);
155 unset($file_contents);
156
157 // Handle conflicts
158 if ($diff->get_num_conflicts() !== 0)
159 {
160 $merge_conflicts[] = $filename;
161 }
162
163 // Save merged output
164 $this->cache->put(
165 '_file_' . md5($filename),
166 base64_encode(implode("\n", $diff->merged_output()))
167 );
168
169 unset($diff);
170
171 $progress_count++;
172 $this->iohandler->set_progress('UPDATE_FILE_DIFF', $progress_count);
173
174 if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0)
175 {
176 // Save differ progress
177 $this->installer_config->set('differ_progress_key', $key);
178 $this->installer_config->set('merge_conflict_list', $merge_conflicts);
179 $this->installer_config->set('file_diff_update_count', $progress_count);
180
181 // Request refresh
182 throw new resource_limit_reached_exception();
183 }
184 }
185
186 $this->iohandler->finish_progress('ALL_FILES_DIFFED');
187 $this->installer_config->set('merge_conflict_list', $merge_conflicts);
188 }
189
190 /**
191 * {@inheritdoc}
192 */
193 static public function get_step_count()
194 {
195 return 0;
196 }
197
198 /**
199 * {@inheritdoc}
200 */
201 public function get_task_lang_name()
202 {
203 return '';
204 }
205 }
206