Where is the content stored in Umbraco database? - sql

I've inherited a database for an Umbraco website that I need to pull out the content so it can be loaded into another CMS.
I've restored the SQL Server database and I still cannot find where what is essentially 'blog posts' would be stored.
What I'm looking to do is something like:
SELECT *
FROM blogposts
Thanks

Unfortunately, it won't be quite that simple. Almost everything in umbraco has representation in the umbracoNode table.
Then, all of the custom property data that you have will be stored in these two tables: cmsPropertyData and cmsPropertyType.
I've found that I can get most of what I want with queries like this:
SELECT TOP 1000 *
FROM cmsPropertyData pd
INNER JOIN cmsPropertyType pt
ON pt.id = pd.propertytypeid
INNER JOIN umbracoNode n
ON n.id = pd.contentNodeId
WHERE n.id = 1853
However, you're after info about a specific document type, so you're might look more like this:
SELECT TOP 1000 *
FROM cmsPropertyData pd
INNER JOIN cmsPropertyType pt
ON pt.id = pd.propertytypeid
INNER JOIN cmsContent c
ON c.nodeId = pd.contentNodeId
INNER JOIN cmsContentType ct
ON ct.nodeId = c.contentType
WHERE ct.alias = 'BlogPost'
And then, you'd probably be getting data back for multiple versions of each blog post node, so you'd need to do more joins with the cmsContentVersion table to get just the latest data.
You might think about trying to sidestep some of the database queries and try using the xml cache on disk that already exists. You can find an xml representation of all of the published content at App_Data\umbraco.config. You should be able to trim it down to just the xml representation of the Blog Posts.
I was also reading at this stackoverflow post that you can just export by document type as a Package. You could go to Developer->Packages->Created packages and right click to create. Then in the Package Contents tab, just check the Blog Post document type. Not sure if that will be useful to you because I haven't tried that myself. Looks promising though.

Related

Where in the Sitefinity database is content stored?

I've successfully migrated 1,000s of news items and other content from Sitefinity 5 to Wordpress after hours of excruciating analysis and sheer luck with guessing but have a few items that are still left over. Specifically the pages. I know a lot of the content is stored in very obscure ways but there has to be somebody who has done this before and can steer me in the right direction.
My research (and text-search against the DB) has found the page titles etc but when I search the content I get nothing. My gut tells me that the content is being stored in binary form, can anyone confirm if this is the case?
Sitefinity documentation is only helpful if you're a .net developer who has a site set up in Visual Studio (as far as I've seen).
This is probably the most obfuscated manner of storing content that I've ever encountered. After performing text searches against the database I've finally found where the content is stored but it's not a simple process to get it out.
Pages' master record appears to be sf_page_node, there are related tables:
sf_object_data (page_id is related to sf_page_node.content_id)
sf_draft_pages (page_id is related to sf_page_node.content_id)
sf_page_data (content_id is related to sf_page_node.content_id)
sf_control_properties (control_id is related to sf_object_data.id)
So you could get the info you need with a query like this:
select * from
[sf_page_node]
join sf_object_data on sf_page_node.content_id = sf_object_data.page_id
join sf_control_properties on sf_object_data.id = sf_control_properties.control_id
Other things to consider:
the parent_id field is related to the sf_page_node table, so if you're writing a script, be sure to query this as well
the page may have a banner image, you will pick up the "place_holder" value as 'BannerHolder' with a caption of "Image" The image may be stored as blobs in sf_media_content, you should handle this separately. The "nme" value of 'ImageId' will have a GUID in the "val" column. You can query sf_media_content with this value as "content_id" the actual binary data is stored in sf_chunks, they relate on "file_id"
My revised query taking into account what I'll need to migrate content is below:
select
original.content_id,
original.url_name_,
original.title_,
parent.id,
parent.url_name_,
parent.title_,
place_holder,
sf_object_data.caption_,
sf_control_properties.nme,
val
from [sf_page_node] original
join sf_object_data on original.content_id = sf_object_data.page_id
join sf_control_properties on sf_object_data.id = sf_control_properties.control_id
join sf_page_node parent on original.parent_id = parent.id
I hope this helps someone!
You don't need the version items in this case - as you already found out, it stores the previous version of the pages in binary format.
The current live pages' data is available in sf_control_properties and sf_object_data tables. You need to join these together with sf_page_data and sf_page_node and you will get the full picture.
Depending on your requirements, it may be easier to do a GET request to each page and parse the returned html response.

What do I need to change to get a count of deleted, locked posts from SEDE?

I'm trying to query for some stats on how many posts have been deleted as spam/abusive. I've got what I think should work, but the numbers it throws out don't make sense.
Since posts deleted this way are characterized by being both deleted and locked, I'm querying for those attributes by looking at the PostHistory table.
My initial query looks like this:
SELECT
COUNT(DISTINCT ph0.PostId)
FROM
PostHistory ph0
INNER JOIN
PostHistory ph1
ON
ph0.PostId = ph1.PostId AND
ph1.PostHistoryTypeId = 12
WHERE
ph0.PostHistoryTypeId = 14
That one throws up a count of 397, which doesn't make sense. There are at least 6485 posts that have been identified as spam on Stack Overflow. So, to check that query, I'm using a debugging query that outputs the post bodies:
SELECT
Body
FROM
PostsWithDeleted
WHERE
Id IN
(SELECT
DISTINCT ph0.PostId
FROM
PostHistory ph0
INNER JOIN
PostHistory ph1
ON
ph0.PostId = ph1.PostId AND
ph1.PostHistoryTypeId = 12
WHERE
ph0.PostHistoryTypeId = 14)
The bodies that outputs just plain aren't spam - certainly not of the kind I'm used to seeing. A sample:
All I can say is that you need to subclass UIView and make it a delegate of UIGestureRecognizerDelegate and UICollectionViewDelegate, then in your UIView subclass, do the following, I can't give out anymore information on this because the code, although owned by myself, is proprietary to the point of probably enraging quite a few organizations that I've used this for, so here's the secret...
I'm looking for an application or a social wall plugin to be added to a project. After looking at Wordpress and finally sifting through all the plugins (maybe all), I have come to a conclusion the plugins are not giving me enough customization options. For example, customizing the registration form. I need to add javascript for a combo box in order to display different options dependI added a movieclip here, and a number. To get an effect, like a star with a number...
The message is "starCount is not a child of a caller". I don't know...
So, what am I doing wrong that means I'm not selecting deleted, locked posts, and what do I need to do to fix it?
Although your query output is exactly the same as mine I believe my attempt gives a clear view of what you're trying to achieve.
If you find this not giving you the desired output, there must be some more logic into finding these posts that you mention.
Below query returns a number of posts that in their history have been marked as both Locked and Deleted at least once.
SELECT COUNT(*)
FROM (
SELECT
ph.PostId
FROM
PostHistory ph
INNER JOIN PostHistoryTypes pht ON
ph.PostHistoryTypeId = pht.id
WHERE
pht.Name IN ('Post Locked', 'Post Deleted')
GROUP BY ph.PostId
HAVING COUNT(DISTINCT ph.PostHistoryTypeId) >= 2
) foo
You've included below message and it seems alright with your query.
Since posts deleted this way are characterized by being both deleted and locked, I'm querying for those attributes by looking at the PostHistory table.

Search through Users with dynamic attributes with SQL

.Hi i'm working with Asp and SQL-Server and i have no problem with writing dynamic query
I'm trying to Write a search page for searching people.
I have 3 related tables:
See my table diagram in : http://tinypic.com/r/21159go/5
What i'm trying to do is to design a search page that a person can search users with a dynamic number of attributes.
Example:
think that a username called "User1" has 3 attributes named "Attr1", "Attr2" and "Attr3" related to him in "UserAttributes" table and "User2" has 3 attributes named "Attr1", "Attr2" and "Attr4".
Attribute names and other bunch of items unrelated to search function saved in "Attributes" Table. This is because i want to relate an attribute between multiple users. and their values are stored in "UserAttributes" table.
Well someone wants to search upon "Attr1" and "Attr2" and wants to return all users that have "Attr1" and "Attr2" with specific value.
I need a query to know how to implement this. I can write a dynamic query with asp.net so if someone please give me a query for this one example i have brought, i would be thankful
P.S. This is not my real database. my real database is much more complex and has more fields and tables but i just cut it and brought only necessary items. and because attributes are very dynamic they can't be embedded in table columns.
Thanks in advance
Based on your DB diagram your code would be something like this
update:
SELECT u.*
FROM users AS u
LEFT OUTER JOIN UserAttributes AS ua1
ON u.USER_ID = ua1.USER_ID
LEFT OUTER JOIN UserAttributes AS ua2
ON u.USER_ID = ua2.USER_ID
WHERE (
ua1.attribute_id = 'att1'
AND ua.attribute_value = 'MyValue' )
AND (
ua2.attribute_id = 'att2'
AND ua.attribute_value = 'MyValue2' )
In where clause you would specify the attirbute_Id and what value you are expecting out of it. Than just decide if you want to restrict users to have all values match or just one of them, in that case modify AND between statements to be OR
if you just want to do this quick and dirty you can create your own class library that can create adhoc sql that will pass to the database.
if you want more organized matter, create SP that will bring back users and accepts any left of id and value. Do a lot of that by passing list separated by comma, colon or semicolon. Than split it up in SP and filter results based on those values
there are many other alternatives like EntityFramework, LINQ-to-SQL and other options, just need to figure out what works best for you, how much time you want to spend on it and how easy will it be to support later.

SQL Query Accross Three Tables Requiring Different Joins

I have 3 tables. An Applications (relevant field is AppID) table containing information about various application available to download, a Packages table (relevant field is PackageID) containg information on the various downloadable items available and an App/Packages table (relevant field is AppID and PackageID) which shows which packages should be downloaded for each application. I need a query to find out which packages are not related to a specific application.
My idea was to INNER JOIN Applications to AppPackages to get a list of all the packages that are related to an Application and then OUTER JOIN this resultant set to Packages and find all the null results to show which packages were not related.
The problem is I can't seem to work out how to chain these queries. Subqueries don't seem to work, and EXIST/NOT EXIST requires information from the outer query which I just can't make work. I'm assuming there's something simple I'm mising, but all the literature I read is for two tables, never more than two.
This is my best attempt, but the EXISTS part doesn't work for the reason mentioned above.
SELECT Packages.PackageID FROM Packages WHERE NOT EXISTS
(Select AppPackages.PackageID, AppPackages.AppID FROM AppPackages WHERE AppPackages.AppID = #AppID)
Thanks in advance for any help :)
Cheers,
Matt :)
I need a query to find out which packages are not related to a specific application.
SELECT
*
FROM
Packages p
WHERE
NOT EXISTS (
SELECT 1
FROM Applications a
INNER JOIN AppPackages ap ON ap.PackageId = p.PackageId
WHERE ap.AppId = <Your App ID>
)
I would try sth like this:
SELECT Packages.PackageID FROM Packages WHERE Packages.PackageID NOT IN
(Select AppPackages.PackageID FROM AppPackages WHERE AppPackages.AppID = #AppID)

Nhibernate: left outer join on subquery

Update take 2
here is the two queries i'm working with (paging is omitted in both queries)
i'd like to get the following query
SELECT *
FROM product
LEFT OUTER JOIN
(
SELECT *
FROM Cart
LEFT OUTER JOIN
cartproducts
ON Cart.Id = cartproducts.Cart_id
WHERE Cart.username = 'user'
)
AS CartFiltered
ON product.Id = CartFiltered.product_id
but i always seem to get
SELECT *
FROM product
LEFT OUTER JOIN
cartproducts
ON product.Id = cartproducts.Product_id
LEFT OUTER JOIN
Cart
ON
cartproducts.cart_id = cart.id
WHERE Cart.username = 'user'
How can i manage to create the first type of query?
I hope my question is clearer :) lack of clarity is sometimes a great enemy of mine :p
Update:
FWIW, i still haven't found the answer, and am currently loading the paged product data and the whole cart to display the correct object.
Crude solution but it works and it beats the combinatorials i've been through trying to make the Criteria API recognize me as its master. I would be very interested if somebody could happen to point me in the right direction though ;)
Hello,
i'm having a hard time writing the following query in the Criteria API, and i don't really see how to do it: i hope some people can help.
On the database, i have products. Theses products can be in many carts (one cart per user), and each cart can contain many products, so we have a manytomany relationship.
I would like to display a list of every product, along with a small icon next to it to inform the user that this particular product is already in the cart. What i did is i asked NHibernate for my products, and to do a left outer join on carts filtered by the cart's owner.
Dim critPage As ICriteria = Session.CreateCriteria(GetType(Product)) _
.SetFirstResult(pageNumber * itemsPerPage).SetMaxResults(itemsPerPage) _
.CreateCriteria("Carts", "c", SqlCommand.JoinType.LeftOuterJoin) _
.SetProjection(plist) _
.SetResultTransformer(New TypedResultTransformer(Of ProductWithCartInfo)) _
.Add(Expression.Eq("c.User", username))
the projection list is here to reduce the number of columns to what's interesting for the ProductWithCartInfo class. It contains only property projections.
The problem is that with this query, the cart filtering is applied to the whole result set and i don't see every product with its presence in the user's cart, but rather every product in the user's cart.
Is it possible to do a left outer join on a subquery with the Criteria API in Nhibernate? For information, i would like to keep it in the Criteria API if possible.
Thanks
I'm not sure I entirly follow your issue but it sounds very similar to an issue I had. I seems that when you have the nested (sub) criteira with NHibernate you loose some of the control. I was able to get around my issue but aliasing my tables instead of using the nested criteira.
Possibly try...
criteria.CreateAlias("Cart", "Cart", JoinType.LeftOuterJoin);
and then your filter on the cart will have to be an OR condition
ICriterion cartCriterion = Restrictions.Eq("Cart.User", username);
customerCriterion = Restrictions.Or(customerCriterion, Restrictions.IsNull("Cart.User"));
criteria.Add(customerCriterion);
Let me know if that helps you out... if not... maybe post the SQL that your criteria above is generating and where it needs to change.
Good Luck