Skip to content

Commit 14e8188

Browse files
committed
Merge branch '2.9' into 2.10
2 parents 57e38bf + 35b7f70 commit 14e8188

5 files changed

Lines changed: 84 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
# Every Monday at 12:10pm UTC
8+
schedule:
9+
- cron: '10 12 * * 1'
10+
11+
jobs:
12+
ci:
13+
name: CI
14+
# Only run cron on the silverstripe account
15+
if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule')
16+
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1

.github/workflows/keepalive.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Keepalive
2+
3+
on:
4+
workflow_dispatch:
5+
# The 4th of every month at 10:50am UTC
6+
schedule:
7+
- cron: '50 10 4 * *'
8+
9+
jobs:
10+
keepalive:
11+
name: Keepalive
12+
# Only run cron on the silverstripe account
13+
if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule')
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Keepalive
17+
uses: silverstripe/gha-keepalive@v1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CWP features modules
22

3-
[![Build Status](https://api.travis-ci.com/silverstripe/cwp.svg?branch=2)](https://travis-ci.com/silverstripe/cwp)
3+
[![CI](https://github.com/silverstripe/cwp/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/cwp/actions/workflows/ci.yml)
44
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/silverstripe/cwp/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/cwp/?branch=master)
55
[![codecov](https://codecov.io/gh/silverstripe/cwp/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/cwp)
66
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^9.5",
20-
"squizlabs/php_codesniffer": "^3"
20+
"squizlabs/php_codesniffer": "^3",
21+
"cwp/starter-theme": "^2"
22+
},
23+
"conflict": {
24+
"silverstripe/auditor": "<2.2.1"
2125
},
2226
"suggest": {
2327
"silverstripe/crontask": "Allows CWP cleanup tasks to be scheduled"

src/PageTypes/DatedUpdateHolder.php

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
use DateTime;
66
use Page;
77
use SilverStripe\CMS\Model\SiteTree;
8+
use SilverStripe\Control\Controller;
89
use SilverStripe\Control\Director;
910
use SilverStripe\Control\HTTP;
1011
use SilverStripe\Core\Config\Config;
1112
use SilverStripe\Core\Convert;
1213
use SilverStripe\ORM\ArrayList;
14+
use SilverStripe\ORM\Connect\DatabaseException;
1315
use SilverStripe\ORM\DataList;
1416
use SilverStripe\ORM\DataObject;
1517
use SilverStripe\ORM\PaginatedList;
@@ -146,6 +148,15 @@ public static function AllUpdates(
146148
));
147149
}
148150

151+
try {
152+
// Try running query inside try/catch block to handle any invalid date format
153+
$items->dataQuery()->execute();
154+
} catch (DatabaseException $e) {
155+
self::handleInvalidDateFormat($e);
156+
// Ensure invalid SQL does not get run again
157+
$items = $className::get()->limit(0);
158+
}
159+
149160
// Unpaginated DataList.
150161
return $items;
151162
}
@@ -185,20 +196,25 @@ public static function ExtractMonths(
185196
$link = Director::makeRelative($_SERVER['REQUEST_URI']);
186197
}
187198

188-
$dates = $updates->dataQuery()
189-
->groupby('YEAR("Date")')
190-
->groupby('MONTH("Date")')
191-
->query()
192-
->setSelect([
193-
'Year' => 'YEAR("Date")',
194-
'Month' => 'MONTH("Date")',
195-
])
196-
->addWhere('"Date" IS NOT NULL')
197-
->setOrderBy([
198-
'YEAR("Date")' => 'DESC',
199-
'MONTH("Date")' => 'DESC',
200-
])
201-
->execute();
199+
$dates = [];
200+
try {
201+
$dates = $updates->dataQuery()
202+
->groupby('YEAR("Date")')
203+
->groupby('MONTH("Date")')
204+
->query()
205+
->setSelect([
206+
'Year' => 'YEAR("Date")',
207+
'Month' => 'MONTH("Date")',
208+
])
209+
->addWhere('"Date" IS NOT NULL')
210+
->setOrderBy([
211+
'YEAR("Date")' => 'DESC',
212+
'MONTH("Date")' => 'DESC',
213+
])
214+
->execute();
215+
} catch (DatabaseException $e) {
216+
self::handleInvalidDateFormat($e);
217+
}
202218

203219
$years = [];
204220
foreach ($dates as $date) {
@@ -260,4 +276,19 @@ public function getSubscriptionTitle()
260276
{
261277
return $this->Title;
262278
}
279+
280+
private static function handleInvalidDateFormat(DatabaseException $e): void
281+
{
282+
$controller = Controller::curr();
283+
if ($controller instanceof DatedUpdateHolderController &&
284+
strpos($e->getMessage(), 'Incorrect DATETIME value') !== false
285+
) {
286+
$controller->getRequest()->getSession()->set(DatedUpdateHolderController::TEMP_FORM_MESSAGE, _t(
287+
DatedUpdateHolderController::class . '.InvalidDateFormat',
288+
'Dates must be in "y-MM-dd" format.'
289+
));
290+
} else {
291+
throw $e;
292+
}
293+
}
263294
}

0 commit comments

Comments
 (0)