Creating Documents Directly in the Database Options
KeithChadwick
Posted: Wednesday, June 11, 2008 8:42:14 PM

Rank: Enthusiast

Joined: 4/11/2008
Posts: 36
Location: Ottawa Canada
Hey everyone,

I am trying to create an specific document within umbraco via the database directly. It is one of those things we have no choice but to do, no API or other method is going to solve this one.

Any way, my route for this was to run SQL Trace and create my document in admin center in the normal fashion. I then painstakingly when through the trace data and create a stored procedure that did the exact same thing for a new document. It appears to work but the page does not show up in the xml data and it is not being seen as published. The procedure inserts into the following tables:

UmbracoNode
cmsContent
cmsContentVersion
cmsPropertyData * 3 (one for each of my properties)
cmsDocument
-- then again for published version
cmsContentVersion
cmsPropertyData * 3 (one for each of my properties)
cmsDocument
cmsContentXml

All looks perfect but in the admin center the document in the tree shows the icon correctly as if it is published yet when I save it in the admin center it goes to unpublished.

I must be missing a table somewhere.

Any help would be appreciated as it has been 9 hours of work on this and the grey matter is getting a little tired.

Cheers
Keith
KeithChadwick
Posted: Wednesday, June 11, 2008 9:03:16 PM

Rank: Enthusiast

Joined: 4/11/2008
Posts: 36
Location: Ottawa Canada
Guess you didn't read the second sentence in the post

"It is one of those things we have no choice but to do, no API or other method is going to solve this one."
imayat12
Posted: Wednesday, June 11, 2008 10:03:07 PM

Rank: Addict

Joined: 7/19/2006
Posts: 659
Location: Preston, UK
Keith,

What is the issue that is preventing document creation via api? Doing this directly via db is asking for trouble.

Regards

Ismail

Level 2 certified. If it aint broke dont fix.
KeithChadwick
Posted: Wednesday, June 11, 2008 10:08:48 PM

Rank: Enthusiast

Joined: 4/11/2008
Posts: 36
Location: Ottawa Canada
Actually I got it to work fine. The only issue is that the xml cache is not updated but I will schedule that to happen on the parent node to publish the childs. Doing it directly with the DB is actually not that bad at all.

As per the API not the entire world is Windows and .NET... :-)
darrenjferguson
Posted: Thursday, June 12, 2008 10:21:50 AM

Rank: Fanatic

Joined: 3/19/2008
Posts: 219
Location: London, UK
KeithChadwick wrote:
Actually I got it to work fine. The only issue is that the xml cache is not updated but I will schedule that to happen on the parent node to publish the childs. Doing it directly with the DB is actually not that bad at all.

As per the API not the entire world is Windows and .NET... :-)


I'd have to second Ismail and say that manipulating the DB directly is asking for trouble.

This model is subject to change as Umbraco versions are released.

When you don't have the ability to access the API using C# and .net I'd suggest looking at the webservices.

http://yourhost/umbraco/webservices/api/DocumentService.asmx

You need to enable them, but they should do what you want.




Darren Ferguson - Umbraco level 2 certified
www.darren-ferguson.com - www.fergusonmoriyama.com
VirtualRichard
Posted: Thursday, June 12, 2008 11:23:38 AM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
For updating the xml cache, take a look at XmlGenerate() in the API. I use something like new myObject.XmlGenerate(new System.Xml.XmlDocument()) to make changes to memberships visible (where myObject is a Member object I've been working on). If that's not quite right, you'll certainly be in the right area.

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
KeithChadwick
Posted: Thursday, June 12, 2008 2:17:39 PM

Rank: Enthusiast

Joined: 4/11/2008
Posts: 36
Location: Ottawa Canada
I find it amusing that everyone is saying not to do option A and proposing many other options when there is no knowledge of the landscape in play. There are times when the only point of contact is the database depending on an organizations I.T topologies and security implementations. This is not to say that the my current project has these limitations but I have worked on many where the ability to http requests to an external site within the same organization is forbidden, this is often true within government organizations or on secure networks.

As for the idea of upgrades, in my experience the probability of an upgrade being implemented within a clients environment is less than 0. When development is done in house by an organization you will then see planned upgrades take place.

Thanks for the input everyone but all I was asking was if anyone new if I was missing a table insert/update?


darrenjferguson
Posted: Thursday, June 12, 2008 3:17:40 PM

Rank: Fanatic

Joined: 3/19/2008
Posts: 219
Location: London, UK
The forum is for the use of the community as a whole.

Even if you are not willing or able to consider the alternatives suggested here they will at least be stored here and be searchable who others who encounter similar problems.

Cheers

Darren Ferguson - Umbraco level 2 certified
www.darren-ferguson.com - www.fergusonmoriyama.com
hartvig
Posted: Thursday, June 12, 2008 3:41:04 PM

Rank: Addict

Joined: 3/17/2008
Posts: 957
Location: Nyborg, Denmark
I find it amusing that anyone would insist working with the DB directly when experienced umbraco users say it's a no go'er.

If it's any help I say
"Don't use the db directly as the umbraco api's does more than simply update db tables. They also ensure cache sync and content state in the application. A part from accessing the db directly probably won't work as intended, chances are huge - maybe even guaranteed - that it'll break with even minor updates and you won't get any warnings in upgrade instructions.".

With that quote in mind combined with the fact that it's from the core team, I'm sure that any CIO in your organization would applaud using the API instead of direct SQL. It's simply not best practice.

Jeeeez, did I really start this :-)
pkoutoul
Posted: Thursday, June 12, 2008 4:59:04 PM

Rank: Fanatic

Joined: 8/9/2007
Posts: 284
Location: Kentucky, USA
I can vouch for that. The other day I made what I thought was a very simple change to some property type names in the database and wound up with a content syncing nightmare.





Pete Koutoulas • Fayette County Public Schools • Lexington, Kentucky
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.