silverstripe-frameworktest/code/tasks/FTPageMakerTask.php

54 lines
1.2 KiB
PHP
Raw Normal View History

2012-02-29 15:49:37 +01:00
<?php
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
{
/**
* Defaults create 2,000 pages
*/
protected $pageCountByDepth = [
5,
100,
1,
1,
1
];
2012-02-29 15:49:37 +01:00
2015-12-17 21:20:49 +01:00
public function run($request)
{
$this->generatePages();
2015-12-17 21:20:49 +01:00
}
protected function generatePages($depth = 0, $prefix = "", $parentID = 0)
2015-12-17 21:20:49 +01: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;
$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
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
}
}
}
2015-12-17 21:20:49 +01:00
}