Skip to content

Commit f14bbd9

Browse files
authored
Merge pull request #406 from iMattPro/prep-phpbb4-branch-releases
Composer repository builder should also make a phpBB4 only packages.json
2 parents afc5f0d + d4239e8 commit f14bbd9

File tree

5 files changed

+95
-14
lines changed

5 files changed

+95
-14
lines changed

composer/repository.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use phpbb\config\config;
1717
use phpbb\exception\runtime_exception;
18+
use phpbb\titania\ext;
1819
use Symfony\Component\Filesystem\Filesystem;
1920
use Symfony\Component\Finder\Finder;
2021

@@ -63,6 +64,13 @@ public function prepare_build_dir($force)
6364
}
6465
$this->fs->mkdir($this->build_dir);
6566

67+
// Create filtered repository subdirectories
68+
$branches = ext::get_filtered_repository_branches();
69+
foreach ($branches as $branch)
70+
{
71+
$this->fs->mkdir($this->build_dir . $branch);
72+
}
73+
6674
return $this;
6775
}
6876

@@ -152,8 +160,9 @@ public function set_release(array $packages, $composer_json, $download_url, $con
152160
*
153161
* @param string $name File name
154162
* @param array $packages Packages to be dumped
163+
* @param string $subdir Optional subdirectory
155164
*/
156-
public function dump_include($name, array $packages)
165+
public function dump_include($name, array $packages, $subdir = '')
157166
{
158167
foreach ($packages as $package_name => $versions)
159168
{
@@ -163,7 +172,8 @@ public function dump_include($name, array $packages)
163172
array('packages' => $packages),
164173
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
165174
);
166-
$file = $this->build_dir . $name;
175+
$target_dir = $this->build_dir . $subdir;
176+
$file = $target_dir . $name;
167177
$this->fs->dumpFile($file, $packages);
168178
}
169179

@@ -189,9 +199,25 @@ protected function get_include_files()
189199
* Build include file parents included package.json
190200
*/
191201
protected function build_parents()
202+
{
203+
$this->build_parent_structure();
204+
$branches = ext::get_filtered_repository_branches();
205+
foreach ($branches as $branch)
206+
{
207+
$this->build_parent_structure($branch . '/');
208+
}
209+
}
210+
211+
/**
212+
* Build parent structure for given subdirectory
213+
*
214+
* @param string $subdir Optional subdirectory
215+
*/
216+
protected function build_parent_structure($subdir = '')
192217
{
193218
$includes = $this->get_include_files();
194219
$parent = $types = array();
220+
$target_dir = $this->build_dir . $subdir;
195221

196222
foreach ($includes as $file)
197223
{
@@ -212,7 +238,7 @@ protected function build_parents()
212238
foreach ($types as $type => $includes)
213239
{
214240
$type_filename = 'packages-' . $type . '.json';
215-
$type_filepath = $this->build_dir . $type_filename;
241+
$type_filepath = $target_dir . $type_filename;
216242
$contents = json_encode(array('includes' => $includes));
217243
$this->fs->dumpFile($type_filepath, $contents);
218244

@@ -223,7 +249,7 @@ protected function build_parents()
223249
if (!empty($parent))
224250
{
225251
$contents = json_encode(array('includes' => $parent));
226-
$this->fs->dumpFile($this->build_dir . 'packages.json', $contents);
252+
$this->fs->dumpFile($target_dir . 'packages.json', $contents);
227253
}
228254
}
229255

config/routes/general.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ phpbb.titania.contribution.id:
6464
requirements:
6565
id: \d+
6666

67+
phpbb.titania.composer.40.files:
68+
path: /composer/40/{filename}.json
69+
defaults: { _controller: phpbb.titania.controller.composer:serve_file, subdirectory: '40/' }
70+
71+
phpbb.titania.composer.40:
72+
path: /composer/40/
73+
defaults: { _controller: phpbb.titania.controller.composer:serve_file, filename: packages, subdirectory: '40/' }
74+
6775
phpbb.titania.composer:
6876
path: /composer/{filename}.json
6977
defaults: { _controller: phpbb.titania.controller.composer:serve_file }

controller/composer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,21 @@ public function __construct(\phpbb\user $user, \phpbb\titania\controller\helper
4444
* Serve composer's files.
4545
*
4646
* @param string $filename Filename to serve (without extension)
47+
* @param string $subdirectory Optional subdirectory
4748
* @return \Symfony\Component\HttpFoundation\Response
4849
*/
49-
public function serve_file($filename)
50+
public function serve_file($filename, $subdirectory = '')
5051
{
51-
if (strpos($filename, '..') !== false)
52+
if (strpos($filename, '..') !== false || strpos($subdirectory, '..') !== false)
5253
{
5354
throw new http_exception(404, 'NO_PAGE_FOUND');
5455
}
5556

56-
$filename = $this->titania_root_path . 'composer_packages/prod/' . $filename . '.json';
57+
$filepath = $this->titania_root_path . 'composer_packages/prod/' . $subdirectory . $filename . '.json';
5758

5859
try
5960
{
60-
return new BinaryFileResponse($filename, 200);
61+
return new BinaryFileResponse($filepath, 200);
6162
}
6263
catch (\Exception $e)
6364
{

ext.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ class ext extends \phpbb\extension\base
9595

9696
// Misc
9797
const TITANIA_CONFIG_PREFIX = 'titania_';
98+
99+
/**
100+
* Get filtered repository branch versions
101+
*
102+
* @return array Array of branch numbers to create filtered repositories for
103+
*/
104+
public static function get_filtered_repository_branches(): array
105+
{
106+
return [40];
107+
}
98108
}

manage/tool/composer/rebuild_repo.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use phpbb\titania\ext;
2424
use phpbb\titania\manage\tool\base;
2525
use Symfony\Component\Console\Helper\ProgressBar;
26-
use Symfony\Component\Finder\SplFileInfo;
2726

2827
class rebuild_repo extends base
2928
{
@@ -57,6 +56,9 @@ class rebuild_repo extends base
5756
/** @var string */
5857
protected $revisions_table;
5958

59+
/** @var string */
60+
protected $revisions_phpbb_table;
61+
6062
/** @var int */
6163
protected $total;
6264

@@ -84,6 +86,7 @@ public function __construct(db_driver_interface $db, ext_config $ext_config, typ
8486
$this->attachments_table = $table_prefix . 'attachments';
8587
$this->contribs_table = $table_prefix . 'contribs';
8688
$this->revisions_table = $table_prefix . 'revisions';
89+
$this->revisions_phpbb_table = $table_prefix . 'revisions_phpbb';
8790
}
8891

8992
/**
@@ -140,11 +143,13 @@ protected function get_batch($fetch_attach_data)
140143
}
141144

142145
$sql = 'SELECT c.contrib_id, c.contrib_name_clean, c.contrib_type, r.revision_id,
143-
r.attachment_id, r.revision_composer_json' . $attach_fields . '
146+
r.attachment_id, r.revision_composer_json, rp.phpbb_version_branch' . $attach_fields . '
144147
FROM ' . $this->contribs_table . ' c, ' .
145-
$this->revisions_table . ' r ' .
148+
$this->revisions_table . ' r, ' .
149+
$this->revisions_phpbb_table . ' rp ' .
146150
$attach_table . '
147-
WHERE c.contrib_id = r.contrib_id ' .
151+
WHERE c.contrib_id = r.contrib_id
152+
AND r.revision_id = rp.revision_id ' .
148153
$attach_where . '
149154
AND c.contrib_status = ' . ext::TITANIA_CONTRIB_APPROVED . '
150155
AND r.revision_status = ' . ext::TITANIA_REVISION_APPROVED . '
@@ -192,6 +197,12 @@ public function run($from_file = false, $force = false, $progress = null)
192197

193198
$last_type = $last_contrib = '';
194199
$packages = array();
200+
$filtered_packages = array();
201+
$branches = ext::get_filtered_repository_branches();
202+
foreach ($branches as $branch)
203+
{
204+
$filtered_packages[$branch] = array();
205+
}
195206

196207
foreach ($batch as $contrib_id => $revisions)
197208
{
@@ -246,6 +257,20 @@ public function run($from_file = false, $force = false, $progress = null)
246257
$download_url,
247258
$contrib_url
248259
);
260+
261+
foreach ($filtered_packages as $branch => $packages_data)
262+
{
263+
if ($revision['phpbb_version_branch'] >= $branch)
264+
{
265+
$filtered_packages[$branch] = $this->repo->set_release(
266+
$filtered_packages[$branch],
267+
$revision['revision_composer_json'],
268+
$download_url,
269+
$contrib_url
270+
);
271+
}
272+
}
273+
249274
unset($batch[$contrib_id][$index]);
250275
}
251276

@@ -257,6 +282,11 @@ public function run($from_file = false, $force = false, $progress = null)
257282
if (($group_count % 50) === 0)
258283
{
259284
$this->dump_include($last_type, $group, $packages);
285+
foreach ($filtered_packages as $branch => $packages_data)
286+
{
287+
$this->dump_include($last_type, $group, $packages_data, $branch);
288+
$filtered_packages[$branch] = array();
289+
}
260290
$group_count = 0;
261291
$group++;
262292
$packages = array();
@@ -266,6 +296,10 @@ public function run($from_file = false, $force = false, $progress = null)
266296
if (!empty($packages))
267297
{
268298
$this->dump_include($last_type, $group, $packages);
299+
foreach ($filtered_packages as $branch => $packages_data)
300+
{
301+
$this->dump_include($last_type, $group, $packages_data, $branch);
302+
}
269303
}
270304

271305
$next_batch = $this->limit ? $this->start + $this->limit : $this->get_total();
@@ -288,11 +322,13 @@ public function run($from_file = false, $force = false, $progress = null)
288322
* @param string $type Contrib type name
289323
* @param int $group Group id
290324
* @param array $packages Packages
325+
* @param int $branch Optional branch number for subdirectory
291326
*/
292-
protected function dump_include($type, $group, array $packages)
327+
protected function dump_include($type, $group, array $packages, $branch = null)
293328
{
294329
$type_name = $this->types->get($type)->name;
295-
$this->repo->dump_include("packages-$type_name-$group.json", $packages);
330+
$subdir = $branch ? $branch . '/' : '';
331+
$this->repo->dump_include("packages-$type_name-$group.json", $packages, $subdir);
296332
}
297333

298334
/**

0 commit comments

Comments
 (0)