mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
a87a857a6e
Remove @package / @subpackage Fix inifinite loop in VirtualPage_Controller
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\CMS\Tasks;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
use SilverStripe\ORM\DB;
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
class SiteTreeMaintenanceTask extends Controller {
|
|
private static $allowed_actions = array(
|
|
'*' => 'ADMIN'
|
|
);
|
|
|
|
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)");
|
|
|
|
foreach($pages as $page) {
|
|
echo "<li>$page->Title: ";
|
|
$urlSegment = $page->URLSegment;
|
|
$page->write();
|
|
if($urlSegment != $page->URLSegment) {
|
|
echo _t(
|
|
'SiteTree.LINKSCHANGEDTO',
|
|
" changed {url1} -> {url2}",
|
|
array('url1' => $urlSegment, 'url2' => $page->URLSegment)
|
|
);
|
|
}
|
|
else {
|
|
echo _t(
|
|
'SiteTree.LINKSALREADYUNIQUE',
|
|
" {url} is already unique",
|
|
array('url' => $urlSegment)
|
|
);
|
|
}
|
|
die();
|
|
}
|
|
}
|
|
|
|
public function Link($action = null)
|
|
{
|
|
/** @skipUpgrade */
|
|
return Controller::join_links('SiteTreeMaintenanceTask', $action, '/');
|
|
}
|
|
}
|