Skip to content

Commit

Permalink
refactor: Utilize existing Category record using WikiDiscouragedArtic…
Browse files Browse the repository at this point in the history
…leManager

The WikiDiscouragedArticleManager has been created to leverage the existing Category table for storing and updating Wiki Edu discouraged articles. This change eliminates the need for creating a new record type in the database, ensuring the utilization of the pre-existing Category record for managing discouraged articles. The updates will occur through the DailyUpdate mechanism.
  • Loading branch information
Abishekcs committed Nov 1, 2023
1 parent 1f4bd31 commit d9a3fca
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/wiki_discouraged_article_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true
require_dependency "#{Rails.root}/lib/importers/category_importer"

class WikiDiscouragedArticleManager
def retrieve_wiki_edu_discouraged_articles
category_titles = [ENV['blocked_assignment_category'],
ENV['warning_assignment_category']]

category_titles.each do |category_title|
discouraged_articles = CategoryImporter.new(Wiki.default_wiki)
.page_titles_for_category(category_title)
update_or_save_discouraged_articles(discouraged_articles, category_title)
end
end

private

def update_or_save_discouraged_articles(discouraged_articles, category_title)
existing_article = Category.find_by(source: category_title)

if existing_article
# Update the existing article
existing_article.update(article_titles: discouraged_articles)
else
# Create a new entry in the database
article_details = {
article_titles: discouraged_articles,
name: 'Wiki_Edu_Discouraged_Articles',
source: category_title,
wiki_id: en_wiki.id
}
Category.create(article_details)
end
end

def en_wiki
Wiki.find_by(language: 'en', project: 'wikipedia')
end
end

0 comments on commit d9a3fca

Please sign in to comment.