Пример #1
0
 public function createFeedEntryAction(Request $request)
 {
     $feed = $this->getFeedRepository()->find($request->request->get('feed_id'));
     if (null === $feed) {
         $this->app->abort(404, "Feed not found");
     }
     $user = $this->getAuthenticatedUser();
     $publisher = $this->getFeedPublisherRepository()->findOneBy(['feed' => $feed, 'user' => $user]);
     if ('' === ($title = trim($request->request->get('title', '')))) {
         $this->app->abort(400, "Bad request");
     }
     if (!$feed->isPublisher($user)) {
         $this->app->abort(403, 'Unauthorized action');
     }
     $entry = new FeedEntry();
     $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setFeed($feed)->setPublisher($publisher)->setSubtitle($request->request->get('subtitle', ''));
     $feed->addEntry($entry);
     $publishing = RecordsRequest::fromRequest($this->app, $request, true, [], ['bas_chupub']);
     $manager = $this->getEntityManager();
     foreach ($publishing as $record) {
         $item = new FeedItem();
         $item->setEntry($entry)->setRecordId($record->get_record_id())->setSbasId($record->get_sbas_id());
         $entry->addItem($item);
         $manager->persist($item);
     }
     $manager->persist($entry);
     $manager->persist($feed);
     $manager->flush();
     $this->dispatch(PhraseaEvents::FEED_ENTRY_CREATE, new FeedEntryEvent($entry, $request->request->get('notify')));
     return $this->app->json(['error' => false, 'message' => false]);
 }
Пример #2
0
 public function testLoadLatestWithDeletedDatabox()
 {
     $feed = self::$DI['app']['EM']->find('Phraseanet:Feed', 2);
     $entry = $feed->getEntries()->first();
     $item = new FeedItem();
     $item->setEntry($entry)->setOrd(4)->setRecordId(self::$DI['record_1']->get_record_id())->setSbasId(0);
     $entry->addItem($item);
     self::$DI['app']['EM']->persist($item);
     $item = new FeedItem();
     $item->setEntry($entry)->setOrd(4)->setRecordId(0)->setSbasId(self::$DI['record_1']->get_sbas_id());
     $entry->addItem($item);
     self::$DI['app']['EM']->persist($item);
     $item = new FeedItem();
     $item->setEntry($entry)->setOrd(4)->setRecordId(123456789)->setSbasId(123456789);
     $entry->addItem($item);
     self::$DI['app']['EM']->persist($item);
     self::$DI['app']['EM']->persist($entry);
     self::$DI['app']['EM']->flush();
     $this->assertCount(3, self::$DI['app']['EM']->getRepository('Phraseanet:FeedItem')->loadLatest(self::$DI['app'], 20));
 }
Пример #3
0
 public function connect(Application $app)
 {
     $app['controller.prod.feed'] = $this;
     $controllers = $app['controllers_factory'];
     $app['firewall']->addMandatoryAuthentication($controllers);
     $controllers->post('/requestavailable/', function (Application $app, Request $request) {
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']);
         return $app['twig']->render('prod/actions/publish/publish.html.twig', ['publishing' => $publishing, 'feeds' => $feeds]);
     });
     $controllers->post('/entry/create/', function (Application $app, Request $request) {
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($request->request->get('feed_id'));
         if (null === $feed) {
             $app->abort(404, "Feed not found");
         }
         $publisher = $app['EM']->getRepository('Phraseanet:FeedPublisher')->findOneBy(['feed' => $feed, 'user' => $app['authentication']->getUser()]);
         if ('' === ($title = trim($request->request->get('title', '')))) {
             $app->abort(400, "Bad request");
         }
         if (!$feed->isPublisher($app['authentication']->getUser())) {
             $app->abort(403, 'Unathorized action');
         }
         $entry = new FeedEntry();
         $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setFeed($feed)->setPublisher($publisher)->setSubtitle($request->request->get('subtitle', ''));
         $feed->addEntry($entry);
         $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']);
         foreach ($publishing as $record) {
             $item = new FeedItem();
             $item->setEntry($entry)->setRecordId($record->get_record_id())->setSbasId($record->get_sbas_id());
             $entry->addItem($item);
             $app['EM']->persist($item);
         }
         $app['EM']->persist($entry);
         $app['EM']->persist($feed);
         $app['EM']->flush();
         $app['events-manager']->trigger('__FEED_ENTRY_CREATE__', ['entry_id' => $entry->getId(), 'notify_email' => (bool) $request->request->get('notify')], $entry);
         $datas = ['error' => false, 'message' => false];
         return $app->json($datas);
     })->bind('prod_feeds_entry_create')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->get('/entry/{id}/edit/', function (Application $app, Request $request, $id) {
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (!$entry->isPublisher($app['authentication']->getUser())) {
             throw new AccessDeniedHttpException();
         }
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', ['entry' => $entry, 'feeds' => $feeds]);
         return new Response($datas);
     })->bind('feed_entry_edit')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->post('/entry/{id}/update/', function (Application $app, Request $request, $id) {
         $datas = ['error' => true, 'message' => '', 'datas' => ''];
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (null === $entry) {
             $app->abort(404, 'Entry not found');
         }
         if (!$entry->isPublisher($app['authentication']->getUser())) {
             $app->abort(403, 'Unathorized action');
         }
         if ('' === ($title = trim($request->request->get('title', '')))) {
             $app->abort(400, "Bad request");
         }
         $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setSubtitle($request->request->get('subtitle', ''));
         $currentFeedId = $entry->getFeed()->getId();
         $new_feed_id = $request->request->get('feed_id', $currentFeedId);
         if ($currentFeedId !== (int) $new_feed_id) {
             $new_feed = $app['EM']->getRepository('Phraseanet:Feed')->find($new_feed_id);
             if ($new_feed === null) {
                 $app->abort(404, 'Feed not found');
             }
             if (!$new_feed->isPublisher($app['authentication']->getUser())) {
                 $app->abort(403, 'You are not publisher of this feed');
             }
             $entry->setFeed($new_feed);
         }
         $items = explode(';', $request->request->get('sorted_lst'));
         foreach ($items as $item_sort) {
             $item_sort_datas = explode('_', $item_sort);
             if (count($item_sort_datas) != 2) {
                 continue;
             }
             $item = $app['EM']->getRepository('Phraseanet:FeedItem')->find($item_sort_datas[0]);
             $item->setOrd($item_sort_datas[1]);
             $app['EM']->persist($item);
         }
         $app['EM']->persist($entry);
         $app['EM']->flush();
         return $app->json(['error' => false, 'message' => 'succes', 'datas' => $app['twig']->render('prod/feeds/entry.html.twig', ['entry' => $entry])]);
     })->bind('prod_feeds_entry_update')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->post('/entry/{id}/delete/', function (Application $app, Request $request, $id) {
         $datas = ['error' => true, 'message' => ''];
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (null === $entry) {
             $app->abort(404, 'Entry not found');
         }
         if (!$entry->isPublisher($app['authentication']->getUser()) && $entry->getFeed()->isOwner($app['authentication']->getUser()) === false) {
             $app->abort(403, $app->trans('Action Forbidden : You are not the publisher'));
         }
         $app['EM']->remove($entry);
         $app['EM']->flush();
         return $app->json(['error' => false, 'message' => 'succes']);
     })->bind('prod_feeds_entry_delete')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->get('/', function (Application $app, Request $request) {
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page > 0 ? $page : 1;
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feeds' => $feeds, 'feed' => new Aggregate($app['EM'], $feeds), 'page' => $page]);
         return new Response($datas);
     })->bind('prod_feeds');
     $controllers->get('/feed/{id}/', function (Application $app, Request $request, $id) {
         $page = (int) $request->query->get('page');
         $page = $page > 0 ? $page : 1;
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id);
         if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
             $app->abort(404, 'Feed not found');
         }
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feed' => $feed, 'feeds' => $feeds, 'page' => $page]);
         return new Response($datas);
     })->bind('prod_feeds_feed')->assert('id', '\\d+');
     $controllers->get('/subscribe/aggregated/', function (Application $app, Request $request) {
         $renew = $request->query->get('renew') === 'true';
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $link = $app['feed.aggregate-link-generator']->generate(new Aggregate($app['EM'], $feeds), $app['authentication']->getUser(), AggregateLinkGenerator::FORMAT_RSS, null, $renew);
         $output = ['texte' => '<p>' . $app->trans('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') . '</p><p>' . $app->trans('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
         <div><input type="text" readonly="readonly" class="input_select_copy" value="' . $link->getURI() . '"/></div>', 'titre' => $app->trans('publications::votre rss personnel')];
         return $app->json($output);
     })->bind('prod_feeds_subscribe_aggregated');
     $controllers->get('/subscribe/{id}/', function (Application $app, Request $request, $id) {
         $renew = $request->query->get('renew') === 'true';
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id);
         if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
             $app->abort(404, 'Feed not found');
         }
         $link = $app['feed.user-link-generator']->generate($feed, $app['authentication']->getUser(), FeedLinkGenerator::FORMAT_RSS, null, $renew);
         $output = ['texte' => '<p>' . $app->trans('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') . '</p><p>' . $app->trans('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
         <div><input type="text" style="width:100%" value="' . $link->getURI() . '"/></div>', 'titre' => $app->trans('publications::votre rss personnel')];
         return $app->json($output);
     })->bind('prod_feeds_subscribe_feed')->assert('id', '\\d+');
     return $controllers;
 }
Пример #4
0
 protected function addContent(Application $app, \DOMDocument $document, \DOMNode $node, FeedItem $content)
 {
     $preview_sd = $content->getRecord($app)->get_subdef('preview');
     $preview_permalink = $preview_sd->get_permalink();
     $thumbnail_sd = $content->getRecord($app)->get_thumbnail();
     $thumbnail_permalink = $thumbnail_sd->get_permalink();
     $medium = strtolower($content->getRecord($app)->get_type());
     if (!in_array($medium, ['image', 'audio', 'video'])) {
         return $this;
     }
     if (null === $preview_permalink || null === $thumbnail_permalink) {
         return $this;
     }
     //add item node to channel node
     $item = $this->addTag($document, $node, 'item');
     $caption = $content->getRecord($app)->get_caption();
     $title_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Title);
     if (null !== $title_field) {
         $str_title = $title_field->get_serialized_values(' ');
     } else {
         $str_title = $content->getRecord($app)->get_title();
     }
     //attach tile node to item node
     $title = $this->addTag($document, $item, 'title', $str_title);
     $desc_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Description);
     if (null !== $desc_field) {
         $str_desc = $desc_field->get_serialized_values(' ');
     } else {
         $str_desc = '';
     }
     //attach desc node to item node
     $desc = $this->addTag($document, $item, 'description', $str_desc);
     $duration = $content->getRecord($app)->get_duration();
     if (null !== $preview_permalink) {
         $preview = $this->addTag($document, $item, 'media:content');
         $preview->setAttribute('url', (string) $preview_permalink->get_url());
         $preview->setAttribute('fileSize', $preview_sd->get_size());
         $preview->setAttribute('type', $preview_sd->get_mime());
         $preview->setAttribute('medium', $medium);
         $preview->setAttribute('expression', 'full');
         $preview->setAttribute('isDefault', 'true');
         if (null !== $preview_sd->get_width()) {
             $preview->setAttribute('width', $preview_sd->get_width());
         }
         if (null !== $preview_sd->get_height()) {
             $preview->setAttribute('height', $preview_sd->get_height());
         }
         if (null !== $duration) {
             $preview->setAttribute('duration', $duration);
         }
     }
     if (null !== $thumbnail_permalink) {
         $thumbnail = $this->addTag($document, $item, 'media:thumbnail');
         $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url());
         if (null !== $thumbnail_sd->get_width()) {
             $thumbnail->setAttribute('width', $thumbnail_sd->get_width());
         }
         if (null !== $thumbnail_sd->get_height()) {
             $thumbnail->setAttribute('height', $thumbnail_sd->get_height());
         }
         $thumbnail = $this->addTag($document, $item, 'media:content');
         $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url());
         $thumbnail->setAttribute('fileSize', $thumbnail_sd->get_size());
         $thumbnail->setAttribute('type', $thumbnail_sd->get_mime());
         $thumbnail->setAttribute('medium', $medium);
         $thumbnail->setAttribute('isDefault', 'false');
         if (null !== $thumbnail_sd->get_width()) {
             $thumbnail->setAttribute('width', $thumbnail_sd->get_width());
         }
         if (null !== $thumbnail_sd->get_height()) {
             $thumbnail->setAttribute('height', $thumbnail_sd->get_height());
         }
         if (null !== $duration) {
             $thumbnail->setAttribute('duration', $duration);
         }
     }
     return $this;
 }
Пример #5
0
 public function checkOptionnalMediaGroupNode(\DOMNode $node, FeedItem $entry_item)
 {
     $fields = ['title' => ['dc_field' => \databox_Field_DCESAbstract::Title, 'media_field' => ['name' => 'media:title', 'attributes' => ['type' => 'plain']], 'separator' => ' '], 'description' => ['dc_field' => \databox_Field_DCESAbstract::Description, 'media_field' => ['name' => 'media:description', 'attributes' => []], 'separator' => ' '], 'contributor' => ['dc_field' => \databox_Field_DCESAbstract::Contributor, 'media_field' => ['name' => 'media:credit', 'attributes' => ['role' => 'contributor', 'scheme' => 'urn:ebu']], 'separator' => ' '], 'director' => ['dc_field' => \databox_Field_DCESAbstract::Creator, 'media_field' => ['name' => 'media:credit', 'attributes' => ['role' => 'director', 'scheme' => 'urn:ebu']], 'separator' => ' '], 'publisher' => ['dc_field' => \databox_Field_DCESAbstract::Publisher, 'media_field' => ['name' => 'media:credit', 'attributes' => ['role' => 'publisher', 'scheme' => 'urn:ebu']], 'separator' => ' '], 'rights' => ['dc_field' => \databox_Field_DCESAbstract::Rights, 'media_field' => ['name' => 'media:copyright', 'attributes' => []], 'separator' => ' '], 'keywords' => ['dc_field' => \databox_Field_DCESAbstract::Subject, 'media_field' => ['name' => 'media:keywords', 'attributes' => []], 'separator' => ', ']];
     foreach ($fields as $key_field => $field) {
         $role = true;
         if (isset($field["media_field"]['attributes']['role'])) {
             $role = false;
             foreach ($node->attributes as $attr) {
                 if ($attr->name == 'role') {
                     $role = $attr->value == $field["media_field"]['attributes']['role'];
                     break;
                 }
             }
         }
         if ($field["media_field"]["name"] == $node->nodeName && $role != false) {
             if ($p4field = $entry_item->getRecord(self::$DI['app'])->get_caption()->get_dc_field($field["dc_field"])) {
                 $this->assertEquals($p4field->get_serialized_values($field["separator"]), $node->nodeValue, sprintf('Asserting good value for DC %s', $field["dc_field"]));
                 if (sizeof($field["media_field"]["attributes"]) > 0) {
                     foreach ($node->attributes as $attribute) {
                         $this->assertTrue(array_key_exists($attribute->name, $field["media_field"]["attributes"]), "Checkin attribute " . $attribute->name . " for " . $field['media_field']['name']);
                         $this->assertEquals($attribute->value, $field["media_field"]["attributes"][$attribute->name], "Checkin attribute " . $attribute->name . " for " . $field['media_field']['name']);
                     }
                 }
             } else {
                 $this->fail("Missing media:entry");
             }
             break;
         }
     }
 }
 private function insertOneFeedItem(EntityManager $em, \Pimple $DI, FeedEntry $entry, $public)
 {
     if ($public) {
         $start = 5;
     } else {
         $start = 1;
     }
     $limit = $start + 3;
     for ($start; $start < $limit; $start++) {
         $item = new FeedItem();
         $item->setEntry($entry);
         $actual = $DI['record_' . $start];
         $item->setRecordId($actual->get_record_id());
         $item->setSbasId($actual->get_sbas_id());
         $item->setEntry($entry);
         $entry->addItem($item);
         $em->persist($item);
     }
     $em->persist($entry);
 }
Пример #7
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;
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     try {
         $sql = 'ALTER TABLE `ssel` ADD `migrated` INT NOT NULL DEFAULT "0"';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute();
         $stmt->closeCursor();
     } catch (\Exception $e) {
     }
     $sql = 'SELECT ssel_id, usr_id, name, descript, pub_date, updater, pub_restrict, homelink
             FROM ssel
             WHERE (public = "1" OR homelink="1")
               AND migrated = 0';
     $stmt = $appbox->get_connection()->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $date_ref = new DateTime();
     $n = 0;
     $app['orm.em']->getEventManager()->removeEventSubscriber(new TimestampableListener());
     foreach ($rs as $row) {
         if (null === ($user = $this->loadUser($app['orm.em'], $row['usr_id']))) {
             continue;
         }
         $feed = $this->get_feed($app, $appbox, $user, $row['pub_restrict'], $row['homelink']);
         if (!$feed instanceof Feed) {
             continue;
         }
         $publishers = $feed->getPublishers();
         $entry = new FeedEntry();
         $entry->setAuthorEmail((string) $user->getEmail());
         $entry->setAuthorName((string) $user->getDisplayName());
         $entry->setFeed($feed);
         $entry->setPublisher($publishers->first());
         $entry->setTitle($row['name']);
         $entry->setSubtitle($row['descript']);
         $feed->addEntry($entry);
         $date_create = new DateTime($row['pub_date']);
         if ($date_create < $date_ref) {
             $date_ref = $date_create;
         }
         $entry->setCreatedOn($date_create);
         if ($row['updater'] != '0000-00-00 00:00:00') {
             $date_update = new DateTime($row['updater']);
             $entry->setUpdatedOn($date_update);
         }
         $sql = 'SELECT sselcont_id, ssel_id, base_id, record_id
                 FROM sselcont
                 WHERE ssel_id = :ssel_id
                 ORDER BY ord ASC';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute([':ssel_id' => $row['ssel_id']]);
         $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         foreach ($rs as $row) {
             try {
                 $record = new record_adapter($app, phrasea::sbasFromBas($app, $row['base_id']), $row['record_id']);
                 $item = new FeedItem();
                 $item->setEntry($entry);
                 $entry->addItem($item);
                 $item->setRecordId($record->get_record_id());
                 $item->setSbasId($record->get_sbas_id());
                 $app['orm.em']->persist($item);
             } catch (NotFoundHttpException $e) {
             }
         }
         $app['orm.em']->persist($entry);
         $sql = 'UPDATE ssel SET deleted = "1", migrated="1"
                 WHERE ssel_id = :ssel_id';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute([':ssel_id' => $row['ssel_id']]);
         $stmt->closeCursor();
         $app['orm.em']->persist($feed);
         $n++;
         if ($n % 1000 == 0) {
             $app['orm.em']->flush();
             $app['orm.em']->clear();
         }
     }
     $this->set_feed_dates($date_ref);
     $app['orm.em']->flush();
     $app['orm.em']->clear();
     $app['orm.em']->getEventManager()->removeEventSubscriber(new TimestampableListener());
     return true;
 }
 /**
  * @param Application  $app
  * @param \DOMDocument $document
  * @param \DOMNode     $item
  * @param FeedItem     $content
  * @return $this
  */
 protected function addContent(Application $app, \DOMDocument $document, \DOMNode $item, FeedItem $content)
 {
     $preview_sd = $content->getRecord($app)->get_subdef('preview');
     $preview_permalink = $preview_sd->get_permalink();
     $thumbnail_sd = $content->getRecord($app)->get_thumbnail();
     $thumbnail_permalink = $thumbnail_sd->get_permalink();
     $medium = strtolower($content->getRecord($app)->get_type());
     if (!in_array($medium, ['image', 'audio', 'video'])) {
         return $this;
     }
     if (null === $preview_permalink || null === $thumbnail_permalink) {
         return $this;
     }
     $group = $this->addTag($document, $item, 'media:group');
     $caption = $content->getRecord($app)->get_caption();
     $title_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Title);
     if (null !== $title_field) {
         $str_title = $title_field->get_serialized_values(' ');
         $title = $this->addTag($document, $group, 'media:title', $str_title);
         $title->setAttribute('type', 'plain');
     }
     $desc_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Description);
     if (null !== $desc_field) {
         $str_desc = $desc_field->get_serialized_values(' ');
         $desc = $this->addTag($document, $group, 'media:description', $str_desc);
         $desc->setAttribute('type', 'plain');
     }
     $contrib_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Contributor);
     if (null !== $contrib_field) {
         $str_contrib = $contrib_field->get_serialized_values(' ');
         $contrib = $this->addTag($document, $group, 'media:credit', $str_contrib);
         $contrib->setAttribute('role', 'contributor');
         $contrib->setAttribute('scheme', 'urn:ebu');
     }
     $director_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Creator);
     if (null !== $director_field) {
         $str_director = $director_field->get_serialized_values(' ');
         $director = $this->addTag($document, $group, 'media:credit', $str_director);
         $director->setAttribute('role', 'director');
         $director->setAttribute('scheme', 'urn:ebu');
     }
     $publisher_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Publisher);
     if (null !== $publisher_field) {
         $str_publisher = $publisher_field->get_serialized_values(' ');
         $publisher = $this->addTag($document, $group, 'media:credit', $str_publisher);
         $publisher->setAttribute('role', 'publisher');
         $publisher->setAttribute('scheme', 'urn:ebu');
     }
     $rights_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Rights);
     if (null !== $rights_field) {
         $str_rights = $rights_field->get_serialized_values(' ');
         $rights = $this->addTag($document, $group, 'media:copyright', $str_rights);
     }
     $keyword_field = $caption->get_dc_field(\databox_Field_DCESAbstract::Subject);
     if (null !== $keyword_field) {
         $str_keywords = $keyword_field->get_serialized_values(', ');
         $keywords = $this->addTag($document, $group, 'media:keywords', $str_keywords);
     }
     $duration = $content->getRecord($app)->get_duration();
     if (null !== $preview_permalink) {
         $preview = $this->addTag($document, $group, 'media:content');
         $preview->setAttribute('url', (string) $preview_permalink->get_url());
         $preview->setAttribute('fileSize', $preview_sd->get_size());
         $preview->setAttribute('type', $preview_sd->get_mime());
         $preview->setAttribute('medium', $medium);
         $preview->setAttribute('expression', 'full');
         $preview->setAttribute('isDefault', 'true');
         if (null !== $preview_sd->get_width()) {
             $preview->setAttribute('width', $preview_sd->get_width());
         }
         if (null !== $preview_sd->get_height()) {
             $preview->setAttribute('height', $preview_sd->get_height());
         }
         if (null !== $duration) {
             $preview->setAttribute('duration', $duration);
         }
     }
     if (null !== $thumbnail_permalink) {
         $thumbnail = $this->addTag($document, $group, 'media:thumbnail');
         $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url());
         if (null !== $thumbnail_sd->get_width()) {
             $thumbnail->setAttribute('width', $thumbnail_sd->get_width());
         }
         if (null !== $thumbnail_sd->get_height()) {
             $thumbnail->setAttribute('height', $thumbnail_sd->get_height());
         }
         $thumbnail = $this->addTag($document, $group, 'media:content');
         $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url());
         $thumbnail->setAttribute('fileSize', $thumbnail_sd->get_size());
         $thumbnail->setAttribute('type', $thumbnail_sd->get_mime());
         $thumbnail->setAttribute('medium', $medium);
         $thumbnail->setAttribute('isDefault', 'false');
         if (null !== $thumbnail_sd->get_width()) {
             $thumbnail->setAttribute('width', $thumbnail_sd->get_width());
         }
         if (null !== $thumbnail_sd->get_height()) {
             $thumbnail->setAttribute('height', $thumbnail_sd->get_height());
         }
         if (null !== $duration) {
             $thumbnail->setAttribute('duration', $duration);
         }
     }
     return $this;
 }
Пример #10
0
 /**
  * Retrieve detailled informations about one feed  entry item
  *
  * @param  FeedItem $item
  *
  * @return array
  */
 private function list_publication_entry_item(Application $app, FeedItem $item)
 {
     return ['item_id' => $item->getId(), 'record' => $this->list_record($app, $item->getRecord($app))];
 }
Пример #11
0
 /**
  * Retrieve detailed information about one feed  entry item
  *
  * @param Request   $request
  * @param FeedItem $item
  * @return array
  */
 private function listPublicationEntryItem(Request $request, FeedItem $item)
 {
     return ['item_id' => $item->getId(), 'record' => $this->listRecord($request, $item->getRecord($this->app))];
 }
Пример #12
0
 /**
  * Retrieve detailled informations about one feed  entry item
  *
  * @param  FeedItem $item
  * @return array
  */
 protected function list_publication_entry_item(FeedItem $item)
 {
     $datas = ['item_id' => $item->getId(), 'record' => $this->list_record($item->getRecord($this->app))];
     return $datas;
 }
 /**
  * {@inheritDoc}
  */
 public function getRecord(\Alchemy\Phrasea\Application $app)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getRecord', array($app));
     return parent::getRecord($app);
 }