Skip to content

Commit

Permalink
[API] improve removing snippets, and saving new articles
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilles107 committed Sep 22, 2014
1 parent ce598fd commit edaa04f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion newscoop/library/Newscoop/Entity/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ public function addSnippet(Snippet $snippet)
public function removeSnippet(Snippet $snippet)
{
if ($this->snippets->contains($snippet)) {
$this->snippets->remove($snippet);
$this->snippets->removeElement($snippet);
$snippet->removeArticle($this);
}

Expand Down
2 changes: 1 addition & 1 deletion newscoop/library/Newscoop/Entity/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function removeArticle(Article $article)
{
if ($this->articles->contains($article)) {
$article->removeSnippet($this);
$this->articles->remove($article);
$this->articles->removeElement($article);
}

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ public function createArticleAction(Request $request, $language, $publication, $
public function patchArticleAction(Request $request, $number, $language)
{
$params = array();
$user = $this->getUser();
$translator = \Zend_Registry::get('container')->getService('translator');
// Fetch article
$articleObj = $this->getArticle($number, $language);


$content = $this->get("request")->getContent();
if (!empty($content)) {
$params = json_decode($content, true); // 2nd param to get as array
Expand All @@ -159,7 +165,8 @@ public function patchArticleAction(Request $request, $number, $language)
if ($inputManipulator::getVar(array('inputObject' => $params, 'variableName' => 'created', 'checkIfExists' => true))) {
$clean['creationDate'] = date_format(date_create_from_format(DATE_ATOM, $inputManipulator::getVar(array('inputObject' => $params, 'variableName' => 'created'))), 'Y-m-d H:i:s');
}
if ($inputManipulator::getVar(array('inputObject' => $params, 'variableName' => 'published', 'checkIfExists' => true))) {

if ($articleObj->isPublished() && $inputManipulator::getVar(array('inputObject' => $params, 'variableName' => 'published', 'checkIfExists' => true))) {
$clean['publishDate'] = date_format(date_create_from_format(DATE_ATOM, $inputManipulator::getVar(array('inputObject' => $params, 'variableName' => 'published'))), 'Y-m-d H:i:s');
}

Expand All @@ -182,12 +189,6 @@ public function patchArticleAction(Request $request, $number, $language)
}
}

$user = $this->getUser();
$translator = \Zend_Registry::get('container')->getService('translator');

// Fetch article
$articleObj = $this->getArticle($number, $language);

$articleTypeObj = $articleObj->getArticleData();
$articleType = new \ArticleType($articleTypeObj->m_articleTypeName);
$fields = $articleType->getUserDefinedColumns(null, true, true);
Expand Down

0 comments on commit edaa04f

Please sign in to comment.