Failed to set up Symfony package (third party)

I'm not good at Symfony and I'm trying to set up a third party package that reads RSS feeds and then inserts them into a database. The third bundle I am trying to use is called rss-atom-bundle

After reading the instructions, I can get the rss feeds, but I cannot insert them into the database, possibly due to my ignorance of Symfony

This is the controller I have that fetches feeds and then has to insert into the database

namespace AppBundle\Controller;

use AppBundle\Entity\Feed as Feed;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction()
    {
        // fetch the FeedReader
        $reader = $this->container->get('debril.reader');

        // this date is used to fetch only the latest items
        $unmodifiedSince = '11/11/2014';
        $date = new \DateTime($unmodifiedSince);

        // the feed you want to read
        $url = 'https://example.com/feed/';

        // now fetch its (fresh) content
        $feed = $reader->getFeedContent($url, $date);
        // in developer tool bar I can see the feeds using dump()
        dump($feed);

        $items = $feed->getItems();

        //Insert fetched feeds into database
        $feeds = new Feed;
        $reader->readFeed($url, $feeds, $date);
        return $this->render('default/index.html.twig');
    }

}

      

I dont see any error and I dont see any feeds inside my database table.

Here is the documentaion method readFeed()

that should insert feeds into the database. I followed him but didn't have time yet

This is my Feed

Entity

namespace AppBundle\Entity;

use Debril\RssAtomBundle\Protocol\FeedInterface;
use Debril\RssAtomBundle\Protocol\ItemIn;
use Doctrine\ORM\Mapping as ORM;

/**
 * Feed
 */
class Feed implements FeedInterface
{
    /**
     * @var integer
     */
    private $id;
    private $lastModified;
    private $title;
    private $description;
    private $link;
    private $publicId;



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Atom : feed.entry <feed><entry>
     * Rss  : rss.channel.item <rss><channel><item>
     * @param \Debril\RssAtomBundle\Protocol\ItemIn $item
     */
    public function addItem(ItemIn $item)
    {
        // TODO: Implement addItem() method.
    }

      public function setLastModified(\DateTime $lastModified)
    {
        $this->lastModified = $lastModified;

        return $this;
    }

    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    public function setLink($link)
    {
        $this->link = $link;

        return $this;
    }


    public function setPublicId($id)
    {
        $this->publicId = $id;

        return $this;
    }

    /**
     * Atom : feed.updated <feed><updated>
     * Rss  : rss.channel.lastBuildDate <rss><channel><lastBuildDate>
     * @return \DateTime
     */
    public function getLastModified()
    {
        return $this->lastModified;
    }

    /**
     * Atom : feed.title <feed><title>
     * Rss  : rss.channel.title <rss><channel><title>
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Atom : feed.subtitle <feed><subtitle>
     * Rss  : rss.channel.description <rss><channel><description>
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Atom : feed.link <feed><link>
     * Rss  : rss.channel.link <rss><channel><link>
     * @return string
     */
    public function getLink()
    {
        return $this->link;
    }

    /**
     * Atom : feed.id <feed><id>
     * Rss  : rss.channel.id <rss><channel><id>
     * @return string
     */
    public function getPublicId()
    {
        return $this->publicId;
    }

    /**
     * Atom : feed.entry <feed><entry>
     * Rss  : rss.channel.item <rss><channel><item>
     * @return array[\Debril\RssAtomBundle\Protocol\ItemOut]
     */
    public function getItems()
    {
        // TODO: Implement getItems() method.
    }
}

      

I will be very grateful for pushing in the right direction as I really don't know at the moment.

+3


source to share


1 answer


I have not tried this package yet, but I think you need to tell doctrine that you want to store the newly created channel in the database:

$feeds = new Feed;
$reader->readFeed($url, $feeds, $date);

$em = $this->getDoctrine()->getManager();
$em->persist($feeds);
$em->flush();

return $this->render('default/index.html.twig');

      



UPDATE

According to the docs, if you want to use doctrine

to store the feed and its items in the database, you need to create two classes, one for the FeedInterface

other for ItemInInterface

and ItemOutInterface

. Also, you need to set up the doctrine database schema for these classes, so it will know how to store its data in the db. Then you need to tell the package to use your classes and finally call persist()

and flush()

to actually save the feed and its items to the database.

+1


source







All Articles