Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Upgrading SilverStripe /

Ask questions about upgrading SilverStripe to the latest version.

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

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


Reply


4 Posts   1402 Views

Avatar
1nsane

Community Member, 14 Posts

5 June 2010 at 12:33pm

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?

Avatar
Willr

Forum Moderator, 5513 Posts

6 June 2010 at 11:58am

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.

Avatar
1nsane

Community Member, 14 Posts

9 June 2010 at 4:45am

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?

Avatar
Willr

Forum Moderator, 5513 Posts

9 June 2010 at 8:59am

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.