How do I go about selecting Unpublished nodes in Umbraco?
I know that I can retreive published content using:
Umbraco.Content(id)
However, I need to be able to essentially get all nodes whether they are published or not for an automated update process I am writing.
The process uses the Lucene index to build up a dictionary containing a unique id as the key and the related Umbraco page (unpublished or published) as the value so that I can then access this with the content service and update existing pages and create new ones if necessary.
// Loop through web service tours and create a page if it does not exist for the current culture
foreach (GroupTourMasterData web_service_item in web_service)
{
IContent umbraco_node = null;
List<JSONTourInstance> instances = new List<JSONTourInstance>();
if (umbraco_tours.ContainsKey(web_service_item.Id))
{
// If the tour code already exists then get the Umbraco page
int id = umbraco_tours[web_service_item.Id];
umbraco_node = cs.GetById(id);
}
else
{
// If not create a new tour page
if (parentNode != null)
{
umbraco_node = cs.CreateContent(web_service_item.Title, parentNode.Id, "tour");
}
}
}
Where possible I want to try and avoid the content service for querying existing items as it is incredibly slow.
I have checked and my index is successfully supporting unpublished content but how do I then access this in code, edit it then publish it as at the moment Umbraco.Content is not working for me.
Because they are two different IDs.
One is the Umbraco ID and one is the internal ID within our company software which is the process that is populating these pages automatically.
I've now refined the first stage of my code to do the following which works a treat.
if (tours.Where(x => x.Fields["nodeTypeAlias"] == "tour").Count() > 0)
{
foreach (SearchResult tourRecord in tours.Where(x => x.Fields["nodeTypeAlias"] == "tour"))
{
int axumId = 0;
int umbracoId = 0;
Int32.TryParse(tourRecord.Fields["tripId"], out axumId);
Int32.TryParse(tourRecord.Fields["id"], out umbracoId);
if (axumId != 0 && umbracoId != 0 && !umbraco_tours.ContainsKey(axumId))
{
umbraco_tours.Add(axumId, umbracoId);
}
}
}
// Loop through web service tours and create a page if it does not exist for the current culture
foreach (GroupTourMasterData web_service_item in web_service)
{
IContent umbraco_node = null;
List<JSONTourInstance> instances = new List<JSONTourInstance>();
if (umbraco_tours.ContainsKey(web_service_item.Id))
{
// If the tour code already exists then get the Umbraco page
int id = umbraco_tours[web_service_item.Id];
if (id == 1641)
{
var abreak = "break";
}
try
{
umbraco_node = cs.GetById(id);
}
catch (Exception ex)
{
Log.Error("Non Fatal : Tour master with id " + id + " not found. Skipping to next tour.", ex);
}
}
else
{
// If not create a new tour page
if (parentNode != null)
{
umbraco_node = cs.CreateContent(web_service_item.Title, parentNode.Id, "tour");
}
}
if (umbraco_node != null){
// do stuff
}
}
Selecting UnPublished nodes in Umbraco 7
Hi all,
How do I go about selecting Unpublished nodes in Umbraco? I know that I can retreive published content using:
However, I need to be able to essentially get all nodes whether they are published or not for an automated update process I am writing.
The process uses the Lucene index to build up a dictionary containing a unique id as the key and the related Umbraco page (unpublished or published) as the value so that I can then access this with the content service and update existing pages and create new ones if necessary.
I then do the following:
Where possible I want to try and avoid the content service for querying existing items as it is incredibly slow.
I have checked and my index is successfully supporting unpublished content but how do I then access this in code, edit it then publish it as at the moment Umbraco.Content is not working for me.
Cheers,
Jason
Jason,
The line
after getting that you are just looking to get property tripId why not just do
Regards
Ismail
Hi Ismael,
Because they are two different IDs. One is the Umbraco ID and one is the internal ID within our company software which is the process that is populating these pages automatically.
I've now refined the first stage of my code to do the following which works a treat.
I then do this in the second stage:
is working on a reply...