We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8109
    • 128 Posts
    I just upgraded form 2.0.x to 2.2. I have a lof of resources without aliases, and old links that used to get built replacing a missing alias with the id, now no longer work. I can see in the content table that the uris for many resources use this old format (which was great and should still work, dammit smiley

    /content/123/23/overview.html

    I have hundreds of such uris that now don't work, and dozens of containers without aliases. Is there a way to get all the aliases created automatically at once. And can ew go back to the old url scheme, too?! [ed. note: drwagner13 last edited this post 12 years, 1 month ago.]
      Revo 2.0.8-pl
      • 3749
      • 24,544 Posts
      Here's a utility snippet that should create standard aliases for them, though any hard-coded links, links creates in code without using $modx->makeUrl(), or off-site links still won't work:

      [[!FixAliases]]


      Just create the snippet, put that tag on a page, a preview the page (just once). Then clear the cache and delete the snippet and page.

      <?php
      /* FixAliases snippet */
       
      $resources = $modx->getCollection('modResource');
       
      $count = 0;
      
      foreach ($resources as $resource ) {
          $alias = $resource->get('alias');
          if (empty($alias) )  {
               $count++
               $pageTitle = $resource->get('pagetitle');
               $newAlias = $resource->cleanAlias($pageTitle);
               $resource->set('alias', $newAlias);
          }
       
       $resource->save();
      }
      
      return 'Created new aliases for ' . $count . 'resources';
      


      That will give you aliases that are lowercase versions of the pagetitle with any spaces converted to hyphens.

      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 12 years, 1 month ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 8109
        • 128 Posts
        This appears to have worked perfectly. You are a lifesaver.
          Revo 2.0.8-pl
          • 3749
          • 24,544 Posts
          I'm glad it worked. Thanks for reporting back. smiley

          Please reply and edit the subject to add [Solved].

          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3749
            • 24,544 Posts
            There was a request for fixing empty menu titles. This works just like the snippet above but replaces empty menu titles with the pagetitle:

            <?php
            /* FixAliases snippet */
              
            $resources = $modx->getCollection('modResource');
              
            $count = 0;
             
            foreach ($resources as $resource ) {
                $menutitle = $resource->get('menutitle');
                if (empty($menutitle) )  {
                     $count++
                     $pageTitle = $resource->get('pagetitle');
                     $newMenuTitle = $pageTitle;
                     $resource->set('menutitle', $newMenuTitle);
                }
              
             $resource->save();
            }
             
            return 'Created new menutitles for ' . $count . 'resources';
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting