[contentbox 1.6.0] Utilizing the contentStore....

From where are you reading youc. Ant use the slug. That’s the whole point. To use the slug

I don’t really have the code anymore that I used to access ContentBox, but I know I started with ContentStoreService.findBySlug (which inherits from ContentService).

I can get the content by slug, but half the functions on the ContentStore item are…well, not working if the Content item isn’t in a published state. I can’t use render, I can’t check the publish date, etc. To get what I needed, I’d have to traverse the versions. And even if do traverse the versions, it doesn’t help because the versions themselves have no indication of whether they were published versions or not. Just … here’s version 5.

<cfset prc.PageContent = prc.ServiceFactory.getContentService().getPublishedContentByKey(‘test-content’) />

That now goes to my database, build a struct of info to to return. I store who created the content and who updated it. (With CB native, to get the creator you have to dig back through the versions, assuming you’ve kept them all and not truncated archive at, say, 20 items max history.) I only store the AuthorID for each, though, so I fetch the AuthorService and get the Author object to describe those two people (if different). To save time, I just store the content in my table, too.

But I don’t have to do that now that I receive updates from CB Admin. I’m guessing you’re getting ready to tell me I’m doing it all wrong! (Let’s talk about interfaces for 30 minutes instead!) What I wanted, in my opinion, was very simple: The last published version of content regardless of the current publish/draft state. Folks tried to help, but no one seemed to know the right answer. I probably spent over an hour searching for every scrap of documentation that talks about how to use the ContentStore. Sorry to say, but there just isn’t a lot of stuff out there yet like there is for Coldbox. (On one page I found from Sept. 2013 it (you?) even acknowledge that ContentBox is changing too rapidly to do documentation right now.)

ContentBox is focused heavily on rendering, and I get that. We use it at EQ for the blog, and it’s great. (Unless you save changes and forget to Publish, in which case the article goes offline. Pretty much the situation I’m dealing with today.) I’m trying to use it as what it’s named to be: “a content store” so that I can pull pieces of content into various areas and let the editors update them. If they publish, I’ll pull the content. If they save and forget to publish, or aren’t ready to publish, I at least can access the “last published copy”.

Hopefully you understand what I’m babbling on about here. Trying to give you as much background as possible in case you’re looking to improve ContentBox. I think the change to support this is minimal. Each Content record should store the LastPublished_ContentVersionID. If I ask for findBySlug(‘snippetName’, true), then populate a Content bean based on the version of information in that stored ContentVersionID. Until someone hits publish. Even in the CB admin interface, if I get a new version everytime I save, how will I even know which of the version 1 through 100 was the one I published if I want to go back to it?

There goes the neighborhood, someone let Will Belden on the list! HA!

Good to see Ya Will! Didn’t realize you were on this list J

Marco G. Williams

Information Technology Manager

Global Electronic Technology, Inc. (GET)

970 W. 190th Street, Suite 890

Torrance, CA 90502

Toll-Free: (888) 775-1500 | Local: (949) 380-0345 x209

http://www.gettrx.com

Verifying the World, One Transaction at a time.™

Hey Will,

If you want ping me directly, I have some ideas as to how you can accomplish what you want.

In short, maybe using the ContentStore getBySlug might not suite. You’re on the right track though. You can access all data in the ORM by the service and using a criteria search. I’ve had to do this many times as a work around for things I need in ContentBox.

Also have you taken a look at ContentStoreService.cfc the Search method? This has the glue to everything you would need. Notice the following.

var c = newCriteria();

// isPublished filter

if( structKeyExists(arguments,“isPublished”) AND arguments.isPublished NEQ “any”){

c.eq(“isPublished”, javaCast(“boolean”,arguments.isPublished));

}

Etc… etc…

You will notice code like Aliases, this ( I believe ) is how you join to different tables in the criteria search.

All the tools are there, but I think this is the foundation of a custom way to find the data your looking for.

Feel free to reach me directly and I hope this helps.

Marco G. Williams

Information Technology Manager

Global Electronic Technology, Inc. (GET)

970 W. 190th Street, Suite 890

Torrance, CA 90502

Toll-Free: (888) 775-1500 | Local: (949) 380-0345 x209

http://www.gettrx.com

Verifying the World, One Transaction at a time.™

Will,

Give me a few minutes and I’ll get you over some code that will do what you want.

Thanks,

Marco G. Williams

Information Technology Manager

Global Electronic Technology, Inc. (GET)

970 W. 190th Street, Suite 890

Torrance, CA 90502

Toll-Free: (888) 775-1500 | Local: (949) 380-0345 x209

http://www.gettrx.com

Verifying the World, One Transaction at a time.™

This should get you what you want. There is more than you can do with the Criteria, but this will at least give you the content you want despite its version or if its pending publishing.

contentStoreSvc = controller.getWireBox().getInstance(“ContentStoreService@cb”);

c = contentStoreSvc.newCriteria();

contentObjects = c.createAlias(“activeContent”,“ac”, c.LEFT_JOIN)

.like(“slug”,“test-info”)

.order(“ac.version”,“DESC”)

.list();

content = {};

for(c in contentObjects){

content = c;

}

<— Your content is here —>

content.GETACTIVECONTENT().content

Hope this gets you closer to what you are looking for.

Thanks,

This should get you what you want. There is more than you can do with the Criteria, but this will at least give you the content you want despite its version or if its pending publishing.

contentStoreSvc = controller.getWireBox().getInstance(“ContentStoreService@cb”);

c = contentStoreSvc.newCriteria();

contentObjects = c.createAlias(“activeContent”,“ac”, c.LEFT_JOIN)

.like(“slug”,“test-info”)

.order(“ac.version”,“DESC”)

.list();

content = {};

for(c in contentObjects){

content = c;

}

<— Your content is here —>

content.GETACTIVECONTENT().content

Hope this gets you closer to what you are looking for.

Thanks,

Sure np. The other email came in after this one. I’m not sure in what event the data structure would change and not the beans change with it. That IMO is just bad practice. The beans should reflect what the data structure is, which is in part the point of ORM.

But if you’ve got a work around going for you, then I’m content :smiley:

Realistically, there should be an accessor method that reflects a content pull at the contents current state, weather it is published or not and the getBySlug should only pull the “Last published” content, that is definitely a bug. I may go in and fix that because I can definitely see that being a problem for me in the future.

Thanks,

We use ContentBox for our internal development blog here at work. We see the opposite, not sure how it is on the newer version.

I create, I publish. Blog entry is available. (“Edit 1”)
I edit, change text to “Edit 2”. I save. Even after reloading the editor, the items shows “Draft!”
But when I refresh the blog view, I see “Edit 2”. So it was published but the admin doesn’t show that.

It’s pulling the latest content, even though it’s in a draft state.

Again, no recognition of the version that was published and the edits that aren’t.

Yeah, that would be the bug I was speaking of. The accessor for getting the content by slug should be returning the most recent “Published” content. But that doesn’t mean the data structure would ever change. The data structure and the beans are the same.

This is pseudo, another workaround might be…

contentStoreService.getActiveContent().findBySlug(‘[slugname]’);

I don’t know if that would actually work, but I do know that ActiveContent hold the most recent version. The part I’m a little shakey on is if getActiveContent() will throw an error or not.

Just more food for thought :smiley:

Thanks,

Marco G. Williams

Information Technology Manager

Global Electronic Technology, Inc. (GET)

970 W. 190th Street, Suite 890

Torrance, CA 90502

Toll-Free: (888) 775-1500 | Local: (949) 380-0345 x209

http://www.gettrx.com

Verifying the World, One Transaction at a time.™

Marco,

Based on the database, I don’t see how that could work. Besides, there is a CLEAR difference between active and published. The last version you saved, whether published or not, is the “active” version.

There is no indication in the database that either a) a given version is published or b) what version was published (via the Content record).

Marco,

The findBySlug is similar already.

/**

  • Find a published content object by slug and published unpublished flags, if not found it returns
  • a new content object
  • @slug.hint The slug to search
  • @showUnpublished.hint To also show unpublished content, defaults to false.
    */
    function findBySlug(required any slug, required boolean showUnpublished=false){
    var c = newCriteria();
    // Override usually for admins
    if( !showUnpublished ){
    c.isTrue(“isPublished”)
    .isLT(“publishedDate”, now())
    .$or( c.restrictions.isNull(“expireDate”), c.restrictions.isGT(“expireDate”, now() ) );
    }
    // By criteria now
    var content = c.isEq(“slug”,arguments.slug).get();
    // return accordingly
    return ( isNull( content ) ? new() : content );
    }

Notice how you pass in the showUnPublished, this needs to be true if there is no previously published entry and you have saved it. But ContentBox V2.0 has all this in the road map to have the flow of content and history move to a better flow.

Again this has been reported and is on the todo list for ContentBox V2.0 roadmap.

Okay, y’all acknowledge it. That’s the greatness I needed if there wasn’t a specific way to do it otherwise.

Thanks every, for pitching in on this one! Andrew, you’ve been great!