silverstripe-cms/code/Tasks/SiteTreeMaintenanceTask.php

47 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2016-08-10 06:08:39 +02:00
namespace SilverStripe\CMS\Tasks;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
2017-01-25 21:59:25 +01:00
class SiteTreeMaintenanceTask extends Controller
{
private static $allowed_actions = array(
'*' => 'ADMIN'
);
2016-03-08 21:50:55 +01:00
2017-01-25 21:59:25 +01:00
public function makelinksunique()
{
$badURLs = "'" . implode("', '", DB::query("SELECT URLSegment, count(*) FROM SiteTree GROUP BY URLSegment HAVING count(*) > 1")->column()) . "'";
$pages = DataObject::get("SilverStripe\\CMS\\Model\\SiteTree", "\"SiteTree\".\"URLSegment\" IN ($badURLs)");
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}",
array('url1' => $urlSegment, 'url2' => $page->URLSegment)
);
} 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",
array('url' => $urlSegment)
);
}
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, '/');
}
}