2012-02-29 15:49:37 +01:00
|
|
|
<?php
|
2016-09-07 07:10:55 +02:00
|
|
|
|
|
|
|
use SilverStripe\Dev\BuildTask;
|
2017-11-28 23:45:42 +01:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
|
|
|
|
2012-02-29 15:49:37 +01:00
|
|
|
/**
|
|
|
|
* Creates sample page structure, useful to test tree performance,
|
|
|
|
* UI behaviour on deeply nested pages etc.
|
|
|
|
*
|
|
|
|
* @todo Allow passing in counts
|
|
|
|
*/
|
2015-12-17 21:20:49 +01:00
|
|
|
class FTPageMakerTask extends BuildTask
|
|
|
|
{
|
|
|
|
|
2017-05-18 03:20:53 +02:00
|
|
|
/**
|
2017-07-04 23:58:48 +02:00
|
|
|
* Defaults create 2,000 pages
|
2017-05-18 03:20:53 +02:00
|
|
|
*/
|
|
|
|
protected $pageCountByDepth = [
|
|
|
|
5,
|
2017-07-04 23:58:48 +02:00
|
|
|
100,
|
|
|
|
1,
|
2017-05-18 03:20:53 +02:00
|
|
|
1,
|
|
|
|
1
|
|
|
|
];
|
2012-02-29 15:49:37 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function run($request)
|
|
|
|
{
|
2017-05-18 03:20:53 +02:00
|
|
|
$this->generatePages();
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|
2017-05-18 03:20:53 +02:00
|
|
|
|
|
|
|
protected function generatePages($depth = 0, $prefix = "", $parentID = 0)
|
2015-12-17 21:20:49 +01:00
|
|
|
{
|
2017-05-18 03:20:53 +02:00
|
|
|
$maxDepth = count($this->pageCountByDepth);
|
|
|
|
$pageCount = $this->pageCountByDepth[$depth];
|
2017-11-28 23:45:42 +01:00
|
|
|
$testPageClasses = ClassInfo::implementorsOf('TestPageInterface');
|
|
|
|
$testPageClasses[] = 'Page';
|
2017-05-18 03:20:53 +02:00
|
|
|
|
|
|
|
for ($i=1; $i<=$pageCount; $i++) {
|
|
|
|
$fullPrefix = $prefix ? "{$prefix}-{$i}" : $i;
|
2017-11-28 23:45:42 +01:00
|
|
|
$randomIndex = array_rand($testPageClasses);
|
|
|
|
$pageClass = $testPageClasses[$randomIndex];
|
|
|
|
$page = new $pageClass();
|
2015-12-17 21:20:49 +01:00
|
|
|
$page->ParentID = $parentID;
|
2017-05-18 03:20:53 +02:00
|
|
|
$page->Title = "Test page {$fullPrefix}";
|
2015-12-17 21:20:49 +01:00
|
|
|
$page->write();
|
|
|
|
$page->publish('Stage', 'Live');
|
2012-02-29 15:49:37 +01:00
|
|
|
|
2017-11-28 23:45:42 +01:00
|
|
|
echo "Created '$page->Title' ($page->ClassName)\n";
|
2017-05-18 03:20:53 +02:00
|
|
|
|
|
|
|
$pageID = $page->ID;
|
|
|
|
unset($page);
|
|
|
|
|
|
|
|
if ($depth < $maxDepth-1) {
|
|
|
|
$this->generatePages($depth+1, $fullPrefix, $pageID);
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-18 03:20:53 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|