Skip to content

Commit

Permalink
Merge pull request #68 from open-sausages/pulls/better-file-maker-def…
Browse files Browse the repository at this point in the history
…ault

Improve the file maker default and make the protected attribute configuration flags like they are menat to be
  • Loading branch information
emteknetnz authored Jun 17, 2020
2 parents fc7d419 + 04918fa commit 1af91b4
Showing 1 changed file with 75 additions and 36 deletions.
111 changes: 75 additions & 36 deletions code/tasks/FTFileMakerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@
* The following yml config make 1040 files / 520mb:
*
* To make 100K records, increase the base folderCountByDepth from 1 to 100 and run the task overnight
FTFileMakerTask:
documentsOnly: true
doSetFolderPermissions: true
doSetOldCreationDate: false
doRandomlyPublish: false
depth: 3
folderCountByDepth:
- 1
- 9
- 7
- 0
- 0
fileCountByDepth:
- 50
- 25
- 20
- 0
- 0
*
* ```
* FTFileMakerTask:
* documentsOnly: true
* doSetFolderPermissions: true
* doSetOldCreationDate: false
* doRandomlyPublish: false
* depth: 3
* folderCountByDepth:
* - 1
* - 9
* - 7
* - 0
* - 0
* fileCountByDepth:
* - 50
* - 25
* - 20
* - 0
* - 0
*
* Flush and run:
* /dev/tasks/FTFileMakerTask?flush&reset=1
Expand All @@ -62,31 +63,69 @@
*/
class FTFileMakerTask extends BuildTask
{
/**
* If set to TRUE skip thumbnail generation
* @var bool
* @config
*/
private static $documentsOnly = false;

protected $documentsOnly = false;

protected $doSetFolderPermissions = false;
/**
* Vary the permission on the folders
* @var bool
* @config
*/
private static $doSetFolderPermissions = true;

// simulate scenario where protected files were uploaded into the wrong asset store
protected $doPutProtectedFilesInPublicStore = false;
/**
* Put some files in wrong store to test logic meant to correct this kind of problem..
* @var bool
* @config
*/
private static $doPutProtectedFilesInPublicStore = false;

protected $doSetOldCreationDate = true;
/**
* Set the date of some files to an old date.
* @var bool
* @config
*/
private static $doSetOldCreationDate = true;

protected $doRandomlyPublish = true;
/**
* Publish some files.
* @var bool
* @config
*/
private static $doRandomlyPublish = true;

protected $depth = 2;
/**
* How deep should or folder hierachy be.
* @var int
* @config
*/
private static $depth = 2;

protected $folderCountByDepth = [
/**
* Number of folders to create certain hierachy.
* @var int[]
* @config
*/
private static $folderCountByDepth = [
0 => 2,
1 => 2,
2 => 2,
3 => 2,
4 => 2,
];

protected $fileCountByDepth = [
0 => 10,
1 => 8,
/**
* Number of files to create at various depths in the hierachy
* @var int[]
* @config
*/
private static $fileCountByDepth = [
0 => 100,
1 => 30,
2 => 5,
3 => 5,
4 => 5,
Expand Down Expand Up @@ -269,15 +308,15 @@ protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $
'Name' => "testfolder-{$prefix}{$i}",
]);
if ($doSetFolderPermissions) {
if ($i == 1) {
if ($i === 1) {
// the first folder should always be public to ensure there's some public folders
$folder->CanViewType = 'Inherit';
} elseif ($i == $folderCount) {
} elseif ($i === $folderCount) {
// the last folder should always be protected to ensure there's some protected folders
$folder->CanViewType = 'OnlyTheseUsers';
} else {
// all the other folder have a 33% chance of being a protected folder
$folder->CanViewType = rand(0, 2) == 0 ? 'OnlyTheseUsers' : 'Inherit';
$folder->CanViewType = rand(0, 2) === 0 ? 'OnlyTheseUsers' : 'Inherit';
}
}

Expand Down Expand Up @@ -306,7 +345,7 @@ protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $

// Randomly set old created date (for testing)
if ($doSetOldCreationDate) {
if (rand(0, 10) == 0) {
if (rand(0, 10) === 0) {
$file->Created = '2010-01-01 00:00:00';
$file->Title = '[old] ' . $file->Title;
}
Expand All @@ -315,7 +354,7 @@ protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $
$file->write();

if ($doRandomlyPublish) {
if (rand(0, 1) == 0) {
if (rand(0, 1) === 0) {
$file->publishFile();
}
} else {
Expand Down

0 comments on commit 1af91b4

Please sign in to comment.