Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions composer/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use phpbb\config\config;
use phpbb\exception\runtime_exception;
use phpbb\titania\ext;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;

Expand Down Expand Up @@ -63,6 +64,13 @@ public function prepare_build_dir($force)
}
$this->fs->mkdir($this->build_dir);

// Create filtered repository subdirectories
$branches = ext::get_filtered_repository_branches();
foreach ($branches as $branch)
{
$this->fs->mkdir($this->build_dir . $branch);
}

return $this;
}

Expand Down Expand Up @@ -152,8 +160,9 @@ public function set_release(array $packages, $composer_json, $download_url, $con
*
* @param string $name File name
* @param array $packages Packages to be dumped
* @param string $subdir Optional subdirectory
*/
public function dump_include($name, array $packages)
public function dump_include($name, array $packages, $subdir = '')
{
foreach ($packages as $package_name => $versions)
{
Expand All @@ -163,7 +172,8 @@ public function dump_include($name, array $packages)
array('packages' => $packages),
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
);
$file = $this->build_dir . $name;
$target_dir = $this->build_dir . $subdir;
$file = $target_dir . $name;
$this->fs->dumpFile($file, $packages);
}

Expand All @@ -189,9 +199,25 @@ protected function get_include_files()
* Build include file parents included package.json
*/
protected function build_parents()
{
$this->build_parent_structure();
$branches = ext::get_filtered_repository_branches();
foreach ($branches as $branch)
{
$this->build_parent_structure($branch . '/');
}
}

/**
* Build parent structure for given subdirectory
*
* @param string $subdir Optional subdirectory
*/
protected function build_parent_structure($subdir = '')
{
$includes = $this->get_include_files();
$parent = $types = array();
$target_dir = $this->build_dir . $subdir;

foreach ($includes as $file)
{
Expand All @@ -212,7 +238,7 @@ protected function build_parents()
foreach ($types as $type => $includes)
{
$type_filename = 'packages-' . $type . '.json';
$type_filepath = $this->build_dir . $type_filename;
$type_filepath = $target_dir . $type_filename;
$contents = json_encode(array('includes' => $includes));
$this->fs->dumpFile($type_filepath, $contents);

Expand All @@ -223,7 +249,7 @@ protected function build_parents()
if (!empty($parent))
{
$contents = json_encode(array('includes' => $parent));
$this->fs->dumpFile($this->build_dir . 'packages.json', $contents);
$this->fs->dumpFile($target_dir . 'packages.json', $contents);
}
}

Expand Down
8 changes: 8 additions & 0 deletions config/routes/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ phpbb.titania.contribution.id:
requirements:
id: \d+

phpbb.titania.composer.40.files:
path: /composer/40/{filename}.json
defaults: { _controller: phpbb.titania.controller.composer:serve_file, subdirectory: '40/' }

phpbb.titania.composer.40:
path: /composer/40/
defaults: { _controller: phpbb.titania.controller.composer:serve_file, filename: packages, subdirectory: '40/' }

phpbb.titania.composer:
path: /composer/{filename}.json
defaults: { _controller: phpbb.titania.controller.composer:serve_file }
Expand Down
9 changes: 5 additions & 4 deletions controller/composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,21 @@ public function __construct(\phpbb\user $user, \phpbb\titania\controller\helper
* Serve composer's files.
*
* @param string $filename Filename to serve (without extension)
* @param string $subdirectory Optional subdirectory
* @return \Symfony\Component\HttpFoundation\Response
*/
public function serve_file($filename)
public function serve_file($filename, $subdirectory = '')
{
if (strpos($filename, '..') !== false)
if (strpos($filename, '..') !== false || strpos($subdirectory, '..') !== false)
{
throw new http_exception(404, 'NO_PAGE_FOUND');
}

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

try
{
return new BinaryFileResponse($filename, 200);
return new BinaryFileResponse($filepath, 200);
}
catch (\Exception $e)
{
Expand Down
10 changes: 10 additions & 0 deletions ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,14 @@ class ext extends \phpbb\extension\base

// Misc
const TITANIA_CONFIG_PREFIX = 'titania_';

/**
* Get filtered repository branch versions
*
* @return array Array of branch numbers to create filtered repositories for
*/
public static function get_filtered_repository_branches(): array
{
return [40];
}
}
48 changes: 42 additions & 6 deletions manage/tool/composer/rebuild_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use phpbb\titania\ext;
use phpbb\titania\manage\tool\base;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Finder\SplFileInfo;

class rebuild_repo extends base
{
Expand Down Expand Up @@ -57,6 +56,9 @@ class rebuild_repo extends base
/** @var string */
protected $revisions_table;

/** @var string */
protected $revisions_phpbb_table;

/** @var int */
protected $total;

Expand Down Expand Up @@ -84,6 +86,7 @@ public function __construct(db_driver_interface $db, ext_config $ext_config, typ
$this->attachments_table = $table_prefix . 'attachments';
$this->contribs_table = $table_prefix . 'contribs';
$this->revisions_table = $table_prefix . 'revisions';
$this->revisions_phpbb_table = $table_prefix . 'revisions_phpbb';
}

/**
Expand Down Expand Up @@ -140,11 +143,13 @@ protected function get_batch($fetch_attach_data)
}

$sql = 'SELECT c.contrib_id, c.contrib_name_clean, c.contrib_type, r.revision_id,
r.attachment_id, r.revision_composer_json' . $attach_fields . '
r.attachment_id, r.revision_composer_json, rp.phpbb_version_branch' . $attach_fields . '
FROM ' . $this->contribs_table . ' c, ' .
$this->revisions_table . ' r ' .
$this->revisions_table . ' r, ' .
$this->revisions_phpbb_table . ' rp ' .
$attach_table . '
WHERE c.contrib_id = r.contrib_id ' .
WHERE c.contrib_id = r.contrib_id
AND r.revision_id = rp.revision_id ' .
$attach_where . '
AND c.contrib_status = ' . ext::TITANIA_CONTRIB_APPROVED . '
AND r.revision_status = ' . ext::TITANIA_REVISION_APPROVED . '
Expand Down Expand Up @@ -192,6 +197,12 @@ public function run($from_file = false, $force = false, $progress = null)

$last_type = $last_contrib = '';
$packages = array();
$filtered_packages = array();
$branches = ext::get_filtered_repository_branches();
foreach ($branches as $branch)
{
$filtered_packages[$branch] = array();
}

foreach ($batch as $contrib_id => $revisions)
{
Expand Down Expand Up @@ -246,6 +257,20 @@ public function run($from_file = false, $force = false, $progress = null)
$download_url,
$contrib_url
);

foreach ($filtered_packages as $branch => $packages_data)
{
if ($revision['phpbb_version_branch'] >= $branch)
{
$filtered_packages[$branch] = $this->repo->set_release(
$filtered_packages[$branch],
$revision['revision_composer_json'],
$download_url,
$contrib_url
);
}
}

unset($batch[$contrib_id][$index]);
}

Expand All @@ -257,6 +282,11 @@ public function run($from_file = false, $force = false, $progress = null)
if (($group_count % 50) === 0)
{
$this->dump_include($last_type, $group, $packages);
foreach ($filtered_packages as $branch => $packages_data)
{
$this->dump_include($last_type, $group, $packages_data, $branch);
$filtered_packages[$branch] = array();
}
$group_count = 0;
$group++;
$packages = array();
Expand All @@ -266,6 +296,10 @@ public function run($from_file = false, $force = false, $progress = null)
if (!empty($packages))
{
$this->dump_include($last_type, $group, $packages);
foreach ($filtered_packages as $branch => $packages_data)
{
$this->dump_include($last_type, $group, $packages_data, $branch);
}
}

$next_batch = $this->limit ? $this->start + $this->limit : $this->get_total();
Expand All @@ -288,11 +322,13 @@ public function run($from_file = false, $force = false, $progress = null)
* @param string $type Contrib type name
* @param int $group Group id
* @param array $packages Packages
* @param int $branch Optional branch number for subdirectory
*/
protected function dump_include($type, $group, array $packages)
protected function dump_include($type, $group, array $packages, $branch = null)
{
$type_name = $this->types->get($type)->name;
$this->repo->dump_include("packages-$type_name-$group.json", $packages);
$subdir = $branch ? $branch . '/' : '';
$this->repo->dump_include("packages-$type_name-$group.json", $packages, $subdir);
}

/**
Expand Down