diff --git a/composer/repository.php b/composer/repository.php index 953b44d50..2745379c7 100644 --- a/composer/repository.php +++ b/composer/repository.php @@ -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; @@ -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; } @@ -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) { @@ -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); } @@ -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) { @@ -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); @@ -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); } } diff --git a/config/routes/general.yml b/config/routes/general.yml index 3b9c76178..3734c1ed2 100644 --- a/config/routes/general.yml +++ b/config/routes/general.yml @@ -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 } diff --git a/controller/composer.php b/controller/composer.php index 7555567be..e73a2f58e 100644 --- a/controller/composer.php +++ b/controller/composer.php @@ -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) { diff --git a/ext.php b/ext.php index ff5d36f2f..389805fe8 100644 --- a/ext.php +++ b/ext.php @@ -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]; + } } diff --git a/manage/tool/composer/rebuild_repo.php b/manage/tool/composer/rebuild_repo.php index de6783170..d27f82d2f 100644 --- a/manage/tool/composer/rebuild_repo.php +++ b/manage/tool/composer/rebuild_repo.php @@ -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 { @@ -57,6 +56,9 @@ class rebuild_repo extends base /** @var string */ protected $revisions_table; + /** @var string */ + protected $revisions_phpbb_table; + /** @var int */ protected $total; @@ -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'; } /** @@ -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 . ' @@ -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) { @@ -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]); } @@ -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(); @@ -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(); @@ -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); } /**