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

[chore] Fixes #42 - Import old wordpress data and convert to markdown… #98

Merged
merged 1 commit into from
Dec 10, 2015

Conversation

benichu
Copy link
Member

@benichu benichu commented Dec 3, 2015

Left TODOS:

  • document execution of rake command on heroku
  • cleanup NewsItem model
  • controller tests for news_items#show and news_items#index
  • unit tests .published

PROBLEMS:

  • Overriding thoughtbot/administrate does not work as advertised

Review on Reviewable

@benichu benichu self-assigned this Dec 3, 2015
@benichu
Copy link
Member Author

benichu commented Dec 3, 2015

waiting for #83 to be merged before finishing it up

@benichu benichu force-pushed the chore-bt-42-import-old-data branch 2 times, most recently from fff419d to 57c4060 Compare December 5, 2015 01:00
@@ -11,7 +11,11 @@
devise_for :users

resources :events, only: [:index, :show]

# NewsItem compatibility with old wordpress Posts url
get "/:year/:month/:slug", to: "news_items#show", constraints: { year: /\d{4}/, month: /\d{2}/ }

Choose a reason for hiding this comment

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

Line is too long. [98/80]

@benichu benichu force-pushed the chore-bt-42-import-old-data branch 2 times, most recently from baffaf6 to 2aca4d1 Compare December 5, 2015 17:04
# NOTE: [legacy]
# - This is also where we imported the old wordpress posts
# - The `slug` is purely used to store the old wordpress slug and make sure we
# can still resolve: http://www.montrealrb.com/[post_date:YYYY]/[post_date:MM]/[post_name]

Choose a reason for hiding this comment

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

Line is too long. [92/80]

@benichu
Copy link
Member Author

benichu commented Dec 5, 2015

@montrealrb/organizers If anyone of you is interested to do a code-review and merge that PR, it takes care of the following:

  • Generate a wordpress database dump in db/legacy.yml
  • Create a rake task to import that legacy data in the news_items table
  • Add some unit and controller specs for NewsItem
  • Deal with legacy urls: /YYYY/mm/a-wordpress-slug

Note: you will noticed that I imported all the posts from wordpress (hopefully) but that I only marked the 10 most recent, because some manual markdown cleanup work will need to be done, and I think we should focus on the most recent posts for launch and after that work our way back...

@benichu benichu added this to the Site live for Meetup milestone Dec 5, 2015
@benichu benichu removed their assignment Dec 5, 2015
@benichu benichu changed the title [WIP] [chore] Fixes #42 - Import old wordpress data and convert to markdown… [chore] Fixes #42 - Import old wordpress data and convert to markdown… Dec 5, 2015
@benichu
Copy link
Member Author

benichu commented Dec 5, 2015

code reviewer, please assign the PR to yourself...

@benichu
Copy link
Member Author

benichu commented Dec 5, 2015

Will also Fix #99

get :index
end

it "populates an array of news_items with the most recently published first" do

Choose a reason for hiding this comment

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

Line is too long. [83/80]

@mdeloupy
Copy link
Contributor

mdeloupy commented Dec 6, 2015

@montrealrb/organizers I did a quick review, but don't want to take the responsibility of merging this... Anyone else up for it ?

@news_item = NewsItem.published.find(params[:id])
@news_item = news_item_scope.where(slug: params[:slug]).first ||
news_item_scope.where(id: params[:id]).first ||
raise(ActiveRecord::RecordNotFound)
Copy link
Contributor

Choose a reason for hiding this comment

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

@benichu Could we extract as a method and pushed into the model? e.g.

NewsItem.fetch_published!(params[:id], params[:slug])

This allow to document the method, as I'm unsure why this is required.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. The reason why it's required is to still resolve old wordpress links (ex: if someone clicks on an post url from google)
I'll extract that logic into a tested and documented class method tonight or later today...

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, we probably should do a redirect to the correct URL, but let's do that as a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, just created a ticket for that #151
Until then, I am also going to leave the object loading methods as-is in the controller, I'll just add a comment to the method.

records = YAML.load_file "#{Rails.root}/db/legacy.yml"
records.each do |data|
news_item = NewsItem.new
published_at = data["post_date"]
Copy link
Contributor

Choose a reason for hiding this comment

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

@benichu Since there's a couple of changes that need to be made, how would you feel call #fetch on these?

 data.fetch("post_date")

I like exceptions thrown when the key I expect doesn't exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

published_at could be nil, if the original post is a draft (which will not happen with the collection I am parsing, as the original query generated only published posts with a date). So it's not really necessary to catch the non-existence of that key.

NOTE: It's a one-off task anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite what I meant -- the key should exists, but the value might be nil :-) I should have clarified that this would be for all keys we're accessing in the hash. But happy to move on given it's a one-off task.

@nicholasjhenry
Copy link
Contributor

Awesome, @benichu! I ran this locally -- looks like we got us a site :-)

@benichu
Copy link
Member Author

benichu commented Dec 9, 2015

Cool, I'll do a couple of the fixes you mentioned and we are good to merge, talk to you later...

@benichu benichu force-pushed the chore-bt-42-import-old-data branch from a96d5f9 to 0806774 Compare December 10, 2015 00:36
@benichu
Copy link
Member Author

benichu commented Dec 10, 2015

@nicholasjhenry rebased, I'll merge tomorrow morning.

@sophiedeziel
Copy link
Member

Haha you have to rebase again 😛

… [WIP]

- Generate a wordpress database dump in db/legacy.yml
- Create a rake task to import that legacy data in the news_items table
- Add some unit and controller specs for NewsItem
- Deal with legacy urls: /YYYY/mm/a-wordpress-slug
@benichu benichu force-pushed the chore-bt-42-import-old-data branch from 0806774 to 3cfb664 Compare December 10, 2015 12:09
benichu added a commit that referenced this pull request Dec 10, 2015
[chore] Fixes #42 - Import old wordpress data and convert to markdown…
@benichu benichu merged commit 9a2f744 into master Dec 10, 2015
@benichu benichu deleted the chore-bt-42-import-old-data branch December 10, 2015 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants