Add counts to file task, update readme

This commit is contained in:
Aaron Carlino 2021-05-10 13:19:27 +12:00
parent e0d4faec11
commit f932f5e110
2 changed files with 52 additions and 5 deletions

View File

@ -29,6 +29,21 @@ If you want to test the CMS behaviour for a large and nested tree,
the module includes a simple generator task: `dev/tasks/FTPageMakerTask`.
It will create 3^5 pages by default, so takes a while to run through.
## Configuring the amount of data
Both `FTPageMagerTask` and `FTFileMakerTask` allow the amount of generated content to be configured.
To do this, pass a comma-seprarated list of integers representing the amount of records to create at each
depth.
`$ vendor/bin/sake dev/tasks/FTPageMakerTask pageCounts=10,200,5,5`
`$ vendor/bin/sake dev/tasks/FTFileMakerTask fileCounts=5,300,55,5 folderCounts=1,5,5,5`
## Guaranteed unique images
The `FTFileMakerTask` will randomly watermark each reference to your images by default. If you want to disable this,
set the `uniqueImages` config variable to `false`.
## Blocks
When [dnadesign/silverstripe-elemental](https://github.com/dnadesign/silverstripe-elemental)

View File

@ -185,6 +185,18 @@ class FTFileMakerTask extends BuildTask
/** @var Member */
protected $anonymousMember = null;
/**
* Allow override of the fileCountByDepth
* @var array
*/
protected $fileCounts = [];
/**
* Allow override of the folderCountByDepth
* @var array
*/
protected $folderCounts = [];
public function run($request)
{
set_time_limit(0);
@ -209,6 +221,26 @@ class FTFileMakerTask extends BuildTask
$this->reset();
}
$fileCounts = $request->getVar('fileCounts');
if ($fileCounts) {
$counts = explode(',', $fileCounts);
$this->fileCounts = array_map(function ($int) {
return (int) trim($int);
}, $counts);
} else {
$this->fileCounts = self::config()->get('fileCountByDepth');
}
$folderCounts = $request->getVar('folderCounts');
if ($folderCounts) {
$counts = explode(',', $folderCounts);
$this->folderCounts = array_map(function ($int) {
return (int) trim($int);
}, $counts);
} else {
$this->folderCounts = self::config()->get('folderCountByDepth');
}
echo "Downloading fixtures" . $this->lineBreak;
$fixtureFilePaths = $this->downloadFixtureFiles();
@ -302,8 +334,8 @@ class FTFileMakerTask extends BuildTask
protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $parentID = 0)
{
$folderCount = self::config()->get('folderCountByDepth')[$depth];
$fileCount = self::config()->get('fileCountByDepth')[$depth];
$folderCount = $this->folderCounts[$depth];
$fileCount = $this->fileCounts[$depth];
$doSetFolderPermissions = (bool) self::config()->get('doSetFolderPermissions');