Version: current

     1 <?php
     2 /**
     3  * @package cms
     4  * @subpackage tasks
     5  */
     6 class SiteTreeMaintenanceTask extends Controller {
     7     static $allowed_actions = array(
     8         '*' => 'ADMIN'
     9     );
    10
    11     function makelinksunique() {
    12         $badURLs = "'" . implode("', '", DB::query("SELECT URLSegment, count(*) FROM SiteTree GROUP BY URLSegment HAVING count(*) > 1")->column()) . "'";
    13         $pages = DataObject::get("SiteTree", "\"URLSegment\" IN ($badURLs)");
    14
    15         foreach($pages as $page) {
    16             echo "<li>$page->Title: ";
    17             $urlSegment = $page->URLSegment;
    18             $page->write();
    19             if($urlSegment != $page->URLSegment) {
    20                 echo sprintf(_t('SiteTree.LINKSCHANGEDTO', " changed %s -> %s"), $urlSegment, $page->URLSegment);
    21             }
    22             else {
    23                 echo sprintf(_t('SiteTree.LINKSALREADYUNIQUE', " %s is already unique"), $urlSegment);
    24             }
    25             die();
    26         }
    27     }
    28 }
    29 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -