Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - CS-5982 - Deleting section with many articles from backend fails #1370

Open
wants to merge 2 commits into
base: v4.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions newscoop/classes/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,13 @@ public function delete()

$webcode = $article->getWebcodeEntity();

$em->remove($webcode);
$em->flush();
if (null !== $webcode) {
try {
$em->remove($webcode);
$em->flush();
} catch(\Exception $e) {}
}

$em->detach($article);

$tmpObj = clone $this; // for log
Expand Down
43 changes: 34 additions & 9 deletions newscoop/classes/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,46 @@ public function copy($p_destPublicationId, $p_destIssueNumber,
*/
public function delete($p_deleteArticles = false, $p_deleteArticleTranslations = false)
{
$numArticlesDeleted = 0;
$articlesCount = 0;
if ($p_deleteArticles) {
$languageId = null;
if (!$p_deleteArticleTranslations) {
$languageId = $this->m_data['IdLanguage'];
}
$articles = Article::GetArticles($this->m_data['IdPublication'],
$this->m_data['NrIssue'],
$this->m_data['Number'],
$languageId);
$numArticlesDeleted = count($articles);
foreach ($articles as $deleteMe) {
$deleteMe->delete();

$articlesCount = Article::GetArticles(
$this->m_data['IdPublication'],
$this->m_data['NrIssue'],
$this->m_data['Number'],
$languageId,
null,
true
);

$batch = 30;
$steps = ($articlesCount > $batch) ? ceil($articlesCount / $batch) : 1;

for ($i = 0; $i < $steps; $i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not better do this with doctrine native query and hydrate to array or event run a DELETE query? Or ->delete() does to much magic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check line 211, it invokes delete on \Article object, where inside that method it removes all the associations to that article, geo maps, webcodes, images, topics, article data etc, this would then require a huge refactor I guess

$offset = $i * $batch;
$articles = Article::GetArticles(
$this->m_data['IdPublication'],
$this->m_data['NrIssue'],
$this->m_data['Number'],
$languageId,
array(
'LIMIT' => array(
'START' => $offset,
'MAX_ROWS' => $batch
)
)
);

foreach ($articles as $article) {
$article->delete();
}
}
}

$tmpData = $this->m_data;
$success = parent::delete();
if ($success) {
Expand All @@ -197,7 +222,7 @@ public function delete($p_deleteArticles = false, $p_deleteArticleTranslations =
}
}

return $numArticlesDeleted;
return $articlesCount;
} // fn delete

/* --------------------------------------------------------------- */
Expand Down