Skip to content

Commit dd82941

Browse files
committed
Build a separate phpbb4 only repository list in addition to a complete list
1 parent 70cbe1d commit dd82941

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

composer/repository.php

Lines changed: 25 additions & 8 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

@@ -170,15 +171,17 @@ public function dump_include($name, array $packages)
170171
/**
171172
* Get include files.
172173
*
174+
* @param string $prefix Optional prefix to filter files
173175
* @return Finder
174176
*/
175-
protected function get_include_files()
177+
protected function get_include_files($prefix = '')
176178
{
177179
$finder = new Finder;
180+
$pattern = $prefix ? '/^packages\-' . preg_quote($prefix, '/') . '[a-z]+\-\d+\.json$/' : '/^packages\-[a-z]+\-\d+\.json$/';
178181
$finder
179182
->files()
180183
->depth('== 0')
181-
->name('/^packages\-[a-z]+\-\d+\.json$/')
184+
->name($pattern)
182185
->in($this->build_dir)
183186
;
184187

@@ -190,12 +193,23 @@ protected function get_include_files()
190193
*/
191194
protected function build_parents()
192195
{
193-
$includes = $this->get_include_files();
196+
$this->build_parent_structure();
197+
$this->build_parent_structure(ext::TITANIA_REPOSITORY_MIN_PHPBB_BRANCH . '-');
198+
}
199+
200+
/**
201+
* Build parent structure for given prefix
202+
*
203+
* @param string $prefix Optional prefix for files
204+
*/
205+
protected function build_parent_structure($prefix = '')
206+
{
207+
$includes = $this->get_include_files($prefix);
194208
$parent = $types = array();
195209

196210
foreach ($includes as $file)
197211
{
198-
$type = $this->get_include_type($file->getFilename());
212+
$type = $this->get_include_type($file->getFilename(), $prefix);
199213

200214
if ($type)
201215
{
@@ -211,7 +225,7 @@ protected function build_parents()
211225

212226
foreach ($types as $type => $includes)
213227
{
214-
$type_filename = 'packages-' . $type . '.json';
228+
$type_filename = $prefix ? 'packages-' . $prefix . $type . '.json' : 'packages-' . $type . '.json';
215229
$type_filepath = $this->build_dir . $type_filename;
216230
$contents = json_encode(array('includes' => $includes));
217231
$this->fs->dumpFile($type_filepath, $contents);
@@ -222,23 +236,26 @@ protected function build_parents()
222236
}
223237
if (!empty($parent))
224238
{
239+
$main_filename = $prefix ? 'packages-' . rtrim($prefix, '-') . '.json' : 'packages.json';
225240
$contents = json_encode(array('includes' => $parent));
226-
$this->fs->dumpFile($this->build_dir . 'packages.json', $contents);
241+
$this->fs->dumpFile($this->build_dir . $main_filename, $contents);
227242
}
228243
}
229244

230245
/**
231246
* Get contrib type name from include file name.
232247
*
233248
* @param string $filename
249+
* @param string $prefix Optional prefix to match
234250
* @return bool|string Returns contrib type name or false if not a valid filename
235251
*/
236-
protected function get_include_type($filename)
252+
protected function get_include_type($filename, $prefix = '')
237253
{
238254
$filename = utf8_basename($filename);
239255
$match = array();
256+
$pattern = $prefix ? '/^packages\-' . preg_quote($prefix, '/') . '([a-z]+)\-\d+\.json$/' : '/^packages\-([a-z]+)\-\d+\.json$/';
240257

241-
if (preg_match('/^packages\-([a-z]+)\-\d+\.json$/', $filename, $match))
258+
if (preg_match($pattern, $filename, $match))
242259
{
243260
return $match[1];
244261
}

manage/tool/composer/rebuild_repo.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ public function get_total()
108108

109109
$sql = 'SELECT COUNT(r.revision_id) AS cnt
110110
FROM ' . $this->contribs_table . ' c, ' .
111-
$this->revisions_table . ' r, ' .
112-
$this->revisions_phpbb_table . ' rp
111+
$this->revisions_table . ' r
113112
WHERE c.contrib_id = r.contrib_id
114-
AND r.revision_id = rp.revision_id
115113
AND c.contrib_status = ' . ext::TITANIA_CONTRIB_APPROVED . '
116114
AND r.revision_status = ' . ext::TITANIA_REVISION_APPROVED . '
117-
AND rp.phpbb_version_branch >= ' . ext::TITANIA_REPOSITORY_MIN_PHPBB_BRANCH . '
118115
AND ' . $this->db->sql_in_set('c.contrib_type', $types);
119116
$this->db->sql_query($sql);
120117
$this->total = (int) $this->db->sql_fetchfield('cnt');
@@ -146,7 +143,7 @@ protected function get_batch($fetch_attach_data)
146143
}
147144

148145
$sql = 'SELECT c.contrib_id, c.contrib_name_clean, c.contrib_type, r.revision_id,
149-
r.attachment_id, r.revision_composer_json' . $attach_fields . '
146+
r.attachment_id, r.revision_composer_json, rp.phpbb_version_branch' . $attach_fields . '
150147
FROM ' . $this->contribs_table . ' c, ' .
151148
$this->revisions_table . ' r, ' .
152149
$this->revisions_phpbb_table . ' rp ' .
@@ -156,7 +153,6 @@ protected function get_batch($fetch_attach_data)
156153
$attach_where . '
157154
AND c.contrib_status = ' . ext::TITANIA_CONTRIB_APPROVED . '
158155
AND r.revision_status = ' . ext::TITANIA_REVISION_APPROVED . '
159-
AND rp.phpbb_version_branch >= ' . ext::TITANIA_REPOSITORY_MIN_PHPBB_BRANCH . '
160156
AND ' . $this->db->sql_in_set('c.contrib_type', $types) . '
161157
ORDER BY c.contrib_id ASC, r.revision_id ASC';
162158
$result = $this->db->sql_query_limit($sql, $this->limit, $this->start);
@@ -201,6 +197,7 @@ public function run($from_file = false, $force = false, $progress = null)
201197

202198
$last_type = $last_contrib = '';
203199
$packages = array();
200+
$packages_phpbb4_only = array();
204201

205202
foreach ($batch as $contrib_id => $revisions)
206203
{
@@ -255,6 +252,17 @@ public function run($from_file = false, $force = false, $progress = null)
255252
$download_url,
256253
$contrib_url
257254
);
255+
256+
if ($revision['phpbb_version_branch'] >= ext::TITANIA_REPOSITORY_MIN_PHPBB_BRANCH)
257+
{
258+
$packages_phpbb4_only = $this->repo->set_release(
259+
$packages_phpbb4_only,
260+
$revision['revision_composer_json'],
261+
$download_url,
262+
$contrib_url
263+
);
264+
}
265+
258266
unset($batch[$contrib_id][$index]);
259267
}
260268

@@ -266,15 +274,18 @@ public function run($from_file = false, $force = false, $progress = null)
266274
if (($group_count % 50) === 0)
267275
{
268276
$this->dump_include($last_type, $group, $packages);
277+
$this->dump_include($last_type, $group, $packages_phpbb4_only, ext::TITANIA_REPOSITORY_MIN_PHPBB_BRANCH);
269278
$group_count = 0;
270279
$group++;
271280
$packages = array();
281+
$packages_phpbb4_only = array();
272282
}
273283
$group_count++;
274284
}
275285
if (!empty($packages))
276286
{
277287
$this->dump_include($last_type, $group, $packages);
288+
$this->dump_include($last_type, $group, $packages_phpbb4_only, ext::TITANIA_REPOSITORY_MIN_PHPBB_BRANCH);
278289
}
279290

280291
$next_batch = $this->limit ? $this->start + $this->limit : $this->get_total();
@@ -297,11 +308,13 @@ public function run($from_file = false, $force = false, $progress = null)
297308
* @param string $type Contrib type name
298309
* @param int $group Group id
299310
* @param array $packages Packages
311+
* @param string $suffix Optional suffix for filename
300312
*/
301-
protected function dump_include($type, $group, array $packages)
313+
protected function dump_include($type, $group, array $packages, $prefix = '')
302314
{
303315
$type_name = $this->types->get($type)->name;
304-
$this->repo->dump_include("packages-$type_name-$group.json", $packages);
316+
$filename = $prefix ? "packages-$prefix-$type_name-$group.json" : "packages-$type_name-$group.json";
317+
$this->repo->dump_include($filename, $packages);
305318
}
306319

307320
/**

0 commit comments

Comments
 (0)