/**
  * @dataProvider provideGenerationData
  */
 public function testGenerate($expected, $format, $page, $renew, $alreadyCreated)
 {
     $user = self::$DI['user'];
     $feed = new Feed();
     $feed->setTitle("title");
     $another_feed = new Feed(self::$DI['user']);
     $another_feed->setTitle("another_title");
     $feeds = [$feed, $another_feed];
     $aggregate = new Aggregate(self::$DI['app']['EM'], $feeds);
     $generator = $this->getMockBuilder('Symfony\\Component\\Routing\\Generator\\UrlGenerator')->disableOriginalConstructor()->getMock();
     if ($alreadyCreated) {
         $token = self::$DI['app']['EM']->find('Phraseanet:AggregateToken', 1);
         $tokenValue = $token->getValue();
     }
     $capture = null;
     $generator->expects($this->once())->method('generate')->with('feed_user_aggregated', $this->isType('array'), UrlGenerator::ABSOLUTE_URL)->will($this->returnCallback(function ($name, $data, $option) use(&$capture, $expected) {
         $capture = $data;
         return $expected;
     }));
     $random = self::$DI['app']['tokens'];
     $linkGenerator = new AggregateLinkGenerator($generator, self::$DI['app']['EM'], $random);
     $link = $linkGenerator->generate($aggregate, self::$DI['user'], $format, $page, $renew);
     if ($format == "atom") {
         $this->assertSame("application/atom+xml", $link->getMimetype());
         $this->assertSame("AGGREGATE - Atom", $link->getTitle());
     } elseif ($format == "rss") {
         $this->assertSame("application/rss+xml", $link->getMimetype());
         $this->assertSame("AGGREGATE - RSS", $link->getTitle());
     }
     if ($alreadyCreated) {
         if ($renew) {
             $this->assertEquals($format, $capture['format']);
             if (null !== $page) {
                 $this->assertEquals($page, $capture['page']);
             }
             $this->assertNotEquals($tokenValue, $capture['token']);
             $this->assertCount(0, self::$DI['app']['EM']->getRepository('Phraseanet:AggregateToken')->findBy(['value' => $tokenValue]));
             $this->assertCount(1, self::$DI['app']['EM']->getRepository('Phraseanet:AggregateToken')->findBy(['value' => $capture['token']]));
         } else {
             $expectedParams = ['token' => $tokenValue, 'format' => $format];
             if ($page !== null) {
                 $expectedParams['page'] = $page;
             }
             $this->assertEquals($expectedParams, $capture);
             $this->assertCount(1, self::$DI['app']['EM']->getRepository('Phraseanet:AggregateToken')->findBy(['value' => $tokenValue]));
         }
     } else {
         if (null !== $page) {
             $this->assertEquals($page, $capture['page']);
         }
         $this->assertEquals($format, $capture['format']);
         $this->assertEquals(12, strlen($capture['token']));
         $this->assertCount(1, self::$DI['app']['EM']->getRepository('Phraseanet:AggregateToken')->findBy(['value' => $capture['token']]));
     }
 }
Пример #2
0
 public function checkRSSEntryNode(\DOMXPath $xpath, Feed $feed)
 {
     $list_entries = $xpath->query("/rss/channel/item");
     $count = 0;
     $offset_start = 0;
     $n_entries = 20;
     $entries = $feed->getEntries()->slice($offset_start, $n_entries);
     foreach ($list_entries as $node) {
         if (sizeof($entries) == 0) {
             $offset_start += $n_entries;
             $entries = $feed->getEntries()->slice($offset_start, $n_entries);
             if (sizeof($entries) == 0) {
                 //no more
                 break;
             }
         }
         $feed_entry = array_shift($entries);
         switch ($node->nodeName) {
             case 'title':
                 $this->assertEquals($feed_entry->getTitle(), $node->nodeValue);
                 break;
             case 'description':
                 $this->assertEquals($feed_entry->getSubtitle(), $node->nodeValue);
                 break;
             case 'author':
                 $author = sprintf('%s (%s)', $feed_entry->getAuthorEmail(), $feed_entry->getAuthorName());
                 $this->assertEquals($author, $node->nodeValue);
                 break;
             case 'pubDate':
                 $this->assertEquals($feed_entry->getCreatedOn()->format(DATE_RFC2822), $node->nodeValue);
                 break;
             case 'guid':
                 $this->assertEquals($feed_entry->getLink()->getURI(), $node->nodeValue);
                 break;
             case 'link':
                 $this->assertEquals($feed_entry->getLink()->getURI(), $node->nodeValue);
                 break;
         }
         $count++;
         $this->checkRSSEntryItemsNode($xpath, $feed_entry, $count);
     }
     $this->assertEquals($feed->getCountTotalEntries(), $count);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     if (false === $this->hasFeedBackup($app)) {
         return false;
     }
     $sql = 'DELETE FROM Feeds';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedEntries';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedPublishers';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedItems';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FeedTokens';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM AggregateTokens';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $conn = $app->getApplicationBox()->get_connection();
     $sql = 'SELECT id, title, subtitle, public, created_on, updated_on, base_id FROM feeds_backup;';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 0;
     $em = $app['orm.em'];
     $fpSql = 'SELECT id, usr_id, owner, created_on FROM feed_publishers WHERE feed_id = :feed_id;';
     $fpStmt = $conn->prepare($fpSql);
     $feSql = 'SELECT id, title, description, created_on, updated_on, author_name, author_email FROM feed_entries WHERE feed_id = :feed_id AND publisher = :publisher_id;';
     $feStmt = $conn->prepare($feSql);
     $fiSql = 'SELECT sbas_id, record_id, ord FROM feed_entry_elements WHERE entry_id = :entry_id;';
     $fiStmt = $conn->prepare($fiSql);
     $ftSql = 'SELECT token, usr_id, aggregated FROM feed_tokens WHERE feed_id = :feed_id;';
     $ftStmt = $conn->prepare($ftSql);
     $faSql = 'SELECT token, usr_id FROM feed_tokens WHERE aggregated = 1;';
     $faStmt = $conn->prepare($faSql);
     foreach ($rs as $row) {
         $feed = new Feed();
         $feed->setTitle($row['title']);
         $feed->setSubtitle($row['subtitle']);
         $feed->setIconUrl(false);
         $feed->setIsPublic($row['public']);
         $feed->setCreatedOn(new \DateTime($row['created_on']));
         $feed->setUpdatedOn(new \DateTime($row['updated_on']));
         $feed->setBaseId($row['base_id']);
         $fpStmt->execute([':feed_id' => $row['id']]);
         $fpRes = $fpStmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($fpRes as $fpRow) {
             if (null === ($user = $this->loadUser($app['orm.em'], $fpRow['usr_id']))) {
                 continue;
             }
             $feedPublisher = new FeedPublisher();
             $feedPublisher->setFeed($feed);
             $feed->addPublisher($feedPublisher);
             $feedPublisher->setCreatedOn(new \DateTime($fpRow['created_on']));
             $feedPublisher->setIsOwner((bool) $fpRow['owner']);
             $feedPublisher->setUser($user);
             $feStmt->execute([':feed_id' => $row['id'], ':publisher_id' => $fpRow['id']]);
             $feRes = $feStmt->fetchAll(\PDO::FETCH_ASSOC);
             foreach ($feRes as $feRow) {
                 $feedEntry = new FeedEntry();
                 $feedEntry->setFeed($feed);
                 $feed->addEntry($feedEntry);
                 $feedEntry->setPublisher($feedPublisher);
                 $feedEntry->setTitle($feRow['title']);
                 $feedEntry->setSubtitle($feRow['description']);
                 $feedEntry->setAuthorName((string) $feRow['author_name']);
                 $feedEntry->setAuthorEmail((string) $feRow['author_email']);
                 $feedEntry->setCreatedOn(new \DateTime($feRow['created_on']));
                 $feedEntry->setUpdatedOn(new \DateTime($feRow['updated_on']));
                 $fiStmt->execute([':entry_id' => $feRow['id']]);
                 $fiRes = $fiStmt->fetchAll(\PDO::FETCH_ASSOC);
                 foreach ($fiRes as $fiRow) {
                     $feedItem = new FeedItem();
                     $feedItem->setEntry($feedEntry);
                     $feedEntry->addItem($feedItem);
                     $feedItem->setOrd($fiRow['ord']);
                     $feedItem->setSbasId($fiRow['sbas_id']);
                     $feedItem->setRecordId($fiRow['record_id']);
                     $em->persist($feedItem);
                 }
                 $em->persist($feedEntry);
             }
             $em->persist($feedPublisher);
         }
         $ftStmt->execute([':feed_id' => $row['id']]);
         $ftRes = $ftStmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($ftRes as $ftRow) {
             if (null === ($user = $this->loadUser($app['orm.em'], $ftRow['usr_id']))) {
                 continue;
             }
             $token = new FeedToken();
             $token->setFeed($feed);
             $feed->addToken($token);
             $token->setUser($user);
             $token->setValue($ftRow['token']);
             $em->persist($token);
         }
         $em->persist($feed);
         $n++;
         if ($n % 100 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $fiStmt->closeCursor();
     $feStmt->closeCursor();
     $fpStmt->closeCursor();
     $ftStmt->closeCursor();
     $faStmt->execute();
     $faRes = $faStmt->fetchAll(\PDO::FETCH_ASSOC);
     foreach ($faRes as $faRow) {
         if (null === ($user = $this->loadUser($app['orm.em'], $faRow['usr_id']))) {
             continue;
         }
         $token = new AggregateToken();
         $token->setUser($user);
         $token->setValue($faRow['token']);
         $em->persist($token);
     }
     $faStmt->closeCursor();
     $em->flush();
     $em->clear();
     return true;
 }
Пример #4
0
 protected function get_feed(Application $app, appbox $appbox, User $user, $pub_restrict, $homelink)
 {
     $user_key = 'user_' . $user->getId();
     if ($homelink == '1') {
         $feed_key = 'feed_homelink';
     } elseif ($pub_restrict == '1') {
         $feed_key = 'feed_restricted';
     } else {
         $feed_key = 'feed_public';
     }
     if (!array_key_exists($user_key, self::$feeds) || !isset(self::$feeds[$user_key][$feed_key])) {
         if ($homelink == '1') {
             $title = $user->getDisplayName() . ' - ' . 'homelink Feed';
         } elseif ($pub_restrict == '1') {
             $title = $user->getDisplayName() . ' - ' . 'private Feed';
         } else {
             $title = $user->getDisplayName() . ' - ' . 'public Feed';
         }
         $feed = new Feed();
         $publisher = new FeedPublisher();
         $feed->setTitle('title');
         $feed->setSubtitle('');
         $feed->addPublisher($publisher);
         $publisher->setFeed($feed);
         $publisher->setIsOwner(true);
         $publisher->setUser($user);
         if ($homelink) {
             $feed->setIsPublic(true);
             $app['orm.em']->persist($feed);
             $app['orm.em']->persist($user);
             $app['orm.em']->flush();
         } elseif ($pub_restrict == 1) {
             $collections = $app->getAclForUser($user)->get_granted_base();
             $collection = array_shift($collections);
             if (!$collection instanceof collection) {
                 foreach ($appbox->get_databoxes() as $databox) {
                     foreach ($databox->get_collections() as $coll) {
                         $collection = $coll;
                         break;
                     }
                     if ($collection instanceof collection) {
                         break;
                     }
                 }
             }
             if (!$collection instanceof collection) {
                 return false;
             }
             $feed->setCollection($collection);
         }
         self::$feeds[$user_key][$feed_key] = $feed;
     } else {
         $feed = self::$feeds[$user_key][$feed_key];
     }
     return $feed;
 }
 /**
  * {@inheritDoc}
  */
 public function isAccessible(\Alchemy\Phrasea\Model\Entities\User $user, \Alchemy\Phrasea\Application $app)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'isAccessible', array($user, $app));
     return parent::isAccessible($user, $app);
 }
Пример #6
0
 /**
  * Retrieve detailled informations about one feed
  *
  * @param  Feed $feed
  * @param  type $user
  *
  * @return array
  */
 private function list_publication(Feed $feed, $user)
 {
     return ['id' => $feed->getId(), 'title' => $feed->getTitle(), 'subtitle' => $feed->getSubtitle(), 'total_entries' => $feed->getCountTotalEntries(), 'icon' => $feed->getIconUrl(), 'public' => $feed->isPublic(), 'readonly' => !$feed->isPublisher($user), 'deletable' => $feed->isOwner($user), 'created_on' => $feed->getCreatedOn()->format(DATE_ATOM), 'updated_on' => $feed->getUpdatedOn()->format(DATE_ATOM)];
 }