Skip to content

Commit 246fe71

Browse files
Merge pull request #226 from creative-commoners/pulls/6/docs-site
DOC Prepare for docs site
2 parents 7548504 + d692976 commit 246fe71

File tree

4 files changed

+212
-179
lines changed

4 files changed

+212
-179
lines changed

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"symbiote/silverstripe-queuedjobs": "^6",
3535
"squizlabs/php_codesniffer": "^3.7",
3636
"silverstripe/standards": "^1",
37+
"silverstripe/documentation-lint": "^1",
3738
"phpstan/extension-installer": "^1.3"
3839
},
3940
"extra": {
@@ -49,5 +50,10 @@
4950
}
5051
},
5152
"minimum-stability": "dev",
52-
"prefer-stable": true
53+
"prefer-stable": true,
54+
"config": {
55+
"allow-plugins": {
56+
"dealerdirect/phpcodesniffer-composer-installer": true
57+
}
58+
}
5359
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: External Broken Links Report
3+
summary: Features of the external broken links report in SilverStripe, how it works, and configuration options
4+
icon: unlink
5+
---
6+
7+
# External broken links report
8+
9+
## Features
10+
11+
- Add external links to broken links reports
12+
- Add a task to track external broken links
13+
14+
## Report
15+
16+
A new report is added called 'External Broken links report'. When viewing this report, a user may press
17+
the "Create new report" button which will trigger an ajax request to initiate a report run.
18+
19+
In this initial ajax request this module will do one of two things, depending on which modules are included:
20+
21+
- If the queuedjobs module is installed, a new queued job will be initiated. The queuedjobs module will then manage the progress of the task.
22+
- If the queuedjobs module is absent, then the controller will fallback to running a buildtask in the background. This is less robust, as a failure or error during this process will abort the run.
23+
24+
In either case, the background task will loop over every page in the system, inspecting all external urls and
25+
checking the status code returned by requesting each one. If a URL returns a response code that is considered
26+
"broken" (defined as < 200 or > 302) then the `ss-broken` css class will be assigned to that url, and
27+
a line item will be added to the report. If a previously broken link has been corrected or fixed, then
28+
this class is removed.
29+
30+
In the actual report generated the user can click on any broken link item to either view the link in their browser,
31+
or edit the containing page in the CMS.
32+
33+
While a report is running the current status of this report will be displayed on the report details page, along
34+
with the status. The user may leave this page and return to it later to view the ongoing status of this report.
35+
36+
Any subsequent report may not be generated until a prior report has completed.
37+
38+
## Dev task
39+
40+
Run `sake tasks:CheckExternalLinksTask` to check your site for external
41+
broken links.
42+
43+
## Queued job
44+
45+
If you have the queuedjobs module installed you can set the task to be run every so often.
46+
47+
## Whitelisting codes
48+
49+
If you want to ignore or whitelist certain HTTP codes this can be setup via `ignore_codes` in the config.yml
50+
file in `app/_config`:
51+
52+
```yml
53+
SilverStripe\Reports\ExternalLinks\Tasks\CheckExternalLinksTask:
54+
ignore_codes:
55+
- 401
56+
- 403
57+
- 501
58+
```
59+
60+
## Follow 301 redirects
61+
62+
You may want to follow a redirected URL a example of this would be redirecting from http to https
63+
can give you a false poitive as the http code of 301 will be returned which will be classed
64+
as a working link.
65+
66+
To allow redirects to be followed setup the following config in your config.yml
67+
68+
```yml
69+
# Follow 301 redirects
70+
SilverStripe\Reports\ExternalLinks\Tasks\CurlLinkChecker:
71+
follow_location: 1
72+
```
73+
74+
## Bypass cache
75+
76+
By default the task will attempt to cache any results the cache can be bypassed with the
77+
following config in config.yml.
78+
79+
```yml
80+
# Bypass SS_Cache
81+
SilverStripe\Reports\ExternalLinks\Tasks\CurlLinkChecker::
82+
bypass_cache: 1
83+
```
84+
85+
## Headers
86+
87+
You may want to set headers to be sent with the CURL request (eg: user-agent) to avoid website rejecting the request thinking it is a bot.
88+
You can set them with the following config in config.yml.
89+
90+
```yml
91+
# Headers
92+
SilverStripe\Reports\ExternalLinks\Tasks\CurlLinkChecker:
93+
headers:
94+
- 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0'
95+
- 'accept-encoding: gzip, deflate, br'
96+
- 'referer: https://www.domain.com/'
97+
- 'sec-fetch-mode: navigate'
98+
...
99+
```
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Site-Wide Content Report
3+
summary: Customizing the columns of the site-wide Content Report and improvoing performance of large datasets
4+
icon: file-alt
5+
---
6+
7+
# Site-wide content report
8+
9+
## Customising the report
10+
11+
In order to customise the columns included in a report you can build a custom extension and apply it to the
12+
SitewideContentReport as necessary.
13+
14+
The built in [`SitewideContentTaxonomy`](api:SilverStripe\Reports\SiteWideContentReport\Extensions\SitewideContentTaxonomy) extension, for instance, adds a custom columns extracted from the [`Taxonomies`](https://docs.silverstripe.org/en/optional_features/taxonomies/) module, and can be used as a base for developing further extensions:
15+
16+
For instance, in order to add a new Page field to the report you could add an extension similar to the below:
17+
18+
```php
19+
namespace App\Extensions;
20+
21+
use SilverStripe\Core\Extension;
22+
use SilverStripe\Reports\SiteWideContentReport\Reports\SiteWideContentReport;
23+
24+
class MyReportExtension extends Extension
25+
{
26+
protected function updateColumns($itemType, &$columns)
27+
{
28+
if($itemType !== 'Pages') {
29+
return;
30+
}
31+
$columns["Price"] = [
32+
"title" => _t(SitewideContentReport::class . ".Price", "Price"),
33+
"formatting" => function ($value, $item) use ($mainSiteLabel) {
34+
return number_format($value, 2, '.', ',');
35+
},
36+
];
37+
}
38+
}
39+
```
40+
41+
The `$columns` array can have any number of items added, where the key of the array represents the
42+
field name to be included.
43+
44+
Each item can be either a literal string (which will be used as the title), or an array that may contain
45+
the following key => value pairs:
46+
47+
* `title`: The title to use for the column header
48+
* `format`: A method callback which will take the raw value and original object, and return a formatted
49+
string.
50+
* `datasource`: If the value for this column isn't a direct field on the original object, a custom callback
51+
can be set here. Unlike `format` this callback will only take a single parameter, the original object.
52+
* `printonly`: Set to true if this column is only visible on the print or export-to-csv views.
53+
* `casting`: Specify a field type (e.g. `Text` or `Int`) in order to assist with field casting. This is not
54+
necessary if `formatting` is used.
55+
56+
## Performance considerations
57+
58+
### Large data sets
59+
60+
If your project has a large number of pages or files, you may experience server timeouts while trying to export
61+
this report to CSV. To avoid this issue, you can either increase your server timeout limit, or you can install
62+
and configure the [silverstripe/gridfieldqueuedexport module](https://github.com/silverstripe/silverstripe-gridfieldqueuedexport)
63+
which allows for CSV generation to offloaded to a queued job in the background.
64+
65+
An example of configuring this module in your project:
66+
67+
```php
68+
namespace App\Extensions;
69+
70+
use SilverStripe\Core\Extension;
71+
use SilverStripe\Forms\GridField\GridFieldComponent;
72+
use SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButton;
73+
74+
class SitewideContentReportQueuedExportExtension extends Extension
75+
{
76+
protected function updateExportButton(GridFieldComponent &$exportButton)
77+
{
78+
$exportButton = GridFieldQueuedExportButton::create('buttons-after-left');
79+
}
80+
}
81+
```
82+
83+
Apply the example Extension above with YAML configuration in your project:
84+
85+
```yml
86+
---
87+
Name: queuedsitewidecontentreport
88+
---
89+
SilverStripe\Reports\SitewideContentReport\Reports\SitewideContentReport:
90+
extensions:
91+
- 'App\Extensions\SitewideContentReportQueuedExportExtension'
92+
```
93+

0 commit comments

Comments
 (0)