Jump to:

1133 Posts in 1966 Topics by 403 members

Upgrading SilverStripe

SilverStripe Forums » Upgrading SilverStripe » Running /dev/tasks/MigrateSiteTreeLinkingTask failing: [Notice] Trying to get property of non-object

Ask questions about upgrading SilverStripe to the latest version.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1240 Views
  • 1nsane
    Avatar
    Community Member
    14 Posts

    Running /dev/tasks/MigrateSiteTreeLinkingTask failing: [Notice] Trying to get property of non-object Link to this post

    After upgrading to SS 2.4, I'm trying to run the nested URL migration task as described here: http://doc.silverstripe.org/sitetree#nested_hierarchical_urls

    However, I am getting the following notice/trace and the process fails to do its job:

    [Notice] Trying to get property of non-object
    GET /dev/tasks/MigrateSiteTreeLinkingTask

    Line 40 in /Users/Me/Sites/thesite/sapphire/tasks/MigrateSiteTreeLinkingTask.php

    Source

    31             'SELECT "ChildID", "FieldName" FROM "SiteTree_LinkTracking" WHERE "SiteTreeID" = %d',
    32             $page->ID
    33          ));
    34          
    35          foreach($tracking as $link) {
    36             $linked = DataObject::get_by_id('SiteTree', $link['ChildID']);
    37             
    38             // TOOD: Replace in all HTMLText fields
    39             $page->Content = preg_replace (
    40                "/href *= *([\"']?){$linked->URLSegment}\/?/i",
    41                "href=$1[sitetree_link id={$linked->ID}]",
    42                $page->Content,
    43                -1,
    44                $replaced
    45             );
    46             
    Trace

    MigrateSiteTreeLinkingTask->run(SS_HTTPRequest)
    Line 57 of TaskRunner.php
    TaskRunner->runTask(SS_HTTPRequest)
    Line 134 of RequestHandler.php
    RequestHandler->handleRequest(SS_HTTPRequest)
    Line 147 of Controller.php
    Controller->handleRequest(SS_HTTPRequest)
    Line 152 of RequestHandler.php
    RequestHandler->handleRequest(SS_HTTPRequest)
    Line 147 of Controller.php
    Controller->handleRequest(SS_HTTPRequest)
    Line 283 of Director.php
    Director::handleRequest(SS_HTTPRequest,Session)
    Line 127 of Director.php
    Director::direct(/dev/tasks/MigrateSiteTreeLinkingTask)
    Line 127 of main.php

    Has anyone had a similar experience that could point me in the right direction?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Running /dev/tasks/MigrateSiteTreeLinkingTask failing: [Notice] Trying to get property of non-object Link to this post

    Looks like you have a link to a page which doesn't exist in your Content really the following

    // MigrateSiteTreeLinkingTask.php

    $linked = DataObject::get_by_id('SiteTree', $link['ChildID']);

    // TOOD: Replace in all HTMLText fields
    $page->Content = preg_replace (
       "/href *= *([\"']?){$linked->URLSegment}\/?/i",
       "href=$1[sitetree_link id={$linked->ID}]",
       $page->Content,
       -1,
       $replaced
    );

    Should be something like

    // MigrateSiteTreeLinkingTask.php

    $linked = DataObject::get_by_id('SiteTree', $link['ChildID']);
    $linkedID = ($linked) ? $linked->ID : $link['ChildID'];
    $linkedURL = ($linked) ? $linked->URLSegment : '';

    // TOOD: Replace in all HTMLText fields
    $page->Content = preg_replace (
       "/href *= *([\"']?){$linkedURL}\/?/i",
       "href=$1[sitetree_link id={$linkedID}]",
       $page->Content,
       -1,
       $replaced
    );

    Try that and see if that helps.

  • 1nsane
    Avatar
    Community Member
    14 Posts

    Re: Running /dev/tasks/MigrateSiteTreeLinkingTask failing: [Notice] Trying to get property of non-object Link to this post

    Thanks for your help. I tried your suggestion and it worked for some links but not all. Upon running the link migration task a second time, it added some duplicate link code (I backed up of course, so no big deal).

    Another related question - how are 301 redirects handled from old URLS? Or are they?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Running /dev/tasks/MigrateSiteTreeLinkingTask failing: [Notice] Trying to get property of non-object Link to this post

    AFAIK all the old URLs are saved from the versions table any requests to those are sent as 301 redirects to the new nested structure.

    1240 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.