Cupara
Well-known member
As I'm still new to the XF2 code, this is all new to me.
So I followed the Demo Portal doc and got things up and going for a simple portal for me, but the issue I have when testing the Featured Thread part is when I delete a thread that is currently featured the following error shows:
[/LIST]
Now following the stuff above, I go to my Listener file:
The part it points to is:
This then points me to my entity file where FeaturedThread is defined:
I made sure I had shortName set properly and double checked my code, even triple checked it. Double checked to make sure I had the database set right. So I'm now scratching my head knowing it has to be something I'm just not seeing.
Edit: Just discovered that this also references my Editor file which is included:
Line referenced here is:
Which leads to my entity file so again full circle.
So I followed the Demo Portal doc and got things up and going for a simple portal for me, but the issue I have when testing the Featured Thread part is when I delete a thread that is currently featured the following error shows:
Code:
ErrorException: [E_USER_WARNING] Accessed unknown getter 'FeaturedThread' on XF:NewsFeed[81] in src/XF/Mvc/Entity/Entity.php at line 175
[LIST=1]
[*]XF::handlePhpError()
[*]trigger_error() in src/XF/Mvc/Entity/Entity.php at line 175
[*]XF\Mvc\Entity\Entity->get() in src/XF/Mvc/Entity/Entity.php at line 92
[*]XF\Mvc\Entity\Entity->__get() in src/addons/GoblinTimes/xenPortal/Listener.php at line 50
[*]GoblinTimes\xenPortal\Listener::threadEntityPostDelete()
[*]call_user_func_array() in src/XF/Extension.php at line 35
[*]XF\Extension->fire() in src/XF.php at line 561
[*]XF::fire() in src/XF/Mvc/Entity/Entity.php at line 1516
[*]XF\Mvc\Entity\Entity->delete() in src/XF/Repository/NewsFeed.php at line 83
[*]XF\Repository\NewsFeed->unpublish() in src/XF/Behavior/NewsFeedPublishable.php at line 129
[*]XF\Behavior\NewsFeedPublishable->postDelete() in src/XF/Mvc/Entity/Entity.php at line 1513
[*]XF\Mvc\Entity\Entity->delete() in src/XF/Service/Thread/Deleter.php at line 71
[*]XF\Service\Thread\Deleter->delete() in src/XF/Pub/Controller/Thread.php at line 846
[*]XF\Pub\Controller\Thread->actionDelete() in src/XF/Mvc/Dispatcher.php at line 249
[*]XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
[*]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
Now following the stuff above, I go to my Listener file:
PHP:
public static function threadEntityPostDelete(\XF\Mvc\Entity\Entity $entity)
{
$featuredThread = $entity->FeaturedThread;
if ($featuredThread)
{
$featuredThread->delete();
}
}
The part it points to is:
PHP:
$featuredThread = $entity->FeaturedThread;
This then points me to my entity file where FeaturedThread is defined:
PHP:
<?php
namespace GoblinTimes\xenPortal\Entity;
use XF\Mvc\Entity\Structure;
class FeaturedThread extends \XF\Mvc\Entity\Entity
{
public static function getStructure(Structure $structure)
{
$structure->table = 'xenportal_featured_thread';
$structure->shortName = 'XF:FeaturedThread';
$structure->primaryKey = 'thread_id';
$structure->columns = [
'thread_id' => ['type' => self::UINT, 'required' => true],
'featured_date' => ['type' => self::UINT, 'default' => time()]
];
$structure->getters = [];
$structure->relations = [
'Thread' => [
'entity' => 'XF:Thread',
'type' => self::TO_ONE,
'conditions' => 'thread_id',
'primary' => true
],
];
return $structure;
}
}
I made sure I had shortName set properly and double checked my code, even triple checked it. Double checked to make sure I had the database set right. So I'm now scratching my head knowing it has to be something I'm just not seeing.
Edit: Just discovered that this also references my Editor file which is included:
PHP:
<?php
namespace GoblinTimes\xenPortal\XF\Service\Thread;
class Editor extends XFCP_Editor
{
protected $featureThread;
public function setFeatureThread($featureThread)
{
$this->featureThread = $featureThread;
}
protected function _save()
{
$thread = parent::_save();
if ($this->featureThread !== null && $thread->discussion_state == 'visible')
{
/** @var \GoblinTimes\xenPortal\Entity\FeaturedThread $featuredThread */
$featuredThread = $thread->getRelationOrDefault('FeaturedThread', false);
if ($this->featureThread)
{
if (!$featuredThread->exists())
{
$featuredThread->save();
$thread->fastUpdate('xenportal_featured', true);
}
}
else
{
if ($featuredThread->exists())
{
$featuredThread->delete();
$thread->fastUpdate('xenportal_featured', false);
}
}
}
return $thread;
}
}
Line referenced here is:
PHP:
$featuredThread = $thread->getRelationOrDefault('FeaturedThread', false);
Which leads to my entity file so again full circle.