2008-10-16 14:21:30 +02:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2016-08-10 06:08:39 +02:00
|
|
|
namespace SilverStripe\CMS\Tasks;
|
|
|
|
|
2019-05-17 03:40:15 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\DB;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class SiteTreeMaintenanceTask extends Controller
|
|
|
|
{
|
2020-04-19 06:18:01 +02:00
|
|
|
private static $allowed_actions = [
|
2017-01-25 21:59:25 +01:00
|
|
|
'*' => 'ADMIN'
|
2020-04-19 06:18:01 +02:00
|
|
|
];
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function makelinksunique()
|
|
|
|
{
|
2019-05-17 03:40:15 +02:00
|
|
|
$table = DataObject::singleton(SiteTree::class)->baseTable();
|
|
|
|
$badURLs = "'" . implode("', '", DB::query("SELECT \"URLSegment\", count(*) FROM \"$table\" GROUP BY \"URLSegment\" HAVING count(*) > 1")->column()) . "'";
|
|
|
|
$pages = DataObject::get(SiteTree::class, "\"$table\".\"URLSegment\" IN ($badURLs)");
|
2008-10-16 14:21:30 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
foreach ($pages as $page) {
|
|
|
|
echo "<li>$page->Title: ";
|
|
|
|
$urlSegment = $page->URLSegment;
|
|
|
|
$page->write();
|
|
|
|
if ($urlSegment != $page->URLSegment) {
|
|
|
|
echo _t(
|
2017-04-20 03:15:29 +02:00
|
|
|
'SilverStripe\\CMS\\Model\\SiteTree.LINKSCHANGEDTO',
|
2017-01-25 21:59:25 +01:00
|
|
|
" changed {url1} -> {url2}",
|
2020-04-19 06:18:01 +02:00
|
|
|
['url1' => $urlSegment, 'url2' => $page->URLSegment]
|
2017-01-25 21:59:25 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
echo _t(
|
2017-04-20 03:15:29 +02:00
|
|
|
'SilverStripe\\CMS\\Model\\SiteTree.LINKSALREADYUNIQUE',
|
2017-01-25 21:59:25 +01:00
|
|
|
" {url} is already unique",
|
2020-04-19 06:18:01 +02:00
|
|
|
['url' => $urlSegment]
|
2017-01-25 21:59:25 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 06:08:39 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function Link($action = null)
|
|
|
|
{
|
|
|
|
/** @skipUpgrade */
|
|
|
|
return Controller::join_links('SiteTreeMaintenanceTask', $action, '/');
|
|
|
|
}
|
2008-10-16 14:21:30 +02:00
|
|
|
}
|