2008-10-16 14:21:30 +02:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\DB;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
|
2008-10-16 14:21:30 +02:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tasks
|
|
|
|
*/
|
2008-11-10 02:45:35 +01:00
|
|
|
class SiteTreeMaintenanceTask extends Controller {
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_actions = array(
|
2008-10-16 14:21:30 +02:00
|
|
|
'*' => 'ADMIN'
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function makelinksunique() {
|
2008-10-16 14:21:30 +02:00
|
|
|
$badURLs = "'" . implode("', '", DB::query("SELECT URLSegment, count(*) FROM SiteTree GROUP BY URLSegment HAVING count(*) > 1")->column()) . "'";
|
2013-08-29 03:59:45 +02:00
|
|
|
$pages = DataObject::get("SiteTree", "\"SiteTree\".\"URLSegment\" IN ($badURLs)");
|
2008-10-16 14:21:30 +02:00
|
|
|
|
|
|
|
foreach($pages as $page) {
|
|
|
|
echo "<li>$page->Title: ";
|
|
|
|
$urlSegment = $page->URLSegment;
|
|
|
|
$page->write();
|
|
|
|
if($urlSegment != $page->URLSegment) {
|
2012-12-21 11:18:18 +01:00
|
|
|
echo _t(
|
2016-01-06 00:42:07 +01:00
|
|
|
'SiteTree.LINKSCHANGEDTO',
|
|
|
|
" changed {url1} -> {url2}",
|
2012-12-21 11:18:18 +01:00
|
|
|
array('url1' => $urlSegment, 'url2' => $page->URLSegment)
|
|
|
|
);
|
2008-10-16 14:21:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-12-21 11:18:18 +01:00
|
|
|
echo _t(
|
2016-01-06 00:42:07 +01:00
|
|
|
'SiteTree.LINKSALREADYUNIQUE',
|
2012-12-21 11:18:18 +01:00
|
|
|
" {url} is already unique",
|
|
|
|
array('url' => $urlSegment)
|
|
|
|
);
|
2008-10-16 14:21:30 +02:00
|
|
|
}
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|