mongoid / mongodb - replicating/copy records - mongodb

I am building a cms where the site and pages are stored within mongo. I need to be able to create a new site using another site as a template.
For example:
Site A - news page and home page
Create a new site selecting site A as a template, this selects site A and then makes copies of each page site A owns and saves them under Site B
The result
Site A - news page and home page
Site B - news page and home page
Site B will be able to then use site A as a starting point to build there new site.
I am new to Mongo/mongoid so really would like some pointers about the best way to approach this.
Thanks

One way to organise the data is to use collections with the site ID as the namespace, giving you collections like:
site_a.pages
site_a.news
site_a.users
site_b.pages
site_b.news
site_b.users
To create a new site from an existing one, you would copy the relevant collections (possibly excluding .users for example), changing the namespace. That is, copy site_a.pages to site_c.pages. In the shell:
db.site_a.pages.find().forEach( function(x){db.site_c.pages.insert(x)} );
Note that site_a is not a database name, but the namespace of a collection.
There is a limit to the number of collections you can have in a database that might be a problem if you're hosting the CMS in the cloud for many customers. You could get around this by having different databases for different customers. You should read the documentation on this for more details.
Another way to do this is to put the site ID in each document and always filter for this in your queries. Then you would only have a few collections, for example:
pages
news
users
With the documents in those collections having a site_id field:
{
"site_id": "site_a",
"page_title": "Homepage",
...
}
The copying would be similar to above (but with filters and updating the site_id field in the function). I think namespaces for collections is a neater approach however.

Related

Is it possible to automatically redirect a Redmine wiki page to another page?

Is it possible to automatically redirect a Redmine wiki page to another page?
I mean a mechanism similar to Wikipedia's "redirected from..." so I can assign different titles to the same page (with one of them being the main one).
I've just tried it with Redmine 3.1.0. You need access to the database. It's not that complicated, though it is not official.
Insert one line per redirect into the table wiki_redirects. You need the wiki id, which is the project id in normal cases. To find the id look into the wikis table.
Insert:
id: (should be set by the database system)
wiki_id: From which wiki should be redirected (is likely the same as wiki_id if redirecting takes place in a single wiki, and not across projects)
title: The not existing page name from which will be redirected
created_on: some date (I wouldn't use one which is in the future...)
redirects_to: the target page name
redirects_to_wiki_id: the target wiki id
Since your working in the database you have to maintain the entries there. Modifications and deletions have to be done there as well.

Export list of relevant public Facebook group/pages URLS

I am attempting to export a list of URLS all Facebook groups and pages relevant to a search query.
At present, if I search the term ("parents") in the search bar on Facebook, the drop down list is populated, but I cannot find a way to capture these links, and to do so at a large scale (given that there are thousands of groups/pages which include the term "parents")
You can't do that and should not do that. See also the Automated Data Collection Terms. It's not allowed by Facebook.

Entity Property in URL and SEO

I have coded my ASP.NET MVC application in a way that allows stored entities to be retrieved via a friendly name in the URL, for example:
www.mysite.com/artists/james-brown/songs
Where james-brown is a URL friendly string stored on my Artist entity.
Now imagine I add an artist that no one has heard of before, and no one ever navigated to that artist's songs page.
How would Google/Yahoo/Other Search Engines know that my site does indeed have songs for that unknown artist.
Do I create a sitemap and maintain it through code as I add / remove artists?
There are few defined known ways to make the new links visible to search engine world.
XML and HTML Sitemap:
Add it to sitemap and submit it through webmaster tools.
HTML sitemaps are another way to achieve it. If your site has footer sitemap, you can add it to them.
Internal Links
Create internal links from your high ranking pages or highly crawled pages to the new pages. Google and other search engines tend to crawl pages where the content changes frequently. So if you have a refreshed content pages, try adding it to those pages and chances are high for those pages to be discovered quickly.
External Links
Create links from external blogs, company blogs and sites like pagetube.org which can help it to be discovered.
Yeah just add them to either sitemap, internal or even external links

How to design efficient module for star rating with persistent connection using ZF?

My CMS based on Zend Framework.
I use star rating for news, articles, blog posts etc. Star rating is a module, so I include it for different content type via inner API which is a wrapper for :
$view->action($action, $controller, $module, $params);
When I include it to the page with detailed description of news, article ... everything is simple because I call my API method only once, so I make only one call to the DB (MySql).
But I need to include star rating in the items list of the page. There are 20 news on the page. In other case can be more than 100 items. If I use that structure which I have I will make more than 100 call to the MySql. This is not good, right? How can I design the star rating module in right way?
This is like facebook like-buttons which joins to a different content type on the page.

How to setup redirects for a large number of posts

I am working on a major site migration for alpinezone.com . As part of that migration, I moved all the news articles from vbulletin into wordpress cms. The vbulletin articles were previousyl pulled out via a plugin called GARS.
In any event, I have 3400 news articles over the course of five years or so. They are presently in the following format:
news.alpinezone.com/12345
If the title of the news article was "Sugarloaf Sets World Record" then the new location will be
alpinezone.com/sugarloaf-sets-world-record/
Is there a way for me to automate creating the necessary redirects that take the title from the literal page 12345 and convert into a URL?
Finally; the additional trick is that since I did a VB upgrade the existing news articles no longer show up. So going to news.alpinezone.com/12345 won't show anything right now, you need to pull up the forum thread (which is typically hidden) by taking that identifier and going to http://forums.alpinezone.com/showthread.php?12345 to see the actual title. I can pull all this from the WP database, (since all the posts are from a user AlpineZone News).
Any ideas? I'm fairly new to this and the added complexity of subdomains is somethign I am trying to figure out. Thx!
you could make your own showthread.php file in the correct location it was previously located.
have it use the passed id, retrieve the associated record from your database.
Construct the new url by turning the title to lowercase and changing spaces to - and do a redirect via header('Location: new url here');