2012-02-29 15:49:37 +01:00
|
|
|
<?php
|
2016-09-07 07:10:55 +02:00
|
|
|
|
|
|
|
use SilverStripe\Dev\BuildTask;
|
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
|
|
|
/**
|
|
|
|
* Defaults create 15,000 pages
|
|
|
|
*/
|
|
|
|
protected $pageCountByDepth = [
|
|
|
|
10,
|
|
|
|
100,
|
|
|
|
5,
|
|
|
|
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];
|
|
|
|
|
|
|
|
for ($i=1; $i<=$pageCount; $i++) {
|
|
|
|
$fullPrefix = $prefix ? "{$prefix}-{$i}" : $i;
|
2015-12-17 21:20:49 +01:00
|
|
|
$page = new Page();
|
|
|
|
$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-05-18 03:20:53 +02:00
|
|
|
echo "Created '$page->Title'\n";
|
|
|
|
|
|
|
|
$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
|
|
|
}
|