Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Address archive-open error handling, default TSV format normalization, and download-label translations.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (3)
What changed in this PR
Adds permission-protected CSV/TSV statistics exports packaged in a ZIP archive, with routing, UI controls, CSV encoding, and utility enhancements.
Changes:
- Added the statistics download endpoint and route.
- Added CSV/TSV encoding and ZIP generation.
- Added download controls and customizable chart labels.
- Added an element-wise array utility.
| File | Description |
|---|---|
panel/views/statistics/index.php |
Adds CSV/TSV download controls |
panel/config/routes/routes.php |
Registers the download route |
formwork/src/Utils/Arr.php |
Adds array zipping |
formwork/src/Statistics/Statistics.php |
Supports custom chart label formats |
formwork/src/Parsers/Csv.php |
Adds CSV/TSV parsing and encoding |
formwork/src/Panel/Controllers/StatisticsController.php |
Generates and serves statistics archives |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return $this->forward(ErrorsController::class, 'forbidden'); | ||
| } | ||
|
|
||
| $format = $routeParams->get('format', 'tsv'); |
| $file = FileSystem::joinPaths($this->config->getString('site.statistics.path'), sprintf('.export-%s.zip', FileSystem::randomName())); | ||
|
|
||
| $zipArchive = new ZipArchive(); | ||
| $zipArchive->open($file, ZipArchive::CREATE); |
Comment on lines
+13
to
+16
| <button type="button" class="button button-accent dropdown-button caret" data-dropdown="dropdown-statistics-download"><?= $this->icon('cloud-download') ?> Download</button> | ||
| <div class="dropdown-menu" id="dropdown-statistics-download"> | ||
| <a class="dropdown-item" href="<?= $panel->uri('/statistics/download/tsv/') ?>">Download TSV</a> | ||
| <a class="dropdown-item" href="<?= $panel->uri('/statistics/download/csv/') ?>">Download CSV</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This pull request introduces a new feature that allows users with the appropriate permission to export site statistics as CSV or TSV files. It adds a download endpoint, a CSV parser/encoder, and UI enhancements to support downloading statistics, as well as utility improvements for array handling.
New statistics export functionality:
downloadaction toStatisticsControllerthat exports statistics data (devices, page views, sources, visits) as CSV or TSV files bundled in a ZIP archive, with permission checks and automatic file cleanup. (formwork/src/Panel/Controllers/StatisticsController.php, formwork/src/Panel/Controllers/StatisticsController.phpR46-R95)panel.statistics.downloadfor the download endpoint, supporting both CSV and TSV formats. (panel/config/routes/routes.php, panel/config/routes/routes.phpR177-R184)panel/views/statistics/index.php, panel/views/statistics/index.phpR4-R21)Core and utility enhancements:
Csvparser/encoder class supporting customizable separators and enclosures, used for encoding statistics data. (formwork/src/Parsers/Csv.php, formwork/src/Parsers/Csv.phpR1-R119)Arr::ziputility method to combine multiple arrays element-wise, used for preparing tabular data for export. (formwork/src/Utils/Arr.php, formwork/src/Utils/Arr.phpR830-R865)Statistics::getChartDatamethod to accept a customizable label format for chart data export. (formwork/src/Statistics/Statistics.php, [1] [2]These changes enable convenient, permission-protected export of site statistics for further analysis or reporting.