LPH
Well-known member
The following appears to work but PhpStorm is showing an error:
	
	
	
		
Can someone explain the error? Is this due to the finder line with the whereId?
Next, I'd like to modify the edit($post) method but I cannot figure out how to modify the \XF::asVisitor because edit doesn't use Thread\Creator but rather Post\Editor. Any suggestions would be great.
				
			Expected \XF\Entity\User, got \XF\Mvc\Entity\Entity
Invocation parameter types are not compatible with declared.
		PHP:
	
	/**
 * @param $post
 *
 * @return string
 * @throws \Exception
 */
public function insert( $post ) {
   $title = $this->getTitle( $post );
   $message = $this->getMessage( $post );
   // Get the forum using forum_id
   $forum_id = $this->getForumId( $post );
   $forum = \XF::em()->find( 'XF:Forum', $forum_id );
   $user = \XF::app()->finder('XF:User')->whereId($post->post_author)->fetchOne();
   \XF::asVisitor($user, function() use ($forum, $title, $message, $post)
   {
      /** @var \XF\Service\Thread\Creator $creator */
      $creator = \XF::service('XF:Thread\Creator', $forum);
      $creator->setContent( $title, $message );
      $creator->setPrefix( $this->getForumId( $post ) );
      $creator->setTags( $this->getTags( $post ) );
      $creator->setIsAutomated();
      if (!$creator->validate())
      {
         return null;
      }
      $creator->save();
      $creator->sendNotifications();
      $this->postMeta( $creator, $post );
   });
   return '';
}Can someone explain the error? Is this due to the finder line with the whereId?
Next, I'd like to modify the edit($post) method but I cannot figure out how to modify the \XF::asVisitor because edit doesn't use Thread\Creator but rather Post\Editor. Any suggestions would be great.
 
 
		 
 
		