2008-10-16 14:21:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tasks
|
|
|
|
*/
|
2008-11-10 02:45:35 +01:00
|
|
|
class SiteTreeMaintenanceTask extends Controller {
|
2008-10-16 14:21:30 +02:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'*' => 'ADMIN'
|
|
|
|
);
|
|
|
|
|
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()) . "'";
|
2008-11-24 10:30:41 +01:00
|
|
|
$pages = DataObject::get("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(
|
|
|
|
'SiteTree.LINKSCHANGEDTO',
|
|
|
|
" changed {url1} -> {url2}",
|
|
|
|
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(
|
|
|
|
'SiteTree.LINKSALREADYUNIQUE',
|
|
|
|
" {url} is already unique",
|
|
|
|
array('url' => $urlSegment)
|
|
|
|
);
|
2008-10-16 14:21:30 +02:00
|
|
|
}
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|