Sitecore: Get child items of parent item when the items are in publish restricted period - sitecore

I am trying to get the children items of a Item.,of which some of the child items applied publish restrictions and there end date had expired.
I want to collect all the child items, whether it's end expired or not.
when i debugged my code i got only those items which have end date in time.
I have used following code
var childItems=item.GetChildren();
the child items collection is collecting only those child items which have there end date in time.
is there any method to collect all the items??
I have asked in sitecore forum, they asked to get child items from master database, but that approach also not working. i have tried following code also.
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentNode= master.GetItem("ItemNAme");
var childItems=parentNode.GetChildren();
The childitems is only collecting those child items whose end date is not expired
Please suggest me some solution for this
Thanks in advance
-Vaibhav

What you said about going to the master database is correct, as the master contains all versions of all pieces of content, not just publicly published content. I would wrap your code in a SecurityDisabler() in case that is somehow interfering with getting the right items.
using(new SecurityDisabler()) {
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentNode= master.GetItem("ItemNAme");
var childItems=parentNode.GetChildren();
}

The reason you find this problem is not related to security.
When IsPreview is true (cookie based) and Filtering on the site config is allowed you will not get Items with publishing restrictions. This functionality is from the implementation of the PageEditor Preview where you need to browse the master database as if published items where not visible.
See the answers on Sitecore Publishable flag makes it impossible to GetItem() from Master database

Related

Can we restrict publish subitems count in sitecore if items more than 20

Want to restrict to publish items ,if items count is more than 20.
You could do this with an item validator, so that "the 21st" item and onward would fail validation so that it cannot transition to the final workflow step.
Another, more intrusive, alternative could potentially be having a item:saved processor that could set __Never publish to 1 to the surplus items, so they can't be published.
As a general recommendation, I'd say you should avoid changing the publishing pipeline. Try having all the items in a "good/valid" state instead, like the solutions above, where you don't change the behavior of Sitecore - rather just keep the content in a state that's in line with the application requirements.

Update of QTreeView without changing selection

I have a model that retrieves data from a table in a database from a certain SQL query, and shows the items in a QTreeView. The characteristics are:
the data comes from a table, but has an underlying tree structure (some rows are parents that have rows below them as children)
this tree structure is shown in the QTreeView
the children are selectable in the QTreeView (not so the parents)
the table in the database gets updated continuously
in the updates, a children can be added to any existing parent
periodically (with a QTimer) the QTreeView is updated with the contents of the table
Since the children are added at any time to any parent, the first silly approach when updating the QTreeView is clearing it all, and append all the rows again, in form of parent or children, to the QTreeView. This is a 0-order approximation, and it is indeed terrible inefficient. In particular, the following problems appear:
Any existing selection is gone
Any expanded parent showing its children is collapsed (unless ExpandAll is active)
The view is reset to show the very first row.
What is the best solution to this problem? I mean, the first solution I will try will be not to clear the QTreeView, but instead parse all the returned rows from the table, and check for each of them whether the corresponding item in the QTreeView exists, and add it if not. But I wonder if there is a trickiest solution to engage a given table in a database with a QTreeView (I know this exists for a QTableView, but then the tree structure is gone).
This thread mentions a general approach, but this might get tricky quickly, but I am not sure how this would work if the underlying model is changing constantly (i.e. the QModelIndex becoming invalid).
Worst case is that you will have to write your own mechanism to remember the selection before updating and then re-applying it.
I assume you use some model/view implementation? You could enhance your model with a safe selection handling, in case the example mentioned above does not work for you.
I guess this is the case for a self-answer.
As I presumed, after a careful analysis of what data is retrieved from the database, I had to do the following "upgrades" to the retrieval code:
I retrieve, along with the fields I want to show in the view, two identifiers, one for grouping rows and one for sorting items into groups
I also retrieve the internal record ID (an increasing integer number) from the table in the database, in order to ask only for new records in the next retrieval.
In the model population code, I added the following:
I first scan the initial records that may belong to existing groups in the model
When, in the scanning, I reach the last group in the model, this implies that the rest of retrieved records belong to new groups (remember the records are retrieved sorted such that items that belong to the same group are retrieved together)
Then start creating groups and adding items to each group, until we use all the records retrieved.
Finally, it is very important:
the use beginInsertRows() and endInsertRows() before and after inserting new items in the model
capture the sorting status of the view (with sortIndicatorSection() and sortIndicatorOrder()) and re-apply this sorting status after updating the model (with sortByColumn())
Doing that the current position and selection in the QTreeView receiving the model updates are preserved, and the items in the view are added and the view updated transparently for the user.

See Publication Date for Items in Sitecore

I'm trying to figure out how to know when an Item was published in Sitecore. I've looked at the History table in SQL Server and I see when the Item was changed, and also when it moved through every step in the workflow. But I don't see anything that looks like a "Publication" event.
Thanks...!
Unfortunately you can't get a published date. You need to implement a custom way to track when items are published.
Please check this blog post:
http://sitecoreskills.blogspot.ro/2014/04/first-and-last-publish-dates-in-sitecore.html
If tracking the item published date using the History Table, note that the History Table is cleaned-up every 4hrs by default. So, you may end up having no values for the item.
Normally, once an item has been modified, it is inserted into the publish queue table. You may instead track the last published that occurred. You may refer to my blog post: https://hishaamn.wordpress.com/2015/10/25/last-published-timestamp-on-sitecore-login-page/
Thanks

How to Access Sitecore_Web Database Tables using Sitecore API

Hi i m new to Sitecore. I want to know how to access any table values from Sitecore Web Database through Sitecore API as i want to fill dropdownlist from a table inside sitecore_web database.How can we use Sitecore Queries to access data from Sitecore_Web Database?
I don't suggest you to access directly Sitecore_Web Database.What do you want to do exactly ?
Sitecore Api has a lot of classes, methods for accesing sitecore items but you don't access directly databases .
Maybe this link will help you.
You need to create some items to fill your dropdown list.
An item is a record in a database. Items are the basic building block of a Sitecore site. An item may represent any kind of information, e.g. a piece of content, a media file, a layout etc.
Items always have a name and and ID that uniquely identifies the item within the database. Items have a template that defines which fields the item contains. An item represent a single version of piece of content is a single language.
An item can be retrieved from a database using Items.
An item may have a number of subitems or children. These child items can be accessed through the Children property. The resulting items are checked for security and workflow before being returned. So while an item may have subitems, the current user may be denied access to them. The Parent property define the single parent item of this item.
An item represents a single version in a single language of a piece of content. The language of the item can be obtained from the Language property, while the version is available from the Version property.
The item must be in Editing state before the name or any field values can be changed. If not, an exception is raised. To enter the Editing state use the BeginEdit method and to end it, use the EndEdit method. The EditContext class can be used as a shortcut to BeginEdit/EndEdit.
I get this from Sitecore Api Documentation
As sitecore climber stated, you would not access the Sitecore database directly - this is not something which is supported by Sitecore. Typically you would achieve this through the Sitecore API using the following steps:
retrieve a node from the Sitecore tree which contains child items representing your dropdown items
retrieve the child items
databind your dropdown list to the list of child items
In an ascx, you could have something like this:
<asp:DropDownList ID="exampleDropDown" runat="server"/>
and in the code-behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var item = Sitecore.Context.Database.GetItem("/sitecore/content/SiteData/StuffForADropDownList");
if (item != null)
{
exampleDropDown.DataTextField = "Text";
exampleDropDown.DataValueField = "Value";
exampleDropDown.DataSource = from i in item.Children.AsEnumerable<Sitecore.Data.Items.Item>()
select new
{
Text = i["Text"],
Value = i.ID.ToString()
};
exampleDropDown.DataBind();
}
}
}
This example assumes that you have an item at /sitecore/content/SiteData/StuffForADropDownList with some child items, which each have a field called Text.
Default in Sitecore you will NEVER work with real database objects other then objects filled using the Sitecore API. Sitecore API will provide you with data from your Sitecore back-end.
If you want to fill a dropdown with a list of items as datasource try something like this:
var items = Sitecore.Context.Item.GetChildren().toList();
yourdropdown.Datasource = items;
yourdropdown.Databind();
Obviously setting your Datatext and Datevalue key correctly, but that's standard .Net.
In Sitecore, never directly get data out of your database and use the Sitecore API.
Please use the built in services to access the sitecore items. It provides the option to select the database in the Get Item method.
You can access the sitecore service with the below URL:
{Your Site}/sitecore/shell/webservice/service.asmx

Sitecore Advanced Database Crawler index is populated with deleted items over newly created items

I have a Sitecore Advanced Database Crawler index in Sitecore 6.5 which shows strange behavior.
I use the index to index product-items and have the following structure in my Sitecore content
tree:
/Products/Category/Product1
./Product2
./Product3
Every night an import process runs that removes the item /Category/ and all of its descendants and creates a new item (with new Guids) with underlying products.
The products are mostly the same every day, only a few are added or removed.
The rootPath of my ADC index is set to /Products/Category/
After the import a publish is done on the /Products/ item and all its descendants.
So far so good. But I noticed that after the publish, the ADC index is modified but when I open the page that is supposed to display the products, I have no products.
When I use Luke to open the index, I have only "Deleted" documents in my index.
I checked the HistoryTable of the Web-database and it includes records for the deleted products as well as the newly created products.
The IndexingProvider_LastUpdate timestamp in the web-database is later than the most recent record in the historytable.
It seems like the ADC/Lucene index takes the Deleted items over the Created items and uses the Path instead of the ID to determine which item is the most recent.
When I manualy do a full-publish of the /Category/ item and it's descendants after the import, the index will get modified again and then the product items are back as normal items in the index and on the webpage.
What is going wrong here and how can this be resolved?
I noticed that my index is pointing to /Products/Category/ and during import the /Category/ item is removed and re-created. Changing the index path to /Products/ seems to resolve the issue.
Somehow the Index Crawler gets stuck when the index startingpoint is removed and recreated.