aboutsummaryrefslogtreecommitdiff
blob: 0824b53caaeda7e0ade1b1d31ca21868f7b52e6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#!/usr/bin/env php
<?php
/**
*
* @package build
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

if ($_SERVER['argc'] != 3)
{
	die("Please specify the previous and current version as arguments (e.g. build_diff.php '1.0.2' '1.0.3').");
}

$old_version = trim($_SERVER['argv'][1]);
$new_version = trim($_SERVER['argv'][2]);

$substitute_old = $old_version;
$substitute_new = $new_version;
$simple_name_old = 'release-' . $old_version;
$simple_name_new = 'release-' . $new_version;
$echo_changes = false;

// DO NOT EVER USE THE FOLLOWING! Fix the script to generate proper changes,
// do NOT manually create them.

// Set this to true to just compress the changes and do not build them again
// This should be used for building custom modified txt file. ;)
$package_changed_files = false;

//$debug_file = 'includes/functions_user.php'; //'styles/prosilver/style.cfg';
$debug_file = false;

if ($debug_file !== false)
{
	$echo_changes = false;
}

$s_name = 'save_' . $substitute_old . '_to_' . $substitute_new;

$location = dirname(__FILE__);

if (!$package_changed_files)
{
	if (!$echo_changes)
	{
		// Create directory...
		run_command("mkdir $location/save/{$s_name}");
		run_command("mkdir $location/save/{$s_name}/language");
		run_command("mkdir $location/save/{$s_name}/prosilver");
		run_command("mkdir $location/save/{$s_name}/subsilver2");
	}
}

// Build code changes and place them into 'save'
if (!$package_changed_files)
{
	build_code_changes('language');
	build_code_changes('prosilver');
	build_code_changes('subsilver2');
}

// Package code changes
$code_changes_filename = 'phpBB-' . $substitute_old . '_to_' . $substitute_new . '-codechanges';

if (!$echo_changes)
{
	// Now compress the files...
	// Build Main phpBB Release
	$compress_programs = array(
//		'tar.gz'	=> 'tar -czf',
		'tar.bz2'	=> 'tar -cjf',
		'zip'		=> 'zip -r'
	);

	chdir($location . '/save/' . $s_name);
	foreach ($compress_programs as $extension => $compress_command)
	{
		echo "Packaging code changes for $extension\n";
		run_command("rm ./../../new_version/release_files/{$code_changes_filename}.{$extension}");
		flush();

		// Build Package
		run_command("$compress_command ./../../new_version/release_files/{$code_changes_filename}.{$extension} *");

		// Build MD5 Sum
		run_command("md5sum ./../../new_version/release_files/{$code_changes_filename}.{$extension} > ./../../new_version/release_files/{$code_changes_filename}.{$extension}.md5");
		flush();
	}
}

/**
* $output_format can be: language, prosilver and subsilver2
*/
function build_code_changes($output_format)
{
	global $substitute_new, $substitute_old, $simple_name_old, $simple_name_new, $echo_changes, $package_changed_files, $location, $debug_file, $s_name;

	// Global array holding the data entries
	$data = array(
		'header'		=> array(),
		'diff'			=> array(),
	);

	// Read diff file and prepare the output filedata...
	//$patch_filename = '../new_version/patches/phpBB-' . $substitute_old . '_to_' . $substitute_new . '.patch';
	$release_filename = 'phpbb-' . $substitute_old . '_to_' . $substitute_new . '_' . $output_format . '.txt';

	if (!$package_changed_files)
	{
		if (!$echo_changes)
		{
			$fp = fopen('save/' . $s_name . '/' . $output_format . '/' . $release_filename, 'wb');

			if (!$fp)
			{
				die('Unable to create ' . $release_filename);
			}
		}
	}

	include_once($location . '/build_helper.php');
	$package = new build_package(array($substitute_old, $substitute_new), false);

	$titles = array(
		'language'		=> 'phpBB ' . $substitute_old . ' to phpBB ' . $substitute_new . ' Language Pack Changes',
		'prosilver'		=> 'phpBB ' . $substitute_old . ' to phpBB ' . $substitute_new . ' prosilver Changes',
		'subsilver2'	=> 'phpBB ' . $substitute_old . ' to phpBB ' . $substitute_new . ' subsilver2 Changes',
	);

	$data['header'] = array(
		'title'		=> $titles[$output_format],
		'intro'		=> '

These are the ' . $titles[$output_format] . ' summed up into a little Mod. These changes are only partial and do not include any code changes, therefore not meant for updating phpBB.

	',
		'included_files'	=> array(),
	);

	// We collect the files we want to diff first (ironically we grab this from a diff file)
	if (!$echo_changes)
	{
		echo "\n\nCollecting Filenames:";
	}

	// We re-create the patch file
	foreach ($package->old_packages as $_package_name => $dest_package_filename)
	{
		chdir($package->locations['old_versions']);

		if (!$echo_changes)
		{
			echo "\n\n" . 'Creating patch/diff files for phpBB-' . $dest_package_filename . $package->get('new_version_number');
		}

		$dest_package_filename = $location . '/save/' . $s_name . '/phpBB-' . $dest_package_filename . $package->get('new_version_number') . '.patch';
		$package->run_command('diff ' . $package->diff_options . ' ' . $_package_name . ' ' . $package->get('simple_name') . ' > ' . $dest_package_filename);

		// Parse this diff to determine file changes from the checked versions and save them
		$result = $package->collect_diff_files($dest_package_filename, $_package_name);
		$package->run_command('rm ' . $dest_package_filename);
	}

	chdir($location);

	$filenames = array();
	foreach ($result['files'] as $filename)
	{
		if ($debug_file !== false && $filename != $debug_file)
		{
			continue;
		}

		// Decide which files to compare...
		switch ($output_format)
		{
			case 'language':
				if (strpos($filename, 'language/en/') !== 0)
				{
					continue 2;
				}
			break;

			case 'prosilver':
				if (strpos($filename, 'styles/prosilver/') !== 0)
				{
					continue 2;
				}
			break;

			case 'subsilver2':
				if (strpos($filename, 'styles/subsilver2/') !== 0)
				{
					continue 2;
				}
			break;
		}

		if (!file_exists($location . '/old_versions/' . $simple_name_old . '/' . $filename))
		{
			// New file... include it
			$data['header']['included_files'][] = array(
				'old'				=> $location . '/old_versions/' . $simple_name_old . '/' . $filename,
				'new'				=> $location . '/old_versions/' . $simple_name_new . '/' . $filename,
				'phpbb_filename'	=> $filename,
			);
			continue;
		}

		$filenames[] = array(
			'old'				=> $location . '/old_versions/' . $simple_name_old . '/' . $filename,
			'new'				=> $location . '/old_versions/' . $simple_name_new . '/' . $filename,
			'phpbb_filename'	=> $filename,
		);
	}

	// Now let us go through the filenames list and create a more comprehensive diff
	if (!$echo_changes)
	{
		fwrite($fp, build_header($output_format, $filenames, $data['header']));
	}
	else
	{
		//echo build_header('text', $filenames, $data['header']);
	}

	// Copy files...
	$files_to_copy = array();

	foreach ($data['header']['included_files'] as $filename)
	{
		$files_to_copy[] = $filename['phpbb_filename'];
	}

	// First step is to copy the new version over (clean structure)
	if (!$echo_changes && sizeof($files_to_copy))
	{
		foreach ($files_to_copy as $file)
		{
			// Create directory?
			$dirname = dirname($file);

			if ($dirname)
			{
				$dirname = explode('/', $dirname);
				$__dir = array();

				foreach ($dirname as $i => $dir)
				{
					$__dir[] = $dir;
					run_command("mkdir -p $location/save/" . $s_name . '/' . $output_format . '/' . implode('/', $__dir));
				}
			}

			$source_file = $location . '/new_version/phpBB3/' . $file;
			$dest_file = $location . '/save/' . $s_name . '/' . $output_format . '/';
			$dest_file .= $file;

			$command = "cp -p $source_file $dest_file";
			$result = trim(`$command`);
			echo "- Copied File: " . $source_file . " -> " . $dest_file . "\n";
		}
	}

	include_once('diff_class.php');

	if (!$echo_changes)
	{
		echo "\n\nDiffing Codebases:";
	}

	foreach ($filenames as $file_ary)
	{
		if (!file_exists($file_ary['old']))
		{
			$lines1 = array();
		}
		else
		{
			$lines1 = file($file_ary['old']);
		}
		$lines2 = file($file_ary['new']);

		if (!sizeof($lines1))
		{
			// New File
		}
		else
		{
			$diff = new Diff($lines1, $lines2);
			$fmt = new BBCodeDiffFormatter(false, 5, $debug_file);

			if (!$echo_changes)
			{
				fwrite($fp, $fmt->format_open($file_ary['phpbb_filename']));
				fwrite($fp, $fmt->format($diff, $lines1));
				fwrite($fp, $fmt->format_close($file_ary['phpbb_filename']));
			}
			else
			{
				echo $fmt->format_open($file_ary['phpbb_filename']);
				echo $fmt->format($diff, $lines1);
				echo $fmt->format_close($file_ary['phpbb_filename']);
			}

			if ($debug_file !== false)
			{
				echo $fmt->format_open($file_ary['phpbb_filename']);
				echo $fmt->format($diff, $lines1);
				echo $fmt->format_close($file_ary['phpbb_filename']);
				exit;
			}
		}
	}

	if (!$echo_changes)
	{
		fwrite($fp, build_footer($output_format));

		// Close file
		fclose($fp);

		chmod('save/' . $s_name . '/' . $output_format . '/' . $release_filename, 0666);
	}
	else
	{
		echo build_footer($output_format);
	}
}

/**
* Build Footer
*/
function build_footer($mode)
{
	$html = '';

	$html .= "# \n";
	$html .= "#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ \n";
	$html .= "# \n";
	$html .= "# EoM";

	return $html;
}

/**
* Build Header
*/
function build_header($mode, $filenames, $header)
{
	global $substitute_old;

	$html = '';

	$html .= "############################################################## \n";
	$html .= "## Title: " . $header['title'] . "\n";
	$html .= "## Author: naderman < naderman@phpbb.com > (Nils Adermann) http://www.phpbb.com \n";
	$html .= "## Description: \n";

	$intr = explode("\n", $header['intro']);
	$introduction = '';
	foreach ($intr as $_line)
	{
		$introduction .= wordwrap($_line, 80) . "\n";
	}
	$intr = explode("\n", $introduction);

	foreach ($intr as $_line)
	{
		$html .= "##		" . $_line . "\n";
	}
	$html .= "## \n";
	$html .= "## Files To Edit: \n";

	foreach ($filenames as $file_ary)
	{
		$html .= "##		" . $file_ary['phpbb_filename'] . "\n";
	}
	$html .= "##\n";
	if (sizeof($header['included_files']))
	{
		$html .= "## Included Files: \n";
		foreach ($header['included_files'] as $filename)
		{
			$html .= "##		{$filename['phpbb_filename']}\n";
		}
	}
	$html .= "## License: http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 \n";
	$html .= "############################################################## \n";
	$html .= "\n";

	// COPY Statement?
	if (sizeof($header['included_files']))
	{
		$html .= "#\n#-----[ COPY ]------------------------------------------\n#\n";
		foreach ($header['included_files'] as $filename)
		{
			$html .= "copy {$filename['phpbb_filename']} to {$filename['phpbb_filename']}\n";
		}
		$html .= "\n";
	}

	return $html;
}

function run_command($command)
{
	$result = trim(`$command`);
	echo "\n- Command Run: " . $command . "\n";
}

?>