Skip to content

Commit 82134a1

Browse files
committed
Silverstripe v6 support
1 parent f966b61 commit 82134a1

File tree

6 files changed

+76
-113
lines changed

6 files changed

+76
-113
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ method.
246246

247247
## Fluent support
248248

249-
It is my intention to support Fluent and exporting Localised fields in the future, but at this time, there is no
250-
support provided.
249+
I would like to add Fluent support, but realistically, I don't have the time to do so at the moment. If anyone has the
250+
capacity to add Fluent support, I would be happy to review and merge a PR for that.
251251

252252
## Future features
253253

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"issues": "https://github.com/chrispenny/silverstripe-dataobject-to-fixture/issues"
1717
},
1818
"require": {
19-
"php": "^8.1",
20-
"silverstripe/framework": "^5",
21-
"silverstripe/cms": "^5"
19+
"php": "^8.3",
20+
"silverstripe/framework": "^6",
21+
"silverstripe/cms": "^6"
2222
},
2323
"require-dev": {
24-
"silverstripe/recipe-testing": "^3",
24+
"silverstripe/recipe-testing": "^4",
2525
"slevomat/coding-standard": "^8"
2626
},
2727
"autoload": {

phpunit.xml.dist

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
2-
<testsuite name="Default">
3-
<directory>tests/</directory>
4-
</testsuite>
5-
<filter>
6-
<whitelist processUncoveredFilesFromWhitelist="true">
2+
<testsuites>
3+
<testsuite name="Default">
4+
<directory>tests/</directory>
5+
</testsuite>
6+
</testsuites>
7+
<source>
8+
<include>
79
<directory suffix=".php">src/</directory>
8-
<exclude>
9-
<directory suffix=".php">tests/</directory>
10-
</exclude>
11-
</whitelist>
12-
</filter>
10+
</include>
11+
<exclude>
12+
<directory suffix=".php">tests/</directory>
13+
</exclude>
14+
</source>
1315
</phpunit>

src/Helper/FluentHelper.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/Task/GenerateFixtureFromDataObject.php

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
use ChrisPenny\DataObjectToFixture\Service\FixtureService;
66
use Exception;
7-
use SilverStripe\Control\HTTPRequest;
87
use SilverStripe\Core\ClassInfo;
98
use SilverStripe\Core\Config\Config;
109
use SilverStripe\Dev\BuildTask;
10+
use SilverStripe\Model\List\PaginatedList;
1111
use SilverStripe\ORM\DataObject;
12-
use SilverStripe\ORM\PaginatedList;
12+
use SilverStripe\PolyExecution\PolyOutput;
13+
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Input\InputOption;
1316
use Throwable;
1417

1518
/**
@@ -18,42 +21,38 @@
1821
class GenerateFixtureFromDataObject extends BuildTask
1922
{
2023

21-
protected $title = 'Generate Fixture From DataObject'; // phpcs:ignore
24+
protected static string $commandName = 'generate-fixture-from-dataobject';
2225

23-
protected $description = 'Generate a text fixture from a DataObject in your Database'; // phpcs:ignore
26+
protected string $title = 'Generate Fixture From DataObject';
2427

25-
private static string $segment = 'generate-fixture-from-dataobject'; // phpcs:ignore
28+
protected static string $description = 'Generate a text fixture from a DataObject in your Database';
2629

2730
private ?int $previousExecution = null;
2831

29-
/**
30-
* @param HTTPRequest|mixed $request
31-
* @throws Exception
32-
*/
33-
public function run($request): void // phpcs:ignore
32+
protected function execute(InputInterface $input, PolyOutput $output): int
3433
{
3534
try {
3635
$this->previousExecution = ini_get('max_execution_time');
3736
ini_set('max_execution_time', 60);
3837

3938
$this->outputStyles();
4039

41-
$className = $request->getVar('ClassName');
42-
$id = $request->getVar('ID');
40+
$className = $input->getOption('ClassName');
41+
$id = $input->getOption('ID');
4342

4443
// We have both a ClassName and ID, which means we can render out the fixture for a particular record
4544
if ($className && $id) {
46-
$this->outputFixture($request, $className, (int)$id);
45+
$this->outputFixture($className, (int) $id);
4746

48-
return;
47+
return Command::SUCCESS;
4948
}
5049

5150
// We have a ClassName, but not ID yet, this means the user needs to be provided with a list of available
5251
// records for that particular class
5352
if ($className) {
54-
$this->outputClassForm($request, $className);
53+
$this->outputClassForm($input, $className);
5554

56-
return;
55+
return Command::SUCCESS;
5756
}
5857

5958
// The initial form is a list of available classes
@@ -62,6 +61,8 @@ public function run($request): void // phpcs:ignore
6261
throw $e;
6362
} finally {
6463
ini_set('max_execution_time', $this->previousExecution);
64+
65+
return Command::SUCCESS;
6566
}
6667
}
6768

@@ -100,10 +101,10 @@ protected function outputInitialForm(): void
100101
echo '</form>';
101102
}
102103

103-
protected function outputClassForm(HTTPRequest $request, string $className): void
104+
protected function outputClassForm(InputInterface $input, string $className): void
104105
{
105106
$dbFields = Config::inst()->get($className, 'db');
106-
$start = $request->getVar('start') ?? 0;
107+
$start = $input->getOption('start') ?? 0;
107108

108109
/** @var PaginatedList|DataObject[] $paginatedList */
109110
$paginatedList = PaginatedList::create($className::get());
@@ -117,7 +118,10 @@ protected function outputClassForm(HTTPRequest $request, string $className): voi
117118
return;
118119
}
119120

120-
echo '<p><a href="/dev/tasks/generate-fixture-from-dataobject">< Back to the beginning</a></p>';
121+
echo sprintf(
122+
'<p><a href="/dev/tasks/%s">< Back to the beginning</a></p>',
123+
self::$commandName
124+
);
121125

122126
echo '<div class="pagination">';
123127
echo '<p><strong>Pagination:</strong></p>';
@@ -149,7 +153,7 @@ protected function outputClassForm(HTTPRequest $request, string $className): voi
149153

150154
// Remove Datatime and Boolean fields, as they're (likely) not that useful for trying to find a specific record
151155
$dbFields = array_diff($dbFields, ['Datetime', 'Boolean']);
152-
$linkTemplate = '<td><a href="/dev/tasks/generate-fixture-from-dataobject?ClassName=%s&ID=%s">Link</a></td>';
156+
$linkTemplate = '<td><a href="/dev/tasks/%s?ClassName=%s&ID=%s">Link</a></td>';
153157

154158
echo '<table>';
155159
echo '<thead>';
@@ -168,7 +172,7 @@ protected function outputClassForm(HTTPRequest $request, string $className): voi
168172

169173
foreach ($paginatedList as $dataObject) {
170174
echo '<tr>';
171-
echo sprintf($linkTemplate, $className, $dataObject->ID);
175+
echo sprintf($linkTemplate, self::$commandName, $className, $dataObject->ID);
172176
echo sprintf('<td>%s</td>', $dataObject->ID);
173177

174178
foreach (array_keys($dbFields) as $fieldName) {
@@ -184,12 +188,9 @@ protected function outputClassForm(HTTPRequest $request, string $className): voi
184188
}
185189

186190
/**
187-
* @param HTTPRequest $request
188-
* @param string $className
189-
* @param int $id
190191
* @throws Exception
191192
*/
192-
protected function outputFixture(HTTPRequest $request, string $className, int $id): void
193+
protected function outputFixture(string $className, int $id): void
193194
{
194195
if (!$className) {
195196
echo '<p>No ClassName provided</p>';
@@ -208,6 +209,11 @@ protected function outputFixture(HTTPRequest $request, string $className, int $i
208209

209210
if ($dataObject === null) {
210211
echo sprintf('<p>DataObject not found. ClassName: %s, ID: %s</p>', $className, $id);
212+
echo sprintf(
213+
'<p><a href="/dev/tasks/%s?ClassName=%s">< Back to list of records</a></p>',
214+
self::$commandName,
215+
$className
216+
);
211217

212218
return;
213219
}
@@ -220,7 +226,8 @@ protected function outputFixture(HTTPRequest $request, string $className, int $i
220226
}
221227

222228
echo sprintf(
223-
'<p><a href="/dev/tasks/generate-fixture-from-dataobject?ClassName=%s">< Back to list of records</a></p>',
229+
'<p><a href="/dev/tasks/%s?ClassName=%s">< Back to list of records</a></p>',
230+
self::$commandName,
224231
$className
225232
);
226233

@@ -348,4 +355,28 @@ protected function outputStyles(): void
348355
echo '</style>';
349356
}
350357

358+
public function getOptions(): array
359+
{
360+
return [
361+
new InputOption(
362+
'ClassName',
363+
null,
364+
InputOption::VALUE_OPTIONAL,
365+
'Specify class of the DataObject to be exported'
366+
),
367+
new InputOption(
368+
'ID',
369+
null,
370+
InputOption::VALUE_OPTIONAL,
371+
'Specify the ID of the DataObject to be exported'
372+
),
373+
new InputOption(
374+
'start',
375+
null,
376+
InputOption::VALUE_OPTIONAL,
377+
'Pagination value'
378+
),
379+
];
380+
}
381+
351382
}

tests/Mocks/Pages/MockNativePoly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use SilverStripe\ORM\DataObject;
77

88
/**
9-
* Uses the Silverstripe 5 array-format polymorphic has_one definition.
9+
* Uses the Silverstripe array-format polymorphic has_one definition.
1010
*
1111
* @property string $Title
1212
* @property int $OwnerID

0 commit comments

Comments
 (0)