function test_article() { $article = new Article(9000001,9000002,9000003,9000004); // Test create $article->create("Unit Test Long Name", "Unit Test Short Name", "fastnews"); $this->assertTrue($article->exists()); // Test SET functions $article->setTitle("Unit Test New Title"); $article->setCreatorId(9000005); $article->setOnFrontPage(true); $article->setOnSection(true); $article->setWorkflowStatus('Y'); $article->setKeywords("Unit, Test"); $article->setIsIndexed(true); // Test GET functions $articleCopy = new Article(9000001, 9000002, 9000003, 9000004, $article->getArticleId()); $this->assertEquals(9000001, $articleCopy->getPublicationId()); $this->assertEquals(9000002, $articleCopy->getIssueNumber()); $this->assertEquals(9000003, $articleCopy->getSectionNumber()); $this->assertEquals(9000004, $articleCopy->getLanguageId()); $this->assertEquals(9000005, $articleCopy->getCreatorId()); $this->assertEquals("Unit Test New Title", $articleCopy->getTitle()); $this->assertEquals(true, $articleCopy->onFrontPage()); $this->assertEquals(true, $articleCopy->onSection()); $this->assertEquals('Y', $articleCopy->getWorkflowStatus()); $this->assertEquals("Unit, Test", $articleCopy->getKeywords()); $this->assertEquals(true, $articleCopy->isIndexed()); // Test DELETE functions $article->delete(); $this->assertFalse($article->exists()); }
$xmlArticle = get_object_vars($article); $articleTypeObj = $articleObj->getArticleData(); $dbColumns = $articleTypeObj->getUserDefinedColumns(false, true); $articleTypeFields = array(); foreach ($dbColumns as $dbColumn) { $fieldName = $dbColumn->getPrintName(); $field = strtolower($fieldName); if (!isset($article->{$field})) { $errorMessages[$articleCount][] = 'The article type field "<i>' . $fieldName . '</i>" does not match any field from XML input file.<br />'; continue; } $articleFields[$field] = true; $articleTypeObj->setProperty($dbColumn->getName(), (string) $article->{$field}); } // Updates the article creator and author $articleObj->setCreatorId($g_user->getUserId()); $isAuthorFromCreator = FALSE; if (isset($article->author) && !empty($article->author)) { $authorName = (string) $article->author; } else { $authorName = (string) $g_user->getRealName(); $isAuthorFromCreator = TRUE; } $authorObj = new Author($authorName); if (!$authorObj->exists()) { $authorData = Author::ReadName($authorName); if ($isAuthorFromCreator) { $authorData['email'] = $g_user->getEmail(); } $authorObj->create($authorData); }
/** * Creates an legacy Article based on a feed entry * * @param \NewscoopIngestPluginBundle\Entity\Feed\Entry $entry * * @return \Article Returns legacy article opbject */ protected function createLegacy(\Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry) { $feed = $entry->getFeed(); $publication = $feed->getPublication(); // Determine issue if ($feed->getIssue() === null) { $issue = $this->em->getRepository('\\Newscoop\\Entity\\Issue')->findOneBy(array('publication' => $publication, 'language' => $entry->getLanguage(), 'workflowStatus' => 'Y'), array('number' => 'DESC')); } else { $issue = $feed->getIssue(); } $articleType = $this->em->getRepository('\\Newscoop\\Entity\\ArticleType')->findOneByName('Newswire'); $article = new \Article($entry->getLanguage()->getId()); $createSuccess = $article->create($articleType->getName(), $entry->getTitle(), $publication->getId(), $issue->getNumber(), $entry->getSection()->getNumber()); $article->setCreatorId(1); $article->setWorkflowStatus('N'); $article->setKeywords(implode(',', $entry->getKeywords())); $article->setCommentsEnabled(1); $article->setIsLocked(false); // ArticleType data $this->setArticleDataLegacy($article, $entry); // Dates $article->setCreationDate($entry->getCreated()->format('Y-m-d H:i:s')); $article->setProperty('time_updated', $entry->getUpdated()->format('Y-m-d H:i:s')); // Author $this->setArticleAuthorsLegacy($article, $entry); $this->setArticleImagesLegacy($article, $entry); try { $entry->setArticleId($article->getArticleNumber()); $articleAdded = $article->commit(); $this->em->persist($entry); $this->em->flush(); } catch (\Exception $e) { throw new Exception('Could not publish article.'); } // Topics $this->setArticleTopics($article->getArticleNumber(), $entry->getFeed()->getTopics()); // Webcode $articleEntity = $this->em->getRepository('Newscoop\\Entity\\Article')->findOneByNumber($article->getArticleNumber()); if (!is_null($articleEntity)) { $this->webcode->setArticleWebcode($articleEntity); } return $article; }