• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed Server Errors Every Few Minutes

Affected version
2.0
#1
This only started today for some reason and there have been no changes to the site since upgrading to XF2 and it had been fine for the last few days.

Code:
Error: Call to a member function canView() on null src/addons/XFMG/Entity/MediaItem.php:94
Generated by: Unknown account Dec 4, 2017 at 7:32 AM

Stack trace
#0 src/addons/XFMG/Sitemap/Media.php(57): XFMG\Entity\MediaItem->canView()
#1 src/XF/Sitemap/Builder.php(181): XFMG\Sitemap\Media->isIncluded(Object(XFMG\Entity\MediaItem))
#2 src/XF/Sitemap/Builder.php(146): XF\Sitemap\Builder->writeContentTypeData('xfmg_media', 2006, 5.5344219207764)
#3 src/XF/Sitemap/Builder.php(81): XF\Sitemap\Builder->buildType('xfmg_media', 5.5344219207764)
#4 src/XF/Job/Sitemap.php(25): XF\Sitemap\Builder->build(5.5344219207764)
#5 src/XF/Job/Manager.php(241): XF\Job\Sitemap->run(7.9999978542328)
#6 src/XF/Job/Manager.php(187): XF\Job\Manager->runJobInternal(Array, 7.9999978542328)
#7 src/XF/Job/Manager.php(76): XF\Job\Manager->runJobEntry(Array, 7.9999978542328)
#8 job.php(15): XF\Job\Manager->runQueue(false, 8)
#9 {main}

Request state
array(4) {
  ["url"] => string(8) "/job.php"
  ["referrer"] => string(27) "https://www.lrukforums.com/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
Any ideas what may be causing this?
 

Chris D

XenForo developer
Staff member
#2
This is an XFMG bug.

I'm surprised it happened, though it implies that you have media items which are not part of a category, but also not attached to a valid Album.

To fix this, please find the file src/addons/XFMG/Entity/MediaItem.php and look for line 92 which is currently:
PHP:
else
And change it to:
PHP:
else if ($this->album_id && $this->Album)
 
#3
This is an XFMG bug.

I'm surprised it happened, though it implies that you have media items which are not part of a category, but also not attached to a valid Album.

To fix this, please find the file src/addons/XFMG/Entity/MediaItem.php and look for line 92 which is currently:
PHP:
else
And change it to:
PHP:
else if ($this->album_id && $this->Album)
Hi Chris, thank you for the prompt fix.

Is there any way to locate the orphaned media so that it can be moved into categories?
 

Chris D

XenForo developer
Staff member
#4
We'd be in the realms of delving into the database to find it.

The obvious thing to check first, though I suspect it's not going to bring anything up:
SQL:
SELECT * FROM xf_mg_media_item
WHERE category_id = 0 AND album_id = 0
 
#5
We'd be in the realms of delving into the database to find it.

The obvious thing to check first, though I suspect it's not going to bring anything up:
SQL:
SELECT * FROM xf_mg_media_item
WHERE category_id = 0 AND album_id = 0
Hi Chris, I've now applied the fix above but I'm still getting errors but they have changed.

Code:
ErrorException: [E_NOTICE] Undefined variable: canView src/addons/XFMG/Entity/MediaItem.php:97
Generated by: Unknown account Dec 4, 2017 at 4:26 PM

Stack trace

#0 src/addons/XFMG/Entity/MediaItem.php(97): XF::handlePhpError(8, '[E_NOTICE] Unde...', '/home/lruk/publ...', 97, Array)
#1 src/addons/XFMG/Sitemap/Media.php(57): XFMG\Entity\MediaItem->canView()
#2 src/XF/Sitemap/Builder.php(181): XFMG\Sitemap\Media->isIncluded(Object(XFMG\Entity\MediaItem))
#3 src/XF/Sitemap/Builder.php(146): XF\Sitemap\Builder->writeContentTypeData('xfmg_media', 2006, 2.123064994812)
#4 src/XF/Sitemap/Builder.php(81): XF\Sitemap\Builder->buildType('xfmg_media', 2.123064994812)
#5 src/XF/Job/Sitemap.php(25): XF\Sitemap\Builder->build(2.123064994812)
#6 src/XF/Job/Manager.php(241): XF\Job\Sitemap->run(7.9999990463257)
#7 src/XF/Job/Manager.php(187): XF\Job\Manager->runJobInternal(Array, 7.9999990463257)
#8 src/XF/Job/Manager.php(76): XF\Job\Manager->runJobEntry(Array, 7.9999990463257)
#9 job.php(15): XF\Job\Manager->runQueue(false, 8)
#10 {main}

Request state

array(4) {
  ["url"] => string(8) "/job.php"
  ["referrer"] => string(58) "https://www.lrukforums.com/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
 
#7
If I try to view the orphaned media so that I can assign it to a category I receive this error:

Code:
ErrorException: [E_NOTICE] Undefined variable: canView in src/addons/XFMG/Entity/MediaItem.php at line 97
XF::handlePhpError() in src/addons/XFMG/Entity/MediaItem.php at line 97
XFMG\Entity\MediaItem->canView() in src/addons/XFMG/Pub/Controller/AbstractController.php at line 61
XFMG\Pub\Controller\AbstractController->assertViewableMediaItem() in src/addons/XFMG/Pub/Controller/Media.php at line 53
XFMG\Pub\Controller\Media->actionView() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 88
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
XF\App->run() in src/XF.php at line 328
XF::runApp() in index.php at line 13
 

Chris D

XenForo developer
Staff member
#8
Fair enough, I took care of that in the code locally, but it really is just a side effect of the orphaned media. The orphaned media won't be viewable unless it is in a category or an album.

In the same file, line 88 is this:
PHP:
if ($this->category_id && $this->Category)
Don't change that line, instead, add this directly above:
PHP:
$canView = false;
 
#9
Thank you again Chris, I have applied your second fix now too but assigning the orphaned media into categories had also fixed the problem. I have no idea how they became orphaned and they were all from the same (still existing) category too.

SQL:
UPDATE xf_mg_media_item SET category_id=18 WHERE category_id=0 AND album_id=0
The above query placed them all back into their category (18) and they seem to be working correctly now

No more server errors, thank you again.

P.S. As a future feature request, an option to fix orphaned media would be much appreciated :)
 

Chris D

XenForo developer
Staff member
#10
Well, basically, it should never happen. If you can shed any light on how it might have done, that would be great. Were they newer images? Or older? Were they visible before the upgrade to 2.0? Any info like that would be ideal.
 
#11
Hi Chris,

I do not believe they were visible prior to upgrading to XF2 as now I've seen them they are unfamiliar to me, they were very old images (circa 2011)

The XFMG had 2 imports, the first was from VBGallery and the second was from vBulletin albums, it's very possible that it happened at some point during those two imports but the images themselves were from VBGallery.

Aside from that, there's not much more I can tell you I'm afraid.

I guess it's possible they were orphaned in VBGallery? I'm not sure whether it would import orphaned files or not.
 

Chris D

XenForo developer
Staff member
#12
I guess it's possible they were orphaned in VBGallery? I'm not sure whether it would import orphaned files or not.
You've been most helpful. Considering their age and the importers involved, it's certainly possible. What we need to do going forward is ensure we don't import media that is already orphaned, or at least import them into an appropriate place.

So we'll bear that in mind, thank you.