Receiving Call to a member function getUserName() on a non-object error in Page Type output

Permalink
Hey, all.

I've run into a strange issue in my concrete5.7.5.3 installation and I'm hoping someone can help me out.

I have an "Article" page type that has about 200 pages built from it. I attempted to add a bit of code to the output via the HTML+PHP Code block from the Marketplace. Part of this code included the following:

$ownerID = UserInfo::getByID($page->getCollectionUserID());
   $name = $ownerID->getUserName();


I received an error that reads "Call to a member function getUserName() on a non-object" and prevents me from making any further changes to the page type output.

I can still create Article pages, and the block I added works just fine in those pages. I copied the Article page type to an Article2 page type, and I can get to the Article2 output and edit it successfully, too. But for some reason, I can't get back to Article output to edit it at all. And I have no idea how to fix it.

Has anyone experienced this kind of thing before?

Thanks,
John

campbell
 
jero replied on at Permalink Reply
jero
That would tend to imply your user ID is either not set or points to a user that no longer exists.

You can get round it like this:

$ownerID = UserInfo::getByID($page->getCollectionUserID());
if (is_object($ownerID)) {
     $name = $ownerID->getUserName();
} else {
     $name = 'A Horse With No Name';
}
campbell replied on at Permalink Reply
campbell
Thanks, jero. That's some useful information.

Unfortunately, I'm not sure how to even get back into the page type output to make that change. When I go to the output page, it provides that error and nothing else.
MrKDilkington replied on at Permalink Reply
MrKDilkington
@campbell

The Php Code Block looks like it saves entered code in the btPhpCodeBlockContent table. One option would be to edit the code in the table directly. When editing database tables directly, it is recommended to make a backup first.

In the add-on description, it lists an ability to disable the block code interpretation. This may allow you to edit the entered code through the interface.

"There are options under the dashboard page (System&Settings->Basics->Php Code Block Settings), where you can disable all the blocks at once. If you disable the Php Code Blocks, the code is not interpreted, and does not appear in the source code if you are not in edit mode.

NEW: You can also disable the interpretation of the code in edit mode now, until you fix the problem."
https://www.concrete5.org/marketplace/addons/php-code-block...